Use WxWidgets linker flags for scsi2sd-test
[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 endif
100 ifeq ($(TARGET),Darwin)
101         # Should match OSX
102         VPATH += hidapi/mac
103         LDFLAGS += -framework IOKit -framework CoreFoundation -lexpat
104         CC=clang -mmacosx-version-min=10.7
105         CXX=clang++ -stdlib=libc++ -mmacosx-version-min=10.7
106         WX_CONFIG += --with-macosx-version-min=10.7
107         CPPFLAGS_WXBUILD += -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=1
108         LIBUSB_CONFIG += --with-macosx-version-min=10.7 --disable-shared
109         LDFLAGS_LIBUSB += -lobjc
110         DFU-UTIL_CONFIG += --with-macosx-version-min=10.7 --disable-shared
111         BUILD := $(PWD)/build/mac
112 all: $(BUILD)/scsi2sd-util6.dmg
113
114 $(BUILD)/scsi2sd-util6.dmg: $(BUILD)/scsi2sd-util6 $(BUILD)/dfu-util/buildstamp
115         rm -rf $(dir $@)/dmg $@
116         mkdir -p $(dir $@)/dmg
117         cp $(BUILD)/scsi2sd-util6 $(BUILD)/dfu-util/src/dfu-util $(dir $@)/dmg
118         chmod a+rx $(dir $@)/dmg/*
119         hdiutil create -volname scsi2sd-util6 -srcfolder $(dir $@)/dmg $@
120 endif
121
122 ifeq ($(TARGET),osxcross)
123         # TODO osxcross tools must be in path for the wx configure to find the
124         # correct AR binary
125         VPATH += hidapi/mac
126         LDFLAGS += -framework IOKit -framework CoreFoundation -lexpat
127         CC=/home/michael/osx/osxcross/target/bin/x86_64-apple-darwin19-cc -mmacosx-version-min=10.7
128         CXX=/home/michael/osx/osxcross/target/bin/x86_64-apple-darwin19-c++ -stdlib=libc++ -mmacosx-version-min=10.7
129         LIBZIPPER_CONFIG+=--host=x86_64-apple-darwin19 "ZLIB_CFLAGS=-I$(BUILD)/zlib" "ZLIB_LIBS=-L$(BUILD)/zlib -lz"
130         CROSS_PREFIX=/home/michael/osx/osxcross/target/bin/x86_64-apple-darwin19-
131         WX_CONFIG += --with-macosx-version-min=10.7 --host=x86_64-apple-darwin19 SETFILE=/bin/true
132         CPPFLAGS_WXBUILD += -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=1
133         LIBUSB_CONFIG += --with-macosx-version-min=10.7 --disable-shared --host=x86_64-apple-darwin19
134         LDFLAGS_LIBUSB += -lobjc
135         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"
136         BUILD := $(PWD)/build/mac
137 all: $(BUILD)/scsi2sd-util6.dmg
138
139 $(BUILD)/scsi2sd-util6.dmg: $(BUILD)/scsi2sd-util6 $(BUILD)/dfu-util/buildstamp
140         rm -rf $(dir $@)/dmg $@
141         mkdir -p $(dir $@)/dmg
142         cp $(BUILD)/scsi2sd-util6 $(BUILD)/dfu-util/src/dfu-util $(dir $@)/dmg
143         chmod a+rx $(dir $@)/dmg/*
144         hdiutil create -volname scsi2sd-util6 -srcfolder $(dir $@)/dmg $@
145 endif
146
147 export CC CXX
148
149 all:  $(BUILD)/scsi2sd-util6$(EXE)
150
151
152 ifneq ($(USE_SYSTEM_HIDAPI),Yes)
153 HIDAPI = \
154         $(BUILD)/hid.o
155 endif
156
157 WXOBJ =\
158         $(BUILD)/ConfigUtil.o \
159         $(BUILD)/BoardPanel.o \
160         $(BUILD)/TargetPanel.o \
161         $(BUILD)/terminalwx.o \
162         $(BUILD)/terminalinputevent.o \
163         $(BUILD)/wxterm.o \
164         $(BUILD)/gterm.o \
165         $(BUILD)/actions.o \
166         $(BUILD)/keytrans.o \
167         $(BUILD)/states.o \
168         $(BUILD)/utils.o \
169         $(BUILD)/vt52_states.o \
170
171 OBJ = \
172         $(HIDAPI) \
173         $(BUILD)/SCSI2SD_HID.o \
174         $(BUILD)/hidpacket.o \
175         $(BUILD)/Dfu.o \
176
177
178 EXEOBJ = \
179         $(BUILD)/scsi2sd-util6.o \
180
181
182 ifneq ($(USE_SYSTEM_ZLIB),Yes)
183 $(OBJ): $(BUILD)/zlib/buildstamp
184 $(WXOBJ): $(BUILD)/zlib/buildstamp
185 $(EXEOBJ): $(BUILD)/zlib/buildstamp
186 $(BUILD)/zlib/buildstamp:
187         mkdir -p $(dir $@)
188         ( \
189                 cd $(dir $@) && \
190                 cp -a $(CURDIR)/zlib-1.2.8/* . && \
191                 CROSS_PREFIX=${CROSS_PREFIX} ./configure --static && \
192                 $(MAKE) \
193         ) && \
194         touch $@
195 endif
196
197 ifneq ($(USE_SYSTEM_LIBUSB),Yes)
198 $(OBJ): $(BUILD)/libusb/buildstamp
199 $(WXOBJ): $(BUILD)/libusb/buildstamp
200 $(EXEOBJ): $(BUILD)/libusb/buildstamp
201 $(BUILD)/libusb/buildstamp:
202         mkdir -p $(dir $@)
203         ( \
204                 cd $(dir $@) && \
205                 $(CURDIR)/libusb-1.0.23/configure $(LIBUSB_CONFIG) && \
206                 $(MAKE) \
207         ) && \
208         touch $@
209 else
210 $(BUILD)/libusb/buildstamp:
211         mkdir -p $(dir $@)
212         touch $@
213 endif
214
215 ifneq ($(USE_SYSTEM_WX),Yes)
216 $(OBJ): $(BUILD)/wx/buildstamp
217 $(WXOBJ): $(BUILD)/wx/buildstamp
218 $(EXEOBJ): $(BUILD)/wx/buildstamp
219 ifneq ($(USE_SYSTEM_ZLIB),Yes)
220 $(BUILD)/wx/buildstamp: $(BUILD)/zlib/buildstamp
221 else
222 $(BUILD)/wx/buildstamp:
223 endif
224         mkdir -p $(dir $@)
225         ( \
226                 cd $(dir $@) && \
227                 $(CURDIR)/wxWidgets/configure $(WX_CONFIG) CPPFLAGS="$(CPPFLAGS_ZLIB) $(CPPFLAGS_WXBUILD)" LDFLAGS="$(LDFLAGS_ZLIB)" && \
228                 $(MAKE) \
229         ) && \
230         touch $@
231 endif
232
233 ifneq ($(USE_SYSTEM_ZLIB),Yes)
234 LIBZIPPER_STATIC=-enable-static
235 endif
236
237 $(OBJ): $(BUILD)/libzipper/buildstamp
238 $(WXOBJ): $(BUILD)/libzipper/buildstamp
239 $(EXEOBJ): $(BUILD)/libzipper/buildstamp
240 ifneq ($(USE_SYSTEM_ZLIB),Yes)
241 $(BUILD)/libzipper/buildstamp: $(BUILD)/zlib/buildstamp
242 else
243 $(BUILD)/libzipper/buildstamp:
244 endif
245         mkdir -p $(dir $@)
246         ( \
247                 cd $(dir $@) && \
248                 $(CURDIR)/libzipper-1.0.4/configure ${LIBZIPPER_CONFIG} --disable-shared $(LIBZIPPER_STATIC) && \
249                 $(MAKE) libzipper.la \
250         ) && \
251         touch $@
252
253 $(BUILD)/%.o: %.c
254         mkdir -p $(dir $@)
255         $(CC) $(CPPFLAGS) $(CFLAGS) $< -c -o $@
256
257 $(BUILD)/%.o: %.cc
258         mkdir -p $(dir $@)
259 ifneq ($(USE_SYSTEM_WX),Yes)
260         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `$(BUILD)/wx/wx-config --cxxflags` $< -c -o $@
261 else
262         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `wx-config-3.0 --cxxflags` $< -c -o $@
263 endif
264
265 $(BUILD)/%.o: %.cpp
266         mkdir -p $(dir $@)
267 ifneq ($(USE_SYSTEM_WX),Yes)
268         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `$(BUILD)/wx/wx-config --cxxflags` $< -c -o $@
269 else
270         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `wx-config-3.0 --cxxflags` $< -c -o $@
271 endif
272
273 $(BUILD)/scsi2sd-util6$(EXE): $(OBJ) $(WXOBJ) $(BUILD)/scsi2sd-util.o
274         mkdir -p $(dir $@)
275         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
276
277 all: $(BUILD)/scsi2sd-test$(EXE)
278 $(BUILD)/scsi2sd-test$(EXE): $(OBJ) $(BUILD)/scsi2sd-test.o
279         mkdir -p $(dir $@)
280         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
281
282 all: $(BUILD)/dfu-util/buildstamp
283 $(BUILD)/dfu-util/buildstamp: $(BUILD)/libusb/buildstamp
284         mkdir -p $(dir $@)
285         ( \
286                 cd $(dir $@) && \
287                 $(CURDIR)/dfu-util/configure ${DFU-UTIL_CONFIG} CPPFLAGS="${CPPFLAGS_LIBUSB}" LDFLAGS="${LDFLAGS_LIBUSB} ${LDFLAGS}" && \
288                 $(MAKE) \
289         ) && \
290         touch $@
291
292 clean:
293         rm $(BUILD)/scsi2sd-util6$(EXE) $(OBJ) $(BUILD)/libzipper/buildstamp
294
295 PREFIX=/usr
296 install:
297         install -d $(DESTDIR)/$(PREFIX)/bin
298         install build/linux/scsi2sd-util6 $(DESTDIR)/$(PREFIX)/bin
299
300 dist:
301         rm -fr $(NAME)-$(VERSION)
302         mkdir $(NAME)-$(VERSION)
303         cp -pr ConfigUtil.cc ConfigUtil.hh scsi2sd-util6.spec \
304                ../SCSI2SD/src/hidpacket.c ../../include/hidpacket.h ../../include/scsi2sd.h \
305                libzipper-1.0.4 Makefile \
306                SCSI2SD_Bootloader.cc SCSI2SD_Bootloader.hh SCSI2SD_HID.cc SCSI2SD_HID.hh \
307                scsi2sd-util.cc TargetPanel.cc TargetPanel.hh \
308                BoardPanel.cc BoardPanel.hh \
309                $(NAME)-$(VERSION)
310         tar jcvf $(NAME)-$(VERSION).tar.bz2 $(NAME)-$(VERSION)