include ../make.config


# Set up a bunch of environment settings
SHELL = /bin/sh

#INCLUDES = -I${APACHEINCLUDE_DIR} -I../Adaptor
INCLUDES = ${APACHE_INCL_FLAGS} -I../Adaptor

# Common compiler and linker flags
CFLAGS = -O2 -Wall ${INCLUDES} ${DEBUG_FLAG} -DSINGLE_THREADED_ADAPTOR -D${OS} -DFORKING_WEBSERVER -DAPACHE ${ENABLE_SSL_SUPPORT}

APXSFLAGS = -c -S CC=${CC} -Wc,"${CFLAGS}" -Wl,"${LDFLAGS}"



ifeq "LINUX" "${OS}"
# Flags for use when enabling mod_ssl support
ENABLE_SSL_SUPPORT =-DAPACHE_SECURITY_ENABLED
# These should be set to point at the ssl include and lib directories, respectively.
OPENSSL_INCL_FLAGS =-I/usr/include/openssl
OPENSSL_LIB_FLAGS = -L/usr/lib -lcrypto -lssl

# If Apache is in a nonstandard location, change this
#APACHE_INCL_FLAGS = -I/usr/local/apache2/include
APACHE_INCL_FLAGS = -I/usr/include/apache2 -I/usr/include/apr-1.0

CFLAGS +=-DEAPI -fPIC ${APACHE_INCL_FLAGS} -fno-stack-protector
LDFLAGS +=-G -L/lib -lc ${OPENSSL_LIB_FLAGS}
APXSFLAGS = -c
endif
# End Linux Config


# Build steps
# Get the list of source files from the ../Adaptor directory and change their extension to .o
	COMMON_SRCFILES := $(wildcard ../Adaptor/*.c)
#COMMON_OBJFILES := $(patsubst %.c, %.o, $(wildcard ../Adaptor/*.c))
	COMMON_OBJFILES := $(patsubst ../Adaptor/%.c, %.o, $(wildcard ../Adaptor/*.c))
# The same list as above but with the .lo extension (libtool object, FWIW)
	lo_objects = $(patsubst ../Adaptor/%.c, %.lo, $(wildcard ../Adaptor/*.c))


all:	mod_WebObjects.so

# The objects target compiles all the .c files, except mod_WebObjects.c, which we want
# libtool (through apxs or otherwise) to take care of.
$(COMMON_OBJFILES) : %.o : ../Adaptor/%.c
	$(CC) $(CFLAGS) -c $<



# LINUX Section mostly from Senmeisha, Inc.'s Makefile. Thanks.
ifeq "LINUX" "${OS}"
#echo "${OS}"
mod_WebObjects.so : mod_WebObjects.o ${COMMON_OBJFILES}
	ld ${LDFLAGS} mod_WebObjects.o ${COMMON_OBJFILES} -o mod_WebObjects.so
	${APXS} ${APXSFLAGS} mod_WebObjects.so

mod_WebObjects.o : mod_WebObjects.c ${COMMON_OBJFILES}
	${CC} -c ${CFLAGS} mod_WebObjects.c ${COMMON_OBJFILES}
endif
#end Linux


# The install target does what you'd think it would: install the module; By default, this is not called.
install: mod_WebObjects.la
ifeq "MACOS" "${OS}"
	${APXS} -i -a -n WebObjects mod_WebObjects.la
else
	# This works on Linux at least, while the above leads to:
	# "Can't locate API module structure `WebObjects_module' in file .../modules/mod_WebObjects.so: 
	# .../modules/mod_WebObjects.so: undefined symbol: WebObjects_module"
	${APXS} -i -a -n WebObjects mod_WebObjects.so
endif

clean:
	-rm -rf mod_WebObjects.la *.o *.lo *.so *.slo .libs

.PHONY: clean install



