Makefile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #
  2. # This Makefile is called from the core Makefile hierarchy which is a hierarchical
  3. # make which uses parent callbacks to implement inheritance. However if luac_cross
  4. # build stands outside this, it uses the host toolchain to implement a separate
  5. # host build of the luac.cross image.
  6. #
  7. .NOTPARALLEL:
  8. summary ?= @true
  9. CCFLAGS:= -I. -I.. -I../../include -I../../uzlib
  10. LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile
  11. CCFLAGS += -Wall
  12. TARGET = host
  13. # Validate LUA setting
  14. ifeq ("$(LUA)","")
  15. else ifeq ("$(LUA)","51")
  16. # ok
  17. else ifeq ("$(LUA)","53")
  18. $(error Your variable LUA="$(LUA)" looks like you probably want \
  19. app/lua53/host/Makefile instead)
  20. else
  21. $(error Unsupported value "$(LUA)" for variable "LUA", \
  22. expected empty/unset (recommended) or "51")
  23. endif
  24. VERBOSE ?=
  25. V ?= $(VERBOSE)
  26. ifeq ("$(V)","1")
  27. export summary := @true
  28. else
  29. export summary := @echo
  30. # disable echoing of commands, directory names
  31. MAKEFLAGS += --silent -w
  32. endif # $(V)==1
  33. DEBUG ?=
  34. ifeq ("$(DEBUG)","1")
  35. FLAVOR = debug
  36. CCFLAGS += -O0 -ggdb
  37. TARGET_LDFLAGS += -O0 -ggdb
  38. DEFINES += -DLUA_CROSS_COMPILER -DLUA_DEBUG_BUILD -DDEVELOPMENT_TOOLS -DDEVELOPMENT_USE_GDB
  39. else
  40. FLAVOR = release
  41. CCFLAGS += -O2
  42. TARGET_LDFLAGS += -O2
  43. DEFINES += -DLUA_CROSS_COMPILER
  44. endif # DEBUG
  45. LUACSRC := luac.c lflashimg.c liolib.c loslib.c print.c
  46. LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c \
  47. ldo.c ldump.c lfunc.c lgc.c linit.c llex.c \
  48. lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c lparser.c \
  49. lstate.c lstring.c lstrlib.c ltable.c ltablib.c \
  50. ltm.c lundump.c lvm.c lzio.c lnodemcu.c
  51. UZSRC := uzlib_deflate.c crc32.c
  52. #
  53. # This relies on the files being unique on the vpath
  54. #
  55. SRC := $(LUACSRC) $(LUASRC) $(UZSRC)
  56. vpath %.c .:..:../../libc:../../uzlib
  57. ODIR := .output/$(TARGET)/$(FLAVOR)/obj
  58. OBJS := $(SRC:%.c=$(ODIR)/%.o)
  59. DEPS := $(SRC:%.c=$(ODIR)/%.d)
  60. CFLAGS = $(CCFLAGS) $(DEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
  61. DFLAGS = $(CCFLAGS) $(DDEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
  62. CC := $(WRAPCC) gcc
  63. ECHO := echo
  64. BUILD_TYPE := $(shell $(CC) $(EXTRA_CCFLAGS) -E -dM - <../../include/user_config.h | grep LUA_NUMBER_INTEGRAL | wc -l)
  65. ifeq ($(BUILD_TYPE),0)
  66. IMAGE := ../../../luac.cross
  67. else
  68. IMAGE := ../../../luac.cross.int
  69. endif
  70. .PHONY: test clean all
  71. all: $(DEPS) $(IMAGE)
  72. $(IMAGE) : $(OBJS)
  73. $(summary) HOSTLD $@
  74. $(CC) $(OBJS) -o $@ $(LDFLAGS)
  75. test :
  76. @echo CC: $(CC)
  77. @echo SRC: $(SRC)
  78. @echo OBJS: $(OBJS)
  79. @echo DEPS: $(DEPS)
  80. @echo IMAGE: $(IMAGE)
  81. clean :
  82. $(RM) -r $(ODIR)
  83. ifneq ($(MAKECMDGOALS),clean)
  84. -include $(DEPS)
  85. endif
  86. $(ODIR)/%.o: %.c
  87. @mkdir -p $(ODIR);
  88. $(summary) HOSTCC $(CURDIR)/$<
  89. $(CC) $(if $(findstring $<,$(DSRCS)),$(DFLAGS),$(CFLAGS)) $(COPTS_$(*F)) -o $@ -c $<
  90. $(ODIR)/%.d: %.c
  91. @mkdir -p $(ODIR);
  92. $(summary) DEPEND: HOSTCC $(CURDIR)/$<
  93. @set -e; rm -f $@; \
  94. $(CC) -M $(CFLAGS) $< > $@.$$$$; \
  95. sed 's,\($*\.o\)[ :]*,$(ODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \
  96. rm -f $@.$$$$