-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
56 lines (44 loc) · 1.14 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
# Target executables
TARGET = tilemaker
TEST = test
# Extensions
SRCEXT = c
# Folder structure
SRCDIR = src
TSTDIR = test
BULDIR = build
INCDIR = include
# Sources and directories
SRCS := $(shell find $(SRCDIR) -name '*.$(SRCEXT)')
SRCDIRS := $(shell find $(SRCDIR) -name '*.$(SRCEXT)' -exec dirname {} \; | uniq)
TSTS := $(shell find $(TSTDIR) -name '*.$(SRCEXT)')
TSTDIRS := $(shell find $(TSTDIR) -name '*.$(SRCEXT)' -exec dirname {} \; | uniq)
OBJS := $(patsubst %.$(SRCEXT),$(BULDIR)/%.o,$(SRCS))
# Flags and compiler definition
CC = gcc
INCLUDES = -I./$(INCDIR)
CFLAGS = -Wall -c $(INCLUDES)
LDFLAGS = -lm -lpng
DEBUG = -d
all: $(TARGET)
$(TARGET): buildrepo $(OBJS)
@echo "Linking $@..."
@$(CC) $(OBJS) $(LDFLAGS) -o $@
$(TEST): buildrepo $(OBJS)
@echo "Not yet implemented..."
$(BULDIR)/%.o: %.$(SRCEXT)
@echo "Generating dependencies for $<..."
@$(call make-depend,$<,$@,$(subst .o,.d,$@))
@echo "Compiling $<..."
@$(CC) $(CFLAGS) $< -o $@
clean:
rm -rf $(BULDIR)
rm -f $(TARGET)
buildrepo:
@$(call make-repo)
define make-repo
for dir in $(SRCDIRS); \
do \
mkdir -p $(BULDIR)/$$dir; \
done
endef