#
# Makefile for Rexx/CURL Extension
#
# The variable 'srcdir' refers to the source-distribution, and can be set with
# the configure script by "--srcdir=DIR".
#

SHELL		= /bin/sh
THIS		= Makefile

@SET_MAKE@

VER=@VER@
VER_DOT=@VER_DOT@
VER_DATE=@VER_DATE@
PACKAGE=RexxCURL
PACKAGE_DIR=$(PACKAGE)-$(VER_DOT)
PACKAGE_NAME=rexxcurl

srcdir		= @srcdir@
prefix		= @prefix@
exec_prefix	= @exec_prefix@
libdir		= $(exec_prefix)/lib
bindir		= $(exec_prefix)/bin
includedir		= $(exec_prefix)/include
docdir		= $(srcdir)/doc
thisdir		=@thisdir@
commondir		= $(srcdir)/common
sharedir = $(prefix)/share/rexxcurl

INSTALL		= $(srcdir)/install-sh

CC		= @CC@
CFLAGS		= @CFLAGS@

CEXTRA =           @CEXTRA@ @DLFCNINCDIR@
DEBUG =            @DEBUG@
DEBUGGING =        @DEBUGGING@
EEXTRA =           @EEXTRA@
OSAVE  =           @OSAVE@
OBJ  =             @OBJ@
EXE  =             @EXE@
SHLPRE =           @SHLPRE@
SHLPST =           @SHLPST@
LIBPRE =           @LIBPRE@
LIBPST =           @LIBPST@
LIBEXE =           @LIBEXE@
LIBFLAGS =         @LIBFLAGS@
RANLIB =           @RANLIB@
GETOPT  =          @GETOPT@
DYN_COMP  =        @DYN_COMP@
SYS_DEFS  =        @SYS_DEFS@
LIBS  =            @LIBS@ @LEXLIB@
SHLIBS  =          @SHLIBS@ @DLFCNLIBDIR@
LD_RXLIB1  =       @LD_RXLIB1@
LD_RXLIB2  =       @REXX_LIBS@ @MH_EXTRA_LIBS@ $(LIBS) -lc @CURLLIBDIR@ -lcurl @CURLLIBS@
DYNAMIC_LDFLAGS  = @DYNAMIC_LDFLAGS@
SHL_TARGETS  =     @SHL_TARGETS@
O2SAVE  =          @O2SAVE@
O2SHO  =           @O2SHO@
CC2O   =           @CC2O@
SAVE2O  =          @SAVE2O@
PURIFY =           @PURIFY@
OTHER_INSTALLS =   @OTHER_INSTALLS@
BASE_INSTALL =     @BASE_INSTALL@
BASE_BINARY =      @BASE_BINARY@
USE_ABI =          @USE_ABI@
RPMTOPDIR =        @RPMTOPDIR@

@aix_exports@
RXDEFEXP1 =        @RXDEFEXP1@

INCDIR		= $(srcdir)
COMMONDIR = $(commondir)
CPPFLAGS	= -I. -I$(INCDIR) -I$(COMMONDIR) $(DEBUGGING) @DEFS@ @SYS_DEFS@ -DREXXCURL_VERSION=\"$(VER_DOT)\" -DREXXCURL_DATE=\"$(VER_DATE)\"

CCFLAGS		= -c $(CFLAGS) $(CPPFLAGS) @REXX_INCLUDES@ @CURLINCDIR@ @CURLCFLAGS@

LINK		= @PURIFY@ $(CC)
LDFLAGS		= $(DEBUG) @LDFLAGS@ @REXX_LIBS@ @MH_EXTRA_LIBS@ $(LIBS) @CURLLIBDIR@ -lcurl @CURLLIBS@

################################################################################

H1=config.h
H2=$(commondir)/rxpack.h $(commondir)/rxdef.h $(srcdir)/rexxcurl.h

#------------------------------------------------------------------------
include $(commondir)/dist.inc

CSRCFILES = $(PACKAGE_DIR)/$(PACKAGE_NAME).c
ZIPCSRCFILES = $(PACKAGE_NAME).c

