# Copyright 2001-2009 The Apache Software Foundation or its licensors, as
# applicable.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ====================================================================
#
# NMAKEmakefile   Master Tomcat Native makefile.
# Usage:
#                 STATIC=1  Use static version of the APR
#                 DEBUG=1   Build DEBUG version of TCN
#
# Originally contributed by Mladen Turk <mturk jboss.com>
#
# ====================================================================
#

!IF !DEFINED(APR_DECLARE_STATIC) || "$(APR_DECLARE_STATIC)" == ""
PROJECT = libtcnative-1
APR_LIB = libapr-1.lib
APU_LIB = libaprutil-1.lib
!ELSE
CFLAGS = -DAPR_DECLARE_STATIC -DAPU_DECLARE_STATIC $(CFLAGS)
PROJECT = tcnative-1
APR_LIB = apr-1.lib
APU_LIB = aprutil-1.lib
!ENDIF
TARGET = DLL

!include <xbuild.inc>

!IF DEFINED(WITH_OPENSSL) && "$(WITH_OPENSSL)" != "no"
CFLAGS = $(CFLAGS) -DZLIB_WINAPI -DNO_IDEA -DNO_RC5 -DNO_MDC2 -DOPENSSL_NO_IDEA \
	-DOPENSSL_NO_SEED -DOPENSSL_NO_EC -DOPENSSL_NOECDSA -DOPENSSL_NO_ECDH -DOPENSSL_FIPS \
	-DOPENSSL_NO_RC5 -DOPENSSL_NO_MDC2 -DOPENSSL_NO_KRB5 -DHAVE_OPENSSL \
	-DHAVE_SSL_SET_STATE=1 -DTCN_DECLARE_EXPORT
!ELSE
CFLAGS = $(CFLAGS) -DZLIB_WINAPI -DTCN_DECLARE_EXPORT
!ENDIF

!IF !DEFINED(SRCDIR) || "$(SRCDIR)" == ""
SRCDIR = .\jni\native
!ENDIF

INCLUDES = -I$(SRCDIR)\include $(JAVA_INCLUDES)

!IF DEFINED(EXTINCPATH) && "$(EXTINCPATH)" != "no"
INCLUDES = $(INCLUDES) -I$(EXTINCPATH) -I$(EXTINCPATH)\arch\win32 -I$(EXTINCPATH)\httpd -I$(EXTINCPATH)\httpd\arch\win32
!ENDIF
!IF DEFINED(EXTLIBPATH) && "$(EXTLIBPATH)" != "no"
LDIRS = /libpath:"$(EXTLIBPATH)"
!ENDIF

LFLAGS = $(LFLAGS) /version:1.1
LFLAGS = $(LFLAGS) user32.lib psapi.lib gdi32.lib shlwapi.lib wldap32.lib ole32.lib
LFLAGS = $(LFLAGS) $(APR_LIB) $(APU_LIB)
!IF DEFINED(WITH_OPENSSL) && "$(WITH_OPENSSL)" != "no"
LFLAGS = $(LFLAGS) libeay32.lib ssleay32.lib
!ENDIF

PDBFLAGS = -Fo$(WORKDIR)\ -Fd$(WORKDIR)\$(PROJECT)-src
OBJECTS = \
	$(WORKDIR)\address.obj \
	$(WORKDIR)\bb.obj \
	$(WORKDIR)\dir.obj \
	$(WORKDIR)\error.obj \
	$(WORKDIR)\file.obj \
	$(WORKDIR)\info.obj \
	$(WORKDIR)\jnilib.obj \
	$(WORKDIR)\lock.obj \
	$(WORKDIR)\misc.obj \
	$(WORKDIR)\mmap.obj \
	$(WORKDIR)\multicast.obj \
	$(WORKDIR)\network.obj \
	$(WORKDIR)\os.obj \
	$(WORKDIR)\poll.obj \
	$(WORKDIR)\pool.obj \
	$(WORKDIR)\proc.obj \
	$(WORKDIR)\shm.obj \
	$(WORKDIR)\ssl.obj \
	$(WORKDIR)\sslcontext.obj \
	$(WORKDIR)\sslinfo.obj \
	$(WORKDIR)\sslnetwork.obj \
	$(WORKDIR)\sslutils.obj \
	$(WORKDIR)\stdlib.obj \
	$(WORKDIR)\user.obj \
	$(WORKDIR)\thread.obj \
	$(WORKDIR)\ntpipe.obj \
	$(WORKDIR)\registry.obj \
	$(WORKDIR)\system.obj

BUILDBIN = $(PREFIX)\bin
BUILDOUT = $(WORKDIR)\$(PROJECT).dll
BUILDPDB = $(WORKDIR)\$(PROJECT).pdb
BUILDRES = $(WORKDIR)\$(PROJECT).res
BUILDMAN = $(BUILDOUT).manifest

all : $(WORKDIR) $(BUILDOUT)

$(BUILDBIN) :
	@if not exist "$(BUILDBIN)\$(NULL)" mkdir "$(BUILDBIN)"

$(WORKDIR) :
	@$(MAKEWORKDIR)

{$(SRCDIR)\src}.c{$(WORKDIR)}.obj:
	$(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<

{$(SRCDIR)\os\win32}.c{$(WORKDIR)}.obj:
	$(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<

$(OBJECTS): $(SRCDIR)\include\*.h

$(BUILDRES): $(SRCDIR)\os\win32\libtcnative.rc $(SRCDIR)\include\*.h
	$(RC) $(RCFLAGS) /i "$(SRCDIR)\include" /fo $(BUILDRES) $(SRCDIR)\os\win32\libtcnative.rc

$(BUILDOUT): $(WORKDIR) $(OBJECTS) $(BUILDRES)
	$(LINK) $(LFLAGS) $(OBJECTS) $(BUILDRES) $(LIBS) $(LDIRS) /pdb:$(BUILDPDB) /out:$(BUILDOUT)
	IF EXIST $(BUILDMAN) \
		mt -nologo -manifest $(BUILDMAN) -outputresource:$(BUILDOUT);2

clean:
	@$(CLEANTARGET)

install: all $(BUILDBIN)
	@xcopy "$(WORKDIR)\*.dll" "$(BUILDBIN)" /I /Y /Q
