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