]> err.no Git - sope/blob - configure
synced with latest gstep-make process
[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   cfgwrite "# avoid a gstep-make warning"
362   cfgwrite "PATH:=\$(GNUSTEP_SYSTEM_ROOT)/Tools:\$(PATH)"
363 }
364
365 function checkLinking() {
366   # library-name => $1, type => $2
367   local oldpwd=$PWD
368   local tmpdir=".configure-test-$$"
369   
370   mkdir $tmpdir
371   cd $tmpdir
372   cp ../maintenance/dummytool.c .
373   
374   tmpmake="GNUmakefile"
375   echo  >$tmpmake "include ../config.make"
376   echo >>$tmpmake "include \$(GNUSTEP_MAKEFILES)/common.make"
377   echo >>$tmpmake "CTOOL_NAME           := linktest"
378   echo >>$tmpmake "linktest_C_FILES := dummytool.c"
379   echo >>$tmpmake "linktest_TOOL_LIBS  += -l$1"
380   echo >>$tmpmake "SYSTEM_LIB_DIR      += ${LINK_SYSLIBDIRS}"
381   echo >>$tmpmake "include \$(GNUSTEP_MAKEFILES)/ctool.make"
382   
383   make -s messages=yes -f $tmpmake linktest >out.log 2>err.log
384   LINK_RESULT=$?
385   
386   if test $LINK_RESULT = 0; then
387     echo "$2 library found: $1"
388     cfgwrite "HAS_LIBRARY_$1=yes"
389   else
390     if test "x$2" = "xrequired"; then
391       echo "failed to link $2 library: $1"
392       rm ../config.make
393       exit 1
394     else
395       echo "failed to link $2 library: $1"
396       cfgwrite "HAS_LIBRARY_$1=no"
397     fi
398   fi
399   
400   cd $oldpwd
401   rm -rf $tmpdir
402 }
403
404 function checkDependencies() {
405   cfgwrite ""
406   cfgwrite "# library dependencies"
407   checkLinking "xml2"        optional;
408   checkLinking "ldap"        optional;
409   checkLinking "ssl"         required; # TODO: make optional
410   checkLinking "pq"          optional;
411   checkLinking "sqlite3"     optional;
412   checkLinking "mysqlclient" optional;
413 }
414
415 function runIt() {
416   if test $ARG_BEQUIET != 1; then
417     printParas;
418   fi
419   
420   if test $ARG_NOCREATE = 1; then 
421     if test $ARG_BEQUIET != 1; then
422       echo "not creating the config file ...";
423     fi
424   else
425     genConfigMake;
426     checkDependencies;
427     
428     if test -x $NGSTREAMS_DIR/configure; then
429       if test $ARG_BEQUIET != 1; then
430         echo -n "configuring NGStreams library .."
431         old="$PWD"
432         cd $NGSTREAMS_DIR
433         ./configure >$old/config-NGStreams.log
434         cd $old
435         echo ".. done (log in config-NGStreams.log)."
436       fi
437     fi
438   fi
439 }
440
441 # ******************** options ********************
442
443 function extractFuncValue() {
444   VALUE="`echo "$1" | sed "s/[^=]*=//g"`"
445 }
446
447 function processOption() {
448   case "x$1" in
449     "x--help"|"x-h")
450         usage;
451         ;;
452     "x--quiet"|"x--silent"|"x-q") ARG_BEQUIET=1;  ;;
453     "x--no-create"|"x-n")         ARG_NOCREATE=1; ;;
454     x--prefix=*)
455         extractFuncValue $1;
456         ARG_PREFIX="$VALUE";
457         ;;
458     x--frameworks=*)
459         extractFuncValue $1;
460         ARG_FRAMEWORK_DIR="$VALUE";
461         ;;
462     x--gsmake=*)
463         extractFuncValue $1;
464         ARG_GSMAKE="$VALUE";
465         ;;
466     x--configmake=*)
467         extractFuncValue $1;
468         ARG_CFGMAKE="$VALUE";
469         ;;
470     "x--with-gnustep")
471         ARG_WITH_GNUSTEP=1
472         DARG_IS_FHS=0
473         ;;
474     "x--without-gnustep")
475         ARG_WITH_GNUSTEP=0
476         DARG_IS_FHS=1
477         ;;
478     "x--enable-debug")
479         ARG_WITH_DEBUG=1
480         ;;
481     "x--disable-debug")
482         ARG_WITH_DEBUG=0
483         ;;
484     "x--enable-strip")
485         ARG_WITH_STRIP=1
486         ;;
487     "x--disable-strip")
488         ARG_WITH_STRIP=0
489         ;;
490
491     *) echo "error: cannot process argument: $1"; exit 1; ;;
492   esac
493 }
494
495 for i in $@; do
496   processOption $i;
497 done
498
499 # load GNUstep environment
500 validateGNUstepArgs
501 # first we load the GNUstep.sh environment
502 source $DARG_GNUSTEP_SH
503 if test $ARG_BEQUIET != 1; then
504   printGNUstepSetup;
505 fi
506
507 # setup some GNUstep dependend defaults
508 if test "x$GNUSTEP_HOST_VENDOR" = "xapple"; then
509   setupAppleArgs;
510 fi
511
512 # ensure the parameters make sense
513 validateArgs
514
515 # start it
516 runIt