-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.mk
45 lines (32 loc) · 832 Bytes
/
rules.mk
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
.DEFAULT_GOAL = all
DEPDIR := .dependencies
DEP := $(addprefix $(DEPDIR)/,$(subst /,-,$(OBJ:.o=.dep)))
TARGET := $(if $(MCU),-mmcu=$(MCU),)
CFLAGS += -std=c11 -pedantic -Wall -Wextra
CFLAGS += -MMD -MP -MF $(DEPDIR)/$(subst /,-,$*).dep
ASFLAGS += -mN -mY
ASFLAGS += -MP -MD $(DEPDIR)/$(subst /,-,$*).dep
.SUFFIXES:
.SECONDARY:
.PHONY: all debug clean
all: CFLAGS += -Os
all: LDFLAGS += -s
all: $(BIN) $(LIB)
debug: CFLAGS += -O0 -g
debug: ASFLAGS += -g
debug: $(BIN) $(LIB)
clean:
rm -f $(BIN) $(LIB) $(OBJ)
rm -rf $(DEPDIR)
$(BIN): $(OBJ)
$(CC) $(TARGET) -minrt -o $@ $^ $(LDFLAGS)
$(LIB): $(OBJ)
$(AR) rcs $@ $^
%.o: %.c $(DEPDIR)/sentinel
$(CC) $(TARGET) -c $(CFLAGS) -o $@ $<
%.o: %.s $(DEPDIR)/sentinel
$(AS) $(TARGET) $(ASFLAGS) -o $@ $<
$(DEPDIR)/sentinel:
@mkdir -p $(@D)
@touch $@
-include $(DEP)