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.

161 lines
3.7 KiB

3 years ago
3 years ago
3 years ago
  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 := psharp
  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. .SUFFIXES:
  104. .PHONY: clean debug install release style test
  105. debug: export CFLAGS := $(CFLAGS) $(DCFLAGS)
  106. debug: engine sapi modules
  107. release: export CFLAGS := $(CFLAGS) $(RCFLAGS)
  108. release: engine sapi modules
  109. engine: $(ENGINE_OBJS)
  110. $(CC) -o $(BUILD_DIR)/lib$(BINARY)$(LIBSUFFIX) $(LDFLAGS) $(LIBS) -shared $(ENGINE_OBJS)
  111. modules: $(MODULE)
  112. sapi: $(SAPI)
  113. $(BUILD_DIR)/%.o: %.c
  114. $(MD) $(dir $@)
  115. $(CC) $(CFLAGS) -c $< -o $@
  116. $(MODULE):
  117. $(eval MODULE_DIRS := $@)
  118. $(eval MODULE_SRCS := $(foreach dir,modules/$(MODULE_DIRS),$(wildcard $(dir)/*.c)))
  119. $(eval MODULE_MAKE := $(MODULE_SRCS:.c=.o))
  120. $(eval MODULE_OBJS := $(addprefix $(BUILD_DIR)/,$(MODULE_MAKE)))
  121. $(eval MODULE_PROG := $(MODULE_DIRS)$(LIBSUFFIX))
  122. $(MAKE) $(MODULE_OBJS)
  123. $(CC) -o $(BUILD_DIR)/$(MODULE_PROG) $(LDFLAGS) $(LIBFLAGS) -shared $(MODULE_OBJS)
  124. $(SAPI):
  125. $(eval SAPI_DIRS := $@)
  126. $(eval SAPI_SRCS := $(foreach dir,sapi/$(SAPI_DIRS),$(wildcard $(dir)/*.c)))
  127. $(eval SAPI_MAKE := $(SAPI_SRCS:.c=.o))
  128. $(eval SAPI_OBJS := $(addprefix $(BUILD_DIR)/,$(SAPI_MAKE)))
  129. $(eval SAPI_PROG := $(subst -cli,,$(BINARY)-$(SAPI_DIRS))$(EXESUFFIX))
  130. $(MAKE) $(SAPI_OBJS)
  131. $(CC) -o $(BUILD_DIR)/$(SAPI_PROG) $(LDFLAGS) $(LIBFLAGS) $(SAPI_OBJS)
  132. clean:
  133. $(RM) $(BUILD_DIR)
  134. install:
  135. $(MD) $(DESTDIR)
  136. $(CP) $(BUILD_DIR)/$(BINARY)* $(DESTDIR)/
  137. $(CP) $(BUILD_DIR)/*$(LIBSUFFIX) $(DESTDIR)/
  138. style:
  139. astyle $(ASTYLE_FLAGS) --recursive ./*.c,*.h