-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGNUmakefile.subcommon
175 lines (143 loc) · 5.82 KB
/
GNUmakefile.subcommon
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
THISDIR := $(TOPDIR)/$(PACKAGE)
LIBDIR := $(TOPDIR)/lib
TMP_OPT := $(TOPDIR)/tmp/OPT/$(PACKAGE)
TMP_DEB := $(TOPDIR)/tmp/DEB/$(PACKAGE)
ifeq (,$($(PACKAGE)_EXCEPT_DIR))
EXCEPT_DIR_PATS :=
else
EXCEPT_DIR_PATS := $(foreach d,$($(PACKAGE)_EXCEPT_DIR),$(THISDIR)/$(d)/%)
endif
ifeq (,$(wildcard $(LIBDIR)))
$(shell mkdir -p $(LIBDIR))
endif
ifeq (,$(wildcard $(TMP_OPT)))
$(shell mkdir -p $(TMP_OPT))
endif
ifeq (,$(wildcard $(TMP_DEB)))
$(shell mkdir -p $(TMP_DEB))
endif
ifneq (,$($(PACKAGE)_SOURCE_FOR))
SOURCE_FOR := $(foreach s,$($(PACKAGE)_SOURCE_FOR),\
$(wildcard $(THISDIR)/*/$(s)))
else
SOURCE_FOR := $(wildcard $(THISDIR)/*/*.for)
endif
SOURCE_FOR := $(filter-out $(EXCEPT_DIR_PATS), $(SOURCE_FOR))
ifneq (,$($(PACKAGE)_EXCEPT_FOR))
EXCEPT_FOR := $(foreach s,$($(PACKAGE)_EXCEPT_FOR),\
$(wildcard $(THISDIR)/*/$(s)))
SOURCE_FOR := $(filter-out $(EXCEPT_FOR),$(SOURCE_FOR))
endif
OBJECT_FOR := $(patsubst %.for,%.o,$(patsubst $(THISDIR)/%,%,$(SOURCE_FOR)))
OBJECT_FOR_OPT := $(addprefix $(TMP_OPT)/,$(OBJECT_FOR))
OBJECT_FOR_DEB := $(addprefix $(TMP_DEB)/,$(OBJECT_FOR))
ifneq (,$($(PACKAGE)_SOURCE_F))
SOURCE_F := $(foreach s,$($(PACKAGE)_SOURCE_F),\
$(wildcard $(THISDIR)/*/$(s)))
else
SOURCE_F := $(wildcard $(THISDIR)/*/*.f)
endif
SOURCE_F := $(filter-out $(EXCEPT_DIR_PATS), $(SOURCE_F))
ifneq (,$($(PACKAGE)_EXCEPT_F))
EXCEPT_F := $(foreach s,$($(PACKAGE)_EXCEPT_F),\
$(wildcard $(THISDIR)/*/$(s)))
SOURCE_F := $(filter-out $(EXCEPT_F),$(SOURCE_F))
endif
OBJECT_F := $(patsubst %.f,%.o,$(patsubst $(THISDIR)/%,%,$(SOURCE_F)))
OBJECT_F_OPT := $(addprefix $(TMP_OPT)/,$(OBJECT_F))
OBJECT_F_DEB := $(addprefix $(TMP_DEB)/,$(OBJECT_F))
ifneq (,$($(PACKAGE)_SOURCE_C))
SOURCE_C := $(foreach s,$($(PACKAGE)_SOURCE_C),\
$(wildcard $(THISDIR)/*/$(s)))
else
SOURCE_C := $(wildcard $(THISDIR)/*/*.c)
endif
ifneq (,$($(PACKAGE)_EXCEPT_C))
EXCEPT_C := $(foreach s,$($(PACKAGE)_EXCEPT_C),\
$(wildcard $(THISDIR)/*/$(s)))
SOURCE_C := $(filter-out $(EXCEPT_C),$(SOURCE_C))
endif
SOURCE_C := $(filter-out $(EXCEPT_DIR_PATS), $(SOURCE_C))
OBJECT_C := $(patsubst %.c,%.o,$(patsubst $(THISDIR)/%,%,$(SOURCE_C)))
OBJECT_C_OPT := $(addprefix $(TMP_OPT)/,$(OBJECT_C))
OBJECT_C_DEB := $(addprefix $(TMP_DEB)/,$(OBJECT_C))
OBJECT_DEB := $(OBJECT_FOR_DEB) $(OBJECT_C_DEB) $(OBJECT_F_DEB)
OBJECT_OPT := $(OBJECT_FOR_OPT) $(OBJECT_C_OPT) $(OBJECT_F_OPT)
define for_common_compile
$(NOECHO) echo '-->' $(1) $<
$(NOECHO) mkdir -p $(dir $@)
$(NOECHO) mkdir -p $(TOPDIR)/tmp/$(1)/$(dir $<)
$(NOECHO) $(BINDIR)/tasteofd0 LINUX < $< | \
$(BINDIR)/vmstounix > $(TOPDIR)/tmp/$(1)/$(patsubst %.for,%.f,$<)
$(NOECHO) $(FORT) \
$(FORT_COMMON_FLAGS) -I $(dir $<) $(FORT_$(1)_FLAGS) -c -o $@ \
$(TOPDIR)/tmp/$(1)/$(patsubst %.for,%.f,$<)
$(NOECHO) echo "$@ : $< \\" > $(TOPDIR)/tmp/$(1)/$(patsubst %.for,%.d,$<)
$(NOECHO) $(BINDIR)/for_depend < $< >> $(TOPDIR)/tmp/$(1)/$(patsubst %.for,%.d,$<)
$(NOECHO) echo "" >> $(TOPDIR)/tmp/$(1)/$(patsubst %.for,%.d,$<)
endef
define c_common_compile
$(NOECHO) echo '-->' $(1) $<
$(NOECHO) mkdir -p $(dir $@)
$(NOECHO) $(CC) -MMD \
$(C_COMMON_FLAGS) $(C_$(1)_FLAGS) -c -o $@ $<
endef
define f_common_compile
$(NOECHO) echo '-->' $(1) $<
$(NOECHO) mkdir -p $(dir $@)
$(NOECHO) $(FORT) $(FORT_COMMON_FLAGS) $(FORT_$(1)_FLAGS) -c -o $@ $<
$(NOECHO) echo "$@ : $< \\" > $(TOPDIR)/tmp/$(1)/$(patsubst %.f,%.d,$<)
$(NOECHO) $(BINDIR)/f_depend < $< >> $(TOPDIR)/tmp/$(1)/$(patsubst %.f,%.d,$<)
$(NOECHO) echo "" >> $(TOPDIR)/tmp/$(1)/$(patsubst %.f,%.d,$<)
endef
define make_lib_common
$(NOECHO) echo '-->' Make lib $@
$(NOECHO) ar cr $@ $+
endef
ifneq (,$($(PACKAGE)_LIB))
LIB_OPT := $(LIBDIR)/$(PACKAGE).a
LIB_DEB := $(LIBDIR)/$(PACKAGE)_deb.a
libs : $(LIB_DEB) $(LIB_OPT)
$(LIB_DEB) : $(OBJECT_DEB)
$(make_lib_common)
$(LIB_OPT) : $(OBJECT_OPT)
$(make_lib_common)
$(OBJECT_FOR_DEB) : $(TMP_DEB)/%.o : $(THISDIR)/%.for $(BINDIR)/tasteofd0 $(BINDIR)/vmstounix $(BINDIR)/for_depend
$(call for_common_compile,DEB)
$(OBJECT_FOR_OPT) : $(TMP_OPT)/%.o : $(THISDIR)/%.for $(BINDIR)/tasteofd0 $(BINDIR)/vmstounix $(BINDIR)/for_depend
$(call for_common_compile,OPT)
-include $(foreach f,$(OBJECT_FOR_DEB),$(basename $(f)).d)
-include $(foreach f,$(OBJECT_FOR_OPT),$(basename $(f)).d)
$(OBJECT_C_DEB) : $(TMP_DEB)/%.o : $(THISDIR)/%.c
$(call c_common_compile,DEB)
$(OBJECT_C_OPT) : $(TMP_OPT)/%.o : $(THISDIR)/%.c
$(call c_common_compile,OPT)
-include $(foreach f,$(OBJECT_C_DEB),$(basename $(f)).d)
-include $(foreach f,$(OBJECT_C_OPT),$(basename $(f)).d)
$(OBJECT_F_DEB) : $(TMP_DEB)/%.o : $(THISDIR)/%.f $(BINDIR)/f_depend
$(call f_common_compile,DEB)
$(OBJECT_F_OPT) : $(TMP_OPT)/%.o : $(THISDIR)/%.f $(BINDIR)/f_depend
$(call f_common_compile,OPT)
-include $(foreach f,$(OBJECT_F_DEB),$(basename $(f)).d)
-include $(foreach f,$(OBJECT_F_OPT),$(basename $(f)).d)
endif
##############################################################################3
ifneq (,$($(PACKAGE)_BINS))
BINS_OPT := $(foreach b, $($(PACKAGE)_BINS), $(BINDIR)/$(b))
BINS_DEB := $(foreach b, $($(PACKAGE)_BINS), $(BINDIR)/$(b)_deb)
$(info $(PACKAGE) $($(PACKAGE)_BINS))
$(info $(PACKAGE) BINS_OPT $(BINS_OPT))
$(BINS_OPT) : $(BINDIR)/% : $(TMP_OPT)/source/%.o
$(NOECHO) echo link $< $@ $* libs $(foreach l, $($*_LIBS), $(LIBDIR)/$(l).a)
$(NOECHO) gfortran -o $@ $< $(foreach l, $($*_LIBS), $(LIBDIR)/$(l).a) -L$(CERN_ROOT)/lib -lpacklib -lkernlib -lcrypt
all : $(BINS_OPT)
endif
##############################################################################3
clean : clean-$(PACKAGE)
clean-$(PACKAGE) :
$(NOECHO) PACKAGE=$(patsubst clean-%,%,$@); \
echo Cleaning $$PACKAGE; \
rm -rf $(TOPDIR)/tmp/OPT/$$PACKAGE; \
rm -rf $(TOPDIR)/tmp/DEB/$$PACKAGE; \
rm -f $(LIBDIR)/$$PACKAGE.a; \
rm -f $(LIBDIR)/deb_$$PACKAGE.a