#
# Makefile for Rexx/CURL Extension for AIX
#
# 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=12
VER_DOT=1.2
PACKAGE_DIR=RexxCURL-$(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@
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@
BASE_INSTALL =     @BASE_INSTALL@
BASE_BINARY =      @BASE_BINARY@
rexxtrans_lib_name=@rexxtrans_lib_name@

INCDIR		= $(srcdir)
COMMONDIR = $(commondir)
CPPFLAGS	= -I. -I$(INCDIR) -I$(COMMONDIR) $(DEBUGGING) @DEFS@ @SYS_DEFS@

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

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

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

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

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

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

distclean: clean
	-rm -f Makefile

mostlyclean: clean

realclean: distclean

#------------------------------------------------------------------------

CSRCFILES = $(PACKAGE_DIR)/common/getopt.c $(PACKAGE_DIR)/common/loader.c $(PACKAGE_DIR)/rexxcurl.c $(PACKAGE_DIR)/common/rxpack.c
ZIPCSRCFILES = $(commondir)/getopt.c $(commondir)/loader.c rexxcurl.c $(commondir)/rxpack.c

HEADERS = $(PACKAGE_DIR)/defines.h $(PACKAGE_DIR)/common/rxdef.h $(PACKAGE_DIR)/common/rxpack.h $(PACKAGE_DIR)/apphead.h $(PACKAGE_DIR)/rexxcurl.h
ZIPHEADERS = defines.h $(commondir)/rxdef.h $(commondir)/rxpack.h apphead.h rexxcurl.h

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

SHOFILES = rexxcurl.sho rxpack.sho 

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

# librexxcurl.a
$(SHLPRE)$(PACKAGE_NAME)$(SHLPST): $(SHOFILES) rexxcurl.exp
	$(LD_RXLIB1) -bE:rexxcurl.exp -o $@ $(SHOFILES) $(LD_RXLIB2)

#
# 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.sho : $(srcdir)/rexxcurl.c $(H1) $(H2)
	$(O2SAVE)
	$(CC) $(CCFLAGS) $(CC2O) $(DYN_COMP) $(srcdir)/rexxcurl.c
	$(O2SHO)
	$(SAVE2O)

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

#
# export files for AIX
#
rexxcurl.exp: $(srcdir)/rexxcurlw32.def $(srcdir)/def2exp.rexx
	rexx $(srcdir)/def2exp.rexx $(srcdir)/rexxcurlw32.def rexxcurl.exp

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

dist:
	(cd $(srcdir)/..; tar cvf - \
	$(PACKAGE_DIR)/README $(PACKAGE_DIR)/INSTALL $(PACKAGE_DIR)/TODO $(PACKAGE_DIR)/COPYING-LIB $(PACKAGE_DIR)/HISTORY $(CSRCFILES) $(HEADERS) \
	$(PACKAGE_DIR)/Makefile.in $(PACKAGE_DIR)/Makefile.aix.in $(PACKAGE_DIR)/configure $(PACKAGE_DIR)/config.h.in \
	$(PACKAGE_DIR)/makefile.* $(PACKAGE_DIR)/file_id.* $(PACKAGE_DIR)/*.def $(PACKAGE_DIR)/*.ico $(PACKAGE_DIR)/*.rc \
	$(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)/makedist.cmd \
	$(PACKAGE_DIR)/demo/*.rexx $(PACKAGE_DIR)/makew32.rex \
	$(PACKAGE_DIR)/doc/*.html $(PACKAGE_DIR)/doc/*.png $(PACKAGE_DIR)/*.spec \
	| gzip > $(PACKAGE_DIR).tar.gz)

install: $(BASE_INSTALL)

installbase: all
	$(INSTALL) -m 755 -d $(bindir)
	$(INSTALL) -m 755 -d $(libdir)
	$(INSTALL) -m 755 -d $(sharedir)
	$(INSTALL) -c -m 755 ./$(PACKAGE_NAME) $(bindir)/$(PACKAGE_NAME)
	-$(INSTALL) -c -m 755 ./$(SHLPRE)$(PACKAGE_NAME)$(SHLPST) $(libdir)/$(SHLPRE)$(PACKAGE_NAME)$(SHLPST)
	./$(PACKAGE_NAME) $(srcdir)/preinst.rexx $(bindir)/$(PACKAGE_NAME) $(srcdir)/demo/testcurl.rexx $(sharedir)/testcurl.rexx
	-chmod 755 $(sharedir)/testcurl.rexx
	./$(PACKAGE_NAME) $(srcdir)/preinst.rexx $(bindir)/$(PACKAGE_NAME) $(srcdir)/demo/httppost.rexx $(sharedir)/httppost.rexx
	-chmod 755 $(sharedir)/httppost.rexx
	./$(PACKAGE_NAME) $(srcdir)/preinst.rexx $(bindir)/$(PACKAGE_NAME) $(srcdir)/demo/mirror.rexx $(sharedir)/mirror.rexx
	-chmod 755 $(sharedir)/mirror.rexx
	./$(PACKAGE_NAME) $(srcdir)/preinst.rexx $(bindir)/$(PACKAGE_NAME) $(srcdir)/demo/scp.rexx $(sharedir)/scp.rexx
	-chmod 755 $(sharedir)/scp.rexx
	./$(PACKAGE_NAME) $(srcdir)/preinst.rexx $(bindir)/$(PACKAGE_NAME) $(srcdir)/demo/upload.rexx $(sharedir)/upload.rexx
	-chmod 755 $(sharedir)/upload.rexx

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
	cp $(PACKAGE_NAME) ./tmpdir/bin
	cp $(SHLPRE)$(PACKAGE_NAME)$(SHLPST) ./tmpdir/lib
	-cp $(rexxtrans_lib_name) ./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)/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
	(cd ./tmpdir; \
	tar cvf - * | gzip > ../$(PACKAGE_DIR).$(target).$(REXX_TARGET).$(CURSES_TARGET).tgz )

