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