#
# installation directories. DIR contains the main interactive plan program,
# LIB contains everything else (pland, notifier, plan.help). If you change
# either, remove lock.o.  INCDIR is for searching nonstandard include
# directories, eg. "-I/usr/X11R5". ALWAYS TERMINATE macro assignments with #.
# DO NOT put a blank between the path and the #, or you'll get compile errors.
#

DIR  = /usr/local/bin#		# user-callable executable (plan)
LIB  = /usr/local/bin#		# auxiliary executables (pland, notifier)
HELP = $(LIB)#			# help file (plan.help)
MAN  = /usr/man/local/man#	# unformatted nroff manpage (plan.[14])
# MAN = /usr/local/man/man#	# for linux
CATMAN = /usr/catman/local/cat#	# formatted manpage (plan.[14])
INCDIR =#			# extra cc options, e.g. "-I/var/include"
CPP_PATH="/lib/cpp -P -I$(HELP)"# used by plan to pre-process holiday files,
#				# plan will check if this file really exists
# JAPAN = -DJAPAN#		# uncomment this for Japanese version of plan
#				# JAPAN requires X11R5 and a Japanese env.

#DEBUG = -g
DEBUG = -O2 -s

#DEFTARGET = sgi
DEFTARGET = help

#
# compiler flags. Add these to *_C macro as needed:
#
#	-DDESKTOP	for SGIs running IRIX 5.2, desktop look&feel, 4Dwm only
#	-DBSD		use setpgrp(0, 0) and new wait(); also for OSF systems
#	-DSUN		for SunOS 4.1.x systems
#	-DIBM		for IBM AIX systems, includes sys/lockf.h
#	-DULTRIX	for Ultrix 4.3/Motif 1.1.3 systems, different font
#	-DPID_T=long	for IBM/AIX systems and other systems with pids>30000
#	-DFIXMBAR	use if pulldowns in the menu bar are empty (HP/UX 8.x)
#	-DNOMSEP	remove all XmVaSEPARATORs in pulldowns (some HP/UX's)
#	-DNOREGEX	if you don't have regcmp() and regex()
#	-DNOLIMIT	if there is no /usr/include/limits.h
#	-DNOKILL0	if kill(pid,0) works (sends no signal, pid check only)
#	-DFLOCK		use flock instead of lockf
#	-DNOLOCK	use if lockf() and flock() are both undefined
#	-DUSERAND	use rand/srand instead of random/srandom
#	-DBACKING	for window backing store if supported (untested)
#	-DRABBITS	daemon survives logout (if there is no utmp/getpwnam)
#	-DVARARGS	use pre-ANSI varargs instead of stdargs
#	-DDESTROYBUG	fixes Linux XtDestroyWidget bug that kills plan when a
#			Done button is used. WARNING: introduces a memory leak
#
# Note for HP systems: if you have the PROG-AUX option, remove -DNOREGEX
# from HP_C, and add -lPW to HP_L1. On Suns, try removing -DNOREGEX (and
# adding -lPW if necessary) to get regular expression searches. If you have
# problems with HP/UX and missing pulldowns, try adding/removing -DFIXMBAR.
# Sun users using Solaris 2.1 and gcc may have to add -DNOMSEP for pulldowns,
# and -DNOLOCK if "deadlock avoided" messages appear. There is at least one
# IBM that will compile plan only with -DNOLOCK if -DIBM is removed.
# Don't use a renamed copy of this Makefile, it uses itself recursively.
#


SGI4_C	=
SGI5_C	= -DDESKTOP
HP8_C	= -Aa -I/usr/include/Motif1.1 -I/usr/include/X11R4 -I/usr/include\
	  -D_INCLUDE_HPUX_SOURCE -D_INCLUDE_POSIX_SOURCE\
	  -D_INCLUDE_XOPEN_SOURCE -DNOREGEX -DFIXMBAR -DRABBITS
