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

!IF !DEFINED(APR_DECLARE_STATIC) || "$(APR_DECLARE_STATIC)" == ""
TARGET=DLL
CFLAGS = -DAPR_DECLARE_EXPORT $(CFLAGS)
PROJECT = libapr-1
!ELSE
TARGET=LIB
CFLAGS = -DAPR_DECLARE_STATIC $(CFLAGS)
PROJECT = apr-1
!ENDIF

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

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

INCLUDES = -I$(SRCDIR)\include -I$(SRCDIR)\include\arch -I$(SRCDIR)\include\arch\win32 -I$(SRCDIR)\include\arch\unix
PDBFLAGS = -Fo$(WORKDIR)\ -Fd$(WORKDIR)\$(PROJECT)-src
OBJECTS = \
	$(WORKDIR)\apr_atomic.obj \
	$(WORKDIR)\dso.obj \
	$(WORKDIR)\copy.obj \
	$(WORKDIR)\fileacc.obj \
	$(WORKDIR)\filepath_util.obj \
	$(WORKDIR)\fullrw.obj \
	$(WORKDIR)\mktemp.obj \
	$(WORKDIR)\tempdir.obj \
	$(WORKDIR)\buffer.obj \
	$(WORKDIR)\dir.obj \
	$(WORKDIR)\filedup.obj \
	$(WORKDIR)\filepath.obj \
	$(WORKDIR)\filestat.obj \
	$(WORKDIR)\filesys.obj \
	$(WORKDIR)\flock.obj \
	$(WORKDIR)\open.obj \
	$(WORKDIR)\pipe.obj \
	$(WORKDIR)\readwrite.obj \
	$(WORKDIR)\seek.obj \
	$(WORKDIR)\proc_mutex.obj \
	$(WORKDIR)\thread_cond.obj \
	$(WORKDIR)\thread_mutex.obj \
	$(WORKDIR)\thread_rwlock.obj \
	$(WORKDIR)\apr_pools.obj \
	$(WORKDIR)\errorcodes.obj \
	$(WORKDIR)\getopt.obj \
	$(WORKDIR)\otherchild.obj \
	$(WORKDIR)\version.obj \
	$(WORKDIR)\charset.obj \
	$(WORKDIR)\env.obj \
	$(WORKDIR)\internal.obj \
	$(WORKDIR)\misc.obj \
	$(WORKDIR)\rand.obj \
	$(WORKDIR)\start.obj \
	$(WORKDIR)\utf8.obj \
	$(WORKDIR)\common.obj \
	$(WORKDIR)\mmap.obj \
	$(WORKDIR)\inet_ntop.obj \
	$(WORKDIR)\inet_pton.obj \
	$(WORKDIR)\multicast.obj \
	$(WORKDIR)\sockaddr.obj \
	$(WORKDIR)\sendrecv.obj \
	$(WORKDIR)\sockets.obj \
	$(WORKDIR)\sockopt.obj \
	$(WORKDIR)\apr_getpass.obj \
	$(WORKDIR)\pollcb.obj \
	$(WORKDIR)\pollset.obj \
	$(WORKDIR)\poll.obj \
	$(WORKDIR)\select.obj \
	$(WORKDIR)\apr_random.obj \
	$(WORKDIR)\sha2.obj \
	$(WORKDIR)\sha2_glue.obj \
	$(WORKDIR)\shm.obj \
	$(WORKDIR)\apr_cpystrn.obj \
	$(WORKDIR)\apr_fnmatch.obj \
	$(WORKDIR)\apr_snprintf.obj \
	$(WORKDIR)\apr_strings.obj \
	$(WORKDIR)\apr_strnatcmp.obj \
	$(WORKDIR)\apr_strtok.obj \
	$(WORKDIR)\apr_hash.obj \
	$(WORKDIR)\apr_tables.obj \
	$(WORKDIR)\proc.obj \
	$(WORKDIR)\signals.obj \
	$(WORKDIR)\thread.obj \
	$(WORKDIR)\threadpriv.obj \
	$(WORKDIR)\access.obj \
	$(WORKDIR)\time.obj \
	$(WORKDIR)\timestr.obj \
	$(WORKDIR)\groupinfo.obj \
	$(WORKDIR)\userinfo.obj

HEADERS = $(SRCDIR)\include\apr.h

!IF "$(TARGET)" == "DLL"
BUILDBIN = $(WORKDIR)\$(PROJECT).dll
BUILDPDB = $(WORKDIR)\$(PROJECT).pdb
BUILDRES = $(WORKDIR)\$(PROJECT).res
BUILDMFT = $(BUILDBIN).manifest
!ELSE
BUILDBIN = $(WORKDIR)\$(PROJECT).lib
!ENDIF

all : $(BUILDINS) $(WORKDIR) $(HEADERS) $(BUILDBIN)
	@echo Building APR $(TARGET) ...

$(WORKDIR) :
	@$(MAKEWORKDIR)

.SUFFIXES : .hw

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

$(OBJECTS): $(HEADERS)

!IF "$(TARGET)" == "DLL"
$(BUILDRES): libapr.rc $(HEADERS)
	$(RC) $(RCFLAGS) /i "$(SRCDIR)\include" /d "APR_VERSION_ONLY" /fo $(BUILDRES) libapr.rc
$(BUILDBIN): $(WORKDIR) $(HEADERS) $(OBJECTS) $(BUILDRES)
	$(LINK) $(LFLAGS) $(OBJECTS) $(BUILDRES) $(LIBS) /pdb:$(BUILDPDB) /out:$(BUILDBIN)
	IF EXIST $(BUILDMFT) \
		mt -nologo -manifest $(BUILDMFT) -outputresource:$(BUILDBIN);2
!ELSE
$(BUILDBIN): $(WORKDIR) $(OBJECTS)
	$(LINK) $(LFLAGS) $(OBJECTS) /out:$(BUILDBIN)
!ENDIF

clean:
	@$(CLEANTARGET)

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