#
#	Makefile for fd
#

TITLE	= FD-
PREFIX	= /usr/local
MANSEC	= 1
TOPDIR	= $(PREFIX)
BINDIR	= $(TOPDIR)/bin
MANDIR	= $(TOPDIR)/man__LANGDIR__/man$(MANSEC)
CATDIR	= $(TOPDIR)/man__LANGDIR__/cat$(MANSEC)
DEFRC	= /etc/fdrc
DOSRC	= ~FD\\fdrc
UNITBL	= fd-unicd.tbl
INSTALL	= __INSTALL__
CHMOD	= chmod

SRC	= main.c term.c pathname.c \
	dosdisk.c dosemu.c mkunitbl.c \
	unixdisk.c unixemu.c \
	libc.c file.c apply.c \
	parse.c builtin.c shell.c \
	kanji.c input.c \
	info.c rockridg.c archive.c tree.c \
	command.c browse.c \
	kanjicnv.c mkfuncno.c expfunc.c mkmfsed.c
HEADER	= fd.h machine.h types.h kctype.h term.h pathname.h \
	dosdisk.h \
	unixdisk.h unixemu.h \
	func.h functabl.h

DOC	= README HISTORY FAQ TECHKNOW Install ToAdmin
MANSRC	= fd.man
MANCAT	= fd.cat
RUNCOM	= fdrc
ARGS	= object.arg

JSRCS	= $(DOC) kanji.hin $(MANSRC) $(MANCAT)
ESRCS	= Configur Makefile Makefile.in $(SRC) $(HEADER) \
	makefile.gpc makefile.g98 \
	makefile.dpc makefile.d98 \
	makefile.lpc makefile.l98 \
	makefile.bpc makefile.b98 \
	config.hin mkmfdosg.sed mkmfdosd.sed mkmfdosl.sed mkmfdosb.sed \
	version.h _fdrc _fdrc.dif
SOURCES	= $(JSRCS) $(ESRCS)

CC	= __CC__
SED	= sed
PROGRAM	= fd
OBJ1	= main__OBJ__ term__OBJ__ pathname__OBJ__ \
	dosdisk__OBJ__ __OBJS__
OBJ2	= libc__OBJ__ file__OBJ__ apply__OBJ__ \
	parse__OBJ__ builtin__OBJ__ shell__OBJ__ \
	kanji__OBJ__ input__OBJ__
OBJ3	= info__OBJ__ rockridg__OBJ__ archive__OBJ__ tree__OBJ__ \
	command__OBJ__ browse__OBJ__
ALLOC	=
DEBUG	=

LDFLAGS	= __TERMLIBS__ __REGLIBS__ __OTHERLIBS__ $(ALLOC)
CFLAGS	= -D__OSTYPE__=1 __CCOPTIONS__ $(DEBUG)

.SUFFIXES: .h .c __OBJ__ __EXE__

############################################################
#	Dependency Rules
############################################################

all:	$(PROGRAM)__EXE__ $(PROGRAM).$(MANSEC) __UNITBL__

$(PROGRAM)__EXE__: $(OBJ1) $(OBJ2) $(OBJ3) $(ARGS)
	$(CC) $(CFLAGS) __MEM__ __LNK__ __OBJLIST__ $(LDFLAGS)
	__RENAME__ $@ $(PROGRAM)
	__AOUT2EXE__ $(PROGRAM)
	__REMOVE__ $(PROGRAM)

$(ARGS): $(OBJ1) $(OBJ2) $(OBJ3)
	@echo $(OBJ1) > $(ARGS)
	@echo $(OBJ2) >> $(ARGS)
	@echo $(OBJ3) >> $(ARGS)

main__OBJ__: main.c
	$(CC) -DFD=1 $(CFLAGS) __MEM__ $(CPPFLAGS) -c __OUT__ -DDEFRUNCOM=__DEFRC__ $*.c

.c__OBJ__:
	$(CC) -DFD=1 $(CFLAGS) __MEM__ $(CPPFLAGS) -c __OUT__ $*.c


############################################################
# kanji using module

kanji.h: kanjicnv__EXE__ kanji.hin machine.h config.h
	./kanjicnv__EXE__ __KCODEOPTION__ __PREFIXOPTION__ __MSBOPTION__ kanji.hin $@

$(PROGRAM).$(MANSEC): kanjicnv__EXE__ $(MANSRC) machine.h config.h
	./kanjicnv__EXE__ __KCODEOPTION__ __PREFIXOPTION__ $(MANSRC) $@

$(PROGRAM).$(MANSEC)c: kanjicnv__EXE__ $(MANCAT) machine.h config.h
	./kanjicnv__EXE__ __KCODEOPTION__ $(MANCAT) $@

$(PROGRAM).doc: kanjicnv__EXE__ $(MANCAT) machine.h config.h
	./kanjicnv__EXE__ __KCODEOPTION__ -b $(MANCAT) $@

README.doc: kanjicnv__EXE__ README machine.h config.h
	./kanjicnv__EXE__ __KCODEOPTION__ README $@

