1#!/usr/bin/perl 2# 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 2 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <https://www.gnu.org/licenses/>. 15 16use strict; 17use warnings; 18 19use Test::More tests => 8; 20use Test::Dpkg qw(:paths); 21 22use File::Spec::Functions qw(rel2abs); 23 24use Dpkg (); 25use Dpkg::ErrorHandling; 26use Dpkg::IPC; 27use Dpkg::Vendor; 28 29my $srcdir = $ENV{srcdir} || '.'; 30my $datadir = test_get_data_path(); 31 32# Turn these into absolute names so that we can safely switch to the test 33# directory with «make -C». 34$ENV{$_} = rel2abs($ENV{$_}) foreach qw(srcdir DPKG_DATADIR DPKG_ORIGINS_DIR); 35 36# Any parallelization from the parent should be ignored, we are testing 37# the makefiles serially anyway. 38delete $ENV{MAKEFLAGS}; 39 40# Delete other variables that can affect the tests. 41delete $ENV{$_} foreach grep { m/^DEB_/ } keys %ENV; 42 43$ENV{DEB_BUILD_PATH} = rel2abs($datadir); 44 45sub test_makefile { 46 my $makefile = shift; 47 48 spawn(exec => [ $Dpkg::PROGMAKE, '-C', $datadir, '-f', $makefile ], 49 wait_child => 1, nocheck => 1); 50 ok($? == 0, "makefile $makefile computes all values correctly"); 51} 52 53sub cmd_get_vars { 54 my (@cmd) = @_; 55 my %var; 56 57 open my $cmd_fh, '-|', @cmd or subprocerr($cmd[0]); 58 while (<$cmd_fh>) { 59 chomp; 60 my ($key, $value) = split /=/, $_, 2; 61 $var{$key} = $value; 62 } 63 close $cmd_fh or subprocerr($cmd[0]); 64 65 return %var; 66} 67 68# Test makefiles. 69 70my %arch = cmd_get_vars($ENV{PERL}, "$srcdir/dpkg-architecture.pl", '-f'); 71 72delete $ENV{$_} foreach keys %arch; 73$ENV{"TEST_$_"} = $arch{$_} foreach keys %arch; 74test_makefile('architecture.mk'); 75$ENV{$_} = $arch{$_} foreach keys %arch; 76test_makefile('architecture.mk'); 77 78my %buildflag = cmd_get_vars($ENV{PERL}, "$srcdir/dpkg-buildflags.pl"); 79 80delete $ENV{$_} foreach keys %buildflag; 81$ENV{"TEST_$_"} = $buildflag{$_} foreach keys %buildflag; 82test_makefile('buildflags.mk'); 83 84my %buildtools = ( 85 AS => 'as', 86 CPP => 'gcc -E', 87 CC => 'gcc', 88 CXX => 'g++', 89 OBJC => 'gcc', 90 OBJCXX => 'g++', 91 GCJ => 'gcj', 92 F77 => 'f77', 93 FC => 'f77', 94 LD => 'ld', 95 STRIP => 'strip', 96 OBJCOPY => 'objcopy', 97 OBJDUMP => 'objdump', 98 NM => 'nm', 99 AR => 'ar', 100 RANLIB => 'ranlib', 101 PKG_CONFIG => 'pkg-config', 102); 103 104foreach my $tool (keys %buildtools) { 105 delete $ENV{$tool}; 106 $ENV{"TEST_$tool"} = "$ENV{DEB_HOST_GNU_TYPE}-$buildtools{$tool}"; 107 delete $ENV{"${tool}_FOR_BUILD"}; 108 $ENV{"TEST_${tool}_FOR_BUILD"} = "$ENV{DEB_BUILD_GNU_TYPE}-$buildtools{$tool}"; 109} 110test_makefile('buildtools.mk'); 111 112foreach my $tool (keys %buildtools) { 113 delete $ENV{${tool}}; 114 delete $ENV{"${tool}_FOR_BUILD"}; 115} 116 117test_makefile('pkg-info.mk'); 118 119test_makefile('vendor.mk'); 120test_makefile('vendor-v0.mk'); 121test_makefile('vendor-v1.mk'); 122 1231; 124