#----------------------------------------------------------------------------
# Makefile for xbible Mar 12 2001
#
# Copyright (c) 2001 Toshiki Fujisawa <xbible@fujisawa.gr.jp>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#----------------------------------------------------------------------------
#	(1) "make"     for unix 
#	(2) "make win" for windows
#----------------------------------------------------------------------------
VERSION=1.25
DATE=200103240000
TMP=/tmp/tmp-xbible
AOUT=$(TMP)/xbible
WEB=http://shamash.org/tanach/tanach/text/transliterated.tanach
BIBLE=$(TMP)/bereishit.gross $(TMP)/shmot.gross $(TMP)/vayikra.gross \
	$(TMP)/bamidbar.gross $(TMP)/devarim.gross
#----------------------------------------------------------------------------
INSTALL=install -c -o root -g wheel -m 755 
USR_LOCAL_BIN=/usr/local/bin
#----------------------------------------------------------------------------
all : $(TMP)/xbible
	@echo ""
	@echo "-----------------------------------"
	@echo "Type 'make install' by root user"
	@echo "Type 'make test | less'  for test"
#----------------------------------------------------------------------------
install : $(TMP)/xbible
	$(INSTALL) $(TMP)/xbible           $(USR_LOCAL_BIN)
	$(INSTALL) asc2heb.sh              $(USR_LOCAL_BIN)
	$(INSTALL) heb-conv-disp.sh        $(USR_LOCAL_BIN)
#----------------------------------------------------------------------------
uninstall : 
	rm -f $(USR_LOCAL_BIN)/xbible
	rm -f $(USR_LOCAL_BIN)/asc2heb.sh
	rm -f $(USR_LOCAL_BIN)/heb-conv-disp.sh
#----------------------------------------------------------------------------
$(AOUT) : xbible.c $(TMP)/bdata.o
	mkdir -p $(TMP)
	gcc -Wall -O3 -o $(AOUT) xbible.c $(TMP)/bdata.o $(LIBS)
	if [ -d $(HOME)/bin ] ; then cp -p $(AOUT) $(HOME)/bin ; fi
#----------------------------------------------------------------------------
$(TMP)/bdata.o : $(TMP)/bdata.c
	gcc -c $(TMP)/bdata.c -o $(TMP)/bdata.o
#----------------------------------------------------------------------------
$(TMP)/bdata.c : $(TMP)/bible.txt
	cat $(TMP)/bible.txt | perl mk-data > $(TMP)/bdata.c
#----------------------------------------------------------------------------
CKSUM=339339474 304805
#----------------------------------------------------------------------------
$(TMP)/bible.txt : $(BIBLE)
	cat $(BIBLE) | sed -e 's/^... ...:... //' -e 's/\.$$//' | \
	tr -d '[\- \n]' | tr '[A-Z]' '[a-z]' | \
	tr '[+$$#]]' '[TSs]' > $(TMP)/bible.tmp
	[ "`cksum $(TMP)/bible.tmp`" = "$(CKSUM) $(TMP)/bible.tmp" ] && \
		mv $(TMP)/bible.tmp $(TMP)/bible.txt
#----------------------------------------------------------------------------
$(TMP)/bereishit.gross : 
	@mkdir -p $(TMP) ; cd $(TMP) ; wget $(WEB)/bereishit.gross
$(TMP)/shmot.gross :
	@mkdir -p $(TMP) ; cd $(TMP) ; wget $(WEB)/shmot.gross
$(TMP)/vayikra.gross :
	@mkdir -p $(TMP) ; cd $(TMP) ; wget $(WEB)/vayikra.gross
$(TMP)/bamidbar.gross :
	@mkdir -p $(TMP) ; cd $(TMP) ; wget $(WEB)/bamidbar.gross
$(TMP)/devarim.gross :
	@mkdir -p $(TMP) ; cd $(TMP) ; wget $(WEB)/devarim.gross
