2 # Copyright (C) 2006-2008 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # salome2 environment file (.bash or .sh) - can also be specified with -e option
25 # if present, hxx2salome will try to compile new module, by sourcing ENVIRON_FILE file, and executing
26 # build_configure, configure, make & make install
27 # remark : hxx2salome has to be lanched with clean PATH, LD_LIBRARY_PATH & PYTHONPATH variables!
29 # options you want to pass to configure
32 # which wrappers to generate
47 echo -e "\n Usage :\n"
48 echo -e " Set HXX2SALOME_ROOT_DIR variable"
49 echo -e " ${HXX2SALOME_ROOT_DIR}/hxx2salome [options] "
50 echo -e " cppComponent_root_dir cppComponent.hxx"
51 echo -e " libcppComponent.so salomeComponentRoot\n"
52 echo -e " - cppComponent_root_dir : install directory (absolute path)"
53 echo -e " of the c++ component\n"
54 echo -e " - cppComponent.hxx : header of the component"
55 echo -e " - libcppComponent.so : library\n"
56 echo -e " (cppComponent.hxx and libcppComponent.so have to be found"
57 echo -e " in cppComponent_root_dir)\n"
58 echo -e " - salomeComponentRoot : directory of the source/build/install"
59 echo -e " of the Salome component\n"
61 echo -e " -h : this help"
63 echo -e " -q : be quiet"
65 echo -e " -x Lang : generate a wrapper to use the component"
66 echo -e " from language Lang where Lang can be "
67 echo -e " any of CORBA,C++,python"
68 echo -e " (several -x options can be specified)"
69 echo -e " default : generate all wrappers"
72 echo -e " -e environment_script : to specify the name of a environment file"
73 echo -e " that will be updated with new necessary commands"
74 echo -e " (this file is also used for sourcing environment"
75 echo -e " before compilation if it has sh or bash syntax,"
76 echo -e " if the syntax is csh, it is not sourced and for"
77 echo -e " compiling (-c option) environment must be set up"
80 echo -e " -s script_extension : to use if your environment file name doesn't"
81 echo -e " have extension"
83 echo -e " -g : to create a gui part in your component"
84 echo -e " building tree"
86 echo -e " -c : to compile after generation"
87 echo -e " (use this option only if you don't have"
88 echo -e " dependencies in your header or libraries"
89 echo -e " if it is the case, you'll have to adapt"
90 echo -e " your Makefile.am"
92 echo -e " -l : to launch salome "
99 echo "----------------------------------------------------------------------------"
103 echo " Automatic generation of a Salome2 component from a C++ component"
105 echo "----------------------------------------------------------------------------"
111 if [ "x$HXX2SALOME_ROOT_DIR" == "x" ]
116 source ${HXX2SALOME_ROOT_DIR}/hxx2salome_check
117 source ${HXX2SALOME_ROOT_DIR}/hxx2salome_corba
118 source ${HXX2SALOME_ROOT_DIR}/hxx2salome_cpp
121 # retrieve python test file ending up with _test.py
122 get_python_test_file()
125 for file in `find . -name "*_test.py"`
127 cp $file ${tmp_dir}/${CLASS_NAME}_SRC/src/${CLASS_NAME}
128 python_test_file=${python_test_file}" "`basename $file`
130 if [ ${BE_QUIET} -lt 1 ] ; then
131 echo -e "\nList of exported python file test : $python_test_file \n"
136 create_component_tree()
138 INSTALL_DIR=${salomeComponentRoot}/${CLASS_NAME}
140 export NEW_COMPONENT_SRC_DIR=${INSTALL_DIR}/${CLASS_NAME}_SRC
141 export NEW_COMPONENT_BUILD_DIR=${INSTALL_DIR}/${CLASS_NAME}_BUILD
142 export NEW_COMPONENT_ROOT_DIR=${INSTALL_DIR}/${CLASS_NAME}_INSTALL
144 \rm -rf ${NEW_COMPONENT_SRC_DIR}
145 mkdir -p ${NEW_COMPONENT_SRC_DIR}
151 makefile_lib="-L\${${CLASS_NAME}CPP_ROOT_DIR}${lib_dir#${CPP_ROOT_DIR}} -l${lib_file}"
152 makefile_include="-I\${${CLASS_NAME}CPP_ROOT_DIR}${hxx_dir#${CPP_ROOT_DIR}}"
154 if [ ${BE_QUIET} -lt 1 ] ; then
155 echo -e "\nlinking option : $makefile_lib"
156 echo -e "include option : $makefile_include"
161 generate_module_source()
165 # go in temporary directory to work on code generation
169 # ------------------------- parse hxx file : generic part ---------------------------------------
172 awk -f ${gene_dir}/parse01.awk | \
173 awk -f ${gene_dir}/parse1.awk | \
174 awk -f ${gene_dir}/parse2.awk \
176 sed -e "/${CLASS_NAME}/d" < temp > ${CLASS_NAME}_public_functions
178 if [ ${BE_QUIET} -lt 1 ] ; then
179 echo -e "\n-> Extract public functions\n"
181 if [ ! -s ${CLASS_NAME}_public_functions ]
184 echo -e " Sorry - No compatible function was found!"
185 echo -e " Please check your header file\n"
189 echo -e "\n\n-> Compatibility function\n"
190 cat ${CLASS_NAME}_public_functions | \
191 awk -v class_name=${CLASS_NAME} -f ${gene_dir}/parse30.awk
193 \rm -f hxx2salome_journal && touch hxx2salome_journal
195 if [ ${BE_QUIET} -lt 1 ] ; then
196 echo -e "\n-> Duplicate template module" | tee ../hxx2salome_journal
198 cp -rf ${gene_dir}/HXX2SALOME_GENERIC_CLASS_NAME_SRC ${CLASS_NAME}_SRC
199 cp -f ${gene_dir}/compile_HXX2SALOME_GENERIC_CLASS_NAME.sh compile_${CLASS_NAME}.sh
200 ${gene_dir}/renameSalomeModule -i HXX2SALOME_GENERIC_CLASS_NAME \
201 ${CLASS_NAME} ${CLASS_NAME}_SRC >> ../hxx2salome_journal
203 GEN=( `validate_generation_choices ${GEN[${iCPP}]} ${GEN[${iCORBA}]} ${GEN[${iPython}]}` )
204 echo "-> Wrappers generation : " C++ : ${GEN[${iCPP}]} CORBA : ${GEN[${iCORBA}]} Python : ${GEN[${iPython}]}
206 if [ "x${GEN[${iCORBA}]}" == "xyes" ] ; then
207 generate_corba_module_source
209 clean_corba_module_source
212 if [ "x${GEN[${iCPP}]}" == "xyes" ] ; then
213 generate_cpp_module_source
215 clean_cpp_module_source
221 echo "----------------- Configure -------------------"
223 echo "----------------- Compile ---------------------"
227 # compilation succeeded : we make install
229 echo "----------------- Install ---------------------"
238 if [ -z ${ENVIRON_FILE} ]
240 ENVIRON_FILE="${NEW_COMPONENT_SRC_DIR}/env_${CLASS_NAME}.${SHELL_EXT}"
243 if [ ${BE_QUIET} -lt 1 ] ; then
244 echo -e "\nEnvironment file : " $ENVIRON_FILE
246 if [ -e ${ENVIRON_FILE} ]
248 cp ${ENVIRON_FILE} ${ENVIRON_FILE}.old
250 touch ${ENVIRON_FILE}
252 if [ "${SHELL_EXT}" == "csh" ]
254 grep -q " ${CLASS_NAME}_SRC_DIR" ${ENVIRON_FILE}
258 echo -e "###\n#------ ${CLASS_NAME}-Src ------" >> ${ENVIRON_FILE}
259 echo -e "setenv ${CLASS_NAME}_BASE ${INSTALL_DIR}" >> ${ENVIRON_FILE}
260 echo -e "setenv ${CLASS_NAME}_SRC_DIR \${${CLASS_NAME}_BASE}/${CLASS_NAME}_SRC\n" >> ${ENVIRON_FILE}
263 grep -q " ${CLASS_NAME}_ROOT_DIR" ${ENVIRON_FILE}
267 echo -e "###\n#------ ${CLASS_NAME}-Bin ------" >> ${ENVIRON_FILE}
268 echo -e "setenv ${CLASS_NAME}_ROOT_DIR \${${CLASS_NAME}_BASE}/${CLASS_NAME}_INSTALL" >> ${ENVIRON_FILE}
269 echo -e "setenv ${CLASS_NAME}CPP_ROOT_DIR ${CPP_ROOT_DIR}" >> ${ENVIRON_FILE}
270 echo -e "setenv LD_LIBRARY_PATH \${${CLASS_NAME}CPP_ROOT_DIR}${lib_dir#${CPP_ROOT_DIR}}:\${LD_LIBRARY_PATH}" >> ${ENVIRON_FILE}
273 if [ "${SHELL_EXT}" == "sh" ]
275 grep -q " ${CLASS_NAME}_SRC_DIR=" ${ENVIRON_FILE}
279 echo -e "###\n#------ ${CLASS_NAME}-Src ------" >> ${ENVIRON_FILE}
280 echo -e "export ${CLASS_NAME}_BASE=${INSTALL_DIR}" >> ${ENVIRON_FILE}
281 echo -e "export ${CLASS_NAME}_SRC_DIR=\${${CLASS_NAME}_BASE}/${CLASS_NAME}_SRC\n" >> ${ENVIRON_FILE}
284 grep -q " ${CLASS_NAME}_ROOT_DIR=" ${ENVIRON_FILE}
288 echo -e "###\n#------ ${CLASS_NAME}-Bin ------" >> ${ENVIRON_FILE}
289 echo -e "export ${CLASS_NAME}_ROOT_DIR=\${${CLASS_NAME}_BASE}/${CLASS_NAME}_INSTALL" >> ${ENVIRON_FILE}
290 echo -e "export ${CLASS_NAME}CPP_ROOT_DIR=${CPP_ROOT_DIR}" >> ${ENVIRON_FILE}
291 echo -e "export LD_LIBRARY_PATH=\${${CLASS_NAME}CPP_ROOT_DIR}${lib_dir#${CPP_ROOT_DIR}}:\${LD_LIBRARY_PATH}" \
298 copy_component_source()
300 mv ${tmp_dir}/${CLASS_NAME}_SRC/* ${NEW_COMPONENT_SRC_DIR}
301 mkdir -p ${NEW_COMPONENT_BUILD_DIR}
302 mkdir -p ${NEW_COMPONENT_ROOT_DIR}
308 if [ ${BE_QUIET} -gt 0 ] ; then
311 echo -e "\n\nModule was created in ${NEW_COMPONENT_SRC_DIR}"
317 # ------------------------------------------------------------------------
318 # --------------------------- MAIN PROGRAM -------------------------------
319 # ------------------------------------------------------------------------
322 NEW_COMPONENT_ROOT_DIR=
323 NEW_COMPONENT_SRC_DIR=
324 NEW_COMPONENT_BUILD_DIR=
332 welcome # print some welcome info
334 while getopts "qcs:e:h:lgx:" Option
339 q) BE_QUIET=$[ ${BE_QUIET}+1 ] ;;
340 e) ENVIRON_FILE=$OPTARG;;
350 CORBA) GEN[$iCORBA]="yes" ;;
351 python) GEN[$iPython]="yes" ;;
352 C++) GEN[${iCPP}]="yes";;
355 *) echo "Unimplemented option chosen : $Option."
361 shift $(($OPTIND - 1))
363 # default behaviour is to generate all wrappers
365 if [ "x${GEN[${iCPP}]}${GEN[${iCORBA}]}${GEN[${iPython}]}" == "xnonono" ] ; then
366 for i in ${iCPP} ${iCORBA} ${iPython}
371 echo "-> Wrappers generation : " C++ : ${GEN[${iCPP}]} CORBA : ${GEN[${iCORBA}]} Python : ${GEN[${iPython}]}
375 # check number of other arguments
379 echo -e "\nBad number of arguments\n\n"
384 check_arguments $1 $2 $3 $4
386 # if there is a sh compatible environment file, source it
387 if [[ -n ${ENVIRON_FILE} && -f ${ENVIRON_FILE} ]]
389 # analyse extension of environment file
390 case ${ENVIRON_FILE##*\.} in
398 # Environment policy :
399 # - an existing sh file was specified : we source environment file
400 # - else (no file or csh syntax) : we don't source environment file, and do compile
401 # only if KERNEL_ROOT_DIR and MED_ROOT_DIR are defined
402 if [ "${SHELL_EXT}" == "sh" ] && [ ${ENVIRON_FILE} ] && [ -f ${ENVIRON_FILE} ]
404 echo -e "\n Environment file with sh syntax specified => we source ${ENVIRON_FILE}"
405 source ${ENVIRON_FILE}
409 if [ ${HXX2SALOME_ROOT_DIR} ] && [ -d ${HXX2SALOME_ROOT_DIR} ]
411 gene_dir=${HXX2SALOME_ROOT_DIR}
413 gene_dir=`pwd` # case where hxx2salome was launched from HXX2SALOME directory
420 if [ ${BE_QUIET} -lt 1 ] ; then
421 echo " hxx2salome directory : $gene_dir"
423 if [ ! -f ${gene_dir}/parse1.awk -o ! -f ${gene_dir}/parse2.awk ] # check if script are found
425 echo -e "\nError : Variable HXX2SALOME_ROOT_DIR shoud be set, or hxx2salome should be launched localy from bin directory"
431 CLASS_NAME=`awk '$1 == "class" && $0 !~ /;/ {print $2}' ${hxx_file}|awk -F: '{print $1}'`
432 echo " Name of class :" $CLASS_NAME
435 echo -e "\nError:\n Sorry - No class definition was found!\n Please check your header file\n"
440 # create temporary working directory
442 tmp_dir="/tmp/${USER}/${CLASS_NAME}"
451 # --------------------- Generation of module source from template ------------------------------------------
454 generate_module_source
457 # ---------------------- Installation of new module sources ------------------------------------------------
459 create_component_tree
462 # ---------------------- Modification of Salome environment file -------------------------------------------
465 export `echo ${CLASS_NAME}`_ROOT_DIR=${NEW_COMPONENT_ROOT_DIR} # to avoid resource env for compiling and launching salome
466 export `echo ${CLASS_NAME}`CPP_ROOT_DIR=${CPP_ROOT_DIR} # idem
468 # ---------------------- Copy the generated source from temp dir -------------------------------------------
470 copy_component_source
475 echo -e "\nGeneration done\n"