summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2014-06-30 09:03:30 (GMT)
committer Jaromil <jaromil@dyne.org>2014-06-30 09:20:46 (GMT)
commit2c477da395c97726c2a69ae995fa12c997bd8ee3 (patch)
tree2e65e0059785756ecc50079bf3f320739fa0b696
parent53967db7ffd5ef683575d1f0b60336387190a278 (diff)
fix toolchain wrappers
-rw-r--r--wrap/agcc206
-rwxr-xr-xwrap/static-cc15
-rwxr-xr-xwrap/strip2
3 files changed, 215 insertions, 8 deletions
diff --git a/wrap/agcc b/wrap/agcc
new file mode 100644
index 0000000..569c037
--- /dev/null
+++ b/wrap/agcc
@@ -0,0 +1,206 @@
+#!/usr/bin/perl -w
+use strict;
+
+# Copyright 2008, Andrew Ross andy@plausible.org
+# Distributable under the terms of the GNU GPL, see COPYING for details
+
+# The Android toolchain is ... rough. Rather than try to manage the
+# complexity directly, this script wraps the tools into an "agcc" that
+# works a lot like a gcc command line does for a native platform or a
+# properly integrated cross-compiler. It accepts arbitrary arguments,
+# but interprets the following specially:
+#
+# -E/-S/-c/-shared - Enable needed arguments (linker flags, include
+# directories, runtime startup objects...) for the
+# specified compilation mode when building under
+# android.
+#
+# -O<any> - Turn on the optimizer flags used by the Dalvik build. No
+# control is provided over low-level optimizer flags.
+#
+# -W<any> - Turn on the warning flags used by the Dalvik build. No
+# control is provided over specific gcc warning flags.
+#
+# Notes:
+# + The prebuilt arm-eabi-gcc from a built (!) android source
+# directory must be on your PATH.
+# + All files are compiled with -fPIC to an ARMv5TE target. No
+# support is provided for thumb.
+# + No need to pass a "-Wl,-soname" argument when linking with
+# -shared, it uses the file name always (so don't pass a directory in
+# the output path for a shared library!)
+
+# Dance around to find the actual android toolchain path (it's very
+# deep, so links on $PATH are going to be common.
+my $GCC = `which arm-eabi-gcc`;
+$GCC = qx(cd `dirname $GCC`; /bin/pwd);
+chomp $GCC;
+die "bad arm-eabi-gcc path" if $GCC !~ /(.*)\/prebuilt\//;
+my $DROID = $1;
+
+
+
+my $ALIB = "$DROID/platforms/android-8/arch-arm/usr/lib";
+my $PREBUILT="$DROID/prebuilt/linux-x86";
+my $TOOLCHAIN = "$PREBUILT/toolchain/arm-eabi-4.2.1";
+my $INTERWORK = "$PREBUILT/arm-eabi-4.2.1";
+#my $LDSCRIPTS = "$PREBUILT/arm-eabi-4.4.0/arm-eabi/lib/ldscripts/";
+my $LDSCRIPTS = "$PREBUILT/arm-eabi-4.2.1/arm-eabi/lib/ldscripts/";
+
+
+
+print "GCC at $GCC \n";
+print "DROID at $DROID \n";
+print "TOOLCHAIN at $TOOLCHAIN \n";
+print "\n\n\n";
+my @include_paths = (
+ "-I$DROID/system/core/include",
+ "-I$DROID/hardware/libhardware/include",
+ "-I$DROID/hardware/ril/include",
+ "-I$DROID/dalvik/libnativehelper/include",
+ "-I$DROID/frameworks/base/include",
+ "-I$DROID/external/skia/include",
+ "-I$DROID/platforms/android-8/arch-arm/usr/include",
+ "-I$DROID/bionic/libc/arch-arm/include",
+ "-I$DROID/bionic/libc/include",
+ "-I$DROID/bionic/libstdc++/include",
+ "-I$DROID/bionic/libc/kernel/common",
+ "-I$DROID/bionic/libc/kernel/arch-arm",
+ "-I$DROID/bionic/libm/include",
+ "-I$DROID/bionic/libm/include/arch/arm",
+ "-I$DROID/bionic/libthread_db/include",
+ "-I$DROID/bionic/libm/arm",
+ "-I$DROID/bionic/libm",
+ "-I$DROID/out/target/product/generic/obj/SHARED_LIBRARIES/libm_intermediates");
+
+my @preprocess_args = (
+ "-D__ARM_ARCH_5__",
+ "-D__ARM_ARCH_5T__",
+ "-D__ARM_ARCH_5E__",
+ "-D__ARM_ARCH_5TE__", # Already defined by toolchain
+ "-DANDROID",
+ "-DSK_RELEASE",
+ "-DNDEBUG",
+ # "-include", "$DROID/system/core/include/arch/linux-arm/AndroidConfig.h",
+ "-UDEBUG");
+
+my @warn_args = (
+ "-Wall",
+ "-Wno-unused", # why?
+ "-Wno-multichar", # why?
+ "-Wstrict-aliasing=2"); # Implicit in -Wall per texinfo
+
+my @compile_args = (
+ "-march=armv5te",
+ "-mtune=xscale",
+ "-msoft-float",
+ "-mthumb-interwork",
+ "-fpic",
+ "-fno-exceptions",
+ "-ffunction-sections",
+ "-funwind-tables", # static exception-like tables
+ "-fstack-protector", # check guard variable before return
+ "-fmessage-length=0"); # No line length limit to error messages
+
+my @optimize_args = (
+ "-O2",
+ "-finline-functions",
+ "-finline-limit=300",
+ "-fno-inline-functions-called-once",
+ "-fgcse-after-reload",
+ "-frerun-cse-after-loop", # Implicit in -O2 per texinfo
+ "-frename-registers",
+ "-fomit-frame-pointer",
+ "-fstrict-aliasing", # Implicit in -O2 per texinfo
+ "-funswitch-loops");
+
+my @link_args = (
+ "-Bdynamic",
+ "-Wl,-T,$LDSCRIPTS/armelf.x",
+ "-Wl,-dynamic-linker,/system/bin/linker",
+ "-Wl,--gc-sections",
+ "-Wl,-z,nocopyreloc",
+ "-Wl,--no-undefined",
+ "-Wl,-rpath-link=$ALIB",
+ "-L$ALIB",
+ "-nostdlib",
+ "$ALIB/crtend_android.o",
+ "$ALIB/crtbegin_dynamic.o",
+ #"$TOOLCHAIN/lib/gcc/arm-eabi/4.2.1/interwork/libgcc.a",
+ "-lc",
+ "$INTERWORK/lib/gcc/arm-eabi/4.2.1/interwork/libgcc.a",
+ "$ALIB/libc.a",
+ "-lm");
+
+# Also need: -Wl,-soname,libXXXX.so
+my @shared_args = (
+ "-nostdlib",
+ "-Wl,-T,$DROID/build/core/armelf.xsc",
+ "-Wl,--gc-sections",
+ "-Wl,-shared,-Bsymbolic",
+ "-L$ALIB",
+ "-Wl,--no-whole-archive",
+ "-lc",
+ "-lm",
+ "-Wl,--no-undefined",
+ "$TOOLCHAIN/lib/gcc/arm-eabi/4.2.1/interwork/libgcc.a",
+ "-Wl,--whole-archive"); # .a, .o input files go *after* here
+
+# Now implement a quick parser for a gcc-like command line
+
+my %MODES = ("-E"=>1, "-c"=>1, "-S"=>1, "-shared"=>1);
+
+my $mode = "DEFAULT";
+my $out;
+my $warn = 0;
+my $opt = 0;
+my @args = ();
+my $have_src = 0;
+while(@ARGV) {
+ my $a = shift;
+ if(defined $MODES{$a}) {
+ die "Can't specify $a and $mode" if $mode ne "DEFAULT";
+ $mode = $a;
+ } elsif($a eq "-o") {
+ die "Missing -o argument" if !@ARGV;
+ die "Duplicate -o argument" if defined $out;
+ $out = shift;
+ } elsif($a =~ /^-W.*/) {
+ $warn = 1;
+ } elsif($a =~ /^-O.*/) {
+ $opt = 1;
+ } else {
+ if($a =~ /\.(c|cpp|cxx)$/i) { $have_src = 1; }
+ push @args, $a;
+ }
+}
+
+my $need_cpp = 0;
+my $need_compile = 0;
+my $need_link = 0;
+my $need_shlink = 0;
+if($mode eq "DEFAULT") { $need_cpp = $need_compile = $need_link = 1; }
+if($mode eq "-E") { $need_cpp = 1; }
+if($mode eq "-c") { $need_cpp = $need_compile = 1; }
+if($mode eq "-S") { $need_cpp = $need_compile = 1; }
+if($mode eq "-shared") { $need_shlink = 1; }
+
+if($have_src and $mode ne "-E") { $need_cpp = $need_compile = 1; }
+
+# Assemble the command:
+my @cmd = ("arm-eabi-gcc");
+if($mode ne "DEFAULT") { @cmd = (@cmd, $mode); }
+if(defined $out) { @cmd = (@cmd, "-o", $out); }
+if($need_cpp) { @cmd = (@cmd, @include_paths, @preprocess_args); }
+if($need_compile){
+ @cmd = (@cmd, @compile_args);
+ if($warn) { @cmd = (@cmd, @warn_args); }
+ if($opt) { @cmd = (@cmd, @optimize_args); }
+}
+if($need_shlink) { @cmd = (@cmd, @shared_args); }
+@cmd = (@cmd, @args);
+if($need_link) { @cmd = (@cmd, @link_args); }
+
+print join(" ", @cmd), "\n"; # Spit it out if you're curious
+exec(@cmd);
+
diff --git a/wrap/static-cc b/wrap/static-cc
index 3a0b36f..927e916 100755
--- a/wrap/static-cc
+++ b/wrap/static-cc
@@ -2,7 +2,7 @@
# Static build wrapper
#
-# Copyleft (C) 2012 Denis Roio <jaromil@dyne.org>
+# Copyleft (C) 2012-2013 Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
@@ -42,20 +42,21 @@ fi
case `basename $0`; in
static-cc|cc|gcc) cc=${TOOLCHAIN}/bin/${ZTARGET}-gcc ;;
static-c++|c++|g++) cc=${TOOLCHAIN}/bin/${ZTARGET}-g++ ;;
- static-ld|ld) cc=${TOOLCHAIN}/bin/${ZTARGET}-ld ;;
+ static-ld|ld) cc=${TOOLCHAIN}/bin/${ZTARGET}-gcc ;; # was -ld until 0.8
*)
print "Error: unknown command to static wrapper: $0"
exit 1
esac
-libdirs+=${PREFIX}/lib
+libdirs=(${PREFIX}/lib)
+libdirs+=(${TOOLCHAIN}/x-tools/arm-dyne-linux-gnueabi/sysroot/usr/lib)
cflags=(${=CFLAGS})
ldflags+=(${=LDFLAGS})
libraries+=(ld-linux-x86 skip)
libraries+=(linux-vdso skip)
libraries+=(c skip)
-libraries+=(rt skip)
+# libraries+=(rt skip)
libraries+=(gcc skip)
libraries+=(gcc_s skip)
@@ -169,13 +170,13 @@ echo $arguments | grep -i ' -l' > /dev/null
}
# remove duplicate arguments
-typeset -U arguments
+# typeset -U arguments
# execute
case $action in
- compile) print "$cc ${=cflags} ${=arguments}"
+ compile) print "[CC] $cc ${=cflags} ${=arguments}"
$cc ${=cflags} ${=arguments} ;;
- link) print "$cc ${=ldflags} ${=arguments}"
+ link) print "[LD] ${TOOLCHAIN}/bin/${ZTARGET}-ld ${=ldflags} ${=arguments}"
$cc ${=ldflags} ${=arguments} ;;
esac
return $?
diff --git a/wrap/strip b/wrap/strip
index 7d19c99..e18350f 100755
--- a/wrap/strip
+++ b/wrap/strip
@@ -1,7 +1,7 @@
#!/bin/zsh
QUIET=1 source $ZHOME/zmake source
-$TOOLCHAIN/bin/${TARGET}-strip ${=@}
+$TOOLCHAIN/bin/${ZTARGET}-strip ${=@}
{ test "$?" = "0" } || { error "Strip error on: ${@}"; return 1 }
return 0