GNUmakefile.osx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. # GNUmakefile.osx
  2. #
  3. # This file is part of libs3.
  4. #
  5. # libs3 is free software: you can redistribute it and/or modify it under the
  6. # terms of the GNU Lesser General Public License as published by the Free
  7. # Software Foundation, version 3 or above of the License. You can also
  8. # redistribute and/or modify it under the terms of the GNU General Public
  9. # License, version 2 or above 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 Lesser General Public License
  21. # version 3 along with libs3, in a file named COPYING. If not, see
  22. # <http://www.gnu.org/licenses/>.
  23. #
  24. # You should also have received a copy of the GNU General Public License
  25. # version 2 along with libs3, in a file named COPYING-GPLv2. If not, see
  26. # <http://www.gnu.org/licenses/>.
  27. # I tried to use the autoconf/automake/autolocal/etc (i.e. autohell) tools
  28. # but I just couldn't stomach them. Since this is a Makefile for POSIX
  29. # systems, I will simply do away with autohell completely and use a GNU
  30. # Makefile. GNU make ought to be available pretty much everywhere, so I
  31. # don't see this being a significant issue for portability.
  32. # All commands assume a GNU compiler. For systems which do not use a GNU
  33. # compiler, write scripts with the same names as these commands, and taking
  34. # the same arguments, and translate the arguments and commands into the
  35. # appropriate non-POSIX ones as needed. libs3 assumes a GNU toolchain as
  36. # the most portable way to build software possible. Non-POSIX, non-GNU
  37. # systems can do the work of supporting this build infrastructure.
  38. # --------------------------------------------------------------------------
  39. # Set libs3 version number, unless it is already set.
  40. LIBS3_VER_MAJOR ?= 4
  41. LIBS3_VER_MINOR ?= 1
  42. LIBS3_VER := $(LIBS3_VER_MAJOR).$(LIBS3_VER_MINOR)
  43. # -----------------------------------------------------------------------------
  44. # Determine verbosity. VERBOSE_SHOW should be prepended to every command which
  45. # should only be displayed if VERBOSE is set. QUIET_ECHO may be used to
  46. # echo text only if VERBOSE is not set. Typically, a VERBOSE_SHOW command will
  47. # be paired with a QUIET_ECHO command, to provide a command which is displayed
  48. # in VERBOSE mode, along with text which is displayed in non-VERBOSE mode to
  49. # describe the command.
  50. #
  51. # No matter what VERBOSE is defined to, it ends up as true if it's defined.
  52. # This will be weird if you defined VERBOSE=false in the environment, and we
  53. # switch it to true here; but the meaning of VERBOSE is, "if it's defined to
  54. # any value, then verbosity is turned on". So don't define VERBOSE if you
  55. # don't want verbosity in the build process.
  56. # -----------------------------------------------------------------------------
  57. ifdef VERBOSE
  58. VERBOSE = true
  59. VERBOSE_ECHO = @ echo
  60. VERBOSE_SHOW =
  61. QUIET_ECHO = @ echo > /dev/null
  62. else
  63. VERBOSE = false
  64. VERBOSE_ECHO = @ echo > /dev/null
  65. VERBOSE_SHOW = @
  66. QUIET_ECHO = @ echo
  67. endif
  68. # --------------------------------------------------------------------------
  69. # BUILD directory
  70. ifndef BUILD
  71. ifdef DEBUG
  72. BUILD := build-debug
  73. else
  74. BUILD := build
  75. endif
  76. endif
  77. # --------------------------------------------------------------------------
  78. # DESTDIR directory
  79. ifndef DESTDIR
  80. DESTDIR := /usr
  81. endif
  82. # --------------------------------------------------------------------------
  83. # Acquire configuration information for libraries that libs3 depends upon
  84. ifndef CURL_LIBS
  85. CURL_LIBS := $(shell curl-config --libs)
  86. endif
  87. ifndef CURL_CFLAGS
  88. CURL_CFLAGS := $(shell curl-config --cflags)
  89. endif
  90. ifndef LIBXML2_LIBS
  91. LIBXML2_LIBS := $(shell xml2-config --libs)
  92. # Work around missing libsystem_symptoms.dylib in Xcode 8; see
  93. # http://stackoverflow.com/questions/39536144/libsystem-symptoms-dylib-missing-in-xcode-8
  94. LIBXML2_LIBS := $(filter-out -L$(shell xcrun --show-sdk-path)/usr/lib, $(LIBXML2_LIBS))
  95. endif
  96. ifndef LIBXML2_CFLAGS
  97. LIBXML2_CFLAGS := $(shell xml2-config --cflags)
  98. endif
  99. # --------------------------------------------------------------------------
  100. # These CFLAGS assume a GNU compiler. For other compilers, write a script
  101. # which converts these arguments into their equivalent for that particular
  102. # compiler.
  103. ifndef CFLAGS
  104. ifdef DEBUG
  105. CFLAGS := -g
  106. else
  107. CFLAGS := -O3
  108. endif
  109. endif
  110. # --------------------------------------------------------------------------
  111. # -Werror breaks the build on the macOS Sierra rendering build unusable
  112. # so we use -Wunused-parameter flag instead that will only issue a warning
  113. # with the newest clang compiler
  114. CFLAGS += -Wall -Wunused-parameter -Wshadow -Wextra -Iinc \
  115. $(CURL_CFLAGS) $(LIBXML2_CFLAGS) \
  116. -DLIBS3_VER_MAJOR=\"$(LIBS3_VER_MAJOR)\" \
  117. -DLIBS3_VER_MINOR=\"$(LIBS3_VER_MINOR)\" \
  118. -DLIBS3_VER=\"$(LIBS3_VER)\" \
  119. -D__STRICT_ANSI__ \
  120. -D_ISOC99_SOURCE \
  121. -fno-common
  122. LDFLAGS = $(CURL_LIBS) $(LIBXML2_LIBS) -lpthread
  123. # --------------------------------------------------------------------------
  124. # Default targets are everything
  125. .PHONY: all
  126. all: exported test
  127. # --------------------------------------------------------------------------
  128. # Exported targets are the library and driver program
  129. .PHONY: exported
  130. exported: libs3 s3 headers
  131. # --------------------------------------------------------------------------
  132. # Install target
  133. .PHONY: install
  134. install: exported
  135. $(QUIET_ECHO) $(DESTDIR)/bin/s3: Installing executable
  136. $(VERBOSE_SHOW) install -ps -m u+rwx,go+rx $(BUILD)/bin/s3 \
  137. $(DESTDIR)/bin/s3
  138. $(QUIET_ECHO) \
  139. $(DESTDIR)/lib/libs3.$(LIBS3_VER).dylib: Installing dynamic library
  140. $(VERBOSE_SHOW) install -p -m u+rw,go+r \
  141. $(BUILD)/lib/libs3.$(LIBS3_VER_MAJOR).dylib \
  142. $(DESTDIR)/lib/libs3.$(LIBS3_VER).dylib
  143. $(QUIET_ECHO) \
  144. $(DESTDIR)/lib/libs3.$(LIBS3_VER_MAJOR).dylib: Linking dynamic library
  145. $(VERBOSE_SHOW) ln -sf libs3.$(LIBS3_VER).dylib \
  146. $(DESTDIR)/lib/libs3.$(LIBS3_VER_MAJOR).dylib
  147. $(QUIET_ECHO) $(DESTDIR)/lib/libs3.dylib: Linking dynamic library
  148. $(VERBOSE_SHOW) ln -sf libs3.$(LIBS3_VER_MAJOR).dylib \
  149. $(DESTDIR)/lib/libs3.dylib
  150. $(QUIET_ECHO) $(DESTDIR)/lib/libs3.a: Installing static library
  151. $(VERBOSE_SHOW) install -p -m u+rw,go+r $(BUILD)/lib/libs3.a \
  152. $(DESTDIR)/lib/libs3.a
  153. $(QUIET_ECHO) $(DESTDIR)/include/libs3.h: Installing header
  154. $(VERBOSE_SHOW) install -p -m u+rw,go+r $(BUILD)/include/libs3.h \
  155. $(DESTDIR)/include/libs3.h
  156. # --------------------------------------------------------------------------
  157. # Uninstall target
  158. .PHONY: uninstall
  159. uninstall:
  160. $(QUIET_ECHO) Installed files: Uninstalling
  161. $(VERBOSE_SHOW) \
  162. rm -f $(DESTDIR)/bin/s3 \
  163. $(DESTDIR)/lib/libs3.dylib \
  164. $(DESTDIR)/lib/libs3.$(LIBS3_VER_MAJOR).dylib \
  165. $(DESTDIR)/lib/libs3.$(LIBS3_VER).dylib \
  166. $(DESTDIR)/lib/libs3.a \
  167. $(DESTDIR)/include/libs3.h
  168. # --------------------------------------------------------------------------
  169. # Compile target patterns
  170. $(BUILD)/obj/%.o: src/%.c
  171. $(QUIET_ECHO) $@: Compiling object
  172. @ mkdir -p $(dir $(BUILD)/dep/$<)
  173. @ gcc $(CFLAGS) -M -MG -MQ $@ -DCOMPILINGDEPENDENCIES \
  174. -o $(BUILD)/dep/$(<:%.c=%.d) -c $<
  175. @ mkdir -p $(dir $@)
  176. $(VERBOSE_SHOW) gcc $(CFLAGS) -o $@ -c $<
  177. $(BUILD)/obj/%.do: src/%.c
  178. $(QUIET_ECHO) $@: Compiling dynamic object
  179. @ mkdir -p $(dir $(BUILD)/dep/$<)
  180. @ gcc $(CFLAGS) -M -MG -MQ $@ -DCOMPILINGDEPENDENCIES \
  181. -o $(BUILD)/dep/$(<:%.c=%.dd) -c $<
  182. @ mkdir -p $(dir $@)
  183. $(VERBOSE_SHOW) gcc $(CFLAGS) -fpic -fPIC -o $@ -c $<
  184. # --------------------------------------------------------------------------
  185. # libs3 library targets
  186. LIBS3_SHARED = $(BUILD)/lib/libs3.$(LIBS3_VER_MAJOR).dylib
  187. LIBS3_STATIC = $(BUILD)/lib/libs3.a
  188. .PHONY: libs3
  189. libs3: $(LIBS3_SHARED) $(LIBS3_SHARED_MAJOR) $(BUILD)/lib/libs3.a
  190. LIBS3_SOURCES := src/bucket.c src/bucket_metadata.c src/error_parser.c src/general.c \
  191. src/object.c src/request.c src/request_context.c \
  192. src/response_headers_handler.c src/service_access_logging.c \
  193. src/service.c src/simplexml.c src/util.c src/multipart.c
  194. $(LIBS3_SHARED): $(LIBS3_SOURCES:src/%.c=$(BUILD)/obj/%.do)
  195. $(QUIET_ECHO) $@: Building shared library
  196. @ mkdir -p $(dir $@)
  197. $(VERBOSE_SHOW) gcc -dynamiclib -install_name \
  198. libs3.$(LIBS3_VER_MAJOR).dylib \
  199. -compatibility_version $(LIBS3_VER_MAJOR) \
  200. -current_version $(LIBS3_VER) -o $@ $^ $(LDFLAGS)
  201. $(LIBS3_STATIC): $(LIBS3_SOURCES:src/%.c=$(BUILD)/obj/%.o)
  202. $(QUIET_ECHO) $@: Building static library
  203. @ mkdir -p $(dir $@)
  204. $(VERBOSE_SHOW) $(AR) cr $@ $^
  205. # --------------------------------------------------------------------------
  206. # Driver program targets
  207. .PHONY: s3
  208. s3: $(BUILD)/bin/s3
  209. $(BUILD)/bin/s3: $(BUILD)/obj/s3.o $(LIBS3_SHARED)
  210. $(QUIET_ECHO) $@: Building executable
  211. @ mkdir -p $(dir $@)
  212. $(VERBOSE_SHOW) gcc -o $@ $^ $(LDFLAGS)
  213. # --------------------------------------------------------------------------
  214. # libs3 header targets
  215. .PHONY: headers
  216. headers: $(BUILD)/include/libs3.h
  217. $(BUILD)/include/libs3.h: inc/libs3.h
  218. $(QUIET_ECHO) $@: Linking header
  219. @ mkdir -p $(dir $@)
  220. $(VERBOSE_SHOW) ln -sf $(abspath $<) $@
  221. # --------------------------------------------------------------------------
  222. # Test targets
  223. .PHONY: test
  224. test: $(BUILD)/bin/testsimplexml
  225. $(BUILD)/bin/testsimplexml: $(BUILD)/obj/testsimplexml.o $(LIBS3_STATIC)
  226. $(QUIET_ECHO) $@: Building executable
  227. @ mkdir -p $(dir $@)
  228. $(VERBOSE_SHOW) gcc -o $@ $^ $(LIBXML2_LIBS)
  229. # --------------------------------------------------------------------------
  230. # Clean target
  231. .PHONY: clean
  232. clean:
  233. $(QUIET_ECHO) $(BUILD): Cleaning
  234. $(VERBOSE_SHOW) rm -rf $(BUILD)
  235. # --------------------------------------------------------------------------
  236. # Clean dependencies target
  237. .PHONY: cleandeps
  238. cleandeps:
  239. $(QUIET_ECHO) $(BUILD)/dep: Cleaning dependencies
  240. $(VERBOSE_SHOW) rm -rf $(BUILD)/dep
  241. # --------------------------------------------------------------------------
  242. # Dependencies
  243. ALL_SOURCES := $(LIBS3_SOURCES) s3.c testsimplexml.c
  244. $(foreach i, $(ALL_SOURCES), $(eval -include $(BUILD)/dep/src/$(i:%.c=%.d)))
  245. $(foreach i, $(ALL_SOURCES), $(eval -include $(BUILD)/dep/src/$(i:%.c=%.dd)))