# ---------------------------------------------------------------------- # Makefile for XSLT simd # # I use a very conservative assumption that every .c/.cpp file depends # on every .h/.hpp file. Use ccache to avoid excessive recompiles. # (http://ccache.samba.org/) .PHONY: clean less-dirty test all # ---------------------------------------------------------------------- # programs we need. This Makefile is probably a bit unix specific... CC=gcc CXX=g++ UNTARGZ=tar zxf UNZIP=unzip -o TOUCH=touch ECHO=echo RENAME=mv RM=rm -rf PYTHON=python READONLY=chmod u-w # ---------------------------------------------------------------------- # Compilation flags CFLAGS+=-I ${EXPATDIR}/lib -g -O0 -I ${BUILDDIR} -I ${SRCDIR} -Wall CXXFLAGS=${CFLAGS} TUTFLAGS=${CFLAGS} -ftemplate-depth-100 # ---------------------------------------------------------------------- # all: the default target SRCDIR=src BUILDDIR=build FINAL=${BUILDDIR}/xslt EXTHFILES= all: $(FINAL) # ---------------------------------------------------------------------- # build: the build directory ${BUILDDIR}: mkdir -p ${BUILDDIR} mkdir -p ${BUILDDIR}/c mkdir -p ${BUILDDIR}/cpp mkdir -p ${BUILDDIR}/test clean: ${RM} ${BUILDDIR} # Avoids rebuilding expact and other more expensive stuff. less-dirty: ${RM} ${BUILDDIR}/* # ---------------------------------------------------------------------- # Expat: our XML parser EXPATVER=2.0.0 EXPATTGZ=external/expat-$(EXPATVER).tar.gz EXPATDIR=${BUILDDIR}/expat-$(EXPATVER) EXPATMK=$(EXPATDIR)/Makefile EXPATLIB=$(EXPATDIR)/.libs/libexpat.a $(EXPATMK): if [[ ! -a $(EXPATDIR) ]] ; \ then cd ${BUILDDIR};${UNTARGZ} ../$(EXPATTGZ) ; \ fi cd $(EXPATDIR) ; ./configure $(EXPATLIB): $(EXPATMK) cd $(EXPATDIR) ; make # ---------------------------------------------------------------------- # Lemon: our parser generator LEMONDIR=${BUILDDIR} LEMONSRC=external/lemon.c LEMONTMPL=external/lempar.c LEMON=${LEMONDIR}/lemon ${LEMON}: ${LEMONSRC} ${LEMONTMPL} mkdir -p ${LEMONDIR} gcc -o $@ ${LEMONSRC} cp ${LEMONTMPL} ${LEMONDIR} # ---------------------------------------------------------------------- # Our XPath 2.0 parser (built in Lemon) XP2P_DIR=${BUILDDIR} XP2P_OBJ=${XP2P_DIR}/xpath20parser.o XP2P_SRC=${SRCDIR}/xpath20parser.y XP2P_CFILE=${XP2P_DIR}/xpath20parser.c XP2P_HFILE=${XP2P_DIR}/xpath20parser.h EXTHFILES+=${XP2P_HFILE} ${XP2P_CFILE}: ${XP2P_SRC} ${LEMON} ${LEMON} ${XP2P_SRC} ${RENAME} ${SRCDIR}/xpath20parser.c ${XP2P_DIR} ${RENAME} ${SRCDIR}/xpath20parser.h ${XP2P_DIR} ${RENAME} ${SRCDIR}/xpath20parser.out ${XP2P_DIR} ${XP2P_HFILE}: ${XP2P_CFILE} ${ECHO} '' >> ${XP2P_HFILE} ${ECHO} 'extern void Xpath2Parse(' >> ${XP2P_HFILE} ${ECHO} ' void *yyp,' >> ${XP2P_HFILE} ${ECHO} ' int token_id,' >> ${XP2P_HFILE} ${ECHO} ' const char *token_str,' >> ${XP2P_HFILE} ${ECHO} ' struct XpathBuilder* build);' >> ${XP2P_HFILE} # Hack: compile the parser's C file with CXX to get C++ compilation # for now. ${XP2P_OBJ}: ${XP2P_CFILE} ${CXX} ${CFLAGS} -c -o $@ $< # ---------------------------------------------------------------------- # Our Flow IR 2.0 parser (built in Lemon) FLOWIRP_DIR=${BUILDDIR} FLOWIRP_OBJ=${FLOWIRP_DIR}/flowir_grammar.o FLOWIRP_SRC=${SRCDIR}/flowir_grammar.y FLOWIRP_YFILE=${FLOWIRP_DIR}/flowir_grammar.y FLOWIRP_CFILE=${FLOWIRP_DIR}/flowir_grammar.c FLOWIRP_HFILE=${FLOWIRP_DIR}/flowir_grammar.h EXTHFILES+=${FLOWIRP_HFILE} ${FLOWIRP_YFILE}: ${FLOWIRP_SRC} ${RM} ${FLOWIRP_YFILE} cp ${FLOWIRP_SRC} ${BUILDDIR} ${READONLY} ${FLOWIRP_YFILE} ${FLOWIRP_HFILE} ${FLOWIRP_CFILE}: ${FLOWIRP_YFILE} ${LEMON} ${RM} ${FLOWIRP_CFILE} ${FLOWIRP_HFILE} ${LEMON} ${FLOWIRP_YFILE} ${READONLY} ${FLOWIRP_CFILE} ${FLOWIRP_HFILE} # Hack: compile the parser's C file with CXX to get C++ compilation # for now. ${FLOWIRP_OBJ}: ${FLOWIRP_CFILE} ${CXX} ${CFLAGS} -c -o $@ $< # ---------------------------------------------------------------------- # TUT: unit testing framework TUTDIR=${BUILDDIR} TUTZIP=external/TUT-2006-03-29.zip TUTH=${TUTDIR}/tut.h TUTREPORTERH=${TUTDIR}/tut_reporter.h EXTHFILES+=${TUTH} ${TUTREPORTERH} ${TUTH}: ${TUTDIR} ${TUTZIP} ${UNZIP} ${TUTZIP} tut.h -d ${TUTDIR} ${TOUCH} ${TUTH} ${TUTREPORTERH}: ${TUTDIR} ${TUTZIP} ${UNZIP} ${TUTZIP} tut_reporter.h -d ${TUTDIR} ${TOUCH} ${TUTREPORTERH} # ---------------------------------------------------------------------- # Generated Flow Sources FLOWIR_OPCODES_HPP=${BUILDDIR}/flowir_opcodes.hpp EXTHFILES+=${FLOWIR_OPCODES_HPP} ${FLOWIR_OPCODES_HPP}: ${SRCDIR}/flowir_opcodes.py ${RM} ${FLOWIR_OPCODES_HPP} ${PYTHON} ${SRCDIR}/flowir_opcodes.py > ${FLOWIR_OPCODES_HPP} ${READONLY} ${FLOWIR_OPCODES_HPP} # ---------------------------------------------------------------------- # Our C and C++ Sources CFILES=$(shell ls ${SRCDIR}/*.c) COBJS=$(CFILES:${SRCDIR}/%.c=${BUILDDIR}/c/%.o) CPPFILES=$(shell ls ${SRCDIR}/*.cpp) CPPOBJS=$(CPPFILES:${SRCDIR}/%.cpp=${BUILDDIR}/cpp/%.o) TESTFILES=$(shell ls ${SRCDIR}/test/*.cpp) TESTOBJS=$(TESTFILES:${SRCDIR}/test/%.cpp=${BUILDDIR}/test/%.o) HFILES=$(shell ls ${SRCDIR}/*.h ${SRCDIR}/*.hpp) ${EXTHFILES} ALLOBJS=${COBJS} ${CPPOBJS} ${TESTOBJS} ${FLOWIRP_OBJ} # ${XP2P_OBJ} #Separate build rules for C, C++, and testing files. This way the #dependency between the .o and the expected file (.c vs .cpp) is very #clear. Hopefully we can eventually move to an all C++ set of #sources, and then we wouldn't need this distinction. (Though we'd #probably still want to separate out the test files as they use #otherwise unused features). ${BUILDDIR}/c/%.o: ${SRCDIR}/%.c ${HFILES} ${CC} ${CFLAGS} -c -o $@ $< ${BUILDDIR}/cpp/%.o: ${SRCDIR}/%.cpp ${HFILES} ${CXX} ${CFLAGS} -c -o $@ $< ${BUILDDIR}/test/%.o: ${SRCDIR}/test/%.cpp ${HFILES} ${CXX} ${TUTFLAGS} -c -o $@ $< ${BUILDDIR}/xslt: build ${EXPATLIB} ${ALLOBJS} ${CXX} -o $@ ${ALLOBJS} ${EXPATLIB} -lm -lstdc++ test: ${BUILDDIR}/xslt ${BUILDDIR}/xslt --test