Skip to content

Commit e064398

Browse files
committed
more crap
1 parent 08b2c30 commit e064398

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

Makefile.w64

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Windows-specific Makefile for r2mcp
2+
# This Makefile uses MSVC compiler (cl.exe) and follows the r2frida pattern
3+
4+
CC = cl
5+
CFLAGS = /nologo /MT /Gy /O2 /Wall
6+
LDFLAGS = /nologo
7+
TARGET = r2mcp.exe
8+
R2MCP_VERSION = 1.2.0
9+
10+
# Source files
11+
SRC = src/main.c src/r2mcp.c src/readbuffer.c src/tools.c src/prompts.c
12+
OBJS = src/main.obj src/r2mcp.obj src/readbuffer.obj src/tools.obj src/prompts.obj
13+
14+
# Include files that are included into other source files
15+
INC = src/utils.inc.c src/r2api.inc.c
16+
17+
# Detect architecture
18+
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
19+
PLATFORM = x64
20+
TARGET_ARCH = x86_64
21+
else
22+
PLATFORM = x86
23+
TARGET_ARCH = x86
24+
endif
25+
26+
# Set up radare2 paths
27+
R2_BASE ?= C:\radare2
28+
ifeq ($(wildcard radare2),)
29+
ifeq ($(wildcard $(R2_BASE)),)
30+
$(error ERROR: Cannot find radare2 in CWD or $(R2_BASE))
31+
endif
32+
else
33+
R2_BASE = $(CURDIR)\radare2
34+
endif
35+
36+
R2_INC = /I"$(R2_BASE)\include" /I"$(R2_BASE)\include\libr" /I"$(R2_BASE)\include\libr\sdb"
37+
R2_LIB = "$(R2_BASE)\lib\*.lib"
38+
39+
# Get radare2 version
40+
R2V := $(shell "$(R2_BASE)\bin\radare2.exe" -qv 2>nul)
41+
42+
# Compiler flags
43+
CFLAGS += /DR2MCP_VERSION_STRING="\"$(R2MCP_VERSION)\""
44+
CFLAGS += $(R2_INC)
45+
CFLAGS += /I"src"
46+
47+
# Linker flags
48+
LDFLAGS += /defaultlib:setupapi.lib
49+
50+
.PHONY: all clean check_deps help install uninstall user-install user-uninstall debug release
51+
52+
all: check_deps $(TARGET)
53+
54+
check_deps:
55+
@echo Checking dependencies...
56+
@if not exist "$(R2_BASE)\bin\radare2.exe" (echo ERROR: radare2 not found at $(R2_BASE) && exit /b 1)
57+
@echo Using R2_BASE: $(R2_BASE)
58+
@echo Radare2 Version: $(R2V)
59+
@echo Platform: $(PLATFORM)
60+
@echo Target Architecture: $(TARGET_ARCH)
61+
62+
$(TARGET): config.h $(OBJS) $(INC)
63+
@echo Building R2 MCP server...
64+
$(CC) $(CFLAGS) -o $@ $(OBJS) $(R2_LIB) $(LDFLAGS)
65+
@echo Server built successfully.
66+
67+
config.h: config.h.w64
68+
@echo Copying Windows configuration header...
69+
copy /y config.h.w64 config.h
70+
71+
src/%.obj: src/%.c config.h
72+
@echo Compiling $<...
73+
$(CC) $(CFLAGS) /c $< /Fo$@
74+
75+
clean:
76+
@echo Cleaning build artifacts...
77+
del /q $(OBJS) 2>nul || echo No object files to clean
78+
del /q $(TARGET) 2>nul || echo No target to clean
79+
del /q config.h 2>nul || echo No config.h to clean
80+
del /q r2mcp-*-w64.zip 2>nul || echo No zip files to clean
81+
rmdir /s /q r2mcp-*-w64 2>nul || echo No distribution directory to clean
82+
83+
debug: CFLAGS := $(subst /O2,/Z7,$(CFLAGS))
84+
debug: $(TARGET)
85+
86+
release: $(TARGET)
87+
88+
install: all
89+
@echo Installing r2mcp to $(R2_BASE)\bin...
90+
copy $(TARGET) "$(R2_BASE)\bin\$(TARGET)"
91+
92+
uninstall:
93+
@echo Uninstalling r2mcp from $(R2_BASE)\bin...
94+
del "$(R2_BASE)\bin\$(TARGET)" 2>nul || echo r2mcp not found in $(R2_BASE)\bin
95+
96+
user-install: all
97+
@echo Installing r2mcp to user directory...
98+
@for /f %%i in ('"$(R2_BASE)\bin\radare2.exe" -H R2_USER_PLUGINS') do set R2_PLUGDIR=%%i
99+
@if not defined R2_PLUGDIR (echo ERROR: Cannot determine R2_USER_PLUGINS directory && exit /b 1)
100+
@echo Installing to %R2_PLUGDIR%...
101+
copy $(TARGET) "%R2_PLUGDIR%\$(TARGET)"
102+
103+
user-uninstall:
104+
@echo Uninstalling r2mcp from user directory...
105+
@for /f %%i in ('"$(R2_BASE)\bin\radare2.exe" -H R2_USER_PLUGINS') do set R2_PLUGDIR=%%i
106+
@if not defined R2_PLUGDIR (echo ERROR: Cannot determine R2_USER_PLUGINS directory && exit /b 1)
107+
del "%R2_PLUGDIR%\$(TARGET)" 2>nul || echo r2mcp not found in %R2_PLUGDIR%
108+
109+
dist: $(TARGET)
110+
@echo Creating distribution package...
111+
@if exist r2mcp-$(R2V)-w64.zip del r2mcp-$(R2V)-w64.zip
112+
@if exist r2mcp-$(R2V)-w64 rmdir /s /q r2mcp-$(R2V)-w64
113+
@mkdir r2mcp-$(R2V)-w64
114+
@copy README.md r2mcp-$(R2V)-w64\
115+
@copy $(TARGET) r2mcp-$(R2V)-w64\
116+
@copy install.bat r2mcp-$(R2V)-w64\
117+
@powershell -command "Compress-Archive -Path r2mcp-$(R2V)-w64 -DestinationPath r2mcp-$(R2V)-w64.zip"
118+
@echo Distribution package created: r2mcp-$(R2V)-w64.zip
119+
120+
help:
121+
@echo Available targets:
122+
@echo all - Build the server (default)
123+
@echo check_deps - Check for required dependencies
124+
@echo clean - Remove built binaries
125+
@echo debug - Build with debug symbols
126+
@echo release - Build release version
127+
@echo install - Install the server to radare2 bin directory
128+
@echo uninstall - Remove the server from radare2 bin directory
129+
@echo user-install - Install the server to user plugin directory
130+
@echo user-uninstall - Remove the server from user plugin directory
131+
@echo dist - Create distribution zip package
132+
@echo help - Display this help message
133+
@echo.
134+
@echo Usage: nmake /f Makefile.w64 [target]
135+
@echo.
136+
@echo Environment variables:
137+
@echo R2_BASE - Path to radare2 installation (default: C:\radare2)
138+
@echo PLATFORM - Target platform (x86 or x64)
139+
@echo.
140+
@echo Example:
141+
@echo nmake /f Makefile.w64 all
142+
@echo nmake /f Makefile.w64 R2_BASE=C:\radare2 install

0 commit comments

Comments
 (0)