| 1 |
#!/usr/bin/env bash |
| 2 |
# |
| 3 |
# crossclang |
| 4 |
# A helper script to simplify cross-compilation |
| 5 |
# |
| 6 |
# sync-target-sdk is to be run on the target platform |
| 7 |
# see prepare-target-sdk for details |
| 8 |
# |
| 9 |
# Copyright 2019 Christian Kohlschütter |
| 10 |
# |
| 11 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 12 |
# you may not use this file except in compliance with the License. |
| 13 |
# You may obtain a copy of the License at |
| 14 |
# |
| 15 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 16 |
# |
| 17 |
# Unless required by applicable law or agreed to in writing, software |
| 18 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 19 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 |
# See the License for the specific language governing permissions and |
| 21 |
# limitations under the License. |
| 22 |
# |
| 23 |
showHelp=0 |
| 24 |
if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then |
| 25 |
showHelp=1 |
| 26 |
fi |
| 27 |
|
| 28 |
no_libraries=0 |
| 29 |
sdkroot= |
| 30 |
while [ $# -gt 0 ]; do |
| 31 |
arg="$1" |
| 32 |
shift |
| 33 |
case "$arg" in |
| 34 |
-L) no_libraries=1 ;; |
| 35 |
-*) showHelp=1 ;; |
| 36 |
*) |
| 37 |
if [ -n "$sdkroot" ]; then |
| 38 |
showHelp=1; |
| 39 |
else |
| 40 |
sdkroot="$arg"; |
| 41 |
fi |
| 42 |
;; |
| 43 |
esac |
| 44 |
done |
| 45 |
|
| 46 |
if [ -z "$sdkroot" ]; then |
| 47 |
showHelp=1 |
| 48 |
fi |
| 49 |
|
| 50 |
if [ $showHelp -eq 1 ]; then |
| 51 |
cat >&2 <<EOT |
| 52 |
USAGE: $0 [-L] <path-to-sdk> |
| 53 |
|
| 54 |
OPTIONS: |
| 55 |
-L Do not transfer libraries or frameworks |
| 56 |
|
| 57 |
EOT |
| 58 |
exit 1 |
| 59 |
fi |
| 60 |
|
| 61 |
targetConf="$sdkroot/target.conf" |
| 62 |
if [ ! -f "$targetConf" ]; then |
| 63 |
echo "target.conf not found: $targetConf" >&2 |
| 64 |
exit 1 |
| 65 |
fi |
| 66 |
|
| 67 |
sdkroot=$(cd "$sdkroot"; pwd) |
| 68 |
|
| 69 |
target_include_path=() |
| 70 |
target_library_path=() |
| 71 |
target_framework_path=() |
| 72 |
IFS=$'\n' |
| 73 |
source "$targetConf" |
| 74 |
|
| 75 |
if [ $no_libraries -gt 0 ]; then |
| 76 |
target_library_path=() |
| 77 |
target_framework_path=() |
| 78 |
fi |
| 79 |
|
| 80 |
recursive_paths=() |
| 81 |
recursive_paths+=("${target_include_path[@]}") |
| 82 |
recursive_paths+=("${target_framework_path[@]}") |
| 83 |
|
| 84 |
flat_paths=() |
| 85 |
flat_paths+=("${target_library_path[@]}") |
| 86 |
|
| 87 |
declare includeFile |
| 88 |
declare -a paths |
| 89 |
declare recursive=0 |
| 90 |
|
| 91 |
includeFile="$sdkroot/include-files.txt" |
| 92 |
rm -f "$includeFile" |
| 93 |
|
| 94 |
function add_paths() { |
| 95 |
for path in "${paths[@]}"; do |
| 96 |
if [[ -z "$path" || "$path" == "/" ]]; then |
| 97 |
continue |
| 98 |
fi |
| 99 |
dir="${path%/*}" |
| 100 |
sourcepath="$path" |
| 101 |
|
| 102 |
if [ $recursive -eq 0 ]; then |
| 103 |
find "$path" -mindepth 1 -maxdepth 1 -not -type d >> "$includeFile" |
| 104 |
else |
| 105 |
find "$path" -not -type d >> "$includeFile" |
| 106 |
fi |
| 107 |
done |
| 108 |
} |
| 109 |
|
| 110 |
paths=(${recursive_paths[@]}) |
| 111 |
recursive=1 |
| 112 |
add_paths |
| 113 |
|
| 114 |
paths=(${flat_paths[@]}) |
| 115 |
recursive=0 |
| 116 |
add_paths |
| 117 |
|
| 118 |
cd "$sdkroot/" |
| 119 |
# rsync -avR --prune-empty-dirs --include-from="$includeFile" --exclude '*' / . |
| 120 |
tar cvf - -C / -T "$includeFile" | tar xvf - -C . |
| 121 |
rm "$includeFile" |