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