Salome HOME
078f78a034b7b185aa2fc0a9ee06bf4d2d479c5b
[modules/hexablock.git] / src / HEXABLOCK / make.make
1 #!/bin/sh
2 # Copyright (C) 2009-2023  CEA, EDF
3 #
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, or (at your option) any later version.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 # Comm : Generateur de Makefile
22
23 commande=$0
24 liste_args="$*"
25
26 # =============================================== al_aide
27 al_aide()
28 {
29 proc=`basename $commande`
30 cat << END_HELP
31 Syntaxe :
32     $    $proc [ options ] <fichiers_source>
33 Effet :
34     Genere un Makefile tenant compte des fichiers sources passes en argument
35     et des includes appeles par ces fichiers.
36 Avec :
37     <fichiers_sources> liste des fichiers *.c *.cc *.cpp *.cxx et *.C
38                        pris en compte pour constituer le Makefile.
39                       Si des fichiers *.h sont presents, c'est pour generer des
40                        fichiers qt (utilitaire moc)
41     Options:
42          Make=<fic>  : Nom du makefile a generer
43          opt=val      : Option passee
44          <autres>     : options de compilation
45                         (par exemple le repertoire des includes)
46 END_HELP
47 exit
48 }
49 # =============================================== ana_arguments
50 ana_arguments()
51 {
52 liste_src=
53 liste_rad=
54 liste_qrc=
55 liste_bnf=
56 liste_moc=
57 for arg in $liste_args
58     do
59     case $arg in
60          -setx )
61              set -x
62              ;;
63          -h | --help  )
64              al_aide
65              ;;
66          Make=* | make=* )
67              make_file=`echo $arg | cut -f2 -d=`
68              ;;
69          * )
70              arg_gcc="$arg_gcc $arg"
71              ;;
72     esac
73     done
74
75 for arg in *.cxx
76     do
77     case $arg in
78
79          \*.* ) :
80              ;;
81
82          *.cpp | *.cc | *.cxx | *.C | *.c )
83              rad=`echo $arg | cut -f1 -d.`
84              liste_src="$liste_src $arg"
85              liste_rad="$liste_rad $rad"
86              ;;
87          * ) :
88              ;;
89     esac
90     done
91 }
92 # =============================================== put_includes
93 put_includes()
94 {
95    if ( [ -z "$3" ] ) then
96       return
97       fi
98
99    obj=$repobj/$1
100    shift 2
101
102    for mot in $*
103        do
104        case $mot in
105            \\* ) : ;;
106
107            */Qt/* ) : ;;
108            */VTK* ) : ;;
109
110            * ) echo $obj $mot
111               ;;
112        esac
113        done
114 }
115 # =============================================== init_par_defaut
116 init_par_defaut()
117 {
118 os=`uname`
119 if ( [ $os = Linux ] ) then
120    opt_pic=-fPIC
121    fi
122
123 hdebut=`date '+%Hh %Mmn %Ss'`
124 make_file=Makefile
125 make_file=makefile.ozz
126 antislash=\\
127 liste_src=
128 liste_rad=
129 arg_gcc=
130 arg_plus=
131 make_body=OK
132 make_ref=OK
133
134 repobj='$(REPOBJ)'
135 replib='$(REPLIB)'
136 repexe='$(REPEXE)'
137 opt_user='$(OPT)'
138 compile='$(CPIL)'
139 archive='$(ARCH)'
140 link='$(LINK)'
141
142 val_repobj=.
143 cmd_cpil="g++ -c -g $opt_pic -Wall -DNO_CASCADE -Inokas --pedantic"
144 cmd_arch='ar rcvu $(BIBLI) *.o'
145 cmd_link='g++ -g'
146 uf=`pwd`
147 uf=`basename "$uf"`
148
149 ext=
150 namof_lib=lib$uf.a
151
152 comm=`basename $commande`
153 reptools=`dirname $commande`
154                    ###  Definition des includes par $ozz_opt_cpp
155
156 if ( [ -n "$OZZ_FLAGS" -a -f "$OZZ_FLAGS" ] ) then
157    . $OZZ_FLAGS
158 fi
159 }
160 # =============================================== add_entete
161 add_entete()
162 {
163 today=`date "+%d/%m/%y a %Hh%M"`
164 echo
165 echo  "# Makefile OZZ genere le $today"
166 echo  "# Par la commande : $comm "
167 echo  "# Role de ce makefile : "
168 echo  "#  - Compiler les fichiers-source defraichis avec la commande \$CPIL"
169 echo  "#  - Les archiver sur le fichier archive \$REPLIB/\$BIBLI"
170 echo  "#  - Linker le programme principal (test unitaire) passe en argument"
171 echo
172 echo ".SUFFIXES:"         ## Pour ne pas etre emm....
173 echo "OPT    = "          ## Options de compilation de l'appelant
174 echo "REPOBJ = ."
175 echo "REPLIB = ."
176 echo "REPEXE = ./work"
177 echo "BIBLI  = $namof_lib"
178 echo "ARCH   = $cmd_arch"
179 echo "CPIL   = $cmd_cpil"
180 echo "LINK   = $cmd_link"
181 echo "main   = test_hexa"
182 echo
183
184 precedente="OBJECTS  ="
185
186 for module in $liste_rad
187     do
188     echo "$precedente \\"
189     precedente="      $repobj/$module.o"
190     done
191
192 cat << FIN
193 $precedente
194
195 all  : saut link
196
197 saut :
198         @ echo ; echo ; echo ; echo ; echo ; echo ; echo ; echo ; echo ; echo
199
200 link     : $repexe/\$(main).exe
201
202 $repexe/\$(main).cpp  :
203         ./make.main \$(main)
204
205 $repexe/\$(main).exe  : $repexe/\$(main).cpp  \$(REPLIB)/\$(BIBLI)
206         \$(LINK) $repexe/\$(main).cpp  \$(REPLIB)/\$(BIBLI) -o $repexe/\$(main).exe
207
208 \$(REPLIB)/\$(BIBLI) : \$(OBJECTS)
209         $archive
210
211 clean :
212         rm -rf *.exe \$(REPLIB)/\$(BIBLI) \$(REPOBJ)/*.o *.bak *~
213
214 cleanobj :
215         rm -rf \$(REPLIB)/\$(BIBLI) \$(REPOBJ)/*.o *.bak *~
216
217 FIN
218 }
219 # =============================================== add_sources
220 add_sources()
221 {
222 echo
223 echo  "                     ### Compilations"
224 echo
225 for arg in $liste_src
226     do
227     radical=`echo $arg | cut -f1 -d.`
228     echo "$repobj/$radical.o : $arg"
229     echo "      $compile $opt_user $arg"
230     done
231 }
232 # =============================================== Begin
233 init_par_defaut
234 echo
235 echo " ... Generation de $make_file qui met a jour $namof_lib ..."
236
237 ana_arguments
238 ./make_dummycad
239
240 rm -rf $make_file
241 add_entete  >> $make_file
242 add_sources >> $make_file
243
244 makedepend -f $make_file -Y -I. $liste_src 2> /dev/null
245
246 hfin=`date '+%Hh %Mmn %Ss'`
247 echo " ... Fin de la generation : $hfin"
248 echo " ... Elle avait debute a  : $hdebut"