Makefile 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # The following is a temporary hack to forefully undefine vars that might have
  2. # be defined by a calling Makefile (from recursive make).
  3. # TODO: Find a better way to be able to call this Makefile recursively.
  4. ifneq ($(findstring undefine,$(.FEATURES)),)
  5. override undefine COPT
  6. override undefine CFLAGS_EXTRA
  7. override undefine LDFLAGS_EXTRA
  8. override undefine FROZEN_DIR
  9. override undefine FROZEN_MPY_DIR
  10. override undefine BUILD
  11. override undefine PROG
  12. endif
  13. include ../py/mkenv.mk
  14. # define main target
  15. PROG = mpy-cross
  16. # qstr definitions (must come before including py.mk)
  17. QSTR_DEFS = qstrdefsport.h
  18. # OS name, for simple autoconfig
  19. UNAME_S := $(shell uname -s)
  20. # include py core make definitions
  21. include $(TOP)/py/py.mk
  22. INC += -I.
  23. INC += -I$(BUILD)
  24. INC += -I$(TOP)
  25. # compiler settings
  26. CWARN = -Wall -Werror
  27. CWARN += -Wpointer-arith -Wuninitialized
  28. CFLAGS = $(INC) $(CWARN) -std=gnu99 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
  29. CFLAGS += -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables
  30. # Debugging/Optimization
  31. ifdef DEBUG
  32. CFLAGS += -g
  33. COPT = -O0
  34. else
  35. COPT = -Os #-DNDEBUG
  36. endif
  37. # On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
  38. # The unix port of MicroPython on OSX must be compiled with clang,
  39. # while cross-compile ports require gcc, so we test here for OSX and
  40. # if necessary override the value of 'CC' set in py/mkenv.mk
  41. ifeq ($(UNAME_S),Darwin)
  42. CC = clang
  43. # Use clang syntax for map file
  44. LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip
  45. else
  46. # Use gcc syntax for map file
  47. LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref -Wl,--gc-sections
  48. endif
  49. LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
  50. # source files
  51. SRC_C = \
  52. main.c \
  53. gccollect.c \
  54. # Add fmode when compiling with mingw gcc
  55. COMPILER_TARGET := $(shell $(CC) -dumpmachine)
  56. ifneq (,$(findstring mingw,$(COMPILER_TARGET)))
  57. SRC_C += ports/windows/fmode.c
  58. endif
  59. OBJ = $(PY_CORE_O)
  60. OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
  61. include $(TOP)/py/mkrules.mk