1 # Copyright 2010, 2012, 2013 2 # Thorsten Glaser <tg (at] mirbsd.org> 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 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 21 cd "$(dirname "$0")" 22 srcdir=$(pwd) 23 rm -rf tmp 24 mkdir tmp 25 cd ../.. 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.) 52 # Since we no longer use the NDK, the AOSP has to have been 53 # built before using this script (targetting generic/emulator). 54 55 CC=$aospdir/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-gcc 56 addvar CPPFLAGS \ 57 -I$aospdir/libnativehelper/include/nativehelper \ 58 -isystem $aospdir/system/core/include \ 59 -isystem $aospdir/hardware/libhardware/include \ 60 -isystem $aospdir/hardware/libhardware_legacy/include \ 61 -isystem $aospdir/hardware/ril/include \ 62 -isystem $aospdir/libnativehelper/include \ 63 -isystem $aospdir/frameworks/native/include \ 64 -isystem $aospdir/frameworks/native/opengl/include \ 65 -isystem $aospdir/frameworks/av/include \ 66 -isystem $aospdir/frameworks/base/include \ 67 -isystem $aospdir/frameworks/base/opengl/include \ 68 -isystem $aospdir/external/skia/include \ 69 -isystem $aospdir/out/target/product/generic/obj/include \ 70 -isystem $aospdir/bionic/libc/arch-arm/include \ 71 -isystem $aospdir/bionic/libc/include \ 72 -isystem $aospdir/bionic/libstdc++/include \ 73 -isystem $aospdir/bionic/libc/kernel/common \ 74 -isystem $aospdir/bionic/libc/kernel/arch-arm \ 75 -isystem $aospdir/bionic/libm/include \ 76 -isystem $aospdir/bionic/libm/include/arm \ 77 -isystem $aospdir/bionic/libthread_db/include \ 78 -D_FORTIFY_SOURCE=1 \ 79 -include $aospdir/build/core/combo/include/arch/linux-arm/AndroidConfig.h \ 80 -I$aospdir/build/core/combo/include/arch/linux-arm/ \ 81 -DANDROID -DNDEBUG -UDEBUG 82 # who would have thought the AOSP devs are funny? -fno-builtin-sin 83 addvar CFLAGS \ 84 -fno-exceptions \ 85 -Wno-multichar \ 86 -msoft-float \ 87 -fpic \ 88 -fPIE \ 89 -ffunction-sections \ 90 -fdata-sections \ 91 -funwind-tables \ 92 -fstack-protector \ 93 -Wa,--noexecstack \ 94 -Werror=format-security \ 95 -fno-short-enums \ 96 -march=armv7-a \ 97 -mfloat-abi=softfp \ 98 -mfpu=vfpv3-d16 \ 99 -Wno-unused-but-set-variable \ 100 -fno-builtin-sin \ 101 -fno-strict-volatile-bitfields \ 102 -Wno-psabi \ 103 -mthumb-interwork \ 104 -fmessage-length=0 \ 105 -W \ 106 -Wall \ 107 -Wno-unused \ 108 -Winit-self \ 109 -Wpointer-arith \ 110 -Werror=return-type \ 111 -Werror=non-virtual-dtor \ 112 -Werror=address \ 113 -Werror=sequence-point \ 114 -g \ 115 -Wstrict-aliasing=2 \ 116 -fgcse-after-reload \ 117 -frerun-cse-after-loop \ 118 -frename-registers \ 119 -mthumb \ 120 -Os \ 121 -fomit-frame-pointer \ 122 -fno-strict-aliasing 123 addvar LDFLAGS \ 124 -nostdlib \ 125 -Bdynamic \ 126 -pie \ 127 -Wl,-dynamic-linker,/system/bin/linker \ 128 -Wl,--gc-sections \ 129 -Wl,-z,nocopyreloc \ 130 -Wl,-z,noexecstack \ 131 -Wl,-z,relro \ 132 -Wl,-z,now \ 133 -Wl,--warn-shared-textrel \ 134 -Wl,--icf=safe \ 135 -Wl,--fix-cortex-a8 \ 136 -Wl,--no-undefined \ 137 $aospdir/out/target/product/generic/obj/lib/crtbegin_dynamic.o 138 addvar LIBS \ 139 -L$aospdir/out/target/product/generic/obj/lib \ 140 -Wl,-rpath-link=$aospdir/out/target/product/generic/obj/lib \ 141 -lc \ 142 -Wl,--no-whole-archive \ 143 $aospdir/out/target/product/generic/obj/STATIC_LIBRARIES/libcompiler-rt-extras_intermediates/libcompiler-rt-extras.a \ 144 $aospdir/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/../lib/gcc/arm-linux-androideabi/4.7/armv7-a/libgcc.a \ 145 $aospdir/out/target/product/generic/obj/lib/crtend_android.o 146 147 148 ### Flags used by test builds 149 if test $mkmfmode = 1; then 150 addvar CPPFLAGS '-DMKSHRC_PATH=\"/system/etc/mkshrc\"' 151 addvar CPPFLAGS '-DMKSH_DEFAULT_EXECSHELL=\"/system/bin/sh\"' 152 addvar CPPFLAGS '-DMKSH_DEFAULT_TMPDIR=\"/data/local\"' 153 fi 154 155 ### Override flags 156 # Let the shell free all memory upon exiting 157 addvar CPPFLAGS -DDEBUG_LEAKS 158 # UTF-8 works nowadays 159 addvar CPPFLAGS -DMKSH_ASSUME_UTF8 160 # Reduce filedescriptor usage 161 addvar CPPFLAGS -DMKSH_CONSERVATIVE_FDS 162 # Leave out RCS ID strings from the binary 163 addvar CPPFLAGS -DMKSH_DONT_EMIT_IDSTRING 164 # No getpwnam() calls (affects "cd ~username/" only) 165 addvar CPPFLAGS -DMKSH_NOPWNAM 166 # Leave out the ulimit builtin 167 #addvar CPPFLAGS -DMKSH_NO_LIMITS 168 # Compile an extra small mksh (optional) 169 #addvar CPPFLAGS -DMKSH_SMALL 170 171 # Set target platform 172 TARGET_OS=Android 173 174 # Android-x86 does not have helper functions for ProPolice SSP 175 # and AOSP adds the flags by itself (same for warning flags) 176 HAVE_CAN_FNOSTRICTALIASING=0 177 HAVE_CAN_FSTACKPROTECTORALL=0 178 HAVE_CAN_WALL=0 179 export HAVE_CAN_FNOSTRICTALIASING HAVE_CAN_FSTACKPROTECTORALL HAVE_CAN_WALL 180 181 # even the idea of persistent history on a phone is funny 182 HAVE_PERSISTENT_HISTORY=0; export HAVE_PERSISTENT_HISTORY 183 184 # this is a run-time check and dependent on the target CPU 185 # architecture (at _least_!) and cannot be auto-detected, 186 # so always include the safety check even if unnecessary 187 HAVE_SILENT_IDIVWRAPV=0; export HAVE_SILENT_IDIVWRAPV 188 189 # ... and run it! 190 export CC CPPFLAGS CFLAGS LDFLAGS LIBS TARGET_OS 191 sh ../src/Build.sh $args 192 rv=$? 193 test x"$args" = x"-r" && exit $rv 194 test x0 = x"$rv" && mv -f Makefrag.inc ../ 195 cd .. 196 rm -rf tmp 197 exit $rv 198