1 # Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
3 # @APPLE_LICENSE_HEADER_START@
5 # This file contains Original Code and/or Modifications of Original Code
6 # as defined in and that are subject to the Apple Public Source License
7 # Version 2.0 (the 'License'). You may not use this file except in
8 # compliance with the License. Please obtain a copy of the License at
9 # http://www.opensource.apple.com/apsl/ and read it before using this
12 # The Original Code and all software distributed under the License are
13 # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
17 # Please see the License for the specific language governing rights and
18 # limitations under the License.
20 # @APPLE_LICENSE_HEADER_END@
23 # Revision 1.34 2004/05/25 18:29:33 cheshire
24 # Move DNSServiceConstructFullName() from dnssd_clientstub.c to dnssd_clientlib.c,
25 # so that it's also accessible to dnssd_clientshim.c (single address space) clients.
27 # Revision 1.33 2004/04/30 16:46:32 rpantos
28 # Add support for building Java libraries.
30 # Revision 1.32 2004/04/14 23:09:29 ksekar
31 # Support for TSIG signed dynamic updates.
33 # Revision 1.31 2004/03/15 19:07:06 cheshire
36 # Revision 1.30 2004/03/11 18:58:29 rpantos
37 # Fix Kill /etc/rc scripts so they run at halt & reboot.
39 # Revision 1.29 2004/03/04 23:35:41 cheshire
40 # Instead of using a dummy target to generate an error message, use "$(error text...)"
42 # Revision 1.28 2004/03/04 23:33:42 cheshire
43 # Fixes from Alfred Perlstein for FreeBSD's benefit
45 # Revision 1.27 2004/02/11 21:00:21 cheshire
46 # Update URL for GNU Make manual page
48 # Revision 1.26 2004/02/05 21:28:30 cheshire
49 # Fixes so that "sudo make install" works on *BSD
51 # Revision 1.25 2004/02/05 20:00:22 cheshire
52 # Define mdnsd's PID file to be /var/run/mdnsd.pid on Posix builds
54 # Revision 1.24 2004/02/05 01:00:01 rpantos
55 # Fix some issues that turned up when building for FreeBSD.
57 # Revision 1.23 2004/02/04 01:50:54 cheshire
58 # Make InstalledStartup conditional, so it automatically installs into
59 # either /etc/init.d/ or /etc/rc.d/init.d/ as appropriate
61 # Revision 1.22 2004/01/20 01:41:21 rpantos
62 # Define USES_NETLINK for Linux builds.
64 # Revision 1.21 2003/12/17 00:51:22 cheshire
65 # Changed mDNSNetMonitor and mDNSIdentify to link the object files
66 # instead of #including the "DNSCommon.c" "uDNS.c" and source files
68 # Revision 1.20 2003/12/13 03:05:28 ksekar
69 # Bug #: <rdar://problem/3192548>: DynDNS: Unicast query of service records
71 # Revision 1.19 2003/12/11 19:42:13 cheshire
72 # Change name "mDNSResponderd" to "mdnsd" for consistency with standard Linux (Unix) naming conventions
74 # Revision 1.18 2003/12/11 19:38:34 cheshire
77 # Revision 1.17 2003/12/11 03:16:49 rpantos
78 # One more change for OS X build: make install work a little better.
80 # Revision 1.16 2003/12/11 03:03:51 rpantos
81 # Clean up mDNSPosix so that it builds on OS X again.
83 # Revision 1.15 2003/12/08 20:47:02 rpantos
84 # Add support for mDNSResponder on Linux.
86 # Revision 1.14 2003/11/14 20:59:09 cheshire
87 # Clients can't use AssignDomainName macro because mDNSPlatformMemCopy is defined in mDNSPlatformFunctions.h.
88 # Best solution is just to combine mDNSClientAPI.h and mDNSPlatformFunctions.h into a single file.
90 # Revision 1.13 2003/08/06 18:20:51 cheshire
93 # Revision 1.12 2003/08/01 02:20:02 cheshire
94 # Add mDNSIdentify tool, used to discover what version of mDNSResponder a particular host is running
96 # Revision 1.11 2003/07/14 18:11:54 cheshire
97 # Fix stricter compiler warnings
99 # Revision 1.10 2003/06/18 05:47:41 cheshire
100 # Enable stricter warnings on Jaguar and Panther builds
102 # Revision 1.9 2003/06/04 18:34:45 ksekar
103 # Bug #: <rdar://problem/3218120>: mDNSPosix does not build on Panther that has socklen_t
104 # Changed build targets "osx10.2" and "osx10.3" to "jaguar" and "panther".
106 # Revision 1.8 2003/06/04 00:23:12 ksekar
107 # Bug #: <rdar://problem/3218120>: mDNSPosix does not build on Panther that has socklen_t
108 # Created separate target OS's for 10.2 and 10.3.
110 # Revision 1.7 2003/04/16 02:11:37 cheshire
111 # Remove unnecessary $(CFLAGS) from linking rules
113 # Revision 1.6 2003/04/04 01:37:14 cheshire
117 # This Makefile builds an mDNSResponder daemon and a libmdns.so shared library
118 # for Linux. It also builds several example programs for embedded systems.
120 # Make with no arguments to build all production targets.
121 # 'make DEBUG=1' to build debugging targets.
122 # 'make clean' or 'make clean DEBUG=1' to delete prod/debug objects & targets
123 # 'sudo make install [DEBUG=1]' to install mdnsd daemon and libmdns.
126 # $@ means "The file name of the target of the rule"
127 # $< means "The name of the first prerequisite"
128 # $+ means "The names of all the prerequisites, with spaces between them, exactly as given"
129 # For more magic automatic variables, see
130 # <http://www.gnu.org/software/make/manual/html_chapter/make_10.html#SEC111>
132 #############################################################################
136 COREDIR = ../mDNSCore
137 SHAREDDIR = ../mDNSShared
145 CFLAGS_COMMON = -I. -I$(COREDIR) -I$(SHAREDDIR) -W -Wall -DPID_FILE=\"/var/run/mdnsd.pid\"
148 JAVACFLAGS_OS = -fPIC -shared -lmdns
150 # Set up diverging paths for debug vs. prod builds
153 CFLAGS_DEBUG = -g -DMDNS_DEBUGMSGS=2
154 OBJDIR = objects/debug
155 BUILDDIR = build/debug
158 CFLAGS_DEBUG = -Os -DMDNS_DEBUGMSGS=0
159 OBJDIR = objects/prod
160 BUILDDIR = build/prod
164 # Configure per-OS peculiarities
166 CFLAGS_OS = -DNOT_HAVE_DAEMON -DNOT_HAVE_SA_LEN -D_XPG4_2 -D__EXTENSIONS__ -DHAVE_BROKEN_RECVIF_NAME -lsocket -lnsl
169 CFLAGS_OS = -DNOT_HAVE_SA_LEN -DUSES_NETLINK
170 JAVACFLAGS_OS += -I$(JDK)/include/linux
177 # If not already defined, set LOCALBASE to /usr/local
178 # FreeBSD requires the startup script to end in ".sh"
179 LOCALBASE?=/usr/local
180 INSTBASE=$(LOCALBASE)
181 STARTUPSCRIPTNAME=mdns.sh
186 CFLAGS_OS = -DHAVE_BROKEN_RECVDSTADDR
190 CFLAGS_OS = -DHAVE_IPV6 -no-cpp-precomp -DNOT_HAVE_SOCKLEN_T
192 LDFLAGS = -dynamic -lSystem
194 JDK = /System/Library/Frameworks/JavaVM.framework/Home
195 JAVACFLAGS_OS = -dynamiclib -I/System/Library/Frameworks/JavaVM.framework/Headers -framework JavaVM
198 CFLAGS_OS = -DHAVE_IPV6 -no-cpp-precomp
200 LDFLAGS = -dynamic -lSystem
202 JDK = /System/Library/Frameworks/JavaVM.framework/Home
203 JAVACFLAGS_OS = -dynamiclib -I/System/Library/Frameworks/JavaVM.framework/Headers -framework JavaVM
205 $(error ERROR: Must specify target OS on command-line: "make os={jaguar,panther,linux,netbsd,freebsd,openbsd,solaris} [target]")
214 # If not otherwise defined, we install into /usr/lib and /usr/include
215 # and our startup script is called mdns (e.g. /etc/init.d/mdns)
217 STARTUPSCRIPTNAME?=mdns
219 ifeq ($(HAVE_IPV6),1)
220 CFLAGS_OS += -DHAVE_IPV6=1
222 ifeq ($(HAVE_IPV6),0)
223 CFLAGS_OS += -DHAVE_IPV6=0
227 # If directory /etc/rc.d/init.d/ exists, then we install into that (old Linux)
228 ifeq ($(wildcard /etc/rc.d/init.d/), /etc/rc.d/init.d/)
229 STARTUPSCRIPTDIR = /etc/rc.d/init.d
230 RUNLEVELSCRIPTSDIR = /etc/rc.d
232 # else if directory /etc/init.d/ exists, then we install into that (new Linux)
233 ifeq ($(wildcard /etc/init.d/), /etc/init.d/)
234 STARTUPSCRIPTDIR = /etc/init.d
235 RUNLEVELSCRIPTSDIR = /etc
237 # else install into /etc/rc.d/ (*BSD)
238 STARTUPSCRIPTDIR = $(INSTBASE)/etc/rc.d
242 CFLAGS = $(CFLAGS_COMMON) $(CFLAGS_OS) $(CFLAGS_DEBUG)
244 #############################################################################
246 all: setup Daemon libmdns Client Responder ProxyResponder Identify NetMonitor
248 install: setup InstalledDaemon InstalledLib InstalledStartup
250 # 'setup' sets up the build directory structure the way we want
252 @if test ! -d objects ; then mkdir objects ; fi
253 @if test ! -d build ; then mkdir build ; fi
254 @if test ! -d $(OBJDIR) ; then mkdir $(OBJDIR) ; fi
255 @if test ! -d $(BUILDDIR) ; then mkdir $(BUILDDIR) ; fi
257 # clean removes targets and objects
259 if test -d $(OBJDIR) ; then rm -r $(OBJDIR) ; fi
260 if test -d $(BUILDDIR) ; then rm -r $(BUILDDIR) ; fi
262 #############################################################################
264 # daemon target builds the daemon
265 DAEMONOBJS = $(OBJDIR)/PosixDaemon.c.o $(OBJDIR)/mDNSPosix.c.o $(OBJDIR)/mDNSUNP.c.o $(OBJDIR)/mDNS.c.o \
266 $(OBJDIR)/DNSDigest.c.o $(OBJDIR)/uDNS.c.o $(OBJDIR)/DNSCommon.c.o $(OBJDIR)/uds_daemon.c.o \
267 $(OBJDIR)/mDNSDebug.c.o $(OBJDIR)/dnssd_ipc.c.o $(OBJDIR)/GenLinkedList.c.o
269 Daemon: setup $(BUILDDIR)/mdnsd
270 @echo "Responder daemon done"
272 $(BUILDDIR)/mdnsd: $(DAEMONOBJS)
276 # libmdns target builds the client library
277 libmdns: setup $(BUILDDIR)/libmdns.$(LDSUFFIX)
278 @echo "Client library done"
280 $(BUILDDIR)/libmdns.$(LDSUFFIX): $(OBJDIR)/dnssd_clientlib.c.so.o $(OBJDIR)/dnssd_clientstub.c.so.o $(OBJDIR)/dnssd_ipc.c.so.o
281 $(LD) $(LDFLAGS) -o $@ $+
284 #############################################################################
286 # The Install targets place built stuff in their proper places
287 InstalledDaemon: $(INSTBASE)/sbin/mdnsd
288 @echo $< " installed"
290 InstalledLib: $(INSTBASE)/lib/libmdns.$(LDSUFFIX).$(LIBVERS) $(INSTBASE)/include/dns_sd.h
291 @echo $< " installed"
293 InstalledStartup: $(STARTUPSCRIPTDIR)/$(STARTUPSCRIPTNAME)
294 @echo $< " installed"
296 $(INSTBASE)/sbin/mdnsd: $(BUILDDIR)/mdnsd
299 $(INSTBASE)/lib/libmdns.$(LDSUFFIX).$(LIBVERS): $(BUILDDIR)/libmdns.$(LDSUFFIX)
301 $(LN) $@ $(INSTBASE)/lib/libmdns.$(LDSUFFIX)
303 # -m means 'merge into existing database', -R means 'rescan directories'
307 $(INSTBASE)/include/dns_sd.h: $(SHAREDDIR)/dns_sd.h
310 $(STARTUPSCRIPTDIR)/$(STARTUPSCRIPTNAME): mdnsd.sh $(STARTUPSCRIPTDIR)
313 ifdef RUNLEVELSCRIPTSDIR
314 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/rc2.d/S52mdns
315 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/rc3.d/S52mdns
316 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/rc4.d/S52mdns
317 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/rc5.d/S52mdns
318 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/rc0.d/K16mdns
319 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/rc6.d/K16mdns
322 #############################################################################
324 # The following targets build Java wrappers for the dns-sd.h API.
326 JAVAC = $(JDK)/bin/javac
327 JAVAH = $(JDK)/bin/javah
328 JAVADOC = $(JDK)/bin/javadoc
330 JAVACFLAGS = $(CFLAGS) $(JAVACFLAGS_OS) -I$(JDK)/include
332 Java: setup $(BUILDDIR)/dns_sd.jar $(BUILDDIR)/libjdns_sd.$(LDSUFFIX)
333 @echo "Java wrappers done"
335 JAVASRC = $(SHAREDDIR)/Java
336 JARCONTENTS = $(OBJDIR)/com/apple/dnssd/DNSSDService.class \
337 $(OBJDIR)/com/apple/dnssd/DNSRecord.class \
338 $(OBJDIR)/com/apple/dnssd/DNSSDException.class \
339 $(OBJDIR)/com/apple/dnssd/TXTRecord.class \
340 $(OBJDIR)/com/apple/dnssd/DNSSDRegistration.class \
341 $(OBJDIR)/com/apple/dnssd/BaseListener.class \
342 $(OBJDIR)/com/apple/dnssd/BrowseListener.class \
343 $(OBJDIR)/com/apple/dnssd/ResolveListener.class \
344 $(OBJDIR)/com/apple/dnssd/RegisterListener.class \
345 $(OBJDIR)/com/apple/dnssd/QueryListener.class \
346 $(OBJDIR)/com/apple/dnssd/DomainListener.class \
347 $(OBJDIR)/com/apple/dnssd/DNSSD.class
349 $(BUILDDIR)/dns_sd.jar: $(JARCONTENTS)
350 $(JAR) -cf $@ -C $(OBJDIR) com
352 $(BUILDDIR)/libjdns_sd.$(LDSUFFIX): $(JAVASRC)/JNISupport.c $(OBJDIR)/DNSSD.java.h
353 $(CC) -o $@ $< $(JAVACFLAGS) -I$(OBJDIR)
355 $(OBJDIR)/com/apple/dnssd/%.class: $(JAVASRC)/%.java
356 $(JAVAC) -d $(OBJDIR) -classpath $(OBJDIR) $<
358 $(OBJDIR)/DNSSD.java.h: $(OBJDIR)/com/apple/dnssd/DNSSD.class
359 $(JAVAH) -force -classpath $(OBJDIR) -o $@ \
360 com.apple.dnssd.AppleDNSSD \
361 com.apple.dnssd.AppleBrowser \
362 com.apple.dnssd.AppleResolver \
363 com.apple.dnssd.AppleRegistration \
364 com.apple.dnssd.AppleQuery \
365 com.apple.dnssd.AppleDomainEnum \
366 com.apple.dnssd.AppleService
368 #############################################################################
370 # The following target builds documentation for the Java wrappers.
373 $(JAVADOC) $(JAVASRC)/*.java -classpath $(OBJDIR) -d $(BUILDDIR) -public
375 #############################################################################
377 # The following targets build embedded example programs
378 SPECIALOBJ = $(OBJDIR)/mDNSPosix.c.o $(OBJDIR)/mDNSUNP.c.o $(OBJDIR)/mDNSDebug.c.o $(OBJDIR)/GenLinkedList.c.o $(OBJDIR)/DNSDigest.c.o $(OBJDIR)/uDNS.c.o $(OBJDIR)/DNSCommon.c.o
379 COMMONOBJ = $(SPECIALOBJ) $(OBJDIR)/mDNS.c.o
380 APPOBJ = $(COMMONOBJ) $(OBJDIR)/ExampleClientApp.c.o
382 Client: setup $(BUILDDIR)/mDNSClientPosix
383 @echo "Embedded Standalone Client done"
385 Responder: setup $(BUILDDIR)/mDNSResponderPosix
386 @echo "Embedded Standalone Responder done"
388 ProxyResponder: setup $(BUILDDIR)/mDNSProxyResponderPosix
389 @echo "Embedded Standalone ProxyResponder done"
391 Identify: setup $(BUILDDIR)/mDNSIdentify
392 @echo "Identify done"
394 NetMonitor: setup $(BUILDDIR)/mDNSNetMonitor
395 @echo "NetMonitor done"
397 $(BUILDDIR)/mDNSClientPosix: $(APPOBJ) $(OBJDIR)/Client.c.o
400 $(BUILDDIR)/mDNSResponderPosix: $(COMMONOBJ) $(OBJDIR)/Responder.c.o
403 $(BUILDDIR)/mDNSProxyResponderPosix: $(COMMONOBJ) $(OBJDIR)/ProxyResponder.c.o
406 $(BUILDDIR)/mDNSIdentify: $(SPECIALOBJ) $(OBJDIR)/Identify.c.o
409 $(BUILDDIR)/mDNSNetMonitor: $(SPECIALOBJ) $(OBJDIR)/NetMonitor.c.o
412 #############################################################################
416 $(CC) $(CFLAGS) -c -o $@ $<
418 $(OBJDIR)/%.c.o: $(COREDIR)/%.c
419 $(CC) $(CFLAGS) -c -o $@ $<
421 $(OBJDIR)/%.c.o: $(SHAREDDIR)/%.c
422 $(CC) $(CFLAGS) -c -o $@ $<
424 $(OBJDIR)/%.c.so.o: %.c
425 $(CC) $(CFLAGS) -c -fPIC -o $@ $<
427 $(OBJDIR)/%.c.so.o: $(SHAREDDIR)/%.c
428 $(CC) $(CFLAGS) -c -fPIC -o $@ $<