# HP_C	= -Aa -I/usr/include/Motif1.2 -I/usr/include/X11R5 -I/usr/include\
#	  -D_INCLUDE_HPUX_SOURCE -D_INCLUDE_POSIX_SOURCE -DRABBITS -DNOMSEP\
#	  -D_INCLUDE_XOPEN_SOURCE -D_INCLUDE_AES_SOURCE -DNOREGEX -DUSERAND
HP_C	= -Aa -I/usr/include/Motif1.2 -I/usr/include/X11R5 -I/usr/include\
	  -D_HPUX_SOURCE -DRABBITS -DNOMSEP -DNOREGEX -DUSERAND
# IBM_C	= -O -I/usr/include/X11 -D_POSIX_SOURCE\
#	  -DIBM -D_XOPEN_SOURCE -D_ANSI_C_SOURCE -DNOMSEP
IBM_C	= -O -I/usr/include/X11 -D_ALL_SOURCE -DIBM -DAIXV3 -DNOMSEP
PS2_C	= -O -I/usr/include/X11 -D_POSIX_SOURCE\
	  -DIBM -D_XOPEN_SOURCE -D_ANSI_C_SOURCE -DNOMSEP -DNOLOCK
OSF_C	= -DNOREGEX -DBSD -DOSF -DRABBITS -DNOMSEP
SUN_C	= -DSUN -DRABBITS -DNOMSEP
SUNG_C	= -DSUN -DRABBITS -DNOMSEP -ansi -I/usr/5include -I/usr/include/X11\
	  -DNOREGEX
SPARC_C	= -DSUN -DRABBITS -DNOMSEP -ansi -I/usr/5include -I/usr/include/X11\
	  -DNOREGEX -Dsparc
SOL_C	= -DSUN -DSOLARIS2 -DNOMSEP -I/usr/local/X11R5/include\
	  -I/usr/local/X11R5/include/X11
SUNKR_C = -I/usr/5include -I/usr/include/X11 -DSUN -DRABBITS -DNOMSEP \
	  -DNOREGEX -D_NO_PROTO -DVARARGS -DNOMSEP -Dvoid=int -Dconst=
ULTRIX_C= -DNOLOCK -DULTRIX -DRABBITS
CDC_C	= -DUSERAND
MIPS_C	= -DMIPS -systype sysv -Wf,-XNd4000 -DPID_T="int" -DMIPS\
	  -I/usr/include/bsd
DG_C	=
SNI_C	= -DSYSV -DNOREGEX
ISC_C	= -DSYSV -DNOREGEX -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_SYSV3
SCO_C	= -DUSERAND
SCOS_C	= -DUSERAND -Dsco -DSYSV
NCR_C	= -DNCR -DNOMSEP
USL_C	= -DNOKILL0 -I/usr/X/include
BSDI_C	= -DBSD -DRABBITS -I/usr/X11/include -DNOLOCK -DNOREGEX -Dbsdi
BSDIG_C	= -ansi -I/usr/X11/include -DBSD -DRABBITS -DNOLOCK -DNOREGEX -Dbsdi
LINUX_C	= -D_POSIX_SOURCE -DNOLOCK -DDESTROYBUG
#LINUX_C= -DNOREGEX -DNOLOCK
#LINUX_C= -D_POSIX_SOURCE -DFLOCK
SVR4_C	= -DSVR4 -DSYSV -DOLDTZ -DUSERAND -DPID_T=long -DNOMSEP
NEWS_C	= -DNEWSOS4 -DSUN -DBSD -DRABBITS -DPID_T="int" -Dconst=""
NEWSG_C	= -DNEWSOS4 -DSUN -DBSD -DRABBITS -DPID_T="int"
SQNT_C	= -I/usr/include  -DUSERAND -DBACKING -DSYSV -D_NO_PROTO -DUSG



