#  (C) COPYRIGHT International Business Machines Corp. 1995, 2000
#  All Rights Reserved.
#
#  US Government Users Restricted Rights - Use, duplication or
#  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.


# makefile for DB2 Universal Database Version 6.1
# CLI sample programs for the PTX operating system
                         

# Enter one of the following commands 
#
#   make <app_name>        - Builds the program designated by <app_name>
#
#   make all               - Builds the all the supplied sample programs
#   make udfspserver       - Builds the examples that implement
#                            stored procedures and UDFs (on the server)
#   make udfspclient       - Builds the examples that call stored 
#                            procedures and UDFs ( they can run remotely )
#   make otherclient       - Builds the examples that will run successfully
#                            on a client platform ( others than udfspclient )
#   make allclient         - Builds programs in udfspclient and otherclient
#                            categories
#
#   make clean             - Erases intermediate files
#   make cleanall          - Erases all files produced in the build process,
#                            except the original source files
#----------------------------------------------------------------------------
#   make ord_all           - Builds the all the supplied sample programs
#                            for the ORDER scenario
#   make ord_udfspserver   - Builds the examples that implement
#                            stored procedures and UDFs (on the server)
#                            for the ORDER scenario
#   make ord_udfspclient   - Builds the examples that call stored 
#                            procedures and UDFs ( they can run remotely )
#                            for the ORDER scenario
#   make ord_otherclient   - Builds the examples that will run successfully
#                            on a client platform ( others than udfspclient )
#                            for the ORDER scenario
#   make ord_allclient     - Builds programs in ord_udfspclient and
#                            ord_otherclient categories
#----------------------------------------------------------------------------
#   make v2all             - Builds the all DB2 Version 2 supplied
#                            sample programs
#----------------------------------------------------------------------------


# The makefile contains the following sections:
#    1 -- COMPILERS + VARIABLES
#    2 -- MAKE CATEGORIES
#    3 -- COMMANDS TO MAKE INDIVIDUAL SAMPLES


##################################################################################
#                  1 -- COMPILERS + VARIABLES                                     
##################################################################################

# This file assumes the DB2 instance path is defined by the variable HOME.
# It also assumes DB2 is installed under the DB2 instance.
# If these statements are not correct, update the variable DB2PATH. 
DB2PATH = $(HOME)/sqllib

# The following compile and link options are for the ptx/C compiler.
CC= cc

# the required compiler flags
CFLAGS= $(EXTRA_CFLAGS) -I$(DB2PATH)/include
# the required compiler flags for UDFs and stored procedures
CFLAGSSRV= $(EXTRA_CFLAGS) -KPIC -I$(DB2PATH)/include  

# the required libraries 
LIBS= -L$(DB2PATH)/lib -ldb2  

# To connect to a remote SAMPLE database cataloged on the client machine
# with another name, update the DB variable.
DB=sample
# Set UID and PWD if neccesary  
UID=
PWD=

COPY=cp
ERASE=rm -f

#############################################################################
#  2 -- MAKE CATEGORIES
#              2a - make all(= allclient + udfspserver)
#              2b - make udfspserver
#              2c - make udfspclient
#              2d - make otherclient
#              2e - make allclient(= udfspclient + otherclient)
#              2f - make clean
#              2g - make cleanall
#############################################################################


#****************************************************************************
#                  2a - make all
#****************************************************************************

all : \
	allclient \
	udfspserver

#****************************************************************************
#                  2b - make udfspserver
#****************************************************************************

udfspserver : \
	spserver \
	udfsrv
#****************************************************************************
#                  2c - make udfspclient 
#****************************************************************************

udfspclient : \
        udfcli \
        spclient

#****************************************************************************
#                  2d - make otherclient
#****************************************************************************

otherclient : \
	aphndls apinfo apsqlca \
	dbconn dbinfo dbmconn dbmuse dbnative dbuse dbusemx \
	dtinfo dtlob dtudt \
	ilinfo \
	ininfo \
	tbconstr tbdefine tbinfo tbmod tbread

#****************************************************************************
#                  2e - make allclient(= udfspclient + otherclient)
#****************************************************************************

allclient : \
	udfspclient \
	otherclient

#****************************************************************************
#                  2f - make clean
#****************************************************************************

clean :	
	$(ERASE) *.o *.map
	$(ERASE) dbusemx.c

#****************************************************************************
#                  2g - make cleanall
#****************************************************************************

cleanall : \
	clean
	$(ERASE) *.bnd
	$(ERASE) aphndls apinfo apsqlca
	$(ERASE) dbconn dbinfo dbmconn dbmuse dbnative dbuse dbusemx
	$(ERASE) dtinfo dtlob dtudt
	$(ERASE) ilinfo
	$(ERASE) ininfo
	$(ERASE) spclient spserver
	$(ERASE) tbconstr tbdefine tbinfo tbmod tbread
	$(ERASE) udfcli udfsrv

	$(ERASE) $(DB2PATH)/function/udfsrv

#############################################################################
#  3 -- COMMANDS TO MAKE INDIVIDUAL SAMPLES
#                  3a -  utilities
#                  3b -  non embedded SQL, non client/server samples
#                  3c -  embedded SQL, non client/server samples
#                  3d -  client/server samples (mixed)
#############################################################################

