1###################################################################
2#
3## Makefile for building GeoIP stuff (NetWare version - gnu make)
4## To build the binaries you need awk, GNU make and gcc / nlmconv
5## or Metrowerks CodeWarrior CommandlineTools.  
6## Usage: make -f Makefile.netware [all|dist|clean|distclean]
7##
8## hacked by: Guenter Knauf
9#
10###################################################################
11
12# Edit the path below to point to the base of your Novell NDK.
13ifndef NDKBASE
14NDKBASE	= c:/novell
15endif
16
17# Edit the path below to point to your zlib sources and libs.
18ifndef ZLIBSDK
19ZLIBSDK = d:/projects/cw/zlib-1.2.3
20endif
21
22ifndef DISTDIR
23DISTDIR	= GeoIP-$(GEOIP_VERSION_STR)-bin-nw
24endif
25ARCHIVE	= $(DISTDIR).zip
26
27# Edit the vars below to change NLM target settings.
28TARGETS	:= $(patsubst apps/%.c,%.nlm,$(wildcard apps/*.c))
29DESCR	= $(subst .def,,$(notdir $@)) $(GEOIP_VERSION_STR)
30COMPANY	= MaxMind LLC
31COPYR	= Copyright (C) 2003-2006 MaxMind LLC  All Rights Reserved.
32WWWURL	= http://www.maxmind.com/app/c
33MTSAFE	= YES
34STACK	= 64000
35#SCREEN	= none
36DATADIR	= sys:/etc/GeoIP
37CONFDIR	= sys:/etc
38
39# Comment the line below if you dont want to link with the static libz.lib.
40LSTATIC = 1
41
42# Edit the var below to point to your lib architecture.
43ifndef LIBARCH
44LIBARCH = LIBC
45endif
46
47# must be equal to DEBUG or NDEBUG
48DB	= NDEBUG
49# DB	= DEBUG
50# Optimization: -O<n> or debugging: -g
51ifeq ($(DB),NDEBUG)
52	OPT	= -O2
53	OBJDIR	= release
54else
55	OPT	= -g
56	OBJDIR	= debug
57endif
58OBJLIB	= lib-$(OBJDIR)
59
60# Include the version info retrieved from header.
61-include $(OBJDIR)/version.inc
62
63# Global tools and toolflags used with all compilers.
64ZIP	= zip -qzR9
65CP	= cp -afv
66MV	= mv -fv
67# RM	= rm -f
68# if you want to mark the target as MTSAFE you will need a tool for
69# generating the xdc data for the linker; here's a minimal tool:
70# http://www.gknw.com/development/prgtools/mkxdc.zip
71MPKXDC	= mkxdc
72
73# The following line defines your compiler.
74ifdef METROWERKS
75	CC = mwccnlm
76else
77	CC = gcc
78endif
79
80# Global flags for all compilers
81CFLAGS	= $(OPT) -D$(DB) -DNETWARE -nostdinc
82CFLAGS	+= -DGEOIPDATADIR=\"$(DATADIR)\"
83CFLAGS	+= -DSYSCONFDIR=\"$(CONFDIR)\"
84
85ifeq ($(CC),mwccnlm)
86LD	= mwldnlm
87LDFLAGS	= -nostdlib $(PRELUDE) $(LDLIBS) $(LIBOBJS) $(OBJDIR)/$(basename $@).o -o $@ -commandfile
88AR	= mwldnlm
89ARFLAGS	= -type library -w nocmdline $(OBJDIR)/*.o -o
90LIBEXT	= lib
91CFLAGS	+= -msgstyle gcc -gccinc -opt nointrinsics -proc 586
92CFLAGS	+= -relax_pointers
93#CFLAGS	+= -w on
94ifeq ($(LIBARCH),LIBC)
95	PRELUDE = $(SDK_LIBC)/imports/libcpre.o
96	CFLAGS += -align 4
97else
98	PRELUDE = "$(METROWERKS)/Novell Support/Libraries/runtime/prelude.obj"
99#	CFLAGS += -include "$(METROWERKS)/Novell Support/Headers/nlm_prefix.h"
100	CFLAGS += -align 1
101endif
102else
103LD	= nlmconv
104LDFLAGS	= -T
105AR	= ar
106ARFLAGS	= -cq
107LIBEXT	= lib
108CFLAGS	+= -fno-builtin -fpack-struct -fpcc-struct-return -fno-strict-aliasing
109CFLAGS	+= -Wall -Wno-unused #-Wno-format # -pedantic
110ifeq ($(LIBARCH),LIBC)
111	PRELUDE = $(SDK_LIBC)/imports/libcpre.gcc.o
112else
113	PRELUDE = $(SDK_CLIB)/imports/clibpre.gcc.o
114	CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h
115endif
116endif
117DESCR += ($(LIBARCH)) - $(CC) build
118
119NDK_ROOT = $(NDKBASE)/ndk
120SDK_CLIB = $(NDK_ROOT)/nwsdk
121SDK_LIBC = $(NDK_ROOT)/libc
122
123ifeq ($(LIBARCH),LIBC)
124	INCLUDES += -I$(SDK_LIBC)/include -I$(SDK_LIBC)/include/nks
125	# INCLUDES += -I$(SDK_LIBC)/include/winsock
126	CFLAGS += -D_POSIX_SOURCE
127	# CFLAGS += -D__ANSIC__
128else
129	INCLUDES += -I$(SDK_CLIB)/include/nlm -I$(SDK_CLIB)/include
130	# INCLUDES += -I$(SDK_CLIB)/include/nlm/obsolete
131	CFLAGS += -DNETDB_USE_INTERNET
132endif
133
134INCLUDES += -I./libGeoIP
135INCLUDES += -I$(ZLIBSDK)
136CFLAGS	+= $(INCLUDES)
137
138ifeq ($(MTSAFE),YES)
139	XDCOPT = -n
140endif
141ifeq ($(MTSAFE),NO)
142	XDCOPT = -u
143endif
144
145LIBPATH	+= -L$(ZLIBSDK)/nw/release
146ifdef LSTATIC
147	LDLIBS	+= $(ZLIBSDK)/nw/release/libz.$(LIBEXT)
148else
149	IMPORTS	+= @$(ZLIBSDK)/nw/release/libz.imp
150	MODULES	+= libz
151endif
152
153ifeq ($(findstring linux,$(OSTYPE)),linux)
154DL	= '
155#-include $(NDKBASE)/nlmconv/ncpfs.inc
156endif
157
158vpath %.c ./apps ./libGeoIP
159
160LIBOBJS	= $(OBJLIB)/GeoIP.o $(OBJLIB)/GeoIPCity.o
161UPDOBJS	= $(OBJLIB)/GeoIPUpdate.o $(OBJLIB)/md5.o $(OBJDIR)/base64.o
162LIBOBJS += $(UPDOBJS)
163
164.PRECIOUS: $(OBJLIB)/%.o $(OBJDIR)/%.o $(OBJDIR)/%.def
165
166
167all: prebuild $(TARGETS)
168
169prebuild: $(OBJLIB) $(OBJDIR) $(OBJDIR)/version.inc
170
171dist: $(DISTDIR) all $(DISTDIR)/readme_bin.txt
172	@$(CP) *.nlm $(DISTDIR)
173	@$(CP) Changelog $(DISTDIR)
174	@$(CP) README $(DISTDIR)
175	@$(CP) conf/GeoIP.conf.default $(DISTDIR)
176	@$(CP) data/GeoIP.dat $(DISTDIR)
177	@echo Creating $(ARCHIVE)
178	@$(ZIP) $(ARCHIVE) $(DISTDIR)/* < $(DISTDIR)/readme_bin.txt
179
180clean:
181	-$(RM) -r $(OBJDIR) $(OBJLIB)
182	-$(RM) $(TARGETS)
183
184distclean:
185	-$(RM) -r $(DISTDIR)
186	-$(RM) $(ARCHIVE)
187
188%.nlm: $(OBJDIR)/%.def $(LIBOBJS) $(OBJDIR)/%.o $(OBJDIR)/%.xdc
189	@echo Linking $@
190	@-$(RM) $@
191	@$(LD) $(LDFLAGS) $<
192
193$(DISTDIR):
194	@mkdir $@
195
196$(OBJDIR):
197	@mkdir $@
198
199$(OBJLIB):
200	@mkdir $@
201
202$(OBJDIR)/%.o: %.c
203#	@echo Compiling $<
204	$(CC) $(CFLAGS) -c $< -o $@
205
206$(OBJLIB)/%.o: %.c
207#	@echo Compiling $<
208	$(CC) $(CFLAGS) -c $< -o $@
209
210$(OBJDIR)/version.inc: configure.in $(OBJDIR)
211	@echo Creating $@
212	@awk -f get_ver.awk $< > $@
213
214$(OBJDIR)/%.xdc: Makefile.netware
215	@echo Creating $@
216	@$(MPKXDC) $(XDCOPT) $@
217
218$(OBJDIR)/%.def: Makefile.netware
219	@echo Creating $@
220	@echo $(DL)# DEF file for linking with $(LD)$(DL) > $@
221	@echo $(DL)# Do not edit this file - it is created by make!$(DL) >> $@
222	@echo $(DL)# All your changes will be lost!!$(DL) >> $@
223	@echo $(DL)#$(DL) >> $@
224	@echo $(DL)copyright "$(COPYR)"$(DL) >> $@
225	@echo $(DL)description "$(DESCR)"$(DL) >> $@
226	@echo $(DL)version $(GEOIP_VERSION)$(DL) >> $@
227ifdef NLMTYPE
228	@echo $(DL)type $(NLMTYPE)$(DL) >> $@
229endif
230ifdef STACK
231	@echo $(DL)stack $(STACK)$(DL) >> $@
232endif
233ifdef SCREEN
234	@echo $(DL)screenname "$(SCREEN)"$(DL) >> $@
235else
236	@echo $(DL)screenname "DEFAULT"$(DL) >> $@
237endif
238ifeq ($(DB),DEBUG)
239	@echo $(DL)debug$(DL) >> $@
240endif
241	@echo $(DL)threadname "$(subst .def,,$(notdir $@))"$(DL) >> $@
242ifdef XDCOPT
243	@echo $(DL)xdcdata $(@:.def=.xdc)$(DL) >> $@
244endif
245ifeq ($(LDRING),0)
246	@echo $(DL)flag_on 16$(DL) >> $@
247endif
248ifeq ($(LDRING),3)
249	@echo $(DL)flag_on 512$(DL) >> $@
250endif
251ifeq ($(LIBARCH),CLIB)
252	@echo $(DL)start _Prelude$(DL) >> $@
253	@echo $(DL)exit _Stop$(DL) >> $@
254	@echo $(DL)import @$(SDK_CLIB)/imports/clib.imp$(DL) >> $@
255	@echo $(DL)import @$(SDK_CLIB)/imports/threads.imp$(DL) >> $@
256	@echo $(DL)import @$(SDK_CLIB)/imports/nlmlib.imp$(DL) >> $@
257	@echo $(DL)module clib$(DL) >> $@
258else
259	@echo $(DL)flag_on 64$(DL) >> $@
260	@echo $(DL)pseudopreemption$(DL) >> $@
261	@echo $(DL)start _LibCPrelude$(DL) >> $@
262	@echo $(DL)exit _LibCPostlude$(DL) >> $@
263	@echo $(DL)check _LibCCheckUnload$(DL) >> $@
264	@echo $(DL)import @$(SDK_LIBC)/imports/libc.imp$(DL) >> $@
265	@echo $(DL)import @$(SDK_LIBC)/imports/netware.imp$(DL) >> $@
266	@echo $(DL)module libc$(DL) >> $@
267endif
268ifdef MODULES
269	@echo $(DL)module $(MODULES)$(DL) >> $@
270endif
271ifdef EXPORTS
272	@echo $(DL)export $(EXPORTS)$(DL) >> $@
273endif
274ifdef IMPORTS
275	@echo $(DL)import $(IMPORTS)$(DL) >> $@
276endif
277ifeq ($(LD),nlmconv)
278ifdef LDLIBS
279	@echo $(DL)input $(LDLIBS)$(DL) >> $@
280endif
281	@echo $(DL)input $(PRELUDE)$(DL) >> $@
282	@echo $(DL)input $(LIBOBJS)$(DL) >> $@
283	@echo $(DL)input $(@:.def=.o)$(DL) >> $@
284	@echo $(DL)output $(notdir $(@:.def=.nlm))$(DL) >> $@
285endif
286
287$(DISTDIR)/readme_bin.txt: Makefile.netware
288	@echo Creating $@
289	@echo $(DL)This is a binary distribution for NetWare platform.$(DL) > $@
290	@echo $(DL)GeoIP version $(GEOIP_VERSION_STR)$(DL) >> $@
291ifndef LSTATIC
292	@echo $(DL)These binaries depend on libz.nlm in the search path!$(DL) >> $@
293endif
294	@echo $(DL)Please download the complete GeoIP package for$(DL) >> $@
295	@echo $(DL)any further documentation:$(DL) >> $@
296	@echo $(DL)$(WWWURL)$(DL) >> $@
297
298info:
299	@echo Targets to build: $(TARGETS)
300
301
302