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