Fix input of size fieds and CDROM sector length in scsi2sd-util
[SCSI2SD.git] / software / scsi2sd-util / Makefile
1 VPATH=cybootloaderutils ../SCSI2SD/src
2
3 VERSION=4.4.0
4 NAME=scsi2sd-util
5
6 ifeq ($(USE_SYSTEM), Yes)
7 USE_SYSTEM_HIDAPI = Yes
8 USE_SYSTEM_ZLIB = Yes
9 USE_SYSTEM_WX = Yes
10 endif
11
12 ifeq ($(USE_SYSTEM_HIDAPI), Yes)
13 CPPFLAGS_HIDAPI=$(shell pkg-config hidapi-hidraw --cflags)
14 LDFLAGS_HIDAPI=$(shell pkg-config hidapi-hidraw --libs)
15 else
16 CPPFLAGS_HIDAPI=-I hidapi/hidapi
17 LDFLAGS_HIDAPI=
18 endif
19
20 ifeq ($(USE_SYSTEM_ZLIB), Yes)
21 CPPFLAGS_ZLIB=$(shell pkg-config zlib --cflags)
22 LDFLAGS_ZLIB=$(shell pkg-config zlib --libs)
23 LIBZIPPER_CONFIG = --disable-shared LDFLAGS="$(LDFLAGS_ZLIB)" CPPFLAGS="$(CPPFLAGS_ZLIB)"
24 else
25 CPPFLAGS_ZLIB=-I$(BUILD)/zlib
26 LDFLAGS_ZLIB=-L$(BUILD)/zlib -lz
27 LIBZIPPER_CONFIG = --disable-shared LDFLAGS="-L../zlib" CPPFLAGS="-I../zlib"
28 endif
29
30 ifeq ($(USE_SYSTEM_WX),Yes)
31 LDFLAGS_WX=$(shell wx-config-3.0 --libs)
32 else
33 LDFLAGS_WX=$(shell $(BUILD)/wx/wx-config --libs)
34 endif
35
36 CPPFLAGS = -I cybootloaderutils $(CPPFLAGS_HIDAPI) -I. -I ../include -Ilibzipper-1.0.4 $(CPPFLAGS_ZLIB)
37 CFLAGS += -Wall -Wno-pointer-sign -O2 -g
38 CXXFLAGS += -Wall -O2 -g -std=c++0x
39
40 LDFLAGS += -L$(BUILD)/libzipper/.libs -lzipper $(LDFLAGS_ZLIB) $(LDFLAGS_HIDAPI)
41
42
43 # wxWidgets 3.0.2 uses broken Webkit headers under OSX Yosemeti
44 # liblzma not available on OSX 10.7
45 # --disable-mediactrl for missing Quicktime.h on Mac OSX Sierra
46 WX_CONFIG=--disable-webkit --disable-webviewwebkit  --disable-mediactrl \
47         --without-libtiff --without-libjbig --without-liblzma --without-opengl \
48         --enable-monolithic --enable-stl --disable-shared
49
50 TARGET ?= $(shell uname -s)
51 ifeq ($(TARGET),Win32)
52         VPATH += hidapi/windows
53         LDFLAGS += -static -mconsole -mwindows -lsetupapi
54         BUILD := $(PWD)/build/windows/32bit
55         CC=i686-w64-mingw32-gcc
56         CXX=i686-w64-mingw32-g++
57         LIBZIPPER_CONFIG+=--host=i686-w64-mingw32
58         EXE=.exe
59         WX_CONFIG+=--host=i686-w64-mingw32
60 endif
61 ifeq ($(TARGET),Win64)
62         VPATH += hidapi-windows
63         LDFLAGS += -static -mconsole -mwindows -lsetupapi
64         BUILD := $(PWD)/build/windows/64bit
65         CC=x86_64-w64-mingw32-gcc
66         CXX=x86_64-w64-mingw32-g++
67         LIBZIPPER_CONFIG+=--host=x86_64-w64-mingw32
68         EXE=.exe
69         WX_CONFIG+=--host=x86_64-w64-mingw32
70 endif
71 ifeq ($(TARGET),Linux)
72         VPATH += hidapi/linux
73         LDFLAGS += -ludev -lexpat
74         BUILD := $(PWD)/build/linux
75 endif
76 ifeq ($(TARGET),Darwin)
77         # Should match OSX
78         VPATH += hidapi-mac
79         LDFLAGS += -framework IOKit -framework CoreFoundation -lexpat
80         CC=clang -mmacosx-version-min=10.7
81         CXX=clang++ -stdlib=libc++ -mmacosx-version-min=10.7
82         WX_CONFIG += --with-macosx-version-min=10.7
83         BUILD := $(PWD)/build/mac
84 all: $(BUILD)/scsi2sd-util.dmg
85
86 $(BUILD)/scsi2sd-util.dmg: $(BUILD)/scsi2sd-util $(BUILD)/scsi2sd-monitor
87         rm -rf $(dir $@)/dmg $@
88         mkdir -p $(dir $@)/dmg
89         cp $(BUILD)/scsi2sd-util $(BUILD)/scsi2sd-monitor $(dir $@)/dmg
90         chmod a+rx $(dir $@)/dmg/*
91         hdiutil create -srcfolder $(dir $@)/dmg $@
92 endif
93
94 export CC CXX
95
96 all:  $(BUILD)/scsi2sd-util$(EXE) $(BUILD)/scsi2sd-monitor$(EXE) $(BUILD)/scsi2sd-bulk$(EXE)
97
98 CYAPI = \
99         $(BUILD)/cybtldr_api2.o \
100         $(BUILD)/cybtldr_api.o \
101         $(BUILD)/cybtldr_command.o \
102         $(BUILD)/cybtldr_parse.o \
103
104
105 ifneq ($(USE_SYSTEM_HIDAPI),Yes)
106 HIDAPI = \
107         $(BUILD)/hid.o
108 endif
109
110
111 CONSOLEOBJ = \
112         $(CYAPI) $(HIDAPI) \
113         $(BUILD)/Firmware.o \
114         $(BUILD)/SCSI2SD_Bootloader.o \
115         $(BUILD)/SCSI2SD_HID.o \
116         $(BUILD)/hidpacket.o \
117
118 OBJ = \
119         ${CONSOLEOBJ} \
120         $(BUILD)/ConfigUtil.o \
121         $(BUILD)/BoardPanel.o \
122         $(BUILD)/TargetPanel.o \
123         $(BUILD)/hidpacket.o \
124
125 EXEOBJ = \
126         $(BUILD)/scsi2sd-util.o \
127         $(BUILD)/scsi2sd-monitor.o \
128
129
130
131 ifneq ($(USE_SYSTEM_ZLIB),Yes)
132 $(OBJ): $(BUILD)/zlib/buildstamp
133 $(EXEOBJ): $(BUILD)/zlib/buildstamp
134 $(BUILD)/zlib/buildstamp:
135         mkdir -p $(dir $@)
136         ( \
137                 cd $(dir $@) && \
138                 cp -a $(CURDIR)/zlib-1.2.8/* . && \
139                 ./configure --static && \
140                 $(MAKE) \
141         ) && \
142         touch $@
143 endif
144
145 ifneq ($(USE_SYSTEM_WX),Yes)
146 $(OBJ): $(BUILD)/wx/buildstamp
147 $(EXEOBJ): $(BUILD)/wx/buildstamp
148 ifneq ($(USE_SYSTEM_ZLIB),Yes)
149 $(BUILD)/wx/buildstamp: $(BUILD)/zlib/buildstamp
150 else
151 $(BUILD)/wx/buildstamp:
152 endif
153         mkdir -p $(dir $@)
154         ( \
155                 cd $(dir $@) && \
156                 $(CURDIR)/wxWidgets/configure $(WX_CONFIG) CPPFLAGS="$(CPPFLAGS_ZLIB)" LDFLAGS="$(LDFLAGS_ZLIB)" && \
157                 $(MAKE) \
158         ) && \
159         touch $@
160 endif
161
162 ifneq ($(USE_SYSTEM_ZLIB),Yes)
163 LIBZIPPER_STATIC=-enable-static
164 endif
165
166 $(OBJ): $(BUILD)/libzipper/buildstamp
167 $(EXEOBJ): $(BUILD)/libzipper/buildstamp
168 ifneq ($(USE_SYSTEM_ZLIB),Yes)
169 $(BUILD)/libzipper/buildstamp: $(BUILD)/zlib/buildstamp
170 else
171 $(BUILD)/libzipper/buildstamp:
172 endif
173         mkdir -p $(dir $@)
174         ( \
175                 cd $(dir $@) && \
176                 $(CURDIR)/libzipper-1.0.4/configure ${LIBZIPPER_CONFIG} --disable-shared $(LIBZIPPER_STATIC) && \
177                 $(MAKE) libzipper.la \
178         ) && \
179         touch $@
180
181 $(BUILD)/%.o: %.c
182         mkdir -p $(dir $@)
183         $(CC) $(CPPFLAGS) $(CFLAGS) $< -c -o $@
184
185 $(BUILD)/%.o: %.cc
186         mkdir -p $(dir $@)
187 ifneq ($(USE_SYSTEM_WX),Yes)
188         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `$(BUILD)/wx/wx-config --cxxflags` $< -c -o $@
189 else
190         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `wx-config-3.0 --cxxflags` $< -c -o $@
191 endif
192
193 $(BUILD)/scsi2sd-util$(EXE): $(OBJ) $(BUILD)/scsi2sd-util.o
194         mkdir -p $(dir $@)
195         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
196
197 $(BUILD)/scsi2sd-monitor$(EXE): $(OBJ) $(BUILD)/scsi2sd-monitor.o
198         mkdir -p $(dir $@)
199         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
200
201 $(BUILD)/scsi2sd-bulk$(EXE): $(CONSOLEOBJ) $(BUILD)/scsi2sd-bulk.o
202         mkdir -p $(dir $@)
203         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@
204
205 clean:
206         rm $(BUILD)/scsi2sd-util$(EXE) $(OBJ) $(BUILD)/libzipper/buildstamp
207
208 PREFIX=/usr
209 install:
210         install -d $(DESTDIR)/$(PREFIX)/bin
211         install build/linux/scsi2sd-util $(DESTDIR)/$(PREFIX)/bin
212         install build/linux/scsi2sd-monitor $(DESTDIR)/$(PREFIX)/bin
213
214 dist:
215         rm -fr $(NAME)-$(VERSION)
216         mkdir $(NAME)-$(VERSION)
217         cp -pr build.sh ConfigUtil.cc ConfigUtil.hh scsi2sd-util.spec \
218                ../SCSI2SD/src/hidpacket.c ../include/hidpacket.h ../include/scsi2sd.h \
219                cybootloaderutils Firmware.cc Firmware.hh libzipper-1.0.4 Makefile \
220                SCSI2SD_Bootloader.cc SCSI2SD_Bootloader.hh SCSI2SD_HID.cc SCSI2SD_HID.hh \
221                scsi2sd-monitor.cc scsi2sd-util.cc TargetPanel.cc TargetPanel.hh \
222                BoardPanel.cc BoardPanel.hh \
223                $(NAME)-$(VERSION)
224         tar jcvf $(NAME)-$(VERSION).tar.bz2 $(NAME)-$(VERSION)