Makefile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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../../include -I../../uzlib
  10. LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile
  11. CCFLAGS += -Wall
  12. DEFINES += -DLUA_CROSS_COMPILER
  13. TARGET = host
  14. ifeq ($(FLAVOR),debug)
  15. CCFLAGS += -O0 -g
  16. TARGET_LDFLAGS += -O0 -g
  17. DEFINES += -DLUA_DEBUG_BUILD
  18. else
  19. FLAVOR = release
  20. CCFLAGS += -O2
  21. TARGET_LDFLAGS += -O2
  22. endif
  23. LUACSRC := luac.c lflashimg.c liolib.c loslib.c print.c
  24. LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c \
  25. ldo.c ldump.c lfunc.c lgc.c linit.c llex.c \
  26. lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c lparser.c \
  27. lrotable.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c \
  28. ltm.c lundump.c lvm.c lzio.c
  29. UZSRC := uzlib_deflate.c crc32.c
  30. #
  31. # This relies on the files being unique on the vpath
  32. #
  33. SRC := $(LUACSRC) $(LUASRC) $(UZSRC)
  34. vpath %.c .:..:../../libc:../../uzlib
  35. ODIR := .output/$(TARGET)/$(FLAVOR)/obj
  36. OBJS := $(SRC:%.c=$(ODIR)/%.o)
  37. DEPS := $(SRC:%.c=$(ODIR)/%.d)
  38. CFLAGS = $(CCFLAGS) $(DEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
  39. DFLAGS = $(CCFLAGS) $(DDEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
  40. CC := $(WRAPCC) gcc
  41. ECHO := echo
  42. BUILD_TYPE := $(shell $(CC) $(EXTRA_CCFLAGS) -E -dM - <../../include/user_config.h | grep LUA_NUMBER_INTEGRAL | wc -l)
  43. ifeq ($(BUILD_TYPE),0)
  44. IMAGE := ../../../luac.cross
  45. else
  46. IMAGE := ../../../luac.cross.int
  47. endif
  48. .PHONY: test clean all
  49. all: $(DEPS) $(IMAGE)
  50. $(IMAGE) : $(OBJS)
  51. $(summary) HOSTLD $@
  52. $(CC) $(OBJS) -o $@ $(LDFLAGS)
  53. test :
  54. @echo CC: $(CC)
  55. @echo SRC: $(SRC)
  56. @echo OBJS: $(OBJS)
  57. @echo DEPS: $(DEPS)
  58. @echo IMAGE: $(IMAGE)
  59. clean :
  60. $(RM) -r $(ODIR)
  61. ifneq ($(MAKECMDGOALS),clean)
  62. -include $(DEPS)
  63. endif
  64. $(ODIR)/%.o: %.c
  65. @mkdir -p $(ODIR);
  66. $(summary) HOSTCC $(CURDIR)/$<
  67. $(CC) $(if $(findstring $<,$(DSRCS)),$(DFLAGS),$(CFLAGS)) $(COPTS_$(*F)) -o $@ -c $<
  68. $(ODIR)/%.d: %.c
  69. @mkdir -p $(ODIR);
  70. $(summary) DEPEND: HOSTCC $(CURDIR)/$<
  71. @set -e; rm -f $@; \
  72. $(CC) -M $(CFLAGS) $< > $@.$$$$; \
  73. sed 's,\($*\.o\)[ :]*,$(ODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \
  74. rm -f $@.$$$$