Makefile 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. include ../../py/mkenv.mk
  2. -include mpconfigport.mk
  3. # qstr definitions (must come before including py.mk)
  4. QSTR_DEFS = qstrdefsport.h
  5. # include py core make definitions
  6. include $(TOP)/py/py.mk
  7. CROSS_COMPILE = arm-none-eabi-
  8. TINYTEST = $(TOP)/lib/tinytest
  9. INC += -I.
  10. INC += -I$(TOP)
  11. INC += -I$(BUILD)
  12. INC += -I$(TINYTEST)
  13. CFLAGS_CORTEX_M3 = -mthumb -mcpu=cortex-m3 -mfloat-abi=soft
  14. CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -std=gnu99 $(CFLAGS_CORTEX_M3) $(COPT) \
  15. -ffunction-sections -fdata-sections
  16. #Debugging/Optimization
  17. ifeq ($(DEBUG), 1)
  18. CFLAGS += -g -DPENDSV_DEBUG
  19. COPT = -O0
  20. else
  21. COPT += -Os -DNDEBUG
  22. endif
  23. ## With CoudeSourcery it's actually a little different, you just need `-T generic-m-hosted.ld`.
  24. ## Although for some reason `$(LD)` will not find that linker script, it works with `$(CC)`.
  25. ## It turns out that this is specific to CoudeSourcery, and ARM version of GCC ships something
  26. ## else instead and according to the following files, this is what we need to pass to `$(CC).
  27. ## - gcc-arm-none-eabi-4_8-2014q1/share/gcc-arm-none-eabi/samples/src/makefile.conf
  28. ## - gcc-arm-none-eabi-4_8-2014q1/share/gcc-arm-none-eabi/samples/src/qemu/Makefile
  29. LDFLAGS= --specs=nano.specs --specs=rdimon.specs -Wl,--gc-sections -Wl,-Map=$(@:.elf=.map)
  30. SRC_COMMON_C = \
  31. moduos.c \
  32. modmachine.c \
  33. SRC_RUN_C = \
  34. main.c \
  35. SRC_TEST_C = \
  36. test_main.c \
  37. LIB_SRC_C += $(addprefix lib/,\
  38. libm/math.c \
  39. libm/fmodf.c \
  40. libm/nearbyintf.c \
  41. libm/ef_sqrt.c \
  42. libm/kf_rem_pio2.c \
  43. libm/kf_sin.c \
  44. libm/kf_cos.c \
  45. libm/kf_tan.c \
  46. libm/ef_rem_pio2.c \
  47. libm/sf_sin.c \
  48. libm/sf_cos.c \
  49. libm/sf_tan.c \
  50. libm/sf_frexp.c \
  51. libm/sf_modf.c \
  52. libm/sf_ldexp.c \
  53. libm/asinfacosf.c \
  54. libm/atanf.c \
  55. libm/atan2f.c \
  56. utils/sys_stdio_mphal.c \
  57. )
  58. OBJ_COMMON =
  59. OBJ_COMMON += $(PY_O)
  60. OBJ_COMMON += $(addprefix $(BUILD)/, $(SRC_COMMON_C:.c=.o))
  61. OBJ_COMMON += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
  62. OBJ_RUN =
  63. OBJ_RUN += $(addprefix $(BUILD)/, $(SRC_RUN_C:.c=.o))
  64. OBJ_TEST =
  65. OBJ_TEST += $(addprefix $(BUILD)/, $(SRC_TEST_C:.c=.o))
  66. OBJ_TEST += $(BUILD)/tinytest.o
  67. # All object files, needed to get dependencies correct
  68. OBJ = $(OBJ_COMMON) $(OBJ_RUN) $(OBJ_TEST)
  69. # List of sources for qstr extraction
  70. SRC_QSTR += $(SRC_COMMON_C) $(SRC_RUN_C) $(LIB_SRC_C)
  71. all: run
  72. run: $(BUILD)/firmware.elf
  73. qemu-system-arm -machine integratorcp -cpu cortex-m3 -nographic -monitor null -serial null -semihosting -kernel $(BUILD)/firmware.elf
  74. ## `$(LD)` doesn't seem to like `--specs` for some reason, but we can just use `$(CC)` here.
  75. $(BUILD)/firmware.elf: $(OBJ_COMMON) $(OBJ_RUN)
  76. $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
  77. $(Q)$(SIZE) $@
  78. include $(TOP)/py/mkrules.mk