GNUmakefile.mingw 10.0 KB

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