-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
94 lines (73 loc) · 2.39 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Makefile for polished_save_patcher with WebAssembly
# Detect the operating system
OS := $(shell uname -s)
# Compiler and flags
CXX := emcc
CXXFLAGS := -Iinclude -std=c++17
# Directories
SRC_DIR := src
INCLUDE_DIR := include
RESOURCES_DIR := resources
VERSION_DIRS := $(wildcard $(RESOURCES_DIR)/version*)
BUILD_DIR := build
# Source files
SOURCES := $(SRC_DIR)/CommonPatchFunctions.cpp \
$(SRC_DIR)/PatchVersion7to8.cpp \
$(SRC_DIR)/PatchVersion7to8_unorderedmaps.cpp \
$(SRC_DIR)/PatchVersion8to9.cpp \
$(SRC_DIR)/SaveBinary.cpp \
$(SRC_DIR)/SymbolDatabase.cpp \
$(SRC_DIR)/Logging.cpp \
$(SRC_DIR)/main.cpp
# Object files
OBJECTS := $(SOURCES:.cpp=.o)
# Executable name
TARGET := $(BUILD_DIR)/polished_save_patcher.html
# Additional output files
ADDITIONAL_FILES := $(BUILD_DIR)/polished_save_patcher.js \
$(BUILD_DIR)/polished_save_patcher.wasm \
$(BUILD_DIR)/polished_save_patcher.mem \
$(BUILD_DIR)/polished_save_patcher.worker.js \
$(BUILD_DIR)/index.html
LDFLAGS := -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=33554432 # 32MB initial memory
# Windows-specific settings
ifeq ($(OS), Windows_NT)
CXX := emcc
RM := del
GZIP := gzip.exe
else
RM := rm -f
GZIP := gzip
endif
# Find all .sym files in version* directories
SYM_FILES := $(shell find $(VERSION_DIRS) -name '*.sym')
# Compressed symbol files
COMPRESSED_SYM_FILES := $(SYM_FILES:.sym=.sym.gz)
# Build target
all: $(BUILD_DIR) compress-symbols $(TARGET) copy-index
# Release target with optimizations
release: CXXFLAGS += -O3
release: LDFLAGS += -O3
release: all
# Create build directory
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Compress .sym files
compress-symbols: $(COMPRESSED_SYM_FILES)
# Rule to compress .sym files
%.sym.gz: %.sym
$(GZIP) -kf $<
# Linking
$(TARGET): $(OBJECTS)
$(CXX) $(OBJECTS) -o $@ $(LDFLAGS) -s WASM=1 -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' -s FORCE_FILESYSTEM=1 --embed-file resources --exclude-file *.sym --bind -sUSE_ZLIB=1
# Compilation
$(SRC_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@ -sUSE_ZLIB=1
# Copy index.html to build directory
copy-index:
cp index.html $(BUILD_DIR)/index.html
# Clean
clean:
$(RM) $(OBJECTS) $(TARGET) $(ADDITIONAL_FILES) $(COMPRESSED_SYM_FILES)
# Phony targets
.PHONY: all clean copy-index release compress-symbols