Skip to content

Commit

Permalink
Perform out-of-tree builds with Makefile
Browse files Browse the repository at this point in the history
Apart from being highly desirable on its own to avoid clutter in the
root folder, this also fixes an error that occurs during cmake
out-of-tree builds if there are left-overs from a make in-tree build.

After some consideration and research, I believe that there is no
reasonable way in cmake to isolate the unwanted files from the build.
The simplest option is to perform out-of-tree builds in make as well.

In fact, the existence of in-tree generated header files during
out-of-tree builds can always lead to inconsistencies between different
translation units because we cannot reliably enfore that the out-of-tree
header is used from everywhere.

Resolves #7.

Notably, the compile-time error in #7 occured due to the fact that the
include guards of in/out-of-tree headers were different, which could
lead to both variants of a header being included, and hence redefinition
errors. However, this is not the actual issue, but rather a symptom that
we were lucky enough to observe.
  • Loading branch information
coldfix committed Jan 10, 2018
1 parent 1c9ae0b commit 2304bd1
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
OBJS = main.o parser.o scanner.o citip.o
BUILDDIR = build
OBJS = $(addprefix $(BUILDDIR)/,main.o parser.o scanner.o citip.o)
CPPFLAGS = -MMD -MP
CXXFLAGS = -std=c++11
CXXFLAGS = -std=c++11 -I. -I$(BUILDDIR)

all: Citip
all: prepare Citip

Citip: $(OBJS)
g++ -o $@ $^ -lglpk

%.o: %.cpp
$(BUILDDIR)/%.o: %.cpp
$(CXX) -o $@ -c $< $(CPPFLAGS) $(CXXFLAGS)

%.o: %.cxx
$(BUILDDIR)/%.o: $(BUILDDIR)/%.cxx
$(CXX) -o $@ -c $< $(CPPFLAGS) $(CXXFLAGS)

parser.cxx: parser.y
bison -o $@ --defines=parser.hxx $<
$(BUILDDIR)/parser.cxx: parser.y
bison -o $@ --defines=$(BUILDDIR)/parser.hxx $<

scanner.cxx: scanner.l
flex -o $@ --header-file=scanner.hxx $<
$(BUILDDIR)/scanner.cxx: scanner.l
flex -o $@ --header-file=$(BUILDDIR)/scanner.hxx $<

$(OBJS): scanner.cxx parser.cxx
$(OBJS): $(BUILDDIR)/scanner.cxx $(BUILDDIR)/parser.cxx

.PHONY: prepare all
prepare:
@mkdir -p $(BUILDDIR)

clean:
rm -f *.o *.cxx *.hxx *.hh *.d
rm -rf $(BUILDDIR)

clobber: clean
rm -f Citip
Expand Down

0 comments on commit 2304bd1

Please sign in to comment.