3 # Copyright (c) 2002-2019 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
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.
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.
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.
33 # This Makefile builds an mDNSResponder daemon and a libdns_sd.so shared library
34 # for Linux. It also builds several example programs for embedded systems.
36 # Make with no arguments to build all production targets.
37 # 'make DEBUG=1' to build debugging targets.
38 # 'make clean' or 'make clean DEBUG=1' to delete prod/debug objects & targets
39 # 'sudo make install [DEBUG=1]' to install mdnsd daemon and libdns_sd.
42 # $@ means "The file name of the target of the rule"
43 # $< means "The name of the first prerequisite"
44 # $* means "The stem with which an implicit rule matches"
45 # $+ means "The names of all the prerequisites, with spaces between them, exactly as given"
46 # For more magic automatic variables, see
47 # <http://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html>
49 #############################################################################
54 SHAREDDIR ?= ../mDNSShared
58 SYSTEM := $(shell uname -s)
59 ifeq ($(SYSTEM), Darwin)
61 else ifeq ($(SYSTEM), Linux)
74 CFLAGS_COMMON = -I$(COREDIR) -I$(SHAREDDIR) -I$(DSODIR) -I$(PROXYDIR) -I$(OBJDIR) -fwrapv -W -Wall -DPID_FILE=\"/var/run/mdnsd.pid\" -DMDNS_UDS_SERVERPATH=\"/var/run/mdnsd\"
77 LINKOPTS_PTHREAD = -lpthread
79 JAVACFLAGS_OS = -fPIC -shared -ldns_sd
81 ifeq "$(OPEN_SOURCE)" "1"
82 CFLAGS_OPEN_SOURCE=-D__OPEN_SOURCE__
87 # Set up diverging paths for debug vs. prod builds
89 CFLAGS_DEBUGGING = -g -DMDNS_DEBUGMSGS=2
90 OBJDIR = objects/debug
91 BUILDDIR = build/debug
94 ifeq "$(DEBUGSYMS)" "1"
95 CFLAGS_DEBUGGING = -g -DMDNS_DEBUGMSGS=0
100 # We use -Os for two reasons:
101 # 1. We want to make small binaries, suitable for putting into hardware devices
102 # 2. Some of the code analysis warnings only work when some form of optimization is enabled
103 CFLAGS_DEBUGGING = -g -DMDNS_DEBUGMSGS=0
104 OBJDIR ?= objects/prod
105 BUILDDIR ?= build/prod
110 # Configure per-OS peculiarities
112 CFLAGS_DEBUGGING = -O0 -DMDNS_DEBUGMSGS=0
113 CFLAGS_OS = -DNOT_HAVE_DAEMON -DNOT_HAVE_SA_LEN -DNOT_HAVE_SOCKLEN_T -DNOT_HAVE_IF_NAMETOINDEX \
114 -DLOG_PERROR=0 -D_XPG4_2 -D__EXTENSIONS__ -DHAVE_BROKEN_RECVIF_NAME -DTARGET_OS_SOLARIS
118 LINKOPTS = -lsocket -lnsl -lresolv
119 JAVACFLAGS_OS += -I$(JDK)/include/solaris
125 # any target that contains the string "linux"
126 ifeq ($(findstring linux,$(os)),linux)
127 CFLAGS_OS = -D_GNU_SOURCE -DHAVE_IPV6 -DNOT_HAVE_SA_LEN -DUSES_NETLINK -DHAVE_LINUX -DTARGET_OS_LINUX -ftabstop=4
131 JAVACFLAGS_OS += -I$(JDK)/include/linux
133 # uClibc does not support Name Service Switch
134 ifneq ($(os),linux-uclibc)
135 OPTIONALTARG = nss_mdns
136 OPTINSTALL = InstalledNSS
146 # If not already defined, set LOCALBASE to /usr/local
147 LOCALBASE?=/usr/local
148 INSTBASE=$(LOCALBASE)
149 CFLAGS_OS = -DHAVE_IPV6
150 # FreeBSD 4 requires threaded code to be compiled and linked using the "-pthread" option,
151 # and requires that the "-lpthread" link option NOT be used
152 # This appies only to FreeBSD -- "man cc" on FreeBSD says:
153 # FreeBSD SPECIFIC OPTIONS
155 # Link a user-threaded process against libc_r instead of libc.
156 CFLAGS_PTHREAD = -pthread -D_THREAD_SAFE
157 LINKOPTS_PTHREAD = -pthread
158 JAVACFLAGS_OS += -I$(JDK)/include/freebsd
163 CFLAGS_OS = -DHAVE_BROKEN_RECVDSTADDR
168 # We have to define __MAC_OS_X_VERSION_MIN_REQUIRED=__MAC_OS_X_VERSION_10_4 or on Leopard
169 # we get build failures: ‘daemon’ is deprecated (declared at /usr/include/stdlib.h:283)
170 CFLAGS_OS = -DHAVE_IPV6 -no-cpp-precomp -Werror -Wdeclaration-after-statement \
171 -D__MAC_OS_X_VERSION_MIN_REQUIRED=__MAC_OS_X_VERSION_10_4 \
172 -DHAVE_STRLCPY=1 -DTARGET_OS_MAC \
173 -D__APPLE_USE_RFC_2292 #-Wunreachable-code
179 JDK = /System/Library/Frameworks/JavaVM.framework/Home
180 JAVACFLAGS_OS = -dynamiclib -I/System/Library/Frameworks/JavaVM.framework/Headers -framework JavaVM
181 OPTIONALTARG = dnsextd
184 $(error ERROR: Must specify target OS on command-line, e.g. "make os=x [target]".\
185 Supported operating systems include: x, linux, linux-uclibc, netbsd, freebsd, openbsd, solaris)
193 NSSLIBNAME := libnss_mdns
195 NSSLIBFILE := $(NSSLIBNAME)-$(NSSVERSION).so
196 NSSLINKNAME := $(NSSLIBNAME).so.2
199 # If not otherwise defined, we install into /usr/lib and /usr/include
200 # and our startup script is called mdns (e.g. /etc/init.d/mdns)
203 STARTUPSCRIPTNAME?=mdns
205 ifeq ($(HAVE_IPV6),1)
206 CFLAGS_OS += -DHAVE_IPV6=1
208 ifeq ($(HAVE_IPV6),0)
209 CFLAGS_OS += -DHAVE_IPV6=0
213 # If directory /usr/share/man exists, then we install man pages into that, else /usr/man
214 ifeq ($(wildcard /usr/share/man), /usr/share/man)
215 MANPATH := /usr/share/man
220 # If directories /etc/init.d/rc*.d exist, then we install into that (Suse)
221 ifeq ($(wildcard /etc/init.d/rc2.d/), /etc/init.d/rc2.d/)
222 STARTUPSCRIPTDIR = /etc/init.d
223 RUNLEVELSCRIPTSDIR = /etc/init.d