1# Modified by Broadcom Corp. Portions Copyright (c) Broadcom Corp, 2012.
2# dnsmasq is Copyright (c) 2000-2012 Simon Kelley
3#
4#  This program is free software; you can redistribute it and/or modify
5#  it under the terms of the GNU General Public License as published by
6#  the Free Software Foundation; version 2 dated June, 1991, or
7#  (at your option) version 3 dated 29 June, 2007.
8#
9#  This program is distributed in the hope that it will be useful,
10#  but WITHOUT ANY WARRANTY; without even the implied warranty of
11#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12#  GNU General Public License for more details.
13#    
14#  You should have received a copy of the GNU General Public License
15#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17# NOTE: Building the i18n targets requires GNU-make 
18
19
20# Variables you may well want to override.
21
22PREFIX        = /usr/local
23BINDIR        = $(PREFIX)/sbin
24MANDIR        = $(PREFIX)/share/man
25LOCALEDIR     = $(PREFIX)/share/locale
26BUILDDIR      = $(SRC)
27DESTDIR       = 
28CFLAGS        = -Wall -W -O2 -DNO_TFP -DNO_DHCP -DNO_DHCP6 -DNO_SCRIPT -DNO_LARGEFILE
29LDFLAGS       = 
30COPTS         = 
31RPM_OPT_FLAGS = 
32LIBS          = 
33
34#################################################################
35
36# Variables you might want to override.
37
38PKG_CONFIG = pkg-config
39INSTALL    = install
40MSGMERGE   = msgmerge
41MSGFMT     = msgfmt
42XGETTEXT   = xgettext
43
44SRC = src
45PO  = po
46MAN = man
47
48#################################################################
49
50# pmake way. (NB no spaces to keep gmake 3.82 happy)
51top!=pwd
52# GNU make way.
53top?=$(CURDIR)
54
55dbus_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --cflags dbus-1` 
56dbus_libs =   `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --libs dbus-1` 
57idn_cflags =  `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --cflags libidn` 
58idn_libs =    `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --libs libidn` 
59ct_cflags =   `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --cflags libnetfilter_conntrack`
60ct_libs =     `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --libs libnetfilter_conntrack`
61lua_cflags =  `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --cflags lua5.1` 
62lua_libs =    `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --libs lua5.1` 
63sunos_libs =  `if uname | grep SunOS >/dev/null 2>&1; then echo -lsocket -lnsl -lposix4; fi`
64version =     -DVERSION='\"`$(top)/bld/get-version $(top)`\"'
65
66objs = cache.o rfc1035.o util.o option.o forward.o network.o \
67       dnsmasq.o dhcp.o lease.o rfc2131.o netlink.o dbus.o bpf.o \
68       helper.o tftp.o log.o conntrack.o dhcp6.o rfc3315.o \
69       dhcp-common.o outpacket.o radv.o slaac.o
70
71hdrs = dnsmasq.h config.h dhcp-protocol.h dhcp6-protocol.h \
72       dns-protocol.h radv-protocol.h
73
74all : $(BUILDDIR)
75	@cd $(BUILDDIR) && $(MAKE) \
76 top="$(top)" \
77 build_cflags="$(version) $(dbus_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags)" \
78 build_libs="$(dbus_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs)" \
79 -f $(top)/Makefile dnsmasq 
80
81clean :
82	rm -f *~ $(BUILDDIR)/*.mo contrib/*/*~ */*~ $(BUILDDIR)/*.pot 
83	rm -f $(BUILDDIR)/.configured $(BUILDDIR)/*.o $(BUILDDIR)/dnsmasq.a $(BUILDDIR)/dnsmasq 
84	rm -rf core */core
85
86install : all install-common
87
88install-common :
89	$(INSTALL) -d $(DESTDIR)$(BINDIR) -d $(DESTDIR)$(MANDIR)/man8
90	$(INSTALL) -m 644 $(MAN)/dnsmasq.8 $(DESTDIR)$(MANDIR)/man8 
91	$(INSTALL) -m 755 $(BUILDDIR)/dnsmasq $(DESTDIR)$(BINDIR)
92
93all-i18n : $(BUILDDIR)
94	@cd $(BUILDDIR) && $(MAKE) \
95 top="$(top)" \
96 i18n=-DLOCALEDIR=\'\"$(LOCALEDIR)\"\' \
97 build_cflags="$(version) $(dbus_cflags) $(ct_cflags) $(lua_cflags) `$(PKG_CONFIG) --cflags libidn`" \
98 build_libs="$(dbus_libs) $(ct_libs) $(lua_libs) $(sunos_libs) `$(PKG_CONFIG) --libs libidn`"  \
99 -f $(top)/Makefile dnsmasq
100	for f in `cd $(PO); echo *.po`; do \
101		cd $(top) && cd $(BUILDDIR) && $(MAKE) top="$(top)" -f $(top)/Makefile $${f%.po}.mo; \
102	done
103
104install-i18n : all-i18n install-common
105	cd $(BUILDDIR); $(top)/bld/install-mo $(DESTDIR)$(LOCALEDIR) $(INSTALL)
106	cd $(MAN); ../bld/install-man $(DESTDIR)$(MANDIR) $(INSTALL)
107
108merge : 
109	@cd $(BUILDDIR) && $(MAKE) -f $(top)/Makefile dnsmasq.pot
110	for f in `cd $(PO); echo *.po`; do \
111		echo -n msgmerge $(PO)/$$f && $(MSGMERGE) --no-wrap -U $(PO)/$$f $(BUILDDIR)/dnsmasq.pot; \
112	done
113
114$(BUILDDIR):
115	mkdir -p $(BUILDDIR)
116
117
118# rules below are targets in recusive makes with cwd=$(BUILDDIR)
119
120.configured: $(hdrs)
121	@rm -f *.o
122	@touch $@
123
124$(objs:.o=.c) $(hdrs):
125	ln -s $(top)/$(SRC)/$@ .
126
127.c.o:
128	$(CC) $(CFLAGS) $(COPTS) $(i18n) $(build_cflags) $(RPM_OPT_FLAGS) -c $<	
129
130dnsmasq : .configured $(hdrs) $(objs) 
131	$(CC) $(LDFLAGS) -o $@ $(objs) $(build_libs) $(LIBS) 
132
133dnsmasq.pot : $(objs:.o=.c) $(hdrs)
134	$(XGETTEXT) -d dnsmasq --foreign-user --omit-header --keyword=_ -o $@ -i $(objs:.o=.c)
135
136%.mo : $(top)/$(PO)/%.po dnsmasq.pot
137	$(MSGMERGE) -o - $(top)/$(PO)/$*.po dnsmasq.pot | $(MSGFMT) -o $*.mo -
138
139
140.PHONY : all clean install install-common all-i18n install-i18n merge 
141