]> err.no Git - sope/blob - configure
improved API, bugfix for recurrent dates
[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=0
21
22 DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
23 DARG_IS_FHS=1
24
25 NGSTREAMS_DIR="./sope-core/NGStreams"
26
27 # ******************** usage ********************
28
29 function usage() {
30   cat <<_ACEOF
31 \`configure' configures a GNUstep-make based sourcetree for installation.
32
33 Usage: $0 [OPTION]...
34
35 Note: You do not need to configure this source tree, as another option
36       just ensure that the GNUstep.sh of your GNUstep make installation
37       is properly sourced prior running make.
38
39 Configuration:
40   -h, --help              display this help and exit
41   -q, --quiet, --silent   do not print \`checking...' messages
42   -n, --no-create         do not create output files
43
44 Installation directories:
45   --prefix=PREFIX         install files in PREFIX [/usr/local]
46   --gsmake=PATH           path to gnustep-make tree
47   --configmake=PATH       path to the config file being created
48   --with-gnustep          install in GNUstep tree
49   --enable-debug          turn on debugging and compile time warnings
50
51 _ACEOF
52
53   exit 0;
54 }
55
56 # ******************** running ********************
57
58 function printParas() {
59   echo "Configuration:"
60   if test $ARG_BEQUIET  = 1; then echo "  will be quite.";  fi
61   if test $ARG_NOCREATE = 1; then echo "  won't create files"; fi
62   if test $DARG_IS_FHS = 1;  then
63     echo "  FHS:    install in FHS root"; 
64   else
65     echo "  FHS:    install in GNUstep tree"; 
66   fi
67
68   if test $ARG_WITH_DEBUG = 1; then 
69     echo "  debug:  yes";
70   else
71     echo "  debug:  no";
72   fi
73   
74   echo "  prefix: $ARG_PREFIX"
75   echo "  gstep:  $ARG_GSMAKE"
76   echo "  config: $ARG_CFGMAKE"
77   echo "  script: $DARG_GNUSTEP_SH"
78   echo ""
79 }
80
81 function warnOnFHSPrefix() {
82   cat <<_ACEOFWARN
83 Warning: you are configuring for a non standard FHS style prefix.
84          prefix: $ARG_PREFIX
85
86 Some code in SOPE only looks in /usr and /usr/local for resources and is
87 therefore incompatible with arbitary install pathes.
88
89 If you want to have the flexibility of installation in arbitary pathes just
90 configure GNUstep-make and source the GNUstep.sh script prior executing tools
91 to ensure a proper environment.
92 All SOPE based code is completely relocatable when being used in a GNUstep
93 environment.
94
95 _ACEOFWARN
96 }
97
98 function validateGNUstepArgs() {
99   # GNUstep make
100   if test "x$ARG_GSMAKE" = "x"; then
101     if test -f $HOME/OGoRoot/Library/Makefiles/GNUstep.sh; then
102       ARG_GSMAKE="$HOME/OGoRoot/Library/Makefiles/"
103     elif test -f $HOME/GNUstep/Library/Makefiles/GNUstep.sh; then
104       ARG_GSMAKE="$HOME/GNUstep/Library/Makefiles/"
105     elif test -f /usr/GNUstep/System/Library/Makefiles/GNUstep.sh; then
106       ARG_GSMAKE="/usr/GNUstep/System/Library/Makefiles/"
107     else
108       echo "error: please specify a GNUstep make tree!"
109       exit 1
110     fi
111     DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
112   elif test -d $ARG_GSMAKE; then
113     if test -f $ARG_GSMAKE/GNUstep.sh; then
114       DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
115     elif test -f $ARG_GSMAKE/Library/Makefiles/GNUstep.sh; then
116       ARG_GSMAKE="$ARG_GSMAKE/Library/Makefiles"
117       DARG_GNUSTEP_SH="$ARG_GSMAKE/GNUstep.sh"
118     else
119       echo "error: specified directory contains no GNUstep.sh: $ARG_GSMAKE"
120       exit 1
121     fi
122   else
123     echo "error: specified GNUstep make tree does not exist: $ARG_GSMAKE"
124     exit 1
125   fi
126 }
127
128 function validateArgs() {
129   # validate prefix (could be better?)
130   case "x$ARG_PREFIX" in
131     "x/usr/local"|"x/usr/local/")
132         DARG_IS_FHS=1;
133         ;;
134     "x/usr"|"x/usr/")
135         DARG_IS_FHS=1;
136         ;;
137     "x$GNUSTEP_USER_ROOT"|"x$GNUSTEP_LOCAL_ROOT"|"x$GNUSTEP_SYSTEM_ROOT")
138         DARG_IS_FHS=0;
139         ARG_WITH_GNUSTEP=1;
140         ;;
141     "x")
142         if test $ARG_WITH_GNUSTEP = 1; then
143           DARG_IS_FHS=0;
144           ARG_PREFIX="$GNUSTEP_LOCAL_ROOT"
145           if test $ARG_BEQUIET != 1; then
146             echo "Note: will install in GNUSTEP_LOCAL_ROOT: $ARG_PREFIX"
147             echo ""
148           fi
149         else
150           DARG_IS_FHS=1;
151           ARG_PREFIX="/usr/local/"
152           echo "Note: will install in default location: $ARG_PREFIX"
153           echo ""
154         fi
155         ;;
156     *)
157         if test $ARG_WITH_GNUSTEP = 1; then
158           echo "error: specified --with-gnustep, but specified prefix is not"
159           echo "       a GNUstep root: '$ARG_PREFIX'"
160           exit 1
161         else
162           if test $ARG_BEQUIET != 1; then
163             warnOnFHSPrefix;
164           fi
165           DARG_IS_FHS=1;
166         fi
167         ;;
168   esac
169   
170   if test $ARG_WITH_GNUSTEP = 1; then
171     if test $DARG_IS_FHS = 1; then
172       echo "error: configured for FHS root _and_ GNUstep tree. Choose one!"
173       exit 1
174     fi
175   fi
176 }
177
178 function printGNUstepSetup() {
179   echo "GNUstep environment:"
180   echo "  system: ${GNUSTEP_SYSTEM_ROOT}"
181   echo "  local:  ${GNUSTEP_LOCAL_ROOT}"
182   echo "  user:   ${GNUSTEP_USER_ROOT}"
183   echo "  path:   ${GNUSTEP_PATHLIST}"
184   echo "  flat:   ${GNUSTEP_FLATTENED}"
185   echo "  arch:   ${GNUSTEP_HOST}"
186   echo "  combo:  ${LIBRARY_COMBO}"
187   echo ""
188 }
189
190 function cfgwrite() {
191   echo "$1" >> $ARG_CFGMAKE
192 }
193
194 function genConfigMake() {
195   # we ignore the following vars also patches by gstep-make:
196   #   PATH
197   #   DYLD_LIBRARY_PATH
198   #   GUILE_LOAD_PATH
199   #   CLASSPATH
200   
201   if test $ARG_BEQUIET != 1; then
202     echo "creating: $ARG_CFGMAKE"
203   fi
204   
205   echo "# GNUstep environment configuration" > $ARG_CFGMAKE
206   cfgwrite "#   created by: '$CFG_ARGS'"
207   cfgwrite ""
208   
209   cfgwrite "# Note: you can override any option as a 'make' parameter, eg:"
210   cfgwrite "#         make debug=yes"
211   cfgwrite ""
212   
213   cfgwrite "# print on the cmdline that this file is being used"
214   cfgwrite "all :: "
215   cfgwrite "    @echo Local GNUstep config.make is active"
216   cfgwrite ""
217   
218   # TODO: should be also write a GNUSTEP_INSTALLATION_DIR / BUNDLE_INSTALL_DIR?
219   
220   if test $DARG_IS_FHS = 1; then
221     cfgwrite "# configured for FHS install"
222     cfgwrite "FHS_INSTALL_ROOT:=$ARG_PREFIX"
223     cfgwrite ""
224   fi
225   
226   if test $ARG_WITH_DEBUG = 1; then
227     cfgwrite "# configured to produce debugging code";
228     cfgwrite "debug:=yes"
229   else
230     cfgwrite "# configured to produce non-debugging code";
231     cfgwrite "debug:=no"
232   fi
233   cfgwrite ""
234   
235   cfgwrite "# enforce shared libraries";
236   cfgwrite "shared:=yes"
237   cfgwrite ""
238   
239   cfgwrite "# GNUstep environment variables:";
240   for i in `env | grep GNUSTEP_ | sort`; do
241     MAKE_ASSI="`echo $i | sed s/=/:=/`"
242     cfgwrite "${MAKE_ASSI}";
243   done
244   cfgwrite "LIBRARY_COMBO=$LIBRARY_COMBO"
245 }
246
247 function runIt() {
248   if test $ARG_BEQUIET != 1; then
249     printParas;
250   fi
251   
252   if test $ARG_NOCREATE = 1; then 
253     if test $ARG_BEQUIET != 1; then
254       echo "not creating the config file ...";
255     fi
256   else
257     genConfigMake;
258     
259     if test -x $NGSTREAMS_DIR/configure; then
260       if test $ARG_BEQUIET != 1; then
261         echo -n "configuring NGStreams library .."
262         old="$PWD"
263         cd $NGSTREAMS_DIR
264         ./configure >$old/config-NGStreams.log
265         cd $old
266         echo ".. done (log in config-NGStreams.log)."
267       fi
268     fi
269   fi
270 }
271
272 # ******************** options ********************
273
274 function extractFuncValue() {
275   VALUE="`echo "$1" | sed "s/[^=]*=//g"`"
276 }
277
278 function processOption() {
279   case "x$1" in
280     "x--help"|"x-h")
281         usage;
282         ;;
283     "x--quiet"|"x--silent"|"x-q") ARG_BEQUIET=1;  ;;
284     "x--no-create"|"x-n")         ARG_NOCREATE=1; ;;
285     x--prefix=*)
286         extractFuncValue $1;
287         ARG_PREFIX="$VALUE";
288         ;;
289     x--gsmake=*)
290         extractFuncValue $1;
291         ARG_GSMAKE="$VALUE";
292         ;;
293     x--configmake=*)
294         extractFuncValue $1;
295         ARG_CFGMAKE="$VALUE";
296         ;;
297     "x--with-gnustep")
298         ARG_WITH_GNUSTEP=1
299         DARG_IS_FHS=0
300         ;;
301     "x--enable-debug")
302         ARG_WITH_DEBUG=1
303         ;;
304
305     *) echo "error: cannot process argument: $1"; exit 1; ;;
306   esac
307 }
308
309 for i in $@; do
310   processOption $i;
311 done
312
313 # load GNUstep environment
314 validateGNUstepArgs
315 # first we load the GNUstep.sh environment
316 source $DARG_GNUSTEP_SH
317 if test $ARG_BEQUIET != 1; then
318   printGNUstepSetup;
319 fi
320
321 # ensure the parameters make sense
322 validateArgs
323
324 # start it
325 runIt