HEADERS = $(PACKAGE_DIR)/apphead.h $(PACKAGE_DIR)/$(PACKAGE_NAME).h
ZIPHEADERS = apphead.h $(PACKAGE_NAME).h

OFILES = loader.$(OBJ) rexxcurl.$(OBJ) rxpack.$(OBJ)

SHOFILES = rexxcurl.so.o rxpack.so.o
LIBFILES = rexxcurl.so.o

################################################################################
all:	$(PACKAGE_NAME) $(LIBPRE)$(PACKAGE_NAME)$(LIBPST) $(SHL_TARGETS)

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

distclean: clean
	-rm -f Makefile

mostlyclean: clean

realclean: distclean

# rexxcurl
$(PACKAGE_NAME): $(OFILES) $(GETOPT)
	$(LINK) $(OFILES) $(XTRA_OBJS) -o $(PACKAGE_NAME) $(LDFLAGS)

# librexxcurl.so
$(SHLPRE)$(PACKAGE_NAME)$(SHLPST): $(SHOFILES) $(RXDEFEXP1) $(RXPACKEXP1)
	$(LD_RXLIB1) $(RXPACKEXPORTS1) -o $@ $(SHOFILES) $(LD_RXLIB2)

# librexxcurl.a
$(LIBPRE)$(PACKAGE_NAME)$(LIBPST): $(LIBFILES)
	$(LIBEXE) $(LIBFLAGS) $@ $(LIBFILES)
	-$(RANLIB) $@

#
# executable objects
#
rxpack.o: $(commondir)/rxpack.c $(H1) $(H2)
	$(CC) $(CCFLAGS) -o rxpack.o $(commondir)/rxpack.c

loader.o: $(commondir)/loader.c $(H1) $(H2)
	$(CC) $(CCFLAGS) -o loader.o $(commondir)/loader.c

rexxcurl.o: $(srcdir)/rexxcurl.c $(H1) $(H2)
	$(CC) $(CCFLAGS) -o rexxcurl.o $(srcdir)/rexxcurl.c

getopt.o: $(commondir)/getopt.c $(H1)
	$(CC) $(CCFLAGS) -o getopt.o $(commondir)/getopt.c

#
# shared library objects
#
rexxcurl.so.o : $(srcdir)/rexxcurl.c $(H1) $(H2)
	$(O2SAVE)
	$(CC) $(CCFLAGS) $(CC2O) $(DYN_COMP) $(srcdir)/rexxcurl.c
	$(O2SHO)
	$(SAVE2O)

rxpack.so.o : $(commondir)/rxpack.c $(H1) $(H2)
	$(O2SAVE)
	$(CC) $(CCFLAGS) $(CC2O) $(DYN_COMP) $(commondir)/rxpack.c
	$(O2SHO)
	$(SAVE2O)

#
# export file for AIX
#
$(RXPACKEXP1): $(srcdir)/$(PACKAGE_NAME)w32.def $(srcdir)/def2exp.rexx
	rexx $(srcdir)/def2exp.rexx $(srcdir)/$(PACKAGE_NAME)w32.def $(RXPACKEXP1)

#
# export file for cygwin
#
$(RXDEFEXP1): $(srcdir)/$(PACKAGE_NAME)w32.def $(commondir)/filterexports.rexx
	./rexxcurl $(commondir)/filterexports.rexx CurlQueryFunction $(srcdir)/$(PACKAGE_NAME)w32.def $(RXDEFEXP1)

