Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1 | # Copyright © 2010, 2012, 2013 |
| 2 | # Thorsten Glaser <tg@mirbsd.org> |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3 | # This file is provided under the same terms as mksh. |
| 4 | #- |
| 5 | # Helper script to let src/Build.sh generate Makefrag.inc |
| 6 | # which we in turn use in the manual creation of Android.mk |
| 7 | # |
| 8 | # This script is supposed to be run from/inside AOSP by the |
| 9 | # porter of mksh to Android (and only manually). |
| 10 | |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11 | if test x"$1" = x"-t"; then |
| 12 | # test compilation |
| 13 | args=-r |
| 14 | mkmfmode=1 |
| 15 | else |
| 16 | # prepare for AOSP |
| 17 | args=-M |
| 18 | mkmfmode=0 |
| 19 | fi |
| 20 | |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 21 | cd "$(dirname "$0")" |
| 22 | srcdir=$(pwd) |
| 23 | rm -rf tmp |
| 24 | mkdir tmp |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 25 | cd ../.. |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 26 | aospdir=$(pwd) |
| 27 | cd $srcdir/tmp |
| 28 | |
| 29 | addvar() { |
| 30 | _vn=$1; shift |
| 31 | |
| 32 | eval $_vn=\"\$$_vn '$*"' |
| 33 | } |
| 34 | |
| 35 | CFLAGS= |
| 36 | CPPFLAGS= |
| 37 | LDFLAGS= |
| 38 | LIBS= |
| 39 | |
| 40 | # The definitions below were generated by examining the |
| 41 | # output of the following command: |
| 42 | # make showcommands out/target/product/generic/system/bin/mksh 2>&1 | tee log |
| 43 | # |
| 44 | # They are only used to let Build.sh find the compiler, header |
| 45 | # files, linker and libraries to generate Makefrag.inc (similar |
| 46 | # to what GNU autotools’ configure scripts do), and never used |
| 47 | # during the real build process. We need this to port mksh to |
| 48 | # the Android platform and it is crucial these are as close as |
| 49 | # possible to the values used later. (You also must example the |
| 50 | # results gathered from Makefrag.inc to see they are the same |
| 51 | # across all Android platforms, or add appropriate ifdefs.) |
Elliott Hughes | 427d76c | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 52 | # Since we no longer use the NDK, AOSP has to have been |
| 53 | # built before using this script. |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 54 | |
Elliott Hughes | 1bd2f37 | 2014-08-12 15:39:09 -0700 | [diff] [blame] | 55 | CC=$ANDROID_TOOLCHAIN/*-gcc |
| 56 | |
| 57 | target_arch=$(cd $ANDROID_BUILD_TOP; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core make --no-print-directory -f build/core/config.mk dumpvar-TARGET_ARCH) |
| 58 | |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 59 | addvar CPPFLAGS \ |
Elliott Hughes | 1bd2f37 | 2014-08-12 15:39:09 -0700 | [diff] [blame] | 60 | -isystem $aospdir/bionic/libc/arch-$target_arch/include \ |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 61 | -isystem $aospdir/bionic/libc/include \ |
Christopher Ferris | 98a3aa6 | 2013-12-18 14:56:42 -0800 | [diff] [blame] | 62 | -isystem $aospdir/bionic/libc/kernel/uapi \ |
Elliott Hughes | 1bd2f37 | 2014-08-12 15:39:09 -0700 | [diff] [blame] | 63 | -isystem $aospdir/bionic/libc/kernel/uapi/asm-$target_arch \ |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 64 | -isystem $aospdir/bionic/libm/include \ |
Elliott Hughes | 1bd2f37 | 2014-08-12 15:39:09 -0700 | [diff] [blame] | 65 | -isystem $aospdir/bionic/libm/include/$target_arch \ |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 66 | -D_FORTIFY_SOURCE=2 \ |
Elliott Hughes | 1bd2f37 | 2014-08-12 15:39:09 -0700 | [diff] [blame] | 67 | -include $aospdir/build/core/combo/include/arch/linux-$target_arch/AndroidConfig.h \ |
| 68 | -I$aospdir/build/core/combo/include/arch/linux-$target_arch/ \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 69 | -DANDROID -DNDEBUG -UDEBUG |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 70 | addvar CFLAGS \ |
| 71 | -fno-exceptions \ |
| 72 | -Wno-multichar \ |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 73 | -fpic \ |
| 74 | -fPIE \ |
| 75 | -ffunction-sections \ |
| 76 | -fdata-sections \ |
| 77 | -funwind-tables \ |
| 78 | -fstack-protector \ |
| 79 | -Wa,--noexecstack \ |
| 80 | -Werror=format-security \ |
| 81 | -fno-short-enums \ |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 82 | -Wno-unused-but-set-variable \ |
| 83 | -fno-builtin-sin \ |
| 84 | -fno-strict-volatile-bitfields \ |
| 85 | -Wno-psabi \ |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 86 | -fmessage-length=0 \ |
| 87 | -W \ |
| 88 | -Wall \ |
| 89 | -Wno-unused \ |
| 90 | -Winit-self \ |
| 91 | -Wpointer-arith \ |
| 92 | -Werror=return-type \ |
| 93 | -Werror=non-virtual-dtor \ |
| 94 | -Werror=address \ |
| 95 | -Werror=sequence-point \ |
| 96 | -g \ |
| 97 | -Wstrict-aliasing=2 \ |
| 98 | -fgcse-after-reload \ |
| 99 | -frerun-cse-after-loop \ |
| 100 | -frename-registers \ |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 101 | -Os \ |
| 102 | -fomit-frame-pointer \ |
| 103 | -fno-strict-aliasing |
| 104 | addvar LDFLAGS \ |
| 105 | -nostdlib \ |
| 106 | -Bdynamic \ |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 107 | -fPIE \ |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 108 | -pie \ |
| 109 | -Wl,-dynamic-linker,/system/bin/linker \ |
| 110 | -Wl,--gc-sections \ |
| 111 | -Wl,-z,nocopyreloc \ |
| 112 | -Wl,-z,noexecstack \ |
| 113 | -Wl,-z,relro \ |
| 114 | -Wl,-z,now \ |
| 115 | -Wl,--warn-shared-textrel \ |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 116 | -Wl,--fatal-warnings \ |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 117 | -Wl,--no-undefined \ |
Elliott Hughes | 427d76c | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 118 | $ANDROID_PRODUCT_OUT/obj/lib/crtbegin_dynamic.o |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 119 | addvar LIBS \ |
Elliott Hughes | 427d76c | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 120 | -L$ANDROID_PRODUCT_OUT/obj/lib \ |
| 121 | -Wl,-rpath-link=$ANDROID_PRODUCT_OUT/obj/lib \ |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 122 | -Wl,--no-whole-archive \ |
Elliott Hughes | 427d76c | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 123 | $ANDROID_PRODUCT_OUT/obj/STATIC_LIBRARIES/libcompiler_rt-extras_intermediates/libcompiler_rt-extras.a \ |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 124 | -lc \ |
Elliott Hughes | 427d76c | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 125 | $ANDROID_PRODUCT_OUT/obj/lib/crtend_android.o |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 126 | |
| 127 | |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 128 | ### Flags used by test builds |
| 129 | if test $mkmfmode = 1; then |
| 130 | addvar CPPFLAGS '-DMKSHRC_PATH=\"/system/etc/mkshrc\"' |
| 131 | addvar CPPFLAGS '-DMKSH_DEFAULT_EXECSHELL=\"/system/bin/sh\"' |
Nick Kralevich | fd187c6 | 2013-02-20 11:20:51 -0800 | [diff] [blame] | 132 | addvar CPPFLAGS '-DMKSH_DEFAULT_TMPDIR=\"/data/local\"' |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 133 | fi |
| 134 | |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 135 | ### Override flags |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 136 | # Let the shell free all memory upon exiting |
| 137 | addvar CPPFLAGS -DDEBUG_LEAKS |
| 138 | # UTF-8 works nowadays |
| 139 | addvar CPPFLAGS -DMKSH_ASSUME_UTF8 |
| 140 | # Reduce filedescriptor usage |
| 141 | addvar CPPFLAGS -DMKSH_CONSERVATIVE_FDS |
| 142 | # Leave out RCS ID strings from the binary |
| 143 | addvar CPPFLAGS -DMKSH_DONT_EMIT_IDSTRING |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 144 | # No getpwnam() calls (affects "cd ~username/" only) |
| 145 | addvar CPPFLAGS -DMKSH_NOPWNAM |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 146 | # Leave out the ulimit builtin |
| 147 | #addvar CPPFLAGS -DMKSH_NO_LIMITS |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 148 | # Compile an extra small mksh (optional) |
| 149 | #addvar CPPFLAGS -DMKSH_SMALL |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 150 | |
| 151 | # Set target platform |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 152 | TARGET_OS=Android |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 153 | |
| 154 | # Android-x86 does not have helper functions for ProPolice SSP |
| 155 | # and AOSP adds the flags by itself (same for warning flags) |
| 156 | HAVE_CAN_FNOSTRICTALIASING=0 |
| 157 | HAVE_CAN_FSTACKPROTECTORALL=0 |
| 158 | HAVE_CAN_WALL=0 |
| 159 | export HAVE_CAN_FNOSTRICTALIASING HAVE_CAN_FSTACKPROTECTORALL HAVE_CAN_WALL |
| 160 | |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 161 | # even the idea of persistent history on a phone is funny |
| 162 | HAVE_PERSISTENT_HISTORY=0; export HAVE_PERSISTENT_HISTORY |
| 163 | |
| 164 | # ... and run it! |
| 165 | export CC CPPFLAGS CFLAGS LDFLAGS LIBS TARGET_OS |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 166 | sh ../src/Build.sh $args |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 167 | rv=$? |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 168 | test x"$args" = x"-r" && exit $rv |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 169 | test x0 = x"$rv" && mv -f Makefrag.inc ../ |
| 170 | cd .. |
| 171 | rm -rf tmp |
| 172 | exit $rv |