e53cce1b2ca4ece2b4ececbad140f2f26f7aa374
[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.
5 #
6 # Among other things, this Makefile requires MinGW-w64 (i686 and x86_64
7 # versions) and a windeps.wim containing the following images:
8 #
9 #       - libxml2-2.9.2 [contents of ftp://xmlsoft.org/libxml2/libxml2-2.9.2.tar.gz]
10 #       - winpthreads-4.0.4 [directory mingw-w64-libraries/winpthreads from http://downloads.sourceforge.net/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v4.0.4.tar.bz2]
11 #       - win-iconv-0.0.6 [contents of https://win-iconv.googlecode.com/files/win-iconv-0.0.6.tar.bz2]
12
13 ARCHITECTURES           := i686 x86_64
14 LIBXML_VERSION          := 2-2.9.2
15 WINPTHREADS_VERSION     := -4.0.4
16 WINICONV_VERSION        := -0.0.6
17
18 LIBXML_SRCDIR           := libxml$(LIBXML_VERSION)
19 SOURCE_TARGETS          += $(LIBXML_SRCDIR)
20 $(LIBXML_SRCDIR):
21         wimapply --unix-data windeps.wim $(LIBXML_SRCDIR) $(LIBXML_SRCDIR)
22         cp $(LIBXML_SRCDIR)/COPYING COPYING.libxml2
23 MAKE_CLEAN_FILES += $(LIBXML_SRCDIR) COPYING.libxml2
24
25 WINPTHREADS_SRCDIR      := winpthreads$(WINPTHREADS_VERSION)
26 SOURCE_TARGETS          += $(WINPTHREADS_SRCDIR)
27 $(WINPTHREADS_SRCDIR):
28         wimapply --unix-data windeps.wim $(WINPTHREADS_SRCDIR) $(WINPTHREADS_SRCDIR)
29         cp $(WINPTHREADS_SRCDIR)/COPYING COPYING.winpthreads
30 MAKE_CLEAN_FILES += $(WINPTHREADS_SRCDIR) COPYING.winpthreads
31
32 WINICONV_SRCDIR         := win-iconv$(WINICONV_VERSION)
33 SOURCE_TARGETS          += $(WINICONV_SRCDIR)
34 $(WINICONV_SRCDIR):
35         wimapply --unix-data windeps.wim $(WINICONV_SRCDIR) $(WINICONV_SRCDIR)
36 # win-iconv is public domain, so there's no license file.
37 MAKE_CLEAN_FILES        += $(WINICONV_SRCDIR)
38
39 #
40 # declare_libxml_target(arch)
41 #
42 define declare_libxml_target
43 libxml_$(1):$(LIBXML_SRCDIR)
44         builddir=build_libxml_$(1);                             \
45         rm -rf $$$$builddir;                                    \
46         mkdir $$$$builddir;                                     \
47         cd $$$$builddir;                                        \
48         ../$(LIBXML_SRCDIR)/configure                           \
49                 --host=$(1)-w64-mingw32                         \
50                 --enable-static                                 \
51                 --disable-shared                                \
52                 --prefix=$$$$PWD/../sysroot_$(1)                \
53                 CFLAGS=-Os                                      \
54                 --with-minimum                                  \
55                 --without-lzma                                  \
56                 --with-tree                                     \
57                 --with-writer;                                  \
58         $(MAKE) install;                                        \
59         rm -f ../sysroot_$(1)/lib/libxml2.la;
60
61 $(1)_BUILD_TARGETS += libxml_$(1)
62 MAKE_CLEAN_FILES += build_libxml_$(1)
63 endef
64
65 #
66 # declare_winpthreads_target(arch)
67 #
68 define declare_winpthreads_target
69 winpthreads_$(1):$(WINPTHREADS_SRCDIR)
70         builddir=build_winpthreads_$(1);                        \
71         rm -rf $$$$builddir;                                    \
72         cp -r $(WINPTHREADS_SRCDIR) $$$$builddir;               \
73         cd $$$$builddir;                                        \
74         ./configure                                             \
75                 --host=$(1)-w64-mingw32                         \
76                 --enable-static                                 \
77                 --disable-shared                                \
78                 --prefix=$$$$PWD/../sysroot_$(1)                \
79                 CFLAGS=-O2;                                     \
80         $(MAKE) install;                                        \
81         sed -i 's/if defined DLL_EXPORT/if 0/' ../sysroot_$(1)/include/pthread.h;
82
83 $(1)_BUILD_TARGETS += winpthreads_$(1)
84 MAKE_CLEAN_FILES += build_winpthreads_$(1)
85 endef
86
87 #
88 # declare_winiconv_target(arch)
89 #
90 define declare_winiconv_target
91 winiconv_$(1):$(WINICONV_SRCDIR)
92         builddir=build_winiconv_$(1);                           \
93         rm -rf $$$$builddir;                                    \
94         cp -r $(WINICONV_SRCDIR) $$$$builddir;                  \
95         cd $$$$builddir;                                        \
96         $(MAKE) CC=$(1)-w64-mingw32-gcc                         \
97                 AR=$(1)-w64-mingw32-ar                          \
98                 RANLIB=$(1)-w64-mingw32-ranlib                  \
99                 DLLTOOL=$(1)-w64-mingw32-dlltool                \
100                 CFLAGS=-O2                                      \
101                 prefix=$$$$PWD/../sysroot_$(1)                  \
102                 install;                                        \
103         rm -f ../sysroot_$(1)/lib/libiconv.dll.a;
104
105 $(1)_BUILD_TARGETS += winiconv_$(1)
106 MAKE_CLEAN_FILES += build_winiconv_$(1)
107 endef
108
109 #
110 # declare_arch_targets(arch)
111 #
112 define declare_arch_targets
113 $(eval $(call declare_libxml_target,$(1)))
114 $(eval $(call declare_winpthreads_target,$(1)))
115 $(eval $(call declare_winiconv_target,$(1)))
116
117 sysroot_$(1): $($(1)_BUILD_TARGETS)
118
119 ALL_SYSROOTS += sysroot_$(1)
120 MAKE_CLEAN_FILES += sysroot_$(1)
121 endef
122
123 $(foreach arch,$(ARCHITECTURES),$(eval $(call declare_arch_targets,$(arch))))
124
125 all: $(ALL_SYSROOTS)
126
127 clean:
128         rm -rf $(MAKE_CLEAN_FILES)
129
130 .PHONY: all clean $(SOURCE_TARGETS)
131
132 .DEFAULT_GOAL = all