-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
151 lines (140 loc) · 4.93 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
.PHONY: help clean lib build
# 检测当前操作系统
ifeq ($(OS),Windows_NT)
PLATFORM := Windows
else
PLATFORM := $(shell uname)
endif
# 定义变量
CAPSTONE_VERSION := 5.0.1
KEYSTONE_VERSION := 0.9.2
INSTALL_PREFIX := /usr/local
CMAKE_FLAGS := -DCMAKE_INSTALL_PREFIX="$(INSTALL_PREFIX)"
MAKE_FLAGS :=
SUDO :=
ifeq ($(PLATFORM),Windows)
CMAKE_FLAGS += -DBUILD_LIBS_ONLY=1 \
-DLLVM_BUILD_32_BITS=0 \
-DCMAKE_OSX_ARCHITECTURES="x86_64" \
-DCMAKE_BUILD_TYPE="Release" \
-DBUILD_SHARED_LIBS=0 \
-DLLVM_TARGETS_TO_BUILD="all" \
-G "Unix Makefiles"
MAKE_FLAGS += -j8
CGO_CFLAGS := -I/usr/local/include -O2 -Wall
CGO_LDFLAGS := -L/usr/local/lib -static -lcapstone -lkeystone -lole32 -lshell32 -lkernel32 -lversion -luuid
TARGET := windows
KEYSTONE_BUILD_CMD := cmake $(CMAKE_FLAGS) .. && time make $(MAKE_FLAGS) && make install
else ifeq ($(PLATFORM),Darwin)
SUDO := sudo
CGO_CFLAGS := -I/usr/local/include -O2 -Wall
CGO_LDFLAGS := -L/usr/local/lib -lcapstone -lkeystone
TARGET := darwin
KEYSTONE_BUILD_CMD := ../make-lib.sh && $(SUDO) make install
else
$(error Unsupported platform: $(PLATFORM))
endif
help:
@echo "Available targets:"
@echo " help - Show this help message"
@echo " clean - Clean up temporary files"
@echo " lib - Build and install Capstone and Keystone libraries"
@echo " build - Build the project"
@echo " lib_riscv - Build and install Capstone and Keystone libraries for RISC-V"
@echo " build_riscv - Build the project for RISC-V"
clean:
@rm -rf tmp build && \
rm -rf $(INSTALL_PREFIX)/include/capstone && \
rm -rf $(INSTALL_PREFIX)/include/keystone && \
rm -f $(INSTALL_PREFIX)/lib/libcapstone* && \
rm -f $(INSTALL_PREFIX)/lib/libkeystone* && \
go clean -cache && \
echo "Cleaned up successfully"
lib:
git checkout main
@if [ -d "$(INSTALL_PREFIX)/lib" ] && \
[ -f "$(INSTALL_PREFIX)/lib/libcapstone.a" ] && \
[ -f "$(INSTALL_PREFIX)/lib/libkeystone.a" ]; then \
echo "Capstone and Keystone libraries are already installed"; \
else \
mkdir -p ./tmp && \
cd ./tmp && \
if [ ! -d "capstone" ]; then \
git clone https://github.com/capstone-engine/capstone.git && \
cd capstone && \
git checkout $(CAPSTONE_VERSION) && \
mkdir build && \
cd build && \
cmake $(CMAKE_FLAGS) .. && \
$(SUDO) cmake --build . --config Release --target install; \
else \
echo "Capstone library is already built, skipping build"; \
fi && \
cd ../.. && \
if [ ! -d "keystone" ]; then \
git clone https://github.com/keystone-engine/keystone.git && \
cd keystone && \
git checkout $(KEYSTONE_VERSION) && \
mkdir build && \
cd build && \
$(KEYSTONE_BUILD_CMD); \
else \
echo "Keystone library is already built, skipping build"; \
fi && \
cd ../.. && \
echo "Libraries installed successfully for $(PLATFORM)"; \
fi
lib_riscv:
git checkout RISCV32
@if [ -d "$(INSTALL_PREFIX)/lib" ] && \
[ -f "$(INSTALL_PREFIX)/lib/libcapstone.a" ] && \
[ -f "$(INSTALL_PREFIX)/lib/libkeystone.a" ]; then \
echo "Capstone and Keystone libraries are already installed"; \
else \
mkdir -p ./tmp && \
cd ./tmp && \
if [ ! -d "capstone" ]; then \
git clone https://github.com/capstone-engine/capstone.git && \
cd capstone && \
git checkout $(CAPSTONE_VERSION) && \
mkdir build && \
cd build && \
cmake $(CMAKE_FLAGS) .. && \
$(SUDO) cmake --build . --config Release --target install; \
else \
echo "Capstone library is already built, skipping build"; \
fi && \
cd ../.. && \
if [ ! -d "keystone" ]; then \
git clone https://github.com/null-cell/keystone.git keystone-riscv && \
cd keystone-riscv && \
git checkout 0.9.3.dev2 && \
mkdir build && \
cd build && \
$(KEYSTONE_BUILD_CMD); \
else \
echo "Keystone library is already built, skipping build"; \
fi && \
cd ../.. && \
echo "Libraries installed successfully for $(PLATFORM)"; \
fi
build_riscv:
git checkout RISCV32
@mkdir -p ./build-riscv && \
CGO_ENABLED=1 \
CGO_CFLAGS="$(CGO_CFLAGS)" \
CGO_LDFLAGS="$(CGO_LDFLAGS)" \
fyne package --release --target $(TARGET) --icon ./theme/icons/asm2hex.png && \
rm -rf ./build-riscv/$(if $(filter $(PLATFORM),Windows),*.exe,*.app) && \
mv -fv $(if $(filter $(PLATFORM),Windows),*.exe,*.app) ./build-riscv && \
echo "Build completed for $(PLATFORM)"
build:
git checkout main
@mkdir -p ./build && \
CGO_ENABLED=1 \
CGO_CFLAGS="$(CGO_CFLAGS)" \
CGO_LDFLAGS="$(CGO_LDFLAGS)" \
fyne package --release --target $(TARGET) --icon ./theme/icons/asm2hex.png && \
rm -rf ./build/$(if $(filter $(PLATFORM),Windows),*.exe,*.app) && \
mv -fv $(if $(filter $(PLATFORM),Windows),*.exe,*.app) ./build && \
echo "Build completed for $(PLATFORM)"