3 # Copyright 2008 Bryan Ischo <bryan@ischo.com>
5 # This file is part of libs3.
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.
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.
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
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/>.
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.
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.
38 # --------------------------------------------------------------------------
39 # Set libs3 version number
43 LIBS3_VER := $(LIBS3_VER_MAJOR).$(LIBS3_VER_MINOR)
46 # --------------------------------------------------------------------------
53 # --------------------------------------------------------------------------
60 # --------------------------------------------------------------------------
61 # Acquire configuration information for libraries that libs3 depends upon
64 CURL_LIBS := $(shell curl-config --libs)
68 CURL_CFLAGS := $(shell curl-config --cflags)
72 LIBXML2_LIBS := $(shell xml2-config --libs)
76 LIBXML2_CFLAGS := $(shell xml2-config --cflags)
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
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)\" \
98 LDFLAGS = $(CURL_LIBS) $(LIBXML2_LIBS) -lpthread
101 # --------------------------------------------------------------------------
102 # Default targets are everything
108 # --------------------------------------------------------------------------
109 # Exported targets are the library and driver program
112 exported: libs3 s3 headers
115 # --------------------------------------------------------------------------
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
131 # --------------------------------------------------------------------------
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 \
144 # --------------------------------------------------------------------------
145 # Debian package target
147 DEBPKG = $(BUILD)/pkg/libs3_$(LIBS3_VER).deb
148 DEBDEVPKG = $(BUILD)/pkg/libs3-dev_$(LIBS3_VER).deb
151 deb: $(DEBPKG) $(DEBDEVPKG)
153 $(DEBPKG): DEBARCH = $(shell dpkg-architecture | grep ^DEB_BUILD_ARCH= | \
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
164 fakeroot dpkg-deb -b $(BUILD)/deb $@
165 mv $@ $(BUILD)/pkg/libs3_$(LIBS3_VER)_$(DEBARCH).deb
167 $(DEBDEVPKG): DEBARCH = $(shell dpkg-architecture | grep ^DEB_BUILD_ARCH= | \
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
177 fakeroot dpkg-deb -b $(BUILD)/deb-dev $@
178 mv $@ $(BUILD)/pkg/libs3-dev_$(LIBS3_VER)_$(DEBARCH).deb
180 $(BUILD)/deb/DEBIAN/control: debian/control
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: >> $@
189 $(BUILD)/deb-dev/DEBIAN/control: debian/control.dev
191 sed -e 's/LIBS3_VERSION/$(LIBS3_VER)/' \
192 < $< | sed -e 's/DEBIAN_ARCHITECTURE/$(DEBARCH)/' > $@
194 $(BUILD)/deb/DEBIAN/shlibs:
195 echo -n "libs3 $(LIBS3_VER_MAJOR) libs3 " > $@
196 echo "(>= $(LIBS3_VER))" >> $@
198 $(BUILD)/deb/DEBIAN/postinst: debian/postinst
202 $(BUILD)/deb/usr/share/doc/libs3/copyright: LICENSE
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." >> $@
210 $(BUILD)/deb-dev/usr/share/doc/libs3-dev/copyright: LICENSE
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." >> $@
218 $(BUILD)/deb/usr/share/doc/libs3/changelog.gz: debian/changelog
220 gzip --best -c $< > $@
222 $(BUILD)/deb-dev/usr/share/doc/libs3-dev/changelog.gz: debian/changelog
224 gzip --best -c $< > $@
226 $(BUILD)/deb/usr/share/doc/libs3/changelog.Debian.gz: debian/changelog.Debian
228 gzip --best -c $< > $@
230 $(BUILD)/deb-dev/usr/share/doc/libs3-dev/changelog.Debian.gz: \
231 debian/changelog.Debian
233 gzip --best -c $< > $@
236 # --------------------------------------------------------------------------
237 # Compile target patterns
239 $(BUILD)/obj/%.o: src/%.c
241 gcc $(CFLAGS) -o $@ -c $<
243 $(BUILD)/obj/%.do: src/%.c
245 gcc $(CFLAGS) -fpic -fPIC -o $@ -c $<
248 # --------------------------------------------------------------------------
249 # libs3 library targets
251 LIBS3_SHARED = $(BUILD)/lib/libs3.$(LIBS3_VER_MAJOR).dylib
254 libs3: $(LIBS3_SHARED) $(LIBS3_SHARED_MAJOR) $(BUILD)/lib/libs3.a
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
261 $(LIBS3_SHARED): $(LIBS3_SOURCES:src/%.c=$(BUILD)/obj/%.do)
263 gcc -dynamiclib -install_name libs3.$(LIBS3_VER_MAJOR).dylib \
264 -compatibility_version $(LIBS3_VER_MAJOR) \
265 -current_version $(LIBS3_VER) -o $@ $^ $(LDFLAGS)
267 $(BUILD)/lib/libs3.a: $(LIBS3_SOURCES:src/%.c=$(BUILD)/obj/%.o)
272 # --------------------------------------------------------------------------
273 # Driver program targets
278 $(BUILD)/bin/s3: $(BUILD)/obj/s3.o $(LIBS3_SHARED)
280 gcc -o $@ $^ $(LDFLAGS)
283 # --------------------------------------------------------------------------
284 # libs3 header targets
287 headers: $(BUILD)/include/libs3.h
289 $(BUILD)/include/libs3.h: inc/libs3.h
294 # --------------------------------------------------------------------------
298 test: $(BUILD)/bin/testsimplexml
300 $(BUILD)/bin/testsimplexml: $(BUILD)/obj/testsimplexml.o $(BUILD)/lib/libs3.a
302 gcc -o $@ $^ $(LIBXML2_LIBS)
305 # --------------------------------------------------------------------------