# 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   HTTPD core library makefile.
# Usage:
#                 DEBUG=1   Build DEBUG version of HTTPD
#
# Originally contributed by Mladen Turk <mturk redhat.com>
#
# ====================================================================
#


TARGET=DLL
PROJECT = libhttpd

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

CFLAGS = $(CFLAGS) -DAP_DECLARE_EXPORT -DPCRE_STATIC

!include <NMAKEbuild.inc>
!include <NMAKEhttpd.inc>

LDIRS = /libpath:"$(BUILDLIB)" /libpath:"$(EXTLIBPATH)"
LFLAGS = $(LFLAGS) user32.lib psapi.lib gdi32.lib shlwapi.lib wldap32.lib ole32.lib $(LIBAPR) $(LIBAPU) $(PCRE)

INCLUDES = -I$(SRCDIR)\include -I$(BUILDINC)
PDBFLAGS = -Fo$(WORKDIR)\ -Fd$(WORKDIR)\$(PROJECT)-src
OBJECTS = \
	$(WORKDIR)\buildmark.obj \
	$(WORKDIR)\byterange_filter.obj \
	$(WORKDIR)\chunk_filter.obj \
	$(WORKDIR)\config.obj \
	$(WORKDIR)\connection.obj \
	$(WORKDIR)\core.obj \
	$(WORKDIR)\core_filters.obj \
	$(WORKDIR)\http_core.obj \
	$(WORKDIR)\http_etag.obj \
	$(WORKDIR)\http_filters.obj \
	$(WORKDIR)\http_protocol.obj \
	$(WORKDIR)\http_request.obj \
	$(WORKDIR)\log.obj \
	$(WORKDIR)\protocol.obj \
	$(WORKDIR)\request.obj \
	$(WORKDIR)\vhost.obj \
	$(WORKDIR)\mod_so.obj \
	$(WORKDIR)\mod_win32.obj \
	$(WORKDIR)\modules.obj \
	$(WORKDIR)\eoc_bucket.obj \
	$(WORKDIR)\error_bucket.obj \
	$(WORKDIR)\util.obj \
	$(WORKDIR)\util_cfgtree.obj \
	$(WORKDIR)\util_filter.obj \
	$(WORKDIR)\util_md5.obj \
	$(WORKDIR)\util_pcre.obj \
	$(WORKDIR)\util_script.obj \
	$(WORKDIR)\util_time.obj \
	$(WORKDIR)\util_win32.obj \
	$(WORKDIR)\util_xml.obj \
	$(WORKDIR)\ap_regkey.obj \
	$(WORKDIR)\child.obj \
	$(WORKDIR)\listen.obj \
	$(WORKDIR)\mpm_common.obj \
	$(WORKDIR)\mpm_winnt.obj \
	$(WORKDIR)\nt_eventlog.obj \
	$(WORKDIR)\provider.obj \
	$(WORKDIR)\scoreboard.obj \
	$(WORKDIR)\service.obj

HEADERS = \
	$(SRCDIR)\include\os.h \
	$(SRCDIR)\include\mpm.h \
	$(SRCDIR)\include\mpm_default.h \
	$(SRCDIR)\include\mod_cgi.h \
	$(SRCDIR)\include\mod_core.h \
	$(SRCDIR)\include\mod_dav.h \
	$(SRCDIR)\include\mod_include.h \
	$(SRCDIR)\include\mod_proxy.h \
	$(SRCDIR)\include\mod_so.h \
	$(SRCDIR)\server\test_char.h

BUILDBIN = $(WORKDIR)\$(PROJECT).dll
BUILDPDB = $(WORKDIR)\$(PROJECT).pdb 
BUILDRES = $(WORKDIR)\$(PROJECT).res
BUILDMFT = $(BUILDBIN).manifest

RCFLAGS =  $(RCFLAGS) /d BIN_NAME="$(PROJECT).dll" /d LONG_NAME="Apache HTTP Server Core"

