-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
66 lines (52 loc) · 1.07 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
58
59
60
61
62
63
64
65
66
# Target programs
programs := basic.x \
half_limit.x \
square_start.x \
no_evens.x
# Default rule
all: $(programs)
# Avoid builtin rules and variables
MAKEFLAGS += -rR
# Don't print the commands unless explicitly requested with `make V=1`
ifneq ($(V),1)
Q = @
V = 0
endif
# Current directory
CUR_PWD := $(shell pwd)
# Define compilation toolchain
CC = gcc
# General gcc options
CFLAGS := -Wall -Werror
CFLAGS += -pipe
## Debug flag
ifneq ($(D),1)
CFLAGS += -O2
else
CFLAGS += -O0
CFLAGS += -g
endif
# Linker options
LDFLAGS := -L$(FSPATH) -lfs
# Generate dependencies
DEPFLAGS = -MMD -MF $(@:.o=.d)
src := $(wildcard *.c)
objs := $(src:.c=.o)
deps := $(src:.c=.d)
# Include dependencies
-include $(deps)
# Generic rule for linking final applications
%.x: %.c bitmap.o
@echo "LD $@"
$(Q)$(CC) $(CFLAGS) -o $@ $< bitmap.o $(LDFLAGS)
# Generic object compilation
%.o: %.c
@echo "CC $@"
$(Q)$(CC) $(CFLAGS) -c -o $@ $< $(DEPFLAGS)
# Cleaning rule
clean:
@echo "CLEAN $(CUR_PWD)"
$(Q)rm -rf $(objs) $(deps) $(programs)
# Keep bitmap.o around
.PRECIOUS: bitmap.o
.PHONY: clean