]> err.no Git - sope/blob - configure
fixed a configure bug in combination with GS deployment roots
[sope] / configure
1 #!/bin/bash
2
3 #
4 # Note: When adding make options to this script, ensure that the source still
5 #       compiles without those options! (and just with GNUstep.sh being
6 #       sourced)
7 #       We do not want to force people to run configure.
8 #
9
10 # ******************** variables ****************
11
12 CFG_ARGS="$0 $1 $2 $3 $4 $5 $6 $7 $8 $9"
13
14 ARG_BEQUIET=0
15 ARG_NOCREATE=0
16 ARG_PREFIX=""
17 ARG_FRAMEWORK_DIR=""
18 ARG_GSMAKE="$GNUSTEP_MAKEFILES"
19 ARG_CFGMAKE="$PWD/config.make"
20 ARG_WITH_GNUSTEP=0
21 ARG_WITH_DEBUG=1
22 ARG_WITH_STRIP=1
23
24 DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
25 DARG_IS_FHS=1
26
27 SOPE_SRCDIR="$PWD" # TODO: rather use location of configure (using basename)
28 NGSTREAMS_DIR="${SOPE_SRCDIR}/sope-core/NGStreams"
29 GSTEPMAKE_SRCDIR="${SOPE_SRCDIR}/gnustep-make"
30 INTERNAL_MAKEDIR="${SOPE_SRCDIR}/.gsmake"
31 USES_INTERNAL_MAKE=no
32
33 # TODO: add pg_config, mysql_config etc!
34 LINK_SYSLIBDIRS="-L/usr/local/pgsql/lib -L/usr/local/lib -L/usr/lib"
35
36 # ******************** usage ********************
37
38 function usage() {
39   cat <<_ACEOF
40 \`configure' configures a GNUstep-make based sourcetree for installation.
41
42 Usage: $0 [OPTION]...
43
44 Note: You do not need to configure this source tree, as another option
45       just ensure that the GNUstep.sh of your GNUstep make installation
46       is properly sourced prior running make.
47
48 Configuration:
49   -h, --help              display this help and exit
50   -q, --quiet, --silent   do not print \`checking...' messages
51   -n, --no-create         do not create output files
52
53 Installation directories:
54   --prefix=PREFIX         install files in PREFIX [/usr/local]
55   --frameworks=DIR        build frameworks and install in DIR
56   --gsmake=PATH           path to gnustep-make tree
57   --configmake=PATH       path to the config file being created
58   --with-gnustep          install in GNUstep tree
59   --enable-debug          turn on debugging and compile time warnings
60   --enable-strip          turn on stripping of debug symbols
61
62 _ACEOF
63
64   exit 0;
65 }
66
67 # ******************** running ********************
68
69 function printParas() {
70   echo "Configuration:"
71   if test $ARG_BEQUIET  = 1; then echo "  will be quite.";  fi
72   if test $ARG_NOCREATE = 1; then echo "  won't create files"; fi
73   if test "x$ARG_FRAMEWORK_DIR" != "x"; then
74     echo "  FHS:    install in frameworks directory"; 
75   elif test $DARG_IS_FHS = 1;  then
76     echo "  FHS:    install in FHS root"; 
77   else
78     echo "  FHS:    install in GNUstep tree"; 
79   fi
80
81   if test $ARG_WITH_DEBUG = 1; then 
82     echo "  debug:  yes";
83   else
84     echo "  debug:  no";
85   fi
86   if test $ARG_WITH_STRIP = 1; then 
87     echo "  strip:  yes";
88   else
89     echo "  strip:  no";
90   fi
91   
92   echo "  prefix:     $ARG_PREFIX"
93   echo "  frameworks: $ARG_FRAMEWORK_DIR"
94   echo "  gstep:      $ARG_GSMAKE"
95   echo "  config:     $ARG_CFGMAKE"
96   echo "  script:     $DARG_GNUSTEP_SH"
97   echo ""
98 }
99
100 function warnOnFHSPrefix() {
101   cat <<_ACEOFWARN
102 Warning: you are configuring for a non standard FHS style prefix.
103          prefix: $ARG_PREFIX
104
105 Some code in SOPE only looks in /usr and /usr/local for resources and is
106 therefore incompatible with arbitary install pathes.
107
108 If you want to have the flexibility of installation in arbitary pathes just
109 configure GNUstep-make and source the GNUstep.sh script prior executing tools
110 to ensure a proper environment.
111 All SOPE based code is completely relocatable when being used in a GNUstep
112 environment.
113
114 _ACEOFWARN
115 }
116
117 function setupInternalGSMake() {
118   if test -f ${INTERNAL_MAKEDIR}/Library/Makefiles/GNUstep.sh; then
119     ARG_GSMAKE="${INTERNAL_MAKEDIR}/Library/Makefiles/"
120     ARG_IS_FHS=1
121     DARG_IS_FHS=1
122     ARG_WITH_GNUSTEP=0
123     USES_INTERNAL_MAKE=yes
124     if test "x$ARG_PREFIX" = "x"; then
125       ARG_PREFIX="/usr/local/"
126     fi
127   elif test -d gnustep-make; then
128     ENABLE_PCH_OPT=""
129     SETUP_COMBO="gnu-fd-nil"
130     SETUP_LOGNAME="config-gstepmake.log"
131     if test -d /Developer/Applications/Xcode.app; then
132       # rather weird OSX test, right? ;->
133       SETUP_COMBO="apple-apple-nil"
134       ENABLE_PCH_OPT="--enable-pch"
135     fi
136     pregsmdir="$PWD"
137     
138     echo -n "configuring builtin gnustep-make environment (${SETUP_LOGNAME}) .."
139     
140     cd "$GSTEPMAKE_SRCDIR"
141     ./configure >${pregsmdir}/${SETUP_LOGNAME} \
142       ${ENABLE_PCH_OPT} \
143       --prefix="${INTERNAL_MAKEDIR}" \
144       --without-system-root \
145       --with-network-root="${INTERNAL_MAKEDIR}" \
146       --with-local-root="${INTERNAL_MAKEDIR}" \
147       --with-user-root="${INTERNAL_MAKEDIR}" \
148       --with-library-combo="${SETUP_COMBO}"
149
150     echo -n ".. install .."
151     make install >>${pregsmdir}/${SETUP_LOGNAME}
152     
153     ARG_GSMAKE="${INTERNAL_MAKEDIR}/Library/Makefiles/"
154     ARG_IS_FHS=1
155     DARG_IS_FHS=1
156     ARG_WITH_GNUSTEP=0
157     USES_INTERNAL_MAKE=yes
158     if test "x$ARG_PREFIX" = "x"; then
159       ARG_PREFIX="/usr/local/"
160     fi
161     
162     cd "$pregsmdir"
163     if test -f $ARG_GSMAKE/GNUstep.sh; then
164       echo ".. done (log in ${SETUP_LOGNAME})."
165     else
166       echo "error: failed to setup embedded gnustep-make sources!"
167       cat ${pregsmdir}/${SETUP_LOGNAME}
168       exit 1
169     fi
170   else
171     echo "error: did not find embedded gnustep-make sources!"
172     exit 1
173   fi
174 }
175
176 function validateGNUstepArgs() {
177   # GNUstep make
178   if test "x$ARG_GSMAKE" = "x"; then
179     if test -f $HOME/OGoRoot/Library/Makefiles/GNUstep.sh; then
180       ARG_GSMAKE="$HOME/OGoRoot/Library/Makefiles/"
181     elif test -f $HOME/GNUstep/Library/Makefiles/GNUstep.sh; then
182       ARG_GSMAKE="$HOME/GNUstep/Library/Makefiles/"
183     elif test -f /usr/GNUstep/System/Library/Makefiles/GNUstep.sh; then
184       ARG_GSMAKE="/usr/GNUstep/System/Library/Makefiles/"
185     else
186       setupInternalGSMake;
187     fi
188     DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
189   elif test -d $ARG_GSMAKE; then
190     if test -f $ARG_GSMAKE/GNUstep.sh; then
191       DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
192     elif test -f $ARG_GSMAKE/Library/Makefiles/GNUstep.sh; then
193       ARG_GSMAKE="$ARG_GSMAKE/Library/Makefiles"
194       DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
195     else
196       echo "error: specified directory contains no GNUstep.sh: $ARG_GSMAKE"
197       exit 1
198     fi
199   else
200     echo "error: specified GNUstep make tree does not exist: $ARG_GSMAKE"
201     exit 1
202   fi
203 }
204
205 function setupAppleArgs() {
206   ARG_WITH_STRIP=0
207   if test "x${USES_INTERNAL_MAKE}" = "no"; then
208     ARG_WITH_GNUSTEP=1
209   fi
210   
211   # no reason to print a warning?
212   #if test "x${xLIBRARY_COMBO}" != "xapple-apple-nil"; then
213   #  if test "x${LIBRARY_COMBO}" != "xapple-apple-apple"; then
214   #    echo "WARNING: detected MacOSX GNUstep setup: ${LIBRARY_COMBO}"
215   #    echo ""
216   #  fi
217   #fi
218 }
219
220 function validateArgs() {
221   # validate prefix (could be better?)
222   case "x$ARG_PREFIX" in
223     "x/usr/local"|"x/usr/local/")
224         DARG_IS_FHS=1;
225         ;;
226     "x/usr"|"x/usr/")
227         DARG_IS_FHS=1;
228         ;;
229     "x$GNUSTEP_USER_ROOT"|"x$GNUSTEP_LOCAL_ROOT"|"x$GNUSTEP_SYSTEM_ROOT")
230         DARG_IS_FHS=0;
231         ARG_WITH_GNUSTEP=1;
232         ;;
233     "x")
234         if test $ARG_WITH_GNUSTEP = 1; then
235           DARG_IS_FHS=0;
236           ARG_PREFIX="$GNUSTEP_LOCAL_ROOT"
237           if test $ARG_BEQUIET != 1; then
238             echo "Note: will install in GNUSTEP_LOCAL_ROOT: $ARG_PREFIX"
239             echo ""
240           fi
241         elif test "x$ARG_FRAMEWORK_DIR" != "x"; then
242           DARG_IS_FHS=0;
243           ARG_PREFIX="$ARG_FRAMEWORK_DIR"
244           echo "Note: will install in frameworks location: $ARG_PREFIX"
245           echo ""
246         else
247           DARG_IS_FHS=1;
248           ARG_PREFIX="/usr/local/"
249           echo "Note: will install in default location: $ARG_PREFIX"
250           echo ""
251         fi
252         ;;
253     *)
254         if test $ARG_WITH_GNUSTEP = 1; then
255           echo "error: specified --with-gnustep, but specified prefix is not"
256           echo "       a GNUstep root: '$ARG_PREFIX'"
257           exit 1
258         else
259           if test $ARG_BEQUIET != 1; then
260             warnOnFHSPrefix;
261           fi
262           DARG_IS_FHS=1;
263         fi
264         ;;
265   esac
266   
267   if test $ARG_WITH_GNUSTEP = 1; then
268     if test $DARG_IS_FHS = 1; then
269       echo "error: configured for FHS root _and_ GNUstep tree. Choose one!"
270       exit 1
271     fi
272   fi
273 }
274
275 function printGNUstepSetup() {
276   echo "GNUstep environment:"
277   echo "  system: ${GNUSTEP_SYSTEM_ROOT}"
278   echo "  local:  ${GNUSTEP_LOCAL_ROOT}"
279   echo "  user:   ${GNUSTEP_USER_ROOT}"
280   echo "  path:   ${GNUSTEP_PATHLIST}"
281   echo "  flat:   ${GNUSTEP_FLATTENED}"
282   echo "  arch:   ${GNUSTEP_HOST}"
283   echo "  combo:  ${LIBRARY_COMBO}"
284   echo ""
285 }
286
287 function cfgwrite() {
288   echo "$1" >> $ARG_CFGMAKE
289 }
290
291 function genConfigMake() {
292   # we ignore the following vars also patches by gstep-make:
293   #   PATH
294   #   DYLD_LIBRARY_PATH
295   #   GUILE_LOAD_PATH
296   #   CLASSPATH
297   
298   if test $ARG_BEQUIET != 1; then
299     echo "creating: $ARG_CFGMAKE"
300   fi
301   
302   echo "# GNUstep environment configuration" > $ARG_CFGMAKE
303   cfgwrite "#   created by: '$CFG_ARGS'"
304   cfgwrite ""
305   
306   cfgwrite "# Note: you can override any option as a 'make' parameter, eg:"
307   cfgwrite "#         make debug=yes"
308   cfgwrite ""
309   
310   #cfgwrite "# print on the cmdline that this file is being used"
311   #cfgwrite "all :: "
312   #cfgwrite "   @echo Local GNUstep config.make is active"
313   #cfgwrite ""
314   
315   # TODO: should be also write a GNUSTEP_INSTALLATION_DIR / BUNDLE_INSTALL_DIR?
316   
317   
318   if test "x$ARG_FRAMEWORK_DIR" != "x"; then
319     cfgwrite "# configured to install in Frameworks directory"
320     cfgwrite "FRAMEWORK_INSTALL_DIR:=${ARG_FRAMEWORK_DIR}"
321     cfgwrite "frameworks=yes"
322     cfgwrite ""
323   elif test $DARG_IS_FHS = 1; then
324     cfgwrite "# configured for FHS install"
325     cfgwrite "FHS_INSTALL_ROOT:=$ARG_PREFIX"
326     cfgwrite ""
327   else
328     cfgwrite "# configured for GNUstep install"
329   fi
330   
331   if test $ARG_WITH_DEBUG = 1; then
332     cfgwrite "# configured to produce debugging code";
333     cfgwrite "debug:=yes"
334   else
335     cfgwrite "# configured to produce non-debugging code";
336     cfgwrite "debug:=no"
337   fi
338   cfgwrite ""
339   
340   if test $ARG_WITH_STRIP = 1; then
341     cfgwrite "# configured to produce stripped code";
342     cfgwrite "strip:=yes"
343   else
344     cfgwrite "# configured not to strip code";
345     cfgwrite "strip:=no"
346   fi
347   cfgwrite ""
348
349   cfgwrite "# enforce shared libraries";
350   cfgwrite "shared:=yes"
351   cfgwrite ""
352   
353   cfgwrite "# GNUstep environment variables:";
354   for i in `env | grep GNUSTEP_ | sort`; do
355     MAKE_ASSI="`echo $i | sed s/=/:=/`"
356     cfgwrite "${MAKE_ASSI}";
357   done
358   cfgwrite "LIBRARY_COMBO=$LIBRARY_COMBO"
359   cfgwrite ""
360   
361   # Note: GNUSTEP_TARGET_CPU is not yet available (set by common.make), so we
362   #       only have environment variables
363   # Note: we can't set SYSTEM_LIB_DIR in this location, it gets overridden by
364   #       common.make
365   cfgwrite "ifeq (\$(findstring _64, \$(GNUSTEP_HOST_CPU)), _64)"
366   cfgwrite "CONFIGURE_64BIT:=yes"
367   cfgwrite "CGS_LIBDIR_NAME:=lib64"
368   cfgwrite "else"
369   cfgwrite "CGS_LIBDIR_NAME:=lib"
370   cfgwrite "endif"
371
372   cfgwrite "ifneq (\$(FHS_INSTALL_ROOT),)"
373   cfgwrite "CONFIGURE_FHS_INSTALL_LIBDIR:=\$(FHS_INSTALL_ROOT)/\$(CGS_LIBDIR_NAME)/"
374   cfgwrite "CONFIGURE_SYSTEM_LIB_DIR += -L\$(CONFIGURE_FHS_INSTALL_LIBDIR)"
375   cfgwrite "endif"
376   cfgwrite "CONFIGURE_SYSTEM_LIB_DIR += -L/usr/\$(CGS_LIBDIR_NAME)/"
377   
378   cfgwrite "# avoid a gstep-make warning"
379   cfgwrite "PATH:=\$(GNUSTEP_SYSTEM_ROOT)/Tools:\$(PATH)"
380 }
381
382 function checkLinking() {
383   # library-name => $1, type => $2
384   local oldpwd=$PWD
385   local tmpdir=".configure-test-$$"
386   
387   mkdir $tmpdir
388   cd $tmpdir
389   cp ../maintenance/dummytool.c .
390   
391   tmpmake="GNUmakefile"
392   echo  >$tmpmake "include ../config.make"
393   echo >>$tmpmake "include \$(GNUSTEP_MAKEFILES)/common.make"
394   echo >>$tmpmake "CTOOL_NAME           := linktest"
395   echo >>$tmpmake "linktest_C_FILES := dummytool.c"
396   echo >>$tmpmake "linktest_TOOL_LIBS  += -l$1"
397   echo >>$tmpmake "SYSTEM_LIB_DIR += \$(CONFIGURE_SYSTEM_LIB_DIR)"
398   echo >>$tmpmake "SYSTEM_LIB_DIR      += ${LINK_SYSLIBDIRS}"
399   echo >>$tmpmake "include \$(GNUSTEP_MAKEFILES)/ctool.make"
400   
401   make -s messages=yes -f $tmpmake linktest >out.log 2>err.log
402   LINK_RESULT=$?
403   
404   if test $LINK_RESULT = 0; then
405     echo "$2 library found: $1"
406     cfgwrite "HAS_LIBRARY_$1=yes"
407   else
408     if test "x$2" = "xrequired"; then
409       echo "failed to link $2 library: $1"
410       rm ../config.make
411       exit 1
412     else
413       echo "failed to link $2 library: $1"
414       cfgwrite "HAS_LIBRARY_$1=no"
415     fi
416   fi
417   
418   cd $oldpwd
419   rm -rf $tmpdir
420 }
421
422 function checkDependencies() {
423   cfgwrite ""
424   cfgwrite "# library dependencies"
425   checkLinking "xml2"        optional;
426   checkLinking "ldap"        optional;
427   checkLinking "ssl"         required; # TODO: make optional
428   checkLinking "pq"          optional;
429   checkLinking "sqlite3"     optional;
430   checkLinking "mysqlclient" optional;
431 }
432
433 function runIt() {
434   if test $ARG_BEQUIET != 1; then
435     printParas;
436   fi
437   
438   if test $ARG_NOCREATE = 1; then 
439     if test $ARG_BEQUIET != 1; then
440       echo "not creating the config file ...";
441     fi
442   else
443     genConfigMake;
444     checkDependencies;
445     
446     if test -x $NGSTREAMS_DIR/configure; then
447       if test $ARG_BEQUIET != 1; then
448         echo -n "configuring NGStreams library .."
449         old="$PWD"
450         cd $NGSTREAMS_DIR
451         ./configure >$old/config-NGStreams.log
452         cd $old
453         echo ".. done (log in config-NGStreams.log)."
454       fi
455     fi
456   fi
457 }
458
459 # ******************** options ********************
460
461 function extractFuncValue() {
462   VALUE="`echo "$1" | sed "s/[^=]*=//g"`"
463 }
464
465 function processOption() {
466   case "x$1" in
467     "x--help"|"x-h")
468         usage;
469         ;;
470     "x--quiet"|"x--silent"|"x-q") ARG_BEQUIET=1;  ;;
471     "x--no-create"|"x-n")         ARG_NOCREATE=1; ;;
472     x--prefix=*)
473         extractFuncValue $1;
474         ARG_PREFIX="$VALUE";
475         ;;
476     x--frameworks=*)
477         extractFuncValue $1;
478         ARG_FRAMEWORK_DIR="$VALUE";
479         ;;
480     x--gsmake=*)
481         extractFuncValue $1;
482         ARG_GSMAKE="$VALUE";
483         ;;
484     x--configmake=*)
485         extractFuncValue $1;
486         ARG_CFGMAKE="$VALUE";
487         ;;
488     "x--with-gnustep")
489         ARG_WITH_GNUSTEP=1
490         DARG_IS_FHS=0
491         ;;
492     "x--without-gnustep")
493         ARG_WITH_GNUSTEP=0
494         DARG_IS_FHS=1
495         ;;
496     "x--enable-debug")
497         ARG_WITH_DEBUG=1
498         ;;
499     "x--disable-debug")
500         ARG_WITH_DEBUG=0
501         ;;
502     "x--enable-strip")
503         ARG_WITH_STRIP=1
504         ;;
505     "x--disable-strip")
506         ARG_WITH_STRIP=0
507         ;;
508
509     *) echo "error: cannot process argument: $1"; exit 1; ;;
510   esac
511 }
512
513 for i in $@; do
514   processOption $i;
515 done
516
517 # load GNUstep environment
518 validateGNUstepArgs
519 # first we load the GNUstep.sh environment
520 source $DARG_GNUSTEP_SH
521 if test $ARG_BEQUIET != 1; then
522   printGNUstepSetup;
523 fi
524
525 # setup some GNUstep dependend defaults
526 if test "x$GNUSTEP_HOST_VENDOR" = "xapple"; then
527   setupAppleArgs;
528 fi
529
530 # ensure the parameters make sense
531 validateArgs
532
533 # start it
534 runIt