|
1 #!/bin/sh |
|
2 |
|
3 # create temporary directory |
|
4 TEMP_DIR=".tmp-`uname -n`" |
|
5 rm -Rf "$TEMP_DIR" |
|
6 if mkdir -p "$TEMP_DIR"; then |
|
7 : |
|
8 else |
|
9 echo "Cannot create tmp dir $TEMP_DIR" |
|
10 echo "Abort" |
|
11 exit 1 |
|
12 fi |
|
13 touch "$TEMP_DIR/options" |
|
14 touch "$TEMP_DIR/features" |
|
15 |
|
16 # define standard variables |
|
17 PREFIX=/usr |
|
18 EPREFIX= |
|
19 BINDIR= |
|
20 SBINDIR= |
|
21 LIBDIR= |
|
22 LIBEXECDIR= |
|
23 DATADIR= |
|
24 SYSCONFDIR= |
|
25 SHAREDSTATEDIR= |
|
26 LOCALSTATEDIR= |
|
27 INCLUDEDIR= |
|
28 INFODIR= |
|
29 MANDIR= |
|
30 |
|
31 # custom variables |
|
32 |
|
33 # features |
|
34 |
|
35 # clean abort |
|
36 abort_configure() |
|
37 { |
|
38 rm -Rf "$TEMP_DIR" |
|
39 exit 1 |
|
40 } |
|
41 |
|
42 # help text |
|
43 printhelp() |
|
44 { |
|
45 echo "Usage: $0 [OPTIONS]..." |
|
46 cat << __EOF__ |
|
47 Installation directories: |
|
48 --prefix=PREFIX path prefix for architecture-independent files |
|
49 [/usr] |
|
50 --exec-prefix=EPREFIX path prefix for architecture-dependent files |
|
51 [PREFIX] |
|
52 |
|
53 --bindir=DIR user executables [EPREFIX/bin] |
|
54 --sbindir=DIR system admin executables [EPREFIX/sbin] |
|
55 --libexecdir=DIR program executables [EPREFIX/libexec] |
|
56 --sysconfdir=DIR system configuration files [PREFIX/etc] |
|
57 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] |
|
58 --localstatedir=DIR modifiable single-machine data [PREFIX/var] |
|
59 --libdir=DIR object code libraries [EPREFIX/lib] |
|
60 --includedir=DIR C header files [PREFIX/include] |
|
61 --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] |
|
62 --datadir=DIR read-only architecture-independent data [DATAROOTDIR] |
|
63 --infodir=DIR info documentation [DATAROOTDIR/info] |
|
64 --mandir=DIR man documentation [DATAROOTDIR/man] |
|
65 |
|
66 __EOF__ |
|
67 } |
|
68 |
|
69 # |
|
70 # parse arguments |
|
71 # |
|
72 BUILD_TYPE="default" |
|
73 for ARG in "$@" |
|
74 do |
|
75 case "$ARG" in |
|
76 "--prefix="*) PREFIX=${ARG#--prefix=} ;; |
|
77 "--exec-prefix="*) EPREFIX=${ARG#--exec-prefix=} ;; |
|
78 "--bindir="*) BINDIR=${ARG#----bindir=} ;; |
|
79 "--sbindir="*) SBINDIR=${ARG#--sbindir=} ;; |
|
80 "--libdir="*) LIBDIR=${ARG#--libdir=} ;; |
|
81 "--libexecdir="*) LIBEXECDIR=${ARG#--libexecdir=} ;; |
|
82 "--datadir="*) DATADIR=${ARG#--datadir=} ;; |
|
83 "--sysconfdir="*) SYSCONFDIR=${ARG#--sysconfdir=} ;; |
|
84 "--sharedstatedir="*) SHAREDSTATEDIR=${ARG#--sharedstatedir=} ;; |
|
85 "--localstatedir="*) LOCALSTATEDIR=${ARG#--localstatedir=} ;; |
|
86 "--includedir="*) INCLUDEDIR=${ARG#--includedir=} ;; |
|
87 "--infodir="*) INFODIR=${ARG#--infodir=} ;; |
|
88 "--mandir"*) MANDIR=${ARG#--mandir} ;; |
|
89 "--help"*) printhelp; abort_configure ;; |
|
90 "--debug") BUILD_TYPE="debug" ;; |
|
91 "--release") BUILD_TYPE="release" ;; |
|
92 "-"*) echo "unknown option: $ARG"; abort_configure ;; |
|
93 esac |
|
94 done |
|
95 |
|
96 |
|
97 # set dir variables |
|
98 : ${EPREFIX:="$PREFIX"} |
|
99 : ${BINDIR:="$EPREFIX/bin"} |
|
100 : ${SBINDIR:="$EPREFIX/sbin"} |
|
101 : ${LIBDIR:="$EPREFIX/lib"} |
|
102 : ${LIBEXECDIR:="$EPREFIX/libexec"} |
|
103 : ${DATADIR:="$PREFIX/share"} |
|
104 : ${SYSCONFDIR:="$PREFIX/etc"} |
|
105 : ${SHAREDSTATEDIR:="$PREFIX/com"} |
|
106 : ${LOCALSTATEDIR:="$PREFIX/var"} |
|
107 : ${INCLUDEDIR:="$PREFIX/include"} |
|
108 : ${INFODIR:="$PREFIX/info"} |
|
109 : ${MANDIR:="$PREFIX/man"} |
|
110 |
|
111 # Test for availability of pkg-config |
|
112 PKG_CONFIG=`command -v pkg-config` |
|
113 : ${PKG_CONFIG:="false"} |
|
114 |
|
115 # Simple uname based platform detection |
|
116 # $PLATFORM is used for platform dependent dependency selection |
|
117 OS=`uname -s` |
|
118 OS_VERSION=`uname -r` |
|
119 printf "detect platform... " |
|
120 if [ "$OS" = "SunOS" ]; then |
|
121 PLATFORM="solaris sunos unix svr4" |
|
122 fi |
|
123 if [ "$OS" = "Linux" ]; then |
|
124 PLATFORM="linux unix" |
|
125 fi |
|
126 if [ "$OS" = "FreeBSD" ]; then |
|
127 PLATFORM="freebsd bsd unix" |
|
128 fi |
|
129 if [ "$OS" = "Darwin" ]; then |
|
130 PLATFORM="macos osx bsd unix" |
|
131 fi |
|
132 if echo "$OS" | grep -i "MINGW" > /dev/null; then |
|
133 PLATFORM="windows mingw" |
|
134 fi |
|
135 : ${PLATFORM:="unix"} |
|
136 |
|
137 PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -` |
|
138 echo "$PLATFORM_NAME" |
|
139 |
|
140 isplatform() |
|
141 { |
|
142 for p in $PLATFORM |
|
143 do |
|
144 if [ "$p" = "$1" ]; then |
|
145 return 0 |
|
146 fi |
|
147 done |
|
148 return 1 |
|
149 } |
|
150 notisplatform() |
|
151 { |
|
152 for p in $PLATFORM |
|
153 do |
|
154 if [ "$p" = "$1" ]; then |
|
155 return 1 |
|
156 fi |
|
157 done |
|
158 return 0 |
|
159 } |
|
160 |
|
161 |
|
162 # generate vars.mk |
|
163 cat > "$TEMP_DIR/vars.mk" << __EOF__ |
|
164 PREFIX=$PREFIX |
|
165 EPREFIX=$EPREFIX |
|
166 BINDIR=$BINDIR |
|
167 SBINDIR=$SBINDIR |
|
168 LIBDIR=$LIBDIR |
|
169 LIBEXECDIR=$LIBEXECDIR |
|
170 DATADIR=$DATADIR |
|
171 SYSCONFDIR=$SYSCONFDIR |
|
172 SHAREDSTATEDIR=$SHAREDSTATEDIR |
|
173 LOCALSTATEDIR=$LOCALSTATEDIR |
|
174 INCLUDEDIR=$INCLUDEDIR |
|
175 INFODIR=$INFODIR |
|
176 MANDIR=$MANDIR |
|
177 __EOF__ |
|
178 sort -u -o "$TEMP_DIR/vars.mk" "$TEMP_DIR/vars.mk" |
|
179 |
|
180 |
|
181 # toolchain detection utilities |
|
182 . make/toolchain.sh |
|
183 |
|
184 # |
|
185 # DEPENDENCIES |
|
186 # |
|
187 |
|
188 # check languages |
|
189 lang_c= |
|
190 lang_cpp= |
|
191 if detect_c_compiler ; then |
|
192 lang_c=1 |
|
193 fi |
|
194 |
|
195 # create buffer for make variables required by dependencies |
|
196 echo > "$TEMP_DIR/make.mk" |
|
197 |
|
198 test_pkg_config() |
|
199 { |
|
200 if "$PKG_CONFIG" --exists "$1" ; then : |
|
201 else return 1 ; fi |
|
202 if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then : |
|
203 else return 1 ; fi |
|
204 if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then : |
|
205 else return 1 ; fi |
|
206 if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then : |
|
207 else return 1 ; fi |
|
208 return 0 |
|
209 } |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 # start collecting dependency information |
|
216 echo > "$TEMP_DIR/flags.mk" |
|
217 |
|
218 DEPENDENCIES_FAILED= |
|
219 ERROR=0 |
|
220 # unnamed dependencies |
|
221 TEMP_CFLAGS= |
|
222 TEMP_CXXFLAGS= |
|
223 TEMP_LDFLAGS= |
|
224 while true |
|
225 do |
|
226 while true |
|
227 do |
|
228 if [ -z "$lang_c" ] ; then |
|
229 ERROR=1 |
|
230 break |
|
231 fi |
|
232 |
|
233 break |
|
234 done |
|
235 break |
|
236 done |
|
237 |
|
238 # add general dependency flags to flags.mk |
|
239 echo "# general flags" >> "$TEMP_DIR/flags.mk" |
|
240 if [ -n "${TEMP_CFLAGS}" ]; then |
|
241 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" |
|
242 fi |
|
243 if [ -n "${TEMP_CXXFLAGS}" ]; then |
|
244 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" |
|
245 fi |
|
246 if [ -n "${TEMP_LDFLAGS}" ]; then |
|
247 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" |
|
248 fi |
|
249 |
|
250 # |
|
251 # OPTION VALUES |
|
252 # |
|
253 |
|
254 # |
|
255 # TARGETS |
|
256 # |
|
257 |
|
258 echo >> "$TEMP_DIR/flags.mk" |
|
259 # Target: default |
|
260 echo "# flags for target default" >> "$TEMP_DIR/flags.mk" |
|
261 TEMP_CFLAGS= |
|
262 TEMP_CXXFLAGS= |
|
263 TEMP_LDFLAGS= |
|
264 |
|
265 |
|
266 # Features |
|
267 |
|
268 |
|
269 if [ -n "${TEMP_CFLAGS}" ]; then |
|
270 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" |
|
271 fi |
|
272 if [ -n "${TEMP_CXXFLAGS}" ]; then |
|
273 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" |
|
274 fi |
|
275 if [ "$BUILD_TYPE" = "debug" ]; then |
|
276 echo 'CFLAGS += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" |
|
277 echo 'CXXFLAGS += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" |
|
278 fi |
|
279 if [ "$BUILD_TYPE" = "release" ]; then |
|
280 echo 'CFLAGS += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" |
|
281 echo 'CXXFLAGS += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" |
|
282 fi |
|
283 if [ -n "${TEMP_LDFLAGS}" ]; then |
|
284 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk" |
|
285 fi |
|
286 |
|
287 |
|
288 # final result |
|
289 if [ $ERROR -ne 0 ]; then |
|
290 echo |
|
291 echo "Error: Unresolved dependencies" |
|
292 echo "$DEPENDENCIES_FAILED" |
|
293 abort_configure |
|
294 fi |
|
295 |
|
296 echo "configure finished" |
|
297 echo |
|
298 echo "Build Config:" |
|
299 echo " PREFIX: $PREFIX" |
|
300 echo " TOOLCHAIN: $TOOLCHAIN_NAME" |
|
301 echo |
|
302 |
|
303 # generate the config.mk file |
|
304 cat > "$TEMP_DIR/config.mk" << __EOF__ |
|
305 # |
|
306 # config.mk generated by configure |
|
307 # |
|
308 |
|
309 __EOF__ |
|
310 write_toolchain_defaults "$TEMP_DIR/toolchain.mk" |
|
311 cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk |
|
312 rm -Rf "$TEMP_DIR" |
|
313 |
|
314 |