# $Id: Makefile,v 2.23 91/02/22 21:22:19 tynor Exp Locker: tynor $
#----------------------------------------------------------------------------
#	FPLAN - Flight Planner
#	Steve Tynor
#	tynor@prism.gatech.edu
#
#	This program is in the public domain. Permission to copy,
# distribute, modify this program is hearby given as long as this header
# remains. If you redistribute this program after modifying it, please
# document your changes so that I do not take the blame (or credit) for
# those changes.  If you fix bugs or add features, please send me a
# patch so that I can keep the 'official' version up-to-date.
#
#	Bug reports are welcome and I'll make an attempt to fix those
# that are reported.
#
# 	USE AT YOUR OWN RISK! I assume no responsibility for any
# errors in this program, its database or documentation. I will make an
# effort to fix bugs, but if you crash and burn because, for example,
# fuel estimates in this program were inaccurate, it's your own fault
# for trusting somebody else's code! Remember, as PIC, it's _your_
# responsibility to do complete preflight planning. Use this program as
# a flight planning aid, but verify its results before using them.
# ---------------------------------------------------------------------------

# ---------------------------------------------------------------------------
# EDIT THE FOLLOWING DEFINITIONS TO SUIT LOCAL CONDITIONS:
# ---------------------------------------------------------------------------

# ---------------------------------------------------------------------------
# define which C compiler (if GNU, be sure to define as 'gcc -traditional')
CC = gcc -traditional

# ---------------------------------------------------------------------------
# define where 'install' should put the man pages and executable:
BINDIR	 = /usr/local/bin
MANDIR	 = /usr/local/man
DBS_LIBDIR = /usr/local/lib/preflight

# ---------------------------------------------------------------------------
# define the install command as 'install' on BSD Unix, otherwise just use 'cp'
#INSTALL  = install
INSTALL = cp

# ---------------------------------------------------------------------------
# define which graphics subroutines you want to include (currently, Sunview 
# or nothing).  If you add X, NeWS, NeXT, EGA, etc. support - please mail me
# your code so I can distribute it!)
#GFX_OPTIONS = 
GFX_OPTIONS = -DGFX_SUNVIEW

# ---------------------------------------------------------------------------
# define which graphics libraries are necessary for linking:
#GFX_LIBS =
GFX_LIBS = -lsuntool -lsunwindow -lpixrect

# ---------------------------------------------------------------------------
# define any flags required for the C compiler:
CFLAGS   = -g $(GFX_OPTIONS)

# ---------------------------------------------------------------------------
# command to format the man pages. Note: tbl is necessary for the fplan.1 man
# page when troffed (not necessary for nroff):
MAN_FORMAT= nroff
#MAN_FORMAT= tbl | troff -Tps

# ---------------------------------------------------------------------------
# NO NEED TO EDIT BELOW HERE.
# ---------------------------------------------------------------------------

# prevent certain makes (e.g. SunOS) from including wierd flags (like -sun386)
.c.o:
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $*.c

OBJS	  = output.o main.o add.o misc.o db.o compute.o fp_yacc.o fp_lex.o \
	    strings.o reverse.o sv_draw.o

C_SRC     = output.c main.c add.c misc.c db.c compute.c paddb.c \
	    strings.c reverse.c sv_draw.c wp_info.h mystring.h version.h

OTHER_SRC = fp_lex.l fp_yacc.y config.h

# things required by the DOS version which are generated by Yacc/Lex:
DOS_SRC   = fp_lex.c fp_yacc.c fp_tok.h dosbuild.bat

MAN	  = fplan.1 fplan.5 paddb.1

FORMATTED_MAN = fplan.man fplan_dbs.man paddb.man

DOC 	  = README NEW_FEATURES EXAMPLE.fplan $(MAN) WHERE_DBS

EXE	  = fplan paddb

DIST_FILES = $(DOC) Makefile $(C_SRC) $(OTHER_SRC) dosbuild.bat 
ALL_SRC    = $(DIST_FILES)

DIST_NAME  = fplan_1_3
PATCH_NAME = $(DIST_NAME)__1_2.patch

# where I test the MessyDOS version:
DOSDIR   = /u/tynor/pc/src/fplan

all : $(EXE)
doc : $(FORMATTED_MAN)

paddb.man : paddb.1
	cat paddb.1 | $(MAN_FORMAT) -man > paddb.man
fplan.man : fplan.1
	cat fplan.1 | $(MAN_FORMAT) -man > fplan.man
fplan_dbs.man : fplan.5
	cat fplan.5 | $(MAN_FORMAT) -man > fplan_dbs.man

paddb : paddb.c
	$(CC) -o paddb paddb.c

fplan : $(OBJS)
	$(CC) -o fplan $(OBJS) $(GFX_LIBS) -lm

fp_lex.c : fp_lex.l fp_tok.h
	lex fp_lex.l
	mv lex.yy.c fp_lex.c

fp_yacc.c fp_tok.h : fp_yacc.y wp_info.h
	yacc -d fp_yacc.y
	mv y.tab.c fp_yacc.c
	mv y.tab.h fp_tok.h

