28a10367b54fd441e51a8320e9c145808339a59e
[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
53 CXXFLAGS += -Wall -O2 -g -std=c++0x
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 WX_CONFIG=--disable-webkit --disable-webviewwebkit  \
64         --without-libtiff --without-libjbig --without-liblzma --without-opengl \
65         --enable-monolithic --enable-stl --disable-shared
66
67 TARGET ?= $(shell uname -s)
68 ifeq ($(TARGET),Win32)
69         VPATH += hidapi/windows
70         LDFLAGS += -static -mconsole -mwindows -lsetupapi
71         BUILD := $(PWD)/build/windows/32bit
72         CC=i686-w64-mingw32-gcc
73         CXX=i686-w64-mingw32-g++
74         LIBZIPPER_CONFIG+=--host=i686-w64-mingw32
75         EXE=.exe
76         WX_CONFIG+=--host=i686-w64-mingw32
77         LIBUSB_CONFIG+=--host=i686-w64-mingw32 --disable-shared
78         DFU-UTIL_CONFIG+=--host=i686-w64-mingw32
79 endif
80 ifeq ($(TARGET),Win64)
81         VPATH += hidapi/windows
82         LDFLAGS += -static -mconsole -mwindows -lsetupapi
83         BUILD := $(PWD)/build/windows/64bit
84         CC=x86_64-w64-mingw32-gcc
85         CXX=x86_64-w64-mingw32-g++
86         LIBZIPPER_CONFIG+=--host=x86_64-w64-mingw32
87         EXE=.exe
88         WX_CONFIG+=--host=x86_64-w64-mingw32
89         LIBUSB_CONFIG+=--host=x86_64-w64-mingw32 --disable-shared
90         DFU-UTIL_CONFIG+=--host=x86_64-w64-mingw32
91 endif
92 ifeq ($(TARGET),Linux)
93         VPATH += hidapi/linux
94         LDFLAGS += -ludev -lexpat -lusb-1.0
95         BUILD := $(PWD)/build/linux
96         LIBUSB_CONFIG+=--disable-shared
97         LDFLAGS_LIBUSB+= -ludev -lpthread
98 endif
99 ifeq ($(TARGET),Darwin)
100         # Should match OSX
101         VPATH += hidapi/mac
102         LDFLAGS += -framework IOKit -framework CoreFoundation -lexpat
103         CC=clang -mmacosx-version-min=10.7
104         CXX=clang++ -stdlib=libc++ -mmacosx-version-min=10.7
105         WX_CONFIG += --with-macosx-version-min=10.7
106         LIBUSB_CONFIG += --with-macosx-version-min=10.7 --disable-shared
107         LDFLAGS_LIBUSB += -lobjc
108         DFU-UTIL_CONFIG += --with-macosx-version-min=10.7 --disable-shared
109         BUILD := $(PWD)/build/mac
110 all: $(BUILD)/scsi2sd-util6.dmg
111
112 $(BUILD)/scsi2sd-util6.dmg: $(BUILD)/scsi2sd-util6 $(BUILD)/dfu-util/buildstamp
113         mkdir -p $(dir $@)/dmg
114         cp $(BUILD)/scsi2sd-util6 $(BUILD)/dfu-util/src/dfu-util $(dir $@)/dmg
115         chmod a+rx $(dir $@)/dmg/*
116         hdiutil create -volname scsi2sd-util6 -srcfolder $(dir $@)/dmg $@
117 endif
118
119 export CC CXX
120
121 all:  $(BUILD)/scsi2sd-util6$(EXE)
122
123
124 ifneq ($(USE_SYSTEM_HIDAPI),Yes)
125 HIDAPI = \
126         $(BUILD)/hid.o
127 endif
128
129
130 OBJ = \
131         $(HIDAPI) \
132         $(BUILD)/ConfigUtil.o \
133         $(BUILD)/BoardPanel.o \
134         $(BUILD)/TargetPanel.o \
135         $(BUILD)/SCSI2SD_HID.o \
136         $(BUILD)/hidpacket.o \
137         $(BUILD)/Dfu.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
149 EXEOBJ = \
150         $(BUILD)/scsi2sd-util6.o \
151
152
153 ifneq ($(USE_SYSTEM_ZLIB),Yes)
154 $(OBJ): $(BUILD)/zlib/buildstamp
155 $(EXEOBJ): $(BUILD)/zlib/buildstamp
156 $(BUILD)/zlib/buildstamp:
157         mkdir -p $(dir $@)
158         ( \
159                 cd $(dir $@) && \
160                 cp -a $(CURDIR)/zlib-1.2.8/* . && \
161                 ./configure --static && \
162                 $(MAKE) \
163         ) && \
164         touch $@
165 endif
166
167 ifneq ($(USE_SYSTEM_LIBUSB),Yes)
168 $(OBJ): $(BUILD)/libusb/buildstamp
169 $(EXEOBJ): $(BUILD)/libusb/buildstamp
170 $(BUILD)/libusb/buildstamp:
171         mkdir -p $(dir $@)
172         ( \
173                 cd $(dir $@) && \
174                 $(CURDIR)/libusb-1.0.20/configure $(LIBUSB_CONFIG) && \
175                 $(MAKE) \
176         ) && \
177         touch $@
178 else
179 $(BUILD)/libusb/buildstamp:
180         mkdir -p $(dir $@)
181         touch $@
182 endif
183
184 ifneq ($(USE_SYSTEM_WX),Yes)
185 $(OBJ): $(BUILD)/wx/buildstamp
186 $(EXEOBJ): $(BUILD)/wx/buildstamp
187 ifneq ($(USE_SYSTEM_ZLIB),Yes)
188 $(BUILD)/wx/buildstamp: $(BUILD)/zlib/buildstamp
189 else
190 $(BUILD)/wx/buildstamp:
191 endif
192         mkdir -p $(dir $@)
193         ( \
194                 cd $(dir $@) && \
195                 $(CURDIR)/wxWidgets/configure $(WX_CONFIG) CPPFLAGS="$(CPPFLAGS_ZLIB)" LDFLAGS="$(LDFLAGS_ZLIB)" && \
196                 $(MAKE) \
197         ) && \
198         touch $@
199 endif
200
201 ifneq ($(USE_SYSTEM_ZLIB),Yes)
202 LIBZIPPER_STATIC=-enable-static
203 endif
204
205 $(OBJ): $(BUILD)/libzipper/buildstamp
206 $(EXEOBJ): $(BUILD)/libzipper/buildstamp
207 ifneq ($(USE_SYSTEM_ZLIB),Yes)
208 $(BUILD)/libzipper/buildstamp: $(BUILD)/zlib/buildstamp
209 else
210 $(BUILD)/libzipper/buildstamp:
211 endif
212         mkdir -p $(dir $@)
213         ( \
214                 cd $(dir $@) && \
215                 $(CURDIR)/libzipper-1.0.4/configure ${LIBZIPPER_CONFIG} --disable-shared $(LIBZIPPER_STATIC) && \
216                 $(MAKE) libzipper.la \
217         ) && \
218         touch $@
219
220 $(BUILD)/%.o: %.c
221         mkdir -p $(dir $@)
222         $(CC) $(CPPFLAGS) $(CFLAGS) $< -c -o $@
223
224 $(BUILD)/%.o: %.cc
225         mkdir -p $(dir $@)
226 ifneq ($(USE_SYSTEM_WX),Yes)
227         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `$(BUILD)/wx/wx-config --cxxflags` $< -c -o $@
228 else
229         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `wx-config-3.0 --cxxflags` $< -c -o $@
230 endif
231
232 $(BUILD)/%.o: %.cpp
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)/scsi2sd-util6$(EXE): $(OBJ) $(BUILD)/scsi2sd-util.o
241         mkdir -p $(dir $@)
242         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
243
244 all: $(BUILD)/dfu-util/buildstamp
245 $(BUILD)/dfu-util/buildstamp: $(BUILD)/libusb/buildstamp
246         mkdir -p $(dir $@)
247         ( \
248                 cd $(dir $@) && \
249                 $(CURDIR)/dfu-util/configure ${DFU-UTIL_CONFIG} CPPFLAGS="${CPPFLAGS_LIBUSB}" LDFLAGS="${LDFLAGS_LIBUSB} ${LDFLAGS}" && \
250                 $(MAKE) \
251         ) && \
252         touch $@
253
254 clean:
255         rm $(BUILD)/scsi2sd-util6$(EXE) $(OBJ) $(BUILD)/libzipper/buildstamp
256
257 PREFIX=/usr
258 install:
259         install -d $(DESTDIR)/$(PREFIX)/bin
260         install build/linux/scsi2sd-util6 $(DESTDIR)/$(PREFIX)/bin
261
262 dist:
263         rm -fr $(NAME)-$(VERSION)
264         mkdir $(NAME)-$(VERSION)
265         cp -pr ConfigUtil.cc ConfigUtil.hh scsi2sd-util6.spec \
266                ../SCSI2SD/src/hidpacket.c ../../include/hidpacket.h ../../include/scsi2sd.h \
267                libzipper-1.0.4 Makefile \
268                SCSI2SD_Bootloader.cc SCSI2SD_Bootloader.hh SCSI2SD_HID.cc SCSI2SD_HID.hh \
269                scsi2sd-util.cc TargetPanel.cc TargetPanel.hh \
270                BoardPanel.cc BoardPanel.hh \
271                $(NAME)-$(VERSION)
272         tar jcvf $(NAME)-$(VERSION).tar.bz2 $(NAME)-$(VERSION)