#
# Define our required macro's if not already done.
#

ifndef AP_WORK
export AP_WORK = $(CURDIR)
endif

ifndef APR_WORK
ifeq "$(wildcard $(AP_WORK)/srclib/apr)" "$(AP_WORK)/srclib/apr"
export APR_WORK = $(AP_WORK)/srclib/apr
endif
endif
ifneq "$(wildcard $(APR_WORK)/include/apr_version.h)" "$(APR_WORK)/include/apr_version.h"
$(error APR_WORK does not point to a valid APR source tree) 
endif

ifndef APU_WORK
ifeq "$(wildcard $(AP_WORK)/srclib/apr-util)" "$(AP_WORK)/srclib/apr-util"
export APU_WORK = $(AP_WORK)/srclib/apr-util
endif
endif
ifndef APU_WORK
ifeq "$(wildcard $(APR_WORK)/include/apu_version.h)" "$(APR_WORK)/include/apu_version.h"
export APU_WORK = $(APR_WORK)
endif
endif
ifneq "$(wildcard $(APU_WORK)/include/apu_version.h)" "$(APU_WORK)/include/apu_version.h"
$(error APU_WORK does not point to a valid APU source tree) 
endif

#
# Declare the sub-directories to be built here
#

SUBDIRS = \
	$(APR_WORK) \
	build \
	support \
	modules \
	$(EOLIST)

#
# Get the 'head' of the build environment.  This includes default targets and
# paths to tools
#

include $(AP_WORK)/build/NWGNUhead.inc

#
# build this level's files

#
# Make sure all needed macro's are defined
#

#
# These directories will be at the beginning of the include list, followed by
# INCDIRS
#
XINCDIRS	+= \
			$(APR)/include \
			$(APRUTIL)/include \
			$(AP_WORK)/include \
			$(HTTPD) \
			$(STDMOD)/filters \
			$(STDMOD)/generators \
			$(STDMOD)/loggers \
			$(STDMOD)/mappers \
			$(STDMOD)/proxy \
			$(SERVER)/mpm/NetWare \
			$(PCRE) \
			$(NWOS) \
			$(EOLIST)

#
# These flags will come after CFLAGS
#
XCFLAGS		+= \
			$(EOLIST)

#
# These defines will come after DEFINES
#
XDEFINES	+= \
			$(EOLIST)

#
# These flags will be added to the link.opt file
#
XLFLAGS		+= \
			$(EOLIST)

#
# These values will be appended to the correct variables based on the value of
# RELEASE
#
ifeq "$(RELEASE)" "debug"
XINCDIRS	+= \
			$(EOLIST)

XCFLAGS		+= \
			$(EOLIST)

XDEFINES	+= \
			$(EOLIST)

XLFLAGS		+= \
			$(EOLIST)
endif

ifeq "$(RELEASE)" "noopt"
XINCDIRS	+= \
			$(EOLIST)

XCFLAGS		+= \
			$(EOLIST)

XDEFINES	+= \
			$(EOLIST)

XLFLAGS		+= \
			$(EOLIST)
endif

ifeq "$(RELEASE)" "release"
XINCDIRS	+= \
			$(EOLIST)

XCFLAGS		+= \
			$(EOLIST)

XDEFINES	+= \
			$(EOLIST)

XLFLAGS		+= \
			$(EOLIST)
endif

#
# These are used by the link target if an NLM is being generated
# This is used by the link 'name' directive to name the nlm.  If left blank
# TARGET_nlm (see below) will be used.
#
NLM_NAME	= Apache2

#
# This is used by the link '-desc ' directive.
# If left blank, NLM_NAME will be used.
#
NLM_DESCRIPTION	= Apache Web Server $(VERSION_STR) $(VERSION_SKT)

#
# This is used by the '-threadname' directive.  If left blank,
# NLM_NAME Thread will be used.
#
NLM_THREAD_NAME	= Apache

#
# This is used by the '-screenname' directive.  If left blank,
# 'Apache for NetWare' Thread will be used.
#
NLM_SCREEN_NAME = Apache $(VERSION_STR) for NetWare


#
# If this is specified, it will override VERSION value in
# $(AP_WORK)/build/NWGNUenvironment.inc
#
NLM_VERSION	=

#
# If this is specified, it will override the default of 64K
#
NLM_STACK_SIZE	= 65536


#
# If this is specified it will be used by the link '-entry' directive
#
NLM_ENTRY_SYM	=

