# title	   makefile for yodl

depth = ../..
NAME = yodl

MODULE_LIBS= ../lib

EXTRA_DIST_FILES = VERSION
STEPMAKE_TEMPLATES=c executable
GRAM_FILES = $(wildcard gram*.c)
BUILTINS = $(shell echo $(GRAM_FILES:gram%.c=%) | tr '[a-z]' '[A-Z]')

include $(depth)/make/stepmake.make 

$(O_FILES): $(outdir)/builtins.h $(outdir)/builtins.c 

default: $(EXECUTABLE)


# script?
$(outdir)/builtins.h:
	rm -f $@
	echo "/*" >> $@;
	echo "  Automatically generated by make" >> $@;
	echo "  Do not edit" >> $@;
	echo "*/" >> $@;
	echo "#define MAX_BUILTINS $(words 0 $(BUILTINS))" >> $@;

#	echo "extern struct Builtin builtins[];" >> $@;
#	urg cygnus' gnu-windows

	echo "extern struct Builtin builtins[MAX_BUILTINS + 1];" >> $@
	for i in $(BUILTINS); do \
	  echo "void gram_$$i ();" >> $@;\
	done
	echo >> $@;
	echo "typedef enum " >> $@;
	echo "  {" >> $@;
	for i in $(BUILTINS); do \
	  echo "    idx_$$i," >> $@;\
	done
	echo "  } BUILTIN_INDEX;" >> $@;

$(outdir)/builtins.c:
	rm -f $@
	echo "/*" >> $@;
	echo "  Automatically generated by make" >> $@;
	echo "  Do not edit" >> $@;
	echo "*/" >> $@;
	echo "struct Builtin builtins[MAX_BUILTINS + 1] = " >> $@;
	echo "  {" >> $@;
	for i in $(BUILTINS); do \
	  echo "    { \"$$i\", gram_$$i }, " >> $@;\
	done
	echo "    { 0, 0 }, " >> $@;\
	echo "  };" >> $@;



VERSION: $(depth)/VERSION
	cp $< $@

