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