Ensure README.Debian is installed in gcc-mingw-w64-base (Closes: #757259).
[collab-maint/gcc-mingw-w64.git] / debian / rules
1 #!/usr/bin/make -f
2 # -*- makefile -*-
3 # Build gcc-mingw-w64 using gcc-4.6-source.
4 # Copyright © 2010 Stephen Kitt <steve@sk2.org>
5
6 # Uncomment this to turn on verbose mode.
7 #export DH_VERBOSE=1
8
9 target_version := 4.6
10
11 top_dir := $(shell pwd)
12 gcc_dir := /usr/src/gcc-$(target_version)
13 upstream_dir := $(top_dir)/src
14 build_dir := $(top_dir)/build
15 stampdir := $(top_dir)/stamp
16 deb_version := $(shell dpkg-query -W -f="\$${Version}\n" gcc-$(target_version)-source)
17 deb_upstream_version := $(shell echo $(deb_version) | cut -d- -f1)
18 base_version := $(shell echo $(deb_version) | sed -e 's/\([1-9]\.[0-9]\).*-.*/\1/')
19
20 # Include the rules variant - symlink rules.bootstrap to produce the
21 # minimal gcc required to build mingw-w64, or rules.full to produce
22 # the full gcc.
23 include debian/rules.variant
24
25 targets := i686-w64-mingw32 x86_64-w64-mingw32
26
27 CFLAGS = $(shell dpkg-buildflags --get CFLAGS)
28 CFLAGS += -Wall
29 export CFLAGS
30 LDFLAGS = $(shell dpkg-buildflags --get LDFLAGS)
31 LDFLAGS += -Wl,--as-needed
32 export LDFLAGS
33
34 # Number of jobs to run for build
35 ifeq ($(USE_NJOBS),no)
36   NJOBS :=
37   USE_CPUS := 1
38 else
39   # Increase to 192 if building Java
40   MEM_PER_CPU = 128
41   NUM_CPUS := $(shell if echo $(USE_NJOBS) | grep -q -E '^[0-9]+$$'; \
42                         then echo $(USE_NJOBS); \
43                         else getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1; fi)
44   USE_CPUS := $(shell mt=`awk '/^MemTotal/ { print $$2 }' /proc/meminfo`; \
45                         awk -vn=$(NUM_CPUS) -vmt=$$mt -vm=$(MEM_PER_CPU) \
46                                 'END { mt/=1024; n2 = int(mt/m); print n==1 ? 1 : n2<n+1 ? n2 : n+1}' < /dev/null)
47   ifneq (,$(strip $(USE_CPUS)))
48     NJOBS := -j $(USE_CPUS)
49   endif
50 endif
51
52 # Support parallel=<n> in DEB_BUILD_OPTIONS (see #209008)
53 ifneq (,$(filter parallel=%,$(subst $(COMMA), ,$(DEB_BUILD_OPTIONS))))
54   NJOBS := -j $(subst parallel=,,$(filter parallel=%,$(subst $(COMMA), ,$(DEB_BUILD_OPTIONS))))
55 endif
56
57 # Patch targets
58 patchdir = $(gcc_dir)/debian/patches
59 series_file = series
60 unpack_stamp = $(stampdir)/unpack
61 patch_stamp = $(stampdir)/patch
62 GFDL_INVARIANT_FREE=yes
63 srcdir=$(upstream_dir)
64 include $(gcc_dir)/debian/rules.patch
65
66 unpack: $(unpack_stamp)
67 $(unpack_stamp):
68         tar xf $(gcc_dir)/gcc-*.tar.*
69         rm -rf $(upstream_dir)
70         mv gcc-$(deb_upstream_version) $(upstream_dir)
71         # Apply our extra patches here...
72         # We can't use a separate target for this because the patches
73         # need to be applied before gcc-4.6-source's
74         patch -p0 < debian/patches/mingw-include.patch
75         patch -p0 < debian/patches/disable-multilib.patch
76         mkdir -p $(stampdir)
77         touch $@
78
79 clean:
80         dh_testdir
81         dh_testroot
82         rm -rf $(stampdir) $(build_dir) $(upstream_dir) .pc autotools_files series
83         dh_clean
84
85 # Configuration constructed as in the gcc package
86 PF=usr
87 libdir=lib
88 libexecdir=$(PF)/$(libdir)
89
90 # Standard Debian configuration flags
91 # TODO Re-enable shared, multilib and linker-build-id
92 CONFFLAGS = \
93         --prefix=/$(PF) \
94         --disable-shared \
95         --disable-multilib \
96         --enable-linker-build-id \
97         --with-system-zlib \
98         --libexecdir=/$(libexecdir) \
99         --without-included-gettext
100 CONFFLAGS += \
101         --libdir=/$(PF)/$(libdir) \
102         --enable-libstdcxx-time=yes \
103         --with-tune=generic
104 # MinGW-w64 flags
105 CONFFLAGS += \
106         --enable-version-specific-runtime-libs
107 # version-specific-runtime-libs puts target-specific libraries in
108 # /usr/lib/gcc rather than /usr/$(target)
109 # Languages
110 CONFFLAGS += \
111         --enable-languages=$(languages)
112 #CONFFLAGS = --disable-shared --disable-multilib --prefix=/usr --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-languages=c,c++,fortran --with-gnu-ld --with-gnu-as --enable-leading-mingw64-underscores
113 # LTO
114 CONFFLAGS += \
115         --enable-lto \
116         --with-plugin-ld
117 # Dynamic strings (as used upstream)
118 CONFFLAGS += \
119         --enable-fully-dynamic-string
120
121 # Patches applied or unapplied after the upstream sources have been
122 # unpacked and patched using the gcc-4.6-source package's patches
123 mingw-w64-patch: mingw-w64-patch-stamp
124 mingw-w64-patch-stamp: $(patch_stamp)
125         # Remove the patch building libstdc++_pic.a before configuring
126         patch -R -p2 -d$(upstream_dir) < $(gcc_dir)/debian/patches/libstdc++-pic.diff
127         # Fix the breakage introduced by the Ada Subversion update
128         # Using "-N" should allow the build to work if this is fixed "upstream"
129         patch -N -p2 -d$(upstream_dir) < debian/patches/g-socthi-mingw-tabs.patch
130         touch $@
131
132 configure: configure-stamp
133 configure-stamp: mingw-w64-patch-stamp
134         dh_testdir
135         set -e; \
136         for target in $(targets); do \
137                 dh_auto_configure -B$(build_dir)/$$target -D$(upstream_dir) -- \
138                         $(CONFFLAGS) \
139                         --target=$$target \
140                         --with-gxx-include-dir=/$(PF)/include/c++/$(base_version) \
141                         --with-as=/usr/bin/$$target-as \
142                         --with-ld=/usr/bin/$$target-ld; \
143         done
144         touch $@
145
146 build: build-stamp
147 build-stamp: configure-stamp
148         dh_testdir
149         set -e; \
150         for target in $(targets); do \
151                 cd $(build_dir)/$$target && $(MAKE) $(NJOBS) $(BUILD_TARGET); \
152         done
153         touch $@
154
155 install: install-stamp
156 install-stamp: build-stamp
157         dh_testdir
158         dh_testroot
159         dh_prep
160         set -e; \
161         for target in $(targets); do \
162                 cd $(build_dir)/$$target && $(MAKE) DESTDIR=$(top_dir)/debian/$(package) $(INSTALL_TARGET); \
163         done
164
165         # Remove files which conflict with other packages
166         # gcc-$(target_version)-locales
167         rm -rf $(top_dir)/debian/$(package)/usr/share/locale
168         # binutils-dev
169         rm -f $(top_dir)/debian/$(package)/usr/lib/libiberty.a
170         # libstdc++6-$(target_version)-dbg (potentially)
171         rm -rf $(top_dir)/debian/$(package)/usr/share/gcc-*/python
172         # libstdc++6-$(target_version)-dev
173         ls -1 $(top_dir)/debian/$(package)/usr/include/c++/$(base_version)/|grep -v w64-mingw32|xargs -I{} rm -rf $(top_dir)/debian/$(package)/usr/include/c++/$(base_version)/{}
174         # -doc packages
175         rm -rf $(top_dir)/debian/$(package)/usr/share/info
176         rm -rf $(top_dir)/debian/$(package)/usr/share/man/man7
177
178         # No need to ship empty manpages
179         rm -rf $(top_dir)/debian/$(package)/usr/share/man/man1
180
181         # Drop .la files
182         find $(top_dir)/debian/$(package) -name \*.la -delete
183
184         # Move libraries to base directories and add version-specific links
185         for gnu_upstream_version in $$(basename debian/gcc-mingw-w64/usr/share/gcc-*|cut -d- -f2); do \
186                 if [ "$$gnu_upstream_version" != "$(base_version)" ]; then \
187                         [ -d $(top_dir)/debian/$(package)/usr/include/c++ ] && cd $(top_dir)/debian/$(package)/usr/include/c++ && ln -s $(base_version) $$gnu_upstream_version || true; \
188                         for target in $(targets); do \
189                                 cd $(top_dir)/debian/$(package)/$(PF)/lib/gcc/$$target && \
190                                 mv $$gnu_upstream_version $(base_version) && \
191                                 ln -s $(base_version) $$gnu_upstream_version; \
192                         done; \
193                 fi; \
194         done
195
196         for i in 1 2; do \
197                 find $(top_dir)/debian/$(package)/ -type d -empty | while read i; do rmdir $$i; done; \
198         done
199
200         touch $@
201
202 binary-indep:
203 binary-arch: build install
204         dh_testdir
205         dh_testroot
206         dh_installdocs
207         dh_installman
208         dh_installchangelogs $(upstream_dir)/ChangeLog
209         # Strip the binaries
210         dh_strip -Xw64-mingw32/lib -Xw64-mingw32/$(base_version)/lib -Xw64-mingw32/$(base_version)/adalib
211         # Special processing for the libraries
212 ifeq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
213         strip --remove-section=.comment --remove-section=.note --strip-unneeded $(patsubst %,$(top_dir)/debian/$(package)/usr/lib/gcc/%/$(target_version)/liblto_plugin.so.0.0.0,$(targets))
214         for target in $(targets); do \
215                 $$target-strip --strip-unneeded $(top_dir)/debian/$(package)/usr/lib/gcc/$$target/$(target_version)/lib*.a $(top_dir)/debian/$(package)/usr/lib/gcc/$$target/$(target_version)/adalib/lib*.a; \
216         done
217 endif
218         dh_lintian
219         dh_compress
220         dh_fixperms
221         dh_installdeb
222         dh_shlibdeps
223         dh_gencontrol -- -v$(deb_version) -Vlocal:Version=$(deb_upstream_version)
224         dh_md5sums
225         dh_builddeb
226
227 binary: binary-indep binary-arch
228
229 .PHONY: binary-indep binary-arch binary clean build install configure mingw-w64-patch