1#
2#  Makefile
3#
4#		NOTE: This top-level Makefile must not
5#		use GNU-make extensions. The lower ones can.
6#
7#  Version:	$Id: 5ec0ab4fde9910cc5783505c598cfa9d678362df $
8#
9
10#
11#  If we didn't call ./configure just define the version.
12#
13RADIUSD_VERSION_STRING := $(shell cat VERSION)
14
15#
16#  The default rule is "all".
17#
18all:
19
20#
21#  Catch people who try to use BSD make
22#
23ifeq "0" "1"
24.error GNU Make is required to build FreeRADIUS
25endif
26
27#
28#  We require Make.inc, UNLESS the target is "make deb"
29#
30#  Since "make deb" re-runs configure... there's no point in
31#  requiring the developer to run configure *before* making
32#  the debian packages.
33#
34ifneq "$(MAKECMDGOALS)" "deb"
35ifneq "$(MAKECMDGOALS)" "rpm"
36ifeq "$(findstring docker,$(MAKECMDGOALS))" ""
37ifeq "$(findstring crossbuild,$(MAKECMDGOALS))" ""
38$(if $(wildcard Make.inc),,$(error Missing 'Make.inc' Run './configure [options]' and retry))
39
40include Make.inc
41endif
42endif
43endif
44endif
45
46MFLAGS += --no-print-directory
47
48#
49#  The version of GNU Make is too old, don't use it (.FEATURES
50#  variable was added in 3.81)
51#
52ifndef .FEATURES
53$(error The build system requires GNU Make 3.81 or later.)
54endif
55
56export DESTDIR := $(R)
57
58#
59#  And over-ride all of the other magic.
60#
61ifneq "$(MAKECMDGOALS)" "deb"
62ifneq "$(MAKECMDGOALS)" "rpm"
63ifeq "$(findstring docker,$(MAKECMDGOALS))" ""
64ifeq "$(findstring crossbuild,$(MAKECMDGOALS))" ""
65include scripts/boiler.mk
66endif
67endif
68endif
69endif
70
71#
72#  To work around OpenSSL issues within CI.
73#
74.PHONY:
75raddb/test.conf:
76	@echo 'security {' >> $@
77	@echo '        allow_vulnerable_openssl = yes' >> $@
78	@echo '}' >> $@
79	@echo '$$INCLUDE radiusd.conf' >> $@
80
81#
82#  Run "radiusd -C", looking for errors.
83#
84#  Only redirect STDOUT, which should contain details of why the test failed.
85#  Don't molest STDERR as this may be used to receive output from a debugger.
86#
87$(BUILD_DIR)/tests/radiusd-c: raddb/test.conf ${BUILD_DIR}/bin/radiusd | build.raddb
88	@$(MAKE) -C raddb/certs
89	@printf "radiusd -C... "
90	@if ! $(TESTBIN)/radiusd -XCMd ./raddb -D ./share -n test > $(BUILD_DIR)/tests/radiusd.config.log; then \
91		rm -f raddb/test.conf; \
92		cat $(BUILD_DIR)/tests/radiusd.config.log; \
93		echo "fail"; \
94		exit 1; \
95	fi
96	@rm -f raddb/test.conf
97	@echo "ok"
98	@touch $@
99
100test: ${BUILD_DIR}/bin/radiusd ${BUILD_DIR}/bin/radclient tests.unit tests.xlat tests.keywords tests.auth test.sql_nas_table $(BUILD_DIR)/tests/radiusd-c | build.raddb
101	@$(MAKE) -C src/tests tests
102
103#
104#  Tests specifically for CI. We do a LOT more than just
105#  the above tests
106#
107ci-test: raddb/test.conf test
108	@$(TESTBIN)/radiusd -xxxv -n test
109	@rm -f raddb/test.conf
110	@$(MAKE) install
111	@perl -p -i -e 's/allow_vulnerable_openssl = no/allow_vulnerable_openssl = yes/' ${raddbdir}/radiusd.conf
112	@sh ${HOME}/freeradius/etc/raddb/certs
113	@${sbindir}/radiusd -XC
114
115#
116#  The $(R) is a magic variable not defined anywhere in this source.
117#  It's purpose is to allow an admin to create an installation 'tar'
118#  file *without* actually installing it.  e.g.:
119#
120#  $ R=/home/root/tmp make install
121#  $ cd /home/root/tmp
122#  $ tar -cf ~/freeradius-package.tar *
123#
124#  The 'tar' file can then be un-tar'd on any similar machine.  It's a
125#  cheap way of creating packages, without using a package manager.
126#  Many of the platform-specific packaging tools use the $(R) variable
127#  when creating their packages.
128#
129#  For compatibility with typical GNU packages (e.g. as seen in libltdl),
130#  we make sure DESTDIR is defined.
131#
132export DESTDIR := $(R)
133
134DICTIONARIES := $(wildcard share/dictionary*)
135install.share: $(addprefix $(R)$(dictdir)/,$(notdir $(DICTIONARIES)))
136
137.PHONY: dictionary.format
138dictionary.format: $(DICTIONARIES)
139	@./share/format.pl $(DICTIONARIES)
140
141$(R)$(dictdir)/%: share/%
142	@echo INSTALL $(notdir $<)
143	@$(INSTALL) -m 644 $< $@
144
145MANFILES := $(wildcard man/man*/*.?)
146MANDIR   := $(wildcard man/man*)
147install.man: $(subst man/,$(R)$(mandir)/,$(MANFILES))
148
149$(MANDIR):
150	@echo INSTALL $(patsubst $(R)$(mandir)/%,man/%,$@)
151	@$(INSTALL) -d -m 755 $@
152
153$(R)$(mandir)/%: man/% | $(dir $@)
154	@echo INSTALL $(notdir $<)
155	@sed -e "s,/etc/raddb,$(raddbdir),g" \
156		-e "s,/usr/local/share,$(datarootdir),g" \
157		$< > $<.subst
158	@$(INSTALL) -m 644 $<.subst $@
159	@rm $<.subst
160
161#
162#  Don't install rlm_test
163#
164ALL_INSTALL := $(patsubst %rlm_test.la,,$(ALL_INSTALL))
165
166install: install.share install.man
167	@$(INSTALL) -d -m 700	$(R)$(logdir)
168	@$(INSTALL) -d -m 700	$(R)$(radacctdir)
169
170ifneq ($(RADMIN),)
171ifneq ($(RGROUP),)
172.PHONY: install-chown
173install-chown:
174	chown -R $(RADMIN)   $(R)$(raddbdir)
175	chgrp -R $(RGROUP)   $(R)$(raddbdir)
176	chmod u=rwx,g=rx,o=  `find $(R)$(raddbdir) -type d -print`
177	chmod u=rw,g=r,o=    `find $(R)$(raddbdir) -type f -print`
178	chown -R $(RADMIN)   $(R)$(logdir)
179	chgrp -R $(RGROUP)   $(R)$(logdir)
180	find $(R)$(logdir) -type d -exec chmod u=rwx,g=rwx,o= {} \;
181	find $(R)$(logdir) -type d -exec chmod g+s {} \;
182	find $(R)$(logdir) -type f -exec chmod u=rw,g=rw,o= {} \;
183	chown -R $(RADMIN)   $(R)$(RUNDIR)
184	chgrp -R $(RGROUP)   $(R)$(RUNDIR)
185	find $(R)$(RUNDIR) -type d -exec chmod u=rwx,g=rwx,o= {} \;
186	find $(R)$(RUNDIR) -type d -exec chmod g+s {} \;
187	find $(R)$(RUNDIR) -type f -exec chmod u=rw,g=rw,o= {} \;
188endif
189endif
190
191distclean: clean
192	@-find src/modules -regex .\*/config[.][^.]*\$$ -delete
193	@-find src/modules -name autom4te.cache -exec rm -rf '{}' \;
194	@rm -rf config.cache config.log config.status libtool \
195		src/include/radpaths.h src/include/stamp-h \
196		libltdl/config.log libltdl/config.status \
197		libltdl/libtool autom4te.cache build
198	@-find . ! -name configure.ac -name \*.in -print | \
199		sed 's/\.in$$//' | \
200		while read file; do rm -f $$file; done
201
202######################################################################
203#
204#  Automatic remaking rules suggested by info:autoconf#Automatic_Remaking
205#
206######################################################################
207#
208#  Do these checks ONLY if we're re-building the "configure"
209#  scripts, and ONLY the "configure" scripts.  If we leave
210#  these rules enabled by default, then they're run too often.
211#
212ifeq "$(MAKECMDGOALS)" "reconfig"
213
214CONFIGURE_AC_FILES := $(shell find . -name configure.ac -print)
215CONFIGURE_FILES	   := $(patsubst %.ac,%,$(CONFIGURE_AC_FILES))
216
217#
218#  The GNU tools make autoconf=="missing autoconf", which then returns
219#  0, even when autoconf doesn't exist.  This check is to ensure that
220#  we run AUTOCONF only when it exists.
221#
222AUTOCONF_EXISTS := $(shell autoconf --version 2>/dev/null)
223
224ifeq "$(AUTOCONF_EXISTS)" ""
225$(error You need to install autoconf to re-build the "configure" scripts)
226endif
227
228#  Configure files depend on "in" files, and on the top-level macro files
229#  If there are headers, run auto-header, too.
230src/%configure: src/%configure.ac acinclude.m4 aclocal.m4 $(wildcard $(dir $@)m4/*m4) | src/freeradius-devel
231	@echo AUTOCONF $(dir $@)
232	cd $(dir $@) && $(AUTOCONF) -I $(top_builddir) -I $(top_builddir)/m4 -I $(top_builddir)/$(dir $@)m4
233	@if grep AC_CONFIG_HEADERS $@ >/dev/null; then\
234		echo AUTOHEADER $@ \
235		cd $(dir $@) && $(AUTOHEADER); \
236	 fi
237
238#  "%configure" doesn't match "configure"
239configure: configure.ac $(wildcard ac*.m4) $(wildcard m4/*.m4)
240	@echo AUTOCONF $@
241	@$(AUTOCONF)
242
243src/include/autoconf.h.in: configure.ac
244	@echo AUTOHEADER $@
245	@$(AUTOHEADER)
246
247reconfig: $(CONFIGURE_FILES) src/include/autoconf.h.in
248
249config.status: configure
250	./config.status --recheck
251
252#  target is "reconfig"
253endif
254
255#
256#  If we've already run configure, then add rules which cause the
257#  module-specific "all.mk" files to depend on the mk.in files, and on
258#  the configure script.
259#
260ifneq "$(wildcard config.log)" ""
261CONFIGURE_ARGS	   := $(shell head -10 config.log | grep '^  \$$' | sed 's/^....//;s:.*configure ::')
262
263src/%all.mk: src/%all.mk.in src/%configure
264	@echo CONFIGURE $(dir $@)
265	@rm -f ./config.cache $(dir $<)/config.cache
266	@cd $(dir $<) && ./configure $(CONFIGURE_ARGS)
267endif
268
269.PHONY: check-includes
270check-includes:
271	scripts/min-includes.pl `find . -name "*.c" -print`
272
273.PHONY: TAGS
274TAGS:
275	etags `find src -type f -name '*.[ch]' -print` > $@
276
277#
278#  Make test certificates.
279#
280.PHONY: certs
281certs:
282	@$(MAKE) -C raddb/certs
283
284######################################################################
285#
286#  Make a release.
287#
288#  Note that "Make.inc" has to be updated with the release number
289#  BEFORE running this command!
290#
291######################################################################
292BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
293
294freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz: .git
295	git archive --format=tar --prefix=freeradius-server-$(RADIUSD_VERSION_STRING)/ $(BRANCH) | gzip > $@
296
297freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2: .git
298	git archive --format=tar --prefix=freeradius-server-$(RADIUSD_VERSION_STRING)/ $(BRANCH) | bzip2 > $@
299
300%.sig: %
301	gpg --default-key packages@freeradius.org -b $<
302
303#
304#  High-level targets
305#
306.PHONY: dist-check
307dist-check: redhat/freeradius.spec suse/freeradius.spec debian/changelog
308	@if [ `grep ^Version: redhat/freeradius.spec | sed 's/.*://;s/ //g'` != "$(RADIUSD_VERSION_STRING)" ]; then \
309		cat redhat/freeradius.spec | sed 's/^Version:.*/Version: $(RADIUSD_VERSION_STRING)/' > redhat/.foo; \
310		mv redhat/.foo redhat/freeradius.spec; \
311		echo redhat/freeradius.spec 'Version' needs to be updated; \
312		exit 1; \
313	fi
314	@if [ `grep ^Version: suse/freeradius.spec | sed 's/.*://;s/ //g'` != "$(RADIUSD_VERSION_STRING)" ]; then \
315		cat suse/freeradius.spec | sed 's/^Version: .*/Version:      $(RADIUSD_VERSION_STRING)/' > suse/.foo; \
316		mv suse/.foo suse/freeradius.spec; \
317		echo suse/freeradius.spec 'Version' needs to be updated; \
318		exit 1; \
319	fi
320	@if [ `head -n 1 doc/ChangeLog | awk '/^FreeRADIUS/{print $$2}'` != "$(RADIUSD_VERSION_STRING)" ]; then \
321		echo doc/ChangeLog needs to be updated; \
322		exit 1; \
323	fi
324	@if [ `head -n 1 debian/changelog | sed 's/.*(//;s/-0).*//;s/-1).*//;s/\+.*//'` != "$(RADIUSD_VERSION_STRING)" ]; then \
325		echo debian/changelog needs to be updated; \
326		exit 1; \
327	fi
328	@if [ `grep version doc/antora/antora.yml | sed 's/^.*version: //'` != "'$(RADIUSD_VERSION_STRING)'" ]; then \
329		echo doc/antora/antora.yml needs to be updated with: version '$(RADIUSD_VERSION_STRING)'; \
330		exit 1; \
331	fi
332
333dist: dist-check freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2
334
335dist-sign: dist-check freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz.sig freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2.sig
336
337dist-publish: freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz.sig freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz.sig freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2 freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz.sig freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2.sig
338	scp $^ freeradius.org@ftp.freeradius.org:public_ftp
339
340#
341#  Note that we do NOT do the tagging here!  We just print out what
342#  to do!
343#
344dist-tag: freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2
345	@echo "git tag release_`echo $(RADIUSD_VERSION_STRING) | tr .- __`"
346
347#
348#  Docker-related targets (main Docker images and crossbuild)
349#
350ifneq "$(findstring docker,$(MAKECMDGOALS))" ""
351include scripts/docker/docker.mk
352endif
353
354ifneq "$(findstring crossbuild,$(MAKECMDGOALS))" ""
355include scripts/crossbuild/crossbuild.mk
356endif
357
358#
359#  Build a Debian package
360#
361.PHONY: deb
362deb:
363	fakeroot debian/rules debian/control #clean
364	fakeroot dpkg-buildpackage -b -uc
365
366#
367#  Build an RPM package
368#
369.PHONY: rpm
370rpmbuild/SOURCES/freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2: freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2
371	@mkdir -p $(addprefix rpmbuild/,SOURCES SPECS BUILD RPMS SRPMS BUILDROOT)
372	@for file in `awk '/^Source...:/ {print $$2}' redhat/freeradius.spec` ; do cp redhat/$$file rpmbuild/SOURCES/$$file ; done
373	@cp $< $@
374
375rpm: rpmbuild/SOURCES/freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2
376	@if ! yum-builddep -q -C --assumeno redhat/freeradius.spec 1> /dev/null 2>&1; then \
377		echo "ERROR: Required depdendencies not found, install them with: yum-builddep redhat/freeradius.spec"; \
378		exit 1; \
379	fi
380	@QA_RPATHS=0x0003 rpmbuild --define "_topdir `pwd`/rpmbuild" -bb redhat/freeradius.spec
381
382#
383#  Developer checks
384#
385.PHONY: warnings
386warnings:
387	@(make clean all 2>&1) | egrep -v '^/|deprecated|^In file included|: In function|   from |^HEADER|^CC|^LN' > warnings.txt
388	@wc -l warnings.txt
389
390#
391#  Ensure we're using tabs in the configuration files,
392#  and remove trailing whitespace in source files.
393#
394.PHONY: whitespace
395whitespace:
396	@for x in $$(git ls-files raddb/ src/); do unexpand $$x > $$x.bak; cp $$x.bak $$x; rm -f $$x.bak;done
397	@perl -p -i -e 'trim' $$(git ls-files src/)
398