]>
Commit | Line | Data |
---|---|---|
eed4f174 JF |
1 | #!/bin/bash |
2 | ||
3 | shopt -s extglob | |
4 | ||
5 | hpp=$1 | |
6 | object=$2 | |
7 | name=$3 | |
8 | sed=$4 | |
9 | otool=$5 | |
10 | lipo=$6 | |
11 | nm=$7 | |
12 | shift 7 | |
13 | ||
14 | #shift 1 | |
15 | #set /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/usr/include "$@" | |
16 | ||
17 | "$@" | |
18 | ||
19 | detailed=$(lipo -detailed_info "${object}") | |
20 | ||
21 | { | |
22 | ||
23 | echo '#include "Trampoline.hpp"' | |
24 | ||
25 | for arch in $(echo "${detailed}" | "${sed}" -e '/^architecture / { s/^architecture //; p; }; d;'); do | |
26 | offset=$(echo "${detailed}" | "${sed}" -e ' | |
27 | /^architecture / { x; s/.*/0/; x; }; | |
28 | /^architecture '${arch}'$/ { x; s/.*/1/; x; }; | |
29 | x; /^1$/ { x; /^ *offset / { s/^ *offset //; p; }; x; }; x; | |
30 | d; | |
31 | ') | |
32 | ||
33 | file=($("${otool}" -arch "${arch}" -l "${object}" | "${sed}" -e ' | |
34 | x; /^1$/ { x; | |
35 | /^ *fileoff / { s/^.* //; p; }; | |
36 | /^ *filesize / { s/^.* //; p; }; | |
37 | x; }; x; | |
38 | ||
39 | /^ *cmd LC_SEGMENT/ { x; s/.*/1/; x; }; | |
40 | ||
41 | d; | |
42 | ')) | |
43 | ||
44 | fileoff=${file[0]} | |
45 | filesize=${file[1]} | |
46 | ||
47 | echo | |
48 | echo "static const char ${name}_${arch}_data_[] = {" | |
49 | ||
50 | od -v -t x1 -t c -j "$((offset + fileoff))" -N "${filesize}" "${object}" | "${sed}" -e ' | |
51 | /^[0-7]/ ! { | |
52 | s@^ @// @; | |
53 | s/\(....\)/ \1/g; | |
54 | s@^ // @//@; | |
73d3a679 | 55 | s/ *$/,/; |
eed4f174 JF |
56 | }; |
57 | ||
58 | /^[0-7]/ { | |
59 | s/^[^ ]*//; | |
60 | s/ */ /g; | |
61 | s/^ *//; | |
62 | s/ $//; | |
63 | s/ /,/g; | |
64 | s/\([^,][^,]\)/0x\1/g; | |
65 | s/$/,/; | |
66 | /^,$/ ! { s/^/ /g; p; }; d; | |
67 | }; | |
68 | ' | |
69 | ||
70 | echo "};" | |
71 | ||
72 | echo | |
73 | entry=$("${nm}" -arch "${arch}" "${object}" | "${sed}" -e '/ _Start$/ { s/ .*//; p; }; d;') | |
74 | entry=${entry##*(0)} | |
75 | echo "static size_t ${name}_${arch}_entry_ = 0x${entry:=0};" | |
76 | ||
77 | echo | |
78 | echo "/*" | |
79 | "${otool}" -vVt -arch "${arch}" "${object}" | |
80 | echo "*/" | |
81 | ||
82 | echo | |
83 | echo "static Trampoline ${name}_${arch}_ = {" | |
84 | echo " ${name}_${arch}_data_," | |
85 | echo " sizeof(${name}_${arch}_data_)," | |
86 | echo " ${name}_${arch}_entry_," | |
87 | echo "};" | |
88 | done | |
89 | ||
90 | } >"${hpp}" | |
91 | ||
92 | #rm -f "${object}" |