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