doco:
	mkdir images
	cp $(docdir)/index.html .
	cp $(docdir)/images/*.png images

zip:
	zip rexxcurl$(VER) README INSTALL TODO COPYING-LIB HISTORY $(ZIPCSRCFILES) $(ZIPHEADERS) $(ZIPCOMMONFILES)
	zip rexxcurl$(VER) Makefile.in Makefile.aix.in configure config.h.in rexxcurl-config.in
	zip rexxcurl$(VER) makefile.* *.def *.ico *.rc rexxcurl.ver
	zip rexxcurl$(VER) config.guess config.sub install-sh preinst.rexx
	zip rexxcurl$(VER) aclocal.m4 configure.in def2exp.rexx
	zip rexxcurl$(VER) demo/*.rexx demo/README.txt makew32.rex
	zip rexxcurl$(VER) doc/*.html doc/images/*.png
	zip rexxcurl$(VER) RexxCURL.spec rxcurl64.xpm

dist:
	(cd $(srcdir)/..;rm -f $(PACKAGE_DIR))
	(cd $(srcdir)/..;ln -sf RexxCURL $(PACKAGE_DIR))
	(cd $(srcdir)/..; tar cvf - \
	$(PACKAGE_DIR)/README $(PACKAGE_DIR)/INSTALL $(PACKAGE_DIR)/TODO $(PACKAGE_DIR)/COPYING-LIB $(PACKAGE_DIR)/HISTORY $(CSRCFILES) $(HEADERS) $(COMMONFILES) \
	$(PACKAGE_DIR)/Makefile.in $(PACKAGE_DIR)/Makefile.aix.in $(PACKAGE_DIR)/configure $(PACKAGE_DIR)/config.h.in $(PACKAGE_DIR)/rexxcurl-config.in \
	$(PACKAGE_DIR)/makefile.* $(PACKAGE_DIR)/*.def $(PACKAGE_DIR)/*.ico $(PACKAGE_DIR)/*.rc $(PACKAGE_DIR)/rexxcurl.ver \
	$(PACKAGE_DIR)/config.guess $(PACKAGE_DIR)/config.sub $(PACKAGE_DIR)/install-sh $(PACKAGE_DIR)/preinst.rexx \
	$(PACKAGE_DIR)/aclocal.m4 $(PACKAGE_DIR)/configure.in $(PACKAGE_DIR)/def2exp.rexx \
	$(PACKAGE_DIR)/demo/*.rexx $(PACKAGE_DIR)/demo/README.txt $(PACKAGE_DIR)/makew32.rex \
	$(PACKAGE_DIR)/doc/*.html $(PACKAGE_DIR)/doc/images/*.png \
	$(PACKAGE_DIR)/rxcurl64.xpm $(PACKAGE_DIR)/RexxCURL.spec \
	| gzip > $(PACKAGE_DIR).tar.gz)
	(cd $(srcdir)/..;rm -f $(PACKAGE_DIR))

install: $(BASE_INSTALL)

installbase: all
	$(INSTALL) -d $(DESTDIR)$(bindir)
	$(INSTALL) -d $(DESTDIR)$(libdir)
	$(INSTALL) -d $(DESTDIR)$(sharedir)
	$(INSTALL) -d $(DESTDIR)$(sharedir)/images
	$(INSTALL) -c -m 755 ./$(PACKAGE_NAME) $(DESTDIR)$(bindir)/$(PACKAGE_NAME)$(EXE)
	$(INSTALL) -c -m 755 ./rexxcurl-config $(DESTDIR)$(bindir)/rexxcurl-config
	-$(INSTALL) -c -m 755 ./$(SHLPRE)$(PACKAGE_NAME)$(SHLPST) $(DESTDIR)$(libdir)/$(SHLPRE)$(PACKAGE_NAME)$(SHLPST)
	$(INSTALL) -c -m 755 ./$(LIBPRE)$(PACKAGE_NAME)$(LIBPST) $(DESTDIR)$(libdir)/$(LIBPRE)$(PACKAGE_NAME)$(LIBPST)
	$(DESTDIR)$(bindir)/$(PACKAGE_NAME) $(srcdir)/preinst.rexx $(bindir)/$(PACKAGE_NAME) $(srcdir)/demo/testcurl.rexx $(DESTDIR)$(sharedir)/testcurl.rexx
	-chmod 755 $(DESTDIR)$(sharedir)/testcurl.rexx
	$(DESTDIR)$(bindir)/$(PACKAGE_NAME) $(srcdir)/preinst.rexx $(bindir)/$(PACKAGE_NAME) $(srcdir)/demo/httppost.rexx $(DESTDIR)$(sharedir)/httppost.rexx
	-chmod 755 $(DESTDIR)$(sharedir)/httppost.rexx
	$(DESTDIR)$(bindir)/$(PACKAGE_NAME) $(srcdir)/preinst.rexx $(bindir)/$(PACKAGE_NAME) $(srcdir)/demo/mirror.rexx $(DESTDIR)$(sharedir)/mirror.rexx
	-chmod 755 $(DESTDIR)$(sharedir)/mirror.rexx
	$(DESTDIR)$(bindir)/$(PACKAGE_NAME) $(srcdir)/preinst.rexx $(bindir)/$(PACKAGE_NAME) $(srcdir)/demo/scp.rexx $(DESTDIR)$(sharedir)/scp.rexx
	-chmod 755 $(DESTDIR)$(sharedir)/scp.rexx
	$(DESTDIR)$(bindir)/$(PACKAGE_NAME) $(srcdir)/preinst.rexx $(bindir)/$(PACKAGE_NAME) $(srcdir)/demo/upload.rexx $(DESTDIR)$(sharedir)/upload.rexx
	-chmod 755 $(DESTDIR)$(sharedir)/upload.rexx
	$(DESTDIR)$(bindir)/$(PACKAGE_NAME) $(srcdir)/preinst.rexx $(bindir)/$(PACKAGE_NAME) $(srcdir)/demo/getright.rexx $(DESTDIR)$(sharedir)/getright.rexx
	-chmod 755 $(DESTDIR)$(sharedir)/getright.rexx
	$(INSTALL) -c -m 644 $(srcdir)/demo/README.txt $(DESTDIR)$(sharedir)/README.txt
	$(INSTALL) -c -m 644 $(docdir)/index.html $(DESTDIR)$(prefix)/share/doc/$(PACKAGE_DIR)/index.html
	$(INSTALL) -c -m 644 $(docdir)/images/rxcurl64.png $(DESTDIR)$(prefix)/share/doc/$(PACKAGE_DIR)/images/rxcurl64.png

cygwininstall: installbase
	mv $(DESTDIR)$(libdir)/$(SHLPRE)$(PACKAGE_NAME)$(SHLPST) $(DESTDIR)$(bindir)/$(SHLPRE)$(PACKAGE_NAME)$(SHLPST)

beosinstall: all
	$(INSTALL) -d /boot/home/config/bin
	$(INSTALL) -d /boot/home/config/lib
	$(INSTALL) -d /boot/home/config/add-ons/rexx
	$(INSTALL) -m 755 -c ./$(PACKAGE_NAME) /boot/home/config/bin/$(PACKAGE_NAME)
	$(INSTALL) -m 755 -c ./rexxcurl-config $(bindir)/rexxcurl-config
	$(INSTALL) -m 755 -c ./$(SHLPRE)$(PACKAGE_NAME)$(SHLPST) /boot/home/config/add-ons/rexx/$(SHLPRE)$(PACKAGE_NAME)$(SHLPST)
	$(INSTALL) -m 755 -c ./$(LIBPRE)$(PACKAGE_NAME)$(LIBPST) /boot/home/config/lib/$(LIBPRE)$(PACKAGE_NAME)$(LIBPST)
	./$(PACKAGE_NAME) $(srcdir)/preinst.rexx /boot/home/config/bin/$(PACKAGE_NAME) $(srcdir)/demo/testcurl.rexx /boot/home/config/bin/rexx/testcurl.rexx
	-chmod 755 /boot/home/config/bin/rexx/testcurl.rexx
	./$(PACKAGE_NAME) $(srcdir)/preinst.rexx /boot/home/config/bin/$(PACKAGE_NAME) $(srcdir)/demo/httppost.rexx /boot/home/config/bin/rexx/httppost.rexx
	-chmod 755 /boot/home/config/bin/rexx/httppost.rexx
	./$(PACKAGE_NAME) $(srcdir)/preinst.rexx /boot/home/config/bin/$(PACKAGE_NAME) $(srcdir)/demo/mirror.rexx /boot/home/config/bin/rexx/mirror.rexx
	-chmod 755 /boot/home/config/bin/rexx/mirror.rexx
	./$(PACKAGE_NAME) $(srcdir)/preinst.rexx /boot/home/config/bin/$(PACKAGE_NAME) $(srcdir)/demo/scp.rexx /boot/home/config/bin/rexx/scp.rexx
	-chmod 755 /boot/home/config/bin/rexx/scp.rexx
	./$(PACKAGE_NAME) $(srcdir)/preinst.rexx /boot/home/config/bin/$(PACKAGE_NAME) $(srcdir)/demo/upload.rexx /boot/home/config/bin/rexx/upload.rexx
	-chmod 755 /boot/home/config/bin/rexx/upload.rexx
	./$(PACKAGE_NAME) $(srcdir)/preinst.rexx /boot/home/config/bin/$(PACKAGE_NAME) $(srcdir)/demo/getright.rexx /boot/home/config/bin/rexx/getright.rexx
	-chmod 755 /boot/home/config/bin/rexx/getright.rexx
	$(INSTALL) -c -m 644 $(srcdir)/demo/README.txt /boot/home/config/bin/rexx/README-rexxcurl.txt
#
# where to put doc for BeOS ?
#	$(INSTALL) -c -m 644 $(docdir)/index.html $(DESTDIR)$(sharedir)/index.html
#	$(INSTALL) -c -m 644 $(docdir)/images/rxcurl64.png $(DESTDIR)$(sharedir)/images/rxcurl64.png
#

binary: $(BASE_BINARY)

binarybase: all
	-rm -fr ./tmpdir
	-mkdir -p ./tmpdir/bin
	-mkdir -p ./tmpdir/lib
	-mkdir -p ./tmpdir/rexx
	-mkdir -p ./tmpdir/doc/rexxcurl
	-mkdir -p ./tmpdir/doc/rexxcurl/images
	cp $(PACKAGE_NAME) ./tmpdir/bin
	cp $(SHLPRE)$(PACKAGE_NAME)$(SHLPST) ./tmpdir/lib
	cp $(LIBPRE)$(PACKAGE_NAME)$(LIBPST) ./tmpdir/lib
	cp $(srcdir)/COPYING-LIB ./tmpdir/doc/rexxcurl
	cp $(srcdir)/HISTORY ./tmpdir/doc/rexxcurl
	cp $(srcdir)/INSTALL ./tmpdir/doc/rexxcurl
	cp $(srcdir)/README ./tmpdir/doc/rexxcurl
	cp $(srcdir)/TODO ./tmpdir/doc/rexxcurl
	cp $(srcdir)/doc/index.html ./tmpdir/doc/rexxcurl
	cp $(srcdir)/doc/images/*.png ./tmpdir/doc/rexxcurl/images
	cp $(srcdir)/demo/testcurl.rexx ./tmpdir/rexx/testcurl.rexx
	cp $(srcdir)/demo/httppost.rexx ./tmpdir/rexx/httppost.rexx
	cp $(srcdir)/demo/mirror.rexx ./tmpdir/rexx/mirror.rexx
	cp $(srcdir)/demo/scp.rexx ./tmpdir/rexx/scp.rexx
	cp $(srcdir)/demo/upload.rexx ./tmpdir/rexx/upload.rexx
	cp $(srcdir)/demo/getright.rexx ./tmpdir/rexx/getright.rexx
	cp $(srcdir)/demo/README.txt ./tmpdir/rexx/README.txt
	(cd ./tmpdir; \
	tar cvf - * | gzip > ../$(PACKAGE_DIR).$(target).$(REXX_TARGET).tgz )

cygwinbinary: all
	-rm -fr ./tmpdir
	-mkdir -p ./tmpdir/bin
	-mkdir -p ./tmpdir/lib
	-mkdir -p ./tmpdir/rexx
	-mkdir -p ./tmpdir/doc/rexxcurl
	-mkdir -p ./tmpdir/doc/rexxcurl/images
	cp $(PACKAGE_NAME).exe ./tmpdir/bin
	cp $(SHLPRE)$(PACKAGE_NAME)$(SHLPST) ./tmpdir/bin
	cp $(LIBPRE)$(PACKAGE_NAME)$(LIBPST) ./tmpdir/lib
	cp $(srcdir)/COPYING-LIB ./tmpdir/doc/rexxcurl
	cp $(srcdir)/HISTORY ./tmpdir/doc/rexxcurl
	cp $(srcdir)/INSTALL ./tmpdir/doc/rexxcurl
	cp $(srcdir)/README ./tmpdir/doc/rexxcurl
	cp $(srcdir)/TODO ./tmpdir/doc/rexxcurl
	cp $(srcdir)/doc/index.html ./tmpdir/doc/rexxcurl
	cp $(srcdir)/doc/images/*.png ./tmpdir/doc/rexxcurl/images
	cp $(srcdir)/demo/testcurl.rexx ./tmpdir/rexx/testcurl.rexx
	cp $(srcdir)/demo/httppost.rexx ./tmpdir/rexx/httppost.rexx
	cp $(srcdir)/demo/mirror.rexx ./tmpdir/rexx/mirror.rexx
	cp $(srcdir)/demo/scp.rexx ./tmpdir/rexx/scp.rexx
	cp $(srcdir)/demo/upload.rexx ./tmpdir/rexx/upload.rexx
	cp $(srcdir)/demo/getright.rexx ./tmpdir/rexx/getright.rexx
	cp $(srcdir)/demo/README.txt ./tmpdir/rexx/README.txt
	(cd ./tmpdir; \
	tar cvf - * | gzip > ../$(PACKAGE_DIR).$(target).$(REXX_TARGET).tgz )

beosbinary: all
	-rm -fr ./tmpdir
	-mkdir -p ./tmpdir/bin
	-mkdir -p ./tmpdir/lib
	-mkdir -p ./tmpdir/add-ons/rexx
	-mkdir -p ./tmpdir/doc/rexxcurl
	-mkdir -p ./tmpdir/doc/rexxcurl/images
	cp $(PACKAGE_NAME) ./tmpdir/bin
	cp $(SHLPRE)$(PACKAGE_NAME)$(SHLPST) ./tmpdir/add-ons/rexx
	cp $(LIBPRE)$(PACKAGE_NAME)$(LIBPST) ./tmpdir/lib
	cp $(srcdir)/COPYING-LIB ./tmpdir/doc/rexxcurl
	cp $(srcdir)/HISTORY ./tmpdir/doc/rexxcurl
	cp $(srcdir)/INSTALL ./tmpdir/doc/rexxcurl
	cp $(srcdir)/README ./tmpdir/doc/rexxcurl
	cp $(srcdir)/TODO ./tmpdir/doc/rexxcurl
	cp $(srcdir)/doc/index.html ./tmpdir/doc/rexxcurl
	cp $(srcdir)/doc/images/*.png ./tmpdir/doc/rexxcurl/images
	cp $(srcdir)/demo/testcurl.rexx ./tmpdir/rexx/testcurl.rexx
	cp $(srcdir)/demo/httppost.rexx ./tmpdir/rexx/httppost.rexx
	cp $(srcdir)/demo/mirror.rexx ./tmpdir/rexx/mirror.rexx
	cp $(srcdir)/demo/scp.rexx ./tmpdir/rexx/scp.rexx
	cp $(srcdir)/demo/upload.rexx ./tmpdir/rexx/upload.rexx
	cp $(srcdir)/demo/getright.rexx ./tmpdir/rexx/getright.rexx
	cp $(srcdir)/demo/README.txt ./tmpdir/rexx/README.txt
	(cd ./tmpdir; \
	zip -r $(PACKAGE_DIR).BeOS.zip * )

rpm:
	cp $(srcdir)/rxcurl64.xpm $(RPMTOPDIR)/SOURCES
	cp $(srcdir)/../$(PACKAGE_DIR).tar.gz $(RPMTOPDIR)/SOURCES
	rpmbuild -ba $(srcdir)/$(PACKAGE).spec
#
# End of makefile
#

