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.4KB

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