Salome HOME
- display error message
authorcrouzet <crouzet>
Tue, 13 Dec 2005 16:03:29 +0000 (16:03 +0000)
committercrouzet <crouzet>
Tue, 13 Dec 2005 16:03:29 +0000 (16:03 +0000)
- update of csh environment file

scripts/SA_build

index 715b9fd7b0a6540beaca2780128570284fde3949..61c81b796352ce4daae931fbc8fdbdd96c671f0a 100755 (executable)
@@ -39,8 +39,10 @@ usage()
     echo "  --disable-debug : compilation without debug traces"
     echo "  --batch         : compilation is done in batch mode - no prompting"
     echo "  --environ=path  : set environment file to path (should be absolute)"
-    echo "  --install=path  : set install directory where module building is done (should be absolute)"
-    echo "  --compile-only -c  : no building - just compile by calling make && make install"
+    echo "                    this file will be updated with new environment variables. "
+    echo "                    it will also be sources if it has sh syntax"
+    echo "  --install=path  : set install directory where module building and install is done (should be absolute)"
+    echo "  --compile-only -c  : no building and configure - just compile by calling make && make install"
     echo "  --local -l      : look for source directories localy - build and install localy"
     echo "  --sources=src1,src2,...  : for specifying source directories that don't end up with _SRC"
     echo 
@@ -109,12 +111,20 @@ compile()
     make 
     if [ $? -eq 0 ]
     then
-       # compilation succeeded : we make install
+       echo -e "\n     [OK] Compile : ${module}/${SOURCE_NAME}_SRC" >> $CR
+       echo Compilation succeeded : we make install
        echo
        echo "----------------- Install ---------------------"
        make install
+       if [ $? -eq 0 ]
+       then
+           echo -e "     [OK] Install : ${module}/${SOURCE_NAME}_SRC" >> $CR
+        else
+           echo -e "     [KO] Install : ${module}/${SOURCE_NAME}_SRC" >> $CR
+       fi    
     else
-        exit 1
+       echo Compilation failed
+       echo -e "\n     [KO] Compile : ${module}/${SOURCE_NAME}_SRC" >> $CR
     fi
 }
 
@@ -171,7 +181,14 @@ build_source_dir()
               ask_confirmation "Compile ?"
            fi
           cd ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD
-          compile
+          if [ $? -eq 0 ]
+          then
+              compile
+          else
+              echo "ERROR : build directory ${INSTALL_ROOT_DIR}/${module}/${SOURCE_NAME}_BUILD  not found"
+              echo "        with -c option, build directory should already exist"
+              exit
+          fi    
        else
 
           if [ $BATCH_MODE -eq 0 ]
