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)\" \
96 -D_POSIX_C_SOURCE=200112L
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 -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
130 # --------------------------------------------------------------------------
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) \
143 # --------------------------------------------------------------------------
144 # Debian package target
146 DEBPKG = $(BUILD)/pkg/libs3_$(LIBS3_VER).deb
147 DEBDEVPKG = $(BUILD)/pkg/libs3-dev_$(LIBS3_VER).deb
150 deb: $(DEBPKG) $(DEBDEVPKG)
152 $(DEBPKG): DEBARCH = $(shell dpkg-architecture | grep ^DEB_BUILD_ARCH= | \
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
163 fakeroot dpkg-deb -b $(BUILD)/deb $@
164 mv $@ $(BUILD)/pkg/libs3_$(LIBS3_VER)_$(DEBARCH).deb
166 $(DEBDEVPKG): DEBARCH = $(shell dpkg-architecture | grep ^DEB_BUILD_ARCH= | \
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*
176 fakeroot dpkg-deb -b $(BUILD)/deb-dev $@
177 mv $@ $(BUILD)/pkg/libs3-dev_$(LIBS3_VER)_$(DEBARCH).deb
179 $(BUILD)/deb/DEBIAN/control: debian/control
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: >> $@
188 $(BUILD)/deb-dev/DEBIAN/control: debian/control.dev
190 sed -e 's/LIBS3_VERSION/$(LIBS3_VER)/' \
191 < $< | sed -e 's/DEBIAN_ARCHITECTURE/$(DEBARCH)/' > $@
193 $(BUILD)/deb/DEBIAN/shlibs:
194 echo -n "libs3 $(LIBS3_VER_MAJOR) libs3 " > $@
195 echo "(>= $(LIBS3_VER))" >> $@
197 $(BUILD)/deb/DEBIAN/postinst: debian/postinst
201 $(BUILD)/deb/usr/share/doc/libs3/copyright: LICENSE
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." >> $@
209 $(BUILD)/deb-dev/usr/share/doc/libs3-dev/copyright: LICENSE
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." >> $@
217 $(BUILD)/deb/usr/share/doc/libs3/changelog.gz: debian/changelog
219 gzip --best -c $< > $@
221 $(BUILD)/deb-dev/usr/share/doc/libs3-dev/changelog.gz: debian/changelog
223 gzip --best -c $< > $@
225 $(BUILD)/deb/usr/share/doc/libs3/changelog.Debian.gz: debian/changelog.Debian
227 gzip --best -c $< > $@
229 $(BUILD)/deb-dev/usr/share/doc/libs3-dev/changelog.Debian.gz: \
230 debian/changelog.Debian
232 gzip --best -c $< > $@
235 # --------------------------------------------------------------------------
236 # Compile target patterns
238 $(BUILD)/obj/%.o: src/%.c
240 gcc $(CFLAGS) -o $@ -c $<
242 $(BUILD)/obj/%.do: src/%.c
244 gcc $(CFLAGS) -fpic -fPIC -o $@ -c $<
247 # --------------------------------------------------------------------------
248 # libs3 library targets
250 LIBS3_SHARED = $(BUILD)/lib/libs3.so.$(LIBS3_VER_MAJOR)
253 libs3: $(LIBS3_SHARED) $(BUILD)/lib/libs3.a
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
260 $(LIBS3_SHARED): $(LIBS3_SOURCES:src/%.c=$(BUILD)/obj/%.do)
262 gcc -shared -Wl,-soname,libs3.so.$(LIBS3_VER_MAJOR) -o $@ $^ $(LDFLAGS)
264 $(BUILD)/lib/libs3.a: $(LIBS3_SOURCES:src/%.c=$(BUILD)/obj/%.o)
269 # --------------------------------------------------------------------------
270 # Driver program targets
275 $(BUILD)/bin/s3: $(BUILD)/obj/s3.o $(LIBS3_SHARED)
277 gcc -o $@ $^ $(LDFLAGS)
280 # --------------------------------------------------------------------------
281 # libs3 header targets
284 headers: $(BUILD)/include/libs3.h
286 $(BUILD)/include/libs3.h: inc/libs3.h
291 # --------------------------------------------------------------------------
295 test: $(BUILD)/bin/testsimplexml
297 $(BUILD)/bin/testsimplexml: $(BUILD)/obj/testsimplexml.o $(BUILD)/lib/libs3.a
299 gcc -o $@ $^ $(LIBXML2_LIBS)
302 # --------------------------------------------------------------------------