# BUSH - Business Shell Makefile
#
# This makefile is for GNU make

# These are filled in by ./configure.  If they are incorrect, change them for
# your system...

CC=gcc
CPU=i686
MAKE=gmake
GNATMAKE=gnatmake
SDLLIBS=-L/usr/lib -lSDL -lpthread -lSDL_image
SDLINCL=-I/usr/include/SDL
CFLAGS=
# For SDL, sdl_config is not always available.

# RPM Directories For Building an RPM file

RPM_BUILD_DIR=~/rpm/tmp/bush-root
RPM_BIN_DIR=${RPM_BUILD_ROOT}/usr/local/bin
RPM_SYSCONF_DIR=/etc
RPM_MAN_DIR=/usr/local/man

# Libraries and Paths

#INCLUDE=-I./adacgi-1.6/ -I./apq-2.1/ -I./ADAVOX-0.51/bc -I./ADAVOX-0.51/wc -I./ADAVOX-0.51/main -I/usr/include/SDL
INCLUDE=-I./adacgi-1.6/ -I./apq-2.1/ -I./ADAVOX-0.51/bc -I./ADAVOX-0.51/wc -I./ADAVOX-0.51/main ${SDLINCL}
#LIBS=-L`pg_config --libdir` -L./apq-1.92/ -lpq -lSDL ${PTHREAD_LIBS}
#LIBS=-L`pg_config --libdir` -L./apq-2.1/ ./apq-2.1/c_mysql.o -l SDL -l SDL_image ${PTHREAD_LIBS}
LIBS=-L`pg_config --libdir` -L./apq-2.1/ ./apq-2.1/c_mysql.o ${SDLLIBS}
# c_mysql.o missing in APQ 2.1 library

# Make Rules Start

all: c_os.o
	@echo
	@echo "==============================================================="
	@echo "  BUSH - Business Shell"
	@echo "    Need help? Type make help"
	@echo "==============================================================="
	@echo
	@echo "---------------------------------------------------------------"
	@echo "  Making AdaCGI"
	@echo "    http://www.dwheeler.com/adacgi"
	@echo "---------------------------------------------------------------"
	@echo
	$(MAKE) -C adacgi-1.6
	@echo
	@echo "---------------------------------------------------------------"
	@echo "  Making AdaVOX (Wav/AU Player)"
	@echo "    http://home.cogeco.ca/~ve3wwg"
	@echo "---------------------------------------------------------------"
	@echo
	$(MAKE) -C ADAVOX-0.51
	@echo
	@echo "---------------------------------------------------------------"
	@echo "  Making APQ (PostgreSQL/MySQL DBI)"
	@echo "    http://home.cogeco.ca/~ve3wwg"
	@echo "---------------------------------------------------------------"
	@echo
	$(MAKE) -C apq-2.1/
	@echo
	@echo "---------------------------------------------------------------"
	@echo " Making BUSH"
	@echo "   http://www.pegasoft.ca/bush.html"
	@echo "---------------------------------------------------------------"
	@echo
	$(GNATMAKE) -c -i -O1 -march=$(CPU) -gnatfaon -fstack-check -c $(INCLUDE) bush
	gnatbind -x $(INCLUDE) bush.ali
	gnatlink bush.ali ./ADAVOX-0.51/wc/cglue.o c_os.o $(LIBS)
	@echo
	@echo "---------------------------------------------------------------"
	@echo "  Thanks for choosing BUSH"
	@echo "---------------------------------------------------------------"
	@echo

c_os.o:	c_os.c
	$(CC) $(CFLAGS) $(INCLUDE) -Wall -c c_os.c

#apq-2.1/Makeincl:
#	@echo "---------------------------------------------------------------"
#	@echo "  Configuring APQ Library"
#	@echo "---------------------------------------------------------------"
#	./apq-2.1/configure
#	mv -f Makeincl apq-2.1/Makeincl

