-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
212 lines (177 loc) · 6.45 KB
/
Makefile
File metadata and controls
212 lines (177 loc) · 6.45 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Makefile for Windows - Use with MinGW or Visual Studio nmake
# For MinGW: mingw32-make
# For Visual Studio: nmake
# Detect architecture
!IF "$(VSCMD_ARG_TGT_ARCH)" == "x86"
ARCH = x86
FTDI_ARCH = i386
!ELSEIF "$(VSCMD_ARG_TGT_ARCH)" == "x64"
ARCH = x64
FTDI_ARCH = amd64
!ELSEIF "$(Platform)" == "x86"
ARCH = x86
FTDI_ARCH = i386
!ELSEIF "$(Platform)" == "x64"
ARCH = x64
FTDI_ARCH = amd64
!ELSE
# Default to x64
ARCH = x64
FTDI_ARCH = amd64
!ENDIF
!MESSAGE Building for $(ARCH) architecture
# Output directory
BUILD_DIR = build
# Compiler selection
!IFDEF USE_MINGW
CC = gcc
CFLAGS = -Wall -O2 -DFORWIN
LDFLAGS =
OBJEXT = .o
EXEEXT = .exe
RM = del /Q
!ELSE
# Visual Studio
CC = cl
CFLAGS = /W3 /O2 /DFORWIN /D_CRT_SECURE_NO_WARNINGS
LDFLAGS = /link
OBJEXT = .obj
EXEEXT = .exe
RM = del /Q
!ENDIF
# FTDI D2XX library paths - using local ftdilib folder
FTDI_DIR = ftdilib
FTDI_INCLUDE = $(FTDI_DIR)
FTDI_LIB = $(FTDI_DIR)\$(FTDI_ARCH)\ftd2xx.lib
# For MinGW, you might need to use the .a import library instead:
# FTDI_LIB = $(FTDI_DIR)\$(FTDI_ARCH)\ftd2xx.a
# Include paths
INCLUDES = -I. -I$(FTDI_INCLUDE)
# Libraries
!IFDEF USE_MINGW
LIBS = -L$(FTDI_DIR)\amd64 -lftd2xx -lws2_32
!ELSE
LIBS = $(FTDI_LIB) ws2_32.lib
!ENDIF
# Object files (in build directory)
LIBXSVF_OBJS = \
$(BUILD_DIR)\memname$(OBJEXT) \
$(BUILD_DIR)\play$(OBJEXT) \
$(BUILD_DIR)\scan$(OBJEXT) \
$(BUILD_DIR)\statename$(OBJEXT) \
$(BUILD_DIR)\svf$(OBJEXT) \
$(BUILD_DIR)\tap$(OBJEXT) \
$(BUILD_DIR)\xsvf$(OBJEXT)
XSVFTOOL_OBJS = \
$(BUILD_DIR)\xsvfplay_ftd2xx$(OBJEXT) \
$(LIBXSVF_OBJS)
# DirtyJTAG object files (Windows nmake target uses libusb-1.0)
DIRTYJTAG_OBJS = \
$(BUILD_DIR)\xsvfplay_dirtyjtag$(OBJEXT) \
$(LIBXSVF_OBJS)
# libusb-1.0 paths - using local VS2022 folder (MS32 for x86, MS64 for x64)
LIBUSB_DIR = VS2022
LIBUSB_INCLUDE = include
!IF "$(ARCH)" == "x86"
LIBUSB_ARCH = MS32
!ELSE
LIBUSB_ARCH = MS64
!ENDIF
LIBUSB_LIB_DIR = $(LIBUSB_DIR)\$(LIBUSB_ARCH)\dll
LIBUSB_DLL = $(LIBUSB_LIB_DIR)\libusb-1.0.dll
# Libraries for DirtyJTAG build (requires libusb-1.0)
!IFDEF USE_MINGW
DIRTYJTAG_LIBS = -L$(LIBUSB_LIB_DIR) -lusb-1.0
!ELSE
DIRTYJTAG_LIBS = /LIBPATH:$(LIBUSB_LIB_DIR) libusb-1.0.lib
!ENDIF
LIBUSB_INCLUDES = /I$(LIBUSB_INCLUDE)
# Combined single-exe object files
COMBINED_OBJS = \
$(BUILD_DIR)\xsvftool$(OBJEXT) \
$(LIBXSVF_OBJS)
# Targets
# 'all' builds the combined tool + both standalone tools
all: check-ftdilib $(BUILD_DIR) $(BUILD_DIR)\xsvftool$(EXEEXT) $(BUILD_DIR)\xsvftool-ftd2xx$(EXEEXT) $(BUILD_DIR)\xsvftool-dirtyjtag$(EXEEXT) copy-dlls clean-objs
# Build only the combined tool (requires both ftdilib and libusb)
combined: check-ftdilib $(BUILD_DIR) $(BUILD_DIR)\xsvftool$(EXEEXT) copy-dlls clean-objs
# Create build directory
$(BUILD_DIR):
@if not exist "$(BUILD_DIR)" mkdir "$(BUILD_DIR)"
check-ftdilib:
!IF !EXIST(ftdilib\ftd2xx.h)
@echo ERROR: ftdilib\ftd2xx.h not found!
@echo Please create ftdilib folder and copy FTDI D2XX files.
@exit 1
!ENDIF
$(BUILD_DIR)\xsvftool-ftd2xx$(EXEEXT): $(XSVFTOOL_OBJS)
!IFDEF USE_MINGW
$(CC) $(CFLAGS) -o $@ $(XSVFTOOL_OBJS) $(LIBS)
!ELSE
$(CC) $(CFLAGS) $(XSVFTOOL_OBJS) /Fe$@ $(LDFLAGS) $(LIBS)
!ENDIF
$(BUILD_DIR)\xsvftool-dirtyjtag$(EXEEXT): $(DIRTYJTAG_OBJS)
!IFDEF USE_MINGW
$(CC) $(CFLAGS) -o $@ $(DIRTYJTAG_OBJS) $(DIRTYJTAG_LIBS)
!ELSE
$(CC) $(CFLAGS) $(DIRTYJTAG_OBJS) /Fe$@ $(LDFLAGS) $(DIRTYJTAG_LIBS)
!ENDIF
$(BUILD_DIR)\xsvftool$(EXEEXT): $(COMBINED_OBJS)
!IFDEF USE_MINGW
$(CC) $(CFLAGS) -o $@ $(COMBINED_OBJS) $(LIBS) $(DIRTYJTAG_LIBS)
!ELSE
$(CC) $(CFLAGS) $(COMBINED_OBJS) /Fe$@ $(LDFLAGS) $(LIBS) $(DIRTYJTAG_LIBS)
!ENDIF
# Copy runtime DLLs into build directory so they're found without PATH changes
# Uses single-line commands and leading dash (-) so missing DLLs are non-fatal
copy-dlls:
@echo Copying runtime DLLs...
-@if exist "$(LIBUSB_DLL)" copy /Y "$(LIBUSB_DLL)" "$(BUILD_DIR)\" >nul && echo libusb-1.0.dll copied from $(LIBUSB_LIB_DIR)
-@if exist "$(FTDI_DIR)\$(FTDI_ARCH)\ftd2xx.dll" copy /Y "$(FTDI_DIR)\$(FTDI_ARCH)\ftd2xx.dll" "$(BUILD_DIR)\" >nul && echo ftd2xx.dll copied from $(FTDI_DIR)\$(FTDI_ARCH)
# Remove intermediate object files from build directory after linking
clean-objs:
-@if exist "$(BUILD_DIR)\*.obj" del /Q "$(BUILD_DIR)\*.obj"
-@if exist "$(BUILD_DIR)\*.o" del /Q "$(BUILD_DIR)\*.o"
# Build only the DirtyJTAG standalone tool (no ftdilib required)
dirtyjtag: $(BUILD_DIR) $(BUILD_DIR)\xsvftool-dirtyjtag$(EXEEXT) copy-dlls clean-objs
# Compilation rules — all objects go into build directory
!IFDEF USE_MINGW
{.}.c{$(BUILD_DIR)}$(OBJEXT):
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
!ELSE
{.}.c{$(BUILD_DIR)}$(OBJEXT):
$(CC) $(CFLAGS) $(INCLUDES) /c $< /Fo$@
!ENDIF
# Explicit rules for the two main files so their unique flags are always applied.
# The DirtyJTAG file needs -DDIRTYJTAG_STANDALONE to emit main(); this cannot
# be left to the generic inference rule which has no way to add per-file flags.
!IFDEF USE_MINGW
$(BUILD_DIR)\xsvfplay_ftd2xx$(OBJEXT): xsvfplay_ftd2xx.c libxsvf.h
$(CC) $(CFLAGS) $(INCLUDES) -c xsvfplay_ftd2xx.c -o $@
$(BUILD_DIR)\xsvfplay_dirtyjtag$(OBJEXT): xsvfplay_dirtyjtag.c libxsvf.h
$(CC) $(CFLAGS) -I. $(LIBUSB_INCLUDES) -DDIRTYJTAG_STANDALONE -c xsvfplay_dirtyjtag.c -o $@
$(BUILD_DIR)\xsvftool$(OBJEXT): xsvftool.c xsvfplay_ftd2xx.c xsvfplay_dirtyjtag.c libxsvf.h
$(CC) $(CFLAGS) $(INCLUDES) $(LIBUSB_INCLUDES) -DCOMBINED_BUILD -c xsvftool.c -o $@
!ELSE
$(BUILD_DIR)\xsvfplay_ftd2xx$(OBJEXT): xsvfplay_ftd2xx.c libxsvf.h
$(CC) $(CFLAGS) $(INCLUDES) /c xsvfplay_ftd2xx.c /Fo$@
$(BUILD_DIR)\xsvfplay_dirtyjtag$(OBJEXT): xsvfplay_dirtyjtag.c libxsvf.h
$(CC) $(CFLAGS) /I. $(LIBUSB_INCLUDES) /DDIRTYJTAG_STANDALONE /c xsvfplay_dirtyjtag.c /Fo$@
$(BUILD_DIR)\xsvftool$(OBJEXT): xsvftool.c xsvfplay_ftd2xx.c xsvfplay_dirtyjtag.c libxsvf.h
$(CC) $(CFLAGS) $(INCLUDES) $(LIBUSB_INCLUDES) /DCOMBINED_BUILD /c xsvftool.c /Fo$@
!ENDIF
# Dependencies for shared libxsvf sources
$(BUILD_DIR)\memname$(OBJEXT): memname.c libxsvf.h
$(BUILD_DIR)\play$(OBJEXT): play.c libxsvf.h
$(BUILD_DIR)\scan$(OBJEXT): scan.c libxsvf.h
$(BUILD_DIR)\statename$(OBJEXT): statename.c libxsvf.h
$(BUILD_DIR)\svf$(OBJEXT): svf.c libxsvf.h
$(BUILD_DIR)\tap$(OBJEXT): tap.c libxsvf.h
$(BUILD_DIR)\xsvf$(OBJEXT): xsvf.c libxsvf.h
# Clean
clean:
-@if exist "$(BUILD_DIR)" rmdir /S /Q "$(BUILD_DIR)"
# Install target (optional)
install:
@echo Copy build\xsvftool-ftd2xx.exe and build\xsvftool-dirtyjtag.exe to your desired location
@echo Runtime DLLs (ftd2xx.dll, libusb-1.0.dll) should already be alongside the .exe files.