summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2014-02-02 23:44:49 +0100
committerSebastian Reichel <sre@ring0.de>2014-02-02 23:44:49 +0100
commit59f174bac810b123365ec2fc0ffb04379751308a (patch)
tree31925ae4563b9f7a1fb80f3b2c1505b6bd3f5b59
parentfe3e87b21a2efb48343cb854d3213fa456199961 (diff)
downloadserial-barcode-scanner-59f174bac810b123365ec2fc0ffb04379751308a.tar.bz2
update configure script
configure script now generates configuration files for the sourcecode and the build system.
-rw-r--r--.gitignore2
-rwxr-xr-xconfigure193
-rwxr-xr-xconfigure-functions.sh351
3 files changed, 395 insertions, 151 deletions
diff --git a/.gitignore b/.gitignore
index cc06bf2..0f922c6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@ gnupg/
*.swp
shop.db
ktt-shopsystem.cfg
+config.mk
+config.h
diff --git a/configure b/configure
index edaa768..4da1bbd 100755
--- a/configure
+++ b/configure
@@ -1,165 +1,56 @@
#!/bin/sh
+. ./configure-functions.sh
-# This awk script is derived from autotools
-awk_verscmp='
- # Use only awk features that work with 7th edition Unix awk (1978).
- # My, what an old awk you have, Mr. Solaris!
- END {
- while (length(v1) && length(v2)) {
- # Set d1 to be the next thing to compare from v1, and likewise for d2.
- # Normally this is a single character, but if v1 and v2 contain digits,
- # compare them as integers and fractions as strverscmp does.
- if (v1 ~ /^[0-9]/ && v2 ~ /^[0-9]/) {
- # Split v1 and v2 into their leading digit string components d1 and d2,
- # and advance v1 and v2 past the leading digit strings.
- for (len1 = 1; substr(v1, len1 + 1) ~ /^[0-9]/; len1++) continue
- for (len2 = 1; substr(v2, len2 + 1) ~ /^[0-9]/; len2++) continue
- d1 = substr(v1, 1, len1); v1 = substr(v1, len1 + 1)
- d2 = substr(v2, 1, len2); v2 = substr(v2, len2 + 1)
- if (d1 ~ /^0/) {
- if (d2 ~ /^0/) {
- # Compare two fractions.
- while (d1 ~ /^0/ && d2 ~ /^0/) {
- d1 = substr(d1, 2); len1--
- d2 = substr(d2, 2); len2--
- }
- if (len1 != len2 && ! (len1 && len2 && substr(d1, 1, 1) == substr(d2, 1, 1))) {
- # The two components differ in length, and the common prefix
- # contains only leading zeros. Consider the longer to be less.
- d1 = -len1
- d2 = -len2
- } else {
- # Otherwise, compare as strings.
- d1 = "x" d1
- d2 = "x" d2
- }
- } else {
- # A fraction is less than an integer.
- exit 1
- }
- } else {
- if (d2 ~ /^0/) {
- # An integer is greater than a fraction.
- exit 2
- } else {
- # Compare two integers.
- d1 += 0
- d2 += 0
- }
- }
- } else {
- # The normal case, without worrying about digits.
- d1 = substr(v1, 1, 1); v1 = substr(v1, 2)
- d2 = substr(v2, 1, 1); v2 = substr(v2, 2)
- }
- if (d1 < d2) exit 1
- if (d1 > d2) exit 2
- }
- # Beware Solaris /usr/xgp4/bin/awk (at least through Solaris 10),
- # which mishandles some comparisons of empty strings to integers.
- if (length(v2)) exit 1
- if (length(v1)) exit 2
- }
-'
+NAME="serial-barcode-scanner"
+AUTHOR="Sebastian Reichel <sre@ring0.de>"
+VERSION="0.1"
-check_prg_version() {
- printf " %-29s" "$1..."
-
- awk "$awk_verscmp" v1="$2" v2="$3" /dev/null
-
- if [ "$?" = "2" ] ; then
- echo "MISSING";
- return 1;
- else
- echo " OK";
- return 0;
- fi
-}
-
-check_pkg_config() {
- pkg="$1"
- version="$2"
-
- printf " %-29s" "$1..."
-
- if [ "x$version" = "x" ] ; then
- pkg-config --exists "$1"
- else
- pkg-config --atleast-version "$2" "$1"
- fi
+check_dependencies() {
+ VALA_VERSION=`valac --api-version`
+ GPGME_VERSION=`gpgme-config --version`
+ ESMTP_VERSION=`libesmtp-config --version`
- result=$?
+ echo "Checking software dependencies:"
+ check_prg_version valac 0.16 $VALA_VERSION "force"
- if [ $result = 1 ] ; then
- echo "MISSING"
- else
- echo " OK"
- fi
+ echo "Checking library dependencies:"
+ check_pkg_version ncursesw 5.9 "force"
+ check_pkg_version gdk-2.0 2.24 "force"
+ check_pkg_version gee-1.0 0.6 "force"
+ check_pkg_version gio-2.0 2.36 "force"
+ check_pkg_version gmime-2.6 2.6.10 "force"
+ check_prg_version gpgme 1.2 $GPGME_VERSION "force"
+ check_pkg_version gstreamer-0.10 0.10.36 "force"
+ check_pkg_version libarchive 3.0 "force"
+ check_prg_version libesmtp 0.1 $ESMTP_VERSION "force"
+ check_pkg_version librsvg-2.0 2.36 "force"
+ check_pkg_version libsoup-2.4 2.38 "force"
+ check_pkg_version pangocairo 1.32 "force"
+ check_pkg_version sqlite3 3.7 "force"
- return $?
+ echo "Checking font dependencies:"
+ check_font LMSans10 "force"
+ check_font LMRoman10 "force"
}
-check_font() {
- name="$1"
-
- printf " %-29s" "$1..."
-
- for file in /etc/fonts/conf.avail/*; do
- grep -q "$name" "$file"
- if [ $? -eq 0 ] ; then
- echo " OK"
- return 0
- fi
- done
-
- echo "MISSING"
- return 1
+extra_options() {
+ case $1 in
+ *)
+ DESC="not available"
+ CMD="not-available"
+ esac
}
-check_dependencies() {
- echo "Checking software dependencies:"
- errors=0
- check_prg_version valac 0.16 `valac --api-version`
- errors=`expr $errors + $?`
+BASE=`dirname $0`
- echo "Checking library dependencies:"
- check_pkg_config ncursesw 5.9
- errors=`expr $errors + $?`
- check_pkg_config gdk-2.0 2.24
- errors=`expr $errors + $?`
- check_pkg_config gee-1.0 0.6
- errors=`expr $errors + $?`
- check_pkg_config gio-2.0 2.36
- errors=`expr $errors + $?`
- check_pkg_config gmime-2.6 2.6.10
- errors=`expr $errors + $?`
- check_prg_version gpgme 1.2 `gpgme-config --version`
- errors=`expr $errors + $?`
- check_pkg_config gstreamer-0.10 0.10.36
- errors=`expr $errors + $?`
- check_pkg_config libarchive 3.0
- errors=`expr $errors + $?`
- check_prg_version libesmtp 0.1 `libesmtp-config --version`
- errors=`expr $errors + $?`
- check_pkg_config librsvg-2.0 2.36
- errors=`expr $errors + $?`
- check_pkg_config libsoup-2.4 2.38
- errors=`expr $errors + $?`
- check_pkg_config pangocairo 1.32
- errors=`expr $errors + $?`
- check_pkg_config sqlite3 3.7
- errors=`expr $errors + $?`
+check_parameters $@
+check_compiler
+check_install
+check_pkgconfig
- echo "Checking font dependencies:"
- check_font LMSans10
- errors=`expr $errors + $?`
- check_font LMRoman10
- errors=`expr $errors + $?`
+check_dependencies
- if [ $errors -ne 0 ] ; then
- echo "Aborting due to errors!"
- exit 1;
- fi
-}
+create_config $BASE/config.mk VALAC
+create_header $BASE/config.h VERSION
-check_dependencies
+final_report CC PREFIX
diff --git a/configure-functions.sh b/configure-functions.sh
new file mode 100755
index 0000000..e003e5d
--- /dev/null
+++ b/configure-functions.sh
@@ -0,0 +1,351 @@
+#!/bin/sh
+# MIT license
+# Copyright 2009-2010 Sebastian Reichel <sre@ring0.de>
+
+# These are default values for some configurable things
+if [ "x$CC" = "x" ] ; then
+ CC=gcc
+fi;
+
+if [ "x$VALAC" = "x" ] ; then
+ VALAC=valac
+fi;
+
+if [ "x$INSTALL" = "x" ] ; then
+ INSTALL=install
+fi;
+
+if [ "x$PKGCONFIG" = "x" ] ; then
+ PKGCONFIG=pkg-config
+fi;
+
+PREFIX=/usr/local
+INSTALL_DATA=`echo ${INSTALL} -m 644`
+INSTALL_PROGRAM=`echo ${INSTALL} -m 755 -s`
+INSTALL_DIR=`echo ${INSTALL} -d`
+
+# This awk script is derived from autotools
+awk_verscmp='
+ # Use only awk features that work with 7th edition Unix awk (1978).
+ # My, what an old awk you have, Mr. Solaris!
+ END {
+ while (length(v1) && length(v2)) {
+ # Set d1 to be the next thing to compare from v1, and likewise for d2.
+ # Normally this is a single character, but if v1 and v2 contain digits,
+ # compare them as integers and fractions as strverscmp does.
+ if (v1 ~ /^[0-9]/ && v2 ~ /^[0-9]/) {
+ # Split v1 and v2 into their leading digit string components d1 and d2,
+ # and advance v1 and v2 past the leading digit strings.
+ for (len1 = 1; substr(v1, len1 + 1) ~ /^[0-9]/; len1++) continue
+ for (len2 = 1; substr(v2, len2 + 1) ~ /^[0-9]/; len2++) continue
+ d1 = substr(v1, 1, len1); v1 = substr(v1, len1 + 1)
+ d2 = substr(v2, 1, len2); v2 = substr(v2, len2 + 1)
+ if (d1 ~ /^0/) {
+ if (d2 ~ /^0/) {
+ # Compare two fractions.
+ while (d1 ~ /^0/ && d2 ~ /^0/) {
+ d1 = substr(d1, 2); len1--
+ d2 = substr(d2, 2); len2--
+ }
+ if (len1 != len2 && ! (len1 && len2 && substr(d1, 1, 1) == substr(d2, 1, 1))) {
+ # The two components differ in length, and the common prefix
+ # contains only leading zeros. Consider the longer to be less.
+ d1 = -len1
+ d2 = -len2
+ } else {
+ # Otherwise, compare as strings.
+ d1 = "x" d1
+ d2 = "x" d2
+ }
+ } else {
+ # A fraction is less than an integer.
+ exit 1
+ }
+ } else {
+ if (d2 ~ /^0/) {
+ # An integer is greater than a fraction.
+ exit 2
+ } else {
+ # Compare two integers.
+ d1 += 0
+ d2 += 0
+ }
+ }
+ } else {
+ # The normal case, without worrying about digits.
+ d1 = substr(v1, 1, 1); v1 = substr(v1, 2)
+ d2 = substr(v2, 1, 1); v2 = substr(v2, 2)
+ }
+ if (d1 < d2) exit 1
+ if (d1 > d2) exit 2
+ }
+ # Beware Solaris /usr/xgp4/bin/awk (at least through Solaris 10),
+ # which mishandles some comparisons of empty strings to integers.
+ if (length(v2)) exit 1
+ if (length(v1)) exit 2
+ }
+'
+
+show_usage() {
+ echo "'configure' configures $1 to adapt to many kinds of systems."
+ echo "Usage: ./configure [OPTION]... [VAR=VALUE]..."
+ echo
+ echo "To assign environment variables (e.g. CC, CFLAGS, ...), specify them"
+ echo "as VAR=VALUE. See below for descriptions of some of the useful variables."
+ echo
+ echo "Defaults for the options are specified in brackets."
+ echo
+ echo "Options:"
+
+ echo " -h, --help display this help and exit"
+ echo " -v, --version display version information and exit"
+ echo " --prefix=PREFIX install files in PREFIX [/usr/local]"
+ echo " --debug enable debug build (-g flag)"
+ echo " --colored enable colored build"
+
+ for parameter in `extra_options list-all` ; do
+ extra_options $parameter
+ printf " %-27s $DESC\n" $parameter
+ done
+
+ echo
+ echo "Some influential environment variables:"
+ echo " CC C compiler command"
+ echo " VALAC Vala compiler"
+ echo " CFLAGS C compiler flags, e.g. -I<header dir>"
+ echo " LDFLAGS linker flags, e.g. -L<lib dir>"
+ echo " INSTALL install binary"
+ echo " PKGCONFIG pkg-config binary"
+ echo
+ echo "Report bugs to: $2"
+ exit 0
+}
+
+show_version() {
+ echo "$1 version $2"
+ echo "Originally written by $3"
+ exit 0
+}
+
+check_parameters() {
+ while : ; do
+ [ -z "$1" ] && break
+ parse_options $1
+ shift
+ done
+
+ if [ "$UNKNOWN_FLAG" = "1" ] ; then
+ echo
+ fi
+}
+
+parse_options() {
+ flag=`echo $1 | cut -d = -f 1`
+ value=`echo $1 | awk 'BEGIN{FS="=";}{print $2}'`
+
+ case $flag in
+ "-h"|"--help")
+ show_usage "$NAME" "$AUTHOR"; ;;
+ "-v"|"--version")
+ show_version "$NAME" "$VERSION" "$AUTHOR"; ;;
+ "--debug")
+ DEBUG="yes"; ;;
+ "--colored")
+ COLOR="yes"; ;;
+ "--prefix")
+ PREFIX="$value"; ;;
+ "CC")
+ CC="$value"; ;;
+ "CFLAGS")
+ CFLAGS="$value"; ;;
+ "LDFLAGS")
+ LDFLAGS="$value"; ;;
+ "INSTALL")
+ INSTALL="$value"; ;;
+ "PKGCONFIG")
+ PKGCONFIG="$value"; ;;
+ "VALAC")
+ VALAC="$value"; ;;
+ *)
+ extra_options $flag $value
+ if [ "$CMD" != "not-available" ] ; then
+ eval "$CMD"
+ else
+ echo "WARNING: unknown flag '$1'." >&2
+ UNKNOWN_FLAG=1
+ fi;;
+ esac
+}
+
+check_prg_version() {
+ printf " %-34s" "$1..."
+
+ if [ "$4" = "disable" ] ; then
+ echo "disabled"
+ return 0
+ fi
+
+ if [ "$3" = "" ] ; then
+ echo "missing"
+ if [ "$4" != "force" ] ; then
+ return 0
+ else
+ exit 1
+ fi
+ fi
+
+ echo "$3"
+
+ awk "$awk_verscmp" v1="$2" v2="$3" /dev/null
+ if [ "$?" = "2" ] ; then
+ echo "Please install at least $2 to use this feature"
+ if [ "$4" != "force" ] ; then
+ return 0
+ else
+ exit 1
+ fi
+ fi
+
+ return 1
+}
+
+check_pkg_version() {
+ printf " %-34s" "$1..."
+
+ if [ "$3" = "disable" ] ; then
+ echo "disabled"
+ return 0
+ fi
+
+ pkg-config --exists $1
+ if [ "$?" = "1" ] ; then
+ echo "missing"
+ if [ "$3" != "force" ] ; then
+ return 0
+ else
+ exit 1
+ fi
+ fi
+
+ echo `pkg-config --modversion $1`
+
+ pkg-config --atleast-version "$2" "$1"
+ if [ "$?" = "1" ] ; then
+ echo "Please install at least $2"
+ if [ "$3" != "force" ] ; then
+ return 0
+ else
+ exit 1
+ fi
+ fi
+
+ return 1
+}
+
+check_font() {
+ name="$1"
+
+ printf " %-34s" "$1..."
+
+ for file in /etc/fonts/conf.avail/*; do
+ grep -q "$name" "$file"
+ if [ $? -eq 0 ] ; then
+ echo "available"
+ return 1
+ fi
+ done
+
+ echo "MISSING"
+
+ if [ "$2" != "force" ] ; then
+ return 0
+ else
+ exit 1
+ fi
+}
+
+check_compiler() {
+ printf "Checking compiler... "
+ echo 'main(){}' > test.c
+ ${CC} ${CFLAGS} ${LDFLAGS} -o a.out test.c >/dev/null 2>&1
+ if [ ! $? = 0 ]; then
+ echo failed
+ exit 1
+ else
+ echo works
+ fi
+ rm -f a.out test.c
+}
+
+check_install() {
+ printf "Checking install... "
+ if [ -x `which ${INSTALL}` ] ; then
+ echo available
+ else
+ echo missing
+ exit 1
+ fi
+}
+
+check_pkgconfig() {
+ printf "Checking pkg-config... "
+ if [ -x `which ${PKGCONFIG}` ] ; then
+ echo `${PKGCONFIG} --version`
+ else
+ echo missing
+ exit 1
+ fi
+}
+
+create_config() {
+ FILE=$1
+ shift
+ printf "Creating %-26s" $FILE...
+ rm -f $FILE && touch $FILE
+
+ # Some standard variables
+ echo DEBUG=$DEBUG >> $FILE
+ echo COLOR=$COLOR >> $FILE
+ echo CC=$CC >> $FILE
+ echo CFLAGS=$CFLAGS >> $FILE
+ echo LDFLAGS=$LDFLAGS >> $FILE
+ echo PREFIX=$PREFIX >> $FILE
+ echo PKGCONFIG=$PKGCONFIG >> $FILE
+ echo INSTALL=$INSTALL >> $FILE
+ echo INSTALL_DATA=$INSTALL_DATA >> $FILE
+ echo INSTALL_PROGRAM=$INSTALL_PROGRAM >> $FILE
+ echo INSTALL_DIR=$INSTALL_DIR >> $FILE
+
+ for option in $@ ; do
+ value=`echo \\$$option`
+ value=`eval echo $value`
+ echo $option=$value >> $FILE
+ done
+
+ echo "done"
+}
+
+create_header() {
+ FILE=$1
+ shift
+ printf "Creating %-26s" $FILE...
+ rm -f $FILE && touch $FILE
+
+ for option in $@ ; do
+ value=`echo \\$$option`
+ value=`eval echo $value`
+ echo "#define $option \"$value\"" >> $FILE
+ done
+
+ echo "done"
+}
+
+final_report() {
+ echo
+ echo "Final Report:"
+ for option in $@ ; do
+ value=`echo \\$$option`
+ value=`eval echo $value`
+ printf " %-10s = %s\n" $option $value
+ done
+}