#!/bin/sh # vim:ft=sh:ts=4:sw=4:expandtab # 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="GEML_VERSION:0.1:string:F:T GEML_CONTACT:cynerd@email.cz:string:F:T PREFIX:/usr/local:string:T:F MOD_LUA:yes::T:F MOD_PYTHON:yes::T:F DEBUG:no::T:F CFLAGS:::T:F LFLAGS:::T:F" ############################################################################ 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 " --prefix=PATH Set PATH as installation prefix." echo " In default /usr/local" echo " --debug, -d Enable development features." echo " --release, -r Disable development features for project." echo " --dep-check Force depencency check for this machine." echo echo " --mod-lua-enable, --mod-lua-disable" echo " Set if Lua module should be compiled. In default is enabled." echo " --mod-python-enable, --mod-python-disable" echo " Set if Python module should be compiled. In default is enabled." echo echo "Environment variables:" echo " CROSS_COMPILE Prefix for compilation tools." echo echo "GEML version $GEML_VERSION" echo "Report bugs to <$GEML_CONTACT>." } CONFIG_FILE=.config CONFIGURED_FILE=.configured # TODO # TODO support for values with escaped colons # Load default configuration eval `echo "$CNFS" | grep -o -E '^[^:]*:[^:]*' | sed 's/:/=/'` # Load existing configuration if [ -f "$CONFIG_FILE" ]; then source ./"$CONFIG_FILE" fi # Requested operation. # c - Configure, default configuration behavior # m - Prints output for Makefile # h - Prints C header file (machine validation is skipped) OP=c # Parse arguments while [ "$#" -gt 0 ]; do case $1 in -h|--help) print_help exit 0 ;; --prefix=*) # TODO ;; -d|--debug) DEBUG=yes ;; -r|--release) DEBUG=no ;; --mod-lua-enable) MOD_LUA=yes ;; --mod-lua-disable) MOD_LUA=no ;; --mod-python-enable) MOD_PYTHON=yes ;; --mod-python-disable) MOD_PYTHON=no ;; --op-makefile) OP=m ;; --op-h) OP=h ;; *) echo Unknown option $1 1>&2 exit 2 ;; esac shift done # Basically save configuration to file configure() { echo "# GEML 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\"" } # Generate Makefile and configure them if they doesn't exists in PWD doext() { if [ -f "Makefile" ] || [ -f configure ]; then return fi GEMLDIR=`dirname "$0"` echo "# This is external Makefile for GEML." > Makefile echo "export CROSS_COMPILE=$CROSS_COMPILE" >> Makefile echo >> Makefile echo "GEML_PATH = $GEMLDIR" >> Makefile echo >> Makefile echo "MAKEARGS := -C \"\$(GEML_PATH)\"" >> Makefile echo "MAKEARGS += O=\"\$(shell pwd)\"" >> Makefile echo >> Makefile echo "MAKEFLAGS += --no-print-directory" >> Makefile echo >> Makefile echo "Q = @" >> Makefile echo ".PHONY: all \$(MAKECMDGOALS)" >> Makefile echo "all \$(MAKECMDGOALS):" >> Makefile echo " \$(Q)\$(MAKE) \$(MAKEARGS) \$@" >> Makefile echo Created local Makefile echo "# This is external configure script for GEML." > configure echo "GEML_PATH=$GEMLDIR" >> configure echo "\$GEML_PATH/configure \$@" >> configure chmod +x configure echo Created local configure script } 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 } validate() { echo -n # TODO check dependencies and programs } case $OP in c) validate doext configure ;; m) validate makefile ;; h) cheader ;; esac