3 # Copyright (C) CEA, EDF
4 # Author : Nicolas Crouzet (CEA)
7 # Utility for building Salome Modules
9 # default directory containing sources. Look-up is performed first localy, then in this directory if present.
11 # default directory where you want to put build & install directories. alternative for -i option
13 # default building environment file. alternative to --environ= option
15 # Utilitaire de compilation Salome
21 echo Name : SA_build - build Salome modules
23 echo "Description : Small utility that automate Salome components building."
24 echo " -> call build_configure in source directories"
25 echo " -> create build and install directories"
26 echo " -> call configure, make, make install from build directories"
27 echo " -> update environment file (only sh syntax is supported)"
31 echo " SA_build [modulename(s)] sourcename(s) [ options ]"
33 echo " sourcename(s) are component's source directories and should end up by convention with _SRC"
34 echo " modulename(s) are module directories that contain source directories"
36 echo " -> A look-up is done to find component's source directories - then building is done"
37 echo " - modulenames are searched localy, then in SRC_ROOT_DIR"
38 echo " - sourcename(s) are searched in modulename(s), or localy if no module name is specified"
39 echo " - if no sourcename is entered, search for modulename_SRC"
43 echo " --disable-debug : compilation without debug traces"
44 echo " --batch : compilation is done in batch mode - no prompting"
45 echo " --environ=path : set environment file to path (should be absolute)"
46 echo " this file will be updated with new environment variables. "
47 echo " it will also be sources if it has sh syntax"
48 echo " --install=path : set install directory where module building and install is done (should be absolute)"
49 echo " --compile-only -c : no building and configure - just compile by calling make && make install"
50 echo " --local -l : look for source directories localy - build and install localy"
51 echo " --sources=src1,src2,... : for specifying source directories that don't end up with _SRC"
56 echo " SA_build KERNEL"
57 echo " -> compilation of KERNEL/KERNEL_SRC"
58 echo " build is done in KERNEL/KERNEL_BUILD"
59 echo " install is done in KERNEL/KERNEL_INSTALL"
60 echo " environment should be set up correctly before (option --environ not used)"
62 echo " SA_build MED_SRC --install=/export/home/SALOME"
63 echo " -> compilation of MED_SRC (no module name was specified)"
64 echo " build is done in /export/home/SALOME/MED_BUILD"
65 echo " install is done in /export/home/SALOME/MED_INSTALL"
67 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"
68 echo " -> compilation without prompting (--batch option) of KERNEL_SRC, GUI_SRC, GEOM_SRC, MED_SRC, MESH_SRC, VISU_SRC and SUPERV_SRC"
69 echo " all sources are searched in V_3_0_2 directory "
70 echo " environment is setup using my_env_products.sh file"
71 echo " configure is done with --disable-debug option"
83 y* | Y* | o* | O* ) ;;
93 echo "remove $1 content"
106 echo -e "\n\nError : environment file $1 NOT FOUND\n"
114 echo "----------------- Compile ---------------------"
118 echo -e "\n [OK] Compile : ${module}/${SOURCE_NAME}_SRC" >> $CR
119 echo Compilation succeeded : we make install
121 echo "----------------- Install ---------------------"
125 echo -e " [OK] Install : ${module}/${SOURCE_NAME}_SRC" >> $CR
127 echo -e " [KO] Install : ${module}/${SOURCE_NAME}_SRC" >> $CR
130 echo Compilation failed
131 echo -e "\n [KO] Compile : ${module}/${SOURCE_NAME}_SRC" >> $CR
139 if [ -d ${LOCAL_DIR}/${module} ]
141 COMPILE_DIR=${LOCAL_DIR}/${module}
142 elif [ -d ${SRC_ROOT_DIR}/${module} ]
144 COMPILE_DIR=${SRC_ROOT_DIR}/${module}
146 echo Sorry : ${module} not found!
150 if [ -d ${COMPILE_DIR}/${module}_SRC ]
152 SOURCE_DIRS=${COMPILE_DIR}/${module}_SRC
155 for src in $LISTE_SRC
157 if [ -d ${COMPILE_DIR}/${src} ]
159 SOURCE_DIRS="$SOURCE_DIRS ${COMPILE_DIR}/${src}"
168 for SOURCE_DIR in ${SOURCE_DIRS}
171 echo -e "\n${isrc}) Compilation dans $SOURCE_DIR \n"
172 src=`basename $SOURCE_DIR`
173 SOURCE_NAME=${src%_SRC}
174 echo " -> Repertoire Source = ${SOURCE_DIR}"
175 echo " -> Component name = ${SOURCE_NAME}"
176 echo " -> Repertoire Build = ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD"
177 echo " -> Repertoire Install = ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL"
181 if [ $COMPILE_ONLY -eq 1 ]
183 if [ $BATCH_MODE -eq 0 ]
185 ask_confirmation "Compile ?"
187 cd ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD
192 echo "ERROR : build directory ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD not found"
193 echo " with -c option, build directory should already exist"
198 if [ $BATCH_MODE -eq 0 ]
200 ask_confirmation "build configure and configure ?"
205 echo "----------------- Build configure ---------------------"
208 echo "----------------- Configure ---------------------"
210 # crée ou vide les répertoires
211 check_dir ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD
212 check_dir ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL
213 cd ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD
214 ${SOURCE_DIR}/configure ${OPTIONS_CONFIGURE} --prefix=${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL | tee ${TMP_FILE}
216 echo "retour configure : $?"
218 if [ $BATCH_MODE -eq 0 ]
220 ask_confirmation "Compile ?"
222 export `echo ${SOURCE_NAME}`_ROOT_DIR=${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL
225 if [ $ENVIRON_FILE ] && [ -f $ENVIRON_FILE ]
227 # Mise à jour du script d'environnement
228 if [ $BATCH_MODE -eq 1 ]
230 update_environ ${SOURCE_NAME}_ROOT_DIR ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL ${SOURCE_NAME}_SRC_DIR ${SOURCE_DIR}
232 echo "Voulez vous mettre mettre à jour le script d'environnement ${ENVIRON_FILE} ?"
233 echo " (ajouter la variable ${SOURCE_NAME}_ROOT_DIR - une copie de l'ancien script est faite dans un .old)"
237 y* | Y* | o* | O* ) update_environ ${SOURCE_NAME}_ROOT_DIR ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_INSTALL ${SOURCE_NAME}_SRC_DIR ${SOURCE_DIR} ;;
247 # update environment scrip : add or replace ROOT_DIR and SRC_DIR variable for component
250 cp ${ENVIRON_FILE} ${ENVIRON_FILE}.old
251 if [ "${SHELL_EXT}" == "sh" ]
253 grep " $1" ${ENVIRON_FILE}.old > /dev/null
256 # if variable is already set, we replace old setting by new one
257 cat ${ENVIRON_FILE}.old | awk -v var_root_dir=$1 -v path=$2 -v src_root_dir=$3 -v src_dir=$4 '
258 $1=="export" && $2 ~ "^"var_root_dir"=" {print "#"$0; $0="export "var_root_dir "=" path}
259 $1=="export" && $2 ~ "^"src_root_dir"=" {print "#"$0; $0="export "src_root_dir "=" src_dir}
260 $1 ~ "^"var_root_dir"=" {print "#"$0; $0=var_root_dir "=" path}
261 $1 ~ "^"src_root_dir"=" {print "#"$0; $0=src_root_dir "=" src_dir}
262 { print $0}' > ${ENVIRON_FILE}
264 echo -e "##\n#------ ${SOURCE_NAME}-Src ------\nexport $3=$4" >> ${ENVIRON_FILE}
265 echo -e "##\n#------ ${SOURCE_NAME}-Bin ------\nexport $1=$2" >> ${ENVIRON_FILE}
266 if [ -d $2/lib ] && [ ! -d $2/lib/salome ]
268 # for salome modules, do nothing
269 echo -e "export PYTHONPATH=\${${1}}/bin:\${${1}}/lib:\${PYTHONPATH}" >> ${ENVIRON_FILE}
273 grep " $1" ${ENVIRON_FILE}.old > /dev/null
276 # if variable is already set, we replace old setting by new one
277 cat ${ENVIRON_FILE}.old | awk -v var_root_dir=$1 -v path=$2 -v src_root_dir=$3 -v src_dir=$4 '
278 $1=="setenv" && $2 == var_root_dir {print "#"$0; $0="setenv "var_root_dir " " path}
279 $1=="setenv" && $2 == src_root_dir {print "#"$0; $0="setenv "src_root_dir " " src_dir}
280 { print $0}' > ${ENVIRON_FILE}
282 echo -e "##\n#------ ${SOURCE_NAME}-Src ------\nsetenv $3 $4" >> ${ENVIRON_FILE}
283 echo -e "##\n#------ ${SOURCE_NAME}-Bin ------\nsetenv $1 $2" >> ${ENVIRON_FILE}
284 if [ -d $2/lib ] && [ ! -d $2/lib/salome ]
286 echo -e "setenv PYTHONPATH \${${1}}/bin:\${${1}}/lib:\${PYTHONPATH}" >> ${ENVIRON_FILE}
293 ########### Programme Principal #############
306 echo "Pas d'arguments!"
314 --disable-debug ) OPTIONS_CONFIGURE="${OPTIONS_CONFIGURE} --disable-debug" ;;
316 --batch) BATCH_MODE=1 ;;
318 --environ=*) set_environ ${arg#--environ=} ;;
320 --install=*) INSTALL_ROOT_DIR=${arg#--install=} ;;
322 --sources=*) LISTE_SRC="${LISTE_SRC} ${arg#--sources=}" ;;
324 --local | -l ) SRC_ROOT_DIR=$PWD ; INSTALL_ROOT_DIR=$PWD ;;
326 --compile-only | -c ) COMPILE_ONLY=1 ;;
328 *_SRC ) LISTE_SRC="${LISTE_SRC} ${arg}" ;;
330 *) LISTE_MODULE="${LISTE_MODULE} ${arg}" ;;
335 LISTE_SRC=`echo ${LISTE_SRC} | sed "s/,/ /g"` # replaces ',' by blanks
337 if [ ! $INSTALL_ROOT_DIR ]
339 echo Local installation
340 INSTALL_ROOT_DIR=$PWD
345 echo " ------------------------------------"
346 echo " | Utilitaire de Compilation Salome |"
347 echo " ------------------------------------"
350 echo "Liste des modules à parcourir : $LISTE_MODULE"
351 echo "Liste repertoire à compiler : $LISTE_SRC"
352 echo "Options configure : $OPTIONS_CONFIGURE"
353 echo "Environment File : $ENVIRON_FILE"
355 CR=/tmp/${USER}_SA_build_CR
358 if [ $ENVIRON_FILE ] && [ -f $ENVIRON_FILE ] # if an existing environment file was specified
360 # get shell extension
361 case ${ENVIRON_FILE##*\.} in
366 *) SHELL_EXT=sh;echo WARNING : shell extension not recognized! Assume sh ;;
368 if [ "${SHELL_EXT}" == "sh" ]
370 # if shell syntax is sh, source environment with ENV_FOR_LAUNCH set to 0
371 cat ${ENVIRON_FILE} | sed "s/ENV_FOR_LAUNCH=1/ENV_FOR_LAUNCH=0/g" > ${ENVIRON_FILE}.tmp
372 source ${ENVIRON_FILE}.tmp
373 rm ${ENVIRON_FILE}.tmp
374 echo source Environment File with ENV_FOR_LAUNCH=0
376 echo "WARNING : environment file has csh extension => cannot source it and assume environment already set."
377 echo -e " (if compilation fails, please set environment before, of choose an sh syntax file)\n"
380 echo Warning : Environment File Not Found!
384 if [ "$LISTE_MODULE" == "" ]
386 # no module specified -> lookup for sources localy
387 echo lookup for sources localy
389 for src in $LISTE_SRC
391 if [ -d ${LOCAL_DIR}/${src} ]
393 SOURCE_DIRS="$SOURCE_DIRS ${LOCAL_DIR}/${src}"
394 elif [ -d ${SRC_ROOT_DIR}/${src} ]
396 SOURCE_DIRS="$SOURCE_DIRS ${LOCAL_DIR}/${src}"
401 for module in $LISTE_MODULE
403 echo "----------------- Compilation dans $module ----------------"
412 echo -e "\n----------------- Résumé ----------------"