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