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