forked from envmodules/modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
414 lines (357 loc) · 13.3 KB
/
Makefile
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
.PHONY: doc pkgdoc initdir install install-testsiteconfig \
install-testsiteconfig-1 install-testmodulerc install-testetcrc \
install-testmodspath install-testmodspath-empty uninstall-testconfig \
uninstall dist dist-tar dist-gzip dist-bzip2 srpm clean distclean test \
testinstall instrument testcoverage
# definitions for code coverage
NAGELFAR_DLSRC1 := http://downloads.sourceforge.net/nagelfar/
NAGELFAR_DLSRC2 := https://ftp.openbsd.org/pub/OpenBSD/distfiles/
NAGELFAR_RELEASE := nagelfar125
NAGELFAR_DIST := $(NAGELFAR_RELEASE).tar.gz
NAGELFAR_DISTSUM := 707e3c305437dce1f14103f0bd058fc9
NAGELFAR := $(NAGELFAR_RELEASE)/nagelfar.tcl
COVERAGE_SRCFILE := modulecmd.tcl
COVERAGE_IFILE := $(COVERAGE_SRCFILE:.tcl=.tcl_i)
COVERAGE_LOGFILE := $(COVERAGE_SRCFILE:.tcl=.tcl_log)
COVERAGE_MFILE := $(COVERAGE_SRCFILE:.tcl=.tcl_m)
# compatibility version-related files
COMPAT_DIR := compat
# source definitions shared across the Makefiles of this project
ifneq ($(wildcard Makefile.inc),Makefile.inc)
$(error Makefile.inc is missing, please run './configure')
endif
include Makefile.inc
all: initdir modulecmd.tcl ChangeLog README \
contrib/scripts/add.modules contrib/scripts/modulecmd
ifeq ($(compatversion),y)
all: $(COMPAT_DIR)/modulecmd$(EXEEXT) $(COMPAT_DIR)/ChangeLog
else
endif
# skip doc build if no sphinx-build
ifeq ($(builddoc),y)
all: pkgdoc
endif
initdir: version.inc
$(MAKE) -C init all
pkgdoc: version.inc
$(MAKE) -C doc man txt
doc: version.inc
$(MAKE) -C doc all
# build version.inc shared definitions from git repository info
ifeq ($(wildcard .git) $(wildcard version.inc.in),.git version.inc.in)
GIT_CURRENT_TAG := $(shell git describe --tags --abbrev=0)
GIT_CURRENT_DESC := $(shell git describe --tags)
GIT_CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
MODULES_RELEASE := $(subst v,,$(GIT_CURRENT_TAG))
MODULES_BUILD_DATE := $(shell git log -1 --format=%cd --date=short)
ifeq ($(GIT_CURRENT_TAG),$(GIT_CURRENT_DESC))
MODULES_BUILD :=
else ifeq ($(GIT_CURRENT_BRANCH),master)
MODULES_BUILD := +$(subst $(GIT_CURRENT_TAG)-,,$(GIT_CURRENT_DESC))
else
MODULES_BUILD := +$(GIT_CURRENT_BRANCH)$(subst $(GIT_CURRENT_TAG),,$(GIT_CURRENT_DESC))
endif
# determine RPM release
# retrieve all parts of the release number and increase minor release number
MODULES_RELEASE_BASE := $(firstword $(subst -, ,$(MODULES_RELEASE)))
ifeq ($(MODULES_RELEASE),$(MODULES_RELEASE_BASE))
MODULES_RELEASE_SUFFIX :=
else
MODULES_RELEASE_SUFFIX := $(subst $(MODULES_RELEASE_BASE)-,,$(MODULES_RELEASE))
endif
MODULES_LAST_RPM_VERSREL := $(shell $(GREP) -Pzo -m 1 '%changelog\n+\*.* - \K.*\n' \
contrib/rpm/environment-modules.spec.in)
MODULES_LAST_RPM_RELEASE := $(subst $(MODULES_RELEASE_BASE)-,,$(MODULES_LAST_RPM_VERSREL))
ifneq ($(MODULES_RELEASE_SUFFIX),)
MODULES_LAST_RPM_RELEASE := $(subst .$(MODULES_RELEASE_SUFFIX),,$(MODULES_LAST_RPM_RELEASE))
endif
# use last release if we currently sat on tag
ifeq ($(GIT_CURRENT_TAG),$(GIT_CURRENT_DESC))
MODULES_RPM_RELEASE := $(MODULES_LAST_RPM_RELEASE)
else
MODULES_LAST_RPM_RELEASE_P1 := $(firstword $(subst ., ,$(MODULES_LAST_RPM_RELEASE)))
MODULES_LAST_RPM_RELEASE_P2 := $(subst $(MODULES_LAST_RPM_RELEASE_P1).,,$(MODULES_LAST_RPM_RELEASE))
ifeq ($(MODULES_LAST_RPM_RELEASE_P2),)
MODULES_RPM_RELEASE_P2 := 1
else
MODULES_RPM_RELEASE_P2 := $(shell echo $$(($(MODULES_LAST_RPM_RELEASE_P2)+1)))
endif
MODULES_RPM_RELEASE := $(MODULES_LAST_RPM_RELEASE_P1).$(MODULES_RPM_RELEASE_P2)
ifneq ($(MODULES_RELEASE_SUFFIX),)
MODULES_RPM_RELEASE := $(MODULES_RPM_RELEASE).$(MODULES_RELEASE_SUFFIX)
endif
MODULES_RPM_RELEASE := $(MODULES_RPM_RELEASE)$(subst -,.,$(MODULES_BUILD))
endif
else
# source version definitions shared across the Makefiles of this project
ifneq ($(wildcard version.inc),version.inc)
$(error version.inc is missing)
endif
include version.inc
endif
# comment entries if feature not enabled
ifeq ($(versioning),y)
setversioning :=
setnotversioning := \#
else
setversioning := \#
setnotversioning :=
endif
define translate-in-script
sed -e 's|@prefix@|$(prefix)|g' \
-e 's|@baseprefix@|$(baseprefix)|g' \
-e 's|@libexecdir@|$(libexecdir)|g' \
-e 's|@initdir@|$(initdir)|g' \
-e 's|@etcdir@|$(etcdir)|g' \
-e 's|@modulefilesdir@|$(modulefilesdir)|g' \
-e 's|@VERSION@|$(VERSION)|g' \
-e 's|@TCLSHDIR@/tclsh|$(TCLSH)|g' \
-e 's|@TCLSH@|$(TCLSH)|g' \
-e 's|@pager@|$(pager)|g' \
-e 's|@pageropts@|$(pageropts)|g' \
-e 's|@VERSIONING@|$(setversioning)|g' \
-e 's|@NOTVERSIONING@|$(setnotversioning)|g' \
-e 's|@MODULES_RELEASE@|$(MODULES_RELEASE)|g' \
-e 's|@MODULES_BUILD@|$(MODULES_BUILD)|g' \
-e 's|@MODULES_RPM_RELEASE@|$(MODULES_RPM_RELEASE)|g' \
-e 's|@MODULES_BUILD_DATE@|$(MODULES_BUILD_DATE)|g' $< > $@
endef
ifeq ($(wildcard .git) $(wildcard version.inc.in),.git version.inc.in)
# rebuild if git repository changed
version.inc: version.inc.in .git/index
$(translate-in-script)
contrib/rpm/environment-modules.spec: contrib/rpm/environment-modules.spec.in .git/index
$(translate-in-script)
else
# avoid shared definitions to be rebuilt by make
version.inc: ;
# do not rebuild spec file if not in git repository
contrib/rpm/environment-modules.spec: ;
endif
DIST_PREFIX := modules-$(MODULES_RELEASE)$(MODULES_BUILD)
# avoid shared definitions to be rebuilt by make
Makefile.inc: ;
modulecmd.tcl: modulecmd.tcl.in version.inc
$(translate-in-script)
chmod +x $@
ChangeLog:
contrib/gitlog2changelog.py
README:
sed -e '/^\[\!\[.*\].*/d' [email protected] > $@
contrib/scripts/add.modules: contrib/scripts/add.modules.in
$(translate-in-script)
contrib/scripts/modulecmd: contrib/scripts/modulecmd.in
$(translate-in-script)
# compatibility version-related rules
$(COMPAT_DIR)/modulecmd$(EXEEXT) $(COMPAT_DIR)/ChangeLog:
$(MAKE) -C $(COMPAT_DIR) $(@F)
# example configs for test rules
testsuite/example/.modulespath: testsuite/example/.modulespath.in
$(translate-in-script)
testsuite/example/modulerc: testsuite/example/modulerc.in
$(translate-in-script)
install-testsiteconfig: testsuite/example/siteconfig.tcl
$(MAKE) -C init install-testconfig DESTDIR=$(DESTDIR)
cp $^ $(DESTDIR)$(etcdir)/
install-testsiteconfig-1: testsuite/example/siteconfig.tcl-1
$(MAKE) -C init install-testconfig DESTDIR=$(DESTDIR)
cp $^ $(DESTDIR)$(etcdir)/siteconfig.tcl
install-testmodulerc: testsuite/example/modulerc
$(MAKE) -C init install-testconfig DESTDIR=$(DESTDIR)
cp $^ $(DESTDIR)$(initdir)/
install-testetcrc: testsuite/etc/empty
$(MAKE) -C init install-testconfig DESTDIR=$(DESTDIR)
cp $^ $(DESTDIR)$(prefix)/etc/rc
install-testmodspath: testsuite/example/.modulespath
$(MAKE) -C init install-testconfig DESTDIR=$(DESTDIR)
cp $^ $(DESTDIR)$(initdir)/
install-testmodspath-empty: testsuite/example/.modulespath-empty
$(MAKE) -C init install-testconfig DESTDIR=$(DESTDIR)
cp $^ $(DESTDIR)$(initdir)/.modulespath
uninstall-testconfig:
rm -f $(DESTDIR)$(prefix)/etc/rc
rm -f $(DESTDIR)$(etcdir)/siteconfig.tcl
rm -f $(DESTDIR)$(initdir)/modulerc
rm -f $(DESTDIR)$(initdir)/.modulespath
$(MAKE) -C init uninstall-testconfig DESTDIR=$(DESTDIR)
ifeq ($(compatversion),y)
install: modulecmd.tcl ChangeLog README contrib/scripts/add.modules \
contrib/scripts/modulecmd $(COMPAT_DIR)/modulecmd$(EXEEXT) $(COMPAT_DIR)/ChangeLog
else
install: modulecmd.tcl ChangeLog README contrib/scripts/add.modules \
contrib/scripts/modulecmd
endif
mkdir -p $(DESTDIR)$(libexecdir)
mkdir -p $(DESTDIR)$(bindir)
cp modulecmd.tcl $(DESTDIR)$(libexecdir)/
chmod +x $(DESTDIR)$(libexecdir)/modulecmd.tcl
ifeq ($(compatversion),y)
cp $(COMPAT_DIR)/modulecmd$(EXEEXT) $(DESTDIR)$(libexecdir)/modulecmd-compat$(EXEEXT)
chmod +x $(DESTDIR)$(libexecdir)/modulecmd-compat$(EXEEXT)
endif
cp contrib/envml $(DESTDIR)$(bindir)/
chmod +x $(DESTDIR)$(bindir)/envml
cp contrib/scripts/add.modules $(DESTDIR)$(bindir)/
chmod +x $(DESTDIR)$(bindir)/add.modules
cp contrib/scripts/modulecmd $(DESTDIR)$(bindir)/
chmod +x $(DESTDIR)$(bindir)/modulecmd
cp contrib/scripts/mkroot $(DESTDIR)$(bindir)/
chmod +x $(DESTDIR)$(bindir)/mkroot
ifeq ($(docinstall),y)
mkdir -p $(DESTDIR)$(docdir)
cp COPYING.GPLv2 $(DESTDIR)$(docdir)/
cp ChangeLog $(DESTDIR)$(docdir)/
cp README $(DESTDIR)$(docdir)/
ifeq ($(compatversion),y)
cp $(COMPAT_DIR)/ChangeLog $(DESTDIR)$(docdir)/ChangeLog-compat
cp $(COMPAT_DIR)/NEWS $(DESTDIR)$(docdir)/NEWS-compat
endif
endif
$(MAKE) -C init install DESTDIR=$(DESTDIR)
ifeq ($(builddoc),y)
$(MAKE) -C doc install DESTDIR=$(DESTDIR)
else
@echo
@echo "WARNING: Documentation not built nor installed"
endif
@echo
@echo "NOTICE: Modules installation is complete."
@echo " Please read the 'Configuration' section in INSTALL.txt to learn"
@echo " how to adapt your installation and make it fit your needs." >&2
@echo
uninstall:
rm -f $(DESTDIR)$(libexecdir)/modulecmd.tcl
ifeq ($(compatversion),y)
rm -f $(DESTDIR)$(libexecdir)/modulecmd-compat$(EXEEXT)
endif
rm -f $(DESTDIR)$(bindir)/envml
rm -f $(DESTDIR)$(bindir)/add.modules
rm -f $(DESTDIR)$(bindir)/modulecmd
rm -f $(DESTDIR)$(bindir)/mkroot
ifeq ($(docinstall),y)
rm -f $(addprefix $(DESTDIR)$(docdir)/,ChangeLog README COPYING.GPLv2)
ifeq ($(compatversion),y)
rm -f $(addprefix $(DESTDIR)$(docdir)/,ChangeLog-compat NEWS-compat)
endif
ifneq ($(builddoc),y)
rmdir $(DESTDIR)$(docdir)
endif
endif
$(MAKE) -C init uninstall DESTDIR=$(DESTDIR)
ifeq ($(builddoc),y)
$(MAKE) -C doc uninstall DESTDIR=$(DESTDIR)
endif
rmdir $(DESTDIR)$(libexecdir)
rmdir $(DESTDIR)$(bindir)
rmdir $(DESTDIR)$(datarootdir)
$(RMDIR_IGN_NON_EMPTY) $(DESTDIR)$(prefix) || true
# include pre-generated documents not to require documentation build
# tools when installing from dist tarball
dist-tar: ChangeLog README version.inc contrib/rpm/environment-modules.spec pkgdoc
git archive --prefix=$(DIST_PREFIX)/ --worktree-attributes \
-o $(DIST_PREFIX).tar HEAD
cp doc/build/MIGRATING.txt doc/build/INSTALL.txt doc/build/NEWS.txt ./
tar -rf $(DIST_PREFIX).tar --transform 's,^,$(DIST_PREFIX)/,' \
ChangeLog README MIGRATING.txt INSTALL.txt NEWS.txt version.inc \
doc/build/MIGRATING.txt doc/build/diff_v3_v4.txt \
doc/build/INSTALL.txt doc/build/NEWS.txt \
doc/build/module.1.in doc/build/modulefile.4 \
contrib/rpm/environment-modules.spec
ifeq ($(compatversion) $(wildcard $(COMPAT_DIR)),y $(COMPAT_DIR))
$(MAKE) -C $(COMPAT_DIR) distdir
mv $(COMPAT_DIR)/modules-* compatdist
tar -cf compatdist.tar --transform 's,^compatdist,$(DIST_PREFIX)/compat,' compatdist
tar --concatenate -f $(DIST_PREFIX).tar compatdist.tar
rm -rf compatdist
rm compatdist.tar
endif
dist-gzip: dist-tar
gzip -f -9 $(DIST_PREFIX).tar
dist-bzip2: dist-tar
bzip2 -f $(DIST_PREFIX).tar
dist: dist-gzip
srpm: dist-bzip2
rpmbuild -ts $(DIST_PREFIX).tar.bz2
clean:
rm -f *.log *.sum
rm -f $(COVERAGE_IFILE) $(COVERAGE_LOGFILE) $(COVERAGE_MFILE)
rm -rf coverage
ifeq ($(wildcard .git) $(wildcard contrib/gitlog2changelog.py),.git contrib/gitlog2changelog.py)
rm -f ChangeLog
endif
ifeq ($(wildcard .git) $(wildcard README.md),.git README.md)
rm -f README
endif
ifeq ($(wildcard .git) $(wildcard MIGRATING.rst),.git MIGRATING.rst)
rm -f MIGRATING.txt
endif
ifeq ($(wildcard .git) $(wildcard INSTALL.rst),.git INSTALL.rst)
rm -f INSTALL.txt
endif
ifeq ($(wildcard .git) $(wildcard NEWS.rst),.git NEWS.rst)
rm -f NEWS.txt
endif
rm -f modulecmd.tcl
rm -f contrib/scripts/add.modules
rm -f contrib/scripts/modulecmd
rm -f testsuite/example/.modulespath testsuite/example/modulerc
rm -f modules-*.tar modules-*.tar.gz modules-*.tar.bz2
rm -f modules-*.srpm
$(MAKE) -C init clean
ifeq ($(builddoc),y)
$(MAKE) -C doc clean
endif
ifeq ($(wildcard .git) $(wildcard version.inc.in),.git version.inc.in)
rm -f version.inc
rm -f contrib/rpm/environment-modules.spec
endif
ifneq ($(wildcard $(COMPAT_DIR)/Makefile),)
$(MAKE) -C compat clean
endif
distclean: clean
rm -f Makefile.inc
rm -f site.exp
rm -rf $(NAGELFAR_RELEASE)
ifeq ($(wildcard .git) $(wildcard $(COMPAT_DIR)),.git $(COMPAT_DIR))
rm -rf $(COMPAT_DIR)
ifeq ($(gitworktree),y)
git worktree prune
endif
endif
ifeq ($(compatversion) $(wildcard $(COMPAT_DIR)),y $(COMPAT_DIR))
test: modulecmd.tcl $(COMPAT_DIR)/modulecmd
$(MAKE) -C $(COMPAT_DIR) test
else
test: modulecmd.tcl
endif
TCLSH=$(TCLSH); export TCLSH; \
OBJDIR=`pwd -P`; export OBJDIR; \
TESTSUITEDIR=`cd testsuite;pwd -P`; export TESTSUITEDIR; \
runtest --srcdir $$TESTSUITEDIR --objdir $$OBJDIR $(RUNTESTFLAGS) --tool modules
testinstall:
OBJDIR=`pwd -P`; export OBJDIR; \
TESTSUITEDIR=`cd testsuite;pwd -P`; export TESTSUITEDIR; \
runtest --srcdir $$TESTSUITEDIR --objdir $$OBJDIR $(RUNTESTFLAGS) --tool install
# install code coverage tool
# download from alt. source if correct tarball not retrieved from primary location
$(NAGELFAR):
wget $(NAGELFAR_DLSRC1)$(NAGELFAR_DIST) || true
echo "$(NAGELFAR_DISTSUM) $(NAGELFAR_DIST)" | md5sum -c --status || \
wget -O $(NAGELFAR_DIST) $(NAGELFAR_DLSRC2)$(NAGELFAR_DIST)
tar xzf $(NAGELFAR_DIST)
rm $(NAGELFAR_DIST)
# instrument source file for code coverage
%.tcl_i: %.tcl $(NAGELFAR)
$(NAGELFAR) -instrument $<
# prepare for code coverage run and make sure coverage log is clear
instrument: $(COVERAGE_IFILE)
rm -f $(COVERAGE_LOGFILE)
# run tests on instrumented file to create coverage log
$(COVERAGE_LOGFILE): $(COVERAGE_IFILE)
MODULECMD=./$< $(MAKE) test
# create markup file for better read coverage result
%.tcl_m: %.tcl_log $(NAGELFAR)
$(NAGELFAR) -markup $*.tcl
testcoverage: instrument $(COVERAGE_MFILE)
testsyntax: $(NAGELFAR) $(COVERAGE_SRCFILE)
$(NAGELFAR) -len 78 $(COVERAGE_SRCFILE)