#
# If this is specified it will be used by the link '-exit' directive
#
NLM_EXIT_SYM	=

#
# If this is specified it will be used by the link '-check' directive
#
NLM_CHECK_SYM	= _LibCCheckUnload

#
# If these are specified it will be used by the link '-flags' directive
#
NLM_FLAGS	= PSEUDOPREEMPTION

#
# If this is specified it will be linked in with the XDCData option in the def
# file instead of the default of $(NWOS)/apache.xdc.  XDCData can be disabled
# by setting APACHE_UNIPROC in the environment
#
XDCDATA		=

#
# If there is an NLM target, put it here
#
TARGET_nlm = \
	$(OBJDIR)/Apache2.nlm \
	$(EOLIST)

#
# If there is an LIB target, put it here
#
TARGET_lib = \
	$(PCRELIB) \
	$(EOLIST)

#
# These are the OBJ files needed to create the NLM target above.
# Paths must all use the '/' character
#
FILES_nlm_objs = \
	$(OBJDIR)/buildmark.o \
	$(OBJDIR)/config.o \
	$(OBJDIR)/connection.o \
	$(OBJDIR)/core.o \
	$(OBJDIR)/core_filters.o \
	$(OBJDIR)/eoc_bucket.o \
	$(OBJDIR)/error_bucket.o \
	$(OBJDIR)/http_core.o \
	$(OBJDIR)/http_protocol.o \
	$(OBJDIR)/http_request.o \
	$(OBJDIR)/byterange_filter.o \
	$(OBJDIR)/chunk_filter.o \
	$(OBJDIR)/http_etag.o \
	$(OBJDIR)/http_filters.o \
	$(OBJDIR)/listen.o \
	$(OBJDIR)/log.o \
	$(OBJDIR)/main.o \
	$(OBJDIR)/mod_authz_host.o \
	$(OBJDIR)/mod_alias.o \
	$(OBJDIR)/mod_dir.o \
	$(OBJDIR)/mod_env.o \
	$(OBJDIR)/mod_include.o \
	$(OBJDIR)/mod_log_config.o \
	$(OBJDIR)/mod_mime.o \
	$(OBJDIR)/mod_negotiation.o \
	$(OBJDIR)/mod_netware.o \
	$(OBJDIR)/mod_setenvif.o \
	$(OBJDIR)/mod_so.o \
	$(OBJDIR)/modules.o \
	$(OBJDIR)/mpm_common.o \
	$(OBJDIR)/mpm_netware.o \
	$(OBJDIR)/protocol.o \
	$(OBJDIR)/provider.o \
	$(OBJDIR)/request.o \
	$(OBJDIR)/scoreboard.o \
	$(OBJDIR)/util.o \
	$(OBJDIR)/util_cfgtree.o \
	$(OBJDIR)/util_charset.o \
	$(OBJDIR)/util_debug.o \
	$(OBJDIR)/util_filter.o \
	$(OBJDIR)/util_md5.o \
	$(OBJDIR)/util_nw.o \
	$(OBJDIR)/util_pcre.o \
	$(OBJDIR)/util_script.o \
	$(OBJDIR)/util_time.o \
	$(OBJDIR)/util_xml.o \
	$(OBJDIR)/vhost.o \
	$(EOLIST)

# Build in mod_nw_ssl if Winsock is being used
ifndef USE_STDSOCKETS
FILES_nlm_objs += $(OBJDIR)/mod_nw_ssl.o \
	$(EOLIST)
endif

#
# These are the LIB files needed to create the NLM target above.
# These will be added as a library command in the link.opt file.
#
FILES_nlm_libs = \
	$(PCRELIB) \
	$(PRELUDE) \
	$(EOLIST)

#
# These are the modules that the above NLM target depends on to load.
# These will be added as a module command in the link.opt file.
#
FILES_nlm_modules = \
	aprlib \
	Libc \
	$(EOLIST)

#
# If the nlm has a msg file, put it's path here
#
FILE_nlm_msg =

#
# If the nlm has a hlp file put it's path here
#
FILE_nlm_hlp =

#
# If this is specified, it will override $(NWOS)\copyright.txt.
#
FILE_nlm_copyright =

#
# Any additional imports go here
#
FILES_nlm_Ximports = \
	@netware.imp \
	@aprlib.imp \
	@libc.imp \
	GetCurrentAddressSpace \
	$(EOLIST)

