summaryrefslogtreecommitdiff
path: root/Makefile
blob: 05676ee6eb7814ac1cd41ca46ff6594dced7798a (plain)
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
CXX := g++
CXXFLAGS := -Wall -Wextra -std=c++11 -O2 -isystem /usr/local/include -I.
LIBS := -lfltk -L/usr/local/lib
BIN := game

object_src := $(wildcard src/objects/*.cpp)
object_obj := $(patsubst src/objects/%.cpp,build/objects/%.o,$(object_src))
object_head := $(patsubst src/objects/%.cpp,build/objects/%.h,$(object_src))
object_xlist := $(shell echo $$(for f in $(object_src); do basename $$f | sed 's/\.[^.]*$$//' | sed 's/.*/X(&)/'; done))

base_src := $(wildcard *_base.cpp)
base_src += library.cpp main.cpp
base_obj := $(patsubst %.cpp,build/%.o,$(base_src))

.PHONY: all clean remake

#keep all intermediate files!
.SECONDARY:

all: $(BIN)

clean:
	rm -rf build $(BIN)

remake: clean all


$(BIN): $(base_obj) $(object_obj)
	$(CXX) $(CXXFLAGS) $(LIBS) -o $(BIN) $^

build/main.o: main.cpp build/objects.h
	@mkdir -p $(dir $@)
	$(CXX) $(CXXFLAGS) -c -o "$@" "$<" "-DOBJECT_CLASSES_XLIST=$(object_xlist)" "-DGAME_NAME=\"$(BIN)\""

build/objects/%.o: build/objects/%.cpp
	@mkdir -p $(dir $@)
	$(CXX) $(CXXFLAGS) -c -o "$@" $^

build/objects/%.cpp: src/objects/%.cpp
	@mkdir -p $(dir $@)
	$(CXX) -E object_wrapper.cpp "-D__OBJECT_FNAME__=\"$<\"" "-D__OBJECT_NAME__=$(basename $(notdir $<))" | sed 's/^# [0-9]\+ ".*//' >"$@"

build/objects/%.h: src/objects/%.cpp
	@mkdir -p $(dir $@)
	$(CXX) -E object_header_maker.cpp "-D__OBJECT_NAME__=$(basename $(notdir $<))" "-DEVENT_XLIST=$$($(CXX) -E object_header_extractor.cpp "-D__OBJECT_FNAME__=\"$<\"" | sed 's/__________EVENT_NEWLINE__________/\n/g' | grep -oe '__________EVENT_COUNTER_TAG_[^_]*__________' | sed 's/[^G]*G_\(.*\)__________.*/X(\1)/g' | xargs)" | sed 's/^# [0-9]\+ ".*//' >"$@"

build/objects.h: $(object_head)
	echo $(object_head) | xargs -n 1 basename | sed 's,.*,#include "objects/&",' >"$@"

build/%.o: %.cpp
	@mkdir -p $(dir $@)
	$(CXX) $(CXXFLAGS) -c -o "$@" $^