Aer Interpreter Source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. # Flags to pass to the compiler
  2. CFLAGS = -std=c99 -D_GNU_SOURCE -fPIC -Iinclude -I. -Wunused -Wall -Wextra -Wpedantic
  3. # Additional CFLAGS for debug build
  4. DCFLAGS = -Og -g3
  5. # Addditional CFLAGS for release build
  6. RCFLAGS = -O3 -s
  7. # Flags to pass to the linker
  8. LDFLAGS =
  9. # Flags to enable sanitize checker
  10. SFLAGS = -fsanitize=address -fsanitize=leak
  11. # Destination directory
  12. DESTDIR ?= $(realpath .)/binary
  13. ##############################################
  14. ### Do not modify anything below this line ###
  15. ##############################################
  16. ifeq ($(OS),Windows_NT)
  17. PLATFORM := Windows
  18. else
  19. PLATFORM := $(shell uname -s)
  20. endif
  21. ifeq "$(PLATFORM)" "Darwin"
  22. CC := clang
  23. CP := cp -v
  24. MD := mkdir -p
  25. RM := rm -rfv
  26. LDFLAGS := $(LDFLAGS) -Wl,-export_dynamic -undefined dynamic_lookup
  27. LIBS := -ldl -lm
  28. EXESUFFIX :=
  29. LIBSUFFIX := .dylib
  30. endif
  31. ifeq "$(PLATFORM)" "FreeBSD"
  32. CC := clang
  33. CP := cp -v
  34. MD := mkdir -p
  35. RM := rm -rfv
  36. LDFLAGS := $(LDFLAGS) -Wl,--export-dynamic
  37. LIBS := -lm
  38. EXESUFFIX :=
  39. LIBSUFFIX := .so
  40. endif
  41. ifeq "$(PLATFORM)" "Linux"
  42. CC := gcc
  43. CP := cp -v
  44. MD := mkdir -p
  45. RM := rm -rfv
  46. LDFLAGS := $(LDFLAGS) -Wl,--export-dynamic
  47. LIBS := -ldl -lm
  48. EXESUFFIX :=
  49. LIBSUFFIX := .so
  50. endif
  51. ifeq "$(PLATFORM)" "OpenBSD"
  52. CC := clang
  53. CP := cp -v
  54. MD := mkdir -p
  55. RM := rm -rfv
  56. LDFLAGS := $(LDFLAGS) -Wl,--export-dynamic
  57. LIBS := -lm
  58. EXESUFFIX :=
  59. LIBSUFFIX := .so
  60. endif
  61. ifeq "$(PLATFORM)" "Windows"
  62. CC := gcc
  63. CP := copy
  64. MD := md
  65. RM := del /F
  66. LDFLAGS := $(LDFLAGS) -Wl,--export-all-symbols
  67. LIBS :=
  68. EXESUFFIX := .exe
  69. LIBSUFFIX := .dll
  70. endif
  71. ASTYLE_FLAGS =\
  72. --style=java \
  73. --indent=force-tab \
  74. --attach-closing-while \
  75. --attach-inlines \
  76. --attach-classes \
  77. --indent-classes \
  78. --indent-modifiers \
  79. --indent-switches \
  80. --indent-cases \
  81. --indent-preproc-block \
  82. --indent-preproc-define \
  83. --indent-col1-comments \
  84. --pad-oper \
  85. --pad-comma \
  86. --unpad-paren \
  87. --delete-empty-lines \
  88. --align-pointer=name \
  89. --align-reference=name \
  90. --break-one-line-headers \
  91. --add-braces \
  92. --verbose \
  93. --formatted \
  94. --lineend=linux
  95. BINARY := aer
  96. BUILD_DIR := build
  97. CFLAGS := $(CFLAGS) -DPH7_LIBRARY_SUFFIX=\"$(LIBSUFFIX)\"
  98. LIBFLAGS := -Wl,-rpath,$(DESTDIR) -L$(BUILD_DIR) -l$(BINARY)
  99. ENGINE_DIRS := engine/lib engine
  100. ENGINE_SRCS := $(foreach dir,$(ENGINE_DIRS),$(wildcard $(dir)/*.c))
  101. ENGINE_MAKE := $(ENGINE_SRCS:.c=.o)
  102. ENGINE_OBJS := $(addprefix $(BUILD_DIR)/,$(ENGINE_MAKE))
  103. MODULE := $(subst /,,$(subst modules/,,$(dir $(wildcard modules/*/))))
  104. SAPI := $(subst /,,$(subst sapi/,,$(dir $(wildcard sapi/*/))))
  105. TEST_DIR := tests
  106. TEST_EXT := aer
  107. TESTS := $(subst .$(TEST_EXT),.test,$(wildcard $(TEST_DIR)/*.$(TEST_EXT)))
  108. .SUFFIXES:
  109. .PHONY: clean debug install release style tests
  110. debug: export CFLAGS := $(CFLAGS) $(DCFLAGS)
  111. debug: engine sapi modules
  112. release: export CFLAGS := $(CFLAGS) $(RCFLAGS)
  113. release: engine sapi modules
  114. sanitize: export CFLAGS := $(CFLAGS) $(DCFLAGS) $(SFLAGS)
  115. sanitize: $(eval LDFLAGS := $(LDFLAGS) $(SFLAGS))
  116. sanitize: engine sapi modules
  117. engine: $(ENGINE_OBJS)
  118. $(CC) -o $(BUILD_DIR)/lib$(BINARY)$(LIBSUFFIX) $(LDFLAGS) $(LIBS) -shared $(ENGINE_OBJS)
  119. modules: $(MODULE)
  120. sapi: $(SAPI)
  121. $(BUILD_DIR)/%.o: %.c
  122. $(MD) $(dir $@)
  123. $(CC) $(CFLAGS) -c $< -o $@
  124. $(MODULE):
  125. $(eval MODULE_DIRS := $@)
  126. $(eval MODULE_SRCS := $(foreach dir,modules/$(MODULE_DIRS),$(wildcard $(dir)/*.c)))
  127. $(eval MODULE_MAKE := $(MODULE_SRCS:.c=.o))
  128. $(eval MODULE_OBJS := $(addprefix $(BUILD_DIR)/,$(MODULE_MAKE)))
  129. $(eval MODULE_PROG := $(MODULE_DIRS)$(LIBSUFFIX))
  130. $(MAKE) $(MODULE_OBJS)
  131. $(CC) -o $(BUILD_DIR)/$(MODULE_PROG) $(LDFLAGS) -shared $(MODULE_OBJS)
  132. $(SAPI):
  133. $(eval SAPI_DIRS := $@)
  134. $(eval SAPI_SRCS := $(foreach dir,sapi/$(SAPI_DIRS),$(wildcard $(dir)/*.c)))
  135. $(eval SAPI_MAKE := $(SAPI_SRCS:.c=.o))
  136. $(eval SAPI_OBJS := $(addprefix $(BUILD_DIR)/,$(SAPI_MAKE)))
  137. $(eval SAPI_PROG := $(subst -cli,,$(BINARY)-$(SAPI_DIRS))$(EXESUFFIX))
  138. $(MAKE) $(SAPI_OBJS)
  139. $(CC) -o $(BUILD_DIR)/$(SAPI_PROG) $(LDFLAGS) $(LIBFLAGS) $(SAPI_OBJS)
  140. %.test: %.exp %.$(TEST_EXT)
  141. @$(MD) ${BUILD_DIR}/${TEST_DIR}
  142. @echo -n "Executing test: $*.$(TEST_EXT) ... "
  143. @if [ "x`echo $* | grep args`" != "x" ]; \
  144. then \
  145. binary/$(BINARY)$(EXESUFFIX) $*.$(TEST_EXT) - arg1 arg2 arg3 arg4 2>&1 >$(BUILD_DIR)/$*.out; \
  146. else \
  147. binary/$(BINARY)$(EXESUFFIX) $*.$(TEST_EXT) 2>&1 >$(BUILD_DIR)/$*.out; \
  148. fi
  149. @if [ "x`diff -qbu $*.exp $(BUILD_DIR)/$*.out`" != "x" ]; \
  150. then \
  151. echo "ERROR!"; \
  152. diff -u $*.exp $(BUILD_DIR)/$*.out; \
  153. rm -f $(BUILD_DIR)/$(TEST_DIR)/*.out \
  154. exit 1; \
  155. fi;
  156. @rm -f $(BUILD_DIR)/$(TEST_DIR)/*.out
  157. @echo "OK!"
  158. clean:
  159. $(RM) $(BUILD_DIR)
  160. install: engine modules sapi
  161. $(MD) $(DESTDIR)
  162. $(CP) $(BUILD_DIR)/$(BINARY)* $(DESTDIR)/
  163. $(CP) $(BUILD_DIR)/*$(LIBSUFFIX) $(DESTDIR)/
  164. style:
  165. astyle $(ASTYLE_FLAGS) --recursive ./*.c,*.h
  166. tests: $(TESTS)