-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile.gappkg
220 lines (186 loc) · 7.32 KB
/
Makefile.gappkg
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
########################################################################
#
# The build rules in this file are intended for use by GAP packages that
# want to build a simple GAP kernel extensions. They are based on the
# GAP build system, and require GNU make. To use this in your GAP
# package, `include` this file from your primary Makefile. You must also
# set several variables beforehand:
#
# - GAPPATH must be set to the location of the GAP installation against
# which to build your package.
# - KEXT_NAME should be the name of your kernel extension (without
# file extensions like .so or .dll)
# - KEXT_SOURCES must contain a list of .c or .cc files to be linked
# into your kernel extension
# - optionally, you can set KEXT_CFLAGS, KEXT_CXXFLAGS, KEXT_LDFLAGS
# - if you are using autoconf to produce your configure script, set
# KEXT_USE_AUTOCONF to 1 to enable dependency rules that enable
# regenerating the configure script etc. when necessary
#
# The contents of this file are released into the public domain; hence
# you may edit this file as you wish, bundle and distribute it with your
# package, etc.
#
# If you bundle this file with your package, please try not to edit it,
# so that we can keep it identical across all GAP packages. Instead, if
# you find that you must edit it, please submit your changes back to
# the GAP team, so that a future version of this file can be adjusted
# to cover your usecase without modifications, thus ensuring you can
# always easily update to newer version of it.
#
########################################################################
# read GAP's build settings
include $(GAPPATH)/sysinfo.gap
# hack to support GAP <= 4.9
ifndef GAP_KERNEL_MAJOR_VERSION
KEXT_CFLAGS += -I$(GAP_LIB_DIR)/src
KEXT_CXXFLAGS += -I$(GAP_LIB_DIR)/src
endif
# honor user supplied flags
KEXT_CFLAGS += $(CPPFLAGS)
KEXT_CFLAGS += $(CFLAGS)
KEXT_CXXFLAGS += $(CPPFLAGS)
KEXT_CXXFLAGS += $(CXXFLAGS)
KEXT_LDFLAGS += $(LDFLAGS)
# various derived settings
KEXT_BINARCHDIR = bin/$(GAParch)
KEXT_SO = $(KEXT_BINARCHDIR)/$(KEXT_NAME).so
# the following settings are provided by sysinfo.gap in GAP >= 4.12;
# for compatibility with older GAP version (at least 4.9, 4.10, 4.11)
# we try to "guess" suitable values here
GAP ?= $(GAPPATH)/gap
GAC ?= $(GAPPATH)/gac
GAP_OBJEXT ?= lo
# override KEXT_RECONF if your package needs a different invocation
# for reconfiguring (e.g. `./config.status --recheck` for autoconf)
ifdef KEXT_USE_AUTOCONF
KEXT_RECONF ?= ./config.status Makefile
else
KEXT_RECONF ?= ./configure "$(GAPPATH)"
endif
# default target
all: $(KEXT_SO)
.PHONY: all
########################################################################
# Object files
# For each file FOO.c in SOURCES, add gen/FOO.$(GAP_OBJEXT) to KEXT_OBJS
# and similar for .cc files
########################################################################
KEXT_OBJS = $(patsubst %.s,gen/%.$(GAP_OBJEXT), \
$(patsubst %.cc,gen/%.$(GAP_OBJEXT), \
$(patsubst %.c,gen/%.$(GAP_OBJEXT), \
$(KEXT_SOURCES))))
########################################################################
# Quiet rules.
#
# Replace regular output with quiet messages, unless V is set,
# e.g. "make V=1"
########################################################################
ifneq ($(findstring $(MAKEFLAGS),s),s)
ifndef V
QUIET_GAC = @echo " GAC $< => $@";>/dev/null # keep the trailing space!
endif
endif
########################################################################
# Rules for automatic header dependency tracking.
# This is based on the GAP build system.
########################################################################
# List of all (potential) dependency files, derived from KEXT_OBJS
KEXT_DEPFILES = $(patsubst %.$(GAP_OBJEXT),%.d,$(KEXT_OBJS))
# Include the dependency tracking files
-include $(KEXT_DEPFILES)
# Mark *.d files as PHONY. This stops make from trying to recreate them
# (which it can't), and in particular from looking for potential source
# files. This can save quite a bit of disk access time.
.PHONY: $(KEXT_DEPFILES)
# The following flags instruct the compiler to enable advanced
# dependency tracking. Supported by GCC 3 and newer; clang; Intel C
# compiler; and more.
KEXT_DEPFLAGS = -MQ "$@" -MMD -MP -MF $(@D)/$(*F).d
# build rule for C code
# The dependency on Makefile ensures that re-running configure recompiles everything
gen/%.$(GAP_OBJEXT): %.c Makefile
@mkdir -p $(@D)
$(QUIET_GAC)$(GAC) -d -p "$(KEXT_DEPFLAGS)" -p "$(KEXT_CFLAGS)" -c $< -o $@
# build rule for C++ code
# The dependency on Makefile ensures that re-running configure recompiles everything
gen/%.$(GAP_OBJEXT): %.cc Makefile
@mkdir -p $(@D)
$(QUIET_GAC)$(GAC) -d -p "$(KEXT_DEPFLAGS)" -p "$(KEXT_CXXFLAGS)" -c $< -o $@
# build rule for assembler code
# The dependency on Makefile ensures that re-running configure recompiles everything
gen/%.$(GAP_OBJEXT): %.s Makefile
@mkdir -p $(@D)
$(QUIET_GAC)$(GAC) -d -p "$(KEXT_DEPFLAGS)" -p "$(KEXT_CFLAGS)" -c $< -o $@
# build rule for linking all object files together into a kernel extension
$(KEXT_SO): $(KEXT_OBJS)
@mkdir -p $(@D)
$(QUIET_GAC)$(GAC) -d -p "$(KEXT_DEPFLAGS)" -P "$(KEXT_LDFLAGS)" $(KEXT_OBJS) -o $@
# hook into `make clean`
clean: clean-kext
clean-kext:
rm -rf $(KEXT_BINARCHDIR) gen
# hook into `make distclean`
distclean: distclean-kext
distclean-kext:
rm -rf bin gen Makefile
rm -rf doc/_*.xml
rm -rf doc/*.aux doc/*.bbl doc/*.blg doc/*.brf doc/*.idx doc/*.idx
rm -rf doc/*.ilg doc/*.ind doc/*.log doc/*.out doc/*.pnr doc/*.toc
# hook into `make doc`
doc: doc-kext
doc-kext:
$(GAP) --quitonbreak -b -q < makedoc.g
# hook into `make check`
check: check-kext
check-kext:
$(GAP) tst/testall.g
# re-run configure if configure, Makefile.in or GAP itself changed
Makefile: configure Makefile.in $(GAPPATH)/sysinfo.gap
$(KEXT_RECONF)
ifdef KEXT_USE_AUTOCONF
# react to modifications of the build system
configure_deps = configure.ac $(wildcard m4/*.m4)
ifneq ($(MAINTAINER_MODE),no)
configure: $(configure_deps)
@if command -v autoconf >/dev/null 2>&1 ; then \
echo "running autoconf" ; \
autoconf ; \
else \
echo "autoconf not available, proceeding with stale configure" ; \
fi
endif # MAINTAINER_MODE
# re-run configure if configure, Makefile.in or GAP itself changed
config.status: configure $(GAPPATH)/sysinfo.gap
./config.status --recheck
# update Makefile if config.status changed
Makefile: config.status
gen/pkgconfig.h: gen/pkgconfig.h.stamp
@if test ! -f $@; then rm -f $<; else :; fi
@if test ! -f $@; then $(MAKE) $<; else :; fi
gen/pkgconfig.h.stamp: src/pkgconfig.h.in config.status
@rm -f $@
@mkdir -p $(@D)
./config.status gen/pkgconfig.h
echo > $@
ifneq ($(MAINTAINER_MODE),no)
src/pkgconfig.h.in: $(configure_deps)
@if command -v autoheader >/dev/null 2>&1 ; then \
mkdir -p $(@D) ; \
echo "running autoheader" ; \
autoheader ; \
rm -f gen/pkgconfig.h.stamp ; \
else \
echo "autoheader not available, proceeding with stale config.h" ; \
fi
touch $@
endif # MAINTAINER_MODE
endif # KEXT_USE_AUTOCONF
.PHONY: check clean distclean doc
.PHONY: check-kext clean-kext distclean-kext doc-kext
########################################################################
# Makefile debugging trick:
# call print-VARIABLE to see the runtime value of any variable
########################################################################
print-%:
@echo '$*=$($*)'