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