GNUmakefile 14 KB

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