#
# loader flags. Requires X11, Xt, and Motif libraries. PW is for regcmp/regex.
#
#SGI_L1	= -lXm_s -lXt_s -lX11_s -lPW -lsun
SGI_L1	= -lXm_s -lXt_s -lXmu -lX11_s -lPW -lsun
SGI_L2	= -lsun -lc_s
HP8_L1	= -L/usr/lib/X11R4 -L/usr/lib/Motif1.1 -lXm -lXt -lX11 -lc
HP8_L2	=
HP_L1	= -L/usr/lib/X11R5 -L/usr/lib/Motif1.2 -lXm -lXt -lX11 -lc
HP_L2	=
IBM_L1	= -lXm -lXt -lX11 -lPW
IBM_L2	=
PS2_L1	= -lXm -lXt -lX11 -lPW
PS2_L2	=
OSF_L1	= -lXm -lXt -lX11
OSF_L2	=
SUN_L1	= -lXm -lXt -lX11
SUN_L2	= -lc
SUNKR_L1= -lXm -lXt -lX11
SUNKR_L2= -lc
SUNG_L1	= -L/usr/5lib -lXm -lXt -lX11
SUNG_L2	= -L/usr/5lib -lc
SPARC_L1= -L/usr/5lib -lXm -lXt -lX11
SPARC_L2= -L/usr/5lib -lc
SOL_L1	= -L$(OPENWINHOME)/lib -L$(MOTIFHOME)/lib -lXm -lXt -lX11 -lelf -lgen
SOL_L2	= -lc
ULTRIX_L1= -lXm -lXt -lX11
ULTRIX_L2=
CDC_L1	= -lXm -lXt -lX11 -lgen -lnsl -lsocket
CDC_L2	=
MIPS_L1	= -lXm -lXt -lX11 -lbsd -lsun -lc -lPW
#MIPS_L1= -L/usr/X11/lib -lXm -lXt -lX11 -lbsd -lc -lPW
MIPS_L2	=
DG_L1	= -lXm -lXt -lX11 -lPW
DG_L2	=
SNI_L1	= -lXm -lXt -lX11 -lsocket -lnsl -lXmu
SNI_L2	=
ISC_L1	= -lXm -lXt -lX11 -lXmu -linet -lnsl_s
ISC_L2	=
SCO_L1  = -lXm -lXt -lXmu -lX11 -lPW -lsocket
SCO_L2  =
SCOS_L1 = -lXtXm_s -lXmu -lX11_s -lsocket -lmalloc -lPW -lintl
SCOS_L2 = -lc_s
NCR_L1	= -lXm -lXt -lX11 -lXext -lnsl -lgen
NCR_L2	= -lgen
USL_L1	= -B static -lXm -B dynamic -lXaw -lXext -lXmu -lXt -lX11 -lm -lnsl -lgen
USL_L1m	= -lXm -lXaw -lXext -lXmu -lXt -lX11 -lm -lnsl -lgen
USL_L2	= -lc
BSDI_L1	= -lXm -lXt -lX11
BSDI_L2	= -lc
BSDIG_L1= -L/usr/X11/lib -lXm -lXt -lX11
BSDIG_L2= -L/usr/X11/lib -lc
LINUX_L1= -lXm -lXt -lX11
#LINUX_L1= -L/usr/X386/lib -lXm -lXt -lX11
LINUX_L2= -lc
SVR4_L1	= -lXm -lXt -lX11 -lgen -lsocket -lnsl
SVR4_LK2=
NEWS_L1	= -lXm -lXt -lX11 -lXlc
NEWS_L2	=
SQNT_L1	= -Xo -lXm -lXaw -lXmu -lXt -lXext -lX11 -lm -lPW -leli -linet -lnsl -lseq
SQNT_L2	= 



start: $(DEFTARGET)

#---------------------------------------------------------------
# to add another system here, define XXX_C, XXX_L1, and XXX_L2 by picking
# available options from the list at the top of this Makefile, add an echo
# here, and add a target in the next section. Please mail patches to me.

