eb16954963cf87a3c84c37e625095a3e4ef28e4c
[bluesky.git] / libs3-1.4 / GNUmakefile
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           -D_POSIX_C_SOURCE=200112L
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 -Dps -m u+rwx,go+rx $(BUILD)/bin/s3 $(DESTDIR)/bin/s3
121         install -Dp -m u+rw,go+r $(BUILD)/include/libs3.h \
122                $(DESTDIR)/include/libs3.h
123         install -Dp -m u+rw,go+r $(BUILD)/lib/libs3.a $(DESTDIR)/lib/libs3.a
124         install -Dps -m u+rw,go+r $(BUILD)/lib/libs3.so.$(LIBS3_VER_MAJOR) \
125                $(DESTDIR)/lib/libs3.so.$(LIBS3_VER)
126         ln -sf libs3.so.$(LIBS3_VER) $(DESTDIR)/lib/libs3.so.$(LIBS3_VER_MAJOR)
127         ln -sf libs3.so.$(LIBS3_VER_MAJOR) $(DESTDIR)/lib/libs3.so
128
129
130 # --------------------------------------------------------------------------
131 # Uninstall target
132
133 .PHONY: uninstall
134 uninstall:
135         rm -f $(DESTDIR)/bin/s3 \
136               $(DESTDIR)/include/libs3.h \
137               $(DESTDIR)/lib/libs3.a \
138               $(DESTDIR)/lib/libs3.so \
139               $(DESTDIR)/lib/libs3.so.$(LIBS3_VER_MAJOR) \
140               $(DESTDIR)/lib/libs3.so.$(LIBS3_VER) \
141
142
143 # --------------------------------------------------------------------------
144 # Debian package target
145
146 DEBPKG = $(BUILD)/pkg/libs3_$(LIBS3_VER).deb
147 DEBDEVPKG = $(BUILD)/pkg/libs3-dev_$(LIBS3_VER).deb
148
149 .PHONY: deb
150 deb: $(DEBPKG) $(DEBDEVPKG)
151
152 $(DEBPKG): DEBARCH = $(shell dpkg-architecture | grep ^DEB_BUILD_ARCH= | \
153                        cut -d '=' -f 2)
154 $(DEBPKG): exported $(BUILD)/deb/DEBIAN/control $(BUILD)/deb/DEBIAN/shlibs \
155            $(BUILD)/deb/DEBIAN/postinst \
156            $(BUILD)/deb/usr/share/doc/libs3/changelog.gz \
157            $(BUILD)/deb/usr/share/doc/libs3/changelog.Debian.gz \
158            $(BUILD)/deb/usr/share/doc/libs3/copyright
159         DESTDIR=$(BUILD)/deb/usr $(MAKE) install
160         rm -rf $(BUILD)/deb/usr/include
161         rm -f $(BUILD)/deb/usr/lib/libs3.a
162         @mkdir -p $(dir $@)
163         fakeroot dpkg-deb -b $(BUILD)/deb $@
164         mv $@ $(BUILD)/pkg/libs3_$(LIBS3_VER)_$(DEBARCH).deb
165
166 $(DEBDEVPKG): DEBARCH = $(shell dpkg-architecture | grep ^DEB_BUILD_ARCH= | \
167                           cut -d '=' -f 2)
168 $(DEBDEVPKG): exported $(BUILD)/deb-dev/DEBIAN/control \
169            $(BUILD)/deb-dev/usr/share/doc/libs3-dev/changelog.gz \
170            $(BUILD)/deb-dev/usr/share/doc/libs3-dev/changelog.Debian.gz \
171            $(BUILD)/deb-dev/usr/share/doc/libs3-dev/copyright
172         DESTDIR=$(BUILD)/deb-dev/usr $(MAKE) install
173         rm -rf $(BUILD)/deb-dev/usr/bin
174         rm -f $(BUILD)/deb-dev/usr/lib/libs3.so*
175         @mkdir -p $(dir $@)
176         fakeroot dpkg-deb -b $(BUILD)/deb-dev $@
177         mv $@ $(BUILD)/pkg/libs3-dev_$(LIBS3_VER)_$(DEBARCH).deb
178
179 $(BUILD)/deb/DEBIAN/control: debian/control
180         @mkdir -p $(dir $@)
181         echo -n "Depends: " > $@
182         dpkg-shlibdeps -O $(BUILD)/lib/libs3.so.$(LIBS3_VER_MAJOR) | \
183             cut -d '=' -f 2- >> $@
184         sed -e 's/LIBS3_VERSION/$(LIBS3_VER)/' \
185             < $< | sed -e 's/DEBIAN_ARCHITECTURE/$(DEBARCH)/' | \
186             grep -v ^Source: >> $@
187
188 $(BUILD)/deb-dev/DEBIAN/control: debian/control.dev
189         @mkdir -p $(dir $@)
190         sed -e 's/LIBS3_VERSION/$(LIBS3_VER)/' \
191             < $< | sed -e 's/DEBIAN_ARCHITECTURE/$(DEBARCH)/' > $@
192
193 $(BUILD)/deb/DEBIAN/shlibs:
194         echo -n "libs3 $(LIBS3_VER_MAJOR) libs3 " > $@
195         echo "(>= $(LIBS3_VER))" >> $@
196
197 $(BUILD)/deb/DEBIAN/postinst: debian/postinst
198         @mkdir -p $(dir $@)
199         cp $< $@
200
201 $(BUILD)/deb/usr/share/doc/libs3/copyright: LICENSE
202         @mkdir -p $(dir $@)
203         cp $< $@
204         @echo >> $@
205         @echo -n "An alternate location for the GNU General Public " >> $@
206         @echo "License version 3 on Debian" >> $@
207         @echo "systems is /usr/share/common-licenses/GPL-3." >> $@
208
209 $(BUILD)/deb-dev/usr/share/doc/libs3-dev/copyright: LICENSE
210         @mkdir -p $(dir $@)
211         cp $< $@
212         @echo >> $@
213         @echo -n "An alternate location for the GNU General Public " >> $@
214         @echo "License version 3 on Debian" >> $@
215         @echo "systems is /usr/share/common-licenses/GPL-3." >> $@
216
217 $(BUILD)/deb/usr/share/doc/libs3/changelog.gz: debian/changelog
218         @mkdir -p $(dir $@)
219         gzip --best -c $< > $@
220
221 $(BUILD)/deb-dev/usr/share/doc/libs3-dev/changelog.gz: debian/changelog
222         @mkdir -p $(dir $@)
223         gzip --best -c $< > $@
224
225 $(BUILD)/deb/usr/share/doc/libs3/changelog.Debian.gz: debian/changelog.Debian
226         @mkdir -p $(dir $@)
227         gzip --best -c $< > $@
228
229 $(BUILD)/deb-dev/usr/share/doc/libs3-dev/changelog.Debian.gz: \
230     debian/changelog.Debian
231         @mkdir -p $(dir $@)
232         gzip --best -c $< > $@
233
234
235 # --------------------------------------------------------------------------
236 # Compile target patterns
237
238 $(BUILD)/obj/%.o: src/%.c
239         @mkdir -p $(dir $@)
240         gcc $(CFLAGS) -o $@ -c $<
241
242 $(BUILD)/obj/%.do: src/%.c
243         @mkdir -p $(dir $@)
244         gcc $(CFLAGS) -fpic -fPIC -o $@ -c $< 
245
246
247 # --------------------------------------------------------------------------
248 # libs3 library targets
249
250 LIBS3_SHARED = $(BUILD)/lib/libs3.so.$(LIBS3_VER_MAJOR)
251
252 .PHONY: libs3
253 libs3: $(LIBS3_SHARED) $(BUILD)/lib/libs3.a
254
255 LIBS3_SOURCES := src/acl.c src/bucket.c src/error_parser.c src/general.c \
256                  src/object.c src/request.c src/request_context.c \
257                  src/response_headers_handler.c src/service_access_logging.c \
258                  src/service.c src/simplexml.c src/util.c
259
260 $(LIBS3_SHARED): $(LIBS3_SOURCES:src/%.c=$(BUILD)/obj/%.do)
261         @mkdir -p $(dir $@)
262         gcc -shared -Wl,-soname,libs3.so.$(LIBS3_VER_MAJOR) -o $@ $^ $(LDFLAGS)
263
264 $(BUILD)/lib/libs3.a: $(LIBS3_SOURCES:src/%.c=$(BUILD)/obj/%.o)
265         @mkdir -p $(dir $@)
266         $(AR) cr $@ $^
267
268
269 # --------------------------------------------------------------------------
270 # Driver program targets
271
272 .PHONY: s3
273 s3: $(BUILD)/bin/s3
274
275 $(BUILD)/bin/s3: $(BUILD)/obj/s3.o $(LIBS3_SHARED)
276         @mkdir -p $(dir $@)
277         gcc -o $@ $^ $(LDFLAGS)
278
279
280 # --------------------------------------------------------------------------
281 # libs3 header targets
282
283 .PHONY: headers
284 headers: $(BUILD)/include/libs3.h
285
286 $(BUILD)/include/libs3.h: inc/libs3.h
287         @mkdir -p $(dir $@)
288         cp $< $@
289
290
291 # --------------------------------------------------------------------------
292 # Test targets
293
294 .PHONY: test
295 test: $(BUILD)/bin/testsimplexml
296
297 $(BUILD)/bin/testsimplexml: $(BUILD)/obj/testsimplexml.o $(BUILD)/lib/libs3.a
298         @mkdir -p $(dir $@)
299         gcc -o $@ $^ $(LIBXML2_LIBS)
300
301
302 # --------------------------------------------------------------------------
303 # Clean target
304
305 .PHONY: clean
306 clean:
307         rm -rf $(BUILD)