#----------------------------------------------------------------------------
gross :
	mkdir -p $(TMP)
	cp -p DATA/*.gross $(TMP)
#----------------------------------------------------------------------------
clean :
	rm -f $(TMP)/xbible.exe
	rm -f $(TMP)/bdata.o
	rm -f $(TMP)/bible.txt 
	rm -f $(TMP)/w32bdata.o
	rm -f $(TMP)/bdata.c
	rm -f $(AOUT)
#----------------------------------------------------------------------------
clean-all :
	@make clean
	rm -f $(TMP)/*.gross
	if [ -d $(TMP) ] ; then rmdir $(TMP) ; fi
#----------------------------------------------------------------------------
PKG_FILES=00README-english.txt 00README-jp-sjis.txt Makefile xbible.c \
	  mk-data asc2heb.sh asc2heb-disp.sh heb-conv-disp.sh
PKG_LIBS=lib_FreeBSD/_rand48.c lib_FreeBSD/srand48.c lib_FreeBSD/lrand48.c \
         lib_FreeBSD/rand48.h
#----------------------------------------------------------------------------
pkg :
	@mkdir -p $(TMP)
	@mkdir -p         $(TMP)/xbible-$(VERSION)/lib_FreeBSD
	@cp $(PKG_LIBS)   $(TMP)/xbible-$(VERSION)/lib_FreeBSD
	@touch -t $(DATE) $(TMP)/xbible-$(VERSION)/lib_FreeBSD/*
	@cp $(PKG_FILES)  $(TMP)/xbible-$(VERSION)
	@touch -t $(DATE) $(TMP)/xbible-$(VERSION)/*
	@touch -t $(DATE) $(TMP)/xbible-$(VERSION)
	tar zcfC          HISTORY/xbible-$(VERSION).tgz $(TMP) xbible-$(VERSION)
	@touch -t $(DATE) HISTORY/xbible-$(VERSION).tgz
	@rm -r            $(TMP)/xbible-$(VERSION)
#----------------------------------------------------------------------------
cvs :
	cvs commit -m by-makefile
#============================================================================
# for Windows
#----------------------------------------------------------------------------
win : $(TMP)/xbible.exe 
#----------------------------------------------------------------------------
$(TMP)/xbible.exe : xbible.c $(TMP)/w32bdata.o
	i386-mingw32-gcc -Wall -O2 -o $(TMP)/xbible.exe xbible.c \
		$(TMP)/w32bdata.o -liberty
#----------------------------------------------------------------------------
$(TMP)/w32bdata.o: $(TMP)/bdata.c
	i386-mingw32-gcc -Wall -c $(TMP)/bdata.c -o $(TMP)/w32bdata.o
#============================================================================
test : rabin rabin2 hayashi hal
#----------------------------------------------------------------------------
rabin : $(AOUT)
	@$(AOUT) -n254245 -s4772 -w78x18 -o-1,+2 ycxqrbyn rvcxasryrcx
#----------------------------------------------------------------------------
rabin2 : $(AOUT)
	@echo "[The bible code ISBN4-10-535901] Page86"
	@$(AOUT) -o+7,+2 -w78x33 -l3 -n254245 -s4772 ycxqrbyn rvcxasryrcx \
	ntnyhv smhrcx hmxlmlvmolk omyro
#----------------------------------------------------------------------------
rabin-heb : $(AOUT)
	$(AOUT) -n254245 -s4772 -w70x18 -o-1,+2 ycxqrbyn rvcxasryrcx | \
	sh asc2heb-disp.sh
#----------------------------------------------------------------------------
HAYASHI=-n303458 -s68 -c1 -w76x27 -o+3,0 -l1:1 mhayasy rol tsnh qry rcx
#----------------------------------------------------------------------------
hayashi : $(AOUT)
	$(AOUT) $(HAYASHI)
#----------------------------------------------------------------------------
hayashi-1: $(AOUT)
	@$(AOUT) -m1 $(HAYASHI)
#----------------------------------------------------------------------------
hal :   $(AOUT)
	@echo 'hal->god cpn->crypt alhym->god amt->true'
	@#                                12345678901234
	@$(AOUT) -o,-2 -w80x34 -s1032 -l2 halcpnalhymamt hkrnalmyhxtmt
#----------------------------------------------------------------------------
