-
Notifications
You must be signed in to change notification settings - Fork 549
/
rules.mk
52 lines (38 loc) · 1.26 KB
/
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
46
47
48
49
50
51
52
#
# Common rules for makefiles for the PX4 bootloaders
#
BUILD_DIR = $(BUILD_DIR_ROOT)/$(TARGET_FILE_NAME)
COBJS := $(addprefix $(BUILD_DIR)/, $(patsubst %.c,%.o,$(SRCS)))
AOBJS := $(addprefix $(BUILD_DIR)/, $(patsubst %.S,%.o,$(ASRCS)))
SUBDIRS := $(sort $(addprefix $(BUILD_DIR)/, $(dir $(ASRCS))) $(addprefix $(BUILD_DIR)/, $(dir $(SRCS))) )
OBJS := $(COBJS) $(AOBJS)
DEPS := $(COBJS:.o=.d)
ELF = $(BUILD_DIR)/$(TARGET_FILE_NAME).elf
HEX = $(BUILD_DIR)/$(TARGET_FILE_NAME).hex
BINARY = $(BUILD_DIR)/$(TARGET_FILE_NAME).bin
FLAGS += -Xlinker -Map=$(BUILD_DIR)/${TARGET_FILE_NAME}.map
all: debug $(BUILD_DIR) $(ELF) $(BINARY) $(HEX)
debug:
# @echo SRCS=$(SRCS)
# @echo COBJS=$(COBJS)
# @echo ASRCS=$(ASRCS)
# @echo AOBJS=$(AOBJS)
# @echo SUBDIRS=$(SUBDIRS)
# Compile and generate dependency files
$(BUILD_DIR)/%.o: %.c
@echo Generating object $@
$(CC) -c -MMD $(FLAGS) -o $@ $<
$(BUILD_DIR)/%.o: %.S
@echo Generating object $@
$(CC) -c -MMD $(FLAGS) -o $@ $*.S
# Make the build directory
$(BUILD_DIR) $(SUBDIRS):
mkdir -p $(BUILD_DIR) $(SUBDIRS)
$(ELF): $(OBJS) $(MAKEFILE_LIST)
$(CC) -o $@ $(OBJS) $(FLAGS)
$(BINARY): $(ELF)
$(OBJCOPY) -O binary $(ELF) $(BINARY)
$(HEX): $(ELF)
$(OBJCOPY) -Oihex $(ELF) $(HEX)
# Dependencies for .o files
-include $(DEPS)