#!/bin/sh # vim:ft=sh:ts=4:sw=4:noexpandtab # 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 EPREFIX:/usr/local:string:T:F DEBUG:no::T:F CPREFIX:::T:F CC:cc::T:F CFLAGS:::T:F LFLAGS:::T:F INSTALL:install::T:F GZIP:gzip::T:F DOT:dot::T:F MKDOCS:mkdocs::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 for this machine." echo " --prefix=PREFIX Set PREFIX as installation prefix for" echo " architecture independent files." echo " In default /usr/local" echo " --exec-prefix=EPREFIX Set EPREFIX as installation prefix for" echo " architecture dependent files." echo " In default PREFIX" echo echo "Environment variables:" echo " CPREFIX Compilation tools prefix." echo " CC C compiler command." echo " CFLAGS C compiler flags." echo " LDFLAGS C Linker flags." echo " INSTALL Copy files and set attributes." echo " GZIP Compress file." echo " DOT Directed graphs drawing program." echo " MKDOCS Project documentation generator." echo echo "GEML version $GEML_VERSION" echo "Report bugs to <$GEML_CONTACT>." } CONFIG_FILE=.config CONFIGURED_FILE=.configured # TODO # Backup variables from environment ENVVARS="CPREFIX CC CFLAGS LDFLAGS INSTALL GZIP DOT CPPCHECK VALGRIND MKDOCS" 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 # 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) PREFIX=$2 [ -z "$EPREFIX_USER" ] && EPREFIX="$PREFIX" shift ;; --prefix=*) PREFIX=${1#--prefix=} [ -z "$EPREFIX_USER" ] && EPREFIX="$PREFIX" ;; --exec-prefix) EPREFIX=$2 EPREFIX_USER=y shift ;; --exec-prefix=*) EPREFIX=${1#--exec-prefix=} EPREFIX_USER=y ;; -d|--debug) DEBUG=yes ;; -r|--release) DEBUG=no ;; --op-makefile) OP=m ;; --op-h) OP=h ;; *) echo Unknown option $1 1>&2 exit 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 "# 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 >> 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 "cd \$(dirname \$0)" >> 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