[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

emchain -u -a $(dpkg-architecture -qDEB_BUILD_ARCH) aka. $arch_glibc->$arch_uclibc compilers



Hi,

I'm thinking about building me a toolchain with uClibc but i'm facing
some loose ends here and there. I'm aware that this may be a usecase
that could be considered erm.. uncommon -- i don't think it is but i'm
biased.

I'm asking for comments, please do not apply anything but 3) and 4) just
yet.
TIA for feedback on how such a setup should be done. I don't consider
the actual perl-changes clean, they are just ment to show what i mean.
The attached hunks were not tested at all.

1) dpkg-architecture et al. seem to treat i?86 as i386 which is fine per
se, but implies that for glibc->uclibc compilers running on (and
targeting) the same arch, one has to be careful in the logic that
decides which packages are available on the mirrors and which are not:

# COLUMNS=150 dpkg -l "gcc-???-i?86-linux-*" | awk '{if (/gcc/)print $2}'
gcc-4.2-i486-linux-gnu-base
gcc-4.3-i486-linux-gnu
gcc-4.3-i486-linux-uclibc

Since dpkg-cross, dpkg-architecture etc don't like "i486" as an arch,
one has to resort to using i386, like:
emchain -u -l -v -v -a i386

2) Special-casing $arch == $target_arch
For the (cross-)compiler we have to adjust the Depends: for these
special cases we can use the native "binutils" et al. and *not* the
binutils-${uclibc_target}. See call to uclibc_build_binutils and above
that. Not really clean yet, can be improved.
The body of uclibc_build_binutils was just moved and was not changed at
all.

3) bugfix "arm"
This snippet:
-       my $gccspecs = `arm-linux-gnu-gcc -dumpspecs`;
+       my $gccspecs = `$arch-linux-gnu-gcc -dumpspecs`;


4) bugfix divert
dpkg-divert didn't work for me. I fixed this up and changed the
diversion-name to \.glibc from formerly \.gcc to make it more obvious
what purpose the diversion had.

This was what i got previously, fwiw:
# dpkg -i gcc-4.3-i486-linux-uclibc_4.3.1-2_all.deb 
(Reading database ... 19853 files and directories currently installed.)
Unpacking gcc-4.3-i486-linux-uclibc (from
gcc-4.3-i486-linux-uclibc_4.3.1-2_all.deb) ...
dpkg-divert: --add needs a single argument

Usage: dpkg-divert [<option> ...] <command>

Commands:
  [--add] <file>           add a diversion.
  --remove <file>          remove the diversion.
  --list [<glob-pattern>]  show file diversions.
  --truename <file>        return the diverted file.

Options:
  --package <package>      name of the package whose copy of <file> will
not
                             be diverted.
  --local                  all packages' versions are diverted.
  --divert <divert-to>     the name used by other packages' versions.
  --rename                 actually move the file aside (or back).
  --admindir <directory>   set the directory with the diversions file.
  --test                   don't do anything, just demonstrate.
  --quiet                  quiet operation, minimal output.
  --help                   show this help message.
  --version                show the version.

When adding, default is --local and --divert <original>.distrib.
When removing, --package or --local and --divert must match if
specified.
Package preinst/postrm scripts should always specify --package and
--divert.
dpkg: error processing gcc-4.3-i486-linux-uclibc_4.3.1-2_all.deb
(--install):
 subprocess pre-installation script returned error exit status 2
