#sccs "@(#)ksh/sh:Makefile	1.3"

include $(MAKEINC)/Makepre.h

ID = id.o
U370 =
DATA=data
FIXDATA=text
TESTDIR = .
ARK = lib.a
SHLIB = ../shlib
D=  -DKSHELL
D4_2 =
sh = ksh
# The following line must be set to make either the emacs or vi version of ksh
EDIT = edit.o
# The following two lines are used for one line emacs editor
EMACS = emacs.o
DESH = -DESH
# The following two lines are used for one line vi editor
VI = vi.o
DVSH = -DVSH
# The following line is used for vi mode always raw (u370 requires this)
# VIRAW = -DRAWONLY
VIRAW =
DJOBS = -DJOBS
JOBS = jobs.o
CINC = $D $(DVSH) $(DESH) $(DJOBS) $(DBSD) $(VIRAW) $(NOBUF) $(INT16) $(SXT) $(DEVFD) $(D4_1c) $(D4_2)  $(VENIX)
C = $(CC) $D $(DVSH) $(DESH) $(DJOBS) $(DBSD) $(VIRAW) $(NOBUF) $(INT16) $(SXT) $(DEVFD) $(D4_1c) $(D4_2)  $(VENIX)
CC_CMD = $(C) $(CFLAGS) -c
OFILES = builtin.o \
args.o \
blok.o \
cmd.o \
ctype.o \
defs.o \
echo.o \
error.o \
expand.o\
fault.o \
history.o\
io.o \
macro.o \
main.o \
msg.o \
name.o \
print.o \
service.o \
stak.o \
test.o \
xec.o \
word.o \
$(EDIT) \
$(EMACS) \
$(VI) \
$(JOBS) \
$(MYIO)

EDITFILES = editlib.o \
edit.o \
history.o \
$(EMACS) \
$(VI)  \
$(SYSCALL)

DEPENDLIST = args.c \
	blok.c \
	builtin.c \
	cmd.c \
	ctype.c \
	defs.c \
	echo.c \
	edit.c \
	editlib.c \
	emacs.c\
	error.c \
	expand.c \
	fault.c \
	history.c \
	io.c \
	jobs.c \
	macro.c \
	main.c \
	msg.c \
	name.c \
	print.c \
	service.c \
	stak.c \
	stdio.c \
	test.c \
	vi.c \
	word.c \
	xec.c

all: Makeincludes $(sh)

Makeincludes: $(DEPENDLIST)
	$(INCCMD) $(CINC) $(DEPENDLIST) | $(SORT) | $(FILTER) > Makeincludes
	$(MAKE)

includes: $(DEPENDLIST)
	$(INCCMD) $(CINC) $(DEPENDLIST) | $(SORT) | $(FILTER) > Makeincludes

$(sh): $(OFILES) $(SHLIB)/$(ARK) $(ID)
	$(C) -s -o $(TESTDIR)/$(sh) $(OFILES) $(SHLIB)/$(ARK) $(ID) $(JOBLIB)
	file $(TESTDIR)/$(sh)
	size $(TESTDIR)/$(sh)

ctype.o:	ctype.c
		-set -ex; if test  "$(FIXDATA)" ;\
		then \
		$(C) -O -S -c ctype.c ;\
		sed 's/^\([ 	]*\.*\)$(DATA)/\1$(FIXDATA)/g' ctype.s > temp.s ;\
		$(AS) -o ctype.o temp.s ;\
		rm ctype.s temp.s ;\
		else \
		$(CC_CMD) ctype.c ;\
		fi

emacs.o:	emacs.c
	set -ex; if test  "$(U370)" = "" ;\
	then \
	$(CC_CMD) emacs.c ;\
	else \
	$(CC_CMD) -b2,0 emacs.c ;\
	fi

msg.o:		msg.c
		-set -ex; if test  "$(FIXDATA)" ;\
		then \
		$(C) -O -S -c msg.c ;\
		sed 's/^\([ 	]*\.*\)$(DATA)/\1$(FIXDATA)/g' msg.s > temp.s ;\
		$(AS) -o msg.o temp.s ;\
		rm msg.s temp.s ;\
		else \
		$(CC_CMD) msg.c ;\
		fi

builtin.o:		builtin.c
	-set -ex; if test  "$(U370)" = "" ;\
	then \
	$(CC_CMD) builtin.c ;\
	else \
	$(CC_CMD) -b2,0 builtin.c ;\
	fi

xec.o:		xec.c
	-set -ex; if test  "$(U370)" = "" ;\
	then \
	$(CC_CMD) xec.c ;\
	else \
	$(CC_CMD) -b1,0 xec.c ;\
	fi

install:
	$(INSTALL) -i$(EXITFLAG) $(sh) $(INSDIR) $(PROTOFILE)

clean:
	  -rm -f *.o

clobber:  clean
	  -rm -f $(sh)

ctype.o:	shtype.h
edit.o:	brkincr.h
edit.o:	builtins.h
edit.o:	defs.h
edit.o:	flags.h
edit.o:	ksh_name.h
edit.o:	io.h
edit.o:	sym.h
edit.o:	shtype.h
emacs.o:	defs.h
emacs.o:	io.h
emacs.o:	shtype.h
echo.o:		brkincr.h
echo.o:		defs.h
history.o:	builtins.h
history.o:	defs.h
history.o:	flags.h
history.o:	io.h
history.o:	ksh_name.h
history.o:	shtype.h
history.o:	stak.h
vi.o:	defs.h
vi.o:	flags.h
vi.o:	io.h
vi.o:	shtype.h

id.c: ../ksh.sl
	mkslid >id.c

populate:
	getunit

include Makeincludes
include $(MAKEINC)/Makepost.h

.c.o:
	$(CC_CMD) $*.c
