diff options
Diffstat (limited to 'makefile')
| -rw-r--r-- | makefile | 59 |
1 files changed, 56 insertions, 3 deletions
| @@ -3,6 +3,7 @@ | |||
| 3 | BIN_NAME := yue | 3 | BIN_NAME := yue |
| 4 | # Compiler used | 4 | # Compiler used |
| 5 | CXX ?= g++ | 5 | CXX ?= g++ |
| 6 | CC ?= gcc | ||
| 6 | # Extension of source files used in the project | 7 | # Extension of source files used in the project |
| 7 | SRC_EXT = cpp | 8 | SRC_EXT = cpp |
| 8 | # Path to the source directory, relative to the makefile | 9 | # Path to the source directory, relative to the makefile |
| @@ -10,7 +11,7 @@ SRC_PATH = ./src | |||
| 10 | # Space-separated pkg-config libraries used by this project | 11 | # Space-separated pkg-config libraries used by this project |
| 11 | LIBS = | 12 | LIBS = |
| 12 | # General compiler flags | 13 | # General compiler flags |
| 13 | COMPILE_FLAGS = -std=c++17 -Wall -Wextra -Wno-deprecated-declarations | 14 | COMPILE_FLAGS = -std=c++17 -Wall -Wextra -DYUE_UTF8_IMPL |
| 14 | # Additional release-specific flags | 15 | # Additional release-specific flags |
| 15 | RCOMPILE_FLAGS = -D NDEBUG -O3 | 16 | RCOMPILE_FLAGS = -D NDEBUG -O3 |
| 16 | # Additional debug-specific flags | 17 | # Additional debug-specific flags |
| @@ -54,13 +55,42 @@ endif | |||
| 54 | INCLUDES += -I $(SRC_PATH)/3rdParty/lua | 55 | INCLUDES += -I $(SRC_PATH)/3rdParty/lua |
| 55 | LINK_FLAGS += -L $(SRC_PATH)/3rdParty/lua -llua -ldl | 56 | LINK_FLAGS += -L $(SRC_PATH)/3rdParty/lua -llua -ldl |
| 56 | endif | 57 | endif |
| 58 | |||
| 59 | # Detect Android Termux environment | ||
| 60 | # Termux typically has ANDROID_ROOT environment variable set and PREFIX points to Termux directory | ||
| 61 | IS_TERMUX := false | ||
| 62 | ANDROID_ROOT_VAR := $(shell echo $$ANDROID_ROOT) | ||
| 63 | PREFIX_VAR := $(shell echo $$PREFIX) | ||
| 64 | ifneq ($(ANDROID_ROOT_VAR),) | ||
| 65 | # Check if PREFIX environment variable points to Termux directory | ||
| 66 | ifneq ($(PREFIX_VAR),) | ||
| 67 | ifneq ($(findstring com.termux,$(PREFIX_VAR)),) | ||
| 68 | IS_TERMUX := true | ||
| 69 | endif | ||
| 70 | endif | ||
| 71 | # Alternative check: verify if Termux installation path exists | ||
| 72 | ifeq ($(IS_TERMUX),false) | ||
| 73 | ifneq ($(shell test -d /data/data/com.termux/files/usr && echo yes),) | ||
| 74 | IS_TERMUX := true | ||
| 75 | endif | ||
| 76 | endif | ||
| 77 | endif | ||
| 78 | |||
| 79 | # Auto-set NO_WATCHER for Termux environment if not explicitly set | ||
| 80 | ifeq ($(IS_TERMUX),true) | ||
| 81 | ifeq ($(NO_WATCHER),) | ||
| 82 | NO_WATCHER := true | ||
| 83 | $(info Detected Android Termux environment, automatically setting NO_WATCHER=true) | ||
| 84 | endif | ||
| 85 | endif | ||
| 86 | |||
| 57 | ifeq ($(NO_WATCHER),true) | 87 | ifeq ($(NO_WATCHER),true) |
| 58 | COMPILE_FLAGS += -DYUE_NO_WATCHER | 88 | COMPILE_FLAGS += -DYUE_NO_WATCHER |
| 59 | endif | 89 | endif |
| 60 | 90 | ||
| 61 | # Add platform related linker flag | 91 | # Add platform related linker flag |
| 62 | ifneq ($(UNAME_S),Darwin) | 92 | ifneq ($(UNAME_S),Darwin) |
| 63 | LINK_FLAGS += -lstdc++fs -Wl,-E | 93 | LINK_FLAGS += -Wl,-E |
| 64 | PLAT = linux | 94 | PLAT = linux |
| 65 | else | 95 | else |
| 66 | LINK_FLAGS += -framework CoreFoundation -framework CoreServices | 96 | LINK_FLAGS += -framework CoreFoundation -framework CoreServices |
| @@ -96,10 +126,13 @@ endif | |||
| 96 | 126 | ||
| 97 | # Combine compiler and linker flags | 127 | # Combine compiler and linker flags |
| 98 | release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS) | 128 | release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS) |
| 129 | release: export CFLAGS := $(CFLAGS) $(filter-out -std=c++17,$(COMPILE_FLAGS)) $(RCOMPILE_FLAGS) | ||
| 99 | release: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(RLINK_FLAGS) | 130 | release: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(RLINK_FLAGS) |
| 100 | debug: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(DCOMPILE_FLAGS) | 131 | debug: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(DCOMPILE_FLAGS) |
| 132 | debug: export CFLAGS := $(CFLAGS) $(filter-out -std=c++17,$(COMPILE_FLAGS)) $(DCOMPILE_FLAGS) | ||
| 101 | debug: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(DLINK_FLAGS) | 133 | debug: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(DLINK_FLAGS) |
| 102 | shared: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS) $(TARGET_FLAGS) | 134 | shared: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS) $(TARGET_FLAGS) |
| 135 | shared: export CFLAGS := $(CFLAGS) $(filter-out -std=c++17,$(COMPILE_FLAGS)) $(RCOMPILE_FLAGS) $(TARGET_FLAGS) | ||
| 103 | 136 | ||
| 104 | # Build and output paths | 137 | # Build and output paths |
| 105 | release: export BUILD_PATH := build/release | 138 | release: export BUILD_PATH := build/release |
| @@ -134,9 +167,15 @@ ifeq ($(NO_LUA),true) | |||
| 134 | SOURCES := $(filter-out $(SRC_PATH)/yuescript/yuescript.cpp, $(SOURCES)) | 167 | SOURCES := $(filter-out $(SRC_PATH)/yuescript/yuescript.cpp, $(SOURCES)) |
| 135 | endif | 168 | endif |
| 136 | 169 | ||
| 170 | # Add colib ljson.c source file | ||
| 171 | SOURCES += $(SRC_PATH)/3rdParty/colib/ljson.c | ||
| 172 | |||
| 137 | # Set the object file names, with the source directory stripped | 173 | # Set the object file names, with the source directory stripped |
| 138 | # from the path, and the build path prepended in its place | 174 | # from the path, and the build path prepended in its place |
| 139 | OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o) | 175 | CPP_SOURCES = $(filter %.cpp,$(SOURCES)) |
| 176 | C_SOURCES = $(filter %.c,$(SOURCES)) | ||
| 177 | OBJECTS = $(CPP_SOURCES:$(SRC_PATH)/%.cpp=$(BUILD_PATH)/%.o) | ||
| 178 | OBJECTS += $(C_SOURCES:$(SRC_PATH)/%.c=$(BUILD_PATH)/%.o) | ||
| 140 | # Set the dependency files that will be used to add header dependencies | 179 | # Set the dependency files that will be used to add header dependencies |
| 141 | DEPS = $(OBJECTS:.o=.d) | 180 | DEPS = $(OBJECTS:.o=.d) |
| 142 | 181 | ||
| @@ -225,8 +264,10 @@ wasm-node: clean | |||
| 225 | -O2 \ | 264 | -O2 \ |
| 226 | -o wasm/dist/esm/yuescript.mjs \ | 265 | -o wasm/dist/esm/yuescript.mjs \ |
| 227 | -I $(SRC_PATH) \ | 266 | -I $(SRC_PATH) \ |
| 267 | -I $(SRC_PATH)/3rdParty/ \ | ||
| 228 | -I $(SRC_PATH)/3rdParty/lua \ | 268 | -I $(SRC_PATH)/3rdParty/lua \ |
| 229 | -std=c++17 \ | 269 | -std=c++17 \ |
| 270 | -DYUE_UTF8_IMPL \ | ||
| 230 | --bind \ | 271 | --bind \ |
| 231 | -fexceptions \ | 272 | -fexceptions \ |
| 232 | -Wno-deprecated-declarations \ | 273 | -Wno-deprecated-declarations \ |
| @@ -265,8 +306,10 @@ wasm-node: clean | |||
| 265 | -o wasm/dist/cjs/yuescript.cjs \ | 306 | -o wasm/dist/cjs/yuescript.cjs \ |
| 266 | --emit-tsd="yuescript.d.ts" \ | 307 | --emit-tsd="yuescript.d.ts" \ |
| 267 | -I $(SRC_PATH) \ | 308 | -I $(SRC_PATH) \ |
| 309 | -I $(SRC_PATH)/3rdParty/ \ | ||
| 268 | -I $(SRC_PATH)/3rdParty/lua \ | 310 | -I $(SRC_PATH)/3rdParty/lua \ |
| 269 | -std=c++17 \ | 311 | -std=c++17 \ |
| 312 | -DYUE_UTF8_IMPL \ | ||
| 270 | --bind \ | 313 | --bind \ |
| 271 | -fexceptions \ | 314 | -fexceptions \ |
| 272 | -Wno-deprecated-declarations \ | 315 | -Wno-deprecated-declarations \ |
| @@ -309,8 +352,10 @@ wasm: clean | |||
| 309 | -O2 \ | 352 | -O2 \ |
| 310 | -o doc/docs/.vuepress/public/js/yuescript.js \ | 353 | -o doc/docs/.vuepress/public/js/yuescript.js \ |
| 311 | -I $(SRC_PATH) \ | 354 | -I $(SRC_PATH) \ |
| 355 | -I $(SRC_PATH)/3rdParty/ \ | ||
| 312 | -I $(SRC_PATH)/3rdParty/lua \ | 356 | -I $(SRC_PATH)/3rdParty/lua \ |
| 313 | -std=c++17 \ | 357 | -std=c++17 \ |
| 358 | -DYUE_UTF8_IMPL \ | ||
| 314 | --bind \ | 359 | --bind \ |
| 315 | -fexceptions \ | 360 | -fexceptions \ |
| 316 | -Wno-deprecated-declarations | 361 | -Wno-deprecated-declarations |
| @@ -440,3 +485,11 @@ $(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT) | |||
| 440 | $(CMD_PREFIX)$(CXX) $(CXXFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@ | 485 | $(CMD_PREFIX)$(CXX) $(CXXFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@ |
| 441 | @echo -en "\t Compile time: " | 486 | @echo -en "\t Compile time: " |
| 442 | @$(END_TIME) | 487 | @$(END_TIME) |
| 488 | |||
| 489 | # C source file rules | ||
| 490 | $(BUILD_PATH)/%.o: $(SRC_PATH)/%.c | ||
| 491 | @echo "Compiling: $< -> $@" | ||
| 492 | @$(START_TIME) | ||
| 493 | $(CMD_PREFIX)$(CC) $(CFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@ | ||
| 494 | @echo -en "\t Compile time: " | ||
| 495 | @$(END_TIME) | ||