help:
	@echo "Usage:"
	@echo "  make sgi4      standard IRIX 4.x and 5.x SGI systems"
	@echo "  make sgi5      5.x SGI systems, desktop look&feel, 4Dwm only"
	@echo "  make hp8       HP/UX 8.x with X11R4 and Motif 1.1.5"
	@echo "  make hp        HP/UX 9.x with X11R5 and Motif 1.2"
	@echo "  make ibm       IBM RS6000 running AIX"
	@echo "  make ps2       IBM PS/2 Model 8577, AIX 1.3 with "mpp" level 0013 patches, gcc"
	@echo "  make osf       DEC running OSF/1"
	@echo "  make sun       Sun with Motif (won't work with OpenLook)"
	@echo "  make sunkr     Sun 4.1.3 with K&R compiler (no ANSI)"
	@echo "  make sung      Sun 4.1.3/Solaris 2.2 with Motif, using gcc"
	@echo "  make sparc     Sun 4.1.3 on SUN 4C, gcc, adds -Dsparc option"
	@echo "  make sol       Solaris 2.2 with Motif, using cc"
	@echo "  make ultrix    Ultrix 4.3 with Motif 1.1.3"
	@echo "  make cdc       CDC/Mips running EP/IX 2.1.1"
	@echo "  make mips      Mips Magnum RISCos 4.52 with RISCwindows 4.0"
	@echo "  make dg        Data General DG/UX, with gcc"
	@echo "  make sni       SNI SINIX 5.41"
	@echo "  make isc       SunSoft Interactive Unix v4.0"
	@echo "  make sco       SCO Open Desktop/Open Server 3.0"
	@echo "  make scos      SCO Open Desktop/Open Server 3.0, shared libs"
	@echo "  make ncr       NCR 3000 systems"
	@echo "  make usl       USL SVR4.2 V1 with mdev package"
	@echo "  make uslm      ...same with Motif run-time libraries"
	@echo "  make linux     Linux with Motif"
	@echo "  make bsdi      BSDI/386"
	@echo "  make bsdig     BSDI/386 with gcc"
	@echo "  make svr4      SVR4 Using gcc"
	@echo "  make news4     Sony NEWS-OS4.x"
	@echo "  make news4g    Sony NEWS-OS4.x with gcc"
	@echo "  make sqnt      Sequent Dynix/ptx 2.0 or 2.1, using cc"
	@echo ""
	@echo "  make install   install compiled programs in"
	@echo "                 $(DIR) and $(LIB)."
	@echo "  make clean     remove everything in this dir except sources"
	@echo ""
	@echo "If you have problems, first read this Makefile. You may also"
	@echo "want to change the installation directory if you are not root."
	@echo "The installation directory is set at the top of this Makefile."
	@echo "For a Japanese version, edit the JAPAN line in the Makefile."


#---------------------------------------------------------------
sgi4:
	env CF="$(SGI4_C)" L1F="$(SGI_L1)" L2F="$(SGI_L2)" MYCC=cc make all

sgi5:
	env CF="$(SGI5_C)" L1F="$(SGI_L1)" L2F="$(SGI_L2)" MYCC=cc make all

hp8:
	env CF="$(HP8_C)" L1F="$(HP8_L1)" L2F="$(HP8_L2)" MYCC=cc make all

hp:
	env CF="$(HP_C)" L1F="$(HP_L1)" L2F="$(HP_L2)" MYCC=cc make all

ibm:
	env CF="$(IBM_C)" L1F="$(IBM_L1)" L2F="$(IBM_L2)" MYCC=cc make all

ps2:
	env CF="$(PS2_C)" L1F="$(PS2_L1)" L2F="$(PS2_L2)" MYCC=gcc make all

osf:
	env CF="$(OSF_C)" L1F="$(OSF_L1)" L2F="$(OSF_L2)" MYCC=cc make all

sun:
	env CF="$(SUN_C)" L1F="$(SUN_L1)" L2F="$(SUN_L2)" MYCC=acc make all

sunkr:
	env CF="$(SUNKR_C)" L1F="$(SUNKR_L1)" L2F="$(SUNKR_L2)" MYCC=gcc make all

sung:
	env CF="$(SUNG_C)" L1F="$(SUNG_L1)" L2F="$(SUNG_L2)" MYCC=gcc make all

sol:
	env CF="$(SOL_C)" L1F="$(SOL_L1)" L2F="$(SOL_L2)" MYCC=cc make all

ultrix:
	env CF="$(ULTRIX_C)" L1F="$(ULTRIX_L1)" L2F="$(ULTRIX_L2)" MYCC=cc make all

cdc:
	env CF="$(CDC_C)" L1F="$(CDC_L1)" L2F="$(CDC_L2)" MYCC=cc make all

mips:
	env CF="$(MIPS_C)" L1F="$(MIPS_L1)" L2F="$(MIPS_L2)" MYCC=cc make all

dg:
	env CF="$(DG_C)" L1F="$(DG_L1)" L2F="$(DG_L2)" MYCC=gcc make all