#------------
fp_yacc.o 	: fp_yacc.c
fp_lex.o 	: fp_lex.c
add.o 		: add.c wp_info.h 
compute.o 	: compute.c wp_info.h
db.o 		: db.c wp_info.h mystring.h config.h
main.o 		: main.c wp_info.h version.h
misc.o 		: misc.c 
output.o 	: output.c wp_info.h mystring.h
strings.o 	: strings.c mystring.h
reverse.o	: reverse.c wp_info.h
sv_draw.o	: sv_draw.c wp_info.h
#------------

# move the current files into the DOS test directory:
dos : $(DOS_SRC)
	cp $(C_SRC) $(DOSDIR)
	cp $(DOS_SRC) $(DOSDIR)
	(cd $(DOSDIR); /u/tynor/bin/2dos $(C_SRC) $(DOS_SRC))

patch: 
	-/bin/rm $(PATCH_NAME)
	echo "Patch file to bring FPLAN 1.2 to FPLAN 1.3" > $(PATCH_NAME)
	-( for f in $(DIST_FILES) ; \
	  do \
	     rcsdiff -w -t -c -rnet_1_2 $$f > /tmp/patch.$$ ;\
	     if [ $$? != 0 ] ; \
	     then \
	       echo "-------------------------------------" >> $(PATCH_NAME) ;\
	       echo FILE: $$f >> $(PATCH_NAME) ;\
	       echo "-------------------------------------" >> $(PATCH_NAME) ;\
	       cat /tmp/patch.$$ >> $(PATCH_NAME) ;\
	     fi ;\
	  done )

TAGS : $(DIST_FILES)
	etags $(DIST_FILES)

freeze:
	@(echo "rcsfreeze msg (1st line used as ci msg) (use ^D to end):";\
	  cat > /tmp/check.$$$$;\
	  read msg < /tmp/check.$$$$;\
	  echo -------------------------------------------------;\
	  echo rcsfreeze message:;\
	  cat /tmp/check.$$$$;\
	  echo -------------------------------------------------;\
	  echo ci message: $$msg;\
	  echo -------------------------------------------------;\
	  echo -n "Ok? [n]: ";\
	  read yn;\
	  if [ "$$yn" \!= "y" ]; then echo Aborted.; exit 1; fi;\
	  echo -n "RCSFREEZE version: ";\
	  read ver;\
	  ci -q -u -m"$$msg" $(ALL_SRC);\
	  rcsfreeze $$ver < /tmp/check.$$$$ )

clean : 
	-rm *.o *~ fp_tok.h fp_lex.c fp_yacc.c fplan paddb *.man fplan.0? fplan.tar.Z

distribute :
	# all-in-one compressed tar file for FTP archive:
	tar cfo $(DIST_NAME).tar $(DIST_FILES)
	compress $(DIST_NAME).tar
	# many shar files for newsgroup distribution:
	cat README > $(DIST_NAME).01
	echo "" >> $(DIST_NAME).01
	echo "---- cut here ---- cut here ---- cut here ---- cut here ----" >> $(DIST_NAME).01
	echo "# This is part 1/6 of FPLAN" >> $(DIST_NAME).01
	shar2 -D -v README NEW_FEATURES EXAMPLE.fplan WHERE_DBS Makefile paddb.c >> $(DIST_NAME).01
	echo "#This is part 2/6 of FPLAN" > $(DIST_NAME).02
	shar2 -D -v fplan.1 fplan.5 paddb.1 >> $(DIST_NAME).02
	echo "#This is part 3/6 of FPLAN" > $(DIST_NAME).03
	shar2 -D -v add.c compute.c >> $(DIST_NAME).03
	echo "#This is part 4/6 of FPLAN" > $(DIST_NAME).04
	shar2 -D -v output.c config.h >> $(DIST_NAME).04
	echo "#This is part 5/6 of FPLAN" > $(DIST_NAME).05
	shar2 -D -v main.c misc.c db.c strings.c >> $(DIST_NAME).05
	echo "#This is part 6/6 of FPLAN" > $(DIST_NAME).06
	shar2 -D -v fp_lex.l fp_yacc.y sv_draw.c dosbuild.bat mystring.h wp_info.h reverse.c version.h >> $(DIST_NAME).06

install : $(EXE) $(MAN) 
	$(INSTALL) $(EXE) $(BINDIR)
	$(INSTALL) fplan.1 paddb.1 $(MANDIR)/man1
	$(INSTALL) fplan.5 $(MANDIR)/man5

install_dbs : $(DBS_LIBDIR)/vors.nav $(DBS_LIBDIR)/airports.nav

$(DBS_LIBDIR)/vors.nav : $(DBS_LIBDIR)/vors.txt
	sort $(DBS_LIBDIR)/vors.txt -o $(DBS_LIBDIR)/vors.txt
	paddb $(DBS_LIBDIR)/vors.txt $(DBS_LIBDIR)/vors.nav

$(DBS_LIBDIR)/airports.nav : $(DBS_LIBDIR)/airports.txt
	sort $(DBS_LIBDIR)/airports.txt -o $(DBS_LIBDIR)/airports.txt
	paddb $(DBS_LIBDIR)/airports.txt $(DBS_LIBDIR)/airports.nav

$(DBS_LIBDIR)/airports.txt $(DBS_LIBDIR)/vors.txt :
	@echo DB files missing. See WHERE_DBS to get the databases.

