
COMPILER=gcc -std=gnu89
FLEX=flex
BISON=bison

include customize.mak

# The name of the script executed when the program starts
INIT_SCR=.initsk

VR=0.5.3

# The following must have at least two characters
PR=seek

# The name of the directory in which the initialization file 
# is to be present. This is also the data directory in the case of 
# single-user (local) installation. 
#
# It must have at least 3 characters (see ".??*" in "local" target of 
# makefile). 
LOCAL_DATA_DIR=.$(PR)

# The name of the data directory in the archive
AR_DATA_DIR=$(PR)

# LOCAL_DATA_DIR is also used as the name of the subdirectory of AR_DATA_DIR 
# for the local file (the initialization file).
# AR_LOCAL_DATA_DIR=$(LOCAL_DATA_DIR)

# the text below taken from .maktext
help: 
	@echo " To  install  the program type \"make install\".  This will build the program and  copy  the  executable file and the data directory to the directories specified  in the file customize.mak. According to the current settings:"
	@echo " - The executable file \"$(PR)\" will be in \"$(LOCAL_BINDIR)\""
	@echo " - The data directory \"$(LOCAL_DATA_DIR)\" will be in \"$(HOME_DIR)\""
	@echo " " 
	@echo " Once the program is bult, it can be run by typing its name."
	@echo " - Type \"$(PR)\" if \"$(LOCAL_BINDIR)\" is on the search path."
	@echo " - Type \"~/$(PR)\" if \"$(LOCAL_BINDIR)\" is the home directory."
	@echo " - Type \"$(LOCAL_BINDIR)/$(PR)\" in any other case."
	@echo " "
	@echo " The  executable file may be moved anywhere. However, the data directory should  not  be moved unless the following procedure is used: edit first customize.mak  to  indicate  the  desired  location  of  the  data directory, then type \"make  install\" to build or rebuild the program."
	@echo " "
	@echo " Installing  the  program  for all users requires administrative privileges. It  can be done by typing \"make forall\"."
	@echo " - The executable file \"$(PR)\" will be in \"$(BINDIR)\""
	@echo " - The data directory \"$(PR)\" will be in \"$(SHARE_DIR)\""
	@echo " "
	@echo " To  uninstall  the program, delete the executable file and its data directory."
