tools/windeps: update Windows dependencies Makefile
[wimlib] / tools / windeps / Makefile
1 #
2 # This Makefile builds the third-party libraries needed to build a standalone
3 # libwim.dll for Windows.  We build these third-party libraries ourselves mainly
4 # to cut down on bloat.  They are automatically downloaded from the URLs
5 # declared below and verified against the checksums given in the 'sha256sums'
6 # file.
7 #
8 # This Makefile requires a GNU toolchain with MinGW-w64 (i686 and x86_64
9 # versions).
10 #
11
12 ARCHITECTURES           := i686 x86_64
13 LIBXML2_VERSION         := 2.9.3
14 WINPTHREADS_VERSION     := 4.0.4
15 WINICONV_VERSION        := 0.0.6
16
17 LIBXML_URL              := ftp://xmlsoft.org/libxml2/libxml2-$(LIBXML2_VERSION).tar.gz
18 WINPTHREADS_URL         := http://downloads.sourceforge.net/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v$(WINPTHREADS_VERSION).tar.bz2
19 WINICONV_URL            := https://github.com/win-iconv/win-iconv/archive/$(WINICONV_VERSION).tar.gz
20
21
22 LIBXML_SRCDIR           := libxml2-$(LIBXML2_VERSION)
23 LIBXML_DIST             := $(LIBXML_SRCDIR).tar.gz
24 SRCDIR_TARGETS          += $(LIBXML_SRCDIR)
25 DIST_TARGETS            += $(LIBXML_DIST)
26 $(LIBXML_DIST):
27         wget $(LIBXML_URL)
28 $(LIBXML_SRCDIR):$(LIBXML_DIST) checksums_verified
29         tar xvf $<
30         cp $@/COPYING COPYING.libxml2
31 MAKE_CLEAN_FILES += $(LIBXML_SRCDIR) COPYING.libxml2
32
33 WINPTHREADS_DIST        := mingw-w64-v$(WINPTHREADS_VERSION).tar.bz2
34 WINPTHREADS_SRCDIR      := winpthreads-$(WINPTHREADS_VERSION)
35 SRCDIR_TARGETS          += $(WINPTHREADS_SRCDIR)
36 DIST_TARGETS            += $(WINPTHREADS_DIST)
37 $(WINPTHREADS_DIST):
38         wget $(WINPTHREADS_URL)
39 $(WINPTHREADS_SRCDIR):$(WINPTHREADS_DIST) checksums_verified
40         tar xvf $<
41         cp -aT mingw-w64-v$(WINPTHREADS_VERSION)/mingw-w64-libraries/winpthreads $@
42         cp $@/COPYING COPYING.winpthreads
43 MAKE_CLEAN_FILES += $(WINPTHREADS_SRCDIR) mingw-w64-v$(WINPTHREADS_VERSION) COPYING.winpthreads
44
45 WINICONV_SRCDIR         := win-iconv-$(WINICONV_VERSION)
46 WINICONV_DIST           := $(WINICONV_VERSION).tar.gz
47 SRCDIR_TARGETS          += $(WINICONV_SRCDIR)
48 DIST_TARGETS            += $(WINICONV_DIST)
49 $(WINICONV_DIST):
50         wget $(WINICONV_URL)
51 $(WINICONV_SRCDIR):$(WINICONV_DIST) checksums_verified
52         tar xvf $<
53 # win-iconv is public domain, so there's no license file.
54 MAKE_CLEAN_FILES        += $(WINICONV_SRCDIR)
55
56 checksums_verified:$(DIST_TARGETS)
57         sha256sum -c sha256sums
58
59 #
60 # declare_libxml_target(arch)
61 #
62 define declare_libxml_target
63 libxml_$(1):$(LIBXML_SRCDIR)
64         builddir=build_libxml_$(1);                             \
65         rm -rf $$$$builddir;                                    \
66         mkdir $$$$builddir;                                     \
67         cd $$$$builddir;                                        \
68         ../$(LIBXML_SRCDIR)/configure                           \
69                 --host=$(1)-w64-mingw32                         \
70                 --enable-static                                 \
71                 --disable-shared                                \
72                 --prefix=$$$$PWD/../sysroot_$(1)                \
73                 CFLAGS=-Os                                      \
74                 --with-minimum                                  \
75                 --without-lzma                                  \
76                 --with-tree                                     \
77                 --with-writer;                                  \
78         $(MAKE) install;                                        \
79         rm -f ../sysroot_$(1)/lib/libxml2.la;
80
81 $(1)_BUILD_TARGETS += libxml_$(1)
82 MAKE_CLEAN_FILES += build_libxml_$(1)
83 endef
84
85 #
86 # declare_winpthreads_target(arch)
87 #
88 define declare_winpthreads_target
89 winpthreads_$(1):$(WINPTHREADS_SRCDIR)
90         builddir=build_winpthreads_$(1);                        \
91         rm -rf $$$$builddir;                                    \
92         cp -r $(WINPTHREADS_SRCDIR) $$$$builddir;               \
93         cd $$$$builddir;                                        \
94         ./configure                                             \
95                 --host=$(1)-w64-mingw32                         \
96                 --enable-static                                 \
97                 --disable-shared                                \
98                 --prefix=$$$$PWD/../sysroot_$(1)                \
99                 CFLAGS=-O2;                                     \
100         $(MAKE) install;                                        \
101         sed -i 's/if defined DLL_EXPORT/if 0/' ../sysroot_$(1)/include/pthread.h;
102
103 $(1)_BUILD_TARGETS += winpthreads_$(1)
104 MAKE_CLEAN_FILES += build_winpthreads_$(1)
105 endef
106
107 #
108 # declare_winiconv_target(arch)
109 #
110 define declare_winiconv_target
111 winiconv_$(1):$(WINICONV_SRCDIR)
112         builddir=build_winiconv_$(1);                           \
113         rm -rf $$$$builddir;                                    \
114         cp -r $(WINICONV_SRCDIR) $$$$builddir;                  \
115         cd $$$$builddir;                                        \
116         $(MAKE) CC=$(1)-w64-mingw32-gcc                         \
117                 AR=$(1)-w64-mingw32-ar                          \
118                 RANLIB=$(1)-w64-mingw32-ranlib                  \
119                 DLLTOOL=$(1)-w64-mingw32-dlltool                \
120                 CFLAGS=-O2                                      \
121                 prefix=$$$$PWD/../sysroot_$(1)                  \
122                 install;                                        \
123         rm -f ../sysroot_$(1)/lib/libiconv.dll.a;
124
125 $(1)_BUILD_TARGETS += winiconv_$(1)
126 MAKE_CLEAN_FILES += build_winiconv_$(1)
127 endef
128
129 #
130 # declare_arch_targets(arch)
131 #
132 define declare_arch_targets
133 $(eval $(call declare_libxml_target,$(1)))
134 $(eval $(call declare_winpthreads_target,$(1)))
135 $(eval $(call declare_winiconv_target,$(1)))
136
137 sysroot_$(1): $($(1)_BUILD_TARGETS)
138
139 ALL_SYSROOTS += sysroot_$(1)
140 MAKE_CLEAN_FILES += sysroot_$(1)
141 endef
142
143 $(foreach arch,$(ARCHITECTURES),$(eval $(call declare_arch_targets,$(arch))))
144
145 all: $(ALL_SYSROOTS)
146
147 clean:
148         rm -rf $(MAKE_CLEAN_FILES) $(DIST_TARGETS)
149
150 .PHONY: all clean $(SRCDIR_TARGETS) checksums_verified
151
152 .DEFAULT_GOAL = all