No diversion `diversion of /usr/lib/gcc/i486-linux-gnu/4.3.1/specs by
gcc-4.3-i486-linux-uclibc', none removed
Errors were encountered while processing:
 gcc-4.3-i486-linux-uclibc_4.3.1-2_all.deb
# echo $?
1

--- usr/bin/emchain.oorig	2008-06-09 20:07:48.000000000 +0200
+++ usr/bin/emchain	2008-06-15 18:13:40.000000000 +0200
@@ -38,7 +38,8 @@
 $binutils_dir $gcc_dir $dev $binutils_deb @glibc_list @glibc_list2
 @glibc_list3 $check $glibc_count $home $ourversion $progname $logfile
 $date $log $cmdline $status $environ $result $workdir $msg $ignore
-*OLDOUT *OLDERR $forcing $arglog $logdir $uclibc $uclibc_vers/;
+*OLDOUT *OLDERR $forcing $arglog $logdir $uclibc $uclibc_vers
+$binutils_cross $binutils_pkg/;
 
 $ourversion = &tools_version();
 $progname = basename($0);
@@ -718,10 +719,48 @@
 	return $uclibc_triplet;
 }
 
+sub uclibc_build_binutils
+{
+	my $uclibc_target = shift;
+	return unless (defined $uclibc_target);
+	my $binutils_pkg = "binutils-${uclibc_target}";
+	print GREEN, "Building $binutils_pkg for $uclibc_target\n", RESET
+		if ($verbose >= 2);
+	system ("mkdir -p debian/${binutils_pkg}/usr/bin");
+	system ("mkdir -p debian/${binutils_pkg}/usr/share/doc/${binutils_pkg}");
+	my (@binutils) = `dpkg -L binutils-${target_gnu_type}`;
+	foreach my $file (@binutils)
+	{
+		chomp($file);
+		next unless $file =~ m:/usr/bin/${target_gnu_type}:;
+		$file =~ s:/usr/bin/${target_gnu_type}-::;
+		print CYAN, "symlinking : $file\n", RESET if ($verbose >= 3);
+		unlink ("debian/${binutils_pkg}/usr/bin/${uclibc_target}-$file") if
+			(-f "debian/${binutils_pkg}/usr/bin/${uclibc_target}-$file");
+		my $e = symlink $file, "debian/${binutils_pkg}/usr/bin/${uclibc_target}-$file";
+	}
+	$uclibc_vers = $binutils_vers;
+	mkdir ("debian/${binutils_pkg}/DEBIAN");
+	open (CTRL, ">debian/control");
+	print CTRL &uclibc_control_info ("$binutils_pkg");
+	close (CTRL);
+	system ("dpkg-gencontrol -p${binutils_pkg} -Pdebian/${binutils_pkg} ".
+		"-cdebian/control");
+	system ("dpkg-deb --build debian/${binutils_pkg} ..");
+	`rm -rf ./debian` if (-d "debian");
+	# end of binutils package.
+
+
+}
+
 sub uclibc_build_chain
 {
 	my $check = &check_toolchains($arch, $target_gnu_type);
-	if($check ne "true")
+	if ($check ne "true" and $arch eq "i386") {# and `dpkg-architecture -qDEB_BUILD_ARCH -ei386 2> /dev/null`) {
+		$arch="i486";
+		$check = "true";
+	}
+	if ($check ne "true")
 	{
 	# need to identify the relevant gcc version from the installed toolchain.
 		my @dpkg_gcc = `dpkg -l "gcc-???-$arch-linux-gnu"`;
@@ -764,34 +803,21 @@
 	`rm -rf ./debian` if (-d "debian");
 	my $uclibc_target = &uclibc_translate_triplet($target_gnu_type);
 	my $gcc_package = "gcc-${gcc_latest}-${uclibc_target}";
-	my $binutils_pkg = "binutils-${uclibc_target}";
+	$binutils_pkg = "binutils-${uclibc_target}";
 	my $gpp_package = "g++-${gcc_latest}-${uclibc_target}";
-	print GREEN, "Building $binutils_pkg for $uclibc_target\n", RESET
-		if ($verbose >= 2);
-	system ("mkdir -p debian/${binutils_pkg}/usr/bin");
-	system ("mkdir -p debian/${binutils_pkg}/usr/share/doc/${binutils_pkg}");
-	my (@binutils) = `dpkg -L binutils-${target_gnu_type}`;
-	foreach my $file (@binutils)
-	{
-		chomp($file);
-		next unless $file =~ m:/usr/bin/${target_gnu_type}:;
-		$file =~ s:/usr/bin/${target_gnu_type}-::;
-		print CYAN, "symlinking : $file\n", RESET if ($verbose >= 3);
-		unlink ("debian/${binutils_pkg}/usr/bin/${uclibc_target}-$file") if
-			(-f "debian/${binutils_pkg}/usr/bin/${uclibc_target}-$file");
-		my $e = symlink $file, "debian/${binutils_pkg}/usr/bin/${uclibc_target}-$file";
+	# cros-gcc Depends:
+	$binutils_cross = "binutils-${target_gnu_type}";
+	my $host_arch = `dpkg-architecture -qDEB_BUILD_ARCH`;
+	my $tgt_arch = $arch;
+	$tgt_arch =~ s/i.86/i386/;
+	chomp($host_arch);
+	printf("tgt='$tgt_arch',  host_arch='$host_arch'\n");
+	if ($host_arch eq $tgt_arch) {
+		$binutils_cross = "binutils";
+		$binutils_pkg   = "binutils";
+	} else {
+		&uclibc_build_binutils(${uclibc_target});
 	}
-	$uclibc_vers = $binutils_vers;
-	mkdir ("debian/${binutils_pkg}/DEBIAN");
-	open (CTRL, ">debian/control");
-	print CTRL &uclibc_control_info ("$binutils_pkg");
-	close (CTRL);
-	system ("dpkg-gencontrol -p${binutils_pkg} -Pdebian/${binutils_pkg} ".
-		"-cdebian/control");
-	system ("dpkg-deb --build debian/${binutils_pkg} ..");
-	`rm -rf ./debian` if (-d "debian");
-	# end of binutils package.
-
 	print GREEN, "Building $gcc_package for $uclibc_target\n", RESET
 		if ($verbose >= 2);
 	system ("mkdir -p debian/${gcc_package}/usr/bin");
@@ -815,7 +841,7 @@
 	print GREEN, "Creating target_compiler directory tree : $target_compiler\n",
 		RESET if ($verbose >= 3);
 	system ("mkdir -p debian/${gcc_package}/${target_compiler}");
-	my $gccspecs = `arm-linux-gnu-gcc -dumpspecs`;
+	my $gccspecs = `$arch-linux-gnu-gcc -dumpspecs`;
 	my $s = &uclibc_munge_specs($gccspecs);
 	open (SPECS, ">debian/${gcc_package}/${target_compiler}/specs");
 	print SPECS "$s\n";
@@ -824,12 +850,12 @@
 	open (PREINST, ">debian/${gcc_package}/DEBIAN/preinst") or die (
 	"Cannot create debian/$gcc_package/DEBIAN/preinst: $!");
 	print PREINST "#!/bin/sh\n";
-	print PREINST "dpkg-divert ${target_compiler}specs.gcc --rename --package ${gcc_package} --add ${target_compiler}specs\n";
+	print PREINST "dpkg-divert --package ${gcc_package} --add --rename --divert ${target_compiler}specs.glibc ${target_compiler}specs\n";
 	close (PREINST);
 	chmod (0755, "debian/${gcc_package}/DEBIAN/preinst");
 	open (POSTRM, ">debian/${gcc_package}/DEBIAN/postrm");
 	print POSTRM "#!/bin/sh\n";
-	print POSTRM "dpkg-divert --rename --package ${gcc_package} --remove ${target_compiler}specs\n";
+	print POSTRM "dpkg-divert --package ${gcc_package} --rename --remove ${target_compiler}specs\n";
 	close (POSTRM);
 	chmod (0755, "debian/${gcc_package}/DEBIAN/postrm");
 	open (CTRL, ">debian/control");
@@ -882,7 +908,7 @@
 	if ($target =~ /^binutils/)
 	{
 		$ctrl .= qq%
-Depends: binutils-${target_gnu_type}
+Depends: ${binutils_cross}
 Description: binutils support for building against uClibc
  This package provides wrapper scripts for the toolchain, providing an
  alternate host triplet for building against uclibc.
@@ -892,7 +918,7 @@
 	{
 		$ctrl .= qq%
 Depends: gcc-${gcc_latest}-${target_gnu_type} (= ${gcc_pkg_v}),
- libuclibc-dev-${arch}-cross, binutils-${arch}-linux-uclibc
+ libuclibc-dev-${arch}-cross, ${binutils_pkg}
 Description: Toolchain alias for building against uclibc
  This package provides wrapper scripts for the toolchain, providing an
  alternate host triplet for building against uclibc.

Reply to: