V4.7 release fixes
[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         mkdir -p $(dir $@)/dmg
88         cp $(BUILD)/scsi2sd-util $(BUILD)/scsi2sd-monitor $(dir $@)/dmg
89         chmod a+rx $(dir $@)/dmg/*
90         hdiutil create -srcfolder $(dir $@)/dmg $@
91 endif
92
93 export CC CXX
94
95 all:  $(BUILD)/scsi2sd-util$(EXE) $(BUILD)/scsi2sd-monitor$(EXE)
96
97 CYAPI = \
98         $(BUILD)/cybtldr_api2.o \
99         $(BUILD)/cybtldr_api.o \
100         $(BUILD)/cybtldr_command.o \
101         $(BUILD)/cybtldr_parse.o \
102
103
104 ifneq ($(USE_SYSTEM_HIDAPI),Yes)
105 HIDAPI = \
106         $(BUILD)/hid.o
107 endif
108
109
110 OBJ = \
111         $(CYAPI) $(HIDAPI) \
112         $(BUILD)/ConfigUtil.o \
113         $(BUILD)/Firmware.o \
114         $(BUILD)/BoardPanel.o \
115         $(BUILD)/TargetPanel.o \
116         $(BUILD)/SCSI2SD_Bootloader.o \
117         $(BUILD)/SCSI2SD_HID.o \
118         $(BUILD)/hidpacket.o \
119
120 EXEOBJ = \
121         $(BUILD)/scsi2sd-util.o \
122         $(BUILD)/scsi2sd-monitor.o \
123
124
125
126 ifneq ($(USE_SYSTEM_ZLIB),Yes)
127 $(OBJ): $(BUILD)/zlib/buildstamp
128 $(EXEOBJ): $(BUILD)/zlib/buildstamp
129 $(BUILD)/zlib/buildstamp:
130         mkdir -p $(dir $@)
131         ( \
132                 cd $(dir $@) && \
133                 cp -a $(CURDIR)/zlib-1.2.8/* . && \
134                 ./configure --static && \
135                 $(MAKE) \
136         ) && \
137         touch $@
138 endif
139
140 ifneq ($(USE_SYSTEM_WX),Yes)
141 $(OBJ): $(BUILD)/wx/buildstamp
142 $(EXEOBJ): $(BUILD)/wx/buildstamp
143 ifneq ($(USE_SYSTEM_ZLIB),Yes)
144 $(BUILD)/wx/buildstamp: $(BUILD)/zlib/buildstamp
145 else
146 $(BUILD)/wx/buildstamp:
147 endif
148         mkdir -p $(dir $@)
149         ( \
150                 cd $(dir $@) && \
151                 $(CURDIR)/wxWidgets/configure $(WX_CONFIG) CPPFLAGS="$(CPPFLAGS_ZLIB)" LDFLAGS="$(LDFLAGS_ZLIB)" && \
152                 $(MAKE) \
153         ) && \
154         touch $@
155 endif
156
157 ifneq ($(USE_SYSTEM_ZLIB),Yes)
158 LIBZIPPER_STATIC=-enable-static
159 endif
160
161 $(OBJ): $(BUILD)/libzipper/buildstamp
162 $(EXEOBJ): $(BUILD)/libzipper/buildstamp
163 ifneq ($(USE_SYSTEM_ZLIB),Yes)
164 $(BUILD)/libzipper/buildstamp: $(BUILD)/zlib/buildstamp
165 else
166 $(BUILD)/libzipper/buildstamp:
167 endif
168         mkdir -p $(dir $@)
169         ( \
170                 cd $(dir $@) && \
171                 $(CURDIR)/libzipper-1.0.4/configure ${LIBZIPPER_CONFIG} --disable-shared $(LIBZIPPER_STATIC) && \
172                 $(MAKE) libzipper.la \
173         ) && \
174         touch $@
175
176 $(BUILD)/%.o: %.c
177         mkdir -p $(dir $@)
178         $(CC) $(CPPFLAGS) $(CFLAGS) $< -c -o $@
179
180 $(BUILD)/%.o: %.cc
181         mkdir -p $(dir $@)
182 ifneq ($(USE_SYSTEM_WX),Yes)
183         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `$(BUILD)/wx/wx-config --cxxflags` $< -c -o $@
184 else
185         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `wx-config-3.0 --cxxflags` $< -c -o $@
186 endif
187
188 $(BUILD)/scsi2sd-util$(EXE): $(OBJ) $(BUILD)/scsi2sd-util.o
189         mkdir -p $(dir $@)
190         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
191
192 $(BUILD)/scsi2sd-monitor$(EXE): $(OBJ) $(BUILD)/scsi2sd-monitor.o
193         mkdir -p $(dir $@)
194         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
195
196 clean:
197         rm $(BUILD)/scsi2sd-util$(EXE) $(OBJ) $(BUILD)/libzipper/buildstamp
198
199 PREFIX=/usr
200 install:
201         install -d $(DESTDIR)/$(PREFIX)/bin
202         install build/linux/scsi2sd-util $(DESTDIR)/$(PREFIX)/bin
203         install build/linux/scsi2sd-monitor $(DESTDIR)/$(PREFIX)/bin
204
205 dist:
206         rm -fr $(NAME)-$(VERSION)
207         mkdir $(NAME)-$(VERSION)
208         cp -pr build.sh ConfigUtil.cc ConfigUtil.hh scsi2sd-util.spec \
209                ../SCSI2SD/src/hidpacket.c ../include/hidpacket.h ../include/scsi2sd.h \
210                cybootloaderutils Firmware.cc Firmware.hh libzipper-1.0.4 Makefile \
211                SCSI2SD_Bootloader.cc SCSI2SD_Bootloader.hh SCSI2SD_HID.cc SCSI2SD_HID.hh \
212                scsi2sd-monitor.cc scsi2sd-util.cc TargetPanel.cc TargetPanel.hh \
213                BoardPanel.cc BoardPanel.hh \
214                $(NAME)-$(VERSION)
215         tar jcvf $(NAME)-$(VERSION).tar.bz2 $(NAME)-$(VERSION)