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