Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[tools/hxx2salome.git] / scripts / hxx2salome
1 #!/bin/bash
2 #
3 #
4 # salome2 environment file (.bash or .sh) - can also be specified with -e option
5 ENVIRON_FILE=
6 # if present, hxx2salome will try to compile new module, by sourcing ENVIRON_FILE file, and executing
7 # build_configure, configure, make & make install
8 # remark : hxx2salome has to be lanched with clean PATH, LD_LIBRARY_PATH & PYTHONPATH variables!
9 #
10 # options you want to pass to configure
11 CONFIGURE_OPTION=
12 #
13 #
14 usage()
15 {
16     echo -e "\n  Usage :\n"
17     echo -e "  Set HXX2SALOME_ROOT_DIR variable"
18     echo -e "  ${HXX2SALOME_ROOT_DIR}/hxx2salome [options] "
19     echo -e "             cppComponent_root_dir cppComponent.hxx"
20     echo -e "             libcppComponent.so salomeComponentRoot\n"
21     echo -e "     - cppComponent_root_dir : install directory (absolute path)"
22     echo -e "                               of the c++ component\n"
23     echo -e "     - cppComponent.hxx      : header of the component"
24     echo -e "     - libcppComponent.so    : library\n"
25     echo -e "       (cppComponent.hxx and libcppComponent.so have to be found"
26     echo -e "        in cppComponent_root_dir)\n"
27     echo -e "     - salomeComponentRoot   : directory of the source/build/install"
28     echo -e "                               of the Salome component\n"
29     echo -e "\n  Options :"
30     echo -e "    -h : help"
31     echo -e "    -e environment_script : to specify the name of a environment file that will be updated with new necessary commands"
32     echo -e "                            (this file is also used for sourcing environment before compilation if it has sh or bash syntax,"
33     echo -e "                             if the syntax is csh, it is not sourced and for compiling (-c option) environment must be set up before)"
34     echo -e "    -s script_extension   : to use if your environment file name doesn't have extension"
35     echo -e "    -g                    : to create a gui part in your component building tree"
36     echo -e "    -c                    : to compile after generation"
37     echo -e "                            (use this option only if you don't have dependencies in your header or libraries"
38     echo -e "                             if it is the case, you'll have to adapt your Makefile.am" 
39     echo -e "    -l                    : to launch salome "
40     exit
41 }
42 #
43 welcome()
44 {
45     echo -e "\n\n"
46     echo  "----------------------------------------------------------------------------"
47     echo
48     echo  "                              hxx2salome"
49     echo
50     echo  "     Automatic generation of a Salome2 component from a C++ component"
51     echo 
52     echo  "----------------------------------------------------------------------------"
53     echo 
54     echo 
55     echo 
56 }
57
58 check_arguments()
59 {
60
61     # check if $1 is a directory
62     echo -e "-> check arguments\n"
63     if [ ! -d $1 ]
64     then
65        echo -e "Error : directory $1 does not exist!\n"
66        usage
67     fi
68     CPP_ROOT_DIR=${1%%/} # remove trailing slash if present 
69     echo "    C++ Component directory : ${CPP_ROOT_DIR}"
70
71     # look for include file $2 - check number of files found and extension
72     nb=`find ${CPP_ROOT_DIR} -name $2 | wc -l` # number of files found, should be equal to 1
73     extension=${2##*\.}
74     if [ $nb -eq 0 ]
75     then
76           echo -e "\n  Error:\n  Include file $2 not found in $1 directory!\n"
77           usage
78     elif [ $nb -ge 2 ]
79     then
80          echo -e "\n  Error:\n  More than one file named $2 was found in $1!\n  Include file should be unique!"
81          usage
82     elif [ $extension != "hxx" -a $extension != "hh" -a $extension != "h" ]
83     then
84          echo -e "\n  Error:\n  Extension=$extension\n  Include file $2 should have extension .hxx .hh or .h !\n"
85          usage
86     fi
87     hxx_file=`find ${CPP_ROOT_DIR} -name $2` # name of c++ header we will parse to generate salome module
88     hxx=$2
89     echo "    C++ Component header    : ${hxx_file}"
90     hxx_dir=`dirname ${hxx_file}`
91
92     # look for library $3
93     nb=`find ${CPP_ROOT_DIR} -name $3 | wc -l` # number of files found, should be equal to 1
94     if [ $nb -eq 0 ]
95     then
96         echo -e "\n  Error:\n  Library file $3 not found in $1 directory!\n"
97         usage
98     elif [ $nb -ge 2 ]
99     then
100         echo -e "\n  Error:\n  More than one file named $3 was found in $1!\n  Library file should be unique!"
101         usage
102     fi
103     so_file=`find ${CPP_ROOT_DIR} -name $3` # absolute path of library containing c++ module
104     echo "    C++ Component library   : ${so_file}"
105     lib_dir=`dirname ${so_file}`
106     lib_file=${3%.so} # name without .so
107     lib_file=${lib_file#lib} # name of library without lib and .so (needed by makefile)
108
109     # installation directory
110     if [[ ! -d $4 ]]
111     then
112        mkdir -p $4
113     fi
114     salomeComponentRoot=${4%%/} # remove trailing slash
115     echo "    Salome Component directory : ${salomeComponentRoot}"
116 }
117
118 # retrieve python test file ending up with _test.py
119 get_python_test_file()
120 {
121     cd ${CPP_ROOT_DIR}
122     for file in `find . -name "*_test.py"`
123     do
124        cp $file ${tmp_dir}/${CLASS_NAME}_SRC/src/${CLASS_NAME}
125        python_test_file=${python_test_file}" "`basename $file`
126     done
127     echo -e "\nList of exported python file test : $python_test_file \n"
128     cd -
129 }
130
131 create_component_tree()
132 {
133     INSTALL_DIR=${salomeComponentRoot}/${CLASS_NAME}
134
135     export NEW_COMPONENT_SRC_DIR=${INSTALL_DIR}/${CLASS_NAME}_SRC
136     export NEW_COMPONENT_BUILD_DIR=${INSTALL_DIR}/${CLASS_NAME}_BUILD
137     export NEW_COMPONENT_ROOT_DIR=${INSTALL_DIR}/${CLASS_NAME}_INSTALL
138
139     \rm -rf ${NEW_COMPONENT_SRC_DIR}
140     mkdir -p ${NEW_COMPONENT_SRC_DIR}
141 }
142
143
144 get_info_makefile()
145 {
146     makefile_lib="-L\${${CLASS_NAME}CPP_ROOT_DIR}${lib_dir#${CPP_ROOT_DIR}} -l${lib_file}"
147     makefile_include="-I\${${CLASS_NAME}CPP_ROOT_DIR}${hxx_dir#${CPP_ROOT_DIR}}"
148     
149     echo -e "\nlinking option : $makefile_lib"
150     echo -e "include option : $makefile_include"
151 }
152
153 generate_module_source()
154 {
155 #
156 # go in temporary directory to work on code generation
157     cd ${tmp_dir}
158 #
159 #
160 # -------------------------  parse hxx file and generate code  ---------------------------------------
161 #
162     echo -e "\n-> Extract public functions\n"
163     cat ${hxx_file} | awk -f ${gene_dir}/parse01.awk | awk -f ${gene_dir}/parse1.awk > ${CLASS_NAME}_public_functions
164     cat ${CLASS_NAME}_public_functions
165     if [ ! -s ${CLASS_NAME}_public_functions ]
166     then
167         echo -e "\nError:\n  Sorry - No compatible function was found!\n  Please check your header file\n"
168         exit
169     fi
170 #
171     echo -e "\n\n-> Parse public functions and generate Salome2 files\n\n  compatibility      function\n"
172     cat ${CLASS_NAME}_public_functions | awk -f ${gene_dir}/parse2.awk |\
173     awk -v class_name=${CLASS_NAME} -f ${gene_dir}/parse3.awk
174 #
175 # outputs
176     echo -e "\n  IDL file:"
177     cat parse_result > hxx2salome_journal
178     echo -e "\n----------------- IDL file ------------------\n" >> hxx2salome_journal
179     cat code_idl >> hxx2salome_journal
180     cat code_idl
181     echo -e "\n----------------- hxx file ------------------\n" >> hxx2salome_journal
182     cat code_hxx >> hxx2salome_journal
183     echo -e "\n----------------- cxx file ------------------\n" >> hxx2salome_journal
184     cat code_cxx >> hxx2salome_journal
185     echo
186 #
187 #
188 # -------------------  duplicates template module and insert generated code  ------------------------------
189 #
190     echo -e "\n-> Duplicate template module" | tee hxx2salome_journal
191     tar xvfz ${gene_dir}/template_src.tgz >> hxx2salome_journal
192     mv HXX2SALOME_GENERIC_CLASS_NAME_SRC ${CLASS_NAME}_SRC
193     ${gene_dir}/renameSalomeModule -i HXX2SALOME_GENERIC_CLASS_NAME ${CLASS_NAME} ${CLASS_NAME}_SRC 
194     ###>> hxx2salome_journal
195     ${gene_dir}/renameSalomeModule -i hxx2salome_generic_class_name ${class_name} ${CLASS_NAME}_SRC
196     ###>> hxx2salome_journal
197 #
198     if [ $make_gui -eq 0 ]
199     then
200         echo -e "\n-> Delete GUI part from the tree" >> hxx2salome_journal
201         'rm' -rf ${CLASS_NAME}_SRC/src/${CLASS_NAME}GUI
202         sed "s/${CLASS_NAME}GUI//" < ${CLASS_NAME}_SRC/src/Makefile.am > /tmp/h2smkf.$$
203         mv /tmp/h2smkf.$$ ${CLASS_NAME}_SRC/src/Makefile.am
204         cat ${CLASS_NAME}_SRC/configure.ac | awk ' $0 !~ "^.*GUI/Makefile"  { print $0}' > /tmp/h2scac.$$
205         mv /tmp/h2scac.$$  ${CLASS_NAME}_SRC/configure.ac
206     fi
207 #
208     echo -e "\n-> Substitute generated code in idl file"
209     echo "// this idl file was generated by hxx2salome" > tmpfile
210     cat ${CLASS_NAME}_SRC/idl/${CLASS_NAME}_Gen.idl |awk ' 
211         $0 ~ "HXX2SALOME_IDL_CODE" {system("cat code_idl >> tmpfile")} 
212         $0 != "HXX2SALOME_IDL_CODE" { print $0 >> "tmpfile" }'
213     mv tmpfile ${CLASS_NAME}_SRC/idl/${CLASS_NAME}_Gen.idl
214 #
215     echo -e "\n-> Substitute generated code in hxx file"
216     echo "// this hxx file was generated by hxx2salome" > tmpfile
217     cat ${CLASS_NAME}_SRC/src/${CLASS_NAME}/${CLASS_NAME}_i.hxx |awk '
218         $0 ~ "HXX2SALOME_HXX_CODE" {system("cat code_hxx >> tmpfile")}
219         $0 !~ "HXX2SALOME" { print $0 >> "tmpfile" }'
220     mv tmpfile ${CLASS_NAME}_SRC/src/${CLASS_NAME}/${CLASS_NAME}_i.hxx
221 #
222     echo -e "\n-> Substitute generated code in cxx file"
223     echo "// this cxx file was generated by hxx2salome" > tmpfile
224     cat ${CLASS_NAME}_SRC/src/${CLASS_NAME}/${CLASS_NAME}_i.cxx |awk -v cpp_include=$hxx '
225         $0 ~ "HXX2SALOME_CXX_CODE" {system("cat code_cxx >> tmpfile")}
226         $0 ~ "HXX2SALOME_CPP_INCLUDE" { printf "#include \"%s\"\n",cpp_include >> "tmpfile" }
227         $0 !~ "HXX2SALOME" { print $0 >> "tmpfile" }'
228     mv tmpfile ${CLASS_NAME}_SRC/src/${CLASS_NAME}/${CLASS_NAME}_i.cxx
229 #
230 # add flags in makefile
231     get_python_test_file
232     get_info_makefile
233     
234     echo -e "\n-> Substitute flags in Makefile.am"
235     sed "s?HXX2SALOME_INCLUDE?${makefile_include}?g
236          s?HXX2SALOME_PYTHON_FILE?${python_test_file}?g
237          s?HXX2SALOME_LIB?${makefile_lib}?g
238         " ${CLASS_NAME}_SRC/src/${CLASS_NAME}/Makefile.am > tmpfile
239     mv tmpfile ${CLASS_NAME}_SRC/src/${CLASS_NAME}/Makefile.am
240 #
241 # generate component catalog
242     echo -e "\n-> Generate component catalog" | tee hxx2salome_journal
243     if [ -f ${KERNEL_ROOT_DIR}/bin/salome/runIDLparser ]
244     then
245        idlparser=${KERNEL_ROOT_DIR}/bin/salome/runIDLparser
246     else
247        idlparser=${gene_dir}/runIDLparser
248     fi
249     cd ${CLASS_NAME}_SRC/resources
250     VER=`cat ${KERNEL_ROOT_DIR}/bin/salome/VERSION | awk ' { print $NF }'` # extract number of version 
251     export PYTHONPATH=${PYTHONPATH}:${KERNEL_ROOT_DIR}/bin/salome  # to be sure IDLparser is in PYTHONPATH
252     ${idlparser} -Wbcatalog=tmp.xml,icon=${CLASS_NAME}.png,version=${VER} -I${KERNEL_ROOT_DIR}/idl/salome -I${MED_ROOT_DIR}/idl/salome ../idl/${CLASS_NAME}_Gen.idl >& /dev/null | tee  hxx2salome_journal
253     if [ -f tmp.xml ]
254     then
255        cat tmp.xml | sed 's/_Gen//g' > ${CLASS_NAME}Catalog.xml
256     else
257        echo Error with runIDLparser - the catalog was not generated
258        exit
259     fi
260     rm tmp.xml
261 #
262 }
263
264 compile()
265 {
266     echo "----------------- Configure -------------------"
267     
268     echo "----------------- Compile ---------------------"
269     make 
270     if [ $? -eq 0 ]
271     then
272         # compilation succeeded : we make install
273         echo
274         echo "----------------- Install ---------------------"
275         make install
276     else
277         exit 1
278     fi
279 }
280
281 update_environment()
282 {
283     if [ -z ${ENVIRON_FILE} ]
284     then
285         ENVIRON_FILE="${NEW_COMPONENT_SRC_DIR}/env_${CLASS_NAME}.${SHELL_EXT}"
286     fi
287
288     echo -e "\nEnvironment file : ", $ENVIRON_FILE
289     if [ -e ${ENVIRON_FILE} ]
290     then
291         cp ${ENVIRON_FILE} ${ENVIRON_FILE}.old
292     fi
293     touch ${ENVIRON_FILE}
294
295     if [ "${SHELL_EXT}" == "csh" ]
296     then
297         grep -q " ${CLASS_NAME}_SRC_DIR" ${ENVIRON_FILE}
298         res=$?
299         if [ $res == 1 ]
300         then
301             echo -e "###\n#------ ${CLASS_NAME}-Src ------" >>  ${ENVIRON_FILE}
302             echo -e "setenv ${CLASS_NAME}_BASE ${INSTALL_DIR}" >> ${ENVIRON_FILE}
303             echo -e "setenv ${CLASS_NAME}_SRC_DIR \${${CLASS_NAME}_BASE}/${CLASS_NAME}_SRC\n" >> ${ENVIRON_FILE}
304         fi
305         
306         grep -q " ${CLASS_NAME}_ROOT_DIR" ${ENVIRON_FILE}
307         res=$?
308         if [ $res == 1 ]
309         then
310             echo -e "###\n#------ ${CLASS_NAME}-Bin ------" >>  ${ENVIRON_FILE}
311             echo -e "setenv ${CLASS_NAME}_ROOT_DIR \${${CLASS_NAME}_BASE}/${CLASS_NAME}_INSTALL" >> ${ENVIRON_FILE}
312             echo -e "setenv ${CLASS_NAME}CPP_ROOT_DIR ${CPP_ROOT_DIR}" >> ${ENVIRON_FILE}
313             echo -e "setenv LD_LIBRARY_PATH \${${CLASS_NAME}CPP_ROOT_DIR}${lib_dir#${CPP_ROOT_DIR}}:\${LD_LIBRARY_PATH}" >> ${ENVIRON_FILE}
314         fi
315     fi
316     if [ "${SHELL_EXT}" == "sh" ]
317     then
318         grep -q " ${CLASS_NAME}_SRC_DIR=" ${ENVIRON_FILE}
319         res=$?
320         if [ $res == 1 ]
321         then
322             echo -e "###\n#------ ${CLASS_NAME}-Src ------" >>  ${ENVIRON_FILE}
323             echo -e "export ${CLASS_NAME}_BASE=${INSTALL_DIR}" >> ${ENVIRON_FILE}
324             echo -e "export ${CLASS_NAME}_SRC_DIR=\${${CLASS_NAME}_BASE}/${CLASS_NAME}_SRC\n" >> ${ENVIRON_FILE}
325         fi
326         
327         grep -q " ${CLASS_NAME}_ROOT_DIR=" ${ENVIRON_FILE}
328         res=$?
329         if [ $res == 1 ]
330         then
331             echo -e "###\n#------ ${CLASS_NAME}-Bin ------" >>  ${ENVIRON_FILE}
332             echo -e "export ${CLASS_NAME}_ROOT_DIR=\${${CLASS_NAME}_BASE}/${CLASS_NAME}_INSTALL" >> ${ENVIRON_FILE}
333             echo -e "export ${CLASS_NAME}CPP_ROOT_DIR=${CPP_ROOT_DIR}" >> ${ENVIRON_FILE}
334             echo -e "export LD_LIBRARY_PATH=\${${CLASS_NAME}CPP_ROOT_DIR}${lib_dir#${CPP_ROOT_DIR}}:\${LD_LIBRARY_PATH}" \
335             >> ${ENVIRON_FILE}
336         fi
337         
338     fi
339 }
340
341 copy_component_source()
342 {
343     mv ${tmp_dir}/${CLASS_NAME}_SRC/* ${NEW_COMPONENT_SRC_DIR}
344     mkdir -p ${NEW_COMPONENT_BUILD_DIR}
345     mkdir -p ${NEW_COMPONENT_ROOT_DIR}
346 }
347
348 good_bye()
349 {
350     echo -e "\n\nModule was created in ${NEW_COMPONENT_SRC_DIR}"
351     echo -e "\nTo compile it, do the following : \n"
352     echo -e "\tsource ${ENVIRON_FILE}"
353     echo -e "\tcd \${${CLASS_NAME}_SRC_DIR}"
354     echo -e "\t./build_configure"
355     echo -e "\tmkdir -p \${${CLASS_NAME}_BUILD_DIR}"
356     echo -e "\tcd \${${CLASS_NAME}_BUILD_DIR}"
357     echo -e "\t\${${CLASS_NAME}_SRC_DIR}/configure ${CONFIGURE_OPTION} --prefix=\${${CLASS_NAME}_ROOT_DIR}"
358     echo -e "\tmake"
359     echo -e "\tmake install"
360     echo -e "\nTo use it :\n"
361     echo -e "\tsource the Salome environment"
362     echo -e "\tsource the component environment file (${ENVIRON_FILE})"
363     echo -e "\trun Salome"
364     echo -e "\tadd ${CLASS_NAME} to the Salome modules list"
365     echo -e "\t\t(with the --modules option of the runSalome command or"
366     echo -e "\t\tby editing your own per-user configuration file ~/.SalomeApprc.3.x.x)"
367     echo -e "\nIf the header of your component includes other headers that are not in the same directories,"
368     echo -e "or if your library has dependencies you want to specify,"
369     echo -e "you'll have to modify the following files Makefile.am: "
370     echo -e "\t\${${CLASS_NAME}_SRC_DIR}/src/${CLASS_NAME}/Makefile.am"
371     echo -e "\t\${${CLASS_NAME}_SRC_DIR}/src/${CLASS_NAME}GUI/Makefile.am"
372 }
373
374 launch_salome()
375 {
376     ${KERNEL_ROOT_DIR}/bin/salome/runSalome --gui --modules=GEOM,SMESH,VISU,SUPERV,MED,`echo ${CLASS_NAME}`  --containers=cpp,python --killall
377 }
378
379 compile_module()
380 {
381     if [ ! -d ${NEW_COMPONENT_BUILD_DIR} ]
382     then
383         mkdir -p ${NEW_COMPONENT_BUILD_DIR}
384     fi
385     if [ ! -d ${NEW_COMPONENT_ROOT_DIR} ]
386     then
387         mkdir -p ${NEW_COMPONENT_ROOT_DIR}
388     fi
389     \rm -rf ${NEW_COMPONENT_ROOT_DIR}/* ${NEW_COMPONENT_BUILD_DIR}/*
390
391 #    source ${ENVIRON_FILE}
392     echo 
393     echo -e "\n-> Build Configure"
394     cd ${NEW_COMPONENT_SRC_DIR}
395     ./build_configure
396     cd ${NEW_COMPONENT_BUILD_DIR}
397     echo -e "\n-> Configure in ${NEW_COMPONENT_BUILD_DIR}"
398     echo -e "\n-> Install in ${NEW_COMPONENT_ROOT_DIR}"
399     ${NEW_COMPONENT_SRC_DIR}/configure ${CONFIGURE_OPTION} --prefix=${NEW_COMPONENT_ROOT_DIR}
400     echo
401
402     if [[ $do_compile -eq 1 ]]
403     then
404         compile
405     fi
406     
407     if [[ $do_launch -eq 1 ]]
408     then
409         launch_salome
410     fi
411 }
412 #
413 #
414 # ------------------------------------------------------------------------
415 # --------------------------- MAIN PROGRAM -------------------------------
416 # ------------------------------------------------------------------------
417 #
418 CPP_ROOT_DIR=
419 NEW_COMPONENT_ROOT_DIR=
420 NEW_COMPONENT_SRC_DIR=
421 NEW_COMPONENT_BUILD_DIR=
422 SHELL_EXT=sh
423 do_compile=0
424 do_launch=0
425 make_gui=0
426  #
427 welcome # print some welcome info
428 #
429 while getopts "cs:e:h:lg" Option
430 do
431    case $Option in
432      h) usage
433         exit;;
434      e) ENVIRON_FILE=$OPTARG;;
435      s) case $OPTARG in
436             bash) SHELL_EXT=sh;;
437             csh)  SHELL_EXT=csh;;      
438             *)    SHELL_EXT=sh;;
439         esac;;
440      g) make_gui=1;;
441      c) do_compile=1;;
442      l) do_launch=1;;
443      *) echo "Unimplemented option chosen : $Option."
444         usage
445         exit;;   # DEFAULT
446    esac
447 done
448
449 shift $(($OPTIND - 1))
450
451 # check number of other arguments
452 #
453 if [ $# -ne 4 ]
454 then
455    echo -e "\nBad number of arguments\n\n"
456    usage
457    exit
458 fi
459
460 check_arguments $1 $2 $3 $4
461
462 # if there is a sh compatible environment file, source it
463 if [[ -n ${ENVIRON_FILE} && -f ${ENVIRON_FILE} ]]
464 then
465    # analyse extension of environment file
466    case ${ENVIRON_FILE##*\.} in 
467        bash) SHELL_EXT=sh;;
468        ksh)  SHELL_EXT=sh;;
469        csh)  SHELL_EXT=csh;;
470        sh)   SHELL_EXT=sh;;
471    esac
472 fi
473
474 # Environment policy :
475 #   - an existing sh file was specified : we source environment file
476 #   - else (no file or csh syntax)      : we don't source environment file, and do compile 
477 #                                         only if KERNEL_ROOT_DIR and MED_ROOT_DIR are defined
478 if [ "${SHELL_EXT}" == "sh" ] && [ ${ENVIRON_FILE} ] && [ -f ${ENVIRON_FILE} ]
479 then
480    echo -e "\n    Environment file with sh syntax specified => we source ${ENVIRON_FILE}"
481    source ${ENVIRON_FILE}
482 else
483    if [ ${KERNEL_ROOT_DIR} ] && [ -d ${KERNEL_ROOT_DIR} ] && [ ${MED_ROOT_DIR} ] && [ -d ${MED_ROOT_DIR} ]
484    then
485        # if KERNEL_ROOT_DIR and MED_ROOT_DIR are defined, we consider that environment is set
486        echo -e "\n    Environment already set (KERNEL_ROOT_DIR and MED_ROOT_DIR are defined)"
487    else
488        if [ $do_compile -eq 1 ]
489        then 
490           echo -e "\n    Warning - Cannot compile : Environment shoud be set up before, or specify a environment file with sh syntax!\n"
491           do_compile=0
492        fi
493    fi
494 fi
495
496 # look up hxx2salome scripts
497 #   - first search in directory ${HXX2SALOME_ROOT_DIR} (if the variable is defined)
498 #   - then search in directory ${HXX2SALOME_ROOT_DIR}/bin
499 #   - finally seach locally.
500 #
501 if [ ${HXX2SALOME_ROOT_DIR} ] && [ -d ${HXX2SALOME_ROOT_DIR} ]
502 then
503     echo "    HXX2SALOME_ROOT_DIR variable is defined : ${HXX2SALOME_ROOT_DIR}  => we look up hxx2salome scripts inside"
504     if [ -f ${HXX2SALOME_ROOT_DIR}/parse1.awk -a  -f ${HXX2SALOME_ROOT_DIR}/parse2.awk ] # check if script are found in ${HXX2SALOME_ROOT_DIR}
505     then
506         gene_dir=${HXX2SALOME_ROOT_DIR}
507     elif [ -f ${HXX2SALOME_ROOT_DIR}/bin/parse1.awk -a  -f ${HXX2SALOME_ROOT_DIR}/bin/parse2.awk ] # else check /bin directory
508     then
509         gene_dir=${HXX2SALOME_ROOT_DIR}/bin
510     else
511         echo -e "\nError : Variable HXX2SALOME_ROOT_DIR not correctly set"
512         usage
513     fi
514 else
515     echo "HXX2SALOME_ROOT_DIR directory not set  => we look up hxx2salome scripts locally"
516     if [  -f parse1.awk -a  -f parse2.awk ] # check if script are found locally
517     then
518         gene_dir=`pwd` # case where hxx2salome was launched from HXX2SALOME directory
519     else
520         echo -e "\nError : Variable HXX2SALOME_ROOT_DIR is not set, and hxx2salome didn't find his scripts locally"
521         usage
522     fi
523 fi
524 echo "    hxx2salome directory found : $gene_dir"
525 if [ ! -f ${gene_dir}/parse3.awk -o ! -f ${gene_dir}/template_src.tgz ] # final check
526 then
527     echo -e "\nError : scripts parse3.awk or template_src.tgz not present in hxx2salome directory  : $gene_dir"
528     usage
529 fi
530 #
531 # get class name
532 #
533 CLASS_NAME=`awk '$1 == "class" && $0 !~ /;/ {print $2}' ${hxx_file}|awk -F: '{print $1}'`
534 echo "    Name of class :" $CLASS_NAME
535 class_name=`echo ${CLASS_NAME} | awk '{print tolower($0)}'`
536 echo class_name = ${class_name}
537
538 if [ ! $CLASS_NAME ]
539 then
540     echo -e "\nError:\n  Sorry - No class definition was found!\n  Please check your header file\n"
541     exit
542 fi
543
544 #
545 # create temporary working directory
546 #
547 tmp_dir="/tmp/${USER}/${CLASS_NAME}"
548 if [ -d ${tmp_dir} ]
549 then
550     rm -rf ${tmp_dir}/*
551 else
552     mkdir -p ${tmp_dir}
553 fi
554
555 #
556 # ---------------------  Generation of module source from template ------------------------------------------
557 #
558 get_info_makefile
559 generate_module_source
560
561 #
562 # ---------------------- Installation of new module sources  ------------------------------------------------
563 #
564 create_component_tree
565
566 #
567 # ---------------------- Modification of Salome environment file  -------------------------------------------
568 #
569 update_environment
570 export `echo ${CLASS_NAME}`_ROOT_DIR=${NEW_COMPONENT_ROOT_DIR}  # to avoid resource env for compiling and launching salome
571 export `echo ${CLASS_NAME}`CPP_ROOT_DIR=${CPP_ROOT_DIR}  # idem
572 #
573 # ---------------------- Copy the generated source from temp dir  -------------------------------------------
574 #
575 copy_component_source
576
577 #
578 # ---------------------- If requested, compilation of the Salome component ----------------------------------
579 if [ ${do_compile} -eq 1 ]
580 then
581     compile_module
582 else
583     good_bye
584 fi
585
586 echo -e "\nGeneration done\n"