aboutsummaryrefslogtreecommitdiff
path: root/configure
blob: 0b1c07bb2a82622e6b2a7ba8f188786b0cb8f5a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/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