ifndef VERBOSE
.SILENT:
endif

NLM_NAME=mod_jk

#
# Base environment
#
ifndef TOOLPATH
TOOLPATH = D:\Tools
endif

ifndef JDKPATH
JDKPATH=$(TOOLPATH)\jdk\jdk-1_2_2
endif

ifndef NOVELLNDK
NOVELLNDK=$(TOOLPATH)\nwsdk
endif

ifndef APACHE_SRC
APACHE_SRC=d:\apache_1.3.19\src
endif

ifndef METROWERKSPATH
METROWERKSPATH=$(TOOLPATH)\mw\5.3
endif

ifndef WINSOCK_INCDIR
WINSOCK_INCDIR=$(NOVELLNDK)\include\winsock
endif

CC=$(METROWERKSPATH)\bin\mwccnlm
LINK=$(METROWERKSPATH)\bin\mwldnlm

JK_OBJS=\
	jk_ajp12_worker.obj \
	jk_ajp13.obj \
	jk_ajp13_worker.obj \
	jk_connect.obj \
	jk_jni_worker.obj \
	jk_lb_worker.obj \
	jk_map.obj \
	jk_msg_buff.obj \
	jk_pool.obj \
	jk_sockbuf.obj \
	jk_uri_worker_map.obj \
	jk_util.obj \
	jk_worker.obj \
	mod_jk.obj \
	jk_nwmain.obj \
	
all: $(NLM_NAME).nlm

$(NLM_NAME).nlm: $(JK_OBJS) link.opt
	@echo Linking $@
	@$(LINK) @link.opt

%.obj: %.c cc.opt
	@echo Compiling $<
	@$(CC) $< -o=$(@F) @cc.opt
	
%.obj: ../common/%.c cc.opt
	@echo Compiling $<
	@$(CC) $< -o=$(@F) @cc.opt
	
cc.opt: Makefile.nw
	-@del cc.opt > NUL
	@echo Generating $@
	@echo -nosyspath -ext obj -c -align 1 -w nocmdline -bool on >> $@
ifdef DEBUG
	@echo -g >> $@
endif
	@echo -I$(NOVELLNDK)\include\nlm >> $@
	@echo -I$(NOVELLNDK)\include >> $@
	@echo -I. >> $@
	@echo -I..\common >> $@
	@echo -I$(METROWERKSPATH)\include >> $@
	@echo -I$(JDKPATH)\include >> $@
	@echo -I$(JDKPATH)\include\netware >> $@
	@echo -I$(APACHE_SRC)\include >> $@
	@echo -I$(APACHE_SRC)\os\netware >> $@
	@echo -I$(WINSOCK_INCDIR) >> $@
	@echo -DN_PLAT_NLM >> $@
	@echo -DNETWARE >> $@
	@echo -DXP_NETWARE >> $@

link.opt: Makefile.nw
	-@del link.opt > NUL
	-@del link.def > NUL
	@echo Generating $@
	@echo -warnings off >> $@
	@echo -zerobss >> $@
	@echo -desc "Apache 1.3 Plugin for Tomcat" >> $@
	@echo -o $(NLM_NAME).nlm >> $@
	@echo -screenname "System Console" >> $@
	@echo -nlmversion 0,1,0 >> $@
ifdef DEBUG
	@echo -g >> $@
	@echo -sym internal >> $@
	@echo -sym codeview4 >> $@
	@echo -osym $(NLM_NAME).sym >> $@
endif
	@echo -nodefaults >> $@
	@echo -map $(NLM_NAME).map >> $@
	@echo -threadname "APTomcat Thread" >> $@
	@echo -stacksize 64000 >> $@
	@echo $(METROWERKSPATH)\lib\nwpre.obj $(strip $(JK_OBJS)) >> $@
	@echo -commandfile link.def >> $@
	@echo module apache >> link.def
	@echo Import @$(NOVELLNDK)\imports\clib.imp >> link.def
	@echo Import @$(NOVELLNDK)\imports\lib0.imp >> link.def
	@echo Import @$(NOVELLNDK)\imports\nlmlib.imp >> link.def
	@echo Import @$(NOVELLNDK)\imports\threads.imp >> link.def
	@echo Import @$(NOVELLNDK)\imports\socklib.imp >> link.def
	@echo Import @$(NOVELLNDK)\imports\ws2nlm.imp >> link.def
	@echo Import @$(APACHE_SRC)\os\netware\ApacheCore.imp >> link.def
	@echo Export jk_module >> link.def

clean:
	-@del *.obj > NUL
	-@del *.map > NUL
	-@del link.* > NUL
	-@del cc.opt > NUL
	-@del *.nlm > NUL
	-@del *.sym > NUL
	
