# Makefile for 'ZLIB PHP Extension for NetWare'
# This makefile uses GNU make, MetroWerks CodeWarrior
# MWCCNLM.EXE as compiler and MWLDNLM.EXE as linker.
#
# 2004 Ulrich Neumann
#
.suffix   : .c .def .lnk .nlm

# Set the folder for zlib and php here:
ZLIBSRC = /A_UNIX_NW/usr/src_libs/zlib-1.2.1

ifndef NOVELLLIBC
NOVELLLIBC = C:/novell/ndk/libc
endif

ifndef METROWERKS
METROWERKS = C:\Program Files\Metrowerks\CodeWarrior
endif

ifndef MWCIncludes
MWCIncludes = C:\novell\ndk\libc\include
endif

DESCRIPTION	= "PHP ZLIB Extension"
COPYRIGHT	= "Copyright (c) 1997-2001 The PHP Group. All rights reserved.                     NetWare Port 2004 by Ulrich Neumann (http://neumann.gne.de)"
VERSION		= 1,0,0

DEBUG_FLAG = debug

# Novell NLM tools
MPKLISTER = MPKXDC

# MetroWerks NLM tools
CC	= mwccnlm
CPP	= mwccnlm
LD	= mwldnlm
LIB	= mwldnlm -type library -w nocmdline

NOVI	= ${NOVELLLIBC}/imports
INCLUDES = -I. -I.. -I$(ZLIBSRC) -I../../../Zend -I../../../TSRM -I../../../main -I../../../ -I../../standard

# Base compile flags
# and prefix or precompiled header added here.

# The default flags are as follows:
#
# -c                    compile only, no link
# -nosyspath            treat #include <...> like #include "..."
# -Cpp_exceptions off   disable C++ exceptions
# -RTTI off             disable C++ run-time typing information
# -align 4              align on 4 byte bounderies
# -w nocmdline          disable command-line driver/parser warnings
# -proc PII             generate code base on Pentium II instruction set
# -inst mmx             use MMX extensions

CFLAGS = -c -nosyspath -msgstyle gcc -align 4 -wchar_t on -bool on -Cpp_exceptions off -RTTI off -relax_pointers -w nocmdline -proc PII -DNETWARE -DZTS -D__BIT_TYPES_DEFINED -DCOMPILE_DL_ZLIB -DZEND_DEBUG=0

#define ZEND_DEBUG 0
LDFLAGS = -w nocmdline -stacksize 32768 -flags autounload -nlmversion $(VERSION) -copy $(COPYRIGHT) -type generic -zerobss

#                      generate internal debug symbols
ifeq "$(DEBUG_FLAG)" "debug"
CFLAGS += -g -O1
endif

# -O4,p                 level 4 optimizations, optimize for speed
ifeq "$(DEBUG_FLAG)" "optimized"
CFLAGS += -O4,p
endif

OBJS = zlib.o zlib_fopen_wrapper.o

.c.o:
	$(CC) $(CFLAGS) $(INCLUDES) $<


php_zlib: nlm.def dllmain.o $(OBJS)
	$(LD) $(LDFLAGS) -commandfile nlm.def -o $@.nlm ${OBJS} dllmain.o "${NOVI}/libcpre.o"

#- Link-definition file -------------------------------------------------------
# Target to build the link definition file which will direct the linker.
#
nlm.def	: libc.xdc
	@echo Creating NLM link parameters in nlm.def...
	@echo Module		LIBC.NLM PHPLIB.NLM LIBZ.NLM			>  nlm.def
	@echo Description	'$(DESCRIPTION)'				>> nlm.def
	@echo XDCData		libc.xdc					>> nlm.def
	@echo Flag_On 		0x00000008					>> nlm.def
	@echo Start 		_LibCPrelude					>> nlm.def
	@echo Exit 		_LibCPostlude					>> nlm.def
	@echo Import		'@C:\novell\ndk\libc\imports\netware.imp'	>> nlm.def
	@echo Import		'@C:\novell\ndk\libc\imports\libc.imp'		>> nlm.def
	@echo Import		'@..\..\..\netware\phplib.imp'			>> nlm.def
	@echo Import		'@zlib.imp'					>> nlm.def
	@echo Export		'(php_zlib) get_module'				>> nlm.def
	@echo									>> nlm.def

#- Cross-domain data ----------------------------------------------------------
# Target to produce MPK-unsafe lists when warranted or, in the normal case, an
# XDC record that signals MPK that all functions in the NLM are completely
# MP-safe. These indications are placed in the cross-domain data (XDC) of the
# NLM.
#
# The list or MP-safe record is produced by MPKXDC.Exe and supplied as XDC data
# at link time. The -n switch will mean that all interfaces are MP-safe.
#
libc.xdc:
	@echo ------------------------------------------------------------
	@echo Designating Module as multiprocessor-safe...
	@$(MPKLISTER) -n $@
#-----------------------------------------------------------------------------

clean	:
	@echo Cleanung Up...
	cmd /C del *.o
	cmd /C del *.def
	cmd /C del *.xdc

zlib.o:			../zlib.c
	$(CC) $(CFLAGS) $(INCLUDES) ../zlib.c

zlib_fopen_wrapper.o:	../zlib_fopen_wrapper.c
	$(CC) $(CFLAGS) $(INCLUDES) ../zlib_fopen_wrapper.c

