@@ -10,7 +10,8 @@ include ../py/py.mk
1010CROSS_COMPILE = arm-none-eabi-
1111
1212CFLAGS_CORTEX_M3 = -mthumb -mcpu=cortex-m3
13- CFLAGS = -I. -I$(PY_SRC ) -Wall -ansi -std=gnu99 $(CFLAGS_CORTEX_M3 ) $(COPT )
13+ CFLAGS = -I. -I$(PY_SRC ) -Wall -ansi -std=gnu99 $(CFLAGS_CORTEX_M3 ) $(COPT ) \
14+ -flto -ffunction-sections -fdata-sections
1415
1516# Debugging/Optimization
1617ifeq ($(DEBUG ) , 1)
2021COPT += -Os -DNDEBUG
2122endif
2223
23- # LDFLAGS = --nostdlib -T stm32f405.ld -Map=$(@:.elf=.map) --cref
24- LDFLAGS = -lm -T generic-m-hosted.ld # -Map=$(@:.elf=.map) --cref
25- LIBS =
26-
27- # uncomment this if you want libgcc
28- # LIBS += $(shell $(CC) -print-libgcc-file-name)
24+ # # With CoudeSourcery it's actually a little different, you just need `-T generic-m-hosted.ld`.
25+ # # Although for some reason `$(LD)` will not find that linker script, it works with `$(CC)`.
26+ # # It turns out that this is specific to CoudeSourcery, and ARM version of GCC ships something
27+ # # else instead and according to the following files, this is what we need to pass to `$(CC).
28+ # # - gcc-arm-none-eabi-4_8-2014q1/share/gcc-arm-none-eabi/samples/src/makefile.conf
29+ # # - gcc-arm-none-eabi-4_8-2014q1/share/gcc-arm-none-eabi/samples/src/qemu/Makefile
30+ LDFLAGS = --specs=nano.specs --specs=rdimon.specs -Wl,--gc-sections -Wl,-Map=$(@:.elf=.map )
2931
3032SRC_C = \
31- help.c \
32- math.c \
33-
34- # gccollect.c \
35- #pyexec.c \
33+ main.c \
3634
3735SRC_S = \
38- gchelper.s \
3936
4037OBJ =
4138OBJ += $(PY_O )
4239OBJ += $(addprefix $(BUILD ) /, $(SRC_C:.c=.o ) )
4340OBJ += $(addprefix $(BUILD ) /, $(SRC_S:.s=.o ) )
4441
45- all : $(BUILD ) /flash.elf
42+ all : run
43+
44+ run : $(BUILD ) /flash.elf
4645
47- run :
4846 qemu-system-arm -cpu cortex-m3 -nographic -monitor null -serial null -semihosting -kernel $(BUILD)/flash.elf
4947
48+ # # `$(LD)` doesn't seem to like `--specs` for some reason, but we can just use `$(CC)` here.
5049$(BUILD ) /flash.elf : $(OBJ )
51- $(Q )$(CC ) $(CFLAGS ) $(LDFLAGS ) main.c -o $@ $(OBJ ) $(LIBS )
50+ $(Q )$(CC ) $(CFLAGS ) $(LDFLAGS ) -o $@ $(OBJ ) $(LIBS )
5251 $(Q )$(SIZE ) $@
5352
5453include ../py/mkrules.mk
0 commit comments