blob: f819e0dfbdafa49ab59a8a664aec45c0757e38ae [file] [log] [blame]
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001# Copyright © 2010, 2012, 2013
2# Thorsten Glaser <tg@mirbsd.org>
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003# 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 Glaserc2dc5de2013-02-18 23:02:51 +000011if test x"$1" = x"-t"; then
12 # test compilation
13 args=-r
14 mkmfmode=1
15else
16 # prepare for AOSP
17 args=-M
18 mkmfmode=0
19fi
20
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070021cd "$(dirname "$0")"
22srcdir=$(pwd)
23rm -rf tmp
24mkdir tmp
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000025cd ../..
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070026aospdir=$(pwd)
27cd $srcdir/tmp
28
29addvar() {
30 _vn=$1; shift
31
32 eval $_vn=\"\$$_vn '$*"'
33}
34
35CFLAGS=
36CPPFLAGS=
37LDFLAGS=
38LIBS=
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
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000055CC=$aospdir/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-gcc
56addvar 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 \
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000067 -isystem $aospdir/external/skia/include \
68 -isystem $aospdir/out/target/product/generic/obj/include \
69 -isystem $aospdir/bionic/libc/arch-arm/include \
70 -isystem $aospdir/bionic/libc/include \
71 -isystem $aospdir/bionic/libstdc++/include \
Christopher Ferris98a3aa62013-12-18 14:56:42 -080072 -isystem $aospdir/bionic/libc/kernel/uapi \
73 -isystem $aospdir/bionic/libc/kernel/uapi/asm-arm \
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000074 -isystem $aospdir/bionic/libm/include \
75 -isystem $aospdir/bionic/libm/include/arm \
76 -isystem $aospdir/bionic/libthread_db/include \
Thorsten Glaser811a5752013-07-25 14:24:45 +000077 -D_FORTIFY_SOURCE=2 \
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000078 -include $aospdir/build/core/combo/include/arch/linux-arm/AndroidConfig.h \
79 -I$aospdir/build/core/combo/include/arch/linux-arm/ \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070080 -DANDROID -DNDEBUG -UDEBUG
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000081addvar CFLAGS \
82 -fno-exceptions \
83 -Wno-multichar \
84 -msoft-float \
85 -fpic \
86 -fPIE \
87 -ffunction-sections \
88 -fdata-sections \
89 -funwind-tables \
90 -fstack-protector \
91 -Wa,--noexecstack \
92 -Werror=format-security \
93 -fno-short-enums \
94 -march=armv7-a \
95 -mfloat-abi=softfp \
96 -mfpu=vfpv3-d16 \
97 -Wno-unused-but-set-variable \
98 -fno-builtin-sin \
99 -fno-strict-volatile-bitfields \
100 -Wno-psabi \
101 -mthumb-interwork \
102 -fmessage-length=0 \
103 -W \
104 -Wall \
105 -Wno-unused \
106 -Winit-self \
107 -Wpointer-arith \
108 -Werror=return-type \
109 -Werror=non-virtual-dtor \
110 -Werror=address \
111 -Werror=sequence-point \
112 -g \
113 -Wstrict-aliasing=2 \
114 -fgcse-after-reload \
115 -frerun-cse-after-loop \
116 -frename-registers \
117 -mthumb \
118 -Os \
119 -fomit-frame-pointer \
120 -fno-strict-aliasing
121addvar LDFLAGS \
122 -nostdlib \
123 -Bdynamic \
Thorsten Glaser811a5752013-07-25 14:24:45 +0000124 -fPIE \
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000125 -pie \
126 -Wl,-dynamic-linker,/system/bin/linker \
127 -Wl,--gc-sections \
128 -Wl,-z,nocopyreloc \
129 -Wl,-z,noexecstack \
130 -Wl,-z,relro \
131 -Wl,-z,now \
132 -Wl,--warn-shared-textrel \
Thorsten Glaser811a5752013-07-25 14:24:45 +0000133 -Wl,--fatal-warnings \
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000134 -Wl,--icf=safe \
135 -Wl,--fix-cortex-a8 \
136 -Wl,--no-undefined \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700137 $aospdir/out/target/product/generic/obj/lib/crtbegin_dynamic.o
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000138addvar LIBS \
139 -L$aospdir/out/target/product/generic/obj/lib \
140 -Wl,-rpath-link=$aospdir/out/target/product/generic/obj/lib \
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000141 -Wl,--no-whole-archive \
Thorsten Glaser811a5752013-07-25 14:24:45 +0000142 $aospdir/out/target/product/generic/obj/STATIC_LIBRARIES/libcompiler_rt-extras_intermediates/libcompiler_rt-extras.a \
143 -lc \
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000144 $aospdir/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/../lib/gcc/arm-linux-androideabi/4.7/armv7-a/libgcc.a \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700145 $aospdir/out/target/product/generic/obj/lib/crtend_android.o
146
147
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000148### Flags used by test builds
149if test $mkmfmode = 1; then
150 addvar CPPFLAGS '-DMKSHRC_PATH=\"/system/etc/mkshrc\"'
151 addvar CPPFLAGS '-DMKSH_DEFAULT_EXECSHELL=\"/system/bin/sh\"'
Nick Kralevichfd187c62013-02-20 11:20:51 -0800152 addvar CPPFLAGS '-DMKSH_DEFAULT_TMPDIR=\"/data/local\"'
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000153fi
154
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700155### Override flags
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000156# Let the shell free all memory upon exiting
157addvar CPPFLAGS -DDEBUG_LEAKS
158# UTF-8 works nowadays
159addvar CPPFLAGS -DMKSH_ASSUME_UTF8
160# Reduce filedescriptor usage
161addvar CPPFLAGS -DMKSH_CONSERVATIVE_FDS
162# Leave out RCS ID strings from the binary
163addvar CPPFLAGS -DMKSH_DONT_EMIT_IDSTRING
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700164# No getpwnam() calls (affects "cd ~username/" only)
165addvar CPPFLAGS -DMKSH_NOPWNAM
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700166# Leave out the ulimit builtin
167#addvar CPPFLAGS -DMKSH_NO_LIMITS
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000168# Compile an extra small mksh (optional)
169#addvar CPPFLAGS -DMKSH_SMALL
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700170
171# Set target platform
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000172TARGET_OS=Android
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700173
174# Android-x86 does not have helper functions for ProPolice SSP
175# and AOSP adds the flags by itself (same for warning flags)
176HAVE_CAN_FNOSTRICTALIASING=0
177HAVE_CAN_FSTACKPROTECTORALL=0
178HAVE_CAN_WALL=0
179export HAVE_CAN_FNOSTRICTALIASING HAVE_CAN_FSTACKPROTECTORALL HAVE_CAN_WALL
180
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700181# even the idea of persistent history on a phone is funny
182HAVE_PERSISTENT_HISTORY=0; export HAVE_PERSISTENT_HISTORY
183
184# ... and run it!
185export CC CPPFLAGS CFLAGS LDFLAGS LIBS TARGET_OS
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000186sh ../src/Build.sh $args
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700187rv=$?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000188test x"$args" = x"-r" && exit $rv
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700189test x0 = x"$rv" && mv -f Makefrag.inc ../
190cd ..
191rm -rf tmp
192exit $rv