Include chrpath fixes for path
[freeradius.git] / Makefile
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$
8 #
9
10 $(if $(wildcard Make.inc),,$(error Missing 'Make.inc' Run './configure [options]' and retry))
11
12 include Make.inc
13
14 MFLAGS += --no-print-directory
15
16 # The version of GNU Make is too old, don't use it (.FEATURES variable was
17 # wad added in 3.81)
18 ifndef .FEATURES
19 $(error The build system requires GNU Make 3.81 or later.)
20 endif
21
22 export DESTDIR := $(R)
23
24 # And over-ride all of the other magic.
25 include scripts/boiler.mk
26
27 #
28 #  Run "radiusd -C", looking for errors.
29 #
30 $(BUILD_DIR)/tests/radiusd-c: ${BUILD_DIR}/bin/radiusd | build.raddb
31         @$(MAKE) -C raddb/certs
32         @if ! ./build/make/jlibtool --mode=execute ./build/bin/radiusd -XCMd ./raddb -n debug -D ./share > $(BUILD_DIR)/tests/radiusd.config.log 2>&1; then \
33                 cat $(BUILD_DIR)/tests/radiusd.config.log; \
34                 echo "FAIL: radiusd -C"; \
35                 exit 1; \
36         fi
37         @echo "OK: radiusd -C"
38         @touch $@
39
40 test: ${BUILD_DIR}/bin/radiusd ${BUILD_DIR}/bin/radclient tests.unit tests.keywords $(BUILD_DIR)/tests/radiusd-c | build.raddb
41         @$(MAKE) -C src/tests tests
42
43 #  Tests specifically for Travis.  We do a LOT more than just
44 #  the above tests
45 ifneq "$(findstring travis,${prefix})" ""
46 travis-test: test
47         @$(MAKE) install
48         @$(MAKE) deb
49 endif
50
51 #
52 # The $(R) is a magic variable not defined anywhere in this source.
53 # It's purpose is to allow an admin to create an installation 'tar'
54 # file *without* actually installing it.  e.g.:
55 #
56 #  $ R=/home/root/tmp make install
57 #  $ cd /home/root/tmp
58 #  $ tar -cf ~/freeradius-package.tar *
59 #
60 # The 'tar' file can then be un-tar'd on any similar machine.  It's a
61 # cheap way of creating packages, without using a package manager.
62 # Many of the platform-specific packaging tools use the $(R) variable
63 # when creating their packages.
64 #
65 # For compatibility with typical GNU packages (e.g. as seen in libltdl),
66 # we make sure DESTDIR is defined.
67 #
68 export DESTDIR := $(R)
69
70 .PHONY: install.bindir
71 install.bindir:
72         @[ -d $(R)$(bindir) ] || $(INSTALL) -d -m 755 $(R)$(bindir)
73
74 .PHONY: install.sbindir
75 install.sbindir:
76         @[ -d $(R)$(sbindir) ] || $(INSTALL) -d -m 755 $(R)$(sbindir)
77
78 .PHONY: install.dirs
79 install.dirs: install.bindir install.sbindir
80         @$(INSTALL) -d -m 755   $(R)$(mandir)
81         @$(INSTALL) -d -m 755   $(R)$(RUNDIR)
82         @$(INSTALL) -d -m 700   $(R)$(logdir)
83         @$(INSTALL) -d -m 700   $(R)$(radacctdir)
84         @$(INSTALL) -d -m 755   $(R)$(datadir)
85         @$(INSTALL) -d -m 755   $(R)$(dictdir)
86
87 DICTIONARIES := $(wildcard share/dictionary*)
88 install.share: $(addprefix $(R)$(dictdir)/,$(notdir $(DICTIONARIES)))
89
90 $(R)$(dictdir)/%: share/%
91         @echo INSTALL $(notdir $<)
92         @$(INSTALL) -m 644 $< $@
93
94 MANFILES := $(wildcard man/man*/*.?)
95 install.man: $(subst man/,$(R)$(mandir)/,$(MANFILES))
96
97 $(R)$(mandir)/%: man/%
98         @echo INSTALL $(notdir $<)
99         @$(INSTALL) -m 644 $< $@
100
101 install: install.dirs install.share install.man
102
103 ifneq ($(RADMIN),)
104 ifneq ($(RGROUP),)
105 .PHONY: install-chown
106 install-chown:
107         chown -R $(RADMIN)   $(R)$(raddbdir)
108         chgrp -R $(RGROUP)   $(R)$(raddbdir)
109         chmod u=rwx,g=rx,o=  `find $(R)$(raddbdir) -type d -print`
110         chmod u=rw,g=r,o=    `find $(R)$(raddbdir) -type f -print`
111         chown -R $(RADMIN)   $(R)$(logdir)
112         chgrp -R $(RGROUP)   $(R)$(logdir)
113         find $(R)$(logdir) -type d -exec chmod u=rwx,g=rwx,o= {} \;
114         find $(R)$(logdir) -type d -exec chmod g+s {} \;
115         find $(R)$(logdir) -type f -exec chmod u=rw,g=rw,o= {} \;
116         chown -R $(RADMIN)   $(R)$(RUNDIR)
117         chgrp -R $(RGROUP)   $(R)$(RUNDIR)
118         find $(R)$(RUNDIR) -type d -exec chmod u=rwx,g=rwx,o= {} \;
119         find $(R)$(RUNDIR) -type d -exec chmod g+s {} \;
120         find $(R)$(RUNDIR) -type f -exec chmod u=rw,g=rw,o= {} \;
121 endif
122 endif
123
124 distclean: clean
125         @-find src/modules -regex .\*/config[.][^.]*\$$ -delete
126         @-find src/modules -name autom4te.cache -exec rm -rf '{}' \;
127         @rm -rf config.cache config.log config.status libtool \
128                 src/include/radpaths.h src/include/stamp-h \
129                 libltdl/config.log libltdl/config.status \
130                 libltdl/libtool autom4te.cache build
131         @-find . ! -name configure.ac -name \*.in -print | \
132                 sed 's/\.in$$//' | \
133                 while read file; do rm -f $$file; done
134
135 ######################################################################
136 #
137 #  Automatic remaking rules suggested by info:autoconf#Automatic_Remaking
138 #
139 ######################################################################
140 #
141 #  Do these checks ONLY if we're re-building the "configure"
142 #  scripts, and ONLY the "configure" scripts.  If we leave
143 #  these rules enabled by default, then they're run too often.
144 #
145 ifeq "$(MAKECMDGOALS)" "reconfig"
146
147 CONFIGURE_AC_FILES := $(shell find . -name configure.ac -print)
148 CONFIGURE_FILES    := $(patsubst %.ac,%,$(CONFIGURE_AC_FILES))
149
150 #
151 #  The GNU tools make autoconf=="missing autoconf", which then returns
152 #  0, even when autoconf doesn't exist.  This check is to ensure that
153 #  we run AUTOCONF only when it exists.
154 #
155 AUTOCONF_EXISTS := $(shell autoconf --version 2>/dev/null)
156
157 ifeq "$(AUTOCONF_EXISTS)" ""
158 $(error You need to install autoconf to re-build the "configure" scripts)
159 endif
160
161 # Configure files depend on "in" files, and on the top-level macro files
162 # If there are headers, run auto-header, too.
163 src/%configure: src/%configure.ac acinclude.m4 aclocal.m4 $(wildcard $(dir $@)m4/*m4) | src/freeradius-devel
164         @echo AUTOCONF $(dir $@)
165         cd $(dir $@) && $(AUTOCONF) -I $(top_builddir) -I $(top_builddir)/m4 -I $(top_builddir)/$(dir $@)m4
166         @if grep AC_CONFIG_HEADERS $@ >/dev/null; then\
167                 echo AUTOHEADER $@ \
168                 cd $(dir $@) && $(AUTOHEADER); \
169          fi
170
171 # "%configure" doesn't match "configure"
172 configure: configure.ac $(wildcard ac*.m4) $(wildcard m4/*.m4)
173         @echo AUTOCONF $@
174         @$(AUTOCONF)
175
176 src/include/autoconf.h.in: configure.ac
177         @echo AUTOHEADER $@
178         @$(AUTOHEADER)
179
180 reconfig: $(CONFIGURE_FILES) src/include/autoconf.h.in
181
182 config.status: configure
183         ./config.status --recheck
184
185 # target is "configure"
186 endif
187
188 #  If we've already run configure, then add rules which cause the
189 #  module-specific "all.mk" files to depend on the mk.in files, and on
190 #  the configure script.
191 #
192 ifneq "$(wildcard config.log)" ""
193 CONFIGURE_ARGS     := $(shell head -10 config.log | grep '^  \$$' | sed 's/^....//;s:.*configure ::')
194
195 src/%all.mk: src/%all.mk.in src/%configure
196         @echo CONFIGURE $(dir $@)
197         @rm -f ./config.cache $(dir $<)/config.cache
198         @cd $(dir $<) && CPPFLAGS=$(DARWIN_CFLAGS) CFLAGS=$(DARWIN_CFLAGS) ./configure $(CONFIGURE_ARGS)
199 endif
200
201 .PHONY: check-includes
202 check-includes:
203         scripts/min-includes.pl `find . -name "*.c" -print`
204
205 .PHONY: TAGS
206 TAGS:
207         etags `find src -type f -name '*.[ch]' -print` > $@
208
209 #
210 #  Make test certificates.
211 #
212 .PHONY: certs
213 certs:
214         @cd raddb/certs && $(MAKE)
215
216 ######################################################################
217 #
218 #  Make a release.
219 #
220 #  Note that "Make.inc" has to be updated with the release number
221 #  BEFORE running this command!
222 #
223 ######################################################################
224 freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz: .git
225         git archive --format=tar --prefix=freeradius-server-$(RADIUSD_VERSION_STRING)/ v3.0.x | gzip > $@
226
227 freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz.sig: freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz
228         gpg --default-key aland@freeradius.org -b $<
229
230 freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2: .git
231         git archive --format=tar --prefix=freeradius-server-$(RADIUSD_VERSION_STRING)/ v3.0.x | bzip2 > $@
232
233 freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2.sig: freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2
234         gpg --default-key aland@freeradius.org -b $<
235
236 # high-level targets
237 .PHONY: dist-check
238 dist-check: redhat/freeradius.spec suse/freeradius.spec debian/changelog
239         @if [ `grep ^Version: redhat/freeradius.spec | sed 's/.*://;s/ //'` != "$(RADIUSD_VERSION_STRING)" ]; then \
240                 cat redhat/freeradius.spec | sed 's/^Version: .*/Version: $(RADIUSD_VERSION_STRING)/' > redhat/.foo; \
241                 mv redhat/.foo redhat/freeradius.spec; \
242                 echo redhat/freeradius.spec 'Version' needs to be updated; \
243                 exit 1; \
244         fi
245         @if [ `grep ^Version: suse/freeradius.spec | sed 's/.*://;s/ //'` != "$(RADIUSD_VERSION_STRING)" ]; then \
246                 cat suse/freeradius.spec | sed 's/^Version: .*/Version: $(RADIUSD_VERSION_STRING)/' > suse/.foo; \
247                 mv suse/.foo suse/freeradius.spec; \
248                 echo suse/freeradius.spec 'Version' needs to be updated; \
249                 exit 1; \
250         fi
251         @if [ `head -n 1 debian/changelog | sed 's/.*(//;s/-0).*//;s/-1).*//;s/\+.*//'`  != "$(RADIUSD_VERSION_STRING)" ]; then \
252                 echo debian/changelog needs to be updated; \
253                 exit 1; \
254         fi
255
256 dist: dist-check freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2
257
258 dist-sign: freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz.sig freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2.sig
259
260 dist-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
261         scp $^ freeradius.org@ftp.freeradius.org:public_ftp
262
263 #
264 #  Note that we do NOT do the tagging here!  We just print out what
265 #  to do!
266 #
267 dist-tag: freeradius-server-$(RADIUSD_VERSION_STRING).tar.gz freeradius-server-$(RADIUSD_VERSION_STRING).tar.bz2
268         @echo "git tag release_`echo $(RADIUSD_VERSION_STRING) | tr .- __`"
269
270 #
271 #       Build a debian package
272 #
273 .PHONY: deb
274 deb:
275         fakeroot dpkg-buildpackage -b -uc
276
277 # Developer checks
278 .PHONY: warnings
279 warnings:
280         @(make clean all 2>&1) | egrep -v '^/|deprecated|^In file included|: In function|   from |^HEADER|^CC|^LINK' > warnings.txt
281         @wc -l warnings.txt