comparison configure @ 256:7520e2260097

- added to configure some detection on how to compile .s/.S with --noexecstack (or similar), as compilers' defaults are often insane - since no-execstack handling is now in build, remove .note.GNU-stack section markers (were of limites use, anyways, b/c unportable or implemented inconsistently across platforms) - some ToDo, etc. updates
author Tassilo Philipp
date Sat, 20 May 2017 00:02:59 +0200
parents 5cfe4322c500
children 8bb4618c18d8
comparison
equal deleted inserted replaced
255:704c28fd9428 256:7520e2260097
1 #!/bin/sh 1 #!/bin/sh
2 C=Makefile.config 2
3 3 usage() {
4 # get full path
5 case $0 in
6 /*)
7 FULL=$0
8 ;;
9 *)
10 FULL=$PWD/$0
11 ;;
12 esac
13
14 printf "# auto-generated by $0\n" >$C
15 while [ $# -gt 0 ]; do
16 X=$1
17 shift 1
18 # Shell common:
19 case $X in
20 --help|-h|-?)
21 cat <<EOF 4 cat <<EOF
22 usage: $0 --<option>=<value> <var>=<value> .. 5 usage: $0 --<option>=<value> <var>=<value> ..
23 6
24 --prefix=<dir> 7 --prefix=<dir>
25 --target=<platform> uname/special targets: MacOSX,iOS,iPhoneSimulator 8 --target=<platform> uname/special targets: MacOSX,iOS,iPhoneSimulator
30 --sdkroot=<dir> 13 --sdkroot=<dir>
31 14
32 Useful variables CC, CXX, CFLAGS, CXXFLAGS, etc.. 15 Useful variables CC, CXX, CFLAGS, CXXFLAGS, etc..
33 16
34 EOF 17 EOF
18 }
19
20 C=Makefile.config
21
22 # get full path to this file (portable way), and set where to build
23 SRCTOP="`cd \`dirname "$0"\` && pwd`"
24 BLDTOP="$PWD"
25
26
27 printf "# auto-generated by $0\n" >$C
28
29 while [ $# -gt 0 ]; do
30 X=$1
31 shift 1
32 case $X in
33 # Shell common:
34 --help|-h|-?)
35 usage
35 exit 1 36 exit 1
36 ;; 37 ;;
37 # GNU Compatibility: 38 # GNU Compatibility:
38 --prefix=*) 39 --prefix=*)
39 PREFIX=`printf -- "${X}" | cut -c 10-` 40 PREFIX=`printf -- "${X}" | cut -c 10-`
59 printf "error: invalid option ${X}\n" >&2 60 printf "error: invalid option ${X}\n" >&2
60 exit 1 61 exit 1
61 ;; 62 ;;
62 esac 63 esac
63 done 64 done
65
64 printf "PREFIX=${PREFIX:=/usr/local}\n" >>$C 66 printf "PREFIX=${PREFIX:=/usr/local}\n" >>$C
67
65 case ${TARGET:=`uname`} in 68 case ${TARGET:=`uname`} in
66 Linux|GNU/kFreeBSD) 69 Linux|GNU/kFreeBSD)
67 if [ -z "${CFLAGS}" ]; then 70 if [ -z "${CFLAGS}" ]; then
68 printf "CFLAGS=-fPIC\n" >>$C 71 printf "CFLAGS=-fPIC\n" >>$C
69 fi 72 fi
184 printf "AR=psp-ar\n" >>$C 187 printf "AR=psp-ar\n" >>$C
185 printf "CFLAGS=-I${SDKROOT}/include/\n" >>$C 188 printf "CFLAGS=-I${SDKROOT}/include/\n" >>$C
186 printf "CXXFLAGS=-I${SDKROOT}/include/\n" >>$C 189 printf "CXXFLAGS=-I${SDKROOT}/include/\n" >>$C
187 # Pulling in dyncall libs below is a hack, for some reason psp-ld is super-picky about order. 190 # Pulling in dyncall libs below is a hack, for some reason psp-ld is super-picky about order.
188 # Use your C lib of choice, from the PSPSDK, or... 191 # Use your C lib of choice, from the PSPSDK, or...
189 #printf "LDLIBS=-L${SDKROOT}/lib/ -L`dirname ${FULL}`/dyncall -L`dirname ${FULL}`/dyncallback -ldyncall_s -ldyncallback_s -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lstdc++ -lpsplibc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser \n" >>$C 192 #printf "LDLIBS=-L${SDKROOT}/lib/ -L${SRCTOP}/dyncall -L${SRCTOP}/dyncallback -ldyncall_s -ldyncallback_s -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lstdc++ -lpsplibc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser \n" >>$C
190 # ... newlib. 193 # ... newlib.
191 printf "LDLIBS=-L${SDKROOT}/lib/ -L`dirname ${FULL}`/dyncall -L`dirname ${FULL}`/dyncallback -ldyncall_s -ldyncallback_s -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lstdc++ -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser \n" >>$C 194 printf "LDLIBS=-L${SDKROOT}/lib/ -L${SRCTOP}/dyncall -L${SRCTOP}/dyncallback -ldyncall_s -ldyncallback_s -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lstdc++ -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser \n" >>$C
192 ;; 195 ;;
193 ?) 196 ?)
194 cat $0 | awk '/^esac$/{b=0}/^ [A-Za-z0-9|]+\)/{if(b==1) print substr($1,1,length($1)-1)}BEGIN{b=0}/^case.*TARGET.*uname.*in$/{b=1}' | tr '|' '\n' 197 cat $0 | awk '/^esac$/{b=0}/^ [A-Za-z0-9|]+\)/{if(b==1) print substr($1,1,length($1)-1)}BEGIN{b=0}/^case.*TARGET.*uname.*in$/{b=1}' | tr '|' '\n'
195 exit 0 198 exit 0
196 ;; 199 ;;
197 esac 200 esac
198 201
199 BLDTOP="$PWD" 202
200 SRCTOP=`dirname ${FULL}` 203 # Assure objects not asking for an execstack (or binary that links dyncall might end
204 # up with one, for no reason).
205
206 # We run our .s and .S files through $CC. GCC and others (annoyingly) assume without
207 # being told explicitly that an executable stack may be required for those.
208 # Trying to specify this per source via .section .note.GNU-stack,"",... turned out to
209 # be not consistently implemented across our supported platforms and toolchains, and
210 # thus not being portable (on some platforms even resulting in the opposite, the mere
211 # presence of this section, no matter the flags, creating an rwx stack).
212 # So, let's set the needed build flags by running a few tests, if we find any that
213 # work.
214
215 #determine_asflags() {
216 # AS_PROG=".global main\nmain:\n"
217 # echo "${AS_PROG}" | cc -xassembler -o rwxtest.d.out -
218 # echo "${AS_PROG}.section .note.GNU-stack,\"\"" | cc -xassembler -o rwxtest.s.out -
219 # echo "${AS_PROG}" | cc -xassembler -o rwxtest.f.out -Wa,--noexecstack -
220
221 # @@@ find solution for platforms without objdump
222 RWXTESTBIN="$BLDTOP/rwxtest.out" # @@@ put this maybe all in Makefile.generic? out of source builds?
223 STACKFLAGS=`make -f - <<MAKEFILE
224 include $C
225 t:
226 @(echo .global main;echo main:) | \\\${CC} -xassembler -o "$RWXTESTBIN" -Wa,--noexecstack -
227 @(which objdump && objdump -p "$RWXTESTBIN") | grep -A1 STACK | sed '1d;s/^.*flags //' | awk '{print \\\$1}'
228 MAKEFILE
229 `
230 rm "$RWXTESTBIN" 2>/dev/null
231 if [ "$STACKFLAGS" = "rw-" ]; then
232 # platforms differe here, so set them all
233 printf "ASFLAGS=-Wa,--noexecstack\n" >>$C # common on GNU
234 printf "ACFLAGS=-Wa,--noexecstack\n" >>$C # specifically for .S.o
235 printf "AFLAGS=--noexecstack\n" >>$C # for direct assembler invocation
236 fi
237
238 #if echo ".global main\nmain:\n" | cc -xassembler -o rwxtest.f.out -Wa,--noexecstack -
239 #(which objdump && objdump -p rwxtest.f.out || echo stack flags lookup_err) | grep -i -A1 stack | grep 'flags.*' | sed 's/^.*flags //'
240 #}
241
242 #printf "ACFLAGS=-Wa,--noexecstack\n" >>$C
243 #printf "AFLAGS=--noexecstack\n" >>$C
244
245
246 # Generate all makefiles needed
201 247
202 FILES=`( cd $SRCTOP ; find . -name "Makefile.generic" )` 248 FILES=`( cd $SRCTOP ; find . -name "Makefile.generic" )`
203 for FILE in $FILES ; do 249 for FILE in $FILES ; do
204 SRCFILE="$SRCTOP/$FILE" 250 SRCFILE="$SRCTOP/$FILE"
205 BLDFILE="$BLDTOP/$FILE" 251 BLDFILE="$BLDTOP/$FILE"
210 VPATH = $SRCDIR 256 VPATH = $SRCDIR
211 include $BLDTOP/Makefile.config 257 include $BLDTOP/Makefile.config
212 include \${VPATH}/Makefile.generic 258 include \${VPATH}/Makefile.generic
213 EOF 259 EOF
214 done 260 done
261