HISTORY.doc: kanjicnv__EXE__ HISTORY machine.h config.h
	./kanjicnv__EXE__ __KCODEOPTION__ HISTORY $@

FAQ.doc: kanjicnv__EXE__ FAQ machine.h config.h
	./kanjicnv__EXE__ __KCODEOPTION__ FAQ $@

kanjicnv__EXE__: kanjicnv.c
	$(CC) $(CFLAGS) __LNK__ kanjicnv.c
	__RENAME__ $@ kanjicnv
	__AOUT2EXE__ kanjicnv
	__REMOVE__ kanjicnv


############################################################
# function list using module

funcno.h: mkfuncno__EXE__
	./mkfuncno__EXE__ $@

mkfuncno__EXE__: mkfuncno.c functabl.h fd.h config.h
	$(CC) $(CFLAGS) __LNK__ mkfuncno.c
	__RENAME__ $@ mkfuncno
	__AOUT2EXE__ mkfuncno
	__REMOVE__ mkfuncno

config.h: config.hin
	__COPY__ config.hin config.h


############################################################
# UNICODE table generating module

$(UNITBL): mkunitbl__EXE__
	./mkunitbl__EXE__ $@

mkunitbl__EXE__: mkunitbl.c
	$(CC) $(CFLAGS) __LNK__ mkunitbl.c
	__RENAME__ $@ mkunitbl
	__AOUT2EXE__ mkunitbl
	__REMOVE__ mkunitbl


############################################################
# to install all

install: $(PROGRAM)__EXE__ $(PROGRAM).$(MANSEC) __UNITBL__
	$(INSTALL) __INSTSTRIP__ $(PROGRAM)__EXE__ $(BINDIR)
	$(CHMOD) a+rx $(BINDIR)/$(PROGRAM)__EXE__
	$(INSTALL) $(PROGRAM).$(MANSEC) $(MANDIR)/$(PROGRAM).$(MANSEC)
	$(CHMOD) a+r $(MANDIR)/$(PROGRAM).$(MANSEC)
	-if [ -f $(RUNCOM) ]; then \
		$(INSTALL) $(RUNCOM) $(DEFRC); \
		$(CHMOD) a+r $(DEFRC); \
	fi
	-if [ -f $(UNITBL) ]; then \
		$(INSTALL) $(UNITBL) $(BINDIR); \
		$(CHMOD) a+r $(BINDIR)/$(UNITBL); \
	fi

catman: $(PROGRAM).$(MANSEC)c
	$(INSTALL) $(PROGRAM).$(MANSEC)c $(CATDIR)/$(PROGRAM).$(MANSEC)
	$(CHMOD) a+r $(CATDIR)/$(PROGRAM).$(MANSEC)

catman-b: $(PROGRAM).doc
	$(INSTALL) $(PROGRAM).doc $(CATDIR)/$(PROGRAM).$(MANSEC)
	$(CHMOD) a+r $(CATDIR)/$(PROGRAM).$(MANSEC)

compman: catman
	compress -f $(CATDIR)/$(PROGRAM).$(MANSEC)

compman-b: catman-b
	compress -f $(CATDIR)/$(PROGRAM).$(MANSEC)


############################################################
# to make dependency

depend: $(SRC) kanji.h funcno.h
	mv Makefile.in Makefile.in.bak
	makedepend -s "# DO NOT DELETE THIS LINE -- make depend depends on it."\
		-f Makefile.tmp -- $(CFLAGS) -- $(SRC)
	rm -f Makefile.tmp.bak
	$(SED) -e '/^# DO NOT DELETE THIS LINE/,$$d' Makefile.in.bak\
		> Makefile.in
	echo "# DO NOT DELETE THIS LINE -- make depend depends on it."\
		>> Makefile.in
	$(SED) -e '1,/^# DO NOT DELETE THIS LINE/d'\
		-e 's/\/[^ ]* *//g'\
		-e 's/\.o/\_\_OBJ\_\_/g'\
		-e 's/ *$$//'\
		-e '/: *$$/d' Makefile.tmp >> Makefile.in
	rm -f Makefile.in.bak Makefile.tmp


############################################################
# to make configuration file manually

config: Configur expfunc.c
	-if (echo 't() { echo $1; }; t test' | $(SHELL) >/dev/null 2>&1); then \
		$(SED) -e "2,3d" -e "s:__cc__:__CC__:" Configur \
		| $(SHELL) > config.h; \
	else \
		if [ ! -f expfunc ]; then \
			$(CC) $(CFLAGS) -o expfunc expfunc.c; \
		fi; \
		$(SED) -e "2,3d" -e "s:__cc__:__CC__:" Configur \
		| ./expfunc | $(SHELL) > config.h; \
	fi


############################################################
# for programer's maintenance

GETVER	= HEAD="`tail -1 version.h`";\
	VER=`expr "$$HEAD" : '.*\([0-9][0-9]*\.[0-9a-z\-]*\).*'`

tar: $(SOURCES)
	($(GETVER);\
	tar cvf $(TITLE)"$$VER".tar $(SOURCES);\
	compress -f $(TITLE)"$$VER".tar)

