blob: 1a4f5485e81fefbb550445ebd47c624737bef77d (
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
|
#!/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 and shell in "") or plain. None implies
# plain.
CNFS="CBUILD:::F:F
CHOST:::F:F
DEBUG:no::T:F
CPREFIX:::T:F
CHOST::string:T:F
CCX:g++::T:F
CFLAGS::string:T:F
LFLAGS::string: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
;;
--host=*)
CHOST=${1#--host=}
shift
;;
--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\""
if [ "`echo $L | awk -F ':' '{ print $3 }'`" = "string" ]; then
echo "$NAME=\"$VALUE\"" >> "$CONFIG_FILE"
else
echo "$NAME=$VALUE" >> "$CONFIG_FILE"
fi
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
|