GNUmakefile.osx 10 KB

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