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 " this file will be updated with new environment variables. "
43 echo " it will also be sources if it has sh syntax"
44 echo " --install=path : set install directory where module building and install is done (should be absolute)"
45 echo " --compile-only -c : no building and configure - just compile by calling make && make install"
46 echo " --local -l : look for source directories localy - build and install localy"
47 echo " --sources=src1,src2,... : for specifying source directories that don't end up with _SRC"
52 echo " SA_build KERNEL"
53 echo " -> compilation of KERNEL/KERNEL_SRC"
54 echo " build is done in KERNEL/KERNEL_BUILD"
55 echo " install is done in KERNEL/KERNEL_INSTALL"
56 echo " environment should be set up correctly before (option --environ not used)"
58 echo " SA_build MED_SRC --install=/export/home/SALOME"
59 echo " -> compilation of MED_SRC (no module name was specified)"
60 echo " build is done in /export/home/SALOME/MED_BUILD"
61 echo " install is done in /export/home/SALOME/MED_INSTALL"
63 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"
64 echo " -> compilation without prompting (--batch option) of KERNEL_SRC, GUI_SRC, GEOM_SRC, MED_SRC, MESH_SRC, VISU_SRC and SUPERV_SRC"
65 echo " all sources are searched in V_3_0_2 directory "
66 echo " environment is setup using my_env_products.sh file"
67 echo " configure is done with --disable-debug option"
79 y* | Y* | o* | O* ) ;;
89 echo "remove $1 content"
102 echo -e "\n\nError : environment file $1 NOT FOUND\n"
110 echo "----------------- Compile ---------------------"
114 echo -e "\n [OK] Compile : ${module}/${SOURCE_NAME}_SRC" >> $CR
115 echo Compilation succeeded : we make install
117 echo "----------------- Install ---------------------"
121 echo -e " [OK] Install : ${module}/${SOURCE_NAME}_SRC" >> $CR
123 echo -e " [KO] Install : ${module}/${SOURCE_NAME}_SRC" >> $CR
126 echo Compilation failed
127 echo -e "\n [KO] Compile : ${module}/${SOURCE_NAME}_SRC" >> $CR
135 if [ -d ${LOCAL_DIR}/${module} ]
137 COMPILE_DIR=${LOCAL_DIR}/${module}
138 elif [ -d ${SRC_ROOT_DIR}/${module} ]
140 COMPILE_DIR=${SRC_ROOT_DIR}/${module}
142 echo Sorry : ${module} not found!
146 if [ -d ${COMPILE_DIR}/${module}_SRC ]
148 SOURCE_DIRS=${COMPILE_DIR}/${module}_SRC
151 for src in $LISTE_SRC
153 if [ -d ${COMPILE_DIR}/${src} ]
155 SOURCE_DIRS="$SOURCE_DIRS ${COMPILE_DIR}/${src}"
164 for SOURCE_DIR in ${SOURCE_DIRS}
167 echo -e "\n${isrc}) Compilation dans $SOURCE_DIR \n"
168 src=`basename $SOURCE_DIR`
169 SOURCE_NAME=${src%_SRC}
170 echo " -> Repertoire Source = ${SOURCE_DIR}"
171 echo " -> Component name = ${SOURCE_NAME}"
172 echo " -> Repertoire Build = ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD"
173 echo " -> Repertoire Install = ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL"
177 if [ $COMPILE_ONLY -eq 1 ]
179 if [ $BATCH_MODE -eq 0 ]
181 ask_confirmation "Compile ?"
183 cd ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD
188 echo "ERROR : build directory ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD not found"
189 echo " with -c option, build directory should already exist"
194 if [ $BATCH_MODE -eq 0 ]
196 ask_confirmation "build configure and configure ?"
201 echo "----------------- Build configure ---------------------"
204 echo "----------------- Configure ---------------------"
206 # crée ou vide les répertoires
207 check_dir ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD
208 check_dir ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL
209 cd ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD
210 ${SOURCE_DIR}/configure ${OPTIONS_CONFIGURE} --prefix=${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL | tee ${TMP_FILE}
212 echo "retour configure : $?"
214 if [ $BATCH_MODE -eq 0 ]
216 ask_confirmation "Compile ?"
218 export `echo ${SOURCE_NAME}`_ROOT_DIR=${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL
221 if [ $ENVIRON_FILE ] && [ -f $ENVIRON_FILE ]
223 # Mise à jour du script d'environnement
224 if [ $BATCH_MODE -eq 1 ]
226 update_environ ${SOURCE_NAME}_ROOT_DIR ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL ${SOURCE_NAME}_SRC_DIR ${SOURCE_DIR}
228 echo "Voulez vous mettre mettre à jour le script d'environnement ${ENVIRON_FILE} ?"
229 echo " (ajouter la variable ${SOURCE_NAME}_ROOT_DIR - une copie de l'ancien script est faite dans un .old)"
233 y* | Y* | o* | O* ) update_environ ${SOURCE_NAME}_ROOT_DIR ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL ${SOURCE_NAME}_SRC_DIR ${SOURCE_DIR} ;;
243 # update environment scrip : add or replace ROOT_DIR and SRC_DIR variable for component
246 cp ${ENVIRON_FILE} ${ENVIRON_FILE}.old
247 if [ "${SHELL_EXT}" == "sh" ]
249 grep " $1" ${ENVIRON_FILE}.old > /dev/null
252 # if variable is already set, we replace old setting by new one
253 cat ${ENVIRON_FILE}.old | awk -v var_root_dir=$1 -v path=$2 -v src_root_dir=$3 -v src_dir=$4 '
254 $1=="export" && $2 ~ "^"var_root_dir"=" {print "#"$0; $0="export "var_root_dir "=" path}
255 $1=="export" && $2 ~ "^"src_root_dir"=" {print "#"$0; $0="export "src_root_dir "=" src_dir}
256 $1 ~ "^"var_root_dir"=" {print "#"$0; $0=var_root_dir "=" path}
257 $1 ~ "^"src_root_dir"=" {print "#"$0; $0=src_root_dir "=" src_dir}
258 { print $0}' > ${ENVIRON_FILE}
260 echo -e "##\n#------ ${SOURCE_NAME}-Src ------\nexport $3=$4" >> ${ENVIRON_FILE}
261 echo -e "##\n#------ ${SOURCE_NAME}-Bin ------\nexport $1=$2" >> ${ENVIRON_FILE}
264 grep " $1" ${ENVIRON_FILE}.old > /dev/null
267 # if variable is already set, we replace old setting by new one
268 cat ${ENVIRON_FILE}.old | awk -v var_root_dir=$1 -v path=$2 -v src_root_dir=$3 -v src_dir=$4 '
269 $1=="setenv" && $2 == var_root_dir {print "#"$0; $0="setenv "var_root_dir " " path}
270 $1=="setenv" && $2 == src_root_dir {print "#"$0; $0="setenv "src_root_dir " " src_dir}
271 { print $0}' > ${ENVIRON_FILE}
273 echo -e "##\n#------ ${SOURCE_NAME}-Src ------\nsetenv $3 $4" >> ${ENVIRON_FILE}
274 echo -e "##\n#------ ${SOURCE_NAME}-Bin ------\nsetenv $1 $2" >> ${ENVIRON_FILE}
279 ########### Programme Principal #############
292 echo "Pas d'arguments!"
300 --disable-debug ) OPTIONS_CONFIGURE="${OPTIONS_CONFIGURE} --disable-debug" ;;
302 --batch) BATCH_MODE=1 ;;
304 --environ=*) set_environ ${arg#--environ=} ;;
306 --install=*) INSTALL_ROOT_DIR=${arg#--install=} ;;
308 --sources=*) LISTE_SRC="${LISTE_SRC} ${arg#--sources=}" ;;
310 --local | -l ) SRC_ROOT_DIR=$PWD ; INSTALL_ROOT_DIR=$PWD ;;
312 --compile-only | -c ) COMPILE_ONLY=1 ;;
314 *_SRC ) LISTE_SRC="${LISTE_SRC} ${arg}" ;;
316 *) LISTE_MODULE="${LISTE_MODULE} ${arg}" ;;
321 LISTE_SRC=`echo ${LISTE_SRC} | sed "s/,/ /g"` # replaces ',' by blanks
323 if [ ! $INSTALL_ROOT_DIR ]
325 echo Local installation
326 INSTALL_ROOT_DIR=$PWD
331 echo " ------------------------------------"
332 echo " | Utilitaire de Compilation Salome |"
333 echo " ------------------------------------"
336 echo "Liste des modules à parcourir : $LISTE_MODULE"
337 echo "Liste repertoire à compiler : $LISTE_SRC"
338 echo "Options configure : $OPTIONS_CONFIGURE"
339 echo "Environment File : $ENVIRON_FILE"
341 CR=/tmp/${USER}_SA_build_CR
344 if [ $ENVIRON_FILE ] && [ -f $ENVIRON_FILE ] # if an existing environment file was specified
346 # get shell extension
347 case ${ENVIRON_FILE##*\.} in
352 *) SHELL_EXT=sh;echo WARNING : shell extension not recognized! Assume sh ;;
354 if [ "${SHELL_EXT}" == "sh" ]
356 # if shell syntax is sh, source environment with ENV_FOR_LAUNCH set to 0
357 cat ${ENVIRON_FILE} | sed "s/ENV_FOR_LAUNCH=1/ENV_FOR_LAUNCH=0/g" > ${ENVIRON_FILE}.tmp
358 source ${ENVIRON_FILE}.tmp
359 rm ${ENVIRON_FILE}.tmp
360 echo source Environment File with ENV_FOR_LAUNCH=0
362 echo "WARNING : environment file has csh extension => cannot source it and assume environment already set."
363 echo -e " (if compilation fails, please set environment before, of choose an sh syntax file)\n"
366 echo Warning : Environment File Not Found!
370 if [ "$LISTE_MODULE" == "" ]
372 # no module specified -> lookup for sources localy
373 echo lookup for sources localy
375 for src in $LISTE_SRC
377 if [ -d ${LOCAL_DIR}/${src} ]
379 SOURCE_DIRS="$SOURCE_DIRS ${LOCAL_DIR}/${src}"
380 elif [ -d ${SRC_ROOT_DIR}/${src} ]
382 SOURCE_DIRS="$SOURCE_DIRS ${LOCAL_DIR}/${src}"
387 for module in $LISTE_MODULE
389 echo "----------------- Compilation dans $module ----------------"
398 echo -e "\n----------------- Résumé ----------------"