summaryrefslogtreecommitdiffstats
path: root/scripts/t/mk
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--scripts/t/mk.t123
-rw-r--r--scripts/t/mk/architecture.mk36
-rw-r--r--scripts/t/mk/buildflags.mk14
-rw-r--r--scripts/t/mk/buildtools.mk35
-rw-r--r--scripts/t/mk/debian/changelog5
-rw-r--r--scripts/t/mk/pkg-info.mk9
-rw-r--r--scripts/t/mk/vendor-v0.mk6
-rw-r--r--scripts/t/mk/vendor-v1.mk6
-rw-r--r--scripts/t/mk/vendor.mk6
9 files changed, 240 insertions, 0 deletions
diff --git a/scripts/t/mk.t b/scripts/t/mk.t
new file mode 100644
index 0000000..98c7e50
--- /dev/null
+++ b/scripts/t/mk.t
@@ -0,0 +1,123 @@
+#!/usr/bin/perl
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+use strict;
+use warnings;
+
+use Test::More tests => 8;
+use Test::Dpkg qw(:paths);
+
+use File::Spec::Functions qw(rel2abs);
+
+use Dpkg ();
+use Dpkg::ErrorHandling;
+use Dpkg::IPC;
+use Dpkg::Vendor;
+
+my $srcdir = $ENV{srcdir} || '.';
+my $datadir = test_get_data_path();
+
+# Turn these into absolute names so that we can safely switch to the test
+# directory with «make -C».
+$ENV{$_} = rel2abs($ENV{$_}) foreach qw(srcdir DPKG_DATADIR DPKG_ORIGINS_DIR);
+
+# Any parallelization from the parent should be ignored, we are testing
+# the makefiles serially anyway.
+delete $ENV{MAKEFLAGS};
+
+# Delete other variables that can affect the tests.
+delete $ENV{$_} foreach grep { m/^DEB_/ } keys %ENV;
+
+$ENV{DEB_BUILD_PATH} = rel2abs($datadir);
+
+sub test_makefile {
+ my $makefile = shift;
+
+ spawn(exec => [ $Dpkg::PROGMAKE, '-C', $datadir, '-f', $makefile ],
+ wait_child => 1, nocheck => 1);
+ ok($? == 0, "makefile $makefile computes all values correctly");
+}
+
+sub cmd_get_vars {
+ my (@cmd) = @_;
+ my %var;
+
+ open my $cmd_fh, '-|', @cmd or subprocerr($cmd[0]);
+ while (<$cmd_fh>) {
+ chomp;
+ my ($key, $value) = split /=/, $_, 2;
+ $var{$key} = $value;
+ }
+ close $cmd_fh or subprocerr($cmd[0]);
+
+ return %var;
+}
+
+# Test makefiles.
+
+my %arch = cmd_get_vars($ENV{PERL}, "$srcdir/dpkg-architecture.pl", '-f');
+
+delete $ENV{$_} foreach keys %arch;
+$ENV{"TEST_$_"} = $arch{$_} foreach keys %arch;
+test_makefile('architecture.mk');
+$ENV{$_} = $arch{$_} foreach keys %arch;
+test_makefile('architecture.mk');
+
+my %buildflag = cmd_get_vars($ENV{PERL}, "$srcdir/dpkg-buildflags.pl");
+
+delete $ENV{$_} foreach keys %buildflag;
+$ENV{"TEST_$_"} = $buildflag{$_} foreach keys %buildflag;
+test_makefile('buildflags.mk');
+
+my %buildtools = (
+ AS => 'as',
+ CPP => 'gcc -E',
+ CC => 'gcc',
+ CXX => 'g++',
+ OBJC => 'gcc',
+ OBJCXX => 'g++',
+ GCJ => 'gcj',
+ F77 => 'f77',
+ FC => 'f77',
+ LD => 'ld',
+ STRIP => 'strip',
+ OBJCOPY => 'objcopy',
+ OBJDUMP => 'objdump',
+ NM => 'nm',
+ AR => 'ar',
+ RANLIB => 'ranlib',
+ PKG_CONFIG => 'pkg-config',
+);
+
+foreach my $tool (keys %buildtools) {
+ delete $ENV{$tool};
+ $ENV{"TEST_$tool"} = "$ENV{DEB_HOST_GNU_TYPE}-$buildtools{$tool}";
+ delete $ENV{"${tool}_FOR_BUILD"};
+ $ENV{"TEST_${tool}_FOR_BUILD"} = "$ENV{DEB_BUILD_GNU_TYPE}-$buildtools{$tool}";
+}
+test_makefile('buildtools.mk');
+
+foreach my $tool (keys %buildtools) {
+ delete $ENV{${tool}};
+ delete $ENV{"${tool}_FOR_BUILD"};
+}
+
+test_makefile('pkg-info.mk');
+
+test_makefile('vendor.mk');
+test_makefile('vendor-v0.mk');
+test_makefile('vendor-v1.mk');
+
+1;
diff --git a/scripts/t/mk/architecture.mk b/scripts/t/mk/architecture.mk
new file mode 100644
index 0000000..2ac0222
--- /dev/null
+++ b/scripts/t/mk/architecture.mk
@@ -0,0 +1,36 @@
+include $(srcdir)/mk/architecture.mk
+
+test:
+ test "$(DEB_BUILD_ARCH)" = "$(TEST_DEB_BUILD_ARCH)"
+ test "$(DEB_BUILD_ARCH_ABI)" = "$(TEST_DEB_BUILD_ARCH_ABI)"
+ test "$(DEB_BUILD_ARCH_BITS)" = "$(TEST_DEB_BUILD_ARCH_BITS)"
+ test "$(DEB_BUILD_ARCH_CPU)" = "$(TEST_DEB_BUILD_ARCH_CPU)"
+ test "$(DEB_BUILD_ARCH_ENDIAN)" = "$(TEST_DEB_BUILD_ARCH_ENDIAN)"
+ test "$(DEB_BUILD_ARCH_LIBC)" = "$(TEST_DEB_BUILD_ARCH_LIBC)"
+ test "$(DEB_BUILD_ARCH_OS)" = "$(TEST_DEB_BUILD_ARCH_OS)"
+ test "$(DEB_BUILD_GNU_CPU)" = "$(TEST_DEB_BUILD_GNU_CPU)"
+ test "$(DEB_BUILD_GNU_SYSTEM)" = "$(TEST_DEB_BUILD_GNU_SYSTEM)"
+ test "$(DEB_BUILD_GNU_TYPE)" = "$(TEST_DEB_BUILD_GNU_TYPE)"
+ test "$(DEB_BUILD_MULTIARCH)" = "$(TEST_DEB_BUILD_MULTIARCH)"
+ test "$(DEB_HOST_ARCH)" = "$(TEST_DEB_HOST_ARCH)"
+ test "$(DEB_HOST_ARCH_ABI)" = "$(TEST_DEB_HOST_ARCH_ABI)"
+ test "$(DEB_HOST_ARCH_BITS)" = "$(TEST_DEB_HOST_ARCH_BITS)"
+ test "$(DEB_HOST_ARCH_CPU)" = "$(TEST_DEB_HOST_ARCH_CPU)"
+ test "$(DEB_HOST_ARCH_ENDIAN)" = "$(TEST_DEB_HOST_ARCH_ENDIAN)"
+ test "$(DEB_HOST_ARCH_LIBC)" = "$(TEST_DEB_HOST_ARCH_LIBC)"
+ test "$(DEB_HOST_ARCH_OS)" = "$(TEST_DEB_HOST_ARCH_OS)"
+ test "$(DEB_HOST_GNU_CPU)" = "$(TEST_DEB_HOST_GNU_CPU)"
+ test "$(DEB_HOST_GNU_SYSTEM)" = "$(TEST_DEB_HOST_GNU_SYSTEM)"
+ test "$(DEB_HOST_GNU_TYPE)" = "$(TEST_DEB_HOST_GNU_TYPE)"
+ test "$(DEB_HOST_MULTIARCH)" = "$(TEST_DEB_HOST_MULTIARCH)"
+ test "$(DEB_TARGET_ARCH)" = "$(TEST_DEB_TARGET_ARCH)"
+ test "$(DEB_TARGET_ARCH_ABI)" = "$(TEST_DEB_TARGET_ARCH_ABI)"
+ test "$(DEB_TARGET_ARCH_BITS)" = "$(TEST_DEB_TARGET_ARCH_BITS)"
+ test "$(DEB_TARGET_ARCH_CPU)" = "$(TEST_DEB_TARGET_ARCH_CPU)"
+ test "$(DEB_TARGET_ARCH_ENDIAN)" = "$(TEST_DEB_TARGET_ARCH_ENDIAN)"
+ test "$(DEB_TARGET_ARCH_LIBC)" = "$(TEST_DEB_TARGET_ARCH_LIBC)"
+ test "$(DEB_TARGET_ARCH_OS)" = "$(TEST_DEB_TARGET_ARCH_OS)"
+ test "$(DEB_TARGET_GNU_CPU)" = "$(TEST_DEB_TARGET_GNU_CPU)"
+ test "$(DEB_TARGET_GNU_SYSTEM)" = "$(TEST_DEB_TARGET_GNU_SYSTEM)"
+ test "$(DEB_TARGET_GNU_TYPE)" = "$(TEST_DEB_TARGET_GNU_TYPE)"
+ test "$(DEB_TARGET_MULTIARCH)" = "$(TEST_DEB_TARGET_MULTIARCH)"
diff --git a/scripts/t/mk/buildflags.mk b/scripts/t/mk/buildflags.mk
new file mode 100644
index 0000000..feed5e3
--- /dev/null
+++ b/scripts/t/mk/buildflags.mk
@@ -0,0 +1,14 @@
+DEB_CPPFLAGS_MAINT_APPEND = -DTEST_MK=test
+
+include $(srcdir)/mk/buildflags.mk
+
+test:
+ test "$(CFLAGS)" = "$(TEST_CFLAGS)"
+ test "$(CPPFLAGS)" = "$(TEST_CPPFLAGS) -DTEST_MK=test"
+ test "$(CXXFLAGS)" = "$(TEST_CXXFLAGS)"
+ test "$(FCFLAGS)" = "$(TEST_FCFLAGS)"
+ test "$(FFLAGS)" = "$(TEST_FFLAGS)"
+ test "$(GCJFLAGS)" = "$(TEST_GCJFLAGS)"
+ test "$(LDFLAGS)" = "$(TEST_LDFLAGS)"
+ test "$(OBJCFLAGS)" = "$(TEST_OBJCFLAGS)"
+ test "$(OBJCXXFLAGS)" = "$(TEST_OBJCXXFLAGS)"
diff --git a/scripts/t/mk/buildtools.mk b/scripts/t/mk/buildtools.mk
new file mode 100644
index 0000000..0077791
--- /dev/null
+++ b/scripts/t/mk/buildtools.mk
@@ -0,0 +1,35 @@
+include $(srcdir)/mk/buildtools.mk
+
+test:
+ test "$(AS)" = "$(TEST_AS)"
+ test "$(AS_FOR_BUILD)" = "$(TEST_AS_FOR_BUILD)"
+ test "$(CC)" = "$(TEST_CC)"
+ test "$(CC_FOR_BUILD)" = "$(TEST_CC_FOR_BUILD)"
+ test "$(CXX)" = "$(TEST_CXX)"
+ test "$(CXX_FOR_BUILD)" = "$(TEST_CXX_FOR_BUILD)"
+ test "$(OBJC)" = "$(TEST_OBJC)"
+ test "$(OBJC_FOR_BUILD)" = "$(TEST_OBJC_FOR_BUILD)"
+ test "$(OBJCXX)" = "$(TEST_OBJCXX)"
+ test "$(OBJCXX_FOR_BUILD)" = "$(TEST_OBJCXX_FOR_BUILD)"
+ test "$(GCJ)" = "$(TEST_GCJ)"
+ test "$(GCJ_FOR_BUILD)" = "$(TEST_GCJ_FOR_BUILD)"
+ test "$(F77)" = "$(TEST_F77)"
+ test "$(F77_FOR_BUILD)" = "$(TEST_F77_FOR_BUILD)"
+ test "$(FC)" = "$(TEST_FC)"
+ test "$(FC_FOR_BUILD)" = "$(TEST_FC_FOR_BUILD)"
+ test "$(LD)" = "$(TEST_LD)"
+ test "$(LD_FOR_BUILD)" = "$(TEST_LD_FOR_BUILD)"
+ test "$(STRIP)" = "$(TEST_STRIP)"
+ test "$(STRIP_FOR_BUILD)" = "$(TEST_STRIP_FOR_BUILD)"
+ test "$(OBJCOPY)" = "$(TEST_OBJCOPY)"
+ test "$(OBJCOPY_FOR_BUILD)" = "$(TEST_OBJCOPY_FOR_BUILD)"
+ test "$(OBJDUMP)" = "$(TEST_OBJDUMP)"
+ test "$(OBJDUMP_FOR_BUILD)" = "$(TEST_OBJDUMP_FOR_BUILD)"
+ test "$(NM)" = "$(TEST_NM)"
+ test "$(NM_FOR_BUILD)" = "$(TEST_NM_FOR_BUILD)"
+ test "$(AR)" = "$(TEST_AR)"
+ test "$(AR_FOR_BUILD)" = "$(TEST_AR_FOR_BUILD)"
+ test "$(RANLIB)" = "$(TEST_RANLIB)"
+ test "$(RANLIB_FOR_BUILD)" = "$(TEST_RANLIB_FOR_BUILD)"
+ test "$(PKG_CONFIG)" = "$(TEST_PKG_CONFIG)"
+ test "$(PKG_CONFIG_FOR_BUILD)" = "$(TEST_PKG_CONFIG_FOR_BUILD)"
diff --git a/scripts/t/mk/debian/changelog b/scripts/t/mk/debian/changelog
new file mode 100644
index 0000000..728c8ec
--- /dev/null
+++ b/scripts/t/mk/debian/changelog
@@ -0,0 +1,5 @@
+source (1:2:3.4-5-6) suite; urgency=low
+
+ * Initial release.
+
+ -- Dpkg Developers <debian-dpkg@lists.debian.org> Tue, 04 Aug 2015 16:13:50 +0200
diff --git a/scripts/t/mk/pkg-info.mk b/scripts/t/mk/pkg-info.mk
new file mode 100644
index 0000000..22a2bf4
--- /dev/null
+++ b/scripts/t/mk/pkg-info.mk
@@ -0,0 +1,9 @@
+include $(srcdir)/mk/pkg-info.mk
+
+test:
+ test "$(DEB_SOURCE)" = "source"
+ test "$(DEB_VERSION)" = "1:2:3.4-5-6"
+ test "$(DEB_VERSION_EPOCH_UPSTREAM)" = "1:2:3.4-5"
+ test "$(DEB_VERSION_UPSTREAM_REVISION)" = "2:3.4-5-6"
+ test "$(DEB_VERSION_UPSTREAM)" = "2:3.4-5"
+ test "$(DEB_DISTRIBUTION)" = "suite"
diff --git a/scripts/t/mk/vendor-v0.mk b/scripts/t/mk/vendor-v0.mk
new file mode 100644
index 0000000..602a8c6
--- /dev/null
+++ b/scripts/t/mk/vendor-v0.mk
@@ -0,0 +1,6 @@
+dpkg_vendor_derives_from = $(dpkg_vendor_derives_from_v0)
+
+include $(srcdir)/mk/vendor.mk
+
+test:
+ test "$(shell $(call dpkg_vendor_derives_from,debian))" = "yes"
diff --git a/scripts/t/mk/vendor-v1.mk b/scripts/t/mk/vendor-v1.mk
new file mode 100644
index 0000000..11c1314
--- /dev/null
+++ b/scripts/t/mk/vendor-v1.mk
@@ -0,0 +1,6 @@
+include $(srcdir)/mk/vendor.mk
+
+dpkg_vendor_derives_from = $(dpkg_vendor_derives_from_v1)
+
+test:
+ test "$(call dpkg_vendor_derives_from,debian)" = "yes"
diff --git a/scripts/t/mk/vendor.mk b/scripts/t/mk/vendor.mk
new file mode 100644
index 0000000..4e0d9ff
--- /dev/null
+++ b/scripts/t/mk/vendor.mk
@@ -0,0 +1,6 @@
+include $(srcdir)/mk/vendor.mk
+
+test:
+ test "$(DEB_VENDOR)" = "Debian"
+ test "$(DEB_PARENT_VENDOR)" = ""
+ test "$(shell $(call dpkg_vendor_derives_from,debian))" = "yes"