# $Id$

-include $(GNUSTEP_MAKEFILES)/common.make

# config

APACHE = /usr
APXS   = $(APACHE)/sbin/apxs
HTTPD  = $(APACHE)/sbin/httpd

ifneq ($(apxs),no)
ifneq ($(apxs),yes)
ifneq ($(apxs),)
APXS=$(apxs)
else
APXS=$(shell which apxs)
endif
else
APXS=$(shell which apxs)
endif
else
APXS=
endif

APACHE_VERSION = $(shell ./apversion.sh -v ${HTTPD} | head -n 1)
#APACHE_SSL     = $(shell ./apversion.sh -iseapi ${HTTPD})
APACHE_SSL     =

ifneq ($(APXS),)
ifneq ($(shared),no)
APXS_CFLAGS       = $(shell $(APXS) -q CFLAGS_SHLIB) $(shell $(APXS) -q CFLAGS)
APXS_INCLUDE_DIRS = -I$(shell $(APXS) -q INCLUDEDIR)
APXS_LIBS         = -l$(shell$ (APXS) -q LIBS_SHLIB)
APXS_LDFLAGS      = $(shell $(APXS) -q LDFLAGS_SHLIB)
else
ifneq ($(APXS),)
APXS_CFLAGS       = $(shell $(APXS) -q CFLAGS)
APXS_INCLUDE_DIRS = -I$(shell $(APXS) -q INCLUDEDIR)
else
APXS_CFLAGS       = 
APXS_INCLUDE_DIRS = 
endif
endif
else # no apxs available

APXS_CFLAGS="-DSHARED_MODULE -O2 -DEAPI_MM -fPIC -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHARD_SERVER_LIMIT=2048 -DDYNAMIC_MODULE_LIMIT=128 -DLINUX=22 -DMOD_SSL=208103 -DEAPI -DUSE_EXPAT"

endif

GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT)/Library/WOAdaptors/Apache

CC            = gcc
LD            = gcc
SHARED_LIBEXT = .so

CFLAGS  = -Wall -I. -fPIC $(APXS_CFLAGS) $(APXS_INCLUDE_DIRS)
LDFLAGS = $(APXS_LDFLAGS) -shared -fPIC

# adaptor

OFILES = \
	globals.o		\
	handler.o		\
	NGBufferedDescriptor.o	\
	scanhttp.o		\
	sns.o			\
	config.o		\
	ngobjweb_module.o	\

ifeq ($(APACHE_SSL),yes)
APACHE_SSL=ssl
else
APACHE_SSL=
endif

product = ngobjweb$(APACHE_SSL)_$(APACHE_VERSION)$(SHARED_LIBEXT)

all : $(product)

clean : 
	rm -f *.o $(product) *.so *~

apache-dir :
	$(MKDIRS) $(GNUSTEP_INSTALLATION_DIR)

install : apache-dir all
	$(INSTALL_PROGRAM) $(product) $(GNUSTEP_INSTALLATION_DIR)

$(product) : $(OFILES)
	$(LD) $(LDFLAGS) -o $@ $(OFILES) $(EXTRA_LDFLAGS)