sni:
	env CF="$(SNI_C)" L1F="$(SNI_L1)" L2F="$(SNI_L2)" MYCC=cc make all

isc:
	env CF="$(ISC_C)" L1F="$(ISC_L1)" L2F="$(ISC_L2)" MYCC=gcc make all

sco:
	env CF="$(SCO_C)" L1F="$(SCO_L1)" L2F="$(SCO_L2)" MYCC=cc make all

scos:
	env CF="$(SCOS_C)" L1F="$(SCOS_L1)" L2F="$(SCOS_L2)" MYCC=cc make all

ncr:
	env CF="$(NCR_C)" L1F="$(NCR_L1)" L2F="$(NCR_L2)" MYCC=cc make all

usl:
	env CF="$(USL_C)" L1F="$(USL_L1)" L2F="$(USL_L2)" MYCC=cc make all

uslm:
	env CF="$(USL_C)" L1F="$(USL_L1m)" L2F="$(USL_L2)" MYCC=cc make all

bsdi:
	env CF="$(BSDI_C)" L1F="$(BSDI_L1)" L2F="$(BSDI_L2)" MYCC=acc make all

bsdig:
	env CF="$(BSDIG_C)" L1F="$(BSDIG_L1)" L2F="$(BSDIG_L2)" MYCC=gcc make all

svr4:
	env CF="$(SVR4_C)" L1F="$(SVR4_L1)" L2F="$(SVR4_L2)" MYCC=gcc make all

linux:
	env CF="$(LINUX_C)" L1F="$(LINUX_L1)" L2F="$(LINUX_L2)" MYCC=gcc make all

news4:
	make CF="$(NEWS_C)" L1F="$(NEWS_L1)" L2F="$(NEWS_L2)" MYCC=cc all

news4g:
	make CF="$(NEWSG_C)" L1F="$(NEWS_L1)" L2F="$(NEWS_L2)" MYCC=gcc all

sqnt:
	env CF="$(SQNT_C)"  L1F="$(SQNT_L1)" L2F="$(SQNT_L2)" MYCC=cc make all


#------------------------------ don't change anything below ------------------

INC	= bm_advance.h bm_blank.h bm_group.h bm_icon.h bm_iconsub.h\
	  bm_private.h bm_message.h bm_noticon.h bm_recycle.h bm_script.h\
	  bm_tri.h cal.h conf.h notifier.h version.h resources.h print_res.h

P_SRC	= main.c popup.c print.c gotomenu.c\
	  calmenu.c monmenu.c mondraw.c\
	  daymenu.c daydraw.c dayedit.c\
	  msgmenu.c cycmenu.c cyccalc.c advmenu.c keymenu.c\
	  cnfmenu.c yearmenu.c yeardraw.c holmenu.c adjmenu.c\
	  weekmenu.c weekdraw.c weekcalc.c usermenu.c rangemenu.c\
	  pixmap.c help.c dbase.c file_r.c file_w.c convert.c\
	  lock.c time.c sublist.c parser.y parser.lex holiday.c
P_OBJ	= main.o popup.o print.o gotomenu.o\
	  calmenu.o monmenu.o mondraw.o\
	  daymenu.o daydraw.o dayedit.o\
	  msgmenu.o cycmenu.o cyccalc.o advmenu.o keymenu.o\
	  cnfmenu.o yearmenu.o yeardraw.o holmenu.o adjmenu.o\
	  weekmenu.o weekdraw.o weekcalc.o usermenu.o rangemenu.o\
	  pixmap.o help.o dbase.o file_r.o file_w.o convert.o\
	  lock.o time.o sublist.o parser.o lex.yy.o holiday.o

D_SRC	= daemon.c dbase.c file_r.c lock.c time.c cyccalc.c
D_OBJ	= daemon.o dbase.o file_r.o lock.o time.o cyccalc.o

N_SRC	= notifier.c notmenu.c
N_OBJ	= notifier.o notmenu.o


#---------------------------------------------------------------
all:	plan pland notifier

plan:	$(P_OBJ)
	$(MYCC) $(DEBUG) $(CF) $(JAPAN) $(INCDIR) -o plan $(P_OBJ) $(L1F)