max: clean c_os.o
	@echo
	@echo "---------------------------------------------------------------"
	@echo "Making AdaCGI"
	@echo "---------------------------------------------------------------"
	@echo
	$(MAKE) -C adacgi-1.6
	@echo
	@echo "---------------------------------------------------------------"
	@echo "Making AdaVOX"
	@echo "---------------------------------------------------------------"
	@echo
	$(MAKE) -C ADAVOX-0.51
	@echo
	@echo "---------------------------------------------------------------"
	@echo "  Making APQ (PostgreSQL/MySQL DBI)"
	@echo "    http://home.cogeco.ca/~ve3wwg"
	@echo "---------------------------------------------------------------"
	@echo
	$(MAKE) -C apq-2.1/
	@echo
	@echo "---------------------------------------------------------------"
	@echo "Making BUSH"
	@echo "---------------------------------------------------------------"
	@echo
	$(GNATMAKE) -c -i -O3 -march=$(CPU) -gnatf -gnatn -gnatp -ffast-math -c $(INCLUDE) bush
	gnatbind -x $(INCLUDE) bush.ali
	gnatlink bush.ali ./ADAVOX-0.51/wc/cglue.o c_os.o $(LIBS)

clean:
	$(MAKE) -C adacgi-1.6 clean
	$(MAKE) -C apq-2.1 clean
	$(MAKE) -C ADAVOX-0.51 clean
	rm -f *.o *.ali t.t t.bush core bush.zip bush testsuite/write_only.txt testsuite/exec_only.txt

distclean:
	$(MAKE) -C adacgi-1.6 clean
	$(MAKE) -C ADAVOX-0.51 clobber
	$(MAKE) -C apq-2.1 clobber
	rm -f *.o *.ali t.t t.bush core bush.zip bush testsuite/write_only.txt testsuite/exec_only.txt
	rm -f bush_os.ads bush_os.adb

test:	all
	@echo "---------------------------------------------------------------"
	@echo "  RUNNING TESTSUITE"
	@echo "---------------------------------------------------------------"
	(cd testsuite; sh test.sh)

zip: distclean
	(cd ..; zip -9r *; cd src)

srczip: distclean
	chmod 440 bush_linux.ads
	chmod 440 bush_hp.ads
	chmod 440 bush_hp.adb
	(cd ..; zip -9r *; cd src)

srctar: distclean
	chmod 440 bush_linux.ads
	chmod 440 bush_hp.ads
	chmod 440 bush_hp.adb
	(cd ..;  tar cfvz bush.tgz *; cd src)
	@echo "Don't forget to unpack and repack under a descriptive directory"

rpm:	all

bintar: c_os.o all
	gnatbind -x $(INCLUDE) bush.ali
	gnatlink bush.ali ./ADAVOX-0.51/wc/cglue.o c_os.o $(LIBS)
	(cd ..; rm -f bush.tgz; tar cfvz bush.tgz src/bush src/bush.1 README COPYING INSTALL examples doc GNUmakefile; rm -f bush )
	@echo "Don't forget to unpack and repack under a descriptive directory"

install:
	install -d /usr/local/bin
	install -m 555 bush /usr/local/bin/bush
	install -d /usr/local/man/man1
	install -m 555 bush.1 /usr/local/man/man1/bush.1

uninstall:
	rm /usr/local/bin/bush
	rm /usr/local/man/man1/bush.1

help:
	@echo "Run configure first, if you have not already done so."
	@echo "Then you can make these:"
	@echo "  all       - (default) normal build"
	@echo "  max       - maximum performance, minimum error checks"
	@echo "  install   - install bush binary file in /usr/local/bin"
	@echo "  uninstall - remove bush binary file in /usr/local/bin"
	@echo "  clean     - remove temporary and binary files"
	@echo "  distclean - clean and remove operating system choice"
	@echo "  test      - make all, then run test.bush script"
	@echo "  zip       - create a .zip source archive with important files"
	@echo "  srczip    - create a .zip source archive to share with others"
	@echo "  srctar    - create a .tgz source archive to share with others"
	@echo "  bintar    - create a tgz of binary files to share with others"
	@echo "  rpm       - build an rpm (must have spec file)"