install: $(PR).exe
	mkdir -p "$(HOME_DIR)/$(LOCAL_DATA_DIR)"
	cp "$(PR).exe" "$(LOCAL_BINDIR)/$(PR)"
	cp -r "$(AR_DATA_DIR)"/* "$(AR_DATA_DIR)"/.??* "$(HOME_DIR)/$(LOCAL_DATA_DIR)"

forall: $(PR).exe
	cp "$(PR).exe" "$(BINDIR)/$(PR)"
	cp -r "$(AR_DATA_DIR)" "$(SHARE_DIR)"

$(PR).exe: seek2.yy.o seek2.tab.o functions.o cmnt.cm.o pretrans.pr.o tinput.o gr_heb.o fnt_info.yy.o range.tab.o range.rn.o extract.ex.o main.o verse_data.o insert.o cmap.o help.lp.o general.o get_forms_act.o get_forms.yy.o get_forms.tab.o dict.o
	$(COMPILER) -o $(PR).exe seek2.yy.o seek2.tab.o functions.o cmnt.cm.o pretrans.pr.o tinput.o verse_data.o insert.o gr_heb.o fnt_info.yy.o range.tab.o range.rn.o extract.ex.o main.o cmap.o help.lp.o general.o get_forms_act.o get_forms.yy.o get_forms.tab.o dict.o

# The next rule is for translating the y and lex files to C.
y2c: seek2.yy.c seek2.tab.c help.lp.c cmnt.cm.c pretrans.pr.c fl2str.yy.c fnt_info.yy.c range.rn.c range.tab.c extract.ex.c get_forms.yy.c get_forms.tab.c

seek2.yy.c: seek2.lex seek2.h
	$(FLEX) -oseek2.yy.c seek2.lex

seek2.yy.o: seek2.tab.c seek2.yy.c
	$(COMPILER) -c seek2.yy.c

seek2.tab.c: seek2.y functions.h seek2.h extract.h
	$(BISON) -d seek2.y

seek2.tab.o: seek2.tab.c customize.mak
	$(COMPILER) -c seek2.tab.c -D SKVERSION="\"$(VR)\"" -D SHARE_DATA_PATH="\"$(SHARE_DIR)/$(PR)\"" -D LOCAL_DATA_PATH="\"$(HOME_DIR)/$(LOCAL_DATA_DIR)\"" -D LOCAL_DATA_DIR="\"$(LOCAL_DATA_DIR)\"" -D INIT_FILE=\""$(INIT_SCR)"\"

help.lp.c: help.lex functions.h
	$(FLEX) -ohelp.lp.c -Plp help.lex

help.lp.o: help.lp.c
	$(COMPILER) -c help.lp.c

functions.o: functions.c cmnt.h functions.h extract.h
	$(COMPILER) -c functions.c

cmnt.cm.c: cmnt.lex cmnt.h
	$(FLEX) -ocmnt.cm.c -Pcm cmnt.lex

cmnt.cm.o: cmnt.cm.c
	$(COMPILER) -c cmnt.cm.c

pretrans.pr.c: pretrans.lex functions.h
	$(FLEX) -opretrans.pr.c -Ppr pretrans.lex

pretrans.pr.o: pretrans.pr.c
	$(COMPILER) -c pretrans.pr.c

tinput.o: tinput.c functions.h gr_heb.h extract.h cmnt.h
	$(COMPILER) -c tinput.c

verse_data.o: verse_data.c
	$(COMPILER) -c verse_data.c

main.o: functions.h main.c
	$(COMPILER) -c main.c

# Do not change the data file names below: 
# The same names appear as variable names in the program.
cmap.o: charmap helptext fl2str.lex fl2str
	./fl2str.exe cmap.c charmap helptext -1 PARSE.rtf
	$(COMPILER) -c cmap.c 

# The LIB files:

insert.o: insert.c insert.h
	$(COMPILER) -c insert.c

fl2str.yy.c: fl2str.lex
	$(FLEX) -ofl2str.yy.c fl2str.lex

fl2str: fl2str.yy.c
	$(COMPILER) -o fl2str.exe fl2str.yy.c

# The DICT files:

fnt_info.yy.c: fnt_info.lex gr_heb.h
	$(FLEX) -Pfn -o fnt_info.yy.c fnt_info.lex

fnt_info.yy.o: fnt_info.yy.c
	$(COMPILER) -c fnt_info.yy.c

gr_heb.o: gr_heb.c gr_heb.h general.h
	$(COMPILER) -c gr_heb.c

general.o: general.c general.h
	$(COMPILER) -c general.c

get_forms.yy.c: get_forms.lex get_forms.tab.c get_forms.h gr_heb.h
	$(FLEX) -Pgf -oget_forms.yy.c get_forms.lex

get_forms.yy.o: get_forms.yy.c  get_forms.tab.c 
	$(COMPILER) -c get_forms.yy.c

get_forms.tab.c: get_forms.y get_forms.h gr_heb.h
	$(BISON) -d -p gf get_forms.y

get_forms.tab.o: get_forms.tab.c
	$(COMPILER) -c get_forms.tab.c

get_forms_act.o: get_forms_act.c get_forms.h gr_heb.h general.h dict.h
	$(COMPILER) -c get_forms_act.c

dict.o: dict.c dict.h
	$(COMPILER) -c dict.c

# The RANGE files:
#  - extract.lex: gets Scripture references in text form
#  - range.y: is called to analyze these references
#  - range.lex: is the scanner of range.y 

range.rn.c: range.lex range.tab.c range.h extract.h
	$(FLEX)  -i -Prn -orange.rn.c range.lex

range.rn.o: range.rn.c
	$(COMPILER) -c range.rn.c

range.tab.c: range.y range.h extract.h
	$(BISON) -d -g -v -prn -o range.tab.c range.y

range.tab.o: range.tab.c
	$(COMPILER) -c range.tab.c

extract.ex.c: extract.lex range.h extract.h
	$(FLEX)  -Pex -o extract.ex.c extract.lex

extract.ex.o: extract.ex.c
	$(COMPILER) -c extract.ex.c