# Don't link with Winsock if standard sockets are being used
ifndef USE_STDSOCKETS
FILES_nlm_Ximports += @ws2nlm.imp \
	$(EOLIST)
endif

#
# Any symbols exported to here
#
FILES_nlm_exports = \
	@httpd.imp \
	$(EOLIST)

#
# These are the OBJ files needed to create the LIB target above.
# Paths must all use the '/' character
#
ifeq "$(wildcard $(PCRE)/pcre.c)" "$(PCRE)/pcre.c"

FILES_lib_objs = \
	$(OBJDIR)/pcre.o \
	$(EOLIST)

else

FILES_lib_objs = \
	$(OBJDIR)/chartables.o \
	$(OBJDIR)/pcre_compile.o \
	$(OBJDIR)/pcre_exec.o \
	$(OBJDIR)/pcre_fullinfo.o \
	$(OBJDIR)/pcre_globals.o \
	$(OBJDIR)/pcre_newline.o \
	$(OBJDIR)/pcre_tables.o \
	$(OBJDIR)/pcre_version.o \
	$(EOLIST)
ifeq "$(wildcard $(PCRE)/pcre_try_flipped.c)" "$(PCRE)/pcre_try_flipped.c"
FILES_lib_objs += \
	$(OBJDIR)/pcre_try_flipped.o \
	$(EOLIST)
endif 

XDEFINES += -DHAVE_CONFIG_H

endif

#
# implement targets and dependancies (leave this section alone)
#

libs :: $(OBJDIR) $(TARGET_lib)

nlms :: libs $(TARGET_nlm)

#
# Updated this target to create necessary directories and copy files to the
# correct place.  (See $(AP_WORK)/build/NWGNUhead.inc for examples)
#
MKCNF	= $(AWK) -v BDIR=$(BASEDIR) -v PORT=$(PORT) -v SSLPORT=$(SSLPORT) -v MODSSL=$(WITH_MOD_SSL) -v BSDSKT=$(USE_STDSOCKETS) -f build/mkconfNW.awk $1 > $2

install :: nlms instscripts FORCE
	$(call COPY,$(OBJDIR)/$(NLM_NAME).nlm,                         $(INSTALLBASE)/)
	$(call COPY,ABOUT_APACHE,                                      $(INSTALLBASE)/)
	$(call COPY,CHANGES,                                           $(INSTALLBASE)/)
	$(call COPY,LICENSE,                                           $(INSTALLBASE)/)
	$(call COPY,README,                                            $(INSTALLBASE)/)
	$(call COPY,VERSIONING,                                        $(INSTALLBASE)/)
	$(call COPY,STATUS,                                            $(INSTALLBASE)/)
	$(call COPY,support/dbmmanage.in,                              $(INSTALLBASE)/bin/dbmmanage.pl)
	$(call COPY,support/logresolve.pl.in,                          $(INSTALLBASE)/bin/logresolve.pl)
	$(call COPY,support/split-logfile.in,                          $(INSTALLBASE)/bin/split-logfile.pl)
	$(call COPY,support/check_forensic,                            $(INSTALLBASE)/bin/check_forensic.sh)
	$(call COPY,docs/conf/magic,                                   $(INSTALLBASE)/conf/)
	$(call COPY,docs/conf/mime.types,                              $(INSTALLBASE)/conf/)
	$(call COPY,docs/conf/charset.conv,                            $(INSTALLBASE)/conf/)
	$(call COPY,docs/cgi-examples/printenv,                        $(INSTALLBASE)/cgi-bin/printenv.pl)
	$(call MKCNF,docs/conf/httpd.conf.in,                          $(INSTALLBASE)/conf/httpd.conf)
	$(call MKCNF,docs/conf/extra/httpd-autoindex.conf.in,          $(INSTALLBASE)/conf/extra/httpd-autoindex.conf)
	$(call MKCNF,docs/conf/extra/httpd-dav.conf.in,                $(INSTALLBASE)/conf/extra/httpd-dav.conf)
	$(call MKCNF,docs/conf/extra/httpd-default.conf.in,            $(INSTALLBASE)/conf/extra/httpd-default.conf)
	$(call MKCNF,docs/conf/extra/httpd-info.conf.in,               $(INSTALLBASE)/conf/extra/httpd-info.conf)
	$(call MKCNF,docs/conf/extra/httpd-languages.conf.in,          $(INSTALLBASE)/conf/extra/httpd-languages.conf)
	$(call MKCNF,docs/conf/extra/httpd-manual.conf.in,             $(INSTALLBASE)/conf/extra/httpd-manual.conf)
	$(call MKCNF,docs/conf/extra/httpd-mpm.conf.in,                $(INSTALLBASE)/conf/extra/httpd-mpm.conf)
	$(call MKCNF,docs/conf/extra/httpd-multilang-errordoc.conf.in, $(INSTALLBASE)/conf/extra/httpd-multilang-errordoc.conf)
	$(call MKCNF,docs/conf/extra/httpd-userdir.conf.in,            $(INSTALLBASE)/conf/extra/httpd-userdir.conf)
	$(call MKCNF,docs/conf/extra/httpd-vhosts.conf.in,             $(INSTALLBASE)/conf/extra/httpd-vhosts.conf)
	$(call MKCNF,docs/conf/extra/httpd-ssl.conf.in,                $(INSTALLBASE)/conf/extra/httpd-ssl.conf)
	$(call COPYR,docs/docroot,                                     $(INSTALLBASE)/htdocs)
	$(call COPYR,docs/error,                                       $(INSTALLBASE)/error)
	$(call COPYR,docs/icons,                                       $(INSTALLBASE)/icons)
	$(call COPYR,docs/man,                                         $(INSTALLBASE)/man)
	$(call COPYR,docs/manual,                                      $(INSTALLBASE)/manual)

