1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
CXX = g++
LEX = flex
YACC = bison
CXXFLAGS ?= -g -Wall -W -Werror
LDFLAGS ?= -g -Wall -W -Werror
CXXSOURCES = $(wildcard *.cpp)
LEXSOURCES = $(wildcard *.ll)
YACCSOURCES = $(wildcard *.yy)
TREESOURCES = $(wildcard *.ftree)
OBJECTS = $(CXXSOURCES:%.cpp=%.o) $(LEXSOURCES:%.ll=%_lex.o) $(YACCSOURCES:%.yy=%_parse.o) $(YACCSOURCES:%.yy=%_tree.o)
DEPFILES = $(addprefix stage1/,$(OBJECTS:%.o=.%.d)) $(addprefix stage2/,$(OBJECTS:%.o=.%.d))
all: foundry-tree \
tree_tree.hpp-stamp tree_tree.cpp-stamp \
tree_bison_tree.hpp-stamp tree_bison_tree.cpp-stamp \
tree_cst_tree.hpp-stamp tree_cst_tree.cpp-stamp
foundry-tree: $(addprefix stage2/,$(OBJECTS))
$(CXX) $(LDFLAGS) -o $@ $^
stage1/foundry-tree: $(addprefix stage1/,$(OBJECTS))
$(CXX) $(LDFLAGS) -o $@ $^
stage2/%_tree.hpp: %.ftree stage1/foundry-tree
stage1/foundry-tree -o $@ $<
stage2/%_tree.cpp: %.ftree stage1/foundry-tree
stage1/foundry-tree -c -o $@ $<
stage2/%_tree.hpp: %.yy stage1/foundry-tree
stage1/foundry-tree -n foundry -n $(subst _, -n ,$*) -o $@ $<
stage2/%_tree.cpp: %.yy stage1/foundry-tree
stage1/foundry-tree -n foundry -n $(subst _, -n ,$*) -c -o $@ $<
%-stamp: % update/% stage2/%
cmp $(wordlist 1,2,$^) || (cmp $(wordlist 2,3,$^) && mv update/$< $<)
touch $@
update/%_tree.hpp: %.ftree foundry-tree
@mkdir -p update
./foundry-tree -o $@ $<
update/%_tree.cpp: %.ftree foundry-tree
@mkdir -p update
./foundry-tree -c -o $@ $<
update/%_tree.hpp: %.yy foundry-tree
@mkdir -p update
./foundry-tree -n foundry -n $(subst _, -n ,$*) -o $@ $<
update/%_tree.cpp: %.yy foundry-tree
@mkdir -p update
./foundry-tree -n foundry -n $(subst _, -n ,$*) -c -o $@ $<
%_lex.cpp: %.ll
$(LEX) -o $@ $<
%_parse.cpp: %.yy
$(YACC) -o $@ $<
%_lex.hpp: %_lex.cpp
@
%_parse.hpp: %_parse.cpp
@
STAGE1_BUILT_HEADERS = $(YACCSOURCES:%.yy=%_parse.hpp) $(YACCSOURCES:%.yy=%_tree.hpp) $(LEXSOURCES:%.ll=%_lex.hpp) $(TREESOURCES:%.ftree=%_tree.hpp)
STAGE2_BUILT_HEADERS = $(YACCSOURCES:%.yy=%_parse.hpp) $(addprefix stage2/,$(YACCSOURCES:%.yy=%_tree.hpp)) $(LEXSOURCES:%.ll=%_lex.hpp) $(addprefix stage2/,$(TREESOURCES:%.ftree=%_tree.hpp))
stage1/%.o: %.cpp
$(CXX) $(CXXFLAGS) -I. -o $@ -MD -MF stage1/.$*.d -c $<
stage2/%.o: %.cpp
$(CXX) $(CXXFLAGS) -Istage2 -I. -o $@ -MD -MF stage2/.$*.d -c $<
stage2/tree_tree.o: stage2/tree_tree.cpp
$(CXX) $(CXXFLAGS) -Istage2 -I. -o $@ -MD -MF stage2/.$*.d -c $<
stage2/tree_bison_tree.o: stage2/tree_bison_tree.cpp
$(CXX) $(CXXFLAGS) -Istage2 -I. -o $@ -MD -MF stage2/.$*.d -c $<
stage2/tree_cst_tree.o: stage2/tree_cst_tree.cpp
$(CXX) $(CXXFLAGS) -Istage2 -I. -o $@ -MD -MF stage2/.$*.d -c $<
stage1/tree_bison_lex.o stage2/tree_bison_lex.o: CXXFLAGS+=-Wno-unused
stage1/tree_cst_lex.o stage2/tree_cst_lex.o: CXXFLAGS+=-Wno-unused
stage1/.%.d:
@mkdir -p $(@D)
@echo >$@ "stage1/$*.o: $(STAGE1_BUILT_HEADERS)"
stage2/.%.d:
@mkdir -p $(@D)
@echo >$@ "stage2/$*.o: $(STAGE2_BUILT_HEADERS)"
clean:
$(RM) *-stamp
$(RM) foundry-tree
$(RM) -r update stage2 stage1
sinclude $(DEPFILES)
.SUFFIXES:
.DELETE_ON_ERROR:
|