]> git.saurik.com Git - apple/mdnsresponder.git/blame - mDNSPosix/Makefile
mDNSResponder-212.1.tar.gz
[apple/mdnsresponder.git] / mDNSPosix / Makefile
CommitLineData
67c8f8a1
A
1# -*- tab-width: 4 -*-
2#
7f0064bd
A
3# Copyright (c) 2002-2004, Apple Computer, Inc. All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are met:
7#
8# 1. Redistributions of source code must retain the above copyright notice,
9# this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright notice,
11# this list of conditions and the following disclaimer in the documentation
12# and/or other materials provided with the distribution.
13# 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
14# contributors may be used to endorse or promote products derived from this
15# software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8e92c31c 27#
67c8f8a1
A
28# IMPORTANT NOTE: This is a Makefile for *GNU make*
29# On some systems, a different program may be the default "make" command.
30# If "make os=xxx" gives lots of errors like "Missing dependency operator",
31# then try typing "gmake os=xxx" instead.
32#
c9b9ae52 33# $Log: Makefile,v $
32bb7e43
A
34# Revision 1.83 2009/02/02 19:44:06 cheshire
35# Use "-fwrapv" option to tell compiler that the code is written assuming that
36# signed arithmetic is implemented using the twos-complement representation
37# (this is pretty much universally true on today's processors).
38# <http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Code-Gen-Options.html>
39# Without this option, gcc may decide that because the C language
40# does not require processors to use twos-complement representation, that means
41# gcc is free to do some "creative" optimizations that don't preserve the overflow
42# behaviour of twos-complement arithmetic. See also "-fstrict-overflow":
43# <http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Optimize-Options.html>
44#
45# Revision 1.82 2009/01/12 22:48:00 cheshire
46# Don't need to include "." in the "#include" search path
47#
48# Revision 1.81 2009/01/11 03:20:06 mkrochma
49# <rdar://problem/5797526> Fixes from Igor Seleznev to get mdnsd working on Solaris
50#
51# Revision 1.80 2008/11/03 23:27:51 cheshire
52# Defined __MAC_OS_X_VERSION_MIN_REQUIRED=__MAC_OS_X_VERSION_10_4 to stop build failures on Leopard
53#
54# Revision 1.79 2008/10/24 01:59:59 mcguire
55# <rdar://problem/6257159> Build Failure: Need to stop using Jam
56#
96f69b28
A
57# Revision 1.78 2007/10/22 20:16:49 cheshire
58# Got rid of jaguar and panther from list of target platforms;
59# changed "os=tiger" to "os=x" (which works with both Tiger and Leopard)
60#
61# Revision 1.77 2007/10/22 20:04:51 cheshire
62# Need to include PlatformCommon.c.o in embedded targets
63#
67c8f8a1
A
64# Revision 1.76 2007/07/31 23:39:02 mcguire
65# Don't bail on errors in flex-generated .c files
66#
67# Revision 1.75 2006/08/24 22:41:23 herscher
68# <rdar://problem/4580067> POSIX: dnsextd_parser doesn't compile on Linux
69#
70# Revision 1.74 2006/08/14 23:07:11 cheshire
71# Added "tab-width" emacs header line
72#
73# Revision 1.73 2006/07/07 00:54:08 cheshire
74# <rdar://problem/4472013> Add Private DNS server functionality to dnsextd
75# Put intermediate files into "objects" folder instead of mDNSShared source code folder
76#
77# Revision 1.72 2006/07/05 23:53:58 cheshire
78# <rdar://problem/4472013> Add Private DNS server functionality to dnsextd
79#
80# Revision 1.71 2006/06/20 23:07:04 rpantos
81# <rdar://problem/3839132> Java needs to implement DNSServiceRegisterRecord equivalent
82#
83# Revision 1.70 2006/05/03 23:35:10 cheshire
84# Add missing dependency: NetMonitor.c textually imports mDNS.c
85#
86# Revision 1.69 2006/02/26 23:18:50 cheshire
87# <rdar://problem/4427969> FreeBSD 4 requires "-pthread" option to compile threaded code
88#
89# Revision 1.68 2006/02/26 01:36:54 cheshire
90# Rename the poorly named "LIBFLAGS" as "LINKOPTS"
91#
92# Revision 1.67 2006/02/25 23:14:29 cheshire
93# Add comment suggesting using "gmake" command
94#
95# Revision 1.66 2006/01/06 01:06:17 cheshire
96# <rdar://problem/3978979> Compile library and client programs in one pass
97#
98# Revision 1.65 2005/12/21 21:15:57 cheshire
99# Add missing dependency: Identify.c textually imports mDNS.c
100#
4aea607d
A
101# Revision 1.64 2005/10/25 23:55:47 cheshire
102# Add tiger to list of target platforms
103#
104# Revision 1.63 2005/10/11 21:30:44 cheshire
105# Add "-Wunreachable-code" (commented out for now)
106#
107# Revision 1.62 2005/06/30 21:46:55 cheshire
108# <rdar://problem/4167287> Solaris should use unix domain sockets, not loopback
109#
110# Revision 1.61 2005/06/30 20:46:05 cheshire
111# Added Makefile rule to build threadsafe object files where necessary using "-D_REENTRANT".
112#
113# Revision 1.60 2005/06/30 10:42:38 cheshire
114# Turn on "-Werror" and "-O" for better error reporting
115#
116# Revision 1.59 2005/04/14 21:07:10 rpantos
117# Bug #: 4089257, Clean build broken for Java support on POSIX
118# Submitted by: Roger Pantos
119# Reviewed by: Kiren Sekar
120#
121# Revision 1.58 2005/04/08 21:37:57 ksekar
122# <rdar://problem/3792767> get_ifi_info doesn't return IPv6 interfaces on Linux
123#
124# Revision 1.57 2005/03/17 04:02:28 cheshire
125# <rdar://problem/3986419> mDNSResponder won't compile with gcc4 on Tiger
126# Changed Makefile to link using gcc instead of libtool
127#
7cb34e5c
A
128# Revision 1.56 2005/02/02 02:25:21 cheshire
129# <rdar://problem/3980388> /var/run/mDNSResponder should be /var/run/mdnsd on Linux
130#
283ee3ff
A
131# Revision 1.55 2005/01/27 22:55:00 cheshire
132# Add "make os=tiger" target which uses gcc4 and "-Wdeclaration-after-statement"
133#
134# Revision 1.54 2004/12/17 19:33:03 cheshire
135# Add "-lresolv" for Solaris
136#
7f0064bd
A
137# Revision 1.53 2004/12/01 20:04:31 cheshire
138# Tidy up alignment
139#
140# Revision 1.52 2004/12/01 19:46:12 cheshire
141# Add install case for Suse 9 (rc*.d directories *inside* the init.d directory)
142#
143# Revision 1.51 2004/12/01 03:30:29 cheshire
144# <rdar://problem/3889346> Add Unicast DNS support to mDNSPosix
145#
146# Revision 1.50 2004/12/01 01:14:20 cheshire
147# Add $(LIBFLAGS) to cc command to build dnsextd (required for Solaris)
148#
149# Revision 1.49 2004/11/11 01:44:52 cheshire
150# Updated error message
151#
152# Revision 1.48 2004/10/06 02:22:19 cheshire
153# Changed MacRoman copyright symbol (should have been UTF-8 in any case :-) to ASCII-compatible "(c)"
154#
155# Revision 1.47 2004/10/01 22:15:54 rpantos
156# rdar://problem/3824265: Replace APSL in client lib with BSD license.
157#
158# Revision 1.46 2004/09/24 21:15:25 cheshire
159# <rdar://problem/3724985> Library "libmdns" misnamed; should be "libdns_sd"
160#
161# Revision 1.45 2004/09/22 16:23:41 cheshire
162# Modify installation for compatibility with Gentoo Linux
163# (Thanks to David Black for this information)
164#
165# Revision 1.44 2004/09/17 01:08:53 cheshire
166# Renamed mDNSClientAPI.h to mDNSEmbeddedAPI.h
167# The name "mDNSClientAPI.h" is misleading to new developers looking at this code. The interfaces
168# declared in that file are ONLY appropriate to single-address-space embedded applications.
169# For clients on general-purpose computers, the interfaces defined in dns_sd.h should be used.
170#
171# Revision 1.43 2004/09/17 00:30:11 cheshire
172# Added some '@' signs to make build output less verbose --
173# when there's too much on the screen it's easy to miss build errors and warnings
174#
175# Revision 1.42 2004/08/24 22:04:37 cheshire
176# Need to specify -lpthread for building dnsextd
177#
178# Revision 1.41 2004/08/11 00:43:26 ksekar
179# <rdar://problem/3722542>: DNS Extension daemon for DNS Update Lease
180#
181# Revision 1.40 2004/07/08 21:45:55 cheshire
182# Make nss_mdns only build on Linux. We can add it to other targets (Solaris,
183# FreeBSD, etc., as we verify them). In particular, NSS is NOT supported on
184# OS X, so including it for "os=jaguar" or "os=panther" broke those builds.
185#
186# Revision 1.39 2004/06/29 03:34:28 cheshire
187# Add 'dot-local' Name Service Switch support from Andrew White at NICTA
188#
189# Revision 1.38 2004/06/25 02:19:40 rpantos
190# And FreeBSD...
191#
192# Revision 1.37 2004/06/25 00:51:09 rpantos
193# And fix the Java build for Posix on Solaris, too.
194#
195# Revision 1.36 2004/06/25 00:26:27 rpantos
196# Changes to fix the Posix build on Solaris.
197#
198# Revision 1.35 2004/06/18 18:51:31 cheshire
199# Add (commented out) "-pedantic" for when we want to check for "mixed declarations and code" warnings
200#
8e92c31c
A
201# Revision 1.34 2004/05/25 18:29:33 cheshire
202# Move DNSServiceConstructFullName() from dnssd_clientstub.c to dnssd_clientlib.c,
203# so that it's also accessible to dnssd_clientshim.c (single address space) clients.
204#
205# Revision 1.33 2004/04/30 16:46:32 rpantos
206# Add support for building Java libraries.
207#
208# Revision 1.32 2004/04/14 23:09:29 ksekar
209# Support for TSIG signed dynamic updates.
210#
211# Revision 1.31 2004/03/15 19:07:06 cheshire
212# Fix error message
213#
214# Revision 1.30 2004/03/11 18:58:29 rpantos
215# Fix Kill /etc/rc scripts so they run at halt & reboot.
216#
217# Revision 1.29 2004/03/04 23:35:41 cheshire
218# Instead of using a dummy target to generate an error message, use "$(error text...)"
219#
220# Revision 1.28 2004/03/04 23:33:42 cheshire
221# Fixes from Alfred Perlstein for FreeBSD's benefit
222#
223# Revision 1.27 2004/02/11 21:00:21 cheshire
224# Update URL for GNU Make manual page
225#
226# Revision 1.26 2004/02/05 21:28:30 cheshire
227# Fixes so that "sudo make install" works on *BSD
228#
229# Revision 1.25 2004/02/05 20:00:22 cheshire
230# Define mdnsd's PID file to be /var/run/mdnsd.pid on Posix builds
231#
232# Revision 1.24 2004/02/05 01:00:01 rpantos
233# Fix some issues that turned up when building for FreeBSD.
234#
235# Revision 1.23 2004/02/04 01:50:54 cheshire
236# Make InstalledStartup conditional, so it automatically installs into
237# either /etc/init.d/ or /etc/rc.d/init.d/ as appropriate
238#
239# Revision 1.22 2004/01/20 01:41:21 rpantos
240# Define USES_NETLINK for Linux builds.
241#
242# Revision 1.21 2003/12/17 00:51:22 cheshire
243# Changed mDNSNetMonitor and mDNSIdentify to link the object files
244# instead of #including the "DNSCommon.c" "uDNS.c" and source files
245#
246# Revision 1.20 2003/12/13 03:05:28 ksekar
247# Bug #: <rdar://problem/3192548>: DynDNS: Unicast query of service records
248#
249# Revision 1.19 2003/12/11 19:42:13 cheshire
250# Change name "mDNSResponderd" to "mdnsd" for consistency with standard Linux (Unix) naming conventions
251#
252# Revision 1.18 2003/12/11 19:38:34 cheshire
253# Add APSL
254#
255# Revision 1.17 2003/12/11 03:16:49 rpantos
256# One more change for OS X build: make install work a little better.
257#
258# Revision 1.16 2003/12/11 03:03:51 rpantos
259# Clean up mDNSPosix so that it builds on OS X again.
260#
261# Revision 1.15 2003/12/08 20:47:02 rpantos
262# Add support for mDNSResponder on Linux.
263#
264# Revision 1.14 2003/11/14 20:59:09 cheshire
265# Clients can't use AssignDomainName macro because mDNSPlatformMemCopy is defined in mDNSPlatformFunctions.h.
7f0064bd 266# Best solution is just to combine mDNSEmbeddedAPI.h and mDNSPlatformFunctions.h into a single file.
8e92c31c 267#
c9b9ae52
A
268# Revision 1.13 2003/08/06 18:20:51 cheshire
269# Makefile cleanup
270#
271# Revision 1.12 2003/08/01 02:20:02 cheshire
272# Add mDNSIdentify tool, used to discover what version of mDNSResponder a particular host is running
273#
274# Revision 1.11 2003/07/14 18:11:54 cheshire
275# Fix stricter compiler warnings
276#
277# Revision 1.10 2003/06/18 05:47:41 cheshire
278# Enable stricter warnings on Jaguar and Panther builds
279#
280# Revision 1.9 2003/06/04 18:34:45 ksekar
281# Bug #: <rdar://problem/3218120>: mDNSPosix does not build on Panther that has socklen_t
282# Changed build targets "osx10.2" and "osx10.3" to "jaguar" and "panther".
283#
284# Revision 1.8 2003/06/04 00:23:12 ksekar
285# Bug #: <rdar://problem/3218120>: mDNSPosix does not build on Panther that has socklen_t
286# Created separate target OS's for 10.2 and 10.3.
287#
288# Revision 1.7 2003/04/16 02:11:37 cheshire
289# Remove unnecessary $(CFLAGS) from linking rules
290#
291# Revision 1.6 2003/04/04 01:37:14 cheshire
292# Added NetMonitor.c
293#
294
7f0064bd 295# This Makefile builds an mDNSResponder daemon and a libdns_sd.so shared library
8e92c31c
A
296# for Linux. It also builds several example programs for embedded systems.
297#
298# Make with no arguments to build all production targets.
299# 'make DEBUG=1' to build debugging targets.
300# 'make clean' or 'make clean DEBUG=1' to delete prod/debug objects & targets
7f0064bd 301# 'sudo make install [DEBUG=1]' to install mdnsd daemon and libdns_sd.
8e92c31c
A
302#
303# Notes:
304# $@ means "The file name of the target of the rule"
305# $< means "The name of the first prerequisite"
67c8f8a1 306# $* means "The stem with which an implicit rule matches"
8e92c31c
A
307# $+ means "The names of all the prerequisites, with spaces between them, exactly as given"
308# For more magic automatic variables, see
67c8f8a1 309# <http://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html>
8e92c31c
A
310
311#############################################################################
312
313LIBVERS = 1
314
315COREDIR = ../mDNSCore
32bb7e43 316SHAREDDIR ?= ../mDNSShared
8e92c31c
A
317JDK = /usr/jdk
318
7f0064bd 319CC = @cc
67c8f8a1
A
320BISON = @bison
321FLEX = @flex
7f0064bd 322LD = ld -shared
8e92c31c
A
323CP = cp
324RM = rm
325LN = ln -s -f
32bb7e43 326CFLAGS_COMMON = -I$(COREDIR) -I$(SHAREDDIR) -I$(OBJDIR) -fwrapv -W -Wall -DPID_FILE=\"/var/run/mdnsd.pid\" -DMDNS_UDS_SERVERPATH=\"/var/run/mdnsd\"
67c8f8a1
A
327CFLAGS_PTHREAD =
328LINKOPTS =
329LINKOPTS_PTHREAD = -lpthread
8e92c31c 330LDSUFFIX = so
7f0064bd 331JAVACFLAGS_OS = -fPIC -shared -ldns_sd
c9b9ae52 332
8e92c31c
A
333# Set up diverging paths for debug vs. prod builds
334DEBUG=0
335ifeq ($(DEBUG),1)
336CFLAGS_DEBUG = -g -DMDNS_DEBUGMSGS=2
337OBJDIR = objects/debug
338BUILDDIR = build/debug
339STRIP = echo
340else
4aea607d
A
341# We use -Os for two reasons:
342# 1. We want to make small binaries, suitable for putting into hardware devices
343# 2. Some of the code analysis warnings only work when some form of optimization is enabled
344CFLAGS_DEBUG = -Os -DMDNS_DEBUGMSGS=0
32bb7e43
A
345OBJDIR ?= objects/prod
346BUILDDIR ?= build/prod
8e92c31c
A
347STRIP = strip -S
348endif
349
350# Configure per-OS peculiarities
c9b9ae52 351ifeq ($(os),solaris)
32bb7e43 352CFLAGS_DEBUG = -O0 -DMDNS_DEBUGMSGS=0
7f0064bd 353CFLAGS_OS = -DNOT_HAVE_DAEMON -DNOT_HAVE_SA_LEN -DNOT_HAVE_SOCKLEN_T -DNOT_HAVE_IF_NAMETOINDEX \
32bb7e43 354 -DLOG_PERROR=0 -D_XPG4_2 -D__EXTENSIONS__ -DHAVE_BROKEN_RECVIF_NAME -DTARGET_OS_SOLARIS
7f0064bd
A
355CC = gcc
356LD = gcc -shared
67c8f8a1 357LINKOPTS = -lsocket -lnsl -lresolv
7f0064bd
A
358JAVACFLAGS_OS += -I$(JDK)/include/solaris
359ifneq ($(DEBUG),1)
360STRIP = strip
361endif
c9b9ae52 362else
7f0064bd 363
c9b9ae52 364ifeq ($(os),linux)
67c8f8a1
A
365CFLAGS_OS = -DNOT_HAVE_SA_LEN -DUSES_NETLINK -DHAVE_LINUX -DTARGET_OS_LINUX
366FLEXFLAGS_OS = -l
8e92c31c 367JAVACFLAGS_OS += -I$(JDK)/include/linux
7f0064bd
A
368OPTIONALTARG = nss_mdns
369OPTINSTALL = InstalledNSS
c9b9ae52 370else
7f0064bd 371
c9b9ae52
A
372ifeq ($(os),netbsd)
373CFLAGS_OS =
8e92c31c 374LDCONFIG = ldconfig
c9b9ae52 375else
7f0064bd 376
c9b9ae52 377ifeq ($(os),freebsd)
8e92c31c
A
378# If not already defined, set LOCALBASE to /usr/local
379# FreeBSD requires the startup script to end in ".sh"
380LOCALBASE?=/usr/local
381INSTBASE=$(LOCALBASE)
382STARTUPSCRIPTNAME=mdns.sh
c9b9ae52 383CFLAGS_OS =
67c8f8a1
A
384# FreeBSD 4 requires threaded code to be compiled and linked using the "-pthread" option,
385# and requires that the "-lpthread" link option NOT be used
386# This appies only to FreeBSD -- "man cc" on FreeBSD says:
387# FreeBSD SPECIFIC OPTIONS
388# -pthread
389# Link a user-threaded process against libc_r instead of libc.
390CFLAGS_PTHREAD = -pthread -D_THREAD_SAFE
391LINKOPTS_PTHREAD = -pthread
7f0064bd 392JAVACFLAGS_OS += -I$(JDK)/include/freebsd
8e92c31c 393LDCONFIG = ldconfig
c9b9ae52 394else
7f0064bd 395
c9b9ae52
A
396ifeq ($(os),openbsd)
397CFLAGS_OS = -DHAVE_BROKEN_RECVDSTADDR
8e92c31c 398LDCONFIG = ldconfig
c9b9ae52 399else
7f0064bd 400
96f69b28 401ifeq ($(os),x)
32bb7e43
A
402# We have to define __MAC_OS_X_VERSION_MIN_REQUIRED=__MAC_OS_X_VERSION_10_4 or on Leopard
403# we get build failures: ‘daemon’ is deprecated (declared at /usr/include/stdlib.h:283)
404CFLAGS_OS = -DHAVE_IPV6 -no-cpp-precomp -Werror -Wdeclaration-after-statement \
405 -D__MAC_OS_X_VERSION_MIN_REQUIRED=__MAC_OS_X_VERSION_10_4 #-Wunreachable-code
283ee3ff 406CC = @gcc-4.0
4aea607d 407LD = $(CC) -dynamiclib
67c8f8a1 408LINKOPTS = -lSystem
283ee3ff
A
409LDSUFFIX = dylib
410JDK = /System/Library/Frameworks/JavaVM.framework/Home
411JAVACFLAGS_OS = -dynamiclib -I/System/Library/Frameworks/JavaVM.framework/Headers -framework JavaVM
412else
413
96f69b28
A
414$(error ERROR: Must specify target OS on command-line, e.g. "make os=x [target]".\
415Supported operating systems include: x, linux, netbsd, freebsd, openbsd, solaris)
c9b9ae52
A
416endif
417endif
418endif
419endif
420endif
283ee3ff 421endif
c9b9ae52 422
7f0064bd
A
423NSSLIBNAME := libnss_mdns
424NSSVERSION := 0.2
425NSSLIBFILE := $(NSSLIBNAME)-$(NSSVERSION).so
426NSSLINKNAME := $(NSSLIBNAME).so.2
427NSSINSTPATH := /lib
428
8e92c31c
A
429# If not otherwise defined, we install into /usr/lib and /usr/include
430# and our startup script is called mdns (e.g. /etc/init.d/mdns)
431INSTBASE?=/usr
432STARTUPSCRIPTNAME?=mdns
433
434ifeq ($(HAVE_IPV6),1)
435CFLAGS_OS += -DHAVE_IPV6=1
436else
437ifeq ($(HAVE_IPV6),0)
438CFLAGS_OS += -DHAVE_IPV6=0
439endif
440endif
c9b9ae52 441
7f0064bd
A
442# If directory /usr/share/man exists, then we install man pages into that, else /usr/man
443ifeq ($(wildcard /usr/share/man), /usr/share/man)
444MANPATH := /usr/share/man
445else
446MANPATH := /usr/man
447endif
448
449# If directories /etc/init.d/rc*.d exist, then we install into that (Suse)
450ifeq ($(wildcard /etc/init.d/rc2.d/), /etc/init.d/rc2.d/)
451STARTUPSCRIPTDIR = /etc/init.d
452RUNLEVELSCRIPTSDIR = /etc/init.d
453else
454# else if directory /etc/rc.d/init.d/ exists, then we install into that (old Linux)
8e92c31c
A
455ifeq ($(wildcard /etc/rc.d/init.d/), /etc/rc.d/init.d/)
456STARTUPSCRIPTDIR = /etc/rc.d/init.d
457RUNLEVELSCRIPTSDIR = /etc/rc.d
458else
459# else if directory /etc/init.d/ exists, then we install into that (new Linux)
460ifeq ($(wildcard /etc/init.d/), /etc/init.d/)
461STARTUPSCRIPTDIR = /etc/init.d
462RUNLEVELSCRIPTSDIR = /etc
463else
464# else install into /etc/rc.d/ (*BSD)
465STARTUPSCRIPTDIR = $(INSTBASE)/etc/rc.d
466endif
467endif
7f0064bd 468endif
c9b9ae52 469
8e92c31c 470CFLAGS = $(CFLAGS_COMMON) $(CFLAGS_OS) $(CFLAGS_DEBUG)
c9b9ae52 471
8e92c31c
A
472#############################################################################
473
67c8f8a1 474all: setup Daemon libdns_sd Clients SAClient SAResponder SAProxyResponder Identify NetMonitor dnsextd $(OPTIONALTARG)
8e92c31c 475
67c8f8a1 476install: setup InstalledDaemon InstalledStartup InstalledLib InstalledManPages InstalledClients $(OPTINSTALL)
8e92c31c
A
477
478# 'setup' sets up the build directory structure the way we want
c9b9ae52 479setup:
32bb7e43
A
480 @if test ! -d $(OBJDIR) ; then mkdir -p $(OBJDIR) ; fi
481 @if test ! -d $(BUILDDIR) ; then mkdir -p $(BUILDDIR) ; fi
8e92c31c
A
482
483# clean removes targets and objects
484clean:
67c8f8a1
A
485 @if test -d $(OBJDIR) ; then rm -r $(OBJDIR) ; fi
486 @if test -d $(BUILDDIR) ; then rm -r $(BUILDDIR) ; fi
487 @$(MAKE) -C ../Clients clean
8e92c31c
A
488
489#############################################################################
490
491# daemon target builds the daemon
492DAEMONOBJS = $(OBJDIR)/PosixDaemon.c.o $(OBJDIR)/mDNSPosix.c.o $(OBJDIR)/mDNSUNP.c.o $(OBJDIR)/mDNS.c.o \
493 $(OBJDIR)/DNSDigest.c.o $(OBJDIR)/uDNS.c.o $(OBJDIR)/DNSCommon.c.o $(OBJDIR)/uds_daemon.c.o \
7f0064bd 494 $(OBJDIR)/mDNSDebug.c.o $(OBJDIR)/dnssd_ipc.c.o $(OBJDIR)/GenLinkedList.c.o $(OBJDIR)/PlatformCommon.c.o
8e92c31c 495
67c8f8a1
A
496# dnsextd target build dnsextd
497DNSEXTDOBJ = $(OBJDIR)/mDNSPosix.c.o $(OBJDIR)/mDNSUNP.c.o $(OBJDIR)/mDNSDebug.c.o $(OBJDIR)/GenLinkedList.c.o $(OBJDIR)/DNSDigest.c.o \
498 $(OBJDIR)/DNSCommon.c.o $(OBJDIR)/PlatformCommon.c.o $(OBJDIR)/dnsextd_parser.y.o $(OBJDIR)/dnsextd_lexer.l.o
499
8e92c31c
A
500Daemon: setup $(BUILDDIR)/mdnsd
501 @echo "Responder daemon done"
502
503$(BUILDDIR)/mdnsd: $(DAEMONOBJS)
67c8f8a1 504 $(CC) -o $@ $+ $(LINKOPTS)
7f0064bd 505 @$(STRIP) $@
8e92c31c 506
7f0064bd
A
507# libdns_sd target builds the client library
508libdns_sd: setup $(BUILDDIR)/libdns_sd.$(LDSUFFIX)
8e92c31c
A
509 @echo "Client library done"
510
7f0064bd
A
511CLIENTLIBOBJS = $(OBJDIR)/dnssd_clientlib.c.so.o $(OBJDIR)/dnssd_clientstub.c.so.o $(OBJDIR)/dnssd_ipc.c.so.o
512
513$(BUILDDIR)/libdns_sd.$(LDSUFFIX): $(CLIENTLIBOBJS)
67c8f8a1 514 @$(LD) $(LINKOPTS) -o $@ $+
7f0064bd
A
515 @$(STRIP) $@
516
67c8f8a1
A
517Clients: setup libdns_sd ../Clients/build/dns-sd
518 @echo "Clients done"
519
520../Clients/build/dns-sd:
521 @$(MAKE) -C ../Clients
522
7f0064bd
A
523# nss_mdns target builds the Name Service Switch module
524nss_mdns: setup $(BUILDDIR)/$(NSSLIBFILE)
525 @echo "Name Service Switch module done"
526
527$(BUILDDIR)/$(NSSLIBFILE): $(CLIENTLIBOBJS) $(OBJDIR)/nss_mdns.c.so.o
67c8f8a1 528 @$(LD) $(LINKOPTS) -o $@ $+
7f0064bd 529 @$(STRIP) $@
8e92c31c
A
530
531#############################################################################
532
533# The Install targets place built stuff in their proper places
534InstalledDaemon: $(INSTBASE)/sbin/mdnsd
7f0064bd 535 @echo $+ " installed"
8e92c31c 536
7f0064bd
A
537InstalledLib: $(INSTBASE)/lib/libdns_sd.$(LDSUFFIX).$(LIBVERS) $(INSTBASE)/include/dns_sd.h
538 @echo $+ " installed"
8e92c31c
A
539
540InstalledStartup: $(STARTUPSCRIPTDIR)/$(STARTUPSCRIPTNAME)
7f0064bd
A
541 @echo $+ " installed"
542
67c8f8a1 543InstalledManPages: $(MANPATH)/man8/mdnsd.8
4aea607d
A
544 @echo $+ " installed"
545
67c8f8a1 546InstalledClients: $(INSTBASE)/bin/dns-sd
7f0064bd 547 @echo $+ " installed"
8e92c31c 548
67c8f8a1
A
549InstalledNSS: $(NSSINSTPATH)/$(NSSLINKNAME) /etc/nss_mdns.conf $(MANPATH)/man5/nss_mdns.conf.5 $(MANPATH)/man8/libnss_mdns.8
550 @echo $+ " installed"
551
552# Note: If daemon already installed, we make sure it's stopped before overwriting it
8e92c31c 553$(INSTBASE)/sbin/mdnsd: $(BUILDDIR)/mdnsd
67c8f8a1 554 @if test -x $@; then $(STARTUPSCRIPTDIR)/$(STARTUPSCRIPTNAME) stop; fi
8e92c31c
A
555 $(CP) $< $@
556
7f0064bd 557$(INSTBASE)/lib/libdns_sd.$(LDSUFFIX).$(LIBVERS): $(BUILDDIR)/libdns_sd.$(LDSUFFIX)
8e92c31c 558 $(CP) $< $@
7f0064bd 559 $(LN) $@ $(INSTBASE)/lib/libdns_sd.$(LDSUFFIX)
8e92c31c
A
560ifdef LDCONFIG
561 # -m means 'merge into existing database', -R means 'rescan directories'
562 $(LDCONFIG) -mR
563endif
564
565$(INSTBASE)/include/dns_sd.h: $(SHAREDDIR)/dns_sd.h
566 $(CP) $< $@
567
67c8f8a1
A
568# We make this target dependent on $(INSTBASE)/sbin/mdnsd because we need to ensure
569# that the daemon is installed *before* we try to execute the command to start it.
570$(STARTUPSCRIPTDIR)/$(STARTUPSCRIPTNAME): mdnsd.sh $(STARTUPSCRIPTDIR) $(INSTBASE)/sbin/mdnsd
8e92c31c
A
571 $(CP) $< $@
572 chmod ugo+x $@
67c8f8a1 573 $@ start
8e92c31c 574ifdef RUNLEVELSCRIPTSDIR
7f0064bd
A
575ifeq ($(wildcard $(RUNLEVELSCRIPTSDIR)/runlevels/default), $(RUNLEVELSCRIPTSDIR)/runlevels/default)
576 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/runlevels/default/mdns
577else
8e92c31c
A
578 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/rc2.d/S52mdns
579 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/rc3.d/S52mdns
580 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/rc4.d/S52mdns
581 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/rc5.d/S52mdns
582 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/rc0.d/K16mdns
583 $(LN) $@ $(RUNLEVELSCRIPTSDIR)/rc6.d/K16mdns
584endif
7f0064bd
A
585endif
586
67c8f8a1
A
587$(MANPATH)/man5/%.5: %.5
588 cp $< $@
589 chmod 444 $@
590
591$(MANPATH)/man8/%.8: %.8
592 cp $< $@
593 chmod 444 $@
594
595$(MANPATH)/man8/mdnsd.8: $(SHAREDDIR)/mDNSResponder.8
596 cp $< $@
597 chmod 444 $@
598
599$(INSTBASE)/bin/dns-sd: ../Clients/build/dns-sd
600 $(CP) $< $@
601
7f0064bd
A
602$(NSSINSTPATH)/$(NSSLINKNAME): $(NSSINSTPATH)/$(NSSLIBFILE)
603 $(LN) $< $@
604 ldconfig
605
606$(NSSINSTPATH)/$(NSSLIBFILE): $(BUILDDIR)/$(NSSLIBFILE)
607 $(CP) $< $@
608 chmod 444 $@
609
610/etc/nss_mdns.conf: nss_mdns.conf
611 $(CP) $< $@
612 chmod 444 $@
613 # Check the nsswitch.conf file.
614 # If 'mdns' does not already appear on the "hosts:" line, then add it right before 'dns'
615 cp -f /etc/nsswitch.conf /etc/nsswitch.conf.pre-mdns
616 sed -e '/mdns/!s/^\(hosts:.*\)dns\(.*\)/\1mdns dns\2/' /etc/nsswitch.conf.pre-mdns > /etc/nsswitch.conf
617
8e92c31c 618#############################################################################
c9b9ae52 619
8e92c31c 620# The following targets build Java wrappers for the dns-sd.h API.
32bb7e43 621# Note that the JavaForXcode targets are used when building the project for OS X using Xcode
c9b9ae52 622
8e92c31c
A
623JAVAC = $(JDK)/bin/javac
624JAVAH = $(JDK)/bin/javah
625JAVADOC = $(JDK)/bin/javadoc
626JAR = $(JDK)/bin/jar
627JAVACFLAGS = $(CFLAGS) $(JAVACFLAGS_OS) -I$(JDK)/include
c9b9ae52 628
32bb7e43
A
629JavaForXcode_: setup $(BUILDDIR)/dns_sd.jar $(PROJECT_DERIVED_FILE_DIR)/DNSSD.java.h
630 @echo $@ done
631
632$(PROJECT_DERIVED_FILE_DIR)/DNSSD.java.h: $(OBJDIR)/DNSSD.java.h
633 @if test ! -d $(PROJECT_DERIVED_FILE_DIR) ; then mkdir -p $(PROJECT_DERIVED_FILE_DIR) ; fi
634 $(CP) $< $@
635
636JavaForXcode_clean:
637 @if test -d $(OBJDIR) ; then rm -r $(OBJDIR) ; fi
638 @if test -f $(PROJECT_DERIVED_FILE_DIR)/DNSSD.java.h ; then $(RM) $(PROJECT_DERIVED_FILE_DIR)/DNSSD.java.h ; fi
639 @if test -f $(BUILDDIR)/dns_sd.jar ; then $(RM) $(BUILDDIR)/dns_sd.jar ; fi
640 @echo $@ done
641
642JavaForXcode_installhdrs:
643 @echo $@ NOOP
644
645JavaForXcode_install: JavaForXcode_ $(DSTROOT)/$(SYSTEM_LIBRARY_DIR)/Java/Extensions/dns_sd.jar
646 @echo $@ done
647
648$(DSTROOT)/$(SYSTEM_LIBRARY_DIR)/Java/Extensions/dns_sd.jar: $(BUILDDIR)/dns_sd.jar
649 @if test ! -d $(DSTROOT)/$(SYSTEM_LIBRARY_DIR)/Java/Extensions ; then mkdir -p $(DSTROOT)/$(SYSTEM_LIBRARY_DIR)/Java/Extensions ; fi
650 $(CP) $< $@
651
8e92c31c
A
652Java: setup $(BUILDDIR)/dns_sd.jar $(BUILDDIR)/libjdns_sd.$(LDSUFFIX)
653 @echo "Java wrappers done"
654
655JAVASRC = $(SHAREDDIR)/Java
656JARCONTENTS = $(OBJDIR)/com/apple/dnssd/DNSSDService.class \
05292456 657 $(OBJDIR)/com/apple/dnssd/DNSSDException.class \
4aea607d 658 $(OBJDIR)/com/apple/dnssd/DNSRecord.class \
8e92c31c
A
659 $(OBJDIR)/com/apple/dnssd/TXTRecord.class \
660 $(OBJDIR)/com/apple/dnssd/DNSSDRegistration.class \
661 $(OBJDIR)/com/apple/dnssd/BaseListener.class \
662 $(OBJDIR)/com/apple/dnssd/BrowseListener.class \
663 $(OBJDIR)/com/apple/dnssd/ResolveListener.class \
664 $(OBJDIR)/com/apple/dnssd/RegisterListener.class \
665 $(OBJDIR)/com/apple/dnssd/QueryListener.class \
666 $(OBJDIR)/com/apple/dnssd/DomainListener.class \
67c8f8a1
A
667 $(OBJDIR)/com/apple/dnssd/RegisterRecordListener.class \
668 $(OBJDIR)/com/apple/dnssd/DNSSDRecordRegistrar.class \
8e92c31c
A
669 $(OBJDIR)/com/apple/dnssd/DNSSD.class
670
67c8f8a1 671$(BUILDDIR)/dns_sd.jar: $(JARCONTENTS) setup
8e92c31c
A
672 $(JAR) -cf $@ -C $(OBJDIR) com
673
67c8f8a1
A
674$(BUILDDIR)/libjdns_sd.$(LDSUFFIX): $(JAVASRC)/JNISupport.c $(OBJDIR)/DNSSD.java.h setup libdns_sd
675 $(CC) -o $@ $< $(JAVACFLAGS) -I$(OBJDIR) -L$(BUILDDIR)
8e92c31c
A
676
677$(OBJDIR)/com/apple/dnssd/%.class: $(JAVASRC)/%.java
678 $(JAVAC) -d $(OBJDIR) -classpath $(OBJDIR) $<
679
680$(OBJDIR)/DNSSD.java.h: $(OBJDIR)/com/apple/dnssd/DNSSD.class
681 $(JAVAH) -force -classpath $(OBJDIR) -o $@ \
682 com.apple.dnssd.AppleDNSSD \
683 com.apple.dnssd.AppleBrowser \
684 com.apple.dnssd.AppleResolver \
685 com.apple.dnssd.AppleRegistration \
686 com.apple.dnssd.AppleQuery \
687 com.apple.dnssd.AppleDomainEnum \
32bb7e43
A
688 com.apple.dnssd.AppleService \
689 com.apple.dnssd.AppleDNSRecord \
690 com.apple.dnssd.AppleRecordRegistrar
8e92c31c
A
691
692#############################################################################
693
694# The following target builds documentation for the Java wrappers.
695
67c8f8a1 696JavaDoc: Java setup
8e92c31c
A
697 $(JAVADOC) $(JAVASRC)/*.java -classpath $(OBJDIR) -d $(BUILDDIR) -public
698
699#############################################################################
700
701# The following targets build embedded example programs
96f69b28
A
702SPECIALOBJ = $(OBJDIR)/mDNSPosix.c.o $(OBJDIR)/mDNSUNP.c.o $(OBJDIR)/mDNSDebug.c.o $(OBJDIR)/GenLinkedList.c.o \
703 $(OBJDIR)/DNSDigest.c.o $(OBJDIR)/uDNS.c.o $(OBJDIR)/DNSCommon.c.o $(OBJDIR)/PlatformCommon.c.o
8e92c31c
A
704COMMONOBJ = $(SPECIALOBJ) $(OBJDIR)/mDNS.c.o
705APPOBJ = $(COMMONOBJ) $(OBJDIR)/ExampleClientApp.c.o
706
67c8f8a1 707SAClient: setup $(BUILDDIR)/mDNSClientPosix
8e92c31c
A
708 @echo "Embedded Standalone Client done"
709
67c8f8a1 710SAResponder: setup $(BUILDDIR)/mDNSResponderPosix
8e92c31c
A
711 @echo "Embedded Standalone Responder done"
712
67c8f8a1 713SAProxyResponder: setup $(BUILDDIR)/mDNSProxyResponderPosix
8e92c31c
A
714 @echo "Embedded Standalone ProxyResponder done"
715
716Identify: setup $(BUILDDIR)/mDNSIdentify
c9b9ae52
A
717 @echo "Identify done"
718
8e92c31c 719NetMonitor: setup $(BUILDDIR)/mDNSNetMonitor
c9b9ae52
A
720 @echo "NetMonitor done"
721
7f0064bd
A
722dnsextd: setup $(BUILDDIR)/dnsextd
723 @echo "dnsextd done"
724
8e92c31c 725$(BUILDDIR)/mDNSClientPosix: $(APPOBJ) $(OBJDIR)/Client.c.o
67c8f8a1 726 $(CC) $+ -o $@ $(LINKOPTS)
c9b9ae52 727
8e92c31c 728$(BUILDDIR)/mDNSResponderPosix: $(COMMONOBJ) $(OBJDIR)/Responder.c.o
67c8f8a1 729 $(CC) $+ -o $@ $(LINKOPTS)
c9b9ae52 730
8e92c31c 731$(BUILDDIR)/mDNSProxyResponderPosix: $(COMMONOBJ) $(OBJDIR)/ProxyResponder.c.o
67c8f8a1 732 $(CC) $+ -o $@ $(LINKOPTS)
c9b9ae52 733
8e92c31c 734$(BUILDDIR)/mDNSIdentify: $(SPECIALOBJ) $(OBJDIR)/Identify.c.o
67c8f8a1
A
735 $(CC) $+ -o $@ $(LINKOPTS)
736
737$(OBJDIR)/Identify.c.o: $(COREDIR)/mDNS.c # Note: Identify.c textually imports mDNS.c
4aea607d 738
8e92c31c 739$(BUILDDIR)/mDNSNetMonitor: $(SPECIALOBJ) $(OBJDIR)/NetMonitor.c.o
67c8f8a1
A
740 $(CC) $+ -o $@ $(LINKOPTS)
741
742$(OBJDIR)/NetMonitor.c.o: $(COREDIR)/mDNS.c # Note: NetMonitor.c textually imports mDNS.c
7f0064bd 743
67c8f8a1
A
744$(BUILDDIR)/dnsextd: $(DNSEXTDOBJ) $(OBJDIR)/dnsextd.c.threadsafe.o
745 $(CC) $+ -o $@ $(LINKOPTS) $(LINKOPTS_PTHREAD)
c9b9ae52 746
8e92c31c 747#############################################################################
c9b9ae52 748
8e92c31c
A
749# Implicit rules
750$(OBJDIR)/%.c.o: %.c
751 $(CC) $(CFLAGS) -c -o $@ $<
c9b9ae52 752
8e92c31c
A
753$(OBJDIR)/%.c.o: $(COREDIR)/%.c
754 $(CC) $(CFLAGS) -c -o $@ $<
755
756$(OBJDIR)/%.c.o: $(SHAREDDIR)/%.c
757 $(CC) $(CFLAGS) -c -o $@ $<
758
4aea607d 759$(OBJDIR)/%.c.threadsafe.o: %.c
67c8f8a1
A
760 $(CC) $(CFLAGS) $(CFLAGS_PTHREAD) -D_REENTRANT -c -o $@ $<
761
762$(OBJDIR)/%.c.threadsafe.o: $(SHAREDDIR)/%.c
763 $(CC) $(CFLAGS) $(CFLAGS_PTHREAD) -D_REENTRANT -c -o $@ $<
4aea607d 764
8e92c31c
A
765$(OBJDIR)/%.c.so.o: %.c
766 $(CC) $(CFLAGS) -c -fPIC -o $@ $<
767
768$(OBJDIR)/%.c.so.o: $(SHAREDDIR)/%.c
769 $(CC) $(CFLAGS) -c -fPIC -o $@ $<
67c8f8a1
A
770
771$(OBJDIR)/%.y.o: $(SHAREDDIR)/%.y
772 $(BISON) -o $(OBJDIR)/$*.c -d $<
773 $(CC) $(CFLAGS) -c -o $@ $(OBJDIR)/$*.c
774
775$(OBJDIR)/%.l.o: $(SHAREDDIR)/%.l
776 $(FLEX) $(FLEXFLAGS_OS) -i -o$(OBJDIR)/$*.l.c $<
777 $(CC) $(CFLAGS) -Wno-error -c -o $@ $(OBJDIR)/$*.l.c