product_env=${install_work}/env_${product_name}.sh
(test -e ${product_env} && rm ${product_env} )
fi
-### !!! writing salome.sh file !!! -> add global functions
+### !!! writing salome.sh file !!! -> define INSTALL_ROOT
cat >> ${install_work}/$SHRC <<EOF
+#${DELIM} Setting products installation directory ${DELIM}
export INSTALL_ROOT=${install_root}
-#$DELIM globals $DELIM
-setenvp() {
- xenv=\$2:\`printenv \$1\`
- out_var=\`echo \$xenv | awk -F: '{n=0 ; for(i=1;i<=NF;i++){v=\$i;t=1;for(j=0;j<=n;j++){if(keys[j]==v){t=0;break;}};if(t)keys[n++]=v} ; for(j=0;j<n;j++){printf "%s",keys[j];if(j<n-1) printf ":"} ; printf "\n"}'\`
- export \$1=\$out_var
-}
-setenva() {
- xenv=\`printenv \$1\`:\$2
- out_var=\`echo \$xenv | awk -F: '{n=0 ; for(i=NF;i>=1;i--){v=\$i;t=1;for(j=0;j<=n;j++){if(keys[j]==v){t=0;break;}};if(t)keys[n++]=v} ; for(j=n-1;j>=0;j--){printf "%s",keys[j];if(j>0) printf ":"} ; printf "\n"}'\`
- export \$1=\$out_var
-}
+#${DELIM} Environment switch: 0 for SALOME building, 1 for SALOME launching ${DELIM}
+export ENV_FOR_LAUNCH=1
+
EOF
-### !!! writing salome.csh file !!! -> add global aliases
-cat >> ${install_work}/$CSHRC <<EOF
-setenv INSTALL_ROOT ${install_root}
-#$DELIM globals $DELIM
-alias cleandup "echo \!:1 | awk -F: '"'{n=0 ; for(i=1;i<=NF;i++){v=\$i;t=1;for(j=0;j<=n;j++){if(keys[j]==v){t=0;break;}};if(t)keys[n++]=v} ; for(j=0;j<n;j++){printf "%s",keys[j];if(j<n-1) printf ":"} ; printf "\n"}'"'"
-alias cleandupr "echo \!:1 | awk -F: '"'{n=0 ; for(i=NF;i>=1;i--){v=\$i;t=1;for(j=0;j<=n;j++){if(keys[j]==v){t=0;break;}};if(t)keys[n++]=v} ; for(j=n-1;j>=0;j--){printf "%s",keys[j];if(j>0) printf ":"} ; printf "\n"}'"'"
+### !!! The next is for RedHat 9 only !!!
+if [ -f /etc/redhat-release ] ; then
+ grep -e "Red Hat Linux release 9" /etc/redhat-release > /dev/null
+ if [ $? -eq 0 ] ; then
+ cat >> ${install_work}/$SHRC <<EOF
+#${DELIM} Force RH9 to use old implementation of threads ${DELIM}
+export LD_ASSUME_KERNEL=2.4.18
-alias setenva 'set a="\!:1" ; set b=\`printenv \$a\`:"'\!:2'" ; set b=\`cleandupr \$b\` ; setenv \$a \$b ; unset a, b'
-alias setenvp 'set a="\!:1" ; set b="'\!:2'":\`printenv \$a\` ; set b=\`cleandup \$b\` ; setenv \$a \$b ; unset a, b'
EOF
+ fi
+fi
### !!! writing salome.csh file !!! -> set inital variables
-pre_vars="PATH LD_LIBRARY_PATH LD_RUN_PATH PYTHONPATH"
+pre_vars="PATH LD_LIBRARY_PATH LD_RUN_PATH PYTHONPATH TCLLIBPATH"
for i in $pre_vars ; do
cat >> ${install_work}/$CSHRC <<EOF
-#$DELIM initial settings $DELIM
+#${DELIM} setting initial ${i} ${DELIM}
if (! (\$?${i}) ) then
setenv $i
endif
+
EOF
done
-### !!! writing salome.(c)sh files !!! -> dump products environment files, changing 'export' by 'setenv(a|b)' where necessary
+
+### !!! writing salome.(c)sh files !!! -> dump products environment files, changing 'export' by 'setenv(a|p)' where necessary
+### Note, that for performance reasons temporary environment files used during installation procedure itself
+### are created without using setenv(a|p) aliases.
+
+# 1. first dump all environment files into the $SHRC file
product_sequence="$2"
for i in $product_sequence ; do
- sed -e 's%^export\([[:blank:]]*\)PATH=\$[{]\?PATH[}]\?:\(.*\)%setenva\1PATH \2%g' -e 's%^export\([[:blank:]]*\)PATH=\(.*\):\$[{]\?PATH[}]\?%setenvp\1PATH \2%g' ${install_work}/env_${i}.sh > ${INSTALL_WORK}/_tmp1 2>/dev/null
- sed -e 's%^export\([[:blank:]]*\)LD_LIBRARY_PATH=\$[{]\?LD_LIBRARY_PATH[}]\?:\(.*\)%setenva\1LD_LIBRARY_PATH \2%g' -e 's%^export\([[:blank:]]*\)LD_LIBRARY_PATH=\(.*\):\$[{]\?LD_LIBRARY_PATH[}]\?%setenvp\1LD_LIBRARY_PATH \2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
- sed -e 's%^export\([[:blank:]]*\)PYTHONPATH=\$[{]\?PYTHONPATH[}]\?:\(.*\)%setenva\1PYTHONPATH \2%g' -e 's%^export\([[:blank:]]*\)PYTHONPATH=\(.*\):\$[{]\?PYTHONPATH[}]\?%setenvp\1PYTHONPATH \2%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
- sed -e 's%^export\([[:blank:]]*\)LD_RUN_PATH=\$[{]\?LD_RUN_PATH[}]\?:\(.*\)%setenva\1LD_RUN_PATH \2%g' -e 's%^export\([[:blank:]]*\)LD_RUN_PATH=\(.*\):\$[{]\?LD_RUN_PATH[}]\?%setenvp\1LD_RUN_PATH \2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
- cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/$SHRC 2>/dev/null
-
- sed -e 's%^export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
- cat ${INSTALL_WORK}/_tmp1 >> ${install_work}/$CSHRC 2>/dev/null
-
- rm -f ${INSTALL_WORK}/_tmp1 ${INSTALL_WORK}/_tmp2
-done
+ cat ${install_work}/env_${i}.sh >> ${install_work}/$SHRC 2>/dev/null
+done
+
+# 2. writing global functions to _salome.sh file
+cat >> ${install_work}/_$SHRC <<EOF
+##########################################################################
+# Functions exporta and exportp are used to append/prepend correspondingly
+# one directory or a set of directories separated by semicolon symbol (':')
+# to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
+# LD_RUN_PATH etc.
+# The main purpose is to replace default setenv command behavior:
+# exporta, exportp also remove duplicated entries, shortening in that way
+# the environment variables.
+# If some directory being added is already included into the variable
+# nothing is done for it.
+# Note, that these functions work some slower that setenv command itself.
+#
+#### cleandup ###
+# appends/prepends set of directories (second parameter)
+# to the another set of directories (first parameter) and
+# removes duplicated entries;
+# the third parameter defines the mode: 0 - append, 1 - prepend
+cleandup() {
+out_var=\`echo \$1 \$2 | awk -v dir=\$3 '{ \\
+ na = split(\$2,a,":"); \\
+ if ( \$1 == "<empty>") nb = split("",b,":"); \\
+ else nb = split(\$1,b,":"); \\
+ s = "" ; \\
+ for(i=1;i<=nb;i++) { \\
+ if(!(b[i] in ccc)) { \\
+ if(length(s)!=0) \\
+ s = sprintf("%s:",s); \\
+ s = sprintf("%s%s",s,b[i]); \\
+ ccc[b[i]]; \\
+ }; \\
+ }; \\
+ s1 = ""; \\
+ for(i=1;i<=na;i++) { \\
+ if(!(a[i] in ccc)) { \\
+ if(length(s1)!=0) \\
+ s1 = sprintf("%s:",s1); \\
+ s1 = sprintf("%s%s",s1,a[i]); \\
+ ccc[a[i]]; \\
+ }; \\
+ }; \\
+ if(dir) \\
+ s = length(s) == 0 ? s1 : sprintf("%s:%s",s1,s); \\
+ else \\
+ s = length(s1) == 0 ? s : sprintf("%s:%s",s,s1); \\
+ printf("%s\n",s); \\
+ }'\`
+echo \$out_var
+}
+### exporta ###
+# appends directory or set of directories, separated by ':' (second parameter)
+# to the variable (first parameter)
+exporta () {
+xenv=\`printenv \$1\`
+if [ -z "\$xenv" ]; then xenv="<empty>"; fi
+out_var=\`cleandup \$xenv \$2 0\`
+export \$1=\$out_var
+}
+### exportp ###
+# prepends directory or set of directories, separated by ':' (second parameter)
+# to the variable (first parameter)
+exportp () {
+xenv=\`printenv \$1\`
+if [ -z "\$xenv" ]; then xenv="<empty>"; fi
+out_var=\`cleandup \$xenv \$2 1\`
+export \$1=\$out_var
+}
+###########################################################################
+
+EOF
+
+# 3. writing global functions to _salome.csh file
+cat >> ${install_work}/_$CSHRC <<EOF
+###########################################################################
+# Aliases setenva and setenvp are used to append/prepend correspondingly
+# one directory or a set of directories separated by semicolon symbol (':')
+# to the environment variables like PATH, LD_LIBRARY_PATH, PYTHONPATH,
+# LD_RUN_PATH etc.
+# The main purpose is to replace default setenv command behavior:
+# setenva, setenvp also remove duplicated entries, shortening in that way
+# the environment variables.
+# If some directory being added is already included into the variable
+# nothing is done for it.
+# Note, that these aliases work some slower that setenv command itself.
+#
+#### cleandup ###
+# appends/prepends set of directories (second parameter)
+# to the another set of directories (first parameter) and
+# removes duplicated entries;
+# the third parameter defines the mode: 0 - append, 1 - prepend
+alias cleandup "echo \!:1 \!:2 | awk -v dir=\!:3 \\\\
+'"'{ na = split(\$2,a,":"); \\\\
+ nb = split(\$1,b,":"); \\\\
+ s = "" ; \\\\
+ for(i=1;i<=nb;i++) { \\\\
+ if(!(b[i] in ccc)) { \\\\
+ if(length(s)!=0) \\\\
+ s = sprintf("%s:",s); \\\\
+ s = sprintf("%s%s",s,b[i]); \\\\
+ ccc[b[i]]; \\\\
+ }; \\\\
+ }; \\\\
+ s1 = ""; \\\\
+ for(i=1;i<=na;i++) { \\\\
+ if(!(a[i] in ccc)) { \\\\
+ if(length(s1)!=0) \\\\
+ s1 = sprintf("%s:",s1); \\\\
+ s1 = sprintf("%s%s",s1,a[i]); \\\\
+ ccc[a[i]]; \\\\
+ }; \\\\
+ }; \\\\
+ if(dir) \\\\
+ s = length(s) == 0 ? s1 : sprintf("%s:%s",s1,s); \\\\
+ else \\\\
+ s = length(s1) == 0 ? s : sprintf("%s:%s",s,s1); \\\\
+ printf("%s\n",s); \\\\
+ }'"'"
+### setenva ###
+# appends directory or set of directories, separated by ':' (second parameter)
+# to the variable (first parameter)
+alias setenva 'set a=\!:1 ; set b=\!:2 ; \\
+ set c=\`printenv \$a\` ; \\
+ set b=\`cleandup \$c \$b 0\` ; \\
+ setenv \$a \$b ; \\
+ unset a, b, c'
+
+### setenvp ###
+# prepends directory or set of directories, separated by ':' (second parameter)
+# to the variable (first parameter)
+alias setenvp 'set a=\!:1 ; set b=\!:2 ; \\
+ set c=\`printenv \$a\` ; \\
+ set b=\`cleandup \$c \$b 1\` ; \\
+ setenv \$a \$b ; \\
+ unset a, b, c'
+###########################################################################
+
+EOF
+cat ${install_work}/$CSHRC >> ${install_work}/_$CSHRC
+
+# 4. put the contents of salome.sh to _salome.sh replacing export by export(a|p) aliases where necessary
+sed -e 's%export\([[:blank:]]*\)PATH=\$[{]\?PATH[}]\?:\(.*\)%exporta\1PATH \2%g' -e 's%export\([[:blank:]]*\)PATH=\(.*\):\$[{]\?PATH[}]\?%exportp\1PATH \2%g' ${install_work}/$SHRC > ${INSTALL_WORK}/_tmp1 2>/dev/null
+sed -e 's%export\([[:blank:]]*\)LD_LIBRARY_PATH=\$[{]\?LD_LIBRARY_PATH[}]\?:\(.*\)%exporta\1LD_LIBRARY_PATH \2%g' -e 's%export\([[:blank:]]*\)LD_LIBRARY_PATH=\(.*\):\$[{]\?LD_LIBRARY_PATH[}]\?%exportp\1LD_LIBRARY_PATH \2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
+sed -e 's%export\([[:blank:]]*\)PYTHONPATH=\$[{]\?PYTHONPATH[}]\?:\(.*\)%exporta\1PYTHONPATH \2%g' -e 's%export\([[:blank:]]*\)PYTHONPATH=\(.*\):\$[{]\?PYTHONPATH[}]\?%exportp\1PYTHONPATH \2%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
+sed -e 's%export\([[:blank:]]*\)LD_RUN_PATH=\$[{]\?LD_RUN_PATH[}]\?:\(.*\)%exporta\1LD_RUN_PATH \2%g' -e 's%export\([[:blank:]]*\)LD_RUN_PATH=\(.*\):\$[{]\?LD_RUN_PATH[}]\?%exportp\1LD_RUN_PATH \2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2
+cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/_$SHRC
+
+# 5. Create a salome.csh file from salome.sh by replacing export by setenv, etc.
+sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${install_work}/$SHRC > ${INSTALL_WORK}/_tmp1 2>/dev/null
+cat ${INSTALL_WORK}/_tmp1 >> ${install_work}/$CSHRC
+
+# 6. Create a _salome.csh file from _salome.sh by replacing export by setenv, exporta by setenva, etc.
+sed -e 's%export \([[:alnum:]_[:blank:]]*\)\=%setenv \1 %g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
+sed -e 's%exporta \([[:alnum:]_[:blank:]]*\)%setenva \1%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
+sed -e 's%exportp \([[:alnum:]_[:blank:]]*\)%setenvp \1%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
+sed -e 's%if \[ -n "\${ENV_FOR_LAUNCH}" \] ; then%if ( ${?ENV_FOR_LAUNCH} ) then%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
+sed -e 's%if \[ "\${ENV_FOR_LAUNCH}" == "1" \] ; then%if ( "\${ENV_FOR_LAUNCH}" == "1" ) then%g' ${INSTALL_WORK}/_tmp2 > ${INSTALL_WORK}/_tmp1 2>/dev/null
+sed -e 's%^\([[:blank:]]*\)fi\([[:blank:]]*\)$%\1endif\2%g' ${INSTALL_WORK}/_tmp1 > ${INSTALL_WORK}/_tmp2 2>/dev/null
+cat ${INSTALL_WORK}/_tmp2 >> ${install_work}/_$CSHRC 2>/dev/null
+
+rm -f ${INSTALL_WORK}/_tmp1 ${INSTALL_WORK}/_tmp2
if [ $# -eq 4 ] ; then
product_dir=$4
if [ -e ${product_dir} ] ; then
- cp -f ${install_work}/$SHRC ${install_work}/$CSHRC ${product_dir}/.
+ cp -f ${install_work}/_$SHRC ${product_dir}/$SHRC
+ cp -f ${install_work}/_$CSHRC ${product_dir}/$CSHRC
fi
fi
-cp -f ${install_work}/$CSHRC ${install_root}/env_products.csh
-cp -f ${install_work}/$SHRC ${install_root}/env_products.sh
+sed -e 's%setenv ENV_FOR_LAUNCH 1%setenv ENV_FOR_LAUNCH 0%' ${install_work}/_$CSHRC > ${install_root}/env_products.csh
+sed -e 's%export ENV_FOR_LAUNCH=1%export ENV_FOR_LAUNCH=0%' ${install_work}/_$SHRC > ${install_root}/env_products.sh
+rm -f ${install_work}/_$SHRC
+rm -f ${install_work}/_$CSHRC
+### !!! copying build.csh script
+if [ -e ./build.csh ]; then
+ cp -f ./build.csh ${install_root}
+fi
}
#try use already existing product
echo $arg1:$arg2
fi
return $to_tail
-}
\ No newline at end of file
+}
+
+where_tcl(){
+if test -z "${TCLHOME}"; then
+ TCLHOME=/usr
+fi
+tclcfg=`find ${TCLHOME}/lib -name "tclConfig.sh" 2> /dev/null`
+file=""
+maxver=0
+for f in $tclcfg; do
+ ver=`cat $f | grep -e "TCL_VERSION=.*" | sed -e "s%TCL_VERSION=[\'|\"]\(.*\)[\'|\"]%\1%g" | awk -F. '{x=0;for(i=1;i<=3;i++){x=x*100;if(i<=NF)x+=$i;}print x;}'`
+ if [ $maxver -lt $ver ]; then
+ maxver=$ver
+ file=$f
+ fi
+done
+if test -n "$file"; then
+ echo `dirname $file`
+ return 0
+else
+ echo ""
+ return 1
+fi
+}
+
+where_tk(){
+if test -z "${TCLHOME}"; then
+ TCLHOME=/usr
+fi
+tclcfg=`find ${TCLHOME}/lib -name "tkConfig.sh" 2> /dev/null`
+file=""
+maxver=0
+for f in $tclcfg; do
+ ver=`cat $f | grep -e "TK_VERSION=.*" | sed -e "s%TK_VERSION=[\'|\"]\(.*\)[\'|\"]%\1%g" | awk -F. '{x=0;for(i=1;i<=3;i++){x=x*100;if(i<=NF)x+=$i;}print x;}'`
+ if [ $maxver -lt $ver ]; then
+ maxver=$ver
+ file=$f
+ fi
+done
+if test -n "$file"; then
+ echo `dirname $file`
+ return 0
+else
+ echo ""
+ return 1
+fi
+}