aboutsummaryrefslogtreecommitdiff
path: root/configure
diff options
context:
space:
mode:
Diffstat (limited to 'configure')
-rwxr-xr-xconfigure152
1 files changed, 152 insertions, 0 deletions
diff --git a/configure b/configure
new file mode 100755
index 0000000..f10ef90
--- /dev/null
+++ b/configure
@@ -0,0 +1,152 @@
+#!/bin/sh
+# vim:ft=sh:ts=4:sw=4:noexpandtab
+set -e
+
+# Configured variables #####################################################
+# Described in following format:
+# name:initial value:type:if exported to makefile:if exported to C header
+# Where type can be just a string (in C in "") or plain. None implies plain.
+CNFS="CBUILD:::F:F
+CHOST:::F:F
+DEBUG:no::T:F
+CPREFIX:::T:F
+CCX:g++::T:F
+CFLAGS:::T:F
+LFLAGS:::T:F"
+############################################################################
+# TODO add options to fine tune installation directories
+
+print_help() {
+ echo "Usage: ./configure [OPTION]..."
+ echo "GEML configuration script. Execute this script to configure project"
+ echo "and prepare it for building."
+ echo
+ echo " --help, -h Give this help list"
+ echo " --debug, -d Enable development features."
+ echo " --release, -r Disable development features for project."
+ echo " --dep-check Force depencency check."
+ echo " --build=CBUILD System compiler prefix on which project is"
+ echo " built."
+ echo " --host=CHOST Compiler prefix for system program and"
+ echo " libraries will run on."
+ echo
+ echo "Environment variables:"
+ echo " CPREFIX Compilation tools prefix."
+ echo " CXX C++ compiler command."
+ echo " CFLAGS C++ compiler flags."
+ echo " LDFLAGS C++ Linker flags."
+}
+
+CONFIG_FILE=.config
+CONFIGURED_FILE=.configured # TODO
+
+# Backup variables from environment
+ENVVARS="CPREFIX CXX CFLAGS LDFLAGS"
+for E in $ENVVARS; do
+ eval "[ -n \"\${$E+y}\" ]" && eval "BACKUP_$E=\$$E"
+done
+
+# Load default configuration if variable not set from environment
+eval `echo "$CNFS" | sed -ne 's/^\([^:]*\):\([^:]*\).*$/\1=\2/p'`
+
+# Load existing configuration
+if [ -f "$CONFIG_FILE" ]; then
+ . ./"$CONFIG_FILE"
+fi
+
+# Functions used for arguments parsing. Handles both --*=* and --* * arguments.
+# First arguments is option name. Second is $1 and third $2
+set_options() {
+ if [[ "$2" == --*=* ]]; then
+ VAL="$(echo "$2" | sed 's/--[^=]*=//')"
+ else
+ VAL="$3"
+ fi
+}
+
+# Requested operation.
+# c - Configure, default configuration behavior
+# m - Prints output for Makefile
+# h - Prints C header file
+OP=c
+
+# Parse arguments
+while [ "$#" -gt 0 ]; do
+ case $1 in
+ -h|--help)
+ print_help
+ exit 0
+ ;;
+ -d|--debug)
+ DEBUG=yes
+ ;;
+ -r|--release)
+ DEBUG=no
+ ;;
+ --op-makefile)
+ OP=m
+ ;;
+ --op-h)
+ OP=h
+ ;;
+ *)
+ echo Warning: Unknown option $1 1>&2
+ ;;
+ esac
+ shift
+done
+
+# Recover from enviroment variables
+for E in $ENVVARS; do
+ eval "[ -n \"\${BACKUP_$E+y}\" ]" && eval "$E=\$BACKUP_$E"
+done
+
+# Basically save configuration to file
+configure() {
+ echo "# linux-lcd configuration file" > "$CONFIG_FILE"
+ echo "# Please do not edit this file directly." >> "$CONFIG_FILE"
+ echo "$CNFS" | while read L; do
+ NAME=`echo "$L" | grep -o -E '^[^:]*'`
+ eval "VALUE=\$$NAME"
+ echo "$NAME=$VALUE" >> "$CONFIG_FILE"
+ done
+ echo "Configuration written to \"$CONFIG_FILE\""
+}
+
+makefile() {
+ echo "$CNFS" | while read L; do
+ if [ `echo $L | awk -F ':' '{ print $4 }'` != "T" ]; then
+ continue
+ fi
+ NAME=`echo "$L" | grep -o -E '^[^:]*'`
+ eval "VALUE=\$$NAME"
+ echo "$NAME := $VALUE"
+ done
+}
+
+cheader() {
+ echo "$CNFS" | while read L; do
+ if [ `echo $L | awk -F ':' '{ print $5 }'` != "T" ]; then
+ continue
+ fi
+ NAME=`echo "$L" | grep -o -E '^[^:]*'`
+ eval "VALUE=\$$NAME"
+ if [ "`echo $L | awk -F ':' '{ print $3 }'`" = "string" ]; then
+ echo "#define $NAME \"$VALUE\""
+ else
+ echo "#define $NAME $VALUE"
+ fi
+ done
+}
+
+case $OP in
+ c)
+ configure
+ ;;
+ m)
+ makefile
+ ;;
+ h)
+ cheader
+ ;;
+esac