pland:	$(D_OBJ)
	$(MYCC) $(DEBUG) $(CF) $(JAPAN) $(INCDIR) -o pland $(D_OBJ) $(L2F)

notifier: $(N_OBJ)
	$(MYCC) $(DEBUG) $(CF) $(JAPAN) $(INCDIR) -o notifier $(N_OBJ) $(L1F)

.c.o:
	$(MYCC) $(DEBUG) $(CF) $(JAPAN) $(INCDIR) -c $<

print.o: print.c
	$(MYCC) $(DEBUG) $(CF) $(JAPAN) $(INCDIR) -c -DLIB=\"$(LIB)\" $<

holiday.o: holiday.c
	$(MYCC) $(DEBUG) $(CF) $(JAPAN) $(INCDIR) -DCPP_PATH=\"$(CPP_PATH)\" -c -DLIB=\"$(LIB)\" $<

lock.o: lock.c
	$(MYCC) $(DEBUG) $(CF) $(JAPAN) $(INCDIR) -c -DPATH=\"$(DIR):$(LIB):$(HELP)\" $<

parser.c: parser.y
	yacc -d parser.y
	-mv y.tab.c parser.c

lex.yy.o: lex.yy.c parser.c
	$(MYCC) $(DEBUG) $(CF) $(JAPAN) $(INCDIR) -c lex.yy.c

lex.yy.c: parser.lex
	lex parser.lex

$(P_OBJ): conf.h cal.h
$(D_OBJ): conf.h
$(N_OBJ): notifier.h
main.o popup.o daemon.o notifier.o: version.h
main.o:	resources.h print_res.h

#---------------------------------------------------------------
install:
	cp plan $(DIR)
	cp pland notifier plan_cal.ps $(LIB)
	cp plan.help $(HELP)
	-strip $(DIR)/plan $(LIB)/pland $(LIB)/notifier
	-chmod 755 $(DIR)/plan $(LIB)/pland $(LIB)/notifier
	-chmod 644 $(HELP)/plan.help
	-test -x `which nroff` && nroff -man plan.1 >plan.1cat
	-test -x `which nroff` && nroff -man plan.4 >plan.4cat
	-test -d $(MAN)1 && cp plan.1 $(MAN)1/plan.1
	-test -d $(MAN)4 && cp plan.4 $(MAN)4/plan.4
	-test -d $(CATMAN)1 && cp plan.1cat $(CATMAN)1/plan.1
	-test -d $(CATMAN)4 && cp plan.4cat $(CATMAN)4/plan.4
	-test -f ${HOME}/.holiday || cp holiday_german ${HOME}/.holiday
	-test `uname` = IRIX && mkdir $$HOME/.icons
	-test `uname` = IRIX && cp Plan.icon $$HOME/.icons/Plan.icon
	@echo ""
	@echo "use holiday_* as templates for your ~/.holiday file"

clean:
	-rm -f *.o
	-rm -f y.tab.h parser.c lex.yy.c
	-rm -f core plan pland notifier tags


#---------------------------------------------------------------
LIST	= README HISTORY plan.1cat plan.4cat plan.1 plan.4 plan.help\
	  Makefile Mkdoc Mkdoc.nawk Killpland $(P_SRC) daemon.c $(N_SRC)\
	  $(INC) holiday_canada holiday_dutch holiday_french holiday_frswiss\
	  holiday_german holiday_uk holiday_us holiday_swedish holiday_japan\
	  holiday_spain holiday_quebec holiday_bavarian Monochrome plan_cal.ps\
	  Plan.icon

shar:
	shar -n plan -a -M -o plan.shar -L 60 $(LIST)


#---------------------------------------------------------------
# on BSD systems, use -acp instead of -bhx
LINTFL= -bhxu $(CF) $(JAPAN) $(INCDIR) -DDAEMON=\"\" -DBIN=\"\" -DHELPFILE=\"\" -D__DATE__=\"\"

lint:
	@echo --- plan
	lint $(LINTFL) $(P_SRC)
	@echo --- pland
	lint $(LINTFL) $(D_SRC)
	@echo --- notifier
	lint $(LINTFL) $(N_SRC)
