33714634469bf40544b841c83ef1c18ad4d31f8a
[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 WX_CONFIG=--disable-webkit --disable-webviewwebkit  \
46         --without-libtiff --without-libjbig --without-liblzma --without-opengl \
47         --enable-monolithic --enable-stl --disable-shared
48
49 TARGET ?= $(shell uname -s)
50 ifeq ($(TARGET),Win32)
51         VPATH += hidapi/windows
52         LDFLAGS += -static -mconsole -mwindows -lsetupapi
53         BUILD := $(PWD)/build/windows/32bit
54         CC=i686-w64-mingw32-gcc
55         CXX=i686-w64-mingw32-g++
56         LIBZIPPER_CONFIG+=--host=i686-w64-mingw32
57         EXE=.exe
58         WX_CONFIG+=--host=i686-w64-mingw32
59 endif
60 ifeq ($(TARGET),Win64)
61         VPATH += hidapi/windows
62         LDFLAGS += -static -mconsole -mwindows -lsetupapi
63         BUILD := $(PWD)/build/windows/64bit
64         CC=x86_64-w64-mingw32-gcc
65         CXX=x86_64-w64-mingw32-g++
66         LIBZIPPER_CONFIG+=--host=x86_64-w64-mingw32
67         EXE=.exe
68         WX_CONFIG+=--host=x86_64-w64-mingw32
69 endif
70 ifeq ($(TARGET),Linux)
71         VPATH += hidapi/linux
72         LDFLAGS += -ludev -lexpat
73         BUILD := $(PWD)/build/linux
74 endif
75 ifeq ($(TARGET),Darwin)
76         # Should match OSX
77         VPATH += hidapi-mac
78         LDFLAGS += -framework IOKit -framework CoreFoundation -lexpat
79         CC=clang -mmacosx-version-min=10.7
80         CXX=clang++ -stdlib=libc++ -mmacosx-version-min=10.7
81         WX_CONFIG += --with-macosx-version-min=10.7
82         BUILD := $(PWD)/build/mac
83 endif
84
85 export CC CXX
86
87 all:  $(BUILD)/scsi2sd-util$(EXE) $(BUILD)/scsi2sd-monitor$(EXE)
88
89 CYAPI = \
90         $(BUILD)/cybtldr_api2.o \
91         $(BUILD)/cybtldr_api.o \
92         $(BUILD)/cybtldr_command.o \
93         $(BUILD)/cybtldr_parse.o \
94
95
96 ifneq ($(USE_SYSTEM_HIDAPI),Yes)
97 HIDAPI = \
98         $(BUILD)/hid.o
99 endif
100
101
102 OBJ = \
103         $(CYAPI) $(HIDAPI) \
104         $(BUILD)/ConfigUtil.o \
105         $(BUILD)/Firmware.o \
106         $(BUILD)/BoardPanel.o \
107         $(BUILD)/TargetPanel.o \
108         $(BUILD)/SCSI2SD_Bootloader.o \
109         $(BUILD)/SCSI2SD_HID.o \
110         $(BUILD)/hidpacket.o \
111
112 EXEOBJ = \
113         $(BUILD)/scsi2sd-util.o \
114         $(BUILD)/scsi2sd-monitor.o \
115
116
117
118 ifneq ($(USE_SYSTEM_ZLIB),Yes)
119 $(OBJ): $(BUILD)/zlib/buildstamp
120 $(EXEOBJ): $(BUILD)/zlib/buildstamp
121 $(BUILD)/zlib/buildstamp:
122         mkdir -p $(dir $@)
123         ( \
124                 cd $(dir $@) && \
125                 cp -a $(CURDIR)/zlib-1.2.8/* . && \
126                 ./configure --static && \
127                 $(MAKE) \
128         ) && \
129         touch $@
130 endif
131
132 ifneq ($(USE_SYSTEM_WX),Yes)
133 $(OBJ): $(BUILD)/wx/buildstamp
134 $(EXEOBJ): $(BUILD)/wx/buildstamp
135 ifneq ($(USE_SYSTEM_ZLIB),Yes)
136 $(BUILD)/wx/buildstamp: $(BUILD)/zlib/buildstamp
137 else
138 $(BUILD)/wx/buildstamp:
139 endif
140         mkdir -p $(dir $@)
141         ( \
142                 cd $(dir $@) && \
143                 $(CURDIR)/wxWidgets/configure $(WX_CONFIG) CPPFLAGS="$(CPPFLAGS_ZLIB)" LDFLAGS="$(LDFLAGS_ZLIB)" && \
144                 $(MAKE) \
145         ) && \
146         touch $@
147 endif
148
149 ifneq ($(USE_SYSTEM_ZLIB),Yes)
150 LIBZIPPER_STATIC=-enable-static
151 endif
152
153 $(OBJ): $(BUILD)/libzipper/buildstamp
154 $(EXEOBJ): $(BUILD)/libzipper/buildstamp
155 ifneq ($(USE_SYSTEM_ZLIB),Yes)
156 $(BUILD)/libzipper/buildstamp: $(BUILD)/zlib/buildstamp
157 else
158 $(BUILD)/libzipper/buildstamp:
159 endif
160         mkdir -p $(dir $@)
161         ( \
162                 cd $(dir $@) && \
163                 $(CURDIR)/libzipper-1.0.4/configure ${LIBZIPPER_CONFIG} --disable-shared $(LIBZIPPER_STATIC) && \
164                 $(MAKE) libzipper.la \
165         ) && \
166         touch $@
167
168 $(BUILD)/%.o: %.c
169         mkdir -p $(dir $@)
170         $(CC) $(CPPFLAGS) $(CFLAGS) $< -c -o $@
171
172 $(BUILD)/%.o: %.cc
173         mkdir -p $(dir $@)
174 ifneq ($(USE_SYSTEM_WX),Yes)
175         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `$(BUILD)/wx/wx-config --cxxflags` $< -c -o $@
176 else
177         $(CXX) $(CPPFLAGS) $(CXXFLAGS) `wx-config-3.0 --cxxflags` $< -c -o $@
178 endif
179
180 $(BUILD)/scsi2sd-util$(EXE): $(OBJ) $(BUILD)/scsi2sd-util.o
181         mkdir -p $(dir $@)
182         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) $(LDFLAGS_WX) -o $@
183
184 $(BUILD)/scsi2sd-monitor$(EXE): $(OBJ) $(BUILD)/scsi2sd-monitor.o
185         mkdir -p $(dir $@)
186         $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) $(LDFLAGS_WX) -o $@
187
188 clean:
189         rm $(BUILD)/scsi2sd-util$(EXE) $(OBJ) $(BUILD)/libzipper/buildstamp
190
191 PREFIX=/usr
192 install:
193         install -d $(DESTDIR)/$(PREFIX)/bin
194         install build/linux/scsi2sd-util $(DESTDIR)/$(PREFIX)/bin
195         install build/linux/scsi2sd-monitor $(DESTDIR)/$(PREFIX)/bin
196
197 dist:
198         rm -fr $(NAME)-$(VERSION)
199         mkdir $(NAME)-$(VERSION)
200         cp -pr build.sh ConfigUtil.cc ConfigUtil.hh scsi2sd-util.spec \
201                ../SCSI2SD/src/hidpacket.c ../include/hidpacket.h ../include/scsi2sd.h \
202                cybootloaderutils Firmware.cc Firmware.hh libzipper-1.0.4 Makefile \
203                SCSI2SD_Bootloader.cc SCSI2SD_Bootloader.hh SCSI2SD_HID.cc SCSI2SD_HID.hh \
204                scsi2sd-monitor.cc scsi2sd-util.cc TargetPanel.cc TargetPanel.hh \
205                BoardPanel.cc BoardPanel.hh \
206                $(NAME)-$(VERSION)
207         tar jcvf $(NAME)-$(VERSION).tar.bz2 $(NAME)-$(VERSION)