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