# makefile for pjc's nroff Copyright Julian H Stacey 21-8-89 @(#) Version 1.0
# (pjc never got round to writing one)

# 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 = alloc.c cmdtab.c cond.c div.c font.c \
 input.c macro.c nroff.c reg.c sysreg.c \
 title.c when.c
OBJS_1 = alloc.$(OBJ) cmdtab.$(OBJ) cond.$(OBJ) div.$(OBJ) font.$(OBJ) \
 input.$(OBJ) macro.$(OBJ)
OBJS_2 = nroff.$(OBJ) reg.$(OBJ) sysreg.$(OBJ) title.$(OBJ) when.$(OBJ)
OBJECTS  = $(OBJS_1) $(OBJS_2)
SRC_CH   = $(SRC_C) nroff.h
SOURCES  = $(SRC_CH) makefile timings notes
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

bak:
	transfer -s $(SOURCES)

unix:	start $(INST_DIR)nroff end

msdos:	start $(INST_DIR)nroff.exe end

start:
	@echo Making nroff.

end:
	@echo Finished nroff.

${OBJECTS}: nroff.h

#.SUFFIXES: .obj .c

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

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

$(INST_DIR)nroff.exe: $(VSL_COMPS) ${OBJECTS}
	@echo Generating $(INST_DIR)nroff.exe  
	@echo Creating an msdos link control file.
	@echo $(VSL_LIB).$(OBJ) +	> $(DV_ROOT)nroff.lnk
	@echo $(OBJS_1) +		>> $(DV_ROOT)nroff.lnk
	@echo $(OBJS_2)	+		>> $(DV_ROOT)nroff.lnk
	@echo $(ARGV_OBJ)		>> $(DV_ROOT)nroff.lnk
	@echo $(DV_ROOT)nroff.exe	>> $(DV_ROOT)nroff.lnk
	@echo $(DV_ROOT)nroff.map ;	>> $(DV_ROOT)nroff.lnk
	link @$(DV_ROOT)nroff.lnk
	@rm $(DV_ROOT)nroff.map $(DV_ROOT)nroff.lnk
	exepack		$(DV_ROOT)nroff.exe $@
	@del		$(DV_ROOT)nroff.exe   
	$(EXPIRE)
	$(REPLACE)
	@$(CHMOD) $(CHMOD_ARGS) $@

#-------------------------------------------------------------------------------

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

cleanmore:

lintclean: cleanlint
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.
