3 # Utility for building Salome Modules
5 # default directory containing sources. Look-up is performed first localy, then in this directory if present.
7 # default directory where you want to put build & install directories. alternative for -i option
9 # default building environment file. alternative to --environ= option
11 # Utilitaire de compilation Salome
17 echo Name : SA_build - build Salome modules
19 echo "Description : Small utility that automate Salome components building."
20 echo " -> call build_configure in source directories"
21 echo " -> create build and install directories"
22 echo " -> call configure, make, make install from build directories"
23 echo " -> update environment file (only sh syntax is supported)"
27 echo " SA_build [modulename(s)] sourcename(s) [ options ]"
29 echo " sourcename(s) are component's source directories and should end up by convention with _SRC"
30 echo " modulename(s) are module directories that contain source directories"
32 echo " -> A look-up is done to find component's source directories - then building is done"
33 echo " - modulenames are searched localy, then in SRC_ROOT_DIR"
34 echo " - sourcename(s) are searched in modulename(s), or localy if no module name is specified"
35 echo " - if no sourcename is entered, search for modulename_SRC"
39 echo " --disable-debug : compilation without debug traces"
40 echo " --batch : compilation is done in batch mode - no prompting"
41 echo " --environ=path : set environment file to path (should be absolute)"
42 echo " --install=path : set install directory where module building is done (should be absolute)"
43 echo " --compile-only -c : no building - just compile by calling make && make install"
44 echo " --local -l : look for source directories localy - build and install localy"
45 echo " --sources=src1,src2,... : for specifying source directories that don't end up with _SRC"
50 echo " SA_build KERNEL"
51 echo " -> compilation of KERNEL/KERNEL_SRC"
52 echo " build is done in KERNEL/KERNEL_BUILD"
53 echo " install is done in KERNEL/KERNEL_INSTALL"
54 echo " environment should be set up correctly before (option --environ not used)"
56 echo " SA_build MED_SRC --install=/export/home/SALOME"
57 echo " -> compilation of MED_SRC (no module name was specified)"
58 echo " build is done in /export/home/SALOME/MED_BUILD"
59 echo " install is done in /export/home/SALOME/MED_INSTALL"
61 echo " SA_build --batch --disable-debug --environ=my_env_products.sh V_3_0_2 KERNEL_SRC GUI_SRC GEOM_SRC MED_SRC MESH_SRC VISU_SRC SUPERV_SRC"
62 echo " -> compilation without prompting (--batch option) of KERNEL_SRC, GUI_SRC, GEOM_SRC, MED_SRC, MESH_SRC, VISU_SRC and SUPERV_SRC"
63 echo " all sources are searched in V_3_0_2 directory "
64 echo " environment is setup using my_env_products.sh file"
65 echo " configure is done with --disable-debug option"
77 y* | Y* | o* | O* ) ;;
87 echo "remove $1 content"
100 echo -e "\n\nError : environment file $1 NOT FOUND\n"
108 echo "----------------- Compile ---------------------"
112 # compilation succeeded : we make install
114 echo "----------------- Install ---------------------"
125 if [ -d ${LOCAL_DIR}/${module} ]
127 COMPILE_DIR=${LOCAL_DIR}/${module}
128 elif [ -d ${SRC_ROOT_DIR}/${module} ]
130 COMPILE_DIR=${SRC_ROOT_DIR}/${module}
132 echo Sorry : ${module} not found!
136 if [ -d ${COMPILE_DIR}/${module}_SRC ]
138 SOURCE_DIRS=${COMPILE_DIR}/${module}_SRC
141 for src in $LISTE_SRC
143 if [ -d ${COMPILE_DIR}/${src} ]
145 SOURCE_DIRS="$SOURCE_DIRS ${COMPILE_DIR}/${src}"
154 for SOURCE_DIR in ${SOURCE_DIRS}
157 echo -e "\n${isrc}) Compilation dans $SOURCE_DIR \n"
158 src=`basename $SOURCE_DIR`
159 SOURCE_NAME=${src%_SRC}
160 echo " -> Repertoire Source = ${SOURCE_DIR}"
161 echo " -> Component name = ${SOURCE_NAME}"
162 echo " -> Repertoire Build = ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD"
163 echo " -> Repertoire Install = ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL"
167 if [ $COMPILE_ONLY -eq 1 ]
169 if [ $BATCH_MODE -eq 0 ]
171 ask_confirmation "Compile ?"
173 cd ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD
177 if [ $BATCH_MODE -eq 0 ]
179 ask_confirmation "build configure and configure ?"
184 echo "----------------- Build configure ---------------------"
187 echo "----------------- Configure ---------------------"
189 # crée ou vide les répertoires
190 check_dir ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD
191 check_dir ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL
192 cd ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD
193 ${SOURCE_DIR}/configure ${OPTIONS_CONFIGURE} --prefix=${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL | tee ${TMP_FILE}
195 echo "retour configure : $?"
197 if [ $BATCH_MODE -eq 0 ]
199 ask_confirmation "Compile ?"
201 export `echo ${SOURCE_NAME}`_ROOT_DIR=${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL
204 if [ $ENVIRON_FILE ] && [ -f $ENVIRON_FILE ]
206 # Mise à jour du script d'environnement
207 if [ $BATCH_MODE -eq 1 ]
209 update_environ ${SOURCE_NAME}_ROOT_DIR ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL ${SOURCE_NAME}_SRC_DIR ${SOURCE_DIR}
211 echo "Voulez vous mettre mettre à jour le script d'environnement ${ENVIRON_FILE} ?"
212 echo " (ajouter la variable ${SOURCE_NAME}_ROOT_DIR - une copie de l'ancien script est faite dans un .old)"
216 y* | Y* | o* | O* ) update_environ ${SOURCE_NAME}_ROOT_DIR ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL ${SOURCE_NAME}_SRC_DIR ${SOURCE_DIR} ;;
226 # update environment scrip : add or replace ROOT_DIR and SRC_DIR variable for component
229 cp ${ENVIRON_FILE} ${ENVIRON_FILE}.old
230 grep " $1" ${ENVIRON_FILE}.old > /dev/null
233 # if variable is already set, we replace old setting by new one
234 cat ${ENVIRON_FILE}.old | awk -v var_root_dir=$1 -v path=$2 -v src_root_dir=$3 -v src_dir=$4 '
235 $1=="export" && $2 ~ "^"var_root_dir"=" {print "#"$0; $0="export "var_root_dir "=" path}
236 $1=="export" && $2 ~ "^"src_root_dir"=" {print "#"$0; $0="export "src_root_dir "=" src_dir}
237 $1 ~ "^"var_root_dir"=" {print "#"$0; $0=var_root_dir "=" path}
238 $1 ~ "^"src_root_dir"=" {print "#"$0; $0=src_root_dir "=" src_dir}
239 { print $0}' > ${ENVIRON_FILE}
241 echo -e "##\n#------ ${SOURCE_NAME}-Src ------\nexport $3=$4" >> ${ENVIRON_FILE}
242 echo -e "##\n#------ ${SOURCE_NAME}-Bin ------\nexport $1=$2" >> ${ENVIRON_FILE}
246 ########### Programme Principal #############
259 echo "Pas d'arguments!"
267 --disable-debug ) OPTIONS_CONFIGURE="${OPTIONS_CONFIGURE} --disable-debug" ;;
269 --batch) BATCH_MODE=1 ;;
271 --environ=*) set_environ ${arg#--environ=} ;;
273 --install=*) INSTALL_ROOT_DIR=${arg#--install=} ;;
275 --sources=*) LISTE_SRC="${LISTE_SRC} ${arg#--sources=}" ;;
277 --local | -l ) SRC_ROOT_DIR=$PWD ; INSTALL_ROOT_DIR=$PWD ;;
279 --compile-only | -c ) COMPILE_ONLY=1 ;;
281 *_SRC ) LISTE_SRC="${LISTE_SRC} ${arg}" ;;
283 *) LISTE_MODULE="${LISTE_MODULE} ${arg}" ;;
288 LISTE_SRC=`echo ${LISTE_SRC} | sed "s/,/ /g"` # replaces ',' by blanks
290 if [ ! $INSTALL_ROOT_DIR ]
292 echo Local installation
293 INSTALL_ROOT_DIR=$PWD
298 echo " ------------------------------------"
299 echo " | Utilitaire de Compilation Salome |"
300 echo " ------------------------------------"
303 echo "Liste des modules à parcourir : $LISTE_MODULE"
304 echo "Liste repertoire à compiler : $LISTE_SRC"
305 echo "Options configure : $OPTIONS_CONFIGURE"
306 echo "Environment File : $ENVIRON_FILE"
309 if [ $ENVIRON_FILE ] && [ -f $ENVIRON_FILE ]
311 # force option for compilation - then source environment
312 cat ${ENVIRON_FILE} | sed "s/ENV_FOR_LAUNCH=1/ENV_FOR_LAUNCH=0/g" > ${ENVIRON_FILE}.tmp
313 source ${ENVIRON_FILE}.tmp
314 rm ${ENVIRON_FILE}.tmp
315 echo source Environment File with ENV_FOR_LAUNCH=0
317 echo Warning : Environment File Not Found!
321 if [ "$LISTE_MODULE" == "" ]
323 # no module specified -> lookup for sources localy
324 echo lookup for sources localy
326 for src in $LISTE_SRC
328 if [ -d ${LOCAL_DIR}/${src} ]
330 SOURCE_DIRS="$SOURCE_DIRS ${LOCAL_DIR}/${src}"
331 elif [ -d ${SRC_ROOT_DIR}/${src} ]
333 SOURCE_DIRS="$SOURCE_DIRS ${LOCAL_DIR}/${src}"
338 for module in $LISTE_MODULE
340 echo "----------------- Compilation dans $module ----------------"