lzh: $(SOURCES)
	($(GETVER);\
	rm -f $(TITLE)"$$VER".lzh;\
	lha a $(TITLE)"$$VER".lzh $(SOURCES))

shar: $(SOURCES)
	($(GETVER);\
	rm -f $(TITLE)$$VER.shar.[0-9][0-9];\
	shar -L50 -apc -n $(TITLE)"$$VER" -o $(TITLE)"$$VER".shar \
	-C $(JSRCS) -T $(ESRCS))

clean:
	-rm -f *__OBJ__ funcno.h kanji.h
	-rm -f kanjicnv__EXE__ mkfuncno__EXE__ expfunc__EXE__ mkunitbl__EXE__
	-rm -f $(PROGRAM)__EXE__ $(PROGRAM).$(MANSEC) $(PROGRAM).$(MANSEC)c
	-rm -f $(PROGRAM).doc $(ARGS)
	-rm -f core __UNITBL__
# DO NOT DELETE THIS LINE -- make depend depends on it.

main__OBJ__: fd.h
main__OBJ__: machine.h config.h
main__OBJ__: types.h pathname.h term.h
main__OBJ__: func.h
main__OBJ__: kanji.h version.h
main__OBJ__: dosdisk.h
term__OBJ__: machine.h config.h
term__OBJ__: term.h
pathname__OBJ__: machine.h config.h
pathname__OBJ__: pathname.h
dosdisk__OBJ__: machine.h config.h
dosdisk__OBJ__: dosdisk.h
dosemu__OBJ__: fd.h
dosemu__OBJ__: machine.h config.h
dosemu__OBJ__: types.h pathname.h func.h
dosemu__OBJ__: kctype.h
dosemu__OBJ__: dosdisk.h
unixdisk__OBJ__: machine.h config.h
unixdisk__OBJ__: unixdisk.h
unixdisk__OBJ__: unixemu.h
unixdisk__OBJ__: dosdisk.h
unixemu__OBJ__: fd.h
unixemu__OBJ__: machine.h config.h
unixemu__OBJ__: types.h pathname.h func.h
unixemu__OBJ__: unixdisk.h
unixemu__OBJ__: unixemu.h dosdisk.h
libc__OBJ__: fd.h
libc__OBJ__: machine.h config.h
libc__OBJ__: types.h pathname.h term.h func.h
libc__OBJ__: kctype.h kanji.h
file__OBJ__: fd.h
file__OBJ__: machine.h config.h
file__OBJ__: types.h pathname.h func.h
file__OBJ__: kctype.h kanji.h
apply__OBJ__: fd.h
apply__OBJ__: machine.h config.h
apply__OBJ__: types.h pathname.h term.h func.h
apply__OBJ__: kanji.h
parse__OBJ__: fd.h
parse__OBJ__: machine.h config.h
parse__OBJ__: types.h pathname.h func.h
parse__OBJ__: kctype.h
parse__OBJ__: dosdisk.h
builtin__OBJ__: fd.h
builtin__OBJ__: machine.h config.h
builtin__OBJ__: types.h pathname.h term.h func.h
builtin__OBJ__: kctype.h
builtin__OBJ__: funcno.h kanji.h dosdisk.h
shell__OBJ__: fd.h
shell__OBJ__: machine.h config.h
shell__OBJ__: types.h pathname.h term.h func.h
shell__OBJ__: kctype.h
shell__OBJ__: kanji.h
kanji__OBJ__: machine.h config.h
kanji__OBJ__: term.h kctype.h
input__OBJ__: fd.h
input__OBJ__: machine.h config.h
input__OBJ__: types.h pathname.h
input__OBJ__: term.h func.h
input__OBJ__: kctype.h
input__OBJ__: kanji.h
info__OBJ__: fd.h
info__OBJ__: machine.h config.h
info__OBJ__: types.h pathname.h term.h funcno.h kctype.h
info__OBJ__: kanji.h
rockridg__OBJ__: fd.h
rockridg__OBJ__: machine.h config.h
rockridg__OBJ__: types.h pathname.h func.h
archive__OBJ__: fd.h
archive__OBJ__: machine.h
archive__OBJ__: config.h types.h
archive__OBJ__: pathname.h term.h func.h
archive__OBJ__: funcno.h kctype.h kanji.h
tree__OBJ__: fd.h
tree__OBJ__: machine.h config.h
tree__OBJ__: types.h pathname.h term.h
tree__OBJ__: func.h
tree__OBJ__: kanji.h
command__OBJ__: fd.h
command__OBJ__: machine.h config.h
command__OBJ__: types.h pathname.h term.h func.h
command__OBJ__: funcno.h kctype.h
command__OBJ__: kanji.h
command__OBJ__: functabl.h
browse__OBJ__: fd.h
browse__OBJ__: machine.h config.h
browse__OBJ__: types.h pathname.h
browse__OBJ__: term.h func.h
browse__OBJ__: funcno.h kctype.h
browse__OBJ__: kanji.h
mkfuncno__OBJ__: fd.h
mkfuncno__OBJ__: machine.h config.h
mkfuncno__OBJ__: types.h pathname.h functabl.h
mkmfsed__OBJ__: machine.h config.h
