| 1 |
#!/usr/bin/make -f |
| 2 |
# -*- makefile -*- |
| 3 |
# Copyright © 2010-2020, 2022-2026 Stephen Kitt <[email protected]> |
| 4 |
# |
| 5 |
# This program is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU Lesser General Public License as |
| 7 |
# published by the Free Software Foundation, either version 2.1 of the |
| 8 |
# License, or (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
# Uncomment this to turn on verbose mode. |
| 19 |
#export DH_VERBOSE=1 |
| 20 |
|
| 21 |
# Disable package mangling in Launchpad; it currently fails to parse |
| 22 |
# Built-Using, which results in build failures |
| 23 |
export NO_PKG_MANGLE=1 |
| 24 |
|
| 25 |
include /usr/share/dpkg/pkg-info.mk |
| 26 |
include /usr/share/dpkg/architecture.mk |
| 27 |
|
| 28 |
top_dir := $(shell pwd) |
| 29 |
gdb_dir := /usr/src |
| 30 |
upstream_dir := $(top_dir)/upstream |
| 31 |
build_gdb_dir := $(top_dir)/build-gdb |
| 32 |
build_gdbserver_dir := $(top_dir)/build-gdbserver |
| 33 |
source_version := $(shell dpkg-query -W -f="\$${Version}\n" gdb-source) |
| 34 |
deb_version := $(source_version)+$(DEB_VERSION) |
| 35 |
deb_upstream_version := $(shell echo $(deb_version) | cut -d- -f1) |
| 36 |
gnu_upstream_version := $(shell echo $(deb_upstream_version) | cut -d. -f1-3) |
| 37 |
package := gdb-mingw-w64 |
| 38 |
|
| 39 |
# Targets where the compiler takes a thread-model suffix have that suffix added |
| 40 |
targets32 := i686-w64-mingw32-posix |
| 41 |
targets64 := x86_64-w64-mingw32-posix x86_64-w64-mingw32ucrt |
| 42 |
|
| 43 |
# Full hardening for Debian-targeted builds |
| 44 |
dpkg_buildflags_arch = DEB_BUILD_MAINT_OPTIONS="hardening=+all" dpkg-buildflags |
| 45 |
|
| 46 |
# Windows targets don't support relro, bindnow or pie |
| 47 |
# We disable PE timestamps to build reproducibly |
| 48 |
# We disable format because the gdb build tries to do so (partially) |
| 49 |
# anyway, and breaks the build with -Werror=format-security as a result |
| 50 |
# We link libstdc++ and libgcc statically to avoid needing the DLLs |
| 51 |
# Specifying the host architecture ensures dpkg-buildflags doesn't attempt |
| 52 |
# to use architecture-specific flags irrelevant for i686 or x86_64 |
| 53 |
dpkg_buildflags_indep_32 = DEB_HOST_ARCH=i386 DEB_BUILD_MAINT_OPTIONS="hardening=-relro,-bindnow,-pie,-format qa=-elfpackagemetadata" DEB_LDFLAGS_MAINT_APPEND="-Xlinker --no-insert-timestamp -static" dpkg-buildflags |
| 54 |
dpkg_buildflags_indep_64 = DEB_HOST_ARCH=amd64 DEB_BUILD_MAINT_OPTIONS="hardening=-relro,-bindnow,-pie,-format qa=-elfpackagemetadata" DEB_LDFLAGS_MAINT_APPEND="-Xlinker --no-insert-timestamp -static" dpkg-buildflags |
| 55 |
|
| 56 |
spelling = grep -rl "$(1)" $(upstream_dir) | xargs -r sed -i "s/$(1)/$(2)/g" |
| 57 |
|
| 58 |
%: |
| 59 |
dh $@ |
| 60 |
|
| 61 |
unpack-stamp: |
| 62 |
tar xf $(gdb_dir)/gdb.tar.* |
| 63 |
rm -rf $(upstream_dir) |
| 64 |
mv gdb $(upstream_dir) |
| 65 |
$(call spelling,occurences,occurrences) |
| 66 |
$(call spelling,Unkown,Unknown) |
| 67 |
$(call spelling,vaild,valid) |
| 68 |
touch $@ |
| 69 |
|
| 70 |
override_dh_auto_clean: |
| 71 |
dh_auto_clean |
| 72 |
rm -rf *-stamp $(build_gdb_dir) $(build_gdbserver_dir) $(upstream_dir) |
| 73 |
|
| 74 |
override_dh_auto_configure-arch: unpack-stamp |
| 75 |
set -e; \ |
| 76 |
for target in $(targets32) $(targets64); do \ |
| 77 |
target="$${target%-posix}"; \ |
| 78 |
mkdir -p $(build_gdb_dir)/$$target; \ |
| 79 |
cd $(build_gdb_dir)/$$target; \ |
| 80 |
$(upstream_dir)/configure \ |
| 81 |
--build=$(DEB_BUILD_GNU_TYPE) \ |
| 82 |
--prefix=/usr --enable-lto \ |
| 83 |
--with-system-readline --with-system-zlib \ |
| 84 |
--enable-tui --with-expat --with-python=python3 \ |
| 85 |
--without-babeltrace \ |
| 86 |
--target=$$target --disable-werror \ |
| 87 |
$(shell $(dpkg_buildflags_arch) --export=cmdline); \ |
| 88 |
done |
| 89 |
|
| 90 |
# We're only interested in gdbserver; that also requires gnulib, libiberty, and gdbsupport |
| 91 |
gdbserver_projects := gnulib libiberty gdbsupport gdbserver |
| 92 |
override_dh_auto_configure-indep: unpack-stamp |
| 93 |
set -e; \ |
| 94 |
for target in $(targets32); do \ |
| 95 |
suffix=; \ |
| 96 |
if [ "$$target" != "$${target%-posix}" ]; then \ |
| 97 |
suffix=-posix; \ |
| 98 |
fi; \ |
| 99 |
target="$${target%-posix}"; \ |
| 100 |
for project in $(gdbserver_projects); do \ |
| 101 |
mkdir -p $(build_gdbserver_dir)/$$target/$$project; \ |
| 102 |
cd $(build_gdbserver_dir)/$$target/$$project; \ |
| 103 |
sh $(upstream_dir)/$$project/configure \ |
| 104 |
--build=$(DEB_BUILD_GNU_TYPE) \ |
| 105 |
--host=$$target --target=$$target \ |
| 106 |
CC=$$target-gcc$$suffix CXX=$$target-g++$$suffix \ |
| 107 |
--disable-werror \ |
| 108 |
$(shell $(dpkg_buildflags_indep_32) --export=cmdline); \ |
| 109 |
done; \ |
| 110 |
done |
| 111 |
for target in $(targets64); do \ |
| 112 |
suffix=; \ |
| 113 |
if [ "$$target" != "$${target%-posix}" ]; then \ |
| 114 |
suffix=-posix; \ |
| 115 |
fi; \ |
| 116 |
target="$${target%-posix}"; \ |
| 117 |
for project in $(gdbserver_projects); do \ |
| 118 |
mkdir -p $(build_gdbserver_dir)/$$target/$$project; \ |
| 119 |
cd $(build_gdbserver_dir)/$$target/$$project; \ |
| 120 |
sh $(upstream_dir)/$$project/configure \ |
| 121 |
--build=$(DEB_BUILD_GNU_TYPE) \ |
| 122 |
--host=$$target --target=$$target \ |
| 123 |
CC=$$target-gcc$$suffix CXX=$$target-g++$$suffix \ |
| 124 |
--disable-werror \ |
| 125 |
$(shell $(dpkg_buildflags_indep_64) --export=cmdline); \ |
| 126 |
done; \ |
| 127 |
done |
| 128 |
|
| 129 |
override_dh_auto_build-arch: |
| 130 |
set -e; \ |
| 131 |
for target in $(targets32) $(targets64); do \ |
| 132 |
target="$${target%-posix}"; \ |
| 133 |
$(shell $(dpkg_buildflags_arch) --export=sh); \ |
| 134 |
dh_auto_build --parallel -B$(build_gdb_dir)/$$target -- V=1; \ |
| 135 |
done |
| 136 |
|
| 137 |
override_dh_auto_build-indep: |
| 138 |
set -e; \ |
| 139 |
for target in $(targets32); do \ |
| 140 |
target="$${target%-posix}"; \ |
| 141 |
for project in $(gdbserver_projects); do \ |
| 142 |
$(shell $(dpkg_buildflags_indep_32) --export=sh); \ |
| 143 |
dh_auto_build --parallel -B$(build_gdbserver_dir)/$$target/$$project -- V=1; \ |
| 144 |
done; \ |
| 145 |
done; \ |
| 146 |
for target in $(targets64); do \ |
| 147 |
target="$${target%-posix}"; \ |
| 148 |
for project in $(gdbserver_projects); do \ |
| 149 |
$(shell $(dpkg_buildflags_indep_64) --export=sh); \ |
| 150 |
dh_auto_build --parallel -B$(build_gdbserver_dir)/$$target/$$project -- V=1; \ |
| 151 |
done; \ |
| 152 |
done |
| 153 |
|
| 154 |
override_dh_auto_install: |
| 155 |
set -e; \ |
| 156 |
for target in $(targets32) $(targets64); do \ |
| 157 |
target="$${target%-posix}"; \ |
| 158 |
dh_auto_install -B$(build_gdb_dir)/$$target; \ |
| 159 |
done |
| 160 |
# Drop files which will conflict with other packages |
| 161 |
rm -rf debian/tmp/usr/include |
| 162 |
rm -rf debian/tmp/usr/lib |
| 163 |
rm -rf debian/tmp/usr/share/gdb |
| 164 |
rm -rf debian/tmp/usr/share/info |
| 165 |
rm -rf debian/tmp/usr/share/locale |
| 166 |
rm -rf debian/tmp/usr/share/man |
| 167 |
|
| 168 |
override_dh_installchangelogs: |
| 169 |
dh_installchangelogs $(upstream_dir)/ChangeLog |
| 170 |
|
| 171 |
override_dh_gencontrol: |
| 172 |
dh_gencontrol -- -v$(deb_version) -Vlocal:Version=$(deb_upstream_version) -Vgdb:Version=$(source_version) |
| 173 |
|
| 174 |
override_dh_strip-indep: |
| 175 |
i686-w64-mingw32-strip debian/gdb-mingw-w64-target/usr/share/win32/*.exe |
| 176 |
x86_64-w64-mingw32-strip debian/gdb-mingw-w64-target/usr/share/win64/*.exe |
| 177 |
x86_64-w64-mingw32ucrt-strip debian/gdb-mingw-w64-target/usr/share/ucrt64/*.exe |