# In MacOS X the -v option causes the infamous "Bus error".
#YACC=bison -dtv
#YACC=bison -dt
YACC=bison -t

parser: QMath_parser.tab.cc QMath_parser.tab.cc.h all

%.tab.cc: %.y
	$(YACC) -o $@ --defines=$@.h $<
	mv $@.h $@.h.raw
	echo  >$@.h "#ifndef _H_"`echo "$@" | sed 's/\.h$$//' | tr [:lower:]. [:upper:]_`
	echo >>$@.h "#define _H_"`echo "$@" | sed 's/\.h$$//' | tr [:lower:]. [:upper:]_`
	echo >>$@.h
	cat $@.h.raw >>$@.h
	echo >>$@.h "#endif"


CXXFLAGS += -Wall -I..

.SILENT :
.EXPORT_ALL_VARIABLES :

.PHONY : all
.PHONY : subdirectories

all: subdirectories
	OBJECT_FILES=''
	for f in *.c *.cc *.cxx *.cpp; do                  \
	  case "$$f" in                                          \
	    \*.*)                                                \
	      ;;                                                 \
	    *)                                                   \
	      obj=`echo $$f | sed 's/^\(.*\)\.[cxp]*$$/\1.o/'` ;\
	      OBJECT_FILES="$$OBJECT_FILES $$obj"               ;\
	      ;;                                                 \
	  esac                                                  ;\
	done                                                    ;\
	if [ "$$OBJECT_FILES" ]; then $(MAKE) $$OBJECT_FILES; fi

subdirectories:
	for d in *; do if [ -f "$$d/makefile" ]; then echo "- make $$d"; $(MAKE) -C $$d; fi; done
