-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
57 lines (41 loc) · 1.15 KB
/
Makefile
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
# Project name
EXEC=compilo
TEST_EXEC=testo
CXX=gcc
LINKER=gcc -o
# Compiler
IDIR=src
IDIRFLAG=$(foreach idir, $(IDIR), -I$(idir))
CXXFLAGS=-Wall $(IDIRFLAG)
# Linker
LFLAGS=$(IDIRFLAG)
# Directories
SRCDIR=src
OBJDIR=obj
BINDIR=.
# Files
SOURCES=$(foreach sdir, $(SRCDIR), $(wildcard $(sdir)/*.c))
OBJECTS=$(patsubst %.c, $(OBJDIR)/%.o, $(notdir $(SOURCES)))
# Can have only one main function per executable
EXEC_OBJECTS=$(filter-out $(OBJDIR)/test.o, $(OBJECTS))
TEST_OBJECTS=$(filter-out $(OBJDIR)/main.o, $(OBJECTS))
vpath %.c $(SRCDIR)
# Reminder, 'cause it is easy to forget makefile's fucked-up syntax...
# $@ is what triggered the rule, ie the target before :
# $^ is the whole dependencies list, ie everything after :
# $< is the first item in the dependencies list
# Rules
all: main test
main: $(BINDIR)/$(EXEC)
test: $(BINDIR)/$(TEST_EXEC)
debug: CXXFLAGS += -ggdb -DDEBUG
debug: clean all
$(BINDIR)/$(EXEC): $(EXEC_OBJECTS)
$(LINKER) $@ $^ $(LFLAGS)
$(BINDIR)/$(TEST_EXEC): $(TEST_OBJECTS)
$(LINKER) $@ $^ $(LFLAGS)
$(OBJDIR)/%.o: %.c
$(CXX) $(CXXFLAGS) -c $< -o $@
.PHONY: clean all main test debug
clean:
rm -fr $(OBJECTS) $(BINDIR)/$(EXEC)