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.

133 lines
3.2 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. BINARY := psharp
  70. BUILD_DIR := build
  71. CFLAGS := $(CFLAGS) -DPH7_LIBRARY_SUFFIX=\"$(LIBSUFFIX)\"
  72. LIBFLAGS := -Wl,-rpath=$(DESTDIR) -L$(BUILD_DIR) -l$(BINARY)
  73. ENGINE_DIRS := engine/lib engine
  74. ENGINE_SRCS := $(foreach dir,$(ENGINE_DIRS),$(wildcard $(dir)/*.c))
  75. ENGINE_MAKE := $(ENGINE_SRCS:.c=.o)
  76. ENGINE_OBJS := $(addprefix $(BUILD_DIR)/,$(ENGINE_MAKE))
  77. MODULE := $(subst /,,$(subst modules/,,$(dir $(wildcard modules/*/))))
  78. SAPI := $(subst /,,$(subst sapi/,,$(dir $(wildcard sapi/*/))))
  79. .SUFFIXES:
  80. .PHONY: clean debug install release style test
  81. debug: export CFLAGS := $(CFLAGS) $(DCFLAGS)
  82. debug: engine sapi modules
  83. release: export CFLAGS := $(CFLAGS) $(RCFLAGS)
  84. release: engine sapi modules
  85. engine: $(ENGINE_OBJS)
  86. $(CC) -o $(BUILD_DIR)/lib$(BINARY)$(LIBSUFFIX) $(LDFLAGS) $(LIBS) -shared $(ENGINE_OBJS)
  87. modules: $(MODULE)
  88. sapi: $(SAPI)
  89. $(BUILD_DIR)/%.o: %.c
  90. $(MD) $(dir $@)
  91. $(CC) $(CFLAGS) -c $< -o $@
  92. $(MODULE):
  93. $(eval MODULE_DIRS := $@)
  94. $(eval MODULE_SRCS := $(foreach dir,modules/$(MODULE_DIRS),$(wildcard $(dir)/*.c)))
  95. $(eval MODULE_MAKE := $(MODULE_SRCS:.c=.o))
  96. $(eval MODULE_OBJS := $(addprefix $(BUILD_DIR)/,$(MODULE_MAKE)))
  97. $(eval MODULE_PROG := $(MODULE_DIRS)$(LIBSUFFIX))
  98. $(MAKE) $(MODULE_OBJS)
  99. $(CC) -o $(BUILD_DIR)/$(MODULE_PROG) $(LDFLAGS) $(LIBFLAGS) -shared $(MODULE_OBJS)
  100. $(SAPI):
  101. $(eval SAPI_DIRS := $@)
  102. $(eval SAPI_SRCS := $(foreach dir,sapi/$(SAPI_DIRS),$(wildcard $(dir)/*.c)))
  103. $(eval SAPI_MAKE := $(SAPI_SRCS:.c=.o))
  104. $(eval SAPI_OBJS := $(addprefix $(BUILD_DIR)/,$(SAPI_MAKE)))
  105. $(eval SAPI_PROG := $(subst -cli,,$(BINARY)-$(SAPI_DIRS))$(EXESUFFIX))
  106. $(MAKE) $(SAPI_OBJS)
  107. $(CC) -o $(BUILD_DIR)/$(SAPI_PROG) $(LDFLAGS) $(LIBFLAGS) $(SAPI_OBJS)
  108. clean:
  109. $(RM) $(BUILD_DIR)
  110. install:
  111. $(MD) $(DESTDIR)
  112. $(CP) $(BUILD_DIR)/$(BINARY)* $(DESTDIR)/
  113. $(CP) $(BUILD_DIR)/*$(LIBSUFFIX) $(DESTDIR)/