BUILDAPR  = $(BUILDOUT)\$(LIBAPR)
BUILDAPU  = $(BUILDOUT)\$(LIBAPU)
BUILDPCRE = $(BUILDLIB)\$(PCRE)
BUILDTCHR = $(SRCDIR)\server\gen_test_char.exe

.SUFFIXES : .h

all: $(BUILDINS) $(WORKDIR) $(HEADERS) $(BUILDAPR) $(BUILDAPU) $(BUILDPCRE) $(BUILDBIN)

$(WORKDIR):
	@$(MAKEWORKDIR)

$(BUILDINS):
    @copy /Y LICENSE $(@D) >NUL

$(BUILDAPR):
	@cd $(SRCDIR)\srclib\apr
	@$(MAKE) -nologo -f NMAKEmakefile install
	@$(MAKE) -nologo -f NMAKEmakefile APR_DECLARE_STATIC=1 install
	@cd ..\..

$(BUILDAPU):
	@cd $(SRCDIR)\srclib\apr-util
	@$(MAKE) -nologo -f NMAKEmakefile install
	@$(MAKE) -nologo -f NMAKEmakefile APR_DECLARE_STATIC=1 install
	@cd ..\..

$(BUILDPCRE):
	@cd $(SRCDIR)\srclib\pcre
	@$(MAKE) -nologo -f NMAKEmakefile PCRE_STATIC=1 install
	@cd ..\..

$(BUILDTCHR):
	@cd $(SRCDIR)\server
	@$(MAKE) -nologo -f NMAKEmakefile install
	@cd ..

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

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

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

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

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

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

$(SRCDIR)\server\test_char.h : $(BUILDAPR) $(BUILDTCHR)
    @$(BUILDTCHR) > $@ 

{$(SRCDIR)\os\win32}.h{$(SRCDIR)\include}.h:
	@copy /Y $< $@ >NUL

{$(SRCDIR)\modules\arch\win32}.h{$(SRCDIR)\include}.h:
	@copy /Y $< $@ >NUL

{$(SRCDIR)\server\mpm\winnt}.h{$(SRCDIR)\include}.h:
	@copy /Y $< $@ >NUL

{$(SRCDIR)\modules\http}.h{$(SRCDIR)\include}.h:
	@copy /Y $< $@ >NUL

{$(SRCDIR)\modules\filters}.h{$(SRCDIR)\include}.h:
	@copy /Y $< $@ >NUL

{$(SRCDIR)\modules\generators}.h{$(SRCDIR)\include}.h:
	@copy /Y $< $@ >NUL

{$(SRCDIR)\modules\proxy}.h{$(SRCDIR)\include}.h:
	@copy /Y $< $@ >NUL

{$(SRCDIR)\modules\mappers}.h{$(SRCDIR)\include}.h:
	@copy /Y $< $@ >NUL

{$(SRCDIR)\modules\dav\main}.h{$(SRCDIR)\include}.h:
	@copy /Y $< $@ >NUL

$(BUILDRES): build\win32\httpd.rc
	$(RC) $(RCFLAGS) /i "$(SRCDIR)\build\win32" /i "$(SRCDIR)\include" /i "$(SRCDIR)\srclib\apr\include" /fo $(BUILDRES) build\win32\httpd.rc

$(BUILDBIN): $(WORKDIR) $(HEADERS) $(BUILDAPR) $(BUILDAPU) $(BUILDPCRE) $(OBJECTS) $(BUILDRES)
	$(LINK) $(LFLAGS) $(OBJECTS) $(BUILDRES) $(LIBS) $(LDIRS) /pdb:$(BUILDPDB) /out:$(BUILDBIN)
	IF EXIST $(BUILDMFT) \
		mt -nologo -manifest $(BUILDMFT) -outputresource:$(BUILDBIN);2

clean:
	@$(CLEANTARGET)

install: all
	@xcopy "$(SRCDIR)\include\*.h" "$(BUILDINC)" /I /Y /Q
	@xcopy "$(WORKDIR)\*.lib" "$(BUILDLIB)" /I /Y /Q
	@xcopy "$(WORKDIR)\*.dll" "$(BUILDOUT)" /I /Y /Q 2>NUL
