5 # salome2 environment file (.bash or .sh) - can also be specified with -e option
7 # if present, hxx2salome will try to compile new module, by sourcing ENVIRON_FILE file, and executing
8 # build_configure, configure, make & make install
9 # remark : hxx2salome has to be lanched with clean PATH, LD_LIBRARY_PATH & PYTHONPATH variables!
11 # options you want to pass to configure
14 # which wrappers to generate
29 echo -e "\n Usage :\n"
30 echo -e " Set HXX2SALOME_ROOT_DIR variable"
31 echo -e " ${HXX2SALOME_ROOT_DIR}/hxx2salome [options] "
32 echo -e " cppComponent_root_dir cppComponent.hxx"
33 echo -e " libcppComponent.so salomeComponentRoot\n"
34 echo -e " - cppComponent_root_dir : install directory (absolute path)"
35 echo -e " of the c++ component\n"
36 echo -e " - cppComponent.hxx : header of the component"
37 echo -e " - libcppComponent.so : library\n"
38 echo -e " (cppComponent.hxx and libcppComponent.so have to be found"
39 echo -e " in cppComponent_root_dir)\n"
40 echo -e " - salomeComponentRoot : directory of the source/build/install"
41 echo -e " of the Salome component\n"
43 echo -e " -h : this help"
45 echo -e " -q : be quiet"
47 echo -e " -x Lang : generate a wrapper to use the component"
48 echo -e " from language Lang where Lang can be "
49 echo -e " any of CORBA,C++,python"
50 echo -e " (several -x options can be specified)"
51 echo -e " default : generate all wrappers"
54 echo -e " -e environment_script : to specify the name of a environment file"
55 echo -e " that will be updated with new necessary commands"
56 echo -e " (this file is also used for sourcing environment"
57 echo -e " before compilation if it has sh or bash syntax,"
58 echo -e " if the syntax is csh, it is not sourced and for"
59 echo -e " compiling (-c option) environment must be set up"
62 echo -e " -s script_extension : to use if your environment file name doesn't"
63 echo -e " have extension"
65 echo -e " -g : to create a gui part in your component"
66 echo -e " building tree"
68 echo -e " -c : to compile after generation"
69 echo -e " (use this option only if you don't have"
70 echo -e " dependencies in your header or libraries"
71 echo -e " if it is the case, you'll have to adapt"
72 echo -e " your Makefile.am"
74 echo -e " -l : to launch salome "
81 echo "----------------------------------------------------------------------------"
85 echo " Automatic generation of a Salome2 component from a C++ component"
87 echo "----------------------------------------------------------------------------"
93 if [ "x$HXX2SALOME_ROOT_DIR" == "x" ]
98 source ${HXX2SALOME_ROOT_DIR}/hxx2salome_check
99 source ${HXX2SALOME_ROOT_DIR}/hxx2salome_corba
100 source ${HXX2SALOME_ROOT_DIR}/hxx2salome_cpp
103 # retrieve python test file ending up with _test.py
104 get_python_test_file()
107 for file in `find . -name "*_test.py"`
109 cp $file ${tmp_dir}/${CLASS_NAME}_SRC/src/${CLASS_NAME}
110 python_test_file=${python_test_file}" "`basename $file`
112 if [ ${BE_QUIET} -lt 1 ] ; then
113 echo -e "\nList of exported python file test : $python_test_file \n"
118 create_component_tree()
120 INSTALL_DIR=${salomeComponentRoot}/${CLASS_NAME}
122 export NEW_COMPONENT_SRC_DIR=${INSTALL_DIR}/${CLASS_NAME}_SRC
123 export NEW_COMPONENT_BUILD_DIR=${INSTALL_DIR}/${CLASS_NAME}_BUILD
124 export NEW_COMPONENT_ROOT_DIR=${INSTALL_DIR}/${CLASS_NAME}_INSTALL
126 \rm -rf ${NEW_COMPONENT_SRC_DIR}
127 mkdir -p ${NEW_COMPONENT_SRC_DIR}
133 makefile_lib="-L\${${CLASS_NAME}CPP_ROOT_DIR}${lib_dir#${CPP_ROOT_DIR}} -l${lib_file}"
134 makefile_include="-I\${${CLASS_NAME}CPP_ROOT_DIR}${hxx_dir#${CPP_ROOT_DIR}}"
136 if [ ${BE_QUIET} -lt 1 ] ; then
137 echo -e "\nlinking option : $makefile_lib"
138 echo -e "include option : $makefile_include"
143 generate_module_source()
147 # go in temporary directory to work on code generation
151 # ------------------------- parse hxx file : generic part ---------------------------------------
154 awk -f ${gene_dir}/parse01.awk | \
155 awk -f ${gene_dir}/parse1.awk | \
156 awk -f ${gene_dir}/parse2.awk \
158 sed -e "/${CLASS_NAME}/d" < temp > ${CLASS_NAME}_public_functions
160 if [ ${BE_QUIET} -lt 1 ] ; then
161 echo -e "\n-> Extract public functions\n"
163 if [ ! -s ${CLASS_NAME}_public_functions ]
166 echo -e " Sorry - No compatible function was found!"
167 echo -e " Please check your header file\n"
171 echo -e "\n\n-> Compatibility function\n"
172 cat ${CLASS_NAME}_public_functions | \
173 awk -v class_name=${CLASS_NAME} -f ${gene_dir}/parse30.awk
175 \rm -f hxx2salome_journal && touch hxx2salome_journal
177 if [ ${BE_QUIET} -lt 1 ] ; then
178 echo -e "\n-> Duplicate template module" | tee ../hxx2salome_journal
180 cp -rf ${gene_dir}/HXX2SALOME_GENERIC_CLASS_NAME_SRC ${CLASS_NAME}_SRC
181 cp -f ${gene_dir}/compile_HXX2SALOME_GENERIC_CLASS_NAME.sh compile_${CLASS_NAME}.sh
182 ${gene_dir}/renameSalomeModule -i HXX2SALOME_GENERIC_CLASS_NAME \
183 ${CLASS_NAME} ${CLASS_NAME}_SRC >> ../hxx2salome_journal
185 GEN=( `validate_generation_choices ${GEN[${iCPP}]} ${GEN[${iCORBA}]} ${GEN[${iPython}]}` )
186 echo "-> Wrappers generation : " C++ : ${GEN[${iCPP}]} CORBA : ${GEN[${iCORBA}]} Python : ${GEN[${iPython}]}
188 if [ "x${GEN[${iCORBA}]}" == "xyes" ] ; then
189 generate_corba_module_source
191 clean_corba_module_source
194 if [ "x${GEN[${iCPP}]}" == "xyes" ] ; then
195 generate_cpp_module_source
197 clean_cpp_module_source
203 echo "----------------- Configure -------------------"
205 echo "----------------- Compile ---------------------"
209 # compilation succeeded : we make install
211 echo "----------------- Install ---------------------"
220 if [ -z ${ENVIRON_FILE} ]
222 ENVIRON_FILE="${NEW_COMPONENT_SRC_DIR}/env_${CLASS_NAME}.${SHELL_EXT}"
225 if [ ${BE_QUIET} -lt 1 ] ; then
226 echo -e "\nEnvironment file : " $ENVIRON_FILE
228 if [ -e ${ENVIRON_FILE} ]
230 cp ${ENVIRON_FILE} ${ENVIRON_FILE}.old
232 touch ${ENVIRON_FILE}
234 if [ "${SHELL_EXT}" == "csh" ]
236 grep -q " ${CLASS_NAME}_SRC_DIR" ${ENVIRON_FILE}
240 echo -e "###\n#------ ${CLASS_NAME}-Src ------" >> ${ENVIRON_FILE}
241 echo -e "setenv ${CLASS_NAME}_BASE ${INSTALL_DIR}" >> ${ENVIRON_FILE}
242 echo -e "setenv ${CLASS_NAME}_SRC_DIR \${${CLASS_NAME}_BASE}/${CLASS_NAME}_SRC\n" >> ${ENVIRON_FILE}
245 grep -q " ${CLASS_NAME}_ROOT_DIR" ${ENVIRON_FILE}
249 echo -e "###\n#------ ${CLASS_NAME}-Bin ------" >> ${ENVIRON_FILE}
250 echo -e "setenv ${CLASS_NAME}_ROOT_DIR \${${CLASS_NAME}_BASE}/${CLASS_NAME}_INSTALL" >> ${ENVIRON_FILE}
251 echo -e "setenv ${CLASS_NAME}CPP_ROOT_DIR ${CPP_ROOT_DIR}" >> ${ENVIRON_FILE}
252 echo -e "setenv LD_LIBRARY_PATH \${${CLASS_NAME}CPP_ROOT_DIR}${lib_dir#${CPP_ROOT_DIR}}:\${LD_LIBRARY_PATH}" >> ${ENVIRON_FILE}
255 if [ "${SHELL_EXT}" == "sh" ]
257 grep -q " ${CLASS_NAME}_SRC_DIR=" ${ENVIRON_FILE}
261 echo -e "###\n#------ ${CLASS_NAME}-Src ------" >> ${ENVIRON_FILE}
262 echo -e "export ${CLASS_NAME}_BASE=${INSTALL_DIR}" >> ${ENVIRON_FILE}
263 echo -e "export ${CLASS_NAME}_SRC_DIR=\${${CLASS_NAME}_BASE}/${CLASS_NAME}_SRC\n" >> ${ENVIRON_FILE}
266 grep -q " ${CLASS_NAME}_ROOT_DIR=" ${ENVIRON_FILE}
270 echo -e "###\n#------ ${CLASS_NAME}-Bin ------" >> ${ENVIRON_FILE}
271 echo -e "export ${CLASS_NAME}_ROOT_DIR=\${${CLASS_NAME}_BASE}/${CLASS_NAME}_INSTALL" >> ${ENVIRON_FILE}
272 echo -e "export ${CLASS_NAME}CPP_ROOT_DIR=${CPP_ROOT_DIR}" >> ${ENVIRON_FILE}
273 echo -e "export LD_LIBRARY_PATH=\${${CLASS_NAME}CPP_ROOT_DIR}${lib_dir#${CPP_ROOT_DIR}}:\${LD_LIBRARY_PATH}" \
280 copy_component_source()
282 mv ${tmp_dir}/${CLASS_NAME}_SRC/* ${NEW_COMPONENT_SRC_DIR}
283 mkdir -p ${NEW_COMPONENT_BUILD_DIR}
284 mkdir -p ${NEW_COMPONENT_ROOT_DIR}
290 if [ ${BE_QUIET} -gt 0 ] ; then
293 echo -e "\n\nModule was created in ${NEW_COMPONENT_SRC_DIR}"
299 # ------------------------------------------------------------------------
300 # --------------------------- MAIN PROGRAM -------------------------------
301 # ------------------------------------------------------------------------
304 NEW_COMPONENT_ROOT_DIR=
305 NEW_COMPONENT_SRC_DIR=
306 NEW_COMPONENT_BUILD_DIR=
314 welcome # print some welcome info
316 while getopts "qcs:e:h:lgx:" Option
321 q) BE_QUIET=$[ ${BE_QUIET}+1 ] ;;
322 e) ENVIRON_FILE=$OPTARG;;
332 CORBA) GEN[$iCORBA]="yes" ;;
333 python) GEN[$iPython]="yes" ;;
334 C++) GEN[${iCPP}]="yes";;
337 *) echo "Unimplemented option chosen : $Option."
343 shift $(($OPTIND - 1))
345 # default behaviour is to generate all wrappers
347 if [ "x${GEN[${iCPP}]}${GEN[${iCORBA}]}${GEN[${iPython}]}" == "xnonono" ] ; then
348 for i in ${iCPP} ${iCORBA} ${iPython}
353 echo "-> Wrappers generation : " C++ : ${GEN[${iCPP}]} CORBA : ${GEN[${iCORBA}]} Python : ${GEN[${iPython}]}
357 # check number of other arguments
361 echo -e "\nBad number of arguments\n\n"
366 check_arguments $1 $2 $3 $4
368 # if there is a sh compatible environment file, source it
369 if [[ -n ${ENVIRON_FILE} && -f ${ENVIRON_FILE} ]]
371 # analyse extension of environment file
372 case ${ENVIRON_FILE##*\.} in
380 # Environment policy :
381 # - an existing sh file was specified : we source environment file
382 # - else (no file or csh syntax) : we don't source environment file, and do compile
383 # only if KERNEL_ROOT_DIR and MED_ROOT_DIR are defined
384 if [ "${SHELL_EXT}" == "sh" ] && [ ${ENVIRON_FILE} ] && [ -f ${ENVIRON_FILE} ]
386 echo -e "\n Environment file with sh syntax specified => we source ${ENVIRON_FILE}"
387 source ${ENVIRON_FILE}
391 if [ ${HXX2SALOME_ROOT_DIR} ] && [ -d ${HXX2SALOME_ROOT_DIR} ]
393 gene_dir=${HXX2SALOME_ROOT_DIR}
395 gene_dir=`pwd` # case where hxx2salome was launched from HXX2SALOME directory
402 if [ ${BE_QUIET} -lt 1 ] ; then
403 echo " hxx2salome directory : $gene_dir"
405 if [ ! -f ${gene_dir}/parse1.awk -o ! -f ${gene_dir}/parse2.awk ] # check if script are found
407 echo -e "\nError : Variable HXX2SALOME_ROOT_DIR shoud be set, or hxx2salome should be launched localy from bin directory"
413 CLASS_NAME=`awk '$1 == "class" && $0 !~ /;/ {print $2}' ${hxx_file}|awk -F: '{print $1}'`
414 echo " Name of class :" $CLASS_NAME
417 echo -e "\nError:\n Sorry - No class definition was found!\n Please check your header file\n"
422 # create temporary working directory
424 tmp_dir="/tmp/${USER}/${CLASS_NAME}"
433 # --------------------- Generation of module source from template ------------------------------------------
436 generate_module_source
439 # ---------------------- Installation of new module sources ------------------------------------------------
441 create_component_tree
444 # ---------------------- Modification of Salome environment file -------------------------------------------
447 export `echo ${CLASS_NAME}`_ROOT_DIR=${NEW_COMPONENT_ROOT_DIR} # to avoid resource env for compiling and launching salome
448 export `echo ${CLASS_NAME}`CPP_ROOT_DIR=${CPP_ROOT_DIR} # idem
450 # ---------------------- Copy the generated source from temp dir -------------------------------------------
452 copy_component_source
457 echo -e "\nGeneration done\n"