example implementation (was: Re: DRAFT: Fixing the architecture query options of dpkg.
On Fri, Jan 08, 1999 at 11:34:18AM -0600, Manoj Srivastava wrote:
> I think that having a stand alne script that can be invoked at
> will is better than embedding it in dpkg-buildpackage. After all, I
> may need to know the GNU OS independently of building the whole
> package, in some script.
Hello,
attached is an example script that returns environment variables.
There is a question at the end of the message, please answer if you can.
===============================================================================
Debian GNU/Linux dpkg-architecture 0.0.1. Copyright (C) 1998 Marcus Brinkmann.
This is free software; see the GNU General Public Licence version 2
or later for copying conditions. There is NO warranty.
Usage:
dpkg-architecture [<option> ...] [<action>]
Options:
-a<debian-arch> set Debian architecture
-t<gnu-system> set GNU system type
Actions:
-l list environment variables (default)
-s print command to set environment variables
-u print command to unset environment variables
Known Debian Architectures are sparc, hurd-i386, i386, m68k, alpha
Known GNU System Types are sparc-linux, i386-gnu, i386-linux, m68k-linux,
alpha-linux
==============================================================================
I have not added all supported architectures.
Example output:
brinkmds@flora:~/hurd$ ./dpkg-architecture
DEB_BUILD_ARCH=i386
DEB_BUILD_GNU_ARCH=i486
DEB_BUILD_GNU_OS=linux
DEB_BUILD_GNU_SYSTEM=i486-linux
DEB_TARGET_ARCH=i386
DEB_TARGET_GNU_ARCH=i486
DEB_TARGET_GNU_OS=linux
DEB_TARGET_GNU_SYSTEM=i486-linux
brinkmds@flora:~/hurd$ ./dpkg-architecture -asparc
DEB_BUILD_ARCH=i386
DEB_BUILD_GNU_ARCH=i486
DEB_BUILD_GNU_OS=linux
DEB_BUILD_GNU_SYSTEM=i486-linux
DEB_TARGET_ARCH=sparc
DEB_TARGET_GNU_ARCH=sparc
DEB_TARGET_GNU_OS=linux
DEB_TARGET_GNU_SYSTEM=sparc-linux
brinkmds@flora:~/hurd$ ./dpkg-architecture -ti386-gnu
DEB_BUILD_ARCH=i386
DEB_BUILD_GNU_ARCH=i486
DEB_BUILD_GNU_OS=linux
DEB_BUILD_GNU_SYSTEM=i486-linux
DEB_TARGET_ARCH=hurd-i386
DEB_TARGET_GNU_ARCH=i386
DEB_TARGET_GNU_OS=gnu
DEB_TARGET_GNU_SYSTEM=i386-gnu
brinkmds@flora:~/hurd$ ./dpkg-architecture -ahurd-i386 -s
export DEB_BUILD_ARCH=i386
DEB_BUILD_GNU_ARCH=i486
DEB_BUILD_GNU_OS=linux
DEB_BUILD_GNU_SYSTEM=i486-linux
DEB_TARGET_ARCH=hurd-i386
DEB_TARGET_GNU_ARCH=i386
DEB_TARGET_GNU_OS=gnu
DEB_TARGET_GNU_SYSTEM=i386-gnu
brinkmds@flora:~/hurd$ ./dpkg-architecture -u
unset DEB_BUILD_ARCH DEB_BUILD_GNU_ARCH DEB_BUILD_GNU_OS DEB_BUILD_GNU_SYSTEM DEB_TARGET_ARCH DEB_TARGET_GNU_ARCH DEB_TARGET_GNU_OS DEB_TARGET_GNU_SYSTEM
brinkmds@flora:~/hurd$ ./dpkg-architecture -asparc -tsparc-gnu
dpkg-architecture: warning: Default GNU system type sparc-linux for Debian arch sparc does not match specified GNU system type sparc-gnu
DEB_BUILD_ARCH=i386
DEB_BUILD_GNU_ARCH=i486
DEB_BUILD_GNU_OS=linux
DEB_BUILD_GNU_SYSTEM=i486-linux
DEB_TARGET_ARCH=sparc
DEB_TARGET_GNU_ARCH=sparc
DEB_TARGET_GNU_OS=gnu
DEB_TARGET_GNU_SYSTEM=sparc-gnu
brinkmds@flora:~/hurd$ ./dpkg-architecture -asparcy
unknown Debian architecture sparcy, you must specify GNU system type, too at ./dpkg-architecture line 67.
You can use it like this:
brinkmds@flora:~/hurd$ `dpkg-aechitecture -aalpha -s`
and it will set the environment properly.
Question: Can I modify the environment of the invoking shell from inside a
perl script? This would make it easier to use the script.
Thanks,
Marcus
--
"Rhubarb is no Egyptian god." Debian GNU/Linux finger brinkmd@
Marcus Brinkmann http://www.debian.org master.debian.org
Marcus.Brinkmann@ruhr-uni-bochum.de for public PGP Key
http://homepage.ruhr-uni-bochum.de/Marcus.Brinkmann/ PGP Key ID 36E7CD09
#! /usr/bin/perl
$version="0.0.1";
$0 = `basename $0`; chomp $0;
$dpkglibdir="/usr/lib/dpkg";
push(@INC,$dpkglibdir);
require 'controllib.pl';
# Set default values:
$deb_build_arch = `dpkg --print-installation-architecture`;
$deb_build_gnu_arch = `dpkg --print-gnu-build-architecture`;
chomp $deb_build_arch;
chomp $deb_build_gnu_arch;
$deb_target_arch = $deb_build_arch;
$deb_target_gnu_arch = $deb_build_gnu_arch;
$deb_target_gnu_os = $deb_build_gnu_os = 'linux';
$deb_target_gnu_system = $deb_build_gnu_system = $deb_build_gnu_arch.'-'.$deb_build_gnu_os;
%archtable=('i386', 'i386-linux',
alpha => 'alpha-linux',
m68k => 'm68k-linux',
sparc => 'sparc-linux',
'hurd-i386' => 'i386-gnu');
sub usageversion {
print STDERR
"Debian GNU/Linux $0 $version. Copyright (C) 1998 Marcus Brinkmann.
This is free software; see the GNU General Public Licence version 2
or later for copying conditions. There is NO warranty.
Usage:
$0 [<option> ...] [<action>]
Options:
-a<debian-arch> set Debian architecture
-t<gnu-system> set GNU system type
Actions:
-l list environment variables (default)
-s print command to set environment variables
-u print command to unset environment variables
Known Debian Architectures are ".join(", ",keys %archtable)."
Known GNU System Types are ".join(", ",map ($archtable{$_},keys %archtable))."
";
}
$req_target_arch = '';
$req_target_gnu_system = '';
$action='l';
while (@ARGV) {
$_=shift(@ARGV);
if (m/^-a/) {
$req_target_arch = $';
} elsif (m/^-t/) {
$req_target_gnu_system = $';
} elsif (m/^-[lsu]$/) {
$action = $_;
$action =~ s/^-//;
} else {
usageerr("unknown option \`$_'");
}
}
if ($req_target_arch ne '' && $req_target_gnu_system eq '') {
die ("unknown Debian architecture $req_target_arch, you must specify GNU system type, too") if !exists $archtable{$req_target_arch};
$req_target_gnu_system = $archtable{$req_target_arch}
}
if ($req_target_gnu_system ne '' && $req_target_arch eq '') {
undef @list;
foreach $a (keys %archtable) {
push @list, $a if $archtable{$a} eq $req_target_gnu_system;
}
die ("unknown GNU system type $req_target_gnu_system, you must specify Debian architecture, too") if !defined(@list);
die ("ambiguous GNU system type $req_target_gnu_system, you must specify Debian architecture, too (one of ".join(", ",@list).")") if $#list > 0;
$req_target_arch = $list[0];
}
if (exists $archtable{$req_target_arch}) {
&warn("Default GNU system type $archtable{$req_target_arch} for Debian arch $req_target_arch does not match specified GNU system type $req_target_gnu_system\n") if $archtable{$req_target_arch} ne $req_target_gnu_system;
}
die "couldn't parse GNU system type $req_target_gnu_system, must be arch-os or arch-vendor-os" if $req_target_gnu_system !~ m/^([\w\d]+(-[\w\d]+){1,2})?$/;
$deb_target_arch = $req_target_arch if $req_target_arch ne '';
if ($req_target_gnu_system ne '') {
$deb_target_gnu_arch = $deb_target_gnu_os = $deb_target_gnu_system = $req_target_gnu_system;
$deb_target_gnu_arch =~ s/-.*$//;
$deb_target_gnu_os =~ s/^.*-//;
}
@env = ("DEB_BUILD_ARCH=$deb_build_arch",
"DEB_BUILD_GNU_ARCH=$deb_build_gnu_arch",
"DEB_BUILD_GNU_OS=$deb_build_gnu_os",
"DEB_BUILD_GNU_SYSTEM=$deb_build_gnu_system",
"DEB_TARGET_ARCH=$deb_target_arch",
"DEB_TARGET_GNU_ARCH=$deb_target_gnu_arch",
"DEB_TARGET_GNU_OS=$deb_target_gnu_os",
"DEB_TARGET_GNU_SYSTEM=$deb_target_gnu_system");
if ($action eq 'l') {
print join("\n",@env)."\n";
} elsif ($action eq 's') {
print "export ".join("\n",@env)."\n";
} elsif ($action eq 'u') {
print "unset DEB_BUILD_ARCH DEB_BUILD_GNU_ARCH DEB_BUILD_GNU_OS DEB_BUILD_GNU_SYSTEM DEB_TARGET_ARCH DEB_TARGET_GNU_ARCH DEB_TARGET_GNU_OS DEB_TARGET_GNU_SYSTEM\n";
}
Reply to: