GNUmakefile.mingw 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. # GNUmakefile.mingw
  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. # <https://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 >nul
  58. else
  59. VERBOSE = false
  60. VERBOSE_ECHO = @ echo >nul
  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 := libs3-$(LIBS3_VER)
  77. endif
  78. # --------------------------------------------------------------------------
  79. # Acquire configuration information for libraries that libs3 depends upon
  80. ifndef CURL_LIBS
  81. CURL_LIBS := -Lc:\libs3-libs\bin -lcurl
  82. endif
  83. ifndef CURL_CFLAGS
  84. CURL_CFLAGS := -Ic:\libs3-libs\include
  85. endif
  86. ifndef LIBXML2_LIBS
  87. LIBXML2_LIBS := -Lc:\libs3-libs\bin -lxml2
  88. endif
  89. ifndef LIBXML2_CFLAGS
  90. LIBXML2_CFLAGS := -Ic:\libs3-libs\include
  91. endif
  92. # --------------------------------------------------------------------------
  93. # These CFLAGS assume a GNU compiler. For other compilers, write a script
  94. # which converts these arguments into their equivalent for that particular
  95. # compiler.
  96. ifndef CFLAGS
  97. ifdef DEBUG
  98. CFLAGS := -g
  99. else
  100. CFLAGS := -O3
  101. endif
  102. endif
  103. CFLAGS += -Wall -Werror -Wshadow -Wextra -Iinc \
  104. $(CURL_CFLAGS) $(LIBXML2_CFLAGS) \
  105. -DLIBS3_VER_MAJOR=\"$(LIBS3_VER_MAJOR)\" \
  106. -DLIBS3_VER_MINOR=\"$(LIBS3_VER_MINOR)\" \
  107. -DLIBS3_VER=\"$(LIBS3_VER)\" \
  108. -D__STRICT_ANSI__ \
  109. -D_ISOC99_SOURCE \
  110. -D_POSIX_C_SOURCE=200112L \
  111. -Dsleep=Sleep -DSLEEP_UNITS_PER_SECOND=1000 \
  112. -DFOPEN_EXTRA_FLAGS=\"b\" \
  113. -Iinc/mingw -include windows.h
  114. LDFLAGS = $(CURL_LIBS) $(LIBXML2_LIBS)
  115. # --------------------------------------------------------------------------
  116. # Default targets are everything
  117. .PHONY: all
  118. all: exported test
  119. # --------------------------------------------------------------------------
  120. # Exported targets are the library and driver program
  121. .PHONY: exported
  122. exported: libs3 s3 headers
  123. # --------------------------------------------------------------------------
  124. # Install target
  125. .PHONY: install
  126. install: exported
  127. $(QUIET_ECHO) $(DESTDIR)/bin/s3.exe: Installing executable
  128. - @ mkdir $(DESTDIR)\bin 2>&1 | echo >nul
  129. $(VERBOSE_SHOW) copy $(BUILD)\bin\s3.exe $(DESTDIR)\bin\s3.exe >nul
  130. $(QUIET_ECHO) $(DESTDIR)/bin/libs3/dll: Installing dynamic library
  131. $(VERBOSE_SHOW) copy $(BUILD)\bin\libs3.dll $(DESTDIR)\bin\libs3.dll >nul
  132. $(QUIET_ECHO) $(DESTDIR)/lib/libs3.a: Installing static library
  133. - @ mkdir $(DESTDIR)\lib 2>&1 | echo >nul
  134. $(VERBOSE_SHOW) copy $(BUILD)\lib\libs3.a $(DESTDIR)\lib\libs3.a >nul
  135. $(QUIET_ECHO) $(DESTDIR)/lib/libs3.def: Installing def file
  136. $(VERBOSE_SHOW) copy mswin\libs3.def $(DESTDIR)\lib\libs3.def >nul
  137. - @ mkdir $(DESTDIR)\include 2>&1 | echo >nul
  138. $(QUIET_ECHO) $(DESTDIR)/include/libs3.h: Copying header
  139. $(VERBOSE_SHOW) copy $(BUILD)\include\libs3.h \
  140. $(DESTDIR)\include\libs3.h >nul
  141. $(QUIET_ECHO) $(DESTDIR)/LICENSE: Copying license
  142. $(VERBOSE_SHOW) copy LICENSE $(DESTDIR)\LICENSE >nul
  143. $(QUIET_ECHO) $(DESTDIR)/COPYING: Copying license
  144. $(VERBOSE_SHOW) copy COPYING $(DESTDIR)\COPYING >nul
  145. # --------------------------------------------------------------------------
  146. # Uninstall target
  147. .PHONY: uninstall
  148. uninstall:
  149. $(QUIET_ECHO) Installed files: Uninstalling
  150. $(VERBOSE_SHOW) \
  151. del $(DESTDIR)\bin\s3.exe \
  152. $(DESTDIR)\bin\libs3.dll \
  153. $(DESTDIR)\lib\libs3.a \
  154. $(DESTDIR)\lib\libs3.def \
  155. $(DESTDIR)\include\libs3.h \
  156. $(DESTDIR)\LICENSE \
  157. $(DESTDIR)\COPYING
  158. # --------------------------------------------------------------------------
  159. # Compile target patterns
  160. $(BUILD)/obj/%.o: src/%.c
  161. $(QUIET_ECHO) $@: Compiling object
  162. - @ mkdir $(subst /,\,$(dir $(BUILD)/dep/$<)) 2>&1 | echo >nul
  163. @ gcc $(CFLAGS) -M -MG -MQ $@ -DCOMPILINGDEPENDENCIES \
  164. -o $(BUILD)/dep/$(<:%.c=%.d) -c $<
  165. - @ mkdir $(subst /,\,$(dir $@)) 2>&1 | echo >nul
  166. $(VERBOSE_SHOW) gcc $(CFLAGS) -o $@ -c $<
  167. # --------------------------------------------------------------------------
  168. # libs3 library targets
  169. LIBS3_SHARED = $(BUILD)/bin/libs3.dll
  170. LIBS3_STATIC = $(BUILD)/lib/libs3.a
  171. .PHONY: libs3
  172. libs3: $(LIBS3_SHARED) $(BUILD)/lib/libs3.a
  173. LIBS3_SOURCES := src/bucket.c src/bucket_metadata.c src/error_parser.c src/general.c \
  174. src/object.c src/request.c src/request_context.c \
  175. src/response_headers_handler.c src/service_access_logging.c \
  176. src/service.c src/simplexml.c src/util.c src/multipart.c \
  177. src/mingw_functions.c
  178. $(LIBS3_SHARED): $(LIBS3_SOURCES:src/%.c=$(BUILD)/obj/%.o)
  179. $(QUIET_ECHO) $@: Building dynamic library
  180. - @ mkdir $(subst /,\,$(dir $@)) 2>&1 | echo >nul
  181. $(VERBOSE_SHOW) gcc -shared -o $@ $^ $(LDFLAGS) -lws2_32
  182. $(LIBS3_STATIC): $(LIBS3_SHARED)
  183. $(QUIET_ECHO) $@: Building static library
  184. - @ mkdir $(subst /,\,$(dir $@)) 2>&1 | echo >nul
  185. $(VERBOSE_SHOW) dlltool --def mswin\libs3.def --dllname $(subst /,\,$<) \
  186. --output-lib $(subst /,\,$@)
  187. # --------------------------------------------------------------------------
  188. # Driver program targets
  189. .PHONY: s3
  190. s3: $(BUILD)/bin/s3.exe
  191. $(BUILD)/bin/s3.exe: $(BUILD)/obj/s3.o $(BUILD)/obj/mingw_s3_functions.o \
  192. $(BUILD)/lib/libs3.a
  193. $(QUIET_ECHO) $@: Building executable
  194. - @ mkdir $(subst /,\,$(dir $@)) 2>&1 | echo >nul
  195. $(VERBOSE_SHOW) gcc -o $@ $^ $(LDFLAGS) -lws2_32
  196. # --------------------------------------------------------------------------
  197. # libs3 header targets
  198. .PHONY: headers
  199. headers: $(BUILD)\include\libs3.h
  200. $(BUILD)\include\libs3.h: inc\libs3.h
  201. $(QUIET_ECHO) $@: Copying header
  202. - @ mkdir $(subst /,\,$(dir $@)) 2>&1 | echo >nul
  203. $(VERBOSE_SHOW) copy $< $@
  204. # --------------------------------------------------------------------------
  205. # Test targets
  206. .PHONY: test
  207. test: $(BUILD)/bin/testsimplexml
  208. $(BUILD)/bin/testsimplexml: $(BUILD)/obj/testsimplexml.o \
  209. $(BUILD)/obj/simplexml.o
  210. $(QUIET_ECHO) $@: Building executable
  211. - @ mkdir $(subst /,\,$(dir $@)) 2>&1 | echo >nul
  212. $(VERBOSE_SHOW) gcc -o $@ $^ $(LIBXML2_LIBS)
  213. # --------------------------------------------------------------------------
  214. # Clean target
  215. .PHONY: clean
  216. clean:
  217. $(QUIET_ECHO) $(BUILD): Cleaning
  218. $(VERBOSE_SHOW) mswin\rmrf.bat $(BUILD)
  219. # --------------------------------------------------------------------------
  220. # Clean dependencies target
  221. .PHONY: cleandeps
  222. cleandeps:
  223. $(QUIET_ECHO) $(BUILD)/dep: Cleaning dependencies
  224. $(VERBOSE_SHOW) mswin\rmrf.bat $(BUILD)\dep
  225. # --------------------------------------------------------------------------
  226. # Dependencies
  227. ALL_SOURCES := $(LIBS3_SOURCES) s3.c testsimplexml.c
  228. $(foreach i, $(ALL_SOURCES), $(eval -include $(BUILD)/dep/src/$(i:%.c=%.d)))