Salome HOME
Change version number
[modules/med.git] / build_configure
1 #!/bin/bash
2
3 #
4 # Tool for updating list of .in file for the SALOME project 
5 # and regenerating configure script
6 #
7 # It may be called with --with-kernel[=yes,no] or --without-kernel
8 # option, default is --with-kernel=yes
9 #
10 # Author : Marc Tajchman - CEA
11 # Date : 10/10/2002
12 # $Header$
13 #
14
15 ORIG_DIR=`pwd`
16 CONF_DIR=`echo $0 | sed -e "s,[^/]*$,,;s,/$,,;s,^$,.,"`
17
18 ########################################################################
19 # Check --with-kernel option
20
21 MED_WITH_KERNEL=""
22
23 for option
24 do
25   case $option in
26       -with-kernel | --with-kernel)
27           MED_WITH_KERNEL="yes"
28           break;;
29       -without-kernel | --without-kernel | -with-kernel=no | --with-kernel=no)
30           MED_WITH_KERNEL="no"
31           break;;
32   esac
33 done
34
35 ########################################################################
36 # Test if the KERNEL_ROOT_DIR is set correctly if KERNEL required
37
38 if test "x${MED_WITH_KERNEL}" != "xno"; then
39     if test ! -d "${KERNEL_ROOT_DIR}"; then
40         echo "failed : KERNEL_ROOT_DIR variable is not correct !"
41         exit
42     fi
43 fi
44
45 ########################################################################
46 # find_in - utility function
47 #
48 # usage :  
49 #    find_in directory filename 
50 #
51 # Finds files following the *.in pattern, recursively in the
52 # directory (first argument).
53 # Results are appended into the file (second argument)
54 #
55 # Difference from the standard unix find is that files are tested
56 # before directories
57
58
59 find_in()
60 {
61   i=0
62   f=$2
63
64 # if the first argument is not a directory, returns
65
66   if [ ! -d "$1" ] ; then 
67      return 
68   fi
69
70 # dont look in the CVS directories
71
72   case $1 in
73     */CVS) return ;;
74     *) ;;
75   esac
76
77 # for each regular file contained in the directory
78 # test if it's a .in file
79
80   for i in "$1"/*
81   do
82      if [ -f "$i" ] ; then
83        case $i in 
84          *.in) echo "   "$i" \\" >> $f;;
85          *) ;;
86         esac
87      fi
88   done
89
90 # for each subdirectory of the first argument, proceeds recursively
91
92   for i in "$1"/*
93   do
94      if [ -d "$i" ] ; then
95         find_in "$i" "$f"
96      fi
97   done
98 }
99
100
101 #######################################################################
102 # Generate list of .in files (Makefile.in, config.h.in, etc)
103 # appending it in file configure.in
104
105 cd ${CONF_DIR}
106 ABS_CONF_DIR=`pwd`
107
108 #
109 # Common part of the configure.in file
110 #
111 if \cp -f configure.in.base configure.in_tmp1
112 then
113         echo
114         chmod u+w configure.in_tmp1
115 else
116         echo
117         echo "error : can't create files in" ${CONF_DIR}
118         echo "aborting ..."
119         exit
120 fi
121 chmod u-w configure.in.base 
122
123 if [ -e "${CONF_DIR}/salome_adm" ] ; then
124     \rm -f ${CONF_DIR}/salome_adm
125 fi
126
127 # insert header and AC_INIT(src) which must go before anything else
128 cat > configure.in_tmp1 <<EOF
129 #
130 #  PLEASE DO NOT MODIFY configure.in FILE
131 #
132 #  ALL CHANGES WILL BE DISCARDED BY THE NEXT
133 #  build_configure COMMAND
134 #
135 #  CHANGES MUST BE MADE IN configure.in.base FILE
136 #
137 #
138 # Author : Marc Tajchman (CEA)
139 # Date : 28/06/2001
140 # Modified by : Patrick GOLDBRONN (CEA)
141 # Modified by : Marc Tajchman (CEA)
142 #
143 # Created from configure.in.base
144 #
145
146 AC_INIT(src)
147
148 EOF
149
150 # initialize MED_WITH_KERNEL
151 echo "MED_WITH_KERNEL=${MED_WITH_KERNEL}"                        >> configure.in_tmp1
152
153 # insert the configure.in.base
154 cat configure.in.base                                            >> configure.in_tmp1
155
156 # make a link allowing AC_OUTPUT to find the salome_adm/.../*.in  files
157 echo ""                                                          >> configure.in_tmp1
158 echo 'if test ${MED_WITH_KERNEL} == yes; then'                   >> configure.in_tmp1
159 echo '    ln -fs ${KERNEL_ROOT_DIR}/salome_adm ${ROOT_SRCDIR}/.' >> configure.in_tmp1
160 echo 'else'                                                      >> configure.in_tmp1
161 echo '    ln -fs ${ROOT_SRCDIR}/adm_local_without_kernel ${ROOT_SRCDIR}/salome_adm' >> configure.in_tmp1
162 echo 'fi'                                                        >> configure.in_tmp1
163
164
165 #
166 # List of .in files in the adm/unix directory
167 # These files MUST be on top of AC_OUTPUT list so we
168 # put them "manually"
169 #
170 # Attention, l'ordre d'entrée des fichiers doit être choisi avec
171 # précision
172 #
173 echo ""                                      >> configure.in_tmp1
174 echo "AC_OUTPUT([ \\"                        >> configure.in_tmp1
175 echo "  ./salome_adm/unix/SALOMEconfig.h \\" >> configure.in_tmp1
176 echo "  ./salome_adm/unix/sstream \\"        >> configure.in_tmp1
177 echo "  ./salome_adm/unix/depend \\"         >> configure.in_tmp1
178 echo  " ])"                                  >> configure.in_tmp1
179 echo ""                                      >> configure.in_tmp1
180 echo 'if test $MED_WITH_KERNEL == yes; then' >> configure.in_tmp1
181 echo "{"                                     >> configure.in_tmp1
182 echo "AC_OUTPUT([ \\"                        >> configure.in_tmp1
183 echo "  ./salome_adm/unix/F77config.h \\"    >> configure.in_tmp1
184 echo "  ./adm_local/unix/make_omniorb \\"    >> configure.in_tmp1
185 echo "  ./salome_adm/unix/envScript \\"      >> configure.in_tmp1
186 echo  " ])"                                  >> configure.in_tmp1
187 echo "}"                                     >> configure.in_tmp1
188 echo "fi"                                    >> configure.in_tmp1
189 echo ""                                      >> configure.in_tmp1
190 echo "AC_OUTPUT([ \\"                        >> configure.in_tmp1
191 echo "  ./salome_adm/unix/make_module \\"    >> configure.in_tmp1
192
193 # _CS_gbo Pour assurer ls construction correct de la chaîne de
194 # dépendance, il apparaît nécessaire de surcharger le make_conclude
195 # (resp. make_commence) pardéfaut, c'est à dire le make_conclude de
196 # salome_adm, par le make_conclude (resp. make_commence) du module,
197 # c'est à dire le make_conclude (resp. make_commence) du répertoire
198 # adm_local
199 echo "  ./adm_local/unix/make_commence \\"   >> configure.in_tmp1
200 echo "  ./adm_local/unix/make_conclude \\"   >> configure.in_tmp1
201
202 \rm -f configure.in_tmp2 configure.in_tmp3
203 touch configure.in_tmp2
204
205 find_in . configure.in_tmp2
206
207 # _CS_gbo_100204 Mise à jour du filtre pour prise en compte des
208 # restrictions imposées par les versions récente de autoconf.
209     sed -e '/^  \.\/salome_adm/d' \
210         -e '/configure.in/d'      \
211         -e '/^  \.\/adm_local/d'  \
212         -e 's/.in / /' configure.in_tmp2     >> configure.in_tmp1
213
214 echo  " ])"                                  >> configure.in_tmp1
215
216
217 # delete the link created for AC_OUTPUT
218 #echo 'rm -f ${ROOT_SRCDIR}/salome_adm' >> configure.in_tmp1
219 \mv configure.in_tmp1 configure.in_new
220 \rm  -f configure.in_tmp2 configure.in_tmp3
221
222
223 ########################################################################
224 # Create new (or replace old) configure.in file
225 # Print a message if the file is write protected
226 #
227
228 echo
229 if test ! -f configure.in
230 then
231         echo -n "Creating new file 'configure.in' ... "
232         if \mv configure.in_new configure.in >& /dev/null
233         then
234                 echo "done"
235         else
236                 echo "error, check your file permissions"
237         fi
238 else
239         echo -n "Updating 'configure.in' file ... "
240         if \cp configure.in configure.in_old >& /dev/null
241         then
242                 echo
243         else
244                 echo
245                 echo
246                 echo "Can't backup previous configure.in"
247                 echo -n "Continue (you will not be able to revert) - (Y/N) ? "
248                 read R
249                 case "x$R" in
250                     xn*) exit;;
251                     xN*) exit;;
252                 esac
253                 echo
254                 echo -n "                                 "
255         fi
256         if \cp configure.in_new configure.in >& /dev/null
257         then
258                 echo "done"
259         else
260                 echo
261                 echo "error, can't update previous configure.in"
262         fi
263 fi
264
265 ########################################################################
266 # Use autoconf to rebuild the configure script
267 #
268
269 if test -f configure
270 then
271         echo -n "Updating 'configure' script ...  "
272 else
273         echo -n "Creating 'configure' script ...  "
274 fi
275
276 if test "x${MED_WITH_KERNEL}" != "xno"; then
277    AUX_CONFIG_DIR=${KERNEL_ROOT_DIR}/salome_adm/unix/config_files
278 else
279    AUX_CONFIG_DIR=adm_local_without_kernel/unix/config_files
280 fi
281
282 aclocal --acdir=adm_local/unix/config_files -I ${AUX_CONFIG_DIR}
283 if autoconf
284 then
285         echo "done"
286 else
287         echo "failed (check file permissions and/or user quotas ...)"
288 fi
289
290 cd ${ORIG_DIR}
291
292 echo