blob: bcbd5571671d9395b613754dc2237b21f73c7217 [file] [log] [blame]
Simon Kelleyc47e3ba2014-01-08 17:07:54 +00001# dnsmasq is Copyright (c) 2000-2014 Simon Kelley
Simon Kelley824af852008-02-12 20:43:05 +00002#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; version 2 dated June, 1991, or
6# (at your option) version 3 dated 29 June, 2007.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
Simon Kelley73a08a22009-02-05 20:28:08 +000013# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
Simon Kelley824af852008-02-12 20:43:05 +000015
Simon Kelley24848942012-02-29 11:23:41 +000016# NOTE: Building the i18n targets requires GNU-make
Simon Kelley9e4abcb2004-01-22 19:47:41 +000017
Simon Kelleyb36ae192012-02-13 12:54:34 +000018
Simon Kelley24848942012-02-29 11:23:41 +000019# Variables you may well want to override.
20
21PREFIX = /usr/local
22BINDIR = $(PREFIX)/sbin
23MANDIR = $(PREFIX)/share/man
24LOCALEDIR = $(PREFIX)/share/locale
25BUILDDIR = $(SRC)
26DESTDIR =
27CFLAGS = -Wall -W -O2
28LDFLAGS =
29COPTS =
30RPM_OPT_FLAGS =
31LIBS =
Simon Kelleyb36ae192012-02-13 12:54:34 +000032
Simon Kelleye5ffdb92012-02-13 14:19:25 +000033#################################################################
34
Simon Kelley24848942012-02-29 11:23:41 +000035# Variables you might want to override.
36
Simon Kelley824af852008-02-12 20:43:05 +000037PKG_CONFIG = pkg-config
Simon Kelley24848942012-02-29 11:23:41 +000038INSTALL = install
39MSGMERGE = msgmerge
40MSGFMT = msgfmt
41XGETTEXT = xgettext
Simon Kelley824af852008-02-12 20:43:05 +000042
Simon Kelley316e2732010-01-22 20:16:09 +000043SRC = src
Simon Kelley24848942012-02-29 11:23:41 +000044PO = po
Simon Kelley316e2732010-01-22 20:16:09 +000045MAN = man
46
Simon Kelley24848942012-02-29 11:23:41 +000047#################################################################
Simon Kelleyfdacfb02012-02-28 15:20:25 +000048
Simon Kelleyc46c7c72012-02-29 21:37:14 +000049# pmake way. (NB no spaces to keep gmake 3.82 happy)
50top!=pwd
Simon Kelley24848942012-02-29 11:23:41 +000051# GNU make way.
Simon Kelleyc46c7c72012-02-29 21:37:14 +000052top?=$(CURDIR)
Simon Kelley9e4abcb2004-01-22 19:47:41 +000053
Simon Kelley86bec2d2014-01-13 21:31:20 +000054dbus_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --cflags dbus-1`
55dbus_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --libs dbus-1`
56idn_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --cflags libidn`
57idn_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --libs libidn`
58ct_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --cflags libnetfilter_conntrack`
59ct_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --libs libnetfilter_conntrack`
60lua_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --cflags lua5.1`
61lua_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --libs lua5.1`
62nettle_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --cflags nettle hogweed`
63nettle_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --libs nettle hogweed`
Simon Kelley063efb32014-06-17 19:49:31 +010064gmp_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC NO_GMP --copy -lgmp`
Simon Kelley86bec2d2014-01-13 21:31:20 +000065sunos_libs = `if uname | grep SunOS >/dev/null 2>&1; then echo -lsocket -lnsl -lposix4; fi`
Simon Kelley24848942012-02-29 11:23:41 +000066version = -DVERSION='\"`$(top)/bld/get-version $(top)`\"'
Yousong Zhou81c538e2015-01-03 16:36:14 +000067copts_conf = .copts_$(shell $(CC) -DDNSMASQ_COMPILE_OPTS $(COPTS) -E $(top)/$(SRC)/dnsmasq.h | \
68 ( md5sum 2>/dev/null || md5 ) | cut -f 1 -d ' ')
Simon Kelley24848942012-02-29 11:23:41 +000069
70objs = cache.o rfc1035.o util.o option.o forward.o network.o \
Simon Kelley316e2732010-01-22 20:16:09 +000071 dnsmasq.o dhcp.o lease.o rfc2131.o netlink.o dbus.o bpf.o \
Simon Kelleyc5ad4e72012-02-24 16:06:20 +000072 helper.o tftp.o log.o conntrack.o dhcp6.o rfc3315.o \
Giovanni Bajoe292e932012-04-22 14:32:02 +020073 dhcp-common.o outpacket.o radv.o slaac.o auth.o ipset.o \
Simon Kelley193de4a2014-12-10 17:32:16 +000074 domain.o dnssec.o blockdata.o tables.o loop.o inotify.o
Simon Kelley208b65c2006-08-05 21:41:37 +010075
Simon Kelley24848942012-02-29 11:23:41 +000076hdrs = dnsmasq.h config.h dhcp-protocol.h dhcp6-protocol.h \
Simon Kelleycc111e02014-01-13 21:38:19 +000077 dns-protocol.h radv-protocol.h ip6addr.h
Simon Kelleyb36ae192012-02-13 12:54:34 +000078
Simon Kelleye5ffdb92012-02-13 14:19:25 +000079all : $(BUILDDIR)
80 @cd $(BUILDDIR) && $(MAKE) \
Simon Kelley24848942012-02-29 11:23:41 +000081 top="$(top)" \
Simon Kelley86bec2d2014-01-13 21:31:20 +000082 build_cflags="$(version) $(dbus_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags)" \
Simon Kelleyb98d22c2014-02-04 16:57:25 +000083 build_libs="$(dbus_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs)" \
Simon Kelley24848942012-02-29 11:23:41 +000084 -f $(top)/Makefile dnsmasq
Simon Kelley9e4abcb2004-01-22 19:47:41 +000085
Simon Kelleyceae52d2013-09-12 15:05:47 +010086mostly_clean :
87 rm -f $(BUILDDIR)/*.mo $(BUILDDIR)/*.pot
Yousong Zhou81c538e2015-01-03 16:36:14 +000088 rm -f $(BUILDDIR)/.copts_* $(BUILDDIR)/*.o $(BUILDDIR)/dnsmasq.a $(BUILDDIR)/dnsmasq
Simon Kelleyceae52d2013-09-12 15:05:47 +010089
90clean : mostly_clean
91 rm -f $(BUILDDIR)/dnsmasq_baseline
92 rm -f core */core
93 rm -f *~ contrib/*/*~ */*~
Simon Kelley9e4abcb2004-01-22 19:47:41 +000094
Simon Kelleyb8187c82005-11-26 21:46:27 +000095install : all install-common
96
97install-common :
Simon Kelley824af852008-02-12 20:43:05 +000098 $(INSTALL) -d $(DESTDIR)$(BINDIR) -d $(DESTDIR)$(MANDIR)/man8
99 $(INSTALL) -m 644 $(MAN)/dnsmasq.8 $(DESTDIR)$(MANDIR)/man8
Simon Kelleye5ffdb92012-02-13 14:19:25 +0000100 $(INSTALL) -m 755 $(BUILDDIR)/dnsmasq $(DESTDIR)$(BINDIR)
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000101
Simon Kelleye5ffdb92012-02-13 14:19:25 +0000102all-i18n : $(BUILDDIR)
103 @cd $(BUILDDIR) && $(MAKE) \
Simon Kelley24848942012-02-29 11:23:41 +0000104 top="$(top)" \
105 i18n=-DLOCALEDIR=\'\"$(LOCALEDIR)\"\' \
Simon Kelley00ec6932014-01-28 11:08:57 +0000106 build_cflags="$(version) $(dbus_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags) `$(PKG_CONFIG) --cflags libidn`" \
Simon Kelleyb98d22c2014-02-04 16:57:25 +0000107 build_libs="$(dbus_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) `$(PKG_CONFIG) --libs libidn`" \
Simon Kelley24848942012-02-29 11:23:41 +0000108 -f $(top)/Makefile dnsmasq
Simon Kelleyfdacfb02012-02-28 15:20:25 +0000109 for f in `cd $(PO); echo *.po`; do \
Simon Kelley24848942012-02-29 11:23:41 +0000110 cd $(top) && cd $(BUILDDIR) && $(MAKE) top="$(top)" -f $(top)/Makefile $${f%.po}.mo; \
Simon Kelleyb8187c82005-11-26 21:46:27 +0000111 done
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000112
Simon Kelleyb8187c82005-11-26 21:46:27 +0000113install-i18n : all-i18n install-common
Simon Kelley24848942012-02-29 11:23:41 +0000114 cd $(BUILDDIR); $(top)/bld/install-mo $(DESTDIR)$(LOCALEDIR) $(INSTALL)
Simon Kelley1f15b812009-10-13 17:49:32 +0100115 cd $(MAN); ../bld/install-man $(DESTDIR)$(MANDIR) $(INSTALL)
Simon Kelleyb8187c82005-11-26 21:46:27 +0000116
Simon Kelleyfdacfb02012-02-28 15:20:25 +0000117merge :
Simon Kelley24848942012-02-29 11:23:41 +0000118 @cd $(BUILDDIR) && $(MAKE) -f $(top)/Makefile dnsmasq.pot
Simon Kelleyfdacfb02012-02-28 15:20:25 +0000119 for f in `cd $(PO); echo *.po`; do \
120 echo -n msgmerge $(PO)/$$f && $(MSGMERGE) --no-wrap -U $(PO)/$$f $(BUILDDIR)/dnsmasq.pot; \
Simon Kelleyb8187c82005-11-26 21:46:27 +0000121 done
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000122
Simon Kelleyb7f666f2013-10-02 11:44:59 +0100123# Cannonicalise .po file.
124%.po :
125 @cd $(BUILDDIR) && $(MAKE) -f $(top)/Makefile dnsmasq.pot
126 mv $(PO)/$*.po $(PO)/$*.po.orig && $(MSGMERGE) --no-wrap $(PO)/$*.po.orig $(BUILDDIR)/dnsmasq.pot >$(PO)/$*.po;
127
Simon Kelleye5ffdb92012-02-13 14:19:25 +0000128$(BUILDDIR):
Simon Kelleyfdacfb02012-02-28 15:20:25 +0000129 mkdir -p $(BUILDDIR)
Simon Kelleyb36ae192012-02-13 12:54:34 +0000130
Simon Kelleyceae52d2013-09-12 15:05:47 +0100131# rules below are helpers for size tracking
132
133baseline : mostly_clean all
134 @cd $(BUILDDIR) && \
135 mv dnsmasq dnsmasq_baseline
136
137bloatcheck : $(BUILDDIR)/dnsmasq_baseline mostly_clean all
138 @cd $(BUILDDIR) && \
139 $(top)/bld/bloat-o-meter dnsmasq_baseline dnsmasq; \
140 size dnsmasq_baseline dnsmasq
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000141
Simon Kelley8e4b8792012-11-14 14:12:56 +0000142# rules below are targets in recusive makes with cwd=$(BUILDDIR)
143
Yousong Zhou81c538e2015-01-03 16:36:14 +0000144$(copts_conf): $(hdrs)
145 @rm -f *.o .copts_*
Simon Kelley8e4b8792012-11-14 14:12:56 +0000146 @touch $@
Simon Kelley316e2732010-01-22 20:16:09 +0000147
Simon Kelley24848942012-02-29 11:23:41 +0000148$(objs:.o=.c) $(hdrs):
149 ln -s $(top)/$(SRC)/$@ .
Simon Kelleyb36ae192012-02-13 12:54:34 +0000150
Yousong Zhoud8dbd902015-01-05 17:03:35 +0000151$(objs): $(copts_conf) $(hdrs)
152
Simon Kelley1adadf52012-02-13 22:15:58 +0000153.c.o:
Simon Kelley24848942012-02-29 11:23:41 +0000154 $(CC) $(CFLAGS) $(COPTS) $(i18n) $(build_cflags) $(RPM_OPT_FLAGS) -c $<
Simon Kelley316e2732010-01-22 20:16:09 +0000155
Yousong Zhoud8dbd902015-01-05 17:03:35 +0000156dnsmasq : $(objs)
Simon Kelley24848942012-02-29 11:23:41 +0000157 $(CC) $(LDFLAGS) -o $@ $(objs) $(build_libs) $(LIBS)
Simon Kelley316e2732010-01-22 20:16:09 +0000158
Simon Kelley24848942012-02-29 11:23:41 +0000159dnsmasq.pot : $(objs:.o=.c) $(hdrs)
160 $(XGETTEXT) -d dnsmasq --foreign-user --omit-header --keyword=_ -o $@ -i $(objs:.o=.c)
Simon Kelley316e2732010-01-22 20:16:09 +0000161
Simon Kelley24848942012-02-29 11:23:41 +0000162%.mo : $(top)/$(PO)/%.po dnsmasq.pot
Simon Kelley4f8ff362012-02-29 16:01:17 +0000163 $(MSGMERGE) -o - $(top)/$(PO)/$*.po dnsmasq.pot | $(MSGFMT) -o $*.mo -
Simon Kelley316e2732010-01-22 20:16:09 +0000164
Simon Kelleyceae52d2013-09-12 15:05:47 +0100165.PHONY : all clean mostly_clean install install-common all-i18n install-i18n merge baseline bloatcheck