aboutsummaryrefslogtreecommitdiff
path: root/makefile
diff options
context:
space:
mode:
Diffstat (limited to 'makefile')
-rw-r--r--makefile59
1 files changed, 56 insertions, 3 deletions
diff --git a/makefile b/makefile
index d7e85d3..e0cdd91 100644
--- a/makefile
+++ b/makefile
@@ -3,6 +3,7 @@
3BIN_NAME := yue 3BIN_NAME := yue
4# Compiler used 4# Compiler used
5CXX ?= g++ 5CXX ?= g++
6CC ?= gcc
6# Extension of source files used in the project 7# Extension of source files used in the project
7SRC_EXT = cpp 8SRC_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
11LIBS = 12LIBS =
12# General compiler flags 13# General compiler flags
13COMPILE_FLAGS = -std=c++17 -Wall -Wextra -Wno-deprecated-declarations 14COMPILE_FLAGS = -std=c++17 -Wall -Wextra -DYUE_UTF8_IMPL
14# Additional release-specific flags 15# Additional release-specific flags
15RCOMPILE_FLAGS = -D NDEBUG -O3 16RCOMPILE_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
56endif 57endif
58
59# Detect Android Termux environment
60# Termux typically has ANDROID_ROOT environment variable set and PREFIX points to Termux directory
61IS_TERMUX := false
62ANDROID_ROOT_VAR := $(shell echo $$ANDROID_ROOT)
63PREFIX_VAR := $(shell echo $$PREFIX)
64ifneq ($(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
77endif
78
79# Auto-set NO_WATCHER for Termux environment if not explicitly set
80ifeq ($(IS_TERMUX),true)
81 ifeq ($(NO_WATCHER),)
82 NO_WATCHER := true
83 $(info Detected Android Termux environment, automatically setting NO_WATCHER=true)
84 endif
85endif
86
57ifeq ($(NO_WATCHER),true) 87ifeq ($(NO_WATCHER),true)
58 COMPILE_FLAGS += -DYUE_NO_WATCHER 88 COMPILE_FLAGS += -DYUE_NO_WATCHER
59endif 89endif
60 90
61# Add platform related linker flag 91# Add platform related linker flag
62ifneq ($(UNAME_S),Darwin) 92ifneq ($(UNAME_S),Darwin)
63 LINK_FLAGS += -lstdc++fs -Wl,-E 93 LINK_FLAGS += -Wl,-E
64 PLAT = linux 94 PLAT = linux
65else 95else
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
98release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS) 128release: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS)
129release: export CFLAGS := $(CFLAGS) $(filter-out -std=c++17,$(COMPILE_FLAGS)) $(RCOMPILE_FLAGS)
99release: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(RLINK_FLAGS) 130release: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(RLINK_FLAGS)
100debug: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(DCOMPILE_FLAGS) 131debug: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(DCOMPILE_FLAGS)
132debug: export CFLAGS := $(CFLAGS) $(filter-out -std=c++17,$(COMPILE_FLAGS)) $(DCOMPILE_FLAGS)
101debug: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(DLINK_FLAGS) 133debug: export LDFLAGS := $(LDFLAGS) $(LINK_FLAGS) $(DLINK_FLAGS)
102shared: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS) $(TARGET_FLAGS) 134shared: export CXXFLAGS := $(CXXFLAGS) $(COMPILE_FLAGS) $(RCOMPILE_FLAGS) $(TARGET_FLAGS)
135shared: 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
105release: export BUILD_PATH := build/release 138release: 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))
135endif 168endif
136 169
170# Add colib ljson.c source file
171SOURCES += $(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
139OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o) 175CPP_SOURCES = $(filter %.cpp,$(SOURCES))
176C_SOURCES = $(filter %.c,$(SOURCES))
177OBJECTS = $(CPP_SOURCES:$(SRC_PATH)/%.cpp=$(BUILD_PATH)/%.o)
178OBJECTS += $(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
141DEPS = $(OBJECTS:.o=.d) 180DEPS = $(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)