configure

changeset 71
0bdb910478cc
child 72
7e58e0f74e50
equal deleted inserted replaced
70:5427beba96d1 71:0bdb910478cc
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 BUILDDIR=`pwd`/build
33
34 # features
35
36 # clean abort
37 abort_configure()
38 {
39 rm -Rf "$TEMP_DIR"
40 exit 1
41 }
42
43 # help text
44 printhelp()
45 {
46 echo "Usage: $0 [OPTIONS]..."
47 cat << __EOF__
48 Installation directories:
49 --prefix=PREFIX path prefix for architecture-independent files
50 [/usr]
51 --exec-prefix=EPREFIX path prefix for architecture-dependent files
52 [PREFIX]
53
54 --bindir=DIR user executables [EPREFIX/bin]
55 --sbindir=DIR system admin executables [EPREFIX/sbin]
56 --libexecdir=DIR program executables [EPREFIX/libexec]
57 --sysconfdir=DIR system configuration files [PREFIX/etc]
58 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
59 --localstatedir=DIR modifiable single-machine data [PREFIX/var]
60 --libdir=DIR object code libraries [EPREFIX/lib]
61 --includedir=DIR C header files [PREFIX/include]
62 --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
63 --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
64 --infodir=DIR info documentation [DATAROOTDIR/info]
65 --mandir=DIR man documentation [DATAROOTDIR/man]
66
67 __EOF__
68 }
69
70 #
71 # parse arguments
72 #
73 BUILD_TYPE="default"
74 for ARG in "$@"
75 do
76 case "$ARG" in
77 "--prefix="*) PREFIX=${ARG#--prefix=} ;;
78 "--exec-prefix="*) EPREFIX=${ARG#--exec-prefix=} ;;
79 "--bindir="*) BINDIR=${ARG#----bindir=} ;;
80 "--sbindir="*) SBINDIR=${ARG#--sbindir=} ;;
81 "--libdir="*) LIBDIR=${ARG#--libdir=} ;;
82 "--libexecdir="*) LIBEXECDIR=${ARG#--libexecdir=} ;;
83 "--datadir="*) DATADIR=${ARG#--datadir=} ;;
84 "--sysconfdir="*) SYSCONFDIR=${ARG#--sysconfdir=} ;;
85 "--sharedstatedir="*) SHAREDSTATEDIR=${ARG#--sharedstatedir=} ;;
86 "--localstatedir="*) LOCALSTATEDIR=${ARG#--localstatedir=} ;;
87 "--includedir="*) INCLUDEDIR=${ARG#--includedir=} ;;
88 "--infodir="*) INFODIR=${ARG#--infodir=} ;;
89 "--mandir"*) MANDIR=${ARG#--mandir} ;;
90 "--help"*) printhelp; abort_configure ;;
91 "--debug") BUILD_TYPE="debug" ;;
92 "--release") BUILD_TYPE="release" ;;
93 "-"*) echo "unknown option: $ARG"; abort_configure ;;
94 esac
95 done
96
97
98 # set dir variables
99 : ${EPREFIX:="$PREFIX"}
100 : ${BINDIR:="$EPREFIX/bin"}
101 : ${SBINDIR:="$EPREFIX/sbin"}
102 : ${LIBDIR:="$EPREFIX/lib"}
103 : ${LIBEXECDIR:="$EPREFIX/libexec"}
104 : ${DATADIR:="$PREFIX/share"}
105 : ${SYSCONFDIR:="$PREFIX/etc"}
106 : ${SHAREDSTATEDIR:="$PREFIX/com"}
107 : ${LOCALSTATEDIR:="$PREFIX/var"}
108 : ${INCLUDEDIR:="$PREFIX/include"}
109 : ${INFODIR:="$PREFIX/info"}
110 : ${MANDIR:="$PREFIX/man"}
111
112 # Test for availability of pkg-config
113 PKG_CONFIG=`command -v pkg-config`
114 : ${PKG_CONFIG:="false"}
115
116 # Simple uname based platform detection
117 # $PLATFORM is used for platform dependent dependency selection
118 OS=`uname -s`
119 OS_VERSION=`uname -r`
120 printf "detect platform... "
121 if [ "$OS" = "SunOS" ]; then
122 PLATFORM="solaris sunos unix svr4"
123 fi
124 if [ "$OS" = "Linux" ]; then
125 PLATFORM="linux unix"
126 fi
127 if [ "$OS" = "FreeBSD" ]; then
128 PLATFORM="freebsd bsd unix"
129 fi
130 if [ "$OS" = "Darwin" ]; then
131 PLATFORM="macos osx bsd unix"
132 fi
133 if echo "$OS" | grep -i "MINGW" > /dev/null; then
134 PLATFORM="windows mingw"
135 fi
136 : ${PLATFORM:="unix"}
137
138 PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -`
139 echo "$PLATFORM_NAME"
140
141 isplatform()
142 {
143 for p in $PLATFORM
144 do
145 if [ "$p" = "$1" ]; then
146 return 0
147 fi
148 done
149 return 1
150 }
151 notisplatform()
152 {
153 for p in $PLATFORM
154 do
155 if [ "$p" = "$1" ]; then
156 return 1
157 fi
158 done
159 return 0
160 }
161
162
163 # generate vars.mk
164 cat > "$TEMP_DIR/vars.mk" << __EOF__
165 PREFIX=$PREFIX
166 EPREFIX=$EPREFIX
167 BINDIR=$BINDIR
168 SBINDIR=$SBINDIR
169 LIBDIR=$LIBDIR
170 LIBEXECDIR=$LIBEXECDIR
171 DATADIR=$DATADIR
172 SYSCONFDIR=$SYSCONFDIR
173 SHAREDSTATEDIR=$SHAREDSTATEDIR
174 LOCALSTATEDIR=$LOCALSTATEDIR
175 INCLUDEDIR=$INCLUDEDIR
176 INFODIR=$INFODIR
177 MANDIR=$MANDIR
178 BUILDDIR=$BUILDDIR
179 __EOF__
180 sort -u -o "$TEMP_DIR/vars.mk" "$TEMP_DIR/vars.mk"
181
182
183 # toolchain detection utilities
184 . make/toolchain.sh
185
186 #
187 # DEPENDENCIES
188 #
189
190 # check languages
191 lang_c=
192 lang_cpp=
193 if detect_c_compiler ; then
194 lang_c=1
195 fi
196
197 # create buffer for make variables required by dependencies
198 echo > "$TEMP_DIR/make.mk"
199
200 test_pkg_config()
201 {
202 if "$PKG_CONFIG" --exists "$1" ; then :
203 else return 1 ; fi
204 if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then :
205 else return 1 ; fi
206 if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then :
207 else return 1 ; fi
208 if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then :
209 else return 1 ; fi
210 return 0
211 }
212
213 dependency_error_archiver()
214 {
215 printf "checking for archiver... "
216 # dependency archiver
217 while true
218 do
219 if command -v ar > /dev/null ; then
220 :
221 else
222 break
223 fi
224 cat >> $TEMP_DIR/make.mk << __EOF__
225 # Dependency: archiver
226 AR = ar
227 ARFLAGS = -r
228
229 __EOF__
230 echo yes
231 return 1
232 done
233
234 echo no
235 return 0
236 }
237 dependency_error_rmdir()
238 {
239 printf "checking for rmdir... "
240 # dependency rmdir
241 while true
242 do
243 if command -v rm > /dev/null ; then
244 :
245 else
246 break
247 fi
248 cat >> $TEMP_DIR/make.mk << __EOF__
249 # Dependency: rmdir
250 RM = rm
251 RMFLAGS = -f -R
252
253 __EOF__
254 echo yes
255 return 1
256 done
257
258 echo no
259 return 0
260 }
261 dependency_error_ncurses()
262 {
263 printf "checking for ncurses... "
264 # dependency ncurses
265 while true
266 do
267 if [ -z "$PKG_CONFIG" ]; then
268 break
269 fi
270 if test_pkg_config "ncursesw" "" "" "" ; then
271 TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags ncursesw`"
272 TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs ncursesw`"
273 else
274 break
275 fi
276 echo yes
277 return 1
278 done
279
280 echo no
281 return 0
282 }
283 dependency_error_mkdir()
284 {
285 printf "checking for mkdir... "
286 # dependency mkdir
287 while true
288 do
289 if command -v mkdir > /dev/null ; then
290 :
291 else
292 break
293 fi
294 cat >> $TEMP_DIR/make.mk << __EOF__
295 # Dependency: mkdir
296 MKDIR = mkdir
297 MKDIRFLAGS = -p
298
299 __EOF__
300 echo yes
301 return 1
302 done
303
304 echo no
305 return 0
306 }
307
308
309
310
311 # start collecting dependency information
312 echo > "$TEMP_DIR/flags.mk"
313
314 DEPENDENCIES_FAILED=
315 ERROR=0
316 # unnamed dependencies
317 TEMP_CFLAGS=
318 TEMP_CXXFLAGS=
319 TEMP_LDFLAGS=
320 while true
321 do
322 while true
323 do
324 if [ -z "$lang_c" ] ; then
325 ERROR=1
326 break
327 fi
328
329 cat >> "$TEMP_DIR/make.mk" << __EOF__
330 LIB_EXT = .a
331 OBJ_EXT = .o
332
333 __EOF__
334 break
335 done
336 break
337 done
338
339 # add general dependency flags to flags.mk
340 echo "# general flags" >> "$TEMP_DIR/flags.mk"
341 if [ -n "${TEMP_CFLAGS}" ]; then
342 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
343 fi
344 if [ -n "${TEMP_CXXFLAGS}" ]; then
345 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
346 fi
347 if [ -n "${TEMP_LDFLAGS}" ]; then
348 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
349 fi
350
351 #
352 # OPTION VALUES
353 #
354
355 #
356 # TARGETS
357 #
358
359 echo >> "$TEMP_DIR/flags.mk"
360 # Target: default
361 echo "# flags for target default" >> "$TEMP_DIR/flags.mk"
362 TEMP_CFLAGS=
363 TEMP_CXXFLAGS=
364 TEMP_LDFLAGS=
365
366 if dependency_error_archiver; then
367 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED archiver "
368 ERROR=1
369 fi
370 if dependency_error_rmdir; then
371 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED rmdir "
372 ERROR=1
373 fi
374 if dependency_error_ncurses; then
375 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ncurses "
376 ERROR=1
377 fi
378 if dependency_error_mkdir; then
379 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED mkdir "
380 ERROR=1
381 fi
382
383 # Features
384
385
386 if [ -n "${TEMP_CFLAGS}" ]; then
387 echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
388 fi
389 if [ -n "${TEMP_CXXFLAGS}" ]; then
390 echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
391 fi
392 if [ "$BUILD_TYPE" = "debug" ]; then
393 echo 'CFLAGS += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk"
394 echo 'CXXFLAGS += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk"
395 fi
396 if [ "$BUILD_TYPE" = "release" ]; then
397 echo 'CFLAGS += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk"
398 echo 'CXXFLAGS += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk"
399 fi
400 if [ -n "${TEMP_LDFLAGS}" ]; then
401 echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
402 fi
403
404
405 # final result
406 if [ $ERROR -ne 0 ]; then
407 echo
408 echo "Error: Unresolved dependencies"
409 echo "$DEPENDENCIES_FAILED"
410 abort_configure
411 fi
412
413 echo "configure finished"
414 echo
415 echo "Build Config:"
416 echo " PREFIX: $PREFIX"
417 echo " TOOLCHAIN: $TOOLCHAIN_NAME"
418 echo
419
420 # generate the config.mk file
421 cat > "$TEMP_DIR/config.mk" << __EOF__
422 #
423 # config.mk generated by configure
424 #
425
426 __EOF__
427 write_toolchain_defaults "$TEMP_DIR/toolchain.mk"
428 cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk
429 rm -Rf "$TEMP_DIR"
430
431

mercurial