#****************************************************************************
#                  3a -  utilities
#****************************************************************************

utilcli.o : utilcli.c
	$(CC) -c utilcli.c $(CFLAGSSRV)

utilapi.o : utilapi.c
	$(CC) -c utilapi.c $(CFLAGS)

#****************************************************************************
#                  3b -  non embedded SQL, non client/server samples
#****************************************************************************

aphndls : utilcli.o aphndls.c
	$(CC) -o aphndls aphndls.c utilcli.o $(CFLAGS) $(LIBS)

apinfo : utilcli.o apinfo.c
	$(CC) -o apinfo apinfo.c utilcli.o $(CFLAGS) $(LIBS)

apsqlca : utilcli.o apsqlca.c
	$(CC) -o apsqlca apsqlca.c utilcli.o $(CFLAGS) $(LIBS)

dbconn : utilcli.o dbconn.c
	$(CC) -o dbconn dbconn.c utilcli.o $(CFLAGS) $(LIBS)

dbinfo : utilcli.o dbinfo.c
	$(CC) -o dbinfo dbinfo.c utilcli.o $(CFLAGS) $(LIBS)

dbmconn : utilcli.o utilapi.o dbmconn.c
	$(CC) -o dbmconn dbmconn.c utilcli.o utilapi.o $(CFLAGS) $(LIBS)

dbmuse : utilcli.o utilapi.o dbmuse.c
	$(CC) -o dbmuse dbmuse.c utilcli.o utilapi.o $(CFLAGS) $(LIBS)

dbnative : utilcli.o dbnative.c
	$(CC) -o dbnative dbnative.c utilcli.o $(CFLAGS) $(LIBS)

dbuse : utilcli.o dbuse.c
	$(CC) -o dbuse dbuse.c utilcli.o $(CFLAGS) $(LIBS)

dtinfo : utilcli.o dtinfo.c
	$(CC) -o dtinfo dtinfo.c utilcli.o $(CFLAGS) $(LIBS)

dtlob : utilcli.o dtlob.c
	$(CC) -o dtlob dtlob.c utilcli.o $(CFLAGS) $(LIBS)

dtudt : utilcli.o dtudt.c
	$(CC) -o dtudt dtudt.c utilcli.o $(CFLAGS) $(LIBS)

ilinfo : utilcli.o ilinfo.c
	$(CC) -o ilinfo ilinfo.c utilcli.o $(CFLAGS) $(LIBS)

ininfo : utilcli.o ininfo.c
	$(CC) -o ininfo ininfo.c utilcli.o $(CFLAGS) $(LIBS)

spcall : utilcli.o spcall.c
	$(CC) -o spcall spcall.c utilcli.o $(CFLAGS) $(LIBS)

tbconstr : utilcli.o tbconstr.c
	$(CC) -o tbconstr tbconstr.c utilcli.o $(CFLAGS) $(LIBS)

tbdefine : utilcli.o tbdefine.c
	$(CC) -o tbdefine tbdefine.c utilcli.o $(CFLAGS) $(LIBS)

tbinfo : utilcli.o tbinfo.c
	$(CC) -o tbinfo tbinfo.c utilcli.o $(CFLAGS) $(LIBS)

tbread : utilcli.o tbread.c
	$(CC) -o tbread tbread.c utilcli.o $(CFLAGS) $(LIBS)

tbmod : utilcli.o tbmod.c
	$(CC) -o tbmod tbmod.c utilcli.o $(CFLAGS) $(LIBS)


#****************************************************************************
#                  3c -  embedded SQL non client/server samples
#****************************************************************************

dbusemx.c : dbusemx.sqc
	embprep dbusemx $(DB) $(UID) $(PWD)
dbusemx : dbusemx.c utilcli.o
	$(CC) -o dbusemx dbusemx.c utilcli.o $(CFLAGS) $(LIBS)

#****************************************************************************
#                  3d -  client/server samples (mixed)   
#****************************************************************************

#------------------------udfcli/udfsrv-------------------------------------#

udfcli : utilcli.o udfcli.c
	$(CC) -o udfcli udfcli.c utilcli.o $(CFLAGS) $(LIBS)

udfsrv : udfsrv.c
	$(CC) -c udfsrv.c $(CFLAGSSRV)
	$(CC) -G -o udfsrv udfsrv.o $(LIBS) -ldb2apie 
	$(ERASE) $(DB2PATH)/function/udfsrv
	$(COPY) udfsrv $(DB2PATH)/function/udfsrv

#--------------------spclient/spserver--------------------------------------#

spclient : utilcli.o spclient.c
	$(CC) -o spclient spclient.c utilcli.o $(CFLAGS) $(LIBS)

spserver : utilcli.o spserver.c
	$(CC) -c spserver.c $(CFLAGSSRV) 
	$(CC) -G -o spserver spserver.o utilcli.o $(LIBS) 
	$(ERASE) $(DB2PATH)/function/spserver
	$(COPY) spserver $(DB2PATH)/function/spserver