Lots of bug fixing, and 4.7 merges
[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.20/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         LIBUSB_CONFIG += --with-macosx-version-min=10.7 --disable-shared
108         LDFLAGS_LIBUSB += -lobjc
109         DFU-UTIL_CONFIG += --with-macosx-version-min=10.7 --disable-shared
110         BUILD := $(PWD)/build/mac
111 all: $(BUILD)/scsi2sd-util6.dmg
112
113 $(BUILD)/scsi2sd-util6.dmg: $(BUILD)/scsi2sd-util6 $(BUILD)/dfu-util/buildstamp
114         rm -rf $(dir $@)/dmg $@
115         mkdir -p $(dir $@)/dmg
116         cp $(BUILD)/scsi2sd-util6 $(BUILD)/dfu-util/src/dfu-util $(dir $@)/dmg
117         chmod a+rx $(dir $@)/dmg/*
118         hdiutil create -volname scsi2sd-util6 -srcfolder $(dir $@)/dmg $@
119 endif
120
121 export CC CXX
122
123 all:  $(BUILD)/scsi2sd-util6$(EXE)
124
125
126 ifneq ($(USE_SYSTEM_HIDAPI),Yes)
127 HIDAPI = \
128         $(BUILD)/hid.o
129 endif
130
131
132 OBJ = \
133         $(HIDAPI) \
134         $(BUILD)/ConfigUtil.o \
135         $(BUILD)/BoardPanel.o \
136         $(BUILD)/TargetPanel.o \
137         $(BUILD)/SCSI2SD_HID.o \
138         $(BUILD)/hidpacket.o \
139         $(BUILD)/Dfu.o \
140         $(BUILD)/terminalwx.o \
141         $(BUILD)/terminalinputevent.o \
142         $(BUILD)/wxterm.o \
143         $(BUILD)/gterm.o \
144         $(BUILD)/actions.o \
145         $(BUILD)/keytrans.o \
146         $(BUILD)/states.o \
147         $(BUILD)/utils.o \
148         $(BUILD)/vt52_states.o \
149
150
151 EXEOBJ = \
152         $(BUILD)/scsi2sd-util6.o \
153
154
155 ifneq ($(USE_SYSTEM_ZLIB),Yes)
156 $(OBJ): $(BUILD)/zlib/buildstamp
157 $(EXEOBJ): $(BUILD)/zlib/buildstamp
158 $(BUILD)/zlib/buildstamp:
159         mkdir -p $(dir $@)
160         ( \
161                 cd $(dir $@) && \
162                 cp -a $(CURDIR)/zlib-1.2.8/* . && \
163                 ./configure --static && \
164                 $(MAKE) \
165         ) && \
166         touch $@
167 endif
168
169 ifneq ($(USE_SYSTEM_LIBUSB),Yes)
170 $(OBJ): $(BUILD)/libusb/buildstamp
171 $(EXEOBJ): $(BUILD)/libusb/buildstamp
172 $(BUILD)/libusb/buildstamp:
173         mkdir -p $(dir $@)
174         ( \
175                 cd $(dir $@) && \
176                 $(CURDIR)/libusb-1.0.20/configure $(LIBUSB_CONFIG) && \
177                 $(MAKE) \
178         ) && \
179         touch $@
180 else
181 $(BUILD)/libusb/buildstamp:
182         mkdir -p $(dir $@)
183         touch $@
184 endif
185
186 ifneq ($(USE_SYSTEM_WX),Yes)
187 $(OBJ): $(BUILD)/wx/buildstamp
188 $(EXEOBJ): $(BUILD)/wx/buildstamp
189 ifneq ($(USE_SYSTEM_ZLIB),Yes)
190 $(BUILD)/wx/buildstamp: $(BUILD)/zlib/buildstamp
191 else
192 $(BUILD)/wx/buildstamp:
193 endif
194         mkdir -p $(dir $@)
195         ( \
196                 cd $(dir $@) && \
197                 $(CURDIR)/wxWidgets/configure $(WX_CONFIG) CPPFLAGS="$(CPPFLAGS_ZLIB)" LDFLAGS="$(LDFLAGS_ZLIB)" && \
198                 $(MAKE) \
199         ) && \
200         touch $@
201 endif
202
203 ifneq ($(USE_SYSTEM_ZLIB),Yes)
204 LIBZIPPER_STATIC=-enable-static
205 endif
206
207 $(OBJ): $(BUILD)/libzipper/buildstamp
208 $(EXEOBJ): $(BUILD)/libzipper/buildstamp
209 ifneq ($(USE_SYSTEM_ZLIB),Yes)
210 $(BUILD)/libzipper/buildstamp: $(BUILD)/zlib/buildstamp
211 else
212 $(BUILD)/libzipper/buildstamp:
213 endif
214         mkdir -p $(dir $@)
215         ( \
216                 cd $(dir $@) && \
217                 $(CURDIR)/libzipper-1.0.4/configure ${LIBZIPPER_CONFIG} --disable-shared $(LIBZIPPER_STATIC) && \
218                 $(MAKE) libzipper.la \
219         ) && \
220         touch $@
221
222 $(BUILD)/%.o: %.c
223         mkdir -p $(dir $@)
224         $(CC) $(CPPFLAGS) $(CFLAGS) $< -c -o $@
225
226 $(BUILD)/%.o: %.cc
227         mkdir -p $(dir $@)
228 ifneq ($(USE_SYSTEM_WX),Yes)
229         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `$(BUILD)/wx/wx-config --cxxflags` $< -c -o $@
230 else
231         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `wx-config-3.0 --cxxflags` $< -c -o $@
232 endif
233
234 $(BUILD)/%.o: %.cpp
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)/scsi2sd-util6$(EXE): $(OBJ) $(BUILD)/scsi2sd-util.o
243         mkdir -p $(dir $@)
244         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
245
246 all: $(BUILD)/dfu-util/buildstamp
247 $(BUILD)/dfu-util/buildstamp: $(BUILD)/libusb/buildstamp
248         mkdir -p $(dir $@)
249         ( \
250                 cd $(dir $@) && \
251                 $(CURDIR)/dfu-util/configure ${DFU-UTIL_CONFIG} CPPFLAGS="${CPPFLAGS_LIBUSB}" LDFLAGS="${LDFLAGS_LIBUSB} ${LDFLAGS}" && \
252                 $(MAKE) \
253         ) && \
254         touch $@
255
256 clean:
257         rm $(BUILD)/scsi2sd-util6$(EXE) $(OBJ) $(BUILD)/libzipper/buildstamp
258
259 PREFIX=/usr
260 install:
261         install -d $(DESTDIR)/$(PREFIX)/bin
262         install build/linux/scsi2sd-util6 $(DESTDIR)/$(PREFIX)/bin
263
264 dist:
265         rm -fr $(NAME)-$(VERSION)
266         mkdir $(NAME)-$(VERSION)
267         cp -pr ConfigUtil.cc ConfigUtil.hh scsi2sd-util6.spec \
268                ../SCSI2SD/src/hidpacket.c ../../include/hidpacket.h ../../include/scsi2sd.h \
269                libzipper-1.0.4 Makefile \
270                SCSI2SD_Bootloader.cc SCSI2SD_Bootloader.hh SCSI2SD_HID.cc SCSI2SD_HID.hh \
271                scsi2sd-util.cc TargetPanel.cc TargetPanel.hh \
272                BoardPanel.cc BoardPanel.hh \
273                $(NAME)-$(VERSION)
274         tar jcvf $(NAME)-$(VERSION).tar.bz2 $(NAME)-$(VERSION)