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.

127 lines
2.9 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 -av
  22. MD := mkdir -p
  23. RM := rm -rfv
  24. LIBS := -ldl -lm
  25. EXESUFFIX :=
  26. LIBSUFFIX := .dylib
  27. endif
  28. ifeq "$(PLATFORM)" "FreeBSD"
  29. CC := clang
  30. CP := cp -av
  31. MD := mkdir -p
  32. RM := rm -rfv
  33. LIBS := -lm
  34. EXESUFFIX :=
  35. LIBSUFFIX := .so
  36. endif
  37. ifeq "$(PLATFORM)" "Linux"
  38. CC := gcc
  39. CP := cp -av
  40. MD := mkdir -p
  41. RM := rm -rfv
  42. LIBS := -ldl -lm
  43. EXESUFFIX :=
  44. LIBSUFFIX := .so
  45. endif
  46. ifeq "$(PLATFORM)" "OpenBSD"
  47. CC := clang
  48. CP := cp -av
  49. MD := mkdir -p
  50. RM := rm -rfv
  51. LIBS := -lm
  52. EXESUFFIX :=
  53. LIBSUFFIX := .so
  54. endif
  55. ifeq "$(PLATFORM)" "Windows"
  56. CC := gcc
  57. CP := copy
  58. MD := md
  59. RM := del /F
  60. LIBS := -ldl -lm
  61. EXESUFFIX := .exe
  62. LIBSUFFIX := .dll
  63. endif
  64. BINARY := psharp
  65. BUILD_DIR := build
  66. CFLAGS := $(CFLAGS) -DPH7_LIBRARY_SUFFIX=\"$(LIBSUFFIX)\"
  67. LIBFLAGS := -Wl,-rpath=$(DESTDIR) -L$(BUILD_DIR) -l$(BINARY)
  68. ENGINE_DIRS := engine/lib engine
  69. ENGINE_SRCS := $(foreach dir,$(ENGINE_DIRS),$(wildcard $(dir)/*.c))
  70. ENGINE_MAKE := $(ENGINE_SRCS:.c=.o)
  71. ENGINE_OBJS := $(addprefix $(BUILD_DIR)/,$(ENGINE_MAKE))
  72. MODULE := $(subst /,,$(subst modules/,,$(dir $(wildcard modules/*/))))
  73. SAPI := $(subst /,,$(subst sapi/,,$(dir $(wildcard sapi/*/))))
  74. .SUFFIXES:
  75. .PHONY: clean debug install release style test
  76. debug: export CFLAGS := $(CFLAGS) $(DCFLAGS)
  77. debug: engine sapi modules
  78. release: export CFLAGS := $(CFLAGS) $(RCFLAGS)
  79. release: engine sapi modules
  80. engine: $(ENGINE_OBJS)
  81. $(CC) -o $(BUILD_DIR)/lib$(BINARY)$(LIBSUFFIX) $(LDFLAGS) $(LIBS) -shared $(ENGINE_OBJS)
  82. modules: $(MODULE)
  83. sapi: $(SAPI)
  84. $(BUILD_DIR)/%.o: %.c
  85. $(MD) $(dir $@)
  86. $(CC) $(CFLAGS) -c $< -o $@
  87. $(MODULE):
  88. $(eval MODULE_DIRS := $@)
  89. $(eval MODULE_SRCS := $(foreach dir,modules/$(MODULE_DIRS),$(wildcard $(dir)/*.c)))
  90. $(eval MODULE_MAKE := $(MODULE_SRCS:.c=.o))
  91. $(eval MODULE_OBJS := $(addprefix $(BUILD_DIR)/,$(MODULE_MAKE)))
  92. $(eval MODULE_PROG := $(MODULE_DIRS)$(LIBSUFFIX))
  93. $(MAKE) $(MODULE_OBJS)
  94. $(CC) -o $(BUILD_DIR)/$(MODULE_PROG) $(LDFLAGS) $(LIBFLAGS) -shared $(MODULE_OBJS)
  95. $(SAPI):
  96. $(eval SAPI_DIRS := $@)
  97. $(eval SAPI_SRCS := $(foreach dir,sapi/$(SAPI_DIRS),$(wildcard $(dir)/*.c)))
  98. $(eval SAPI_MAKE := $(SAPI_SRCS:.c=.o))
  99. $(eval SAPI_OBJS := $(addprefix $(BUILD_DIR)/,$(SAPI_MAKE)))
  100. $(eval SAPI_PROG := $(subst -cli,,$(BINARY)-$(SAPI_DIRS))$(EXESUFFIX))
  101. $(MAKE) $(SAPI_OBJS)
  102. $(CC) -o $(BUILD_DIR)/$(SAPI_PROG) $(LDFLAGS) $(LIBFLAGS) $(SAPI_OBJS)
  103. clean:
  104. $(RM) $(BUILD_DIR)
  105. install:
  106. $(MD) $(DESTDIR)
  107. $(CP) $(BUILD_DIR)/* $(DESTDIR)/