Add option to skip building dfu-util
[SCSI2SD-V6.git] / src / scsi2sd-util6 / Makefile
1 VPATH=../firmware TerminalWx/src TerminalWx/src/taTelnet TerminalWx/src/GTerm
2
3 VERSION=6.0
4 NAME=scsi2sd-util6
5
6 ifeq ($(USE_SYSTEM), Yes)
7 USE_SYSTEM_HIDAPI = Yes
8 USE_SYSTEM_ZLIB = Yes
9 USE_SYSTEM_WX = Yes
10 USE_SYSTEM_LIBUSB = Yes
11 USE_SYSTEM_DFU_UTIL = Yes
12 endif
13
14 ifeq ($(USE_SYSTEM_LIBUSB), Yes)
15 CPPFLAGS_LIBUSB=$(shell pkg-config libusb-1.0 --cflags)
16 LDFLAGS_LIBUSB=$(shell pkg-config libusb-1.0 --libs)
17 else
18 CPPFLAGS_LIBUSB=-I $(PWD)/libusb-1.0.23/libusb
19 LDFLAGS_LIBUSB=-L $(BUILD)/libusb/libusb/.libs -lusb-1.0
20 endif
21
22 ifeq ($(USE_SYSTEM_HIDAPI), Yes)
23 CPPFLAGS_HIDAPI=$(shell pkg-config hidapi-hidraw --cflags)
24 LDFLAGS_HIDAPI=$(shell pkg-config hidapi-hidraw --libs)
25 else
26 CPPFLAGS_HIDAPI=-I hidapi/hidapi
27 LDFLAGS_HIDAPI=
28 endif
29
30 ifeq ($(USE_SYSTEM_ZLIB), Yes)
31 CPPFLAGS_ZLIB=$(shell pkg-config zlib --cflags)
32 LDFLAGS_ZLIB=$(shell pkg-config zlib --libs)
33 LIBZIPPER_CONFIG = --disable-shared LDFLAGS="$(LDFLAGS_ZLIB)" CPPFLAGS="$(CPPFLAGS_ZLIB)"
34 else
35 CPPFLAGS_ZLIB=-I$(BUILD)/zlib
36 LDFLAGS_ZLIB=-L$(BUILD)/zlib -lz
37 LIBZIPPER_CONFIG = --disable-shared LDFLAGS="-L../zlib" CPPFLAGS="-I../zlib"
38 endif
39
40 ifeq ($(USE_SYSTEM_WX),Yes)
41 LDFLAGS_WX=$(shell wx-config-3.0 --libs)
42 else
43 LDFLAGS_WX=$(shell $(BUILD)/wx/wx-config --libs)
44 endif
45
46 CPPFLAGS = $(CPPFLAGS_HIDAPI) -I. -I ../../include -ITerminalWx/src \
47         -Ilibzipper-1.0.4 \
48         $(CPPFLAGS_ZLIB) \
49         $(CPPFLAGS_LIBUSB) \
50         -DHAVE_LIBUSB_1_0 \
51
52
53 CFLAGS += -Wall -Wno-pointer-sign -O2 -g -fPIC
54 CXXFLAGS += -Wall -O2 -g -std=c++0x -fPIC
55
56 LDFLAGS += -L$(BUILD)/libzipper/.libs -lzipper \
57         $(LDFLAGS_ZLIB) \
58         $(LDFLAGS_HIDAPI) \
59         $(LDFLAGS_LIBUSB)
60
61
62 # wxWidgets 3.0.2 uses broken Webkit headers under OSX Yosemeti
63 # liblzma not available on OSX 10.7
64 # --disable-mediactrl for missing Quicktime.h on Mac OSX Sierra
65 WX_CONFIG=--disable-webkit --disable-webviewwebkit  --disable-mediactrl \
66         --without-libtiff --without-libjbig --without-liblzma --without-opengl \
67         --enable-monolithic --enable-stl --disable-shared
68
69 TARGET ?= $(shell uname -s)
70 ifeq ($(TARGET),Win32)
71         VPATH += hidapi/windows
72         LDFLAGS += -static -mconsole -mwindows -lsetupapi
73         BUILD := $(PWD)/build/windows/32bit
74         CC=i686-w64-mingw32-gcc
75         CXX=i686-w64-mingw32-g++
76         LIBZIPPER_CONFIG+=--host=i686-w64-mingw32
77         EXE=.exe
78         WX_CONFIG+=--host=i686-w64-mingw32
79         LIBUSB_CONFIG+=--host=i686-w64-mingw32 --disable-shared
80         DFU-UTIL_CONFIG+=--host=i686-w64-mingw32
81 endif
82 ifeq ($(TARGET),Win64)
83         VPATH += hidapi/windows
84         LDFLAGS += -static -mconsole -mwindows -lsetupapi
85         BUILD := $(PWD)/build/windows/64bit
86         CC=x86_64-w64-mingw32-gcc
87         CXX=x86_64-w64-mingw32-g++
88         LIBZIPPER_CONFIG+=--host=x86_64-w64-mingw32
89         EXE=.exe
90         WX_CONFIG+=--host=x86_64-w64-mingw32
91         LIBUSB_CONFIG+=--host=x86_64-w64-mingw32 --disable-shared
92         DFU-UTIL_CONFIG+=--host=x86_64-w64-mingw32
93 endif
94 ifeq ($(TARGET),Linux)
95         VPATH += hidapi/linux
96         LDFLAGS += -ludev -lexpat -lusb-1.0
97         BUILD := $(PWD)/build/linux
98         LIBUSB_CONFIG+=--disable-shared
99         LDFLAGS_LIBUSB+= -ludev -lpthread
100 endif
101 ifeq ($(TARGET),Darwin)
102         # Should match OSX
103         VPATH += hidapi/mac
104         LDFLAGS += -framework IOKit -framework CoreFoundation -lexpat
105         CC=clang -mmacosx-version-min=10.7
106         CXX=clang++ -stdlib=libc++ -mmacosx-version-min=10.7
107         WX_CONFIG += --with-macosx-version-min=10.7
108         CPPFLAGS_WXBUILD += -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=1
109         LIBUSB_CONFIG += --with-macosx-version-min=10.7 --disable-shared
110         LDFLAGS_LIBUSB += -lobjc
111         DFU-UTIL_CONFIG += --with-macosx-version-min=10.7 --disable-shared
112         BUILD := $(PWD)/build/mac
113 all: $(BUILD)/scsi2sd-util6.dmg
114
115 $(BUILD)/scsi2sd-util6.dmg: $(BUILD)/scsi2sd-util6 $(BUILD)/dfu-util/buildstamp
116         rm -rf $(dir $@)/dmg $@
117         mkdir -p $(dir $@)/dmg
118         cp $(BUILD)/scsi2sd-util6 $(BUILD)/dfu-util/src/dfu-util $(dir $@)/dmg
119         chmod a+rx $(dir $@)/dmg/*
120         hdiutil create -volname scsi2sd-util6 -srcfolder $(dir $@)/dmg $@
121 endif
122
123 ifeq ($(TARGET),osxcross)
124         # TODO osxcross tools must be in path for the wx configure to find the
125         # correct AR binary
126         VPATH += hidapi/mac
127         LDFLAGS += -framework IOKit -framework CoreFoundation -lexpat
128         CC=/home/michael/osx/osxcross/target/bin/x86_64-apple-darwin19-cc -mmacosx-version-min=10.7
129         CXX=/home/michael/osx/osxcross/target/bin/x86_64-apple-darwin19-c++ -stdlib=libc++ -mmacosx-version-min=10.7
130         LIBZIPPER_CONFIG+=--host=x86_64-apple-darwin19 "ZLIB_CFLAGS=-I$(BUILD)/zlib" "ZLIB_LIBS=-L$(BUILD)/zlib -lz"
131         CROSS_PREFIX=/home/michael/osx/osxcross/target/bin/x86_64-apple-darwin19-
132         WX_CONFIG += --with-macosx-version-min=10.7 --host=x86_64-apple-darwin19 SETFILE=/bin/true
133         CPPFLAGS_WXBUILD += -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=1
134         LIBUSB_CONFIG += --with-macosx-version-min=10.7 --disable-shared --host=x86_64-apple-darwin19
135         LDFLAGS_LIBUSB += -lobjc
136         DFU-UTIL_CONFIG += --with-macosx-version-min=10.7 --disable-shared --host=x86_64-apple-darwin19 "USB_CFLAGS=-I$(BUILD)/libusb/libusb/include" "USB_LIBS=-L$(BUILD)/libusb/libusb/.libs -lusb-1.0 -lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
137         BUILD := $(PWD)/build/mac
138 all: $(BUILD)/scsi2sd-util6.dmg
139
140 $(BUILD)/scsi2sd-util6.dmg: $(BUILD)/scsi2sd-util6 $(BUILD)/dfu-util/buildstamp
141         rm -rf $(dir $@)/dmg $@
142         mkdir -p $(dir $@)/dmg
143         cp $(BUILD)/scsi2sd-util6 $(BUILD)/dfu-util/src/dfu-util $(dir $@)/dmg
144         chmod a+rx $(dir $@)/dmg/*
145         hdiutil create -volname scsi2sd-util6 -srcfolder $(dir $@)/dmg $@
146 endif
147
148 export CC CXX
149
150 all:  $(BUILD)/scsi2sd-util6$(EXE)
151
152
153 ifneq ($(USE_SYSTEM_HIDAPI),Yes)
154 HIDAPI = \
155         $(BUILD)/hid.o
156 endif
157
158 WXOBJ =\
159         $(BUILD)/ConfigUtil.o \
160         $(BUILD)/BoardPanel.o \
161         $(BUILD)/TargetPanel.o \
162         $(BUILD)/terminalwx.o \
163         $(BUILD)/terminalinputevent.o \
164         $(BUILD)/wxterm.o \
165         $(BUILD)/gterm.o \
166         $(BUILD)/actions.o \
167         $(BUILD)/keytrans.o \
168         $(BUILD)/states.o \
169         $(BUILD)/utils.o \
170         $(BUILD)/vt52_states.o \
171
172 OBJ = \
173         $(HIDAPI) \
174         $(BUILD)/SCSI2SD_HID.o \
175         $(BUILD)/hidpacket.o \
176         $(BUILD)/Dfu.o \
177
178
179 EXEOBJ = \
180         $(BUILD)/scsi2sd-util6.o \
181
182
183 ifneq ($(USE_SYSTEM_ZLIB),Yes)
184 $(OBJ): $(BUILD)/zlib/buildstamp
185 $(WXOBJ): $(BUILD)/zlib/buildstamp
186 $(EXEOBJ): $(BUILD)/zlib/buildstamp
187 $(BUILD)/zlib/buildstamp:
188         mkdir -p $(dir $@)
189         ( \
190                 cd $(dir $@) && \
191                 cp -a $(CURDIR)/zlib-1.2.8/* . && \
192                 CROSS_PREFIX=${CROSS_PREFIX} ./configure --static && \
193                 $(MAKE) \
194         ) && \
195         touch $@
196 endif
197
198 ifneq ($(USE_SYSTEM_LIBUSB),Yes)
199 $(OBJ): $(BUILD)/libusb/buildstamp
200 $(WXOBJ): $(BUILD)/libusb/buildstamp
201 $(EXEOBJ): $(BUILD)/libusb/buildstamp
202 $(BUILD)/libusb/buildstamp:
203         mkdir -p $(dir $@)
204         ( \
205                 cd $(dir $@) && \
206                 $(CURDIR)/libusb-1.0.23/configure $(LIBUSB_CONFIG) && \
207                 $(MAKE) \
208         ) && \
209         touch $@
210 else
211 $(BUILD)/libusb/buildstamp:
212         mkdir -p $(dir $@)
213         touch $@
214 endif
215
216 ifneq ($(USE_SYSTEM_WX),Yes)
217 $(OBJ): $(BUILD)/wx/buildstamp
218 $(WXOBJ): $(BUILD)/wx/buildstamp
219 $(EXEOBJ): $(BUILD)/wx/buildstamp
220 ifneq ($(USE_SYSTEM_ZLIB),Yes)
221 $(BUILD)/wx/buildstamp: $(BUILD)/zlib/buildstamp
222 else
223 $(BUILD)/wx/buildstamp:
224 endif
225         mkdir -p $(dir $@)
226         ( \
227                 cd $(dir $@) && \
228                 $(CURDIR)/wxWidgets/configure $(WX_CONFIG) CPPFLAGS="$(CPPFLAGS_ZLIB) $(CPPFLAGS_WXBUILD)" LDFLAGS="$(LDFLAGS_ZLIB)" && \
229                 $(MAKE) \
230         ) && \
231         touch $@
232 endif
233
234 ifneq ($(USE_SYSTEM_ZLIB),Yes)
235 LIBZIPPER_STATIC=-enable-static
236 endif
237
238 $(OBJ): $(BUILD)/libzipper/buildstamp
239 $(WXOBJ): $(BUILD)/libzipper/buildstamp
240 $(EXEOBJ): $(BUILD)/libzipper/buildstamp
241 ifneq ($(USE_SYSTEM_ZLIB),Yes)
242 $(BUILD)/libzipper/buildstamp: $(BUILD)/zlib/buildstamp
243 else
244 $(BUILD)/libzipper/buildstamp:
245 endif
246         mkdir -p $(dir $@)
247         ( \
248                 cd $(dir $@) && \
249                 $(CURDIR)/libzipper-1.0.4/configure ${LIBZIPPER_CONFIG} --disable-shared $(LIBZIPPER_STATIC) && \
250                 $(MAKE) libzipper.la \
251         ) && \
252         touch $@
253
254 $(BUILD)/%.o: %.c
255         mkdir -p $(dir $@)
256         $(CC) $(CPPFLAGS) $(CFLAGS) $< -c -o $@
257
258 $(BUILD)/%.o: %.cc
259         mkdir -p $(dir $@)
260 ifneq ($(USE_SYSTEM_WX),Yes)
261         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `$(BUILD)/wx/wx-config --cxxflags` $< -c -o $@
262 else
263         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `wx-config-3.0 --cxxflags` $< -c -o $@
264 endif
265
266 $(BUILD)/%.o: %.cpp
267         mkdir -p $(dir $@)
268 ifneq ($(USE_SYSTEM_WX),Yes)
269         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `$(BUILD)/wx/wx-config --cxxflags` $< -c -o $@
270 else
271         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `wx-config-3.0 --cxxflags` $< -c -o $@
272 endif
273
274 $(BUILD)/scsi2sd-util6$(EXE): $(OBJ) $(WXOBJ) $(BUILD)/scsi2sd-util.o
275         mkdir -p $(dir $@)
276         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
277
278 all: $(BUILD)/scsi2sd-test$(EXE)
279 $(BUILD)/scsi2sd-test$(EXE): $(OBJ) $(BUILD)/scsi2sd-test.o
280         mkdir -p $(dir $@)
281         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
282
283 ifneq ($(USE_SYSTEM_DFU_UTIL),Yes)
284 all: $(BUILD)/dfu-util/buildstamp
285 endif
286 $(BUILD)/dfu-util/buildstamp: $(BUILD)/libusb/buildstamp
287         mkdir -p $(dir $@)
288         ( \
289                 cd $(dir $@) && \
290                 $(CURDIR)/dfu-util/configure ${DFU-UTIL_CONFIG} CPPFLAGS="${CPPFLAGS_LIBUSB}" LDFLAGS="${LDFLAGS_LIBUSB} ${LDFLAGS}" && \
291                 $(MAKE) \
292         ) && \
293         touch $@
294
295 clean:
296         rm $(BUILD)/scsi2sd-util6$(EXE) $(OBJ) $(BUILD)/libzipper/buildstamp
297
298 PREFIX=/usr
299 install:
300         install -d $(DESTDIR)/$(PREFIX)/bin
301         install build/linux/scsi2sd-util6 $(DESTDIR)/$(PREFIX)/bin
302
303 dist:
304         rm -fr $(NAME)-$(VERSION)
305         mkdir $(NAME)-$(VERSION)
306         cp -pr ConfigUtil.cc ConfigUtil.hh scsi2sd-util6.spec \
307                ../SCSI2SD/src/hidpacket.c ../../include/hidpacket.h ../../include/scsi2sd.h \
308                libzipper-1.0.4 Makefile \
309                SCSI2SD_Bootloader.cc SCSI2SD_Bootloader.hh SCSI2SD_HID.cc SCSI2SD_HID.hh \
310                scsi2sd-util.cc TargetPanel.cc TargetPanel.hh \
311                BoardPanel.cc BoardPanel.hh \
312                $(NAME)-$(VERSION)
313         tar jcvf $(NAME)-$(VERSION).tar.bz2 $(NAME)-$(VERSION)