-
Notifications
You must be signed in to change notification settings - Fork 1
/
Imake.tmpl
117 lines (91 loc) · 4.06 KB
/
Imake.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
.SUFFIXES:
.SUFFIXES: .c .cxx .o .s .i .a
/*
* Written by:
* Kevin J. Bowers, Ph.D.
* Plasma Physics Group (X-1)
* Applied Physics Division
* Los Alamos National Lab
* circa 2000 - Original version developed at UC-Berkeley
* March/April 2004 - Adapted and extended from earlier V4PIC Imake.tmpl
*
*/
#define Concat2(a,b)a/**/b
#define Concat3(a,b,c)a/**/b/**/c
#define AltConcat2(a,b)a##b
#define AltConcat3(a,b,c)a##b##c
/* The space after dir is very important! */
#define CleanDir(dir) @@\
ifneq (dir,$(findstring dir ,$(CLEAN_DIRS))) @@\
CLEAN_DIRS += dir @@\
endif
/* The space after Concat2(-I,dir) is very important! */
#define AddModule(module,dir,objects) @@\
CleanDir(dir) @@\
ifneq (Concat2(-I,dir),$(findstring Concat2(-I,dir) ,$(INCLUDE_DIRS))) @@\
INCLUDE_DIRS += Concat2(-I,dir) @@\
endif @@\
Concat2(module,_OBJS) = objects @@\
MODULE_OBJS += $(foreach obj,$(Concat2(module,_OBJS)),dir/$(obj).o) @@\
MODULE_ASMS += $(foreach obj,$(Concat2(module,_OBJS)),dir/$(obj).s) @@\
MODULE_PPPS += $(foreach obj,$(Concat2(module,_OBJS)),dir/$(obj).i)
#define MakeExecutable(exec,dir,objects) @@\
EXEC += exec.EXTENSION @@\
CleanDir(dir) @@\
Concat2(exec,_objs) = objects @@\
Concat2(exec,_OBJS) += $(foreach obj,$(Concat2(exec,_objs)),dir/$(obj).o) @@\
exec.EXTENSION:: libvpic.EXTENSION.a $(Concat2(exec,_OBJS)) @@\
$(LD) -o exec.EXTENSION $(LDFLAGS) $(Concat2(exec,_OBJS)) -L. $(LIBRARY_DIRS) -lvpic.EXTENSION $(LIBRARIES)
#ifndef MACHINE
#define MACHINE machine/default
#endif
#ifndef IMAKEFILE
#define IMAKEFILE Imakefile
#endif
all::
/* Note: MACHINE defines EXTENSION, machine specific libraries and
directories, program locations and compiler flags */
XCOMM -------------------------Begin Machine Include-----------------------
#include Concat3(<,MACHINE,>)
XCOMM -------------------------End Machine Include-------------------------
/* Note: Imakefile adds non-machine specific libraries and directories,
and specifies modules and executable targets */
XCOMM -------------------------Begin Imakefile Include---------------------
#include Concat3(<,IMAKEFILE,>)
XCOMM -------------------------End Imakefile Include-----------------------
all:: build.EXTENSION libvpic.EXTENSION.a $(EXEC)
/* BJA: The following ensures that make clean/veryclean won't get faked out by
nested comments on some versions of Imake... */
clean:
$(foreach dir,$(CLEAN_DIRS),$(RM) Concat2($(dir)/,?*.o) Concat2($(dir)/,?*.s) Concat2($(dir)/,?*.i) Concat2($(dir)/,.?*.swp) Concat2($(dir)/,#?*) Concat2($(dir)/,?*~) Concat2($(dir)/,?.o) Concat2($(dir)/,?.s) Concat2($(dir)/,?.i) Concat2($(dir)/,.?.swp) Concat2($(dir)/,#?) Concat2($(dir)/,?~);)
$(foreach exec,$(EXEC),$(RM) $(exec);)
$(RM) ./libvpic.EXTENSION.a ./Makefile.bak
$(RM) ./build.EXTENSION
veryclean: clean
$(RM) ./libvpic.*.a ./build.* ./Makefile Concat2(./bin/,*)
.c.o:
$(CC) $(CFLAGS) $(INCLUDE_DIRS) -c $*.c -o $*.o
.cxx.o:
$(CXX) $(CXXFLAGS) $(INCLUDE_DIRS) -c $*.cxx -o $*.o
.c.i:
$(CC) $(CFLAGS) $(INCLUDE_DIRS) -E $*.c -o $*.i
.cxx.i:
$(CXX) $(CXXFLAGS) $(INCLUDE_DIRS) -E $*.cxx -o $*.i
.c.s:
$(CC) $(CFLAGS) $(INCLUDE_DIRS) -S -fverbose-asm $*.c -o $*.s
.cxx.s:
$(CXX) $(CXXFLAGS) $(INCLUDE_DIRS) -S -fverbose-asm $*.cxx -o $*.s
preprocessed: $(MODULE_PPPS)
asm: $(MODULE_ASMS)
libvpic.EXTENSION.a: $(MODULE_OBJS)
$(RM) ./libvpic.EXTENSION.a
$(AR) $(ARFLAGS) ./libvpic.EXTENSION.a $(MODULE_OBJS)
$(RANLIB) ./libvpic.EXTENSION.a
build.EXTENSION: libvpic.EXTENSION.a
echo "#!/bin/bash" > build.EXTENSION
echo export INPUT_DECK_DIR='`pwd`' >> build.EXTENSION
echo "pushd . >& /dev/null" >> build.EXTENSION
echo cd $(PWD) >> build.EXTENSION
echo $(CXX) $(CXXFLAGS) $(INCLUDE_DIRS) src/main.cxx src/deck_wrapper.cxx -DINPUT_DECK='$$INPUT_DECK_DIR/$$1' -o '$$INPUT_DECK_DIR/$$1'.EXTENSION $(LIBRARY_DIRS) -L. -lvpic.EXTENSION $(LIBRARIES) >> build.EXTENSION
echo "popd >& /dev/null" >> build.EXTENSION
chmod u+x build.EXTENSION