installdev :: FORCE
	$(call COPY,$(SRC)/include/*.h,                                $(INSTALLBASE)/include/)
	$(call COPY,$(NWOS)/*.h,                                       $(INSTALLBASE)/include/)
	$(call COPY,$(APR)/include/*.h,                                $(INSTALLBASE)/include/)
	$(call COPY,$(APRUTIL)/include/*.h,                            $(INSTALLBASE)/include/)
	$(call COPY,$(STDMOD)/cache/mod_cache.h,                       $(INSTALLBASE)/include/)
	$(call COPY,$(STDMOD)/database/mod_dbd.h,                      $(INSTALLBASE)/include/)
	$(call COPY,$(STDMOD)/dav/main/mod_dav.h,                      $(INSTALLBASE)/include/)
	$(call COPY,$(STDMOD)/filters/mod_include.h,                   $(INSTALLBASE)/include/)
	$(call COPY,$(STDMOD)/generators/mod_cgi.h,                    $(INSTALLBASE)/include/)
	$(call COPY,$(STDMOD)/generators/mod_status.h,                 $(INSTALLBASE)/include/)
	$(call COPY,$(STDMOD)/loggers/mod_log_config.h,                $(INSTALLBASE)/include/)
	$(call COPY,$(STDMOD)/mappers/mod_rewrite.h,                   $(INSTALLBASE)/include/)
	$(call COPY,$(STDMOD)/proxy/mod_proxy.h,                       $(INSTALLBASE)/include/)
	$(call COPY,$(STDMOD)/ssl/mod_ssl.h,                           $(INSTALLBASE)/include/)
	$(call COPY,$(APR)/*.imp,                                      $(INSTALLBASE)/lib/)
	$(call COPY,$(NWOS)/*.imp,                                     $(INSTALLBASE)/lib/)
	$(call COPY,$(NWOS)/*.xdc,                                     $(INSTALLBASE)/lib/)
	$(call COPY,$(APBUILD)/NWGNU*.inc,                             $(INSTALLBASE)/build/)

prebuild :: FORCE
	$(MAKE) -C $(SERVER) -f NWGNUmakefile
	$(MAKE) -C $(PCRE) -f NWGNUmakefile
	$(call MKDIR,$(PREBUILD_INST))
	$(call COPY,$(SERVER)/$(OBJDIR)/*.nlm,                         $(PREBUILD_INST)/)
	$(call COPY,$(PCRE)/$(OBJDIR)/*.nlm,                           $(PREBUILD_INST)/)

#
# Any specialized rules here
#

vpath %.c server:modules/arch/netware:modules/http:modules/aaa:modules/mappers
vpath %.c modules/generators:modules/metadata:modules/filters:modules/loggers
vpath %.c os/netware:server/mpm/netware:$(PCRE)

#
# Include the 'tail' makefile that has targets that depend on variables defined
# in this makefile
#

include $(APBUILD)/NWGNUtail.inc

include $(AP_WORK)/build/NWGNUscripts.inc


