# Standard Linux makefile for BSD csh.

CC	= gcc
CCOMPAT	= -I/usr/include/bsd -include /usr/include/bsd/bsd.h 
CDEFS	= -DFILEC -DNLS -DSHORT_STRINGS -I.
CPPFLAGS= $(CCOMPAT) $(CDEFS)
CFLAGS	= -g -O2

INSTALL_BIN = install -c -s -g root -m 0755 -o root
INSTALL_DIR = install -d -g root -m 0755 -o root
INSTALL_MAN = install -c -g root -m 0644 -o root

BINDIR	= /bin
MANDIR	= /usr/man/man1

SOURCES	= alloc.c char.c const.c csh.c dir.c dol.c err.c exec.o exp.c file.c \
	  func.c glob.c hist.c init.c lex.c misc.c parse.c print.c printf.c \
	  proc.c sem.c set.c str.c time.c

all:	err.h const.h csh

csh:	$(SOURCES:.c=.o)

err.h: 
	@rm -f $@
	@echo '/* Do not edit this file, make creates it. */' > $@
	@echo '#ifndef _h_sh_err' >> $@
	@echo '#define _h_sh_err' >> $@
	egrep 'ERR_' ./$*.c | egrep '^#define' >> $@
	@echo '#endif /* _h_sh_err */' >> $@

const.h: 
	@rm -f $@
	@echo '/* Do not edit this file, make creates it. */' > $@
	${CC} -E ${CPPFLAGS} ./$*.c | egrep 'Char STR' | \
	    sed -e 's/Char \([a-zA-Z0-9_]*\)\(.*\)/extern Char \1[];/' | \
	    sort >> $@

install:
	$(INSTALL_DIR) $(PREFIX)$(BINDIR)
	$(INSTALL_DIR) $(PREFIX)$(MANDIR)
	$(INSTALL_BIN) csh $(PREFIX)$(BINDIR)
	$(INSTALL_MAN) csh.1 $(PREFIX)$(MANDIR)

clean: 
	rm -f *.o core

distclean: clean
	rm -f csh const.h err.h
