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

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



On Sun, Jun 15, 2008 at 07:31:28PM +0100, Neil Williams wrote:
>On Sun, 2008-06-15 at 19:26 +0200, Bernhard Fischer wrote:

Yes, the _all does look a bit odd, not sure though.

>If you can update the other patches against current SVN it would make
>things easier. Your first patch failed to apply cleanly to emchain from
>1.1.4 (i.e. before the current changes).

The patch was against 1.1.5, sorry.
Attached is a patch against trunk with more comments.
Untested, just a RFA.
Index: emdebian-tools/trunk/emchain
===================================================================
--- emdebian-tools/trunk/emchain	(revision 4195)
+++ emdebian-tools/trunk/emchain	(working copy)
@@ -38,7 +38,8 @@ $gcc_pkg_v $binutils_vers $libc_latest $
 $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,63 @@ sub uclibc_translate_triplet
 	return $uclibc_triplet;
 }
 
+# generate a fake binutils package with the correct target 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")
+# mismatch of host arches. Make sure that this also catches non-ia32 mismatches
+	if ($check ne "true" and $arch eq "i386") {# and `dpkg-architecture -qDEB_BUILD_ARCH -ei386 2> /dev/null`) {
+
+		# check is true since in this particular case (where
+		# dpkg-architecture -qDEB_BUILD_ARCH -ei386
+		# or other -e ) we have to check for these packages instead:
+		# gcc, binutils, etc. i.e. the native ones.
+		$check = "true";
+		# getting ugly. While distinct subarches, they are treated
+		# the same for ia32.
+		# See: 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
+		# i.e. nothing for i386 (the primary arch name) but only for
+		# subsrches! Thus prevent havoc:
+		$arch="i486";
+	}
+	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 +818,27 @@ sub uclibc_build_chain
 	`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";
+	# cross-gcc Depends:
+	$binutils_cross = "binutils-${target_gnu_type}";
+	# Check if we are doing a cross-compiler for a different libc or subarch
+	my $host_arch = `dpkg-architecture -qDEB_BUILD_ARCH`;
+	my $tgt_arch = $arch;
+	$tgt_arch =~ s/i.86/i386/;
+	chomp($host_arch);
+	if ($host_arch eq $tgt_arch) {
+		# Setup the Depends: field of the fake-gcc we are about to build
+		# - We are using the same arch.
+		# - Binutils is libc-agnostic
+		# - Binutils can generate code for all subarches, so we
+		#   can cater for the inexactness later on via flags.
+		$binutils_cross = "binutils";
+		$binutils_pkg   = "binutils";
+	} else {
+		# generate a faked package with the needed target triplet
+		&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");
@@ -882,7 +929,7 @@ Architecture: all%;
 	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 +939,7 @@ Description: binutils support for buildi
 	{
 		$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: