# makefile for pjc's csh Copyright Julian H Stacey 21-8-89 @(#) Version 1.0
# supersedes all previous single op system makefiles and batch scripts,
# to be called from directory above in common with all berklix stuff.

# This makefile works for both
#	1) berkley unix/make/bourne shell
#	2) msdos with a minix make that has been ported, and command.com.
# Do not change the syntax without checking on both machines.

SRC_C = alias.c cond.c dirs.c env.c eval.c exec.c glob.c \
 hash.c hist.c inp.c main.c misc.c parse.c shvars.c
OBJS_1 = alias.$(OBJ) cond.$(OBJ) dirs.$(OBJ) env.$(OBJ) eval.$(OBJ) \
 exec.$(OBJ) glob.$(OBJ) hash.$(OBJ)
OBJS_2 = hist.$(OBJ) inp.$(OBJ) main.$(OBJ) misc.$(OBJ) parse.$(OBJ) \
 shvars.$(OBJ)
OBJECTS  = $(OBJS_1) $(OBJS_2)
SRC_CH   = $(SRC_C) csh.h
SOURCES  = $(SRC_CH) makefile notes.jhs
LINT_LNT = bsd.lnt ms.lnt v7.lnt v6.lnt

all:
	@echo It would have been better to have typed	cd ..	make
	@echo We will assume unix and sufficient process ram for a nested make.
	/usr/bin/local/make -f ../include/make/system_5 \
		-f ../include/make/unix -f makefile unix

unix:	start $(INST_DIR)csh end

msdos:	start $(INST_DIR)csh.exe end

bak:
	transfer -s $(SOURCES)

start:
	@echo Making csh$(EXE).

end:
	@echo Finished csh$(EXE).

${OBJECTS}: csh.h

#.SUFFIXES: .obj .c

.c.obj:
	 $(CC) -c $(FLAGS) -I$(INC_LOCAL) $*.c

.c.o:
	 $(CC) -c $(FLAGS) -I$(INC_LOCAL) $*.c

$(INST_DIR)csh: $(VSL_COMPS) ${OBJECTS}
	@echo Generating $(INST_DIR)csh
	$(CC) -o $(INST_DIR)csh ${OBJECTS} $(VSL_LIB).$(OBJ)
	strip $(INST_DIR)csh
	@$(CHGRP) $@
	@$(CHMOD) $(CHMOD_ARGS) $@

$(INST_DIR)csh.exe: $(VSL_COMPS) ${OBJECTS} $(LIB_DIRECT).$(OBJ)
	@echo Generating $(INST_DIR)csh.exe
	echo Making MSDOS MSC Link control file.
	echo $(VSL_LIB).$(OBJ) +	> $(DV_ROOT)csh.lnk
	echo $(OBJS_1) +		>> $(DV_ROOT)csh.lnk
	echo $(OBJS_2)	+		>> $(DV_ROOT)csh.lnk
	echo $(LIB_DIRECT).$(OBJ)	>> $(DV_ROOT)csh.lnk
	echo $(DV_ROOT)csh.exe		>> $(DV_ROOT)csh.lnk
	echo $(DV_ROOT)csh.map ;	>> $(DV_ROOT)csh.lnk
	link @$(DV_ROOT)csh.lnk
	@rm $(DV_ROOT)csh.map $(DV_ROOT)csh.lnk
	exepack $(DV_ROOT)csh.exe $@
	$(EXPIRE)
	$(REPLACE)
	@del $(DV_ROOT)csh.exe
	@echo Just saying exemod csh.exe causes a stack overflow, even without
	@echo any parameters, so do it manually later.
	@echo Stack was 4000, but need large stack for reading termcap entry
	-exemod $@ /stack 7000
	pause 
	$(CHGRP) $@
	@$(CHMOD) $(CHMOD_ARGS) $@

clean:  cleanlint
	-rm $(OBJS_1)
	-rm $(OBJS_2)
	-rm $(DV_ROOT)csh.lnk $(DV_ROOT)csh.map csh$(EXE) $(DV_ROOT)csh.exe

cleanmore:	clean
	@echo dummy entry

cleanlint:
	-rm $(LINT_LNT)
#-------------------------------------------------------------------------------

lint:   $(LINT_LNT)
	ls -l $(LINT_LNT)
LINT_FLAGS = hbxac
#	h	  Apply a number of heuristic tests to attempt to intuit
#	b	  Report break statements that cannot be reached.  (This
#	x	  Report variables referred to by extern declarations,
#	a	  Report assignments of long values to int variables.
#	c	  Complain about casts which have questionable portabil-
#	n	  Do not check compatibility against the standard library.
bsd.lnt: $(SRC_CH)
	lint -$(LINT_FLAGS) $(SRC_C)	> $@

v7.lnt: $(SRC_CH)
	lint -$(LINT_FLAGS)n -DV7 -Uns32000 -I/usr/include/v7 $(SRC_C) > $@

v6.lnt: $(SRC_CH)
	lint -$(LINT_FLAGS)n -DV6 -Uns32000 -I/usr/include/v6 $(SRC_C) > $@
#	standard V6 doesnt have many include files.

ms.lnt: $(SRC_CH)
	lint -$(LINT_FLAGS)n -DMSDOS -DNO_EXT_KEYS -Uunix -Uns32000 \
	  -I/usr/include/ms $(SRC_C) | grep -v fprintf: | grep -v open: > $@
#	NO_EXT_KEYS is to avoid the cdecl ansi C component of the header files
#	ms stdio needs VARARGS 2 adding, but im not doing it.
