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