Makefile 2.57 KB
Newer Older
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
# This Makefile made available to his students by 
# Prof. Ronald Moore  
#     https://fbi.h-da.de/personen/ronald-moore/  
#     mailto:ronald.moore@h-da.de
# with no warranties whatsoever


PROGS := interpret++
SOURCES := main.cpp lexer.cpp parser.cpp
OBJS = $(SOURCES:.cpp=.o)

# Uncomment only one of the next two lines (choose your c++ compiler)
# CC=g++
CC := clang++

## Add your own CFLAGS if you find them necessary... such as -O3 or so... 
##    -g for debugging
##    -std=<whatever> to select the right C++ Version
##    -fmessage-length=0 disallows line wrapping in error messages
##    (helps some IDEs (still?))
CPPFLAGS :=  -g -std=c++17 -Wall -fmessage-length=0


## More preliminaries
# See https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
# In this makefile, we want to keep going even if we find errors
.IGNORE :

# Tell make that the following "targets" are "phony"
# Cf. https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets
.PHONY : all clean tests

# This absolutely needs to be the first target (so to be the default target)
all: $(PROGS)

#  Some of the "Automatic Variables" that can be used in Makefiles.
#      Cf. https://www.gnu.org/software/make/manual/  - particularly
# https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html#Automatic-Variables
# $@ = The filename representing the target.
# $< = The filename of the first prerequisite.
# $(*F) = The stem of the filename of the target (i.e. without .o, .cpp...)
# $^ = The names of all the prerequisites, with spaces between them.

## Following magic is used to figure out which dot cpp files depend
# on which headers (dot h files) -- automatically (so that we recompile
# only the ncessary dot cpp files when a header is maodified).
# Magic taken from 
# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
#  ... and then fixed, and fixed, and fixed some more.
DEPDIR := .deps
# Broken: DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d
DEPFLAGS = -MMD -MF $(DEPDIR)/$*.d

# include dep files, if they exist (minus says don't complain if they don't)
DEPS := $(OBJS:%.o=$(DEPDIR)/%.d)

-include $(DEPS)

%.o : %.cpp %.d
	$(CC) -c $(CPPFLAGS) $(DEPFLAGS) -o $@ $<

# Make depdir if it doesn't exist... 
$(DEPDIR): ; @mkdir -p $@

##  Now, the targets -- the things that will get made!

$(PROGS): $(OBJS) 
	$(CC) $(CPPFLAGS) $(OBJS) $(LIBS) -o $@

clean: 
	$(RM) -v *~ *.o $(PROGS) tmp.txt
	$(RM) -fvr $(DEPDIR)
	# starting recursive clean...
	cd tests && $(MAKE) clean

tests: $(PROGS)
	# Going to the tests directory for testing
	cd tests && $(MAKE) tests