muforth/Makefile

# This file is part of muFORTH: http://pages.nimblemachines.com/muforth
#
# Copyright (c) 2002-2008 David Frech. All rights reserved, and all wrongs
# reversed. (See the file COPYRIGHT for details.)

###
### GNU Makefile for muforth, a "micro" Forth
###

# Set by configure
SEDEXT=		-r

CFLAGS=		-O2 -Wall -fomit-frame-pointer -m32
#CFLAGS=	-g -Wall -fomit-frame-pointer -DDEBUG -DBEING_DEFINED
LDFLAGS=	-m32

# Core objects
COREOBJS=	kernel.o interpret.o dict.o file.o \
		error.o time.o tty.o select.o engine-itc.o

# If any of these files changes, make a new version.h
VERSOBJS=	${COREOBJS}

ALLOBJS=	${VERSOBJS} muforth.o
DEPFILES=	Makefile muforth.h env.h

.PHONY: all clean httplink diffsed

all : public.h muforth

${ALLOBJS} : ${DEPFILES}

muforth.o : version.h

public.h : ${ALLOBJS:.o=.ph}
	@echo Making $@
	(echo "/* This file is automagically generated. Do not edit! */"; \
	cat $^) > $@

forth_chain.h : public.h scripts/gen_dict_chain.sed
	@echo Making $@
	@(echo "/* This file is automagically generated. Do not edit! */"; \
	sed ${SEDEXT} \
		-e '/^void mu_compiler/d' \
		-f scripts/gen_dict_chain.sed public.h \
	) > $@

compiler_chain.h : public.h scripts/gen_dict_chain.sed
	@echo Making $@
	@(echo "/* This file is automagically generated. Do not edit! */"; \
	sed ${SEDEXT} \
		-e '/^void mu_compiler/!d' \
		-e 's/mu_compiler_/mu_/' \
		-f scripts/gen_dict_chain.sed \
		-e 's/mu_/mu_compiler_/' public.h \
	) > $@

dict.o : forth_chain.h compiler_chain.h

.SUFFIXES : .ph

.c.ph : Makefile
	@echo Making $@
	@(echo "/* $< */"; \
	sed ${SEDEXT} -n \
		-e '/^#if/,/^#endif/d' \
		-e '/^static /d' \
		-e 's/^([a-z]+ \**[a-z_0-9]+)\((void)?\).*$$/\1(void);/p' \
		-e 's/^(pw [a-z_0-9]+).*;$$/extern \1;/p' \
		$<; \
	echo) > $@

env.h : envtest
	./envtest > $@

version.h : Makefile ${VERSOBJS:.o=.c}
	@echo Making $@
	@echo "time_t build_time = `date \"+%s\"`;" > version.h

muforth : ${ALLOBJS} ${DEPFILES}
	${CC} ${LDFLAGS} -o $@ ${ALLOBJS} ${LIBS}

.c.asm : Makefile muforth.h
	${CC} ${CFLAGS} -S -o $@ -c $<

clean :
	rm -f muforth version.h *.o *.asm env.h envtest
	rm -f *.ph public.h forth_chain.h compiler_chain.h

distclean : clean
	rm -f Makefile GNUmakefile *.sed

# program avr via avrdude
avr.img : target/AVR/loader.mu4 target/AVR/bitbang.mu4
	./muforth -v -f target/AVR/loader.mu4 -f target/AVR/bitbang.mu4 bye

avr : avr.img
	avrdude -v -c stk500 -p t45 -P /dev/ttyS0 -U flash:w:$<:r

# install Vim bits
install-vim :
	tar cf - .vim | (cd ~; tar xf -)