1# -*- tab-width: 4 -*-
2#
3# Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8# 
9#     http://www.apache.org/licenses/LICENSE-2.0
10# 
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# This Makefile builds a .jar file and accompanying JNI support library
18# containing the DNSSD implementation for Java and support classes.
19#
20# Prior to building Java support, you must build DNSSD.dll.
21#
22# nmake with no arguments builds all production targets.
23# 'nmake DEBUG=1' to build debugging targets.
24# 'nmake clean' or 'nmake clean DEBUG=1' to delete prod/debug objects & targets
25#
26# To run nmake, you may need to set up your PATH correctly, using a script 
27# such as: "\Program Files\Microsoft Visual Studio .NET\Vc7\bin\vcvars32.bat"
28# 
29# The default location of the JDK is \javasdk. You can override this on the
30# command line (e.g. 'nmake JDK=\j2dk1.4.2_03').
31
32############################################################################
33
34COREDIR = ..\..\mDNSCore
35SHAREDDIR = ..\..\mDNSShared
36
37JDK = $(JAVA_HOME)
38
39CC = cl
40RC = rc
41LD = ld
42CP = copy
43RM = del /Q
44RMDIR = rmdir /S /Q
45JAVAC = $(JDK)\bin\javac
46JAVAH = $(JDK)\bin\javah
47JAR = $(JDK)\bin\jar
48CFLAGS_COMMON = -LD -DAUTO_CALLBACKS=0 -I. -I..\.. \
49	-I$(COREDIR) -I$(SHAREDDIR) -I$(JDK)\include -I$(JDK)\include\win32
50
51# Set up diverging paths for debug vs. prod builds
52DEBUG=0
53!if $(DEBUG) == 1
54CFLAGS_DEBUG = -Zi -DMDNS_DEBUGMSGS=2 
55OBJDIR = objects\debug
56BUILDDIR = build\debug
57INSTALLDIR = root\"Program Files"\Bonjour
58LIBDIR = ..\DLL\Win32\Debug
59!else
60CFLAGS_DEBUG = -Os -DMDNS_DEBUGMSGS=0 
61OBJDIR = objects\prod
62BUILDDIR = build\prod
63INSTALLDIR = root\"Program Files"\Bonjour
64LIBDIR = ..\DLL\Win32\Release
65!endif
66
67CFLAGS = $(CFLAGS_COMMON) $(CFLAGS_DEBUG)
68JAVACFLAGS = $(CFLAGS) $(JAVACFLAGS_OS)
69
70#############################################################################
71
72all: setup Java postbuild
73
74# 'setup' sets up the build directory structure the way we want
75setup:
76	@if not exist objects		mkdir objects
77	@if not exist build			mkdir build
78	@if not exist $(OBJDIR)		mkdir $(OBJDIR)
79	@if not exist $(BUILDDIR)	mkdir $(BUILDDIR)
80
81postbuild:
82	@if not "%RC_XBS%"=="YES" GOTO CONT
83	@if not exist "$(DSTROOT)\WINDOWS\system32\Win32"	mkdir "$(DSTROOT)\WINDOWS\system32\Win32"
84	@if not exist "$(DSTROOT)\Program Files\Bonjour\Win32"	mkdir "$(DSTROOT)\Program Files\Bonjour\Win32"
85	@copy $(BUILDDIR)\jdns_sd.dll "$(DSTROOT)\WINDOWS\system32\Win32"
86	@copy $(BUILDDIR)\dns_sd.jar  "$(DSTROOT)\Program Files\Bonjour\Win32"
87	@:CONT
88	@if not exist root					mkdir root
89	@if not exist root\"Program Files"	mkdir root\"Program Files"
90	@if not exist $(INSTALLDIR)			mkdir $(INSTALLDIR)
91	copy $(BUILDDIR)\dns_sd.jar $(INSTALLDIR)
92	copy $(BUILDDIR)\jdns_sd.dll $(INSTALLDIR)
93
94# clean removes targets and objects
95clean:
96	@if exist $(OBJDIR)		$(RMDIR) $(OBJDIR)
97	@if exist $(BUILDDIR)	$(RMDIR) $(BUILDDIR)
98
99#############################################################################
100
101# The following targets build Java wrappers for the dns-sd.h API.
102
103Java: setup $(BUILDDIR)\dns_sd.jar $(BUILDDIR)\jdns_sd.dll postbuild
104	@echo "Java wrappers done"
105
106JAVASRC	= $(SHAREDDIR)\Java
107JARCONTENTS =	$(OBJDIR)\com\apple\dnssd\DNSSDService.class \
108				$(OBJDIR)\com\apple\dnssd\DNSSDException.class \
109				$(OBJDIR)\com\apple\dnssd\DNSRecord.class \
110				$(OBJDIR)\com\apple\dnssd\TXTRecord.class \
111				$(OBJDIR)\com\apple\dnssd\DNSSDRegistration.class \
112				$(OBJDIR)\com\apple\dnssd\DNSSDRecordRegistrar.class \
113				$(OBJDIR)\com\apple\dnssd\BaseListener.class \
114				$(OBJDIR)\com\apple\dnssd\BrowseListener.class \
115				$(OBJDIR)\com\apple\dnssd\ResolveListener.class \
116				$(OBJDIR)\com\apple\dnssd\RegisterListener.class \
117				$(OBJDIR)\com\apple\dnssd\RegisterRecordListener.class \
118				$(OBJDIR)\com\apple\dnssd\QueryListener.class \
119				$(OBJDIR)\com\apple\dnssd\DomainListener.class \
120				$(OBJDIR)\com\apple\dnssd\DNSSD.class
121
122$(BUILDDIR)\dns_sd.jar: $(JARCONTENTS)
123	$(JAR) -cf $@ -C $(OBJDIR) com
124
125$(BUILDDIR)\jdns_sd.dll: $(JAVASRC)\JNISupport.c $(OBJDIR)\DNSSD.java.h $(OBJDIR)\jdns_sd.RES
126	$(CC) -Fe$@ $(JAVASRC)\JNISupport.c $(CFLAGS) -I$(OBJDIR) \
127	$(LIBDIR)\DNSSD.lib $(JDK)\lib\jvm.lib ws2_32.lib iphlpapi.lib $(OBJDIR)\jdns_sd.RES /link /NXCOMPAT /DYNAMICBASE /SAFESEH
128
129.SUFFIXES : .java
130{$(JAVASRC)}.java{$(OBJDIR)\com\apple\dnssd}.class:	
131	$(JAVAC) -d $(OBJDIR) -classpath $(OBJDIR) $<
132
133$(OBJDIR)\DNSSD.java.h: $(OBJDIR)\com\apple\dnssd\DNSSD.class
134	$(JAVAH) -classpath $(OBJDIR) -o $@ \
135		com.apple.dnssd.AppleBrowser \
136		com.apple.dnssd.AppleResolver \
137		com.apple.dnssd.AppleRegistration \
138		com.apple.dnssd.AppleQuery \
139		com.apple.dnssd.AppleService 
140
141$(OBJDIR)\jdns_sd.RES: jdns_sd.rc
142	$(RC) /fo $@ $?
143
144