1 #!/bin/sh
2
3 #foreach( $var in $vars )
4 #if( $var.exec )
5 ${var.name}=`${var.value}`
6 #else
7 ${var.name}=${var.value}
8 #end
9 #end
10
11 #if ( ! $project.hasVar("PREFIX") )
12 PREFIX=/usr
13 #end
14 #if ( ! $project.hasVar("EPREFIX") )
15 EPREFIX=$PREFIX
16 #end
17
18 #if ( ! $project.hasVar("BINDIR") )
19 BINDIR=
20 #end
21 #if ( ! $project.hasVar("SBINDIR") )
22 SBINDIR=
23 #end
24 #if ( ! $project.hasVar("LIBDIR") )
25 LIBDIR=
26 #end
27 #if ( ! $project.hasVar("LIBEXECDIR") )
28 LIBEXECDIR=
29 #end
30 #if ( ! $project.hasVar("DATADIR") )
31 DATADIR=
32 #end
33 #if ( ! $project.hasVar("SYSCONFDIR") )
34 SYSCONFDIR=
35 #end
36 #if ( ! $project.hasVar("SHAREDSTATEDIR") )
37 SHAREDSTATEDIR=
38 #end
39 #if ( ! $project.hasVar("LOCALSTATEDIR") )
40 LOCALSTATEDIR=
41 #end
42 #if ( ! $project.hasVar("INCLUDEDIR") )
43 INCLUDEDIR=
44 #end
45 #if ( ! $project.hasVar("INFODIR") )
46 INFODIR=
47 #end
48 #if ( ! $project.hasVar("MANDIR") )
49 MANDIR=
50 #end
51
52 OS=`uname -s`
53 OS_VERSION=`uname -r`
54
55 TEMP_DIR=".tmp-`uname -n`"
56 mkdir -p $TEMP_DIR
57 if [ $? -ne 0 ]; then
58 echo "Cannot create tmp dir"
59 echo "Abort"
60 fi
61 touch $TEMP_DIR/options
62 touch $TEMP_DIR/features
63
64 # features
65 #foreach( $feature in $features )
66 #if( ${feature.isDefault()} )
67 ${feature.getVarName()}=on
68 #end
69 #end
70
71 # help text
72 printhelp()
73 {
74 echo "Usage: $0 [OPTIONS]..."
75 cat << __EOF__
76 Installation directories:
77 --prefix=PREFIX path prefix for architecture-independent files
78 [/usr]
79 --exec-prefix=EPREFIX path prefix for architecture-dependent files
80 [PREFIX]
81
82 --bindir=DIR user executables [EPREFIX/bin]
83 --sbindir=DIR system admin executables [EPREFIX/sbin]
84 --libexecdir=DIR program executables [EPREFIX/libexec]
85 --sysconfdir=DIR system configuration files [PREFIX/etc]
86 --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
87 --localstatedir=DIR modifiable single-machine data [PREFIX/var]
88 --libdir=DIR object code libraries [EPREFIX/lib]
89 --includedir=DIR C header files [PREFIX/include]
90 --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
91 --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
92 --infodir=DIR info documentation [DATAROOTDIR/info]
93 --mandir=DIR man documentation [DATAROOTDIR/man]
94
95 #if( $options.size() > 0 )
96 Options:
97 #foreach( $opt in $options )
98 --${opt.getArgument()}=${opt.getValuesString()}
99 #end
100
101 #end
102 #if( $features.size() > 0 )
103 Optional Features:
104 #foreach( $feature in $features )
105 #if( $feature.default )
106 --disable-${feature.arg}
107 #else
108 --enable-${feature.arg}
109 #end
110 #end
111
112 #end
113 __EOF__
114 }
115
116 #
117 # parse arguments
118 #
119 #set( $D = '$' )
120 for ARG in $@
121 do
122 if [[ $ARG == --prefix=* ]]; then
123 PREFIX=${D}{ARG:9}
124 elif [[ $ARG = --exec-prefix=* ]]; then
125 EPREFIX=${D}{ARG:14}
126 elif [[ $ARG = --bindir=* ]]; then
127 BINDIR=${D}{ARG:9}
128 elif [[ $ARG = --sbindir=* ]]; then
129 SBINDIR=${D}{ARG:10}
130 elif [[ $ARG = --libdir=* ]]; then
131 LIBDIR=${D}{ARG:9}
132 elif [[ $ARG = --libexecdir=* ]]; then
133 LIBEXECDIR=${D}{ARG:13}
134 elif [[ $ARG = --datadir=* ]]; then
135 DATADIR=${D}{ARG:10}
136 elif [[ $ARG = --sysconfdir=* ]]; then
137 SYSCONFDIR=${D}{ARG:13}
138 elif [[ $ARG = --sharedstatedir=* ]]; then
139 SHAREDSTATEDIR=${D}{ARG:17}
140 elif [[ $ARG = --localstatedir=* ]]; then
141 LOCALSTATEDIR=${D}{ARG:16}
142 elif [[ $ARG = --includedir=* ]]; then
143 INCLUDEDIR=${D}{ARG:12}
144 elif [[ $ARG = --infodir=* ]]; then
145 INFODIR=${D}{ARG:10}
146 elif [[ $ARG = --mandir=* ]]; then
147 MANDIR=${D}{ARG:9}
148 elif [ $ARG = "--help" ]; then
149 printhelp
150 exit 0
151 #foreach( $opt in $options )
152 elif [[ $ARG == --${opt.getArgument()}=* ]]; then
153 ${opt.getVarName()}=${opt.getArgValue()}
154 #end
155 #foreach( $feature in $features )
156 elif [[ $ARG == --enable-${feature.arg} ]]; then
157 ${feature.getVarName()}=on
158 elif [[ $ARG == --disable-${feature.arg} ]]; then
159 unset ${feature.getVarName()}
160 #end
161 fi
162 done
163
164 # set dir variables
165 if [ -z "$BINDIR" ]; then
166 BINDIR=$EPREFIX/bin
167 fi
168 if [ -z "$SBINDIR" ]; then
169 SBINDIR=$EPREFIX/sbin
170 fi
171 if [ -z "$LIBDIR" ]; then
172 LIBDIR=$EPREFIX/lib
173 fi
174 if [ -z "$LIBEXEC" ]; then
175 LIBEXECDIR=$EPREFIX/libexec
176 fi
177 if [ -z "$DATADIR" ]; then
178 DATADIR=$PREFIX/share
179 fi
180 if [ -z "$SYSCONFDIR" ]; then
181 SYSCONFDIR=$PREFIX/etc
182 fi
183 if [ -z "$SHAREDSTATEDIR" ]; then
184 SHAREDSTATEDIR=$PREFIX/com
185 fi
186 if [ -z "$LOCALSTATEDIR" ]; then
187 LOCALSTATEDIR=$PREFIX/var
188 fi
189 if [ -z "$INCLUDEDIR" ]; then
190 INCLUDEDIR=$PREFIX/include
191 fi
192 if [ -z "$INFODIR" ]; then
193 INFODIR=$PREFIX/info
194 fi
195 if [ -z "$MANDIR" ]; then
196 MANDIR=$PREFIX/man
197 fi
198
199 which pkg-config > /dev/null
200 if [ $? -eq 0 ]; then
201 PKG_CONFIG=pkg-config
202 else
203 PKG_CONFIG=false
204 fi
205
206 # Simple uname based platform detection
207 # $PLATFORM is used for platform dependent dependency selection
208 printf "detect platform... "
209 if [ $OS = SunOS ]; then
210 PLATFORM="solaris sunos unix svr4"
211 fi
212 if [ $OS = Linux ]; then
213 PLATFORM="linux unix"
214 fi
215 if [ $OS = FreeBSD ]; then
216 PLATFORM="freebsd bsd unix"
217 fi
218 if [ $OS = Darwin ]; then
219 PLATFORM="macos osx bsd unix"
220 fi
221 echo $OS | grep "MINGW" > /dev/null
222 if [ $? -eq 0 ]; then
223 PLATFORM="windows mingw"
224 fi
225
226 if [ -z "$PLATFORM" ]; then
227 PLATFORM="unix"
228 fi
229
230 for p in $PLATFORM
231 do
232 PLATFORM_NAME=$p
233 break
234 done
235 echo $PLATFORM_NAME
236
237 isplatform()
238 {
239 for p in $PLATFORM
240 do
241 if [ $p = $1 ]; then
242 return 0
243 fi
244 done
245 return 1
246 }
247 isnotplatform()
248 {
249 for p in $PLATFORM
250 do
251 if [ $p = $1 ]; then
252 return 1
253 fi
254 done
255 return 0
256 }
257
258 # generate config.mk and config.h
259 cat > $TEMP_DIR/config.mk << __EOF__
260 #
261 # config.mk generated by configure
262 #
263
264 # general vars
265 #foreach( $var in $vars )
266 ${var.name}=$${var.name}
267 #end
268
269 #if ( ! $project.hasVar("PREFIX") )
270 PREFIX=$PREFIX
271 #end
272 #if ( ! $project.hasVar("EPREFIX") )
273 EPREFIX=$EPREFIX
274 #end
275
276 #if ( ! $project.hasVar("BINDIR") )
277 BINDIR=$BINDIR
278 #end
279 #if ( ! $project.hasVar("SBINDIR") )
280 SBINDIR=$SBINDIR
281 #end
282 #if ( ! $project.hasVar("LIBDIR") )
283 LIBDIR=$LIBDIR
284 #end
285 #if ( ! $project.hasVar("LIBEXECDIR") )
286 LIBEXECDIR=$LIBEXECDIR
287 #end
288 #if ( ! $project.hasVar("DATADIR") )
289 DATADIR=$DATADIR
290 #end
291 #if ( ! $project.hasVar("SYSCONFDIR") )
292 SYSCONFDIR=$SYSCONFDIR
293 #end
294 #if ( ! $project.hasVar("SHAREDSTATEDIR") )
295 SHAREDSTATEDIR=$SHAREDSTATEDIR
296 #end
297 #if ( ! $project.hasVar("LOCALSTATEDIR") )
298 LOCALSTATEDIR=$LOCALSTATEDIR
299 #end
300 #if ( ! $project.hasVar("INCLUDEDIR") )
301 INCLUDEDIR=$INCLUDEDIR
302 #end
303 #if ( ! $project.hasVar("INFODIR") )
304 INFODIR=$INFODIR
305 #end
306 #if ( ! $project.hasVar("MANDIR") )
307 MANDIR=$MANDIR
308 #end
309
310 __EOF__
311
312 echo > $TEMP_DIR/make.mk
313
314 ENV_CFLAGS=$CFLAGS
315 ENV_LDFLAGS=$LDFLAGS
316 ENV_CXXFLAGS=$CXXFLAGS
317
318 # Toolchain detection
319 # this will insert make vars to config.mk
320 . make/toolchain.sh
321
322 # add user specified flags to config.mk
323 echo >> $TEMP_DIR/config.mk
324 if [ ! -z "${ENV_CFLAGS}" ]; then
325 echo "CFLAGS += $ENV_CFLAGS" >> $TEMP_DIR/config.mk
326 fi
327 if [ ! -z "${ENV_CXXFLAGS}" ]; then
328 echo "CXXFLAGS += $ENV_CXXFLAGS" >> $TEMP_DIR/config.mk
329 fi
330 if [ ! -z "${ENV_LDFLAGS}" ]; then
331 echo "LDFLAGS += $ENV_LDFLAGS" >> $TEMP_DIR/config.mk
332 fi
333
334 #
335 # DEPENDENCIES
336 #
337
338 #foreach( $dependency in $namedDependencies )
339 dependency_${dependency.name}()
340 {
341 printf "checking for ${dependency.name}... "
342 #foreach( $sub in $dependency.getSubdependencies() )
343 # dependency $sub.name $sub.getPlatformString()
344 while true
345 do
346 #if( $sub.platform )
347 if isnotplatform "${sub.platform}"; then
348 break
349 fi
350 #end
351 #foreach( $not in $sub.getNotList() )
352 if isplatform "${not}"; then
353 break
354 fi
355 #end
356 #if( $sub.pkgconfig.size() > 0 )
357 if [ -z "$PKG_CONFIG" ]; then
358 break
359 fi
360 #end
361 #foreach( $pkg in $sub.pkgconfig )
362 $PKG_CONFIG $pkg.getPkgConfigParam()
363 if [ $? -ne 0 ] ; then
364 break
365 fi
366 CFLAGS="$CFLAGS `$PKG_CONFIG --cflags $pkg.getPkgConfigParam()`"
367 LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs $pkg.getPkgConfigParam()`"
368 #end
369 #foreach( $flags in $sub.flags )
370 #if( $flags.exec )
371 $flags.value > /dev/null
372 if [ $? -eq 0 ]; then
373 $flags.varName="$$flags.varName `$flags.value`"
374 else
375 break
376 fi
377 #else
378 $flags.varName="$$flags.varName $flags.value"
379 #end
380 #end
381 #foreach( $test in $sub.tests )
382 $test > /dev/null
383 if [ $? -ne 0 ]; then
384 break
385 fi
386 #end
387 #if ( $sub.make.length() > 0 )
388 cat >> $TEMP_DIR/make.mk << __EOF__
389 # Dependency: $dependency.name
390 $sub.make
391 __EOF__
392 #end
393 echo yes
394 return 0
395 done
396
397 #end
398 echo no
399 return 1
400 }
401 #end
402
403 DEPENDENCIES_FAILED=
404 ERROR=0
405 #if( $dependencies.size() > 0 )
406 # general dependencies
407 CFLAGS=
408 LDFLAGS=
409 #foreach( $dependency in $dependencies )
410 while true
411 do
412 #if( $dependency.platform )
413 if isnotplatform "${dependency.platform}"; then
414 break
415 fi
416 #end
417 #foreach( $not in $dependency.getNotList() )
418 if isplatform "${not}"; then
419 break
420 fi
421 #end
422 while true
423 do
424 #if( $dependency.pkgconfig.size() > 0 )
425 if [ -z "$PKG_CONFIG" ]; then
426 ERROR=1
427 break
428 fi
429 #end
430 #foreach( $pkg in $dependency.pkgconfig )
431 printf "checking for pkg-config package $pkg.getPkgConfigParam()... "
432 $PKG_CONFIG $pkg.getPkgConfigParam()
433 if [ $? -ne 0 ]; then
434 echo no
435 ERROR=1
436 break
437 fi
438 echo yes
439 CFLAGS="$CFLAGS `$PKG_CONFIG --cflags $pkg.getPkgConfigParam()`"
440 LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs $pkg.getPkgConfigParam()`"
441 #end
442
443 #foreach( $flags in $dependency.flags )
444 #if( $flags.exec )
445 $flags.value > /dev/null
446 if [ $? -ne 0 ]; then
447 $flags.varName="$$flags.varName `$flags.value`"
448 else
449 ERROR=1
450 break
451 fi
452 #else
453 $flags.varName="$$flags.varName $flags.value"
454 #end
455 #end
456 #if ( $dependency.make.length() > 0 )
457 cat >> $TEMP_DIR/make.mk << __EOF__
458 $dependency.make
459 __EOF__
460 #end
461
462 break
463 done
464
465 break
466 done
467 #end
468
469 # add general dependency flags to config.mk
470 echo >> $TEMP_DIR/config.mk
471 if [ ! -z "${CFLAGS}" ]; then
472 echo "CFLAGS += $CFLAGS" >> $TEMP_DIR/config.mk
473 fi
474 if [ ! -z "${CXXFLAGS}" ]; then
475 echo "CXXFLAGS += $CXXFLAGS" >> $TEMP_DIR/config.mk
476 fi
477 if [ ! -z "${LDFLAGS}" ]; then
478 echo "LDFLAGS += $LDFLAGS" >> $TEMP_DIR/config.mk
479 fi
480 #end
481
482 #
483 # OPTION VALUES
484 #
485 #foreach( $opt in $options )
486 #foreach( $val in $opt.values )
487 ${val.func}()
488 {
489 VERR=0
490 #foreach( $dep in $val.dependencies )
491 dependency_$dep
492 if [ $? -ne 0 ]; then
493 VERR=1
494 fi
495 #end
496 if [ $VERR -ne 0 ]; then
497 return 1
498 fi
499 #foreach( $def in $val.defines )
500 CFLAGS="$CFLAGS ${def.toFlags()}"
501 #end
502 #if( $val.hasMake() )
503 cat >> $TEMP_DIR/make.mk << __EOF__
504 $val.make
505 __EOF__
506 #end
507 return 0
508 }
509 #end
510 #end
511
512 #
513 # TARGETS
514 #
515 CFLAGS=
516 CXXFLAGS=
517 LDFLAGS=
518
519 #foreach( $target in $targets )
520 #if ( $target.name )
521 # Target: $target.name
522 #else
523 # Target
524 #end
525 CFLAGS=
526 LDFLAGS=
527 CXXFLAGS=
528
529 #foreach( $dependency in $target.dependencies )
530 dependency_$dependency
531 if [ $? -ne 0 ]; then
532 DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ${dependency} "
533 ERROR=1
534 fi
535 #end
536
537 #foreach( $opt in $target.options )
538 # Option: --${opt.argument}
539 if [ -z ${D}${opt.getVarName()} ]; then
540 SAVED_ERROR=$ERROR
541 SAVED_DEPENDENCIES_FAILED=$DEPENDENCIES_FAILED
542 ERROR=0
543 while true
544 do
545 #foreach( $optdef in $opt.defaults )
546 #if( $optdef.platform )
547 if isplatform "$optdef.platform"; then
548 #end
549 $optdef.func
550 if [ $? -eq 0 ]; then
551 echo " ${opt.argument}: ${optdef.valueName}" >> $TEMP_DIR/options
552 ERROR=0
553 break
554 fi
555 #if( $optdef.platform )
556 fi
557 #end
558 #end
559 break
560 done
561 if [ $ERROR -ne 0 ]; then
562 SAVED_ERROR=1
563 fi
564 ERROR=$SAVED_ERROR
565 DEPENDENCIES_FAILED=$SAVED_DEPENDENCIES_FAILED=
566 else
567 if false; then
568 false
569 #foreach( $optval in $opt.values )
570 elif [ ${D}${opt.getVarName()} = "${optval.value}" ]; then
571 echo " ${opt.argument}: ${D}${opt.getVarName()}" >> $TEMP_DIR/options
572 $optval.func
573 if [ $? -ne 0 ]; then
574 ERROR=1
575 fi
576 #end
577 fi
578 fi
579 #end
580
581 echo >> $TEMP_DIR/config.mk
582 if [ ! -z "${CFLAGS}" ]; then
583 echo "${target.getCFlags()} += $CFLAGS" >> $TEMP_DIR/config.mk
584 fi
585 if [ ! -z "${CXXFLAGS}" ]; then
586 echo "${target.getCXXFlags()} += $CXXFLAGS" >> $TEMP_DIR/config.mk
587 fi
588 if [ ! -z "${LDFLAGS}" ]; then
589 echo "${target.getLDFlags()} += $LDFLAGS" >> $TEMP_DIR/config.mk
590 fi
591
592 #end
593 if [ $ERROR -ne 0 ]; then
594 echo
595 echo "Error: Unresolved dependencies"
596 echo $DEPENCIES_FAILED
597 rm -Rf $TEMP_DIR
598 exit 1
599 fi
600
601 echo "configure finished"
602 echo
603 echo "Build Config:"
604 echo " PREFIX: $PREFIX"
605 echo " TOOLCHAIN: $TOOLCHAIN_NAME"
606 #if ( $options.size() > 0 )
607 echo "Options:"
608 cat $TEMP_DIR/options
609 #end
610 echo
611 cat $TEMP_DIR/config.mk $TEMP_DIR/make.mk > config.mk
612 rm -Rf $TEMP_DIR
613
614
615