blob: cf45da52bf17821064ac096956a83353d5742b14 [file] [log] [blame]
Tarun Kundu12e3b2e2024-08-15 16:16:53 -07001# dnsmasq is Copyright (c) 2000-2024 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
Tarun Kundu567116b2024-08-15 16:22:58 -070018# CRADLEPOINT
19ROOT ?= $(abspath ../../)
20include $(ROOT)/Makefile.config
21# CRADLEPOINT
Simon Kelleyb36ae192012-02-13 12:54:34 +000022
Simon Kelley24848942012-02-29 11:23:41 +000023# Variables you may well want to override.
24
Tarun Kundu567116b2024-08-15 16:22:58 -070025# CRADLEPOINT
26PREFIX = /usr
27# CRADLEPOINT
28
Simon Kelley24848942012-02-29 11:23:41 +000029BINDIR = $(PREFIX)/sbin
30MANDIR = $(PREFIX)/share/man
31LOCALEDIR = $(PREFIX)/share/locale
32BUILDDIR = $(SRC)
Tarun Kundu567116b2024-08-15 16:22:58 -070033# CRADLEPOINT
34
35#DESTDIR =
36CFLAGS += -Wall -W $(COPT_SIZE)
37LDFLAGS +=
38COPTS = -DCPLINUX
39# CRADLEPOINT
40
Simon Kelley24848942012-02-29 11:23:41 +000041RPM_OPT_FLAGS =
42LIBS =
Tarun Kundu567116b2024-08-15 16:22:58 -070043
44# CRADLEPOINT feature handling
45ifeq ($(PRODUCT_FEATURE_DNSSEC),yes)
46LDFLAGS += -lnettle -lhogweed
47CFLAGS += -DHAVE_DNSSEC -DNO_GMP
48endif
49# CRADLEPOINT
Kyle Swenson545712c2021-11-17 12:25:04 -070050
Simon Kelleye5ffdb92012-02-13 14:19:25 +000051#################################################################
52
Simon Kelley24848942012-02-29 11:23:41 +000053# Variables you might want to override.
54
Simon Kelley824af852008-02-12 20:43:05 +000055PKG_CONFIG = pkg-config
Simon Kelley24848942012-02-29 11:23:41 +000056INSTALL = install
57MSGMERGE = msgmerge
58MSGFMT = msgfmt
59XGETTEXT = xgettext
Simon Kelley824af852008-02-12 20:43:05 +000060
Simon Kelley316e2732010-01-22 20:16:09 +000061SRC = src
Simon Kelley24848942012-02-29 11:23:41 +000062PO = po
Simon Kelley316e2732010-01-22 20:16:09 +000063MAN = man
64
Simon Kelley24848942012-02-29 11:23:41 +000065#################################################################
Simon Kelleyfdacfb02012-02-28 15:20:25 +000066
Simon Kelleyc46c7c72012-02-29 21:37:14 +000067# pmake way. (NB no spaces to keep gmake 3.82 happy)
68top!=pwd
Simon Kelley24848942012-02-29 11:23:41 +000069# GNU make way.
Simon Kelleyc46c7c72012-02-29 21:37:14 +000070top?=$(CURDIR)
Simon Kelley9e4abcb2004-01-22 19:47:41 +000071
Simon Kelley86bec2d2014-01-13 21:31:20 +000072dbus_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --cflags dbus-1`
73dbus_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --libs dbus-1`
Petr Menšík2024f972020-11-25 17:18:55 +010074ubus_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_UBUS "" --copy '-lubox -lubus'`
Simon Kelley86bec2d2014-01-13 21:31:20 +000075idn_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --cflags libidn`
76idn_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --libs libidn`
Simon Kelley43cdf1c2017-05-21 22:12:44 +010077idn2_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LIBIDN2 $(PKG_CONFIG) --cflags libidn2`
78idn2_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LIBIDN2 $(PKG_CONFIG) --libs libidn2`
Simon Kelley86bec2d2014-01-13 21:31:20 +000079ct_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --cflags libnetfilter_conntrack`
80ct_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --libs libnetfilter_conntrack`
Tarun Kundu567116b2024-08-15 16:22:58 -070081lua_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --cflags lua5.2`
82lua_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --libs lua5.2`
Petr Menšík2024f972020-11-25 17:18:55 +010083nettle_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --cflags 'nettle hogweed' \
Simon Kelleya69b0172021-01-24 21:53:28 +000084 HAVE_CRYPTOHASH $(PKG_CONFIG) --cflags nettle \
Petr Menšík2024f972020-11-25 17:18:55 +010085 HAVE_NETTLEHASH $(PKG_CONFIG) --cflags nettle`
86nettle_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --libs 'nettle hogweed' \
Simon Kelleya69b0172021-01-24 21:53:28 +000087 HAVE_CRYPTOHASH $(PKG_CONFIG) --libs nettle \
Petr Menšík2024f972020-11-25 17:18:55 +010088 HAVE_NETTLEHASH $(PKG_CONFIG) --libs nettle`
Simon Kelley063efb32014-06-17 19:49:31 +010089gmp_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC NO_GMP --copy -lgmp`
Simon Kelley86bec2d2014-01-13 21:31:20 +000090sunos_libs = `if uname | grep SunOS >/dev/null 2>&1; then echo -lsocket -lnsl -lposix4; fi`
Tarun Kundu12e3b2e2024-08-15 16:16:53 -070091nft_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_NFTSET $(PKG_CONFIG) --cflags libnftables`
92nft_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_NFTSET $(PKG_CONFIG) --libs libnftables`
Tarun Kundu567116b2024-08-15 16:22:58 -070093version = -DVERSION='\"`$(top)/bld/get-version $(top)`\"'
Simon Kelley10626672015-02-01 00:15:16 +000094
95sum?=$(shell $(CC) -DDNSMASQ_COMPILE_OPTS $(COPTS) -E $(top)/$(SRC)/dnsmasq.h | ( md5sum 2>/dev/null || md5 ) | cut -f 1 -d ' ')
96sum!=$(CC) -DDNSMASQ_COMPILE_OPTS $(COPTS) -E $(top)/$(SRC)/dnsmasq.h | ( md5sum 2>/dev/null || md5 ) | cut -f 1 -d ' '
97copts_conf = .copts_$(sum)
Simon Kelley24848942012-02-29 11:23:41 +000098
99objs = cache.o rfc1035.o util.o option.o forward.o network.o \
Simon Kelley316e2732010-01-22 20:16:09 +0000100 dnsmasq.o dhcp.o lease.o rfc2131.o netlink.o dbus.o bpf.o \
Simon Kelleyc5ad4e72012-02-24 16:06:20 +0000101 helper.o tftp.o log.o conntrack.o dhcp6.o rfc3315.o \
Tarun Kundu12e3b2e2024-08-15 16:16:53 -0700102 dhcp-common.o outpacket.o radv.o slaac.o auth.o ipset.o pattern.o \
Simon Kelleyc2bcd1e2015-12-15 17:25:21 +0000103 domain.o dnssec.o blockdata.o tables.o loop.o inotify.o \
Simon Kelley2d765862020-11-12 22:06:07 +0000104 poll.o rrfilter.o edns0.o arp.o crypto.o dump.o ubus.o \
Tarun Kundu567116b2024-08-15 16:22:58 -0700105 metrics.o hash-questions.o domain-match.o nftset.o \
106 unescape_c_string.o opendns.o # CRADLEPOINT
Simon Kelley208b65c2006-08-05 21:41:37 +0100107
Simon Kelley24848942012-02-29 11:23:41 +0000108hdrs = dnsmasq.h config.h dhcp-protocol.h dhcp6-protocol.h \
Tarun Kundu567116b2024-08-15 16:22:58 -0700109 dns-protocol.h radv-protocol.h ip6addr.h metrics.h \
110 unescape_c_string.h opendns.h # CRADLEPOINT
Simon Kelleyb36ae192012-02-13 12:54:34 +0000111
Simon Kelleye5ffdb92012-02-13 14:19:25 +0000112all : $(BUILDDIR)
113 @cd $(BUILDDIR) && $(MAKE) \
Simon Kelley24848942012-02-29 11:23:41 +0000114 top="$(top)" \
Tarun Kundu12e3b2e2024-08-15 16:16:53 -0700115 build_cflags="$(version) $(dbus_cflags) $(idn2_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags) $(nft_cflags)" \
116 build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) $(ubus_libs) $(nft_libs)" \
Simon Kelley24848942012-02-29 11:23:41 +0000117 -f $(top)/Makefile dnsmasq
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000118
Simon Kelleyceae52d2013-09-12 15:05:47 +0100119mostly_clean :
120 rm -f $(BUILDDIR)/*.mo $(BUILDDIR)/*.pot
Yousong Zhou81c538e2015-01-03 16:36:14 +0000121 rm -f $(BUILDDIR)/.copts_* $(BUILDDIR)/*.o $(BUILDDIR)/dnsmasq.a $(BUILDDIR)/dnsmasq
Simon Kelleyceae52d2013-09-12 15:05:47 +0100122
123clean : mostly_clean
124 rm -f $(BUILDDIR)/dnsmasq_baseline
125 rm -f core */core
126 rm -f *~ contrib/*/*~ */*~
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000127
Simon Kelleyb8187c82005-11-26 21:46:27 +0000128install : all install-common
129
130install-common :
Kevin Darbyshire-Bryant6d379242018-04-07 23:00:56 +0100131 $(INSTALL) -d $(DESTDIR)$(BINDIR)
132 $(INSTALL) -d $(DESTDIR)$(MANDIR)/man8
Simon Kelley824af852008-02-12 20:43:05 +0000133 $(INSTALL) -m 644 $(MAN)/dnsmasq.8 $(DESTDIR)$(MANDIR)/man8
Simon Kelleye5ffdb92012-02-13 14:19:25 +0000134 $(INSTALL) -m 755 $(BUILDDIR)/dnsmasq $(DESTDIR)$(BINDIR)
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000135
Simon Kelleye5ffdb92012-02-13 14:19:25 +0000136all-i18n : $(BUILDDIR)
137 @cd $(BUILDDIR) && $(MAKE) \
Simon Kelley24848942012-02-29 11:23:41 +0000138 top="$(top)" \
139 i18n=-DLOCALEDIR=\'\"$(LOCALEDIR)\"\' \
Tarun Kundu567116b2024-08-15 16:22:58 -0700140 build_cflags="$(version) $(dbus_cflags) $(idn2_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags)" \
141 build_libs="$(dbus_libs) $(idn2_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) $(ubus_libs)" \
Simon Kelley24848942012-02-29 11:23:41 +0000142 -f $(top)/Makefile dnsmasq
Simon Kelleyfdacfb02012-02-28 15:20:25 +0000143 for f in `cd $(PO); echo *.po`; do \
Simon Kelley24848942012-02-29 11:23:41 +0000144 cd $(top) && cd $(BUILDDIR) && $(MAKE) top="$(top)" -f $(top)/Makefile $${f%.po}.mo; \
Simon Kelleyb8187c82005-11-26 21:46:27 +0000145 done
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000146
Simon Kelleyb8187c82005-11-26 21:46:27 +0000147install-i18n : all-i18n install-common
Simon Kelley24848942012-02-29 11:23:41 +0000148 cd $(BUILDDIR); $(top)/bld/install-mo $(DESTDIR)$(LOCALEDIR) $(INSTALL)
Simon Kelley1f15b812009-10-13 17:49:32 +0100149 cd $(MAN); ../bld/install-man $(DESTDIR)$(MANDIR) $(INSTALL)
Simon Kelleyb8187c82005-11-26 21:46:27 +0000150
Simon Kelleyfdacfb02012-02-28 15:20:25 +0000151merge :
Simon Kelleyf7bfbdc2015-06-10 22:31:02 +0100152 @cd $(BUILDDIR) && $(MAKE) top="$(top)" -f $(top)/Makefile dnsmasq.pot
Simon Kelleyfdacfb02012-02-28 15:20:25 +0000153 for f in `cd $(PO); echo *.po`; do \
154 echo -n msgmerge $(PO)/$$f && $(MSGMERGE) --no-wrap -U $(PO)/$$f $(BUILDDIR)/dnsmasq.pot; \
Simon Kelleyb8187c82005-11-26 21:46:27 +0000155 done
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000156
Josh Soref730c6742017-02-06 16:14:04 +0000157# Canonicalise .po file.
Simon Kelleyb7f666f2013-10-02 11:44:59 +0100158%.po :
159 @cd $(BUILDDIR) && $(MAKE) -f $(top)/Makefile dnsmasq.pot
160 mv $(PO)/$*.po $(PO)/$*.po.orig && $(MSGMERGE) --no-wrap $(PO)/$*.po.orig $(BUILDDIR)/dnsmasq.pot >$(PO)/$*.po;
161
Simon Kelleye5ffdb92012-02-13 14:19:25 +0000162$(BUILDDIR):
Simon Kelleyfdacfb02012-02-28 15:20:25 +0000163 mkdir -p $(BUILDDIR)
Simon Kelleyb36ae192012-02-13 12:54:34 +0000164
Simon Kelleyceae52d2013-09-12 15:05:47 +0100165# rules below are helpers for size tracking
166
167baseline : mostly_clean all
168 @cd $(BUILDDIR) && \
169 mv dnsmasq dnsmasq_baseline
170
171bloatcheck : $(BUILDDIR)/dnsmasq_baseline mostly_clean all
172 @cd $(BUILDDIR) && \
173 $(top)/bld/bloat-o-meter dnsmasq_baseline dnsmasq; \
174 size dnsmasq_baseline dnsmasq
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000175
Josh Soref730c6742017-02-06 16:14:04 +0000176# rules below are targets in recursive makes with cwd=$(BUILDDIR)
Simon Kelley8e4b8792012-11-14 14:12:56 +0000177
Yousong Zhou81c538e2015-01-03 16:36:14 +0000178$(copts_conf): $(hdrs)
179 @rm -f *.o .copts_*
Simon Kelley8e4b8792012-11-14 14:12:56 +0000180 @touch $@
Simon Kelley316e2732010-01-22 20:16:09 +0000181
Simon Kelley24848942012-02-29 11:23:41 +0000182$(objs:.o=.c) $(hdrs):
183 ln -s $(top)/$(SRC)/$@ .
Simon Kelleyb36ae192012-02-13 12:54:34 +0000184
Yousong Zhoud8dbd902015-01-05 17:03:35 +0000185$(objs): $(copts_conf) $(hdrs)
186
Simon Kelley1adadf52012-02-13 22:15:58 +0000187.c.o:
Simon Kelley24848942012-02-29 11:23:41 +0000188 $(CC) $(CFLAGS) $(COPTS) $(i18n) $(build_cflags) $(RPM_OPT_FLAGS) -c $<
Simon Kelley316e2732010-01-22 20:16:09 +0000189
Yousong Zhoud8dbd902015-01-05 17:03:35 +0000190dnsmasq : $(objs)
Simon Kelley24848942012-02-29 11:23:41 +0000191 $(CC) $(LDFLAGS) -o $@ $(objs) $(build_libs) $(LIBS)
Simon Kelley316e2732010-01-22 20:16:09 +0000192
Simon Kelley24848942012-02-29 11:23:41 +0000193dnsmasq.pot : $(objs:.o=.c) $(hdrs)
194 $(XGETTEXT) -d dnsmasq --foreign-user --omit-header --keyword=_ -o $@ -i $(objs:.o=.c)
Simon Kelley316e2732010-01-22 20:16:09 +0000195
Simon Kelley24848942012-02-29 11:23:41 +0000196%.mo : $(top)/$(PO)/%.po dnsmasq.pot
Simon Kelley4f8ff362012-02-29 16:01:17 +0000197 $(MSGMERGE) -o - $(top)/$(PO)/$*.po dnsmasq.pot | $(MSGFMT) -o $*.mo -
Simon Kelley316e2732010-01-22 20:16:09 +0000198
Simon Kelleyceae52d2013-09-12 15:05:47 +0100199.PHONY : all clean mostly_clean install install-common all-i18n install-i18n merge baseline bloatcheck