Fixed SCSI issues. It should now be stable on all systems.
[SCSI2SD-V6.git] / src / scsi2sd-util6 / Makefile
1 VPATH=../firmware dfu-programmer/src
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 libusb-1.0.9/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 -Idfu-programmer/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 endif
79 ifeq ($(TARGET),Win64)
80         VPATH += hidapi/windows
81         LDFLAGS += -static -mconsole -mwindows -lsetupapi
82         BUILD := $(PWD)/build/windows/64bit
83         CC=x86_64-w64-mingw32-gcc
84         CXX=x86_64-w64-mingw32-g++
85         LIBZIPPER_CONFIG+=--host=x86_64-w64-mingw32
86         EXE=.exe
87         WX_CONFIG+=--host=x86_64-w64-mingw32
88         LIBUSB_CONFIG+=--host=x86_64-w64-mingw32 --disable-shared
89 endif
90 ifeq ($(TARGET),Linux)
91         VPATH += hidapi/linux
92         LDFLAGS += -ludev -lexpat -lusb-1.0
93         BUILD := $(PWD)/build/linux
94         LIBUSB_CONFIG+=--disable-shared
95 endif
96 ifeq ($(TARGET),Darwin)
97         # Should match OSX
98         VPATH += hidapi/mac
99         LDFLAGS += -framework IOKit -framework CoreFoundation -lexpat
100         CC=clang -mmacosx-version-min=10.7
101         CXX=clang++ -stdlib=libc++ -mmacosx-version-min=10.7
102         WX_CONFIG += --with-macosx-version-min=10.7
103         LIBUSB_CONFIG += --with-macosx-version-min=10.7 --disable-shared
104         BUILD := $(PWD)/build/mac
105 all: $(BUILD)/scsi2sd-util6.dmg
106
107 $(BUILD)/scsi2sd-util6.dmg: $(BUILD)/scsi2sd-util6
108         mkdir -p $(dir $@)/dmg
109         cp $(BUILD)/scsi2sd-util6 $(dir $@)/dmg
110         chmod a+rx $(dir $@)/dmg/*
111         hdiutil create -srcfolder $(dir $@)/dmg $@
112 endif
113
114 export CC CXX
115
116 all:  $(BUILD)/scsi2sd-util6$(EXE)
117
118
119 ifneq ($(USE_SYSTEM_HIDAPI),Yes)
120 HIDAPI = \
121         $(BUILD)/hid.o
122 endif
123
124
125 OBJ = \
126         $(HIDAPI) \
127         $(BUILD)/ConfigUtil.o \
128         $(BUILD)/BoardPanel.o \
129         $(BUILD)/TargetPanel.o \
130         $(BUILD)/SCSI2SD_HID.o \
131         $(BUILD)/hidpacket.o \
132
133 #       $(BUILD)/Dfu.o \
134 #       $(BUILD)/dfu.o \
135
136
137 EXEOBJ = \
138         $(BUILD)/scsi2sd-util6.o \
139
140
141 ifneq ($(USE_SYSTEM_ZLIB),Yes)
142 $(OBJ): $(BUILD)/zlib/buildstamp
143 $(EXEOBJ): $(BUILD)/zlib/buildstamp
144 $(BUILD)/zlib/buildstamp:
145         mkdir -p $(dir $@)
146         ( \
147                 cd $(dir $@) && \
148                 cp -a $(CURDIR)/zlib-1.2.8/* . && \
149                 ./configure --static && \
150                 $(MAKE) \
151         ) && \
152         touch $@
153 endif
154
155 ifneq ($(USE_SYSTEM_LIBUSB),Yes)
156 $(OBJ): $(BUILD)/libusb/buildstamp
157 $(EXEOBJ): $(BUILD)/libusb/buildstamp
158 $(BUILD)/libusb/buildstamp:
159         mkdir -p $(dir $@)
160         ( \
161                 cd $(dir $@) && \
162                 $(CURDIR)/libusb-1.0.9/configure $(LIBUSB_CONFIG) && \
163                 $(MAKE) \
164         ) && \
165         touch $@
166 endif
167
168 ifneq ($(USE_SYSTEM_WX),Yes)
169 $(OBJ): $(BUILD)/wx/buildstamp
170 $(EXEOBJ): $(BUILD)/wx/buildstamp
171 ifneq ($(USE_SYSTEM_ZLIB),Yes)
172 $(BUILD)/wx/buildstamp: $(BUILD)/zlib/buildstamp
173 else
174 $(BUILD)/wx/buildstamp:
175 endif
176         mkdir -p $(dir $@)
177         ( \
178                 cd $(dir $@) && \
179                 $(CURDIR)/wxWidgets/configure $(WX_CONFIG) CPPFLAGS="$(CPPFLAGS_ZLIB)" LDFLAGS="$(LDFLAGS_ZLIB)" && \
180                 $(MAKE) \
181         ) && \
182         touch $@
183 endif
184
185 ifneq ($(USE_SYSTEM_ZLIB),Yes)
186 LIBZIPPER_STATIC=-enable-static
187 endif
188
189 $(OBJ): $(BUILD)/libzipper/buildstamp
190 $(EXEOBJ): $(BUILD)/libzipper/buildstamp
191 ifneq ($(USE_SYSTEM_ZLIB),Yes)
192 $(BUILD)/libzipper/buildstamp: $(BUILD)/zlib/buildstamp
193 else
194 $(BUILD)/libzipper/buildstamp:
195 endif
196         mkdir -p $(dir $@)
197         ( \
198                 cd $(dir $@) && \
199                 $(CURDIR)/libzipper-1.0.4/configure ${LIBZIPPER_CONFIG} --disable-shared $(LIBZIPPER_STATIC) && \
200                 $(MAKE) libzipper.la \
201         ) && \
202         touch $@
203
204 $(BUILD)/%.o: %.c
205         mkdir -p $(dir $@)
206         $(CC) $(CPPFLAGS) $(CFLAGS) $< -c -o $@
207
208 $(BUILD)/%.o: %.cc
209         mkdir -p $(dir $@)
210 ifneq ($(USE_SYSTEM_WX),Yes)
211         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `$(BUILD)/wx/wx-config --cxxflags` $< -c -o $@
212 else
213         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `wx-config-3.0 --cxxflags` $< -c -o $@
214 endif
215
216 $(BUILD)/scsi2sd-util6$(EXE): $(OBJ) $(BUILD)/scsi2sd-util.o
217         mkdir -p $(dir $@)
218         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
219
220 clean:
221         rm $(BUILD)/scsi2sd-util6$(EXE) $(OBJ) $(BUILD)/libzipper/buildstamp
222
223 PREFIX=/usr
224 install:
225         install -d $(DESTDIR)/$(PREFIX)/bin
226         install build/linux/scsi2sd-util6 $(DESTDIR)/$(PREFIX)/bin
227
228 dist:
229         rm -fr $(NAME)-$(VERSION)
230         mkdir $(NAME)-$(VERSION)
231         cp -pr ConfigUtil.cc ConfigUtil.hh scsi2sd-util6.spec \
232                ../SCSI2SD/src/hidpacket.c ../../include/hidpacket.h ../../include/scsi2sd.h \
233                libzipper-1.0.4 Makefile \
234                SCSI2SD_Bootloader.cc SCSI2SD_Bootloader.hh SCSI2SD_HID.cc SCSI2SD_HID.hh \
235                scsi2sd-util.cc TargetPanel.cc TargetPanel.hh \
236                BoardPanel.cc BoardPanel.hh \
237                $(NAME)-$(VERSION)
238         tar jcvf $(NAME)-$(VERSION).tar.bz2 $(NAME)-$(VERSION)