# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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   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
EXTRA_CFLAGS = -DAPR_DECLARE_EXPORT
PROJECT = libapr-1
!ELSE
TARGET=LIB
EXTRA_CFLAGS = -DAPR_DECLARE_STATIC
PROJECT = apr-1
!ENDIF

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

!include <..\..\NMAKEMakefile.inc>


!IF "$(TARGET)" != "LIB"
LFLAGS = $(LFLAGS) /version:1.4
!ENDIF
INCLUDES = -I$(SRCDIR)\include -I$(SRCDIR)\include\arch -I$(SRCDIR)\include\private -I$(SRCDIR)\include\arch\win32 -I$(SRCDIR)\include\arch\unix
PDBFLAGS = -Fo$(WORKDIR)\ -Fd$(WORKDIR)\$(PROJECT)

OBJECTS = \
	$(WORKDIR)\apr_atomic.obj \
	$(WORKDIR)\apr_atomic64.obj \
	$(WORKDIR)\apr_cpystrn.obj \
	$(WORKDIR)\apr_cstr.obj \
	$(WORKDIR)\apr_encode.obj \
	$(WORKDIR)\apr_escape.obj \
	$(WORKDIR)\apr_fnmatch.obj \
	$(WORKDIR)\apr_getpass.obj \
	$(WORKDIR)\apr_hash.obj \
	$(WORKDIR)\apr_pools.obj \
	$(WORKDIR)\apr_random.obj \
	$(WORKDIR)\apr_skiplist.obj \
	$(WORKDIR)\apr_snprintf.obj \
	$(WORKDIR)\apr_strings.obj \
	$(WORKDIR)\apr_strnatcmp.obj \
	$(WORKDIR)\apr_strtok.obj \
	$(WORKDIR)\apr_tables.obj \
	$(WORKDIR)\buffer.obj \
	$(WORKDIR)\charset.obj \
	$(WORKDIR)\common.obj \
	$(WORKDIR)\copy.obj \
	$(WORKDIR)\dir.obj \
	$(WORKDIR)\dso.obj \
	$(WORKDIR)\env.obj \
	$(WORKDIR)\errorcodes.obj \
	$(WORKDIR)\fileacc.obj \
	$(WORKDIR)\filedup.obj \
	$(WORKDIR)\filepath.obj \
	$(WORKDIR)\filepath_util.obj \
	$(WORKDIR)\filestat.obj \
	$(WORKDIR)\filesys.obj \
	$(WORKDIR)\flock.obj \
	$(WORKDIR)\fullrw.obj \
	$(WORKDIR)\getopt.obj \
	$(WORKDIR)\groupinfo.obj \
	$(WORKDIR)\inet_ntop.obj \
	$(WORKDIR)\inet_pton.obj \
	$(WORKDIR)\internal.obj \
	$(WORKDIR)\misc.obj \
	$(WORKDIR)\mktemp.obj \
	$(WORKDIR)\mmap.obj \
	$(WORKDIR)\multicast.obj \
	$(WORKDIR)\open.obj \
	$(WORKDIR)\otherchild.obj \
	$(WORKDIR)\pipe.obj \
	$(WORKDIR)\poll.obj \
	$(WORKDIR)\pollcb.obj \
	$(WORKDIR)\pollset.obj \
	$(WORKDIR)\proc.obj \
	$(WORKDIR)\proc_mutex.obj \
	$(WORKDIR)\rand.obj \
	$(WORKDIR)\readwrite.obj \
	$(WORKDIR)\seek.obj \
	$(WORKDIR)\select.obj \
	$(WORKDIR)\sendrecv.obj \
	$(WORKDIR)\sha2.obj \
	$(WORKDIR)\sha2_glue.obj \
	$(WORKDIR)\shm.obj \
	$(WORKDIR)\signals.obj \
	$(WORKDIR)\sockaddr.obj \
	$(WORKDIR)\socket_util.obj \
	$(WORKDIR)\sockets.obj \
	$(WORKDIR)\sockopt.obj \
	$(WORKDIR)\start.obj \
	$(WORKDIR)\tempdir.obj \
	$(WORKDIR)\thread.obj \
	$(WORKDIR)\thread_cond.obj \
	$(WORKDIR)\thread_mutex.obj \
	$(WORKDIR)\thread_rwlock.obj \
	$(WORKDIR)\threadpriv.obj \
	$(WORKDIR)\time.obj \
	$(WORKDIR)\timestr.obj \
	$(WORKDIR)\userinfo.obj \
	$(WORKDIR)\utf8.obj \
	$(WORKDIR)\version.obj \
	$(WORKDIR)\wakeup.obj

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


BUILDINC = $(PREFIX)\include\apr-1
BUILDLIB = $(PREFIX)\lib
!IF "$(TARGET)" == "DLL"
BUILDBIN = $(WORKDIR)\$(PROJECT).dll
BUILDPDB = $(WORKDIR)\$(PROJECT).pdb
BUILDRES = $(WORKDIR)\$(PROJECT).res
BUILDIMP = $(WORKDIR)\$(PROJECT).lib
!ELSE
BUILDBIN = $(WORKDIR)\$(PROJECT).lib
!ENDIF

all : $(WORKDIR) $(HEADERS) $(BUILDBIN)

$(WORKDIR):
	@$(MAKEWORKDIR)

$(SRCDIR)\include\apr.h: $(SRCDIR)\include\apr.hw
	@type $** > $@

$(SRCDIR)\include\private\apr_escape_test_char.h: $(SRCDIR)\tools\gen_test_char.c
	$(CC) /nologo -MT -W3 -O2 -Ob2 -DWIN32 -D_WIN32 -D_CONSOLE -D_MBCS /Fo$(WORKDIR)\ /Fe$(WORKDIR)\gen_test_char.exe $**
	$(WORKDIR)\gen_test_char.exe > $@

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

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

{$(SRCDIR)\encoding}.c{$(WORKDIR)}.obj:
	$(CC) $(CFLAGS) $(INCLUDES) -I$(WORKDIR) $(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) $<

!IF "$(TARGET)" == "DLL"
$(BUILDRES): $(SRCDIR)\libapr.rc
	$(RC) $(RCFLAGS) /i "$(SRCDIR)\include" /d "APR_VERSION_ONLY" /fo $(BUILDRES) $**
$(BUILDBIN): $(OBJECTS) $(BUILDRES)
	$(LINK) $(LFLAGS) $** $(LIBS) /pdb:$(BUILDPDB) /out:$(BUILDBIN) /implib:$(BUILDIMP)
!ELSE
$(BUILDBIN): $(OBJECTS)
	$(LINK) $(LFLAGS) $** /out:$(BUILDBIN)
!ENDIF

clean:
	@$(CLEANTARGET)

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