@@ -227,19 +244,35 @@ build_source_dir()
 update_environ()
 {
     cp ${ENVIRON_FILE} ${ENVIRON_FILE}.old
-    grep " $1" ${ENVIRON_FILE}.old > /dev/null
-    if [ $? -eq 0 ]
+    if [ "${SHELL_EXT}" == "sh" ]
     then
-       # if variable is already set, we replace old setting by new one
-       cat ${ENVIRON_FILE}.old | awk -v var_root_dir=$1 -v path=$2 -v src_root_dir=$3 -v src_dir=$4 '
-           $1=="export" && $2 ~ "^"var_root_dir"=" {print "#"$0; $0="export "var_root_dir "=" path}
-           $1=="export" && $2 ~ "^"src_root_dir"=" {print "#"$0; $0="export "src_root_dir "=" src_dir}
-          $1 ~ "^"var_root_dir"=" {print "#"$0; $0=var_root_dir "=" path}
-          $1 ~ "^"src_root_dir"=" {print "#"$0; $0=src_root_dir "=" src_dir}
-          { print $0}'  > ${ENVIRON_FILE}
+       grep " $1" ${ENVIRON_FILE}.old > /dev/null
+       if [ $? -eq 0 ]
+       then
+          # if variable is already set, we replace old setting by new one
+          cat ${ENVIRON_FILE}.old | awk -v var_root_dir=$1 -v path=$2 -v src_root_dir=$3 -v src_dir=$4 '
+              $1=="export" && $2 ~ "^"var_root_dir"=" {print "#"$0; $0="export "var_root_dir "=" path}
+              $1=="export" && $2 ~ "^"src_root_dir"=" {print "#"$0; $0="export "src_root_dir "=" src_dir}
+              $1 ~ "^"var_root_dir"=" {print "#"$0; $0=var_root_dir "=" path}
+              $1 ~ "^"src_root_dir"=" {print "#"$0; $0=src_root_dir "=" src_dir}
+              { print $0}'  > ${ENVIRON_FILE}
+       else
+          echo -e "##\n#------ ${SOURCE_NAME}-Src ------\nexport $3=$4" >> ${ENVIRON_FILE}
+          echo -e "##\n#------ ${SOURCE_NAME}-Bin ------\nexport $1=$2" >> ${ENVIRON_FILE}
+       fi
     else
-       echo -e "##\n#------ ${SOURCE_NAME}-Src ------\nexport $3=$4" >> ${ENVIRON_FILE}
-       echo -e "##\n#------ ${SOURCE_NAME}-Bin ------\nexport $1=$2" >> ${ENVIRON_FILE}
+       grep " $1" ${ENVIRON_FILE}.old > /dev/null
+       if [ $? -eq 0 ]
+       then
+          # if variable is already set, we replace old setting by new one
+          cat ${ENVIRON_FILE}.old | awk -v var_root_dir=$1 -v path=$2 -v src_root_dir=$3 -v src_dir=$4 '
+              $1=="setenv" && $2 == var_root_dir {print "#"$0; $0="setenv "var_root_dir " " path}
+              $1=="setenv" && $2 == src_root_dir {print "#"$0; $0="setenv "src_root_dir " " src_dir}
+              { print $0}'  > ${ENVIRON_FILE}
+       else
+          echo -e "##\n#------ ${SOURCE_NAME}-Src ------\nsetenv $3 $4" >> ${ENVIRON_FILE}
+          echo -e "##\n#------ ${SOURCE_NAME}-Bin ------\nsetenv $1 $2" >> ${ENVIRON_FILE}
+       fi
     fi
 }
 
@@ -305,14 +338,30 @@ echo "Liste repertoire 
 echo "Options configure             : $OPTIONS_CONFIGURE"
 echo "Environment File              : $ENVIRON_FILE"
 echo
+CR=/tmp/${USER}_SA_build_CR
+echo -e "\n" > $CR
 
-if [ $ENVIRON_FILE ]  && [ -f $ENVIRON_FILE ]
+if [ $ENVIRON_FILE ]  && [ -f $ENVIRON_FILE ]  # if an existing environment file was specified
 then
-    # force option for compilation - then source environment
-    cat ${ENVIRON_FILE} | sed "s/ENV_FOR_LAUNCH=1/ENV_FOR_LAUNCH=0/g" > ${ENVIRON_FILE}.tmp
-    source ${ENVIRON_FILE}.tmp
-    rm ${ENVIRON_FILE}.tmp
-    echo source Environment File with ENV_FOR_LAUNCH=0
+    # get shell extension
+    case ${ENVIRON_FILE##*\.} in 
+       bash) SHELL_EXT=sh;;
+       ksh)  SHELL_EXT=sh;;
+       csh)  SHELL_EXT=csh;;
+       sh)   SHELL_EXT=sh;;
+       *)    SHELL_EXT=sh;echo WARNING : shell extension not recognized! Assume sh ;;
+    esac
+    if [ "${SHELL_EXT}" == "sh" ]
+    then
+    #   if shell syntax is sh, source environment with ENV_FOR_LAUNCH set to 0
+        cat ${ENVIRON_FILE} | sed "s/ENV_FOR_LAUNCH=1/ENV_FOR_LAUNCH=0/g" > ${ENVIRON_FILE}.tmp
+        source ${ENVIRON_FILE}.tmp
+        rm ${ENVIRON_FILE}.tmp
+        echo source Environment File with ENV_FOR_LAUNCH=0
+    else
+        echo "WARNING : environment file has csh extension => cannot source it and assume environment already set."
+       echo -e "          (if compilation fails, please set environment before, of choose an sh syntax file)\n"
+    fi
 else
     echo Warning : Environment File Not Found!
 fi
@@ -346,3 +395,5 @@ else
     done
 fi
 
+echo -e "\n----------------- Résumé ----------------"
+cat ${CR}