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