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
28# I tried to use the autoconf/automake/autolocal/etc (i.e. autohell) tools
29# but I just couldn't stomach them.  Since this is a Makefile for POSIX
30# systems, I will simply do away with autohell completely and use a GNU
31# Makefile.  GNU make ought to be available pretty much everywhere, so I
32# don't see this being a significant issue for portability.
33
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
42# --------------------------------------------------------------------------
43# Set libs3 version number, unless it is already set.
44
45LIBS3_VER_MAJOR ?= 4
46LIBS3_VER_MINOR ?= 1
47LIBS3_VER := $(LIBS3_VER_MAJOR).$(LIBS3_VER_MINOR)
48
49
50# -----------------------------------------------------------------------------
51# Determine verbosity.  VERBOSE_SHOW should be prepended to every command which
52# should only be displayed if VERBOSE is set.  QUIET_ECHO may be used to
53# echo text only if VERBOSE is not set.  Typically, a VERBOSE_SHOW command will
54# be paired with a QUIET_ECHO command, to provide a command which is displayed
55# in VERBOSE mode, along with text which is displayed in non-VERBOSE mode to
56# describe the command.
57#
58# No matter what VERBOSE is defined to, it ends up as true if it's defined.
59# This will be weird if you defined VERBOSE=false in the environment, and we
60# switch it to true here; but the meaning of VERBOSE is, "if it's defined to
61# any value, then verbosity is turned on".  So don't define VERBOSE if you
62# don't want verbosity in the build process.
63# -----------------------------------------------------------------------------
64
65ifdef VERBOSE
66        VERBOSE = true
67        VERBOSE_ECHO = @ echo
68        VERBOSE_SHOW =
69        QUIET_ECHO = @ echo >nul
70else
71        VERBOSE = false
72        VERBOSE_ECHO = @ echo >nul
73        VERBOSE_SHOW = @
74        QUIET_ECHO = @ echo
75endif
76
77
78# --------------------------------------------------------------------------
79# BUILD directory
80ifndef BUILD
81    ifdef DEBUG
82        BUILD := build-debug
83    else
84        BUILD := build
85    endif
86endif
87
88
89# --------------------------------------------------------------------------
90# DESTDIR directory
91ifndef DESTDIR
92    DESTDIR := libs3-$(LIBS3_VER)
93endif
94
95
96# --------------------------------------------------------------------------
97# Acquire configuration information for libraries that libs3 depends upon
98
99ifndef CURL_LIBS
100    CURL_LIBS := -Lc:\libs3-libs\bin -lcurl
101endif
102
103ifndef CURL_CFLAGS
104    CURL_CFLAGS := -Ic:\libs3-libs\include
105endif
106
107ifndef LIBXML2_LIBS
108    LIBXML2_LIBS := -Lc:\libs3-libs\bin -lxml2
109endif
110
111ifndef LIBXML2_CFLAGS
112    LIBXML2_CFLAGS := -Ic:\libs3-libs\include
113endif
114
115
116# --------------------------------------------------------------------------
117# These CFLAGS assume a GNU compiler.  For other compilers, write a script
118# which converts these arguments into their equivalent for that particular
119# compiler.
120
121ifndef CFLAGS
122    ifdef DEBUG
123        CFLAGS := -g
124    else
125        CFLAGS := -O3
126    endif
127endif
128
129CFLAGS += -Wall -Werror -Wshadow -Wextra -Iinc \
130          $(CURL_CFLAGS) $(LIBXML2_CFLAGS) \
131          -DLIBS3_VER_MAJOR=\"$(LIBS3_VER_MAJOR)\" \
132          -DLIBS3_VER_MINOR=\"$(LIBS3_VER_MINOR)\" \
133          -DLIBS3_VER=\"$(LIBS3_VER)\" \
134          -D__STRICT_ANSI__ \
135          -D_ISOC99_SOURCE \
136          -D_POSIX_C_SOURCE=200112L \
137          -Dsleep=Sleep -DSLEEP_UNITS_PER_SECOND=1000 \
138          -DFOPEN_EXTRA_FLAGS=\"b\" \
139          -Iinc/mingw -include windows.h
140
141LDFLAGS = $(CURL_LIBS) $(LIBXML2_LIBS)
142
143# --------------------------------------------------------------------------
144# Default targets are everything
145
146.PHONY: all
147all: exported test
148
149
150# --------------------------------------------------------------------------
151# Exported targets are the library and driver program
152
153.PHONY: exported
154exported: libs3 s3 headers
155
156
157# --------------------------------------------------------------------------
158# Install target
159
160.PHONY: install
161install: exported
162	$(QUIET_ECHO) $(DESTDIR)/bin/s3.exe: Installing executable
163	- @ mkdir $(DESTDIR)\bin 2>&1 | echo >nul
164	$(VERBOSE_SHOW) copy $(BUILD)\bin\s3.exe $(DESTDIR)\bin\s3.exe >nul
165	$(QUIET_ECHO) $(DESTDIR)/bin/libs3/dll: Installing dynamic library
166	$(VERBOSE_SHOW) copy $(BUILD)\bin\libs3.dll $(DESTDIR)\bin\libs3.dll >nul
167	$(QUIET_ECHO) $(DESTDIR)/lib/libs3.a: Installing static library
168	- @ mkdir $(DESTDIR)\lib 2>&1 | echo >nul
169	$(VERBOSE_SHOW) copy $(BUILD)\lib\libs3.a $(DESTDIR)\lib\libs3.a >nul
170	$(QUIET_ECHO) $(DESTDIR)/lib/libs3.def: Installing def file
171	$(VERBOSE_SHOW) copy mswin\libs3.def $(DESTDIR)\lib\libs3.def >nul
172	- @ mkdir $(DESTDIR)\include 2>&1 | echo >nul
173	$(QUIET_ECHO) $(DESTDIR)/include/libs3.h: Copying header
174	$(VERBOSE_SHOW) copy $(BUILD)\include\libs3.h \
175                    $(DESTDIR)\include\libs3.h >nul
176	$(QUIET_ECHO) $(DESTDIR)/LICENSE: Copying license
177	$(VERBOSE_SHOW) copy LICENSE $(DESTDIR)\LICENSE >nul
178	$(QUIET_ECHO) $(DESTDIR)/COPYING: Copying license
179	$(VERBOSE_SHOW) copy COPYING $(DESTDIR)\COPYING >nul
180
181
182# --------------------------------------------------------------------------
183# Uninstall target
184
185.PHONY: uninstall
186uninstall:
187	$(QUIET_ECHO) Installed files: Uninstalling
188	$(VERBOSE_SHOW) \
189	    del $(DESTDIR)\bin\s3.exe \
190            $(DESTDIR)\bin\libs3.dll \
191            $(DESTDIR)\lib\libs3.a \
192            $(DESTDIR)\lib\libs3.def \
193            $(DESTDIR)\include\libs3.h \
194            $(DESTDIR)\LICENSE \
195            $(DESTDIR)\COPYING
196
197
198# --------------------------------------------------------------------------
199# Compile target patterns
200
201$(BUILD)/obj/%.o: src/%.c
202	$(QUIET_ECHO) $@: Compiling object
203	- @ mkdir $(subst /,\,$(dir $(BUILD)/dep/$<)) 2>&1 | echo >nul
204	@ gcc $(CFLAGS) -M -MG -MQ $@ -DCOMPILINGDEPENDENCIES \
205        -o $(BUILD)/dep/$(<:%.c=%.d) -c $<
206	- @ mkdir $(subst /,\,$(dir $@)) 2>&1 | echo >nul
207	$(VERBOSE_SHOW) gcc $(CFLAGS) -o $@ -c $<
208
209
210# --------------------------------------------------------------------------
211# libs3 library targets
212
213LIBS3_SHARED = $(BUILD)/bin/libs3.dll
214LIBS3_STATIC = $(BUILD)/lib/libs3.a
215
216.PHONY: libs3
217libs3: $(LIBS3_SHARED) $(BUILD)/lib/libs3.a
218
219LIBS3_SOURCES := src/bucket.c src/bucket_metadata.c src/error_parser.c src/general.c \
220                 src/object.c src/request.c src/request_context.c \
221                 src/response_headers_handler.c src/service_access_logging.c \
222                 src/service.c src/simplexml.c src/util.c src/multipart.c \
223                 src/mingw_functions.c
224
225$(LIBS3_SHARED): $(LIBS3_SOURCES:src/%.c=$(BUILD)/obj/%.o)
226	$(QUIET_ECHO) $@: Building dynamic library
227	- @ mkdir $(subst /,\,$(dir $@)) 2>&1 | echo >nul
228	$(VERBOSE_SHOW) gcc -shared -o $@ $^ $(LDFLAGS) -lws2_32
229
230$(LIBS3_STATIC): $(LIBS3_SHARED)
231	$(QUIET_ECHO) $@: Building static library
232	- @ mkdir $(subst /,\,$(dir $@)) 2>&1 | echo >nul
233	$(VERBOSE_SHOW) dlltool --def mswin\libs3.def --dllname $(subst /,\,$<) \
234            --output-lib $(subst /,\,$@)
235
236
237# --------------------------------------------------------------------------
238# Driver program targets
239
240.PHONY: s3
241s3: $(BUILD)/bin/s3.exe
242
243$(BUILD)/bin/s3.exe: $(BUILD)/obj/s3.o $(BUILD)/obj/mingw_s3_functions.o \
244                     $(BUILD)/lib/libs3.a
245	$(QUIET_ECHO) $@: Building executable
246	- @ mkdir $(subst /,\,$(dir $@)) 2>&1 | echo >nul
247	$(VERBOSE_SHOW) gcc -o $@ $^ $(LDFLAGS) -lws2_32
248
249
250# --------------------------------------------------------------------------
251# libs3 header targets
252
253.PHONY: headers
254headers: $(BUILD)\include\libs3.h
255
256$(BUILD)\include\libs3.h: inc\libs3.h
257	$(QUIET_ECHO) $@: Copying header
258	- @ mkdir $(subst /,\,$(dir $@)) 2>&1 | echo >nul
259	$(VERBOSE_SHOW) copy $< $@
260
261
262# --------------------------------------------------------------------------
263# Test targets
264
265.PHONY: test
266test: $(BUILD)/bin/testsimplexml
267
268$(BUILD)/bin/testsimplexml: $(BUILD)/obj/testsimplexml.o \
269                            $(BUILD)/obj/simplexml.o
270	$(QUIET_ECHO) $@: Building executable
271	- @ mkdir $(subst /,\,$(dir $@)) 2>&1 | echo >nul
272	$(VERBOSE_SHOW) gcc -o $@ $^ $(LIBXML2_LIBS)
273
274
275# --------------------------------------------------------------------------
276# Clean target
277
278.PHONY: clean
279clean:
280	$(QUIET_ECHO) $(BUILD): Cleaning
281	$(VERBOSE_SHOW) mswin\rmrf.bat $(BUILD)
282
283
284# --------------------------------------------------------------------------
285# Clean dependencies target
286
287.PHONY: cleandeps
288cleandeps:
289	$(QUIET_ECHO) $(BUILD)/dep: Cleaning dependencies
290	$(VERBOSE_SHOW) mswin\rmrf.bat $(BUILD)\dep
291
292
293# --------------------------------------------------------------------------
294# Dependencies
295
296ALL_SOURCES := $(LIBS3_SOURCES) s3.c testsimplexml.c
297
298$(foreach i, $(ALL_SOURCES), $(eval -include $(BUILD)/dep/src/$(i:%.c=%.d)))
299