1 |
#--------------------------------------------------------------------------- |
2 |
# (C) 1999 - 2002 Jacob Dreyer - Geotechnical Software Services |
3 |
# jacob.dreyer@geosoft.no - http://geosoft.no |
4 |
# |
5 |
# This program is free software; you can redistribute it and/or |
6 |
# modify it under the terms of the GNU General Public License |
7 |
# as published by the Free Software Foundation; either version 2 |
8 |
# of the License, or (at your option) any later version. |
9 |
# |
10 |
# This program is distributed in the hope that it will be useful, |
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with this program; if not, write to the Free Software |
17 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
18 |
# MA 02111-1307, USA. |
19 |
#--------------------------------------------------------------------------- |
20 |
#--------------------------------------------------------------------------- |
21 |
# |
22 |
# GnuMake crash course: |
23 |
# |
24 |
# target : depends |
25 |
# rule |
26 |
# |
27 |
# target - the parameter given to make. I.e. what to build |
28 |
# depends - file or other targets target depends on |
29 |
# rule - how to create target (note that rule is preceeded by a TAB char) |
30 |
# $(VAR) - environment variable or variable defined above |
31 |
# $@ - Current target |
32 |
# $* - Current target without extension |
33 |
# $< - Current dependency |
34 |
# |
35 |
#--------------------------------------------------------------------------- |
36 |
#--------------------------------------------------------------------------- |
37 |
# |
38 |
# Directories |
39 |
# |
40 |
#--------------------------------------------------------------------------- |
41 |
SourceDir = $(DEV_ROOT)/src |
42 |
TargetDir = $(DEV_ROOT)/obj |
43 |
LibDir = $(DEV_ROOT)/lib |
44 |
MakeDir = $(DEV_ROOT)/make |
45 |
BinDir = $(DEV_ROOT)/bin |
46 |
DocsDir = $(DEV_ROOT)/docs |
47 |
CurrentDir = $(CURDIR) |
48 |
|
49 |
ifdef Source |
50 |
Package = $(subst $(SourceDir)/,,$(CurrentDir)) |
51 |
PackageList = $(Package) |
52 |
PackageSourceDir = $(SourceDir)/$(Package) |
53 |
PackageTargetDir = $(TargetDir) |
54 |
JavaMainClass = $(subst /,.,$(Package)).$(Main) |
55 |
else |
56 |
PackageList = $(Packages) $(JavaPackages) |
57 |
endif |
58 |
|
59 |
PackageListLoop = $(patsubst %,$(SourceDir)/%/.loop,$(PackageList)) |
60 |
|
61 |
JRE = $(JAVA_HOME)/jre/lib/rt.jar |
62 |
|
63 |
ifdef IS_UNIX |
64 |
X = : |
65 |
else |
66 |
X = \; |
67 |
endif |
68 |
|
69 |
#--------------------------------------------------------------------------- |
70 |
# |
71 |
# Classification of files |
72 |
# |
73 |
#--------------------------------------------------------------------------- |
74 |
|
75 |
# Source |
76 |
JavaFiles = $(filter %.java, $(Source)) |
77 |
CppFiles = $(filter %.cpp, $(Source)) |
78 |
CFiles = $(filter %.c, $(Source)) |
79 |
FortranFiles = $(filter %.f, $(Source)) |
80 |
F90Files = $(filter %.F90, $(Source)) |
81 |
CorbaFiles = $(filter %.idl, $(Source)) |
82 |
LexFiles = $(filter %.l, $(Source)) |
83 |
YaccFiles = $(filter %.y, $(Source)) |
84 |
OtherSourceFiles = $(filter-out $(JavaFiles) $(CppFiles) $(CFiles) \ |
85 |
$(FortranFiles) $(F90Files) $(LexFiles) \ |
86 |
$(YaccFiles) $(CorbaFiles), \ |
87 |
$(Source)) |
88 |
ManifestFile = $(PackageSourceDir)/Manifest |
89 |
SourceFiles = $(JavaFiles:%.java= $(PackageSourceDir)/%.java)\ |
90 |
$(CppFiles:%.cpp= $(PackageSourceDir)/%.cpp)\ |
91 |
$(CFiles:%.c= $(PackageSourceDir)/%.c)\ |
92 |
$(FortranFiles:%.f= $(PackageSourceDir)/%.f)\ |
93 |
$(F90Files:%.F90= $(PackageSourceDir)/%.F90)\ |
94 |
$(LexFiles:%.l= $(PackageSourceDir)/%.l)\ |
95 |
$(YaccFiles:%.y= $(PackageSourceDir)/%.y)\ |
96 |
|
97 |
|
98 |
# Target |
99 |
JavaClassFiles = $(JavaFiles:%.java= $(PackageTargetDir)/%.class) |
100 |
JavaClassFilesRel = $(JavaFiles:%.java= $(Package)/%.class) |
101 |
RmiStubFiles = $(RmiSource:%.java= $(PackageTargetDir)/%_Stub.class) |
102 |
RmiSkeletonFiles = $(RmiSource:%.java= $(PackageTargetDir)/%_Skel.class) |
103 |
JniClassFiles = $(JniSource:%.java= $(PackageTargetDir)/%.class) |
104 |
JniHeaders = $(JniSource:%.java= $(PackageSourceDir)/%.h) |
105 |
ObjectFiles = $(CFiles:%.c= $(PackageTargetDir)/%.o)\ |
106 |
$(CppFiles:%.cpp= $(PackageTargetDir)/%.o)\ |
107 |
$(FortranFiles:%.f= $(PackageTargetDir)/%.o)\ |
108 |
$(F90Files:%.F90= $(PackageTargetDir)/%.o)\ |
109 |
$(LexFiles:%.l= $(PackageTargetDir)/%.o)\ |
110 |
$(YaccFiles:%.y= $(PackageTargetDir)/%.o) |
111 |
|
112 |
DerivedSource = $(YaccFiles:%.y= %.h) \ |
113 |
$(YaccFiles:%.y= %.c) \ |
114 |
$(LexFiles:%.l= %.c) |
115 |
|
116 |
DerivedCFiles = $(YaccFiles:%.y= %.c) \ |
117 |
$(LexFiles:%.l= %.c) |
118 |
|
119 |
OtherTargetFiles = $(OtherSourceFiles:%=$(PackageTargetDir)/%) |
120 |
|
121 |
ThirdPartyJarsTmp = $(patsubst %,$(LibDir)/%,$(JavaLibraries)) |
122 |
ThirdPartyJars = $(subst $(Space),$(X),$(ThirdPartyJarsTmp)) |
123 |
|
124 |
ifneq "$(words $(JavaFiles))" "0" |
125 |
JavaPackageName = $(subst /,.,$(Package)) |
126 |
JarFile = $(LibDir)/$(subst /,,$(Package)).jar |
127 |
endif |
128 |
ifneq "$(words $(ObjectFiles))" "0" |
129 |
DependencyFile = $(PackageSourceDir)/Makedepend |
130 |
SharedLibrary = $(LibDir)/lib$(subst /,,$(Package)).so |
131 |
StaticLibrary = $(LibDir)/lib$(subst /,,$(Package)).a |
132 |
ifneq "$(Main)" "" |
133 |
Executable = $(BinDir)/$(Main) |
134 |
endif |
135 |
endif |
136 |
# |
137 |
# Misc |
138 |
# |
139 |
ClassPath = $(JRE)$(X)$(TargetDir)$(X)$(ThirdPartyJars) |
140 |
JavaPackageNames = $(subst /,.,$(JavaPackages)) |
141 |
IncludePath = -I$(SourceDir) $(IncludeDirs:%=-I%) |
142 |
LibDirs = -L$(LibDir) $(LibraryDirs:%=-L%) |
143 |
LocalLibs = $(subst /,,$(Packages)) |
144 |
LibList = $(LocalLibs:%=-l%) $(Libraries:%=-l%) |
145 |
|
146 |
|
147 |
#--------------------------------------------------------------------------- |
148 |
# |
149 |
# Tools & Options |
150 |
# |
151 |
#--------------------------------------------------------------------------- |
152 |
Print = @echo |
153 |
Move = mv |
154 |
Copy = cp |
155 |
CCompiler = icc |
156 |
CppCompiler = icpc |
157 |
Linker = icpc |
158 |
MakeDepend = makedepend |
159 |
MakeDir = mkdir -p |
160 |
Delete = rm -fr |
161 |
StaticArchiver = ar |
162 |
DynamicArchiver = icc |
163 |
FortranCompiler = ifort |
164 |
F90Compiler = ifort |
165 |
JavaCompiler = $(JAVA_HOME)/bin/javac |
166 |
JavaArchiver = $(JAVA_HOME)/bin/jar |
167 |
JarSigner = $(JAVA_HOME)/bin/jarsigner |
168 |
JavadocGenerator = $(JAVA_HOME)/bin/javadoc |
169 |
JniCompiler = $(JAVA_HOME)/bin/javah |
170 |
RmiCompiler = $(JAVA_HOME)/bin/rmic |
171 |
JavaExecute = $(JAVA_HOME)/bin/java |
172 |
Purify = purify |
173 |
WordCount = wc |
174 |
List = cat |
175 |
Yacc = bison -y |
176 |
Lex = flex |
177 |
|
178 |
|
179 |
MakeOptions = -k -s |
180 |
MakeDependOptions = |
181 |
StaticArchiverOptions = rc |
182 |
DynamicArchiverOptions = -shared |
183 |
JavaArchiverOptions = |
184 |
JniOptions = |
185 |
RmiOptions = -d $(TargetDir) -classpath $(ClassPath) \ |
186 |
-sourcepath $(SourceDir) |
187 |
FortranOptions = |
188 |
F90Options = -I$(SourceDir) -module $(TargetDir) |
189 |
JavaCompilerOptions = -d $(TargetDir) -classpath $(ClassPath) \ |
190 |
-sourcepath $(SourceDir) -deprecation |
191 |
JavaRunOptions = -classpath $(ClassPath) |
192 |
PurifyOptions = |
193 |
JavadocOptions = -d $(DocsDir) \ |
194 |
-sourcepath $(SourceDir) \ |
195 |
-classpath $(ClassPath) \ |
196 |
-author \ |
197 |
-package \ |
198 |
-use \ |
199 |
-splitIndex \ |
200 |
-version \ |
201 |
-link file:$(JAVA_HOME)/docs/api \ |
202 |
-windowtitle $(JavadocWindowTitle) \ |
203 |
-doctitle $(JavadocDocTitle) \ |
204 |
-header $(JavadocHeader) \ |
205 |
-bottom $(JavadocFooter) |
206 |
WordCountOptions = --lines |
207 |
|
208 |
Empty = |
209 |
Space = $(Empty) $(Empty) |
210 |
|
211 |
|
212 |
#--------------------------------------------------------------------------- |
213 |
# |
214 |
# Rules |
215 |
# |
216 |
#--------------------------------------------------------------------------- |
217 |
default : build |
218 |
|
219 |
%.loop : |
220 |
@$(MAKE) $(MakeOptions) -C $(subst .loop,,$@) _$(MAKECMDGOALS)all |
221 |
|
222 |
# Create target directory |
223 |
$(PackageTargetDir) : |
224 |
$(MakeDir) $@ |
225 |
|
226 |
# .c -> .o |
227 |
$(PackageTargetDir)/%.o : $(PackageSourceDir)/%.c |
228 |
$(Print) $@ |
229 |
@$(CCompiler) $(COptions) -c $(IncludePath) $< -o $@ |
230 |
|
231 |
%.o : $(PackageSourceDir)/%.c |
232 |
$(MAKE) $(MakeOptions) $(PackageTargetDir)/$@ |
233 |
|
234 |
# .cpp -> .o |
235 |
$(PackageTargetDir)/%.o : $(PackageSourceDir)/%.cpp |
236 |
$(Print) $@ |
237 |
$(CppCompiler) $(CppOptions) -c $(IncludePath) $< -o $@ |
238 |
|
239 |
%.o : $(PackageSourceDir)/%.cpp |
240 |
$(MAKE) $(MakeOptions) $(PackageTargetDir)/$@ |
241 |
|
242 |
# .f -> .o |
243 |
$(PackageTargetDir)/%.o : $(PackageSourceDir)/%.f |
244 |
$(Print) $@ |
245 |
@$(FortranCompiler) $(FortranOptions) -c $< -o $@ |
246 |
|
247 |
%.o : $(PackageSourceDir)/%.f |
248 |
$(MAKE) $(MakeOptions) $(PackageTargetDir)/$@ |
249 |
|
250 |
# .F90 -> .o |
251 |
$(PackageTargetDir)/%.o : $(PackageSourceDir)/%.F90 |
252 |
$(Print) $@ |
253 |
@$(F90Compiler) $(F90Options) -c $< -o $@ |
254 |
|
255 |
%.o : $(PackageSourceDir)/%.F90 |
256 |
$(MAKE) $(MakeOptions) $(PackageTargetDir)/$@ |
257 |
|
258 |
# .java -> .class |
259 |
$(PackageTargetDir)/%.class : $(PackageSourceDir)/%.java |
260 |
$(Print) $@ |
261 |
@$(JavaCompiler) $(JavaCompilerOptions) $< |
262 |
|
263 |
%.class : $(PackageSourceDir)/%.java |
264 |
@$(MAKE) $(MakeOptions) $(PackageTargetDir)/$@ |
265 |
|
266 |
# .class -> .h |
267 |
$(PackageSourceDir)/%.h : $(PackageTargetDir)/%.class |
268 |
$(Print) $@ |
269 |
$(JniCompiler) $(JniOptions) $(JavaPackageName).$* |
270 |
|
271 |
%.h : %.class |
272 |
$(MAKE) $(MakeOptions) $(PackageSourceDir)/$@ |
273 |
|
274 |
#.y -> .h |
275 |
$(PackageSourceDir)/%.h : $(PackageSourceDir)/%.y |
276 |
$(Print) $@ |
277 |
$(Print) @$(Yacc) -d $? |
278 |
@$(Yacc) -d $? |
279 |
@$(Move) y.tab.h $*.h |
280 |
@$(Delete) y.tab.c |
281 |
|
282 |
#.y -> .c |
283 |
$(PackageSourceDir)/%.c : $(PackageSourceDir)/%.y |
284 |
$(Print) $@ |
285 |
$(Print) @$(Yacc) -d $? |
286 |
@$(Yacc) -d $? |
287 |
@$(Move) y.tab.c $*.c |
288 |
@$(Delete) y.tab.h |
289 |
|
290 |
# .l -> .c |
291 |
$(PackageSourceDir)/%.c : $(PackageSourceDir)/%.l |
292 |
$(Print) $@ |
293 |
$(Print) @$(Lex) -o$@ $? |
294 |
@$(Lex) -o$@ $? |
295 |
|
296 |
# .o -> .a |
297 |
$(LibDir)/%.a : $(ObjectFiles) |
298 |
$(Print) $@ |
299 |
@$(StaticArchiver) $(StaticArchiverOptions) $@ $(ObjectFiles) |
300 |
|
301 |
%.a : $(ObjectFiles) |
302 |
$(MAKE) $(MakeOptions) $(LibDir)/$@ |
303 |
|
304 |
# .o -> .so |
305 |
$(LibDir)/%.so : $(ObjectFiles) |
306 |
$(Print) $@ |
307 |
$(DynamicArchiver) $(ObjectFiles) $(DynamicArchiverOptions) -o $@ |
308 |
|
309 |
%.so : $(ObjectFiles) |
310 |
$(MAKE) $(MakeOptions) $(LibDir)/$@ |
311 |
|
312 |
# .class -> .jar |
313 |
$(LibDir)/%.jar : $(JavaClassFiles) $(OtherTargetFiles) |
314 |
$(Print) $@ |
315 |
@cd $(TargetDir); $(JavaArchiver) -cf $@ \ |
316 |
$(JavaClassFilesRel) $(OtherTargetFiles) |
317 |
|
318 |
%.jar : $(JavaClassFiles) $(OtherTargetFiles) |
319 |
$(MAKE) $(MakeOptions) $(LibDir)/$@ |
320 |
|
321 |
# .class -> JavaDoc |
322 |
javadoc : |
323 |
$(Print) $(JavaPackageNames) > $(DEV_ROOT)/packages.tmp |
324 |
$(JavadocGenerator) $(JavadocOptions) @$(DEV_ROOT)/packages.tmp |
325 |
$(Delete) $(DEV_ROOT)/packages.tmp |
326 |
$(Print) Done JavaDoc. |
327 |
|
328 |
# .class -> _Stub.class |
329 |
$(PackageTargetDir)/%_Stub.class : $(PackageTargetDir)/%.class |
330 |
$(Print) $@ |
331 |
$(RmiCompiler) $(RmiOptions) $(JavaPackageName).$* |
332 |
|
333 |
%_Stub.class : %.class |
334 |
$(MAKE) $(MakeOptions) $(PackageTargetDir)/$@ |
335 |
|
336 |
# .class -> _Skel.class |
337 |
$(PackageTargetDir)/%_Skel.class : $(PackageTargetDir)/%.class |
338 |
$(Print) $@ |
339 |
$(RmiCompiler) $(RmiOptions) $(JavaPackageName).$* |
340 |
|
341 |
%_Skel.class : %.class |
342 |
$(MAKE) $(MakeOptions) $(PackageTargetDir)/$@ |
343 |
|
344 |
# Executable |
345 |
$(Executable) : $(ObjectFiles) |
346 |
$(Print) $@ |
347 |
$(Linker) $(LinkOptions) $(LibDirs) $(LibList) $(ObjectFiles) -o $@ |
348 |
|
349 |
# Anything else is just copied from source to target |
350 |
$(PackageTargetDir)/% : $(PackageSourceDir)/% |
351 |
$(Print) $@ |
352 |
$(Copy) $< $@ |
353 |
|
354 |
# make (or make build) |
355 |
build : $(PackageListLoop) |
356 |
$(Print) Done build. |
357 |
|
358 |
_all : _buildall |
359 |
|
360 |
_buildall : \ |
361 |
$(DependencyFile) \ |
362 |
$(PackageTargetDir) \ |
363 |
$(ObjectFiles) \ |
364 |
$(JavaClassFiles) \ |
365 |
$(RmiStubFiles) \ |
366 |
$(RmiSkeletonFiles) \ |
367 |
$(OtherTargetFiles) \ |
368 |
$(SharedLibrary) \ |
369 |
$(StaticLibrary) \ |
370 |
$(JarFile) \ |
371 |
$(Executable) |
372 |
|
373 |
|
374 |
# make clean |
375 |
clean : $(PackageListLoop) |
376 |
$(Print) Done clean. |
377 |
|
378 |
_cleanall : |
379 |
$(Delete) $(PackageTargetDir)/* \ |
380 |
$(JarFile) \ |
381 |
$(SharedLibrary) \ |
382 |
$(StaticLibrary) \ |
383 |
$(Executable) \ |
384 |
$(DependencyFile) |
385 |
|
386 |
|
387 |
# make depend |
388 |
depend : $(PackageListLoop) |
389 |
$(Print) Done dependencies. |
390 |
|
391 |
_dependall : $(DependencyFile) |
392 |
|
393 |
$(DependencyFile) : $(DerivedSource) |
394 |
$(Print) $@ |
395 |
$(Print) $(DerivedSource) |
396 |
@cd $(PackageSourceDir) |
397 |
touch Make.temp |
398 |
ifdef $(CppFiles) |
399 |
$(CppCompiler) $(IncludePath) -MM $(CppFiles) > Make.temp |
400 |
endif |
401 |
ifdef $(CFiles) |
402 |
$(CCompiler) $(IncludePath) -MM $(CFiles) $(DerivedCFiles) >> Make.temp |
403 |
endif |
404 |
cat Make.temp | sed 's/^[a-zA-Z0-9]/$$\(DEV_ROOT\)\/obj\/&/g' >> $(DependencyFile) |
405 |
cat Make.temp | sed 's/^[a-zA-Z0-9]/$$\(DEV_ROOT\)\/MPIobj\/&/g' >> $(DependencyFile) |
406 |
echo $(F90Files) |
407 |
#ifdef $(F90Files) |
408 |
$(DEV_ROOT)/scripts/sfmakedepend -I $(DEV_ROOT)/src -d '$$(DEV_ROOT)/obj' -f ./Make.ftemp -h *.F90 |
409 |
cat Make.ftemp >> $(DependencyFile) |
410 |
#endif |
411 |
$(Delete) Make.temp Make.ftemp |
412 |
|
413 |
# make lib |
414 |
lib : $(PackageListLoop) |
415 |
$(Print) Libraries built. |
416 |
|
417 |
_liball : $(JarFile) $(SharedLibrary) $(StaticLibrary) |
418 |
|
419 |
jar : $(JarFile) |
420 |
|
421 |
jarsign : $(JarFile) |
422 |
$(JarSigner) -keystore GeoSoftKeystore $(JarFile) myself |
423 |
|
424 |
# make statistics |
425 |
_statisticsall : |
426 |
@$(Print) $(SourceFiles) >> $(DEV_ROOT)/files.tmp |
427 |
|
428 |
statistics : $(PackageListLoop) |
429 |
@$(List) $(DEV_ROOT)/files.tmp | xargs $(WordCount) $(WordCountOptions) |
430 |
@$(Delete) $(DEV_ROOT)/files.tmp |
431 |
$(Print) Done statistics. |
432 |
|
433 |
# make pure |
434 |
$(Executable).pure : |
435 |
$(Purify) $(PurifyOptions) $(CppCompiler) $(LinkOptions) $(LibDirs) \ |
436 |
$(LibList) $(ObjectFiles) -o $@ |
437 |
|
438 |
pure : $(Executable).pure |
439 |
|
440 |
# Execute |
441 |
_runexe : |
442 |
$(Executable) $(RunParameters) |
443 |
|
444 |
_runjava : |
445 |
$(JavaExecute) $(JavaRunOptions) $(JavaMainClass) $(RunParameters) |
446 |
|
447 |
run : _runjava |
448 |
|
449 |
|
450 |
ifdef $(DependencyFile) |
451 |
-include $(DependencyFile) |
452 |
endif |