Fix BlueSky build on modern Linux and libs3.
[bluesky.git] / libs3-1.4 / GNUmakefile.osx
1 # GNUmakefile
2
3 # Copyright 2008 Bryan Ischo <bryan@ischo.com>
4
5 # This file is part of libs3.
6
7 # libs3 is free software: you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation, version 3 of the License.
10 #
11 # In addition, as a special exception, the copyright holders give
12 # permission to link the code of this library and its programs with the
13 # OpenSSL library, and distribute linked combinations including the two.
14 #
15 # libs3 is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18 # details.
19 #
20 # You should have received a copy of the GNU General Public License version 3
21 # along with libs3, in a file named COPYING.  If not, see
22 # <http://www.gnu.org/licenses/>.
23
24 # I tried to use the autoconf/automake/autolocal/etc (i.e. autohell) tools
25 # but I just couldn't stomach them.  Since this is a Makefile for POSIX
26 # systems, I will simply do away with autohell completely and use a GNU
27 # Makefile.  GNU make ought to be available pretty much everywhere, so I
28 # don't see this being a significant issue for portability.
29
30 # All commands assume a GNU compiler.  For systems which do not use a GNU
31 # compiler, write scripts with the same names as these commands, and taking
32 # the same arguments, and translate the arguments and commands into the
33 # appropriate non-POSIX ones as needed.  libs3 assumes a GNU toolchain as
34 # the most portable way to build software possible.  Non-POSIX, non-GNU
35 # systems can do the work of supporting this build infrastructure.
36
37
38 # --------------------------------------------------------------------------
39 # Set libs3 version number
40
41 LIBS3_VER_MAJOR := 1
42 LIBS3_VER_MINOR := 4
43 LIBS3_VER := $(LIBS3_VER_MAJOR).$(LIBS3_VER_MINOR)
44
45
46 # --------------------------------------------------------------------------
47 # BUILD directory
48 ifndef BUILD
49     BUILD := build
50 endif
51
52
53 # --------------------------------------------------------------------------
54 # DESTDIR directory
55 ifndef DESTDIR
56     DESTDIR := /usr
57 endif
58
59
60 # --------------------------------------------------------------------------
61 # Acquire configuration information for libraries that libs3 depends upon
62
63 ifndef CURL_LIBS
64     CURL_LIBS := $(shell curl-config --libs)
65 endif
66
67 ifndef CURL_CFLAGS
68     CURL_CFLAGS := $(shell curl-config --cflags)
69 endif
70
71 ifndef LIBXML2_LIBS
72     LIBXML2_LIBS := $(shell xml2-config --libs)
73 endif
74
75 ifndef LIBXML2_CFLAGS
76     LIBXML2_CFLAGS := $(shell xml2-config --cflags)
77 endif
78
79
80 # --------------------------------------------------------------------------
81 # These CFLAGS assume a GNU compiler.  For other compilers, write a script
82 # which converts these arguments into their equivalent for that particular
83 # compiler.
84
85 ifndef CFLAGS
86     CFLAGS = -O3
87 endif
88
89 CFLAGS += -Wall -Werror -Wshadow -Wextra -Iinc \
90           $(CURL_CFLAGS) $(LIBXML2_CFLAGS) \
91           -DLIBS3_VER_MAJOR=\"$(LIBS3_VER_MAJOR)\" \
92           -DLIBS3_VER_MINOR=\"$(LIBS3_VER_MINOR)\" \
93           -DLIBS3_VER=\"$(LIBS3_VER)\" \
94           -D__STRICT_ANSI__ \
95           -D_ISOC99_SOURCE \
96           -fno-common
97
98 LDFLAGS = $(CURL_LIBS) $(LIBXML2_LIBS) -lpthread
99
100
101 # --------------------------------------------------------------------------
102 # Default targets are everything
103
104 .PHONY: all
105 all: exported test
106
107
108 # --------------------------------------------------------------------------
109 # Exported targets are the library and driver program
110
111 .PHONY: exported
112 exported: libs3 s3 headers
113
114
115 # --------------------------------------------------------------------------
116 # Install target
117
118 .PHONY: install
119 install: exported
120         install -ps -m u+rwx,go+rx $(BUILD)/bin/s3 $(DESTDIR)/bin/s3
121         install -p -m u+rw,go+r $(BUILD)/include/libs3.h \
122                $(DESTDIR)/include/libs3.h
123         install -p -m u+rw,go+r $(BUILD)/lib/libs3.a $(DESTDIR)/lib/libs3.a
124         install -p -m u+rw,go+r $(BUILD)/lib/libs3.$(LIBS3_VER_MAJOR).dylib \
125                $(DESTDIR)/lib/libs3.$(LIBS3_VER).dylib
126         ln -sf libs3.$(LIBS3_VER).dylib \
127                $(DESTDIR)/lib/libs3.$(LIBS3_VER_MAJOR).dylib
128         ln -sf libs3.$(LIBS3_VER_MAJOR).dylib $(DESTDIR)/lib/libs3.dylib
129
130
131 # --------------------------------------------------------------------------
132 # Uninstall target
133
134 .PHONY: uninstall
135 uninstall:
136         rm -f $(DESTDIR)/bin/s3 \
137               $(DESTDIR)/include/libs3.h \
138               $(DESTDIR)/lib/libs3.a \
139               $(DESTDIR)/lib/libs3.dylib \
140               $(DESTDIR)/lib/libs3.$(LIBS3_VER_MAJOR).dylib \
141               $(DESTDIR)/lib/libs3.$(LIBS3_VER).dylib \
142
143
144 # --------------------------------------------------------------------------
145 # Debian package target
146
147 DEBPKG = $(BUILD)/pkg/libs3_$(LIBS3_VER).deb
148 DEBDEVPKG = $(BUILD)/pkg/libs3-dev_$(LIBS3_VER).deb
149
150 .PHONY: deb
151 deb: $(DEBPKG) $(DEBDEVPKG)
152
153 $(DEBPKG): DEBARCH = $(shell dpkg-architecture | grep ^DEB_BUILD_ARCH= | \
154                        cut -d '=' -f 2)
155 $(DEBPKG): exported $(BUILD)/deb/DEBIAN/control $(BUILD)/deb/DEBIAN/shlibs \
156            $(BUILD)/deb/DEBIAN/postinst \
157            $(BUILD)/deb/usr/share/doc/libs3/changelog.gz \
158            $(BUILD)/deb/usr/share/doc/libs3/changelog.Debian.gz \
159            $(BUILD)/deb/usr/share/doc/libs3/copyright
160         DESTDIR=$(BUILD)/deb/usr $(MAKE) install
161         rm -rf $(BUILD)/deb/usr/include
162         rm -f $(BUILD)/deb/usr/lib/libs3.a
163         @mkdir -p $(dir $@)
164         fakeroot dpkg-deb -b $(BUILD)/deb $@
165         mv $@ $(BUILD)/pkg/libs3_$(LIBS3_VER)_$(DEBARCH).deb
166
167 $(DEBDEVPKG): DEBARCH = $(shell dpkg-architecture | grep ^DEB_BUILD_ARCH= | \
168                           cut -d '=' -f 2)
169 $(DEBDEVPKG): exported $(BUILD)/deb-dev/DEBIAN/control \
170            $(BUILD)/deb-dev/usr/share/doc/libs3-dev/changelog.gz \
171            $(BUILD)/deb-dev/usr/share/doc/libs3-dev/changelog.Debian.gz \
172            $(BUILD)/deb-dev/usr/share/doc/libs3-dev/copyright
173         DESTDIR=$(BUILD)/deb-dev/usr $(MAKE) install
174         rm -rf $(BUILD)/deb-dev/usr/bin
175         rm -f $(BUILD)/deb-dev/usr/lib/libs3*.dylib
176         @mkdir -p $(dir $@)
177         fakeroot dpkg-deb -b $(BUILD)/deb-dev $@
178         mv $@ $(BUILD)/pkg/libs3-dev_$(LIBS3_VER)_$(DEBARCH).deb
179
180 $(BUILD)/deb/DEBIAN/control: debian/control
181         @mkdir -p $(dir $@)
182         echo -n "Depends: " > $@
183         dpkg-shlibdeps -O $(BUILD)/lib/libs3.$(LIBS3_VER_MAJOR).dylib | \
184             cut -d '=' -f 2- >> $@
185         sed -e 's/LIBS3_VERSION/$(LIBS3_VER)/' \
186             < $< | sed -e 's/DEBIAN_ARCHITECTURE/$(DEBARCH)/' | \
187             grep -v ^Source: >> $@
188
189 $(BUILD)/deb-dev/DEBIAN/control: debian/control.dev
190         @mkdir -p $(dir $@)
191         sed -e 's/LIBS3_VERSION/$(LIBS3_VER)/' \
192             < $< | sed -e 's/DEBIAN_ARCHITECTURE/$(DEBARCH)/' > $@
193
194 $(BUILD)/deb/DEBIAN/shlibs:
195         echo -n "libs3 $(LIBS3_VER_MAJOR) libs3 " > $@
196         echo "(>= $(LIBS3_VER))" >> $@
197
198 $(BUILD)/deb/DEBIAN/postinst: debian/postinst
199         @mkdir -p $(dir $@)
200         cp $< $@
201
202 $(BUILD)/deb/usr/share/doc/libs3/copyright: LICENSE
203         @mkdir -p $(dir $@)
204         cp $< $@
205         @echo >> $@
206         @echo -n "An alternate location for the GNU General Public " >> $@
207         @echo "License version 3 on Debian" >> $@
208         @echo "systems is /usr/share/common-licenses/GPL-3." >> $@
209
210 $(BUILD)/deb-dev/usr/share/doc/libs3-dev/copyright: LICENSE
211         @mkdir -p $(dir $@)
212         cp $< $@
213         @echo >> $@
214         @echo -n "An alternate location for the GNU General Public " >> $@
215         @echo "License version 3 on Debian" >> $@
216         @echo "systems is /usr/share/common-licenses/GPL-3." >> $@
217
218 $(BUILD)/deb/usr/share/doc/libs3/changelog.gz: debian/changelog
219         @mkdir -p $(dir $@)
220         gzip --best -c $< > $@
221
222 $(BUILD)/deb-dev/usr/share/doc/libs3-dev/changelog.gz: debian/changelog
223         @mkdir -p $(dir $@)
224         gzip --best -c $< > $@
225
226 $(BUILD)/deb/usr/share/doc/libs3/changelog.Debian.gz: debian/changelog.Debian
227         @mkdir -p $(dir $@)
228         gzip --best -c $< > $@
229
230 $(BUILD)/deb-dev/usr/share/doc/libs3-dev/changelog.Debian.gz: \
231     debian/changelog.Debian
232         @mkdir -p $(dir $@)
233         gzip --best -c $< > $@
234
235
236 # --------------------------------------------------------------------------
237 # Compile target patterns
238
239 $(BUILD)/obj/%.o: src/%.c
240         @mkdir -p $(dir $@)
241         gcc $(CFLAGS) -o $@ -c $<
242
243 $(BUILD)/obj/%.do: src/%.c
244         @mkdir -p $(dir $@)
245         gcc $(CFLAGS) -fpic -fPIC -o $@ -c $< 
246
247
248 # --------------------------------------------------------------------------
249 # libs3 library targets
250
251 LIBS3_SHARED = $(BUILD)/lib/libs3.$(LIBS3_VER_MAJOR).dylib
252
253 .PHONY: libs3
254 libs3: $(LIBS3_SHARED) $(LIBS3_SHARED_MAJOR) $(BUILD)/lib/libs3.a
255
256 LIBS3_SOURCES := src/acl.c src/bucket.c src/error_parser.c src/general.c \
257                  src/object.c src/request.c src/request_context.c \
258                  src/response_headers_handler.c src/service_access_logging.c \
259                  src/service.c src/simplexml.c src/util.c
260
261 $(LIBS3_SHARED): $(LIBS3_SOURCES:src/%.c=$(BUILD)/obj/%.do)
262         @mkdir -p $(dir $@)
263         gcc -dynamiclib -install_name libs3.$(LIBS3_VER_MAJOR).dylib \
264         -compatibility_version $(LIBS3_VER_MAJOR) \
265         -current_version $(LIBS3_VER) -o $@ $^ $(LDFLAGS)
266
267 $(BUILD)/lib/libs3.a: $(LIBS3_SOURCES:src/%.c=$(BUILD)/obj/%.o)
268         @mkdir -p $(dir $@)
269         $(AR) cr $@ $^
270
271
272 # --------------------------------------------------------------------------
273 # Driver program targets
274
275 .PHONY: s3
276 s3: $(BUILD)/bin/s3
277
278 $(BUILD)/bin/s3: $(BUILD)/obj/s3.o $(LIBS3_SHARED)
279         @mkdir -p $(dir $@)
280         gcc -o $@ $^ $(LDFLAGS)
281
282
283 # --------------------------------------------------------------------------
284 # libs3 header targets
285
286 .PHONY: headers
287 headers: $(BUILD)/include/libs3.h
288
289 $(BUILD)/include/libs3.h: inc/libs3.h
290         @mkdir -p $(dir $@)
291         cp $< $@
292
293
294 # --------------------------------------------------------------------------
295 # Test targets
296
297 .PHONY: test
298 test: $(BUILD)/bin/testsimplexml
299
300 $(BUILD)/bin/testsimplexml: $(BUILD)/obj/testsimplexml.o $(BUILD)/lib/libs3.a
301         @mkdir -p $(dir $@)
302         gcc -o $@ $^ $(LIBXML2_LIBS)
303
304
305 # --------------------------------------------------------------------------
306 # Clean target
307
308 .PHONY: clean
309 clean:
310         rm -rf $(BUILD)