Skip to content

Commit 96e415e

Browse files
committed
🔨 add dependency management
1 parent 76dfabd commit 96e415e

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

cpp/Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@ INC_FLAGS = $(addprefix -I,$(INC_DIRS))
4848
# Target-specific flags
4949
CPU_FLAGS ?= -mfloat-abi=$(FLOAT_ABI) -m$(INSTR_SET) -mcpu=$(CPU)
5050

51-
CPPFLAGS ?=$(DEFS) $(INC_FLAGS)
51+
CPPFLAGS ?= -MMD $(DEFS) $(INC_FLAGS)
5252
CFLAGS ?=$(CPU_FLAGS) $(OPT)
5353
CXXFLAGS :=$(CFLAGS) -fno-exceptions -fno-rtti
5454
LDFLAGS ?=$(CPU_FLAGS)
5555

56-
# dependency
57-
CXXFLAGS += -M
56+
5857

5958
# Do not link stdlib with executable
6059
CFLAGS += -nostdlib -fno-tree-loop-distribute-patterns -fdata-sections -ffunction-sections
@@ -93,10 +92,10 @@ $(BUILD_DIR)/%.s:%.cpp
9392
@echo "AS" $< " ==> " $@
9493
$(CXX) $(CPPFLAGS) $(CXXLAGS) -o $@ -S $<
9594

96-
# $(BUILD_DIR)/%.o:%.c
97-
# @mkdir -p $(dir $@)
98-
# @echo "CC" $< " ==> " $@
99-
# $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
95+
$(BUILD_DIR)/%.o:%.c
96+
@mkdir -p $(dir $@)
97+
@echo "CC" $< " ==> " $@
98+
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
10099

101100
$(BUILD_DIR)/%.o:%.cpp
102101
@mkdir -p $(dir $@)
@@ -105,7 +104,7 @@ $(BUILD_DIR)/%.o:%.cpp
105104

106105
$(BUILD_DIR)/$(TARGET).elf: $(OBJS)
107106
@echo "Linking sources into "$@
108-
@$(CC) $(LDFLAGS) -o $@ $^
107+
$(CC) $(LDFLAGS) -o $@ $^
109108

110109

111110
flash: bin
@@ -117,3 +116,6 @@ debug: all
117116

118117
clean:
119118
rm -rf build
119+
120+
121+
-include $(OBJS:%.o=%.d)

cpp/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,22 @@ make flash
135135
3. Click in Run and Debug option in VsCode sidebar. Then launch Cortex Debug target.
136136

137137
Happy debugging....
138+
139+
### Dependency option
140+
-M
141+
Outputs a rule suitable for makefile, does not compile the file
142+
The generated rule does not have a command
143+
144+
-MM
145+
Outputs a rule suitable for makefile, does not compile the file.
146+
In the dependencies only include user files, do not include system header files
147+
148+
-MT/-MQ (-MM -MT abc.o) => change the target
149+
This changes the name of the target
150+
-MT => generates the same string as provided
151+
-MQ => replaces value of the make variable in the target (expansation)
152+
153+
-MD => D represents that the preprocessor output should be generated as a side effect and the main compilation happens
154+
If -o options is specified then it is taken as name for the preprocessor output with .d
155+
else name of input file is taken with extensions as .d
156+
To override the name of the pre-processor output file -MF option should be used

cpp/main.s

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.cpu arm7tdmi
2+
.arch armv4t
3+
.fpu softvfp
4+
.eabi_attribute 20, 1
5+
.eabi_attribute 21, 1
6+
.eabi_attribute 23, 3
7+
.eabi_attribute 24, 1
8+
.eabi_attribute 25, 1
9+
.eabi_attribute 26, 1
10+
.eabi_attribute 30, 6
11+
.eabi_attribute 34, 0
12+
.eabi_attribute 18, 4
13+
.file "main.cpp"

0 commit comments

Comments
 (0)