Skip to content

Commit 0dbd928

Browse files
committed
Makefiles: Remove duplicate object files when linking.
Scenario: module1 depends on some common file from lib/, so specifies it in its SRC_MOD, and the same situation with module2, then common file from lib/ eventually ends up listed twice in $(OBJ), which leads to link errors. Make is equipped to deal with such situation easily, quoting the manual: "The value of $^ omits duplicate prerequisites, while $+ retains them and preserves their order." So, just use $^ consistently in all link targets.
1 parent 9a334d4 commit 0dbd928

8 files changed

Lines changed: 10 additions & 10 deletions

File tree

bare-arm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ all: $(BUILD)/firmware.elf
4242

4343
$(BUILD)/firmware.elf: $(OBJ)
4444
$(ECHO) "LINK $@"
45-
$(Q)$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
45+
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
4646
$(Q)$(SIZE) $@
4747

4848
include ../py/mkrules.mk

esp8266/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ $(BUILD)/firmware-combined.bin: $(BUILD)/firmware.elf
124124

125125
$(BUILD)/firmware.elf: $(OBJ)
126126
$(ECHO) "LINK $@"
127-
$(Q)$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
127+
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
128128
$(Q)$(SIZE) $@
129129

130130
#MAKE_PINS = boards/make-pins.py

minimal/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ all: $(BUILD)/firmware.elf
5959

6060
$(BUILD)/firmware.elf: $(OBJ)
6161
$(ECHO) "LINK $@"
62-
$(Q)$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
62+
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
6363
$(Q)$(SIZE) $@
6464

6565
# Run emulation build on a POSIX system with suitable terminal settings

pic16bit/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ $(BUILD)/firmware.hex: $(BUILD)/firmware.elf
5757

5858
$(BUILD)/firmware.elf: $(OBJ)
5959
$(ECHO) "LINK $@"
60-
$(Q)$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
60+
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
6161
$(Q)size $@
6262

6363
$(PY_BUILD)/gc.o: CFLAGS += -O1

py/mkrules.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ all: $(PROG)
8181

8282
$(PROG): $(OBJ)
8383
$(ECHO) "LINK $@"
84-
$(Q)$(CC) $(COPT) -o $@ $(OBJ) $(LIB) $(LDFLAGS)
84+
$(Q)$(CC) $(COPT) -o $@ $^ $(LIB) $(LDFLAGS)
8585
ifndef DEBUG
8686
$(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG)
8787
endif
8888
$(Q)$(SIZE) $(PROG)
8989

9090
lib: $(OBJ)
91-
$(AR) rcs libmicropython.a $(OBJ)
91+
$(AR) rcs libmicropython.a $^
9292

9393
clean: clean-prog
9494
clean-prog:

qemu-arm/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ $(BUILD)/tinytest.o:
7474

7575
## `$(LD)` doesn't seem to like `--specs` for some reason, but we can just use `$(CC)` here.
7676
$(BUILD)/firmware.elf: $(OBJ)
77-
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
77+
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
7878
$(Q)$(SIZE) $@
7979

8080
$(BUILD)/firmware-test.elf: $(OBJ_TEST)
81-
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ_TEST) $(LIBS)
81+
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
8282
$(Q)$(SIZE) $@
8383

8484
include ../py/mkrules.mk

stmhal/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ $(BUILD)/firmware.hex: $(BUILD)/firmware.elf
285285

286286
$(BUILD)/firmware.elf: $(OBJ)
287287
$(ECHO) "LINK $@"
288-
$(Q)$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
288+
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
289289
$(Q)$(SIZE) $@
290290

291291
MAKE_PINS = boards/make-pins.py

teensy/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ deploy: post_compile reboot
156156

157157
$(BUILD)/micropython.elf: $(OBJ)
158158
$(ECHO) "LINK $@"
159-
$(Q)$(CC) $(LDFLAGS) -o "$@" -Wl,-Map,$(@:.elf=.map) $(OBJ) $(LIBS)
159+
$(Q)$(CC) $(LDFLAGS) -o "$@" -Wl,-Map,$(@:.elf=.map) $^ $(LIBS)
160160
$(Q)$(SIZE) $@
161161

162162
ifeq ($(MEMZIP_DIR),)

0 commit comments

Comments
 (0)