ext-toolchain.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. #!/usr/bin/env bash
  2. #
  3. # Script for various external toolchain tasks, refer to
  4. # the --help output for more information.
  5. #
  6. # Copyright (C) 2012 Jo-Philipp Wich <jo@mein.io>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. CC=""
  22. CXX=""
  23. CPP=""
  24. CFLAGS=""
  25. TOOLCHAIN="."
  26. LIBC_TYPE=""
  27. GCC_VERSION=""
  28. # Library specs
  29. LIB_SPECS="
  30. c: ld-* lib{anl,c,cidn,crypt,dl,m,nsl,nss_dns,nss_files,resolv,util}
  31. rt: librt-* librt
  32. pthread: libpthread-* libpthread
  33. stdcpp: libstdc++
  34. thread_db: libthread-db
  35. gcc: libgcc_s
  36. ssp: libssp
  37. gfortran: libgfortran
  38. gomp: libgomp
  39. "
  40. # Binary specs
  41. BIN_SPECS="
  42. ldd: ldd
  43. ldconfig: ldconfig
  44. gdb: gdb
  45. gdbserver: gdbserver
  46. "
  47. OVERWRITE_CONFIG=""
  48. test_c() {
  49. cat <<-EOT | "${CC:-false}" $CFLAGS -o /dev/null -x c - 2>/dev/null
  50. #include <stdio.h>
  51. int main(int argc, char **argv)
  52. {
  53. printf("Hello, world!\n");
  54. return 0;
  55. }
  56. EOT
  57. }
  58. test_cxx() {
  59. cat <<-EOT | "${CXX:-false}" $CFLAGS -o /dev/null -x c++ - 2>/dev/null
  60. #include <iostream>
  61. using namespace std;
  62. int main()
  63. {
  64. cout << "Hello, world!" << endl;
  65. return 0;
  66. }
  67. EOT
  68. }
  69. test_softfloat() {
  70. cat <<-EOT | "$CC" $CFLAGS -msoft-float -o /dev/null -x c - 2>/dev/null
  71. int main(int argc, char **argv)
  72. {
  73. double a = 0.1;
  74. double b = 0.2;
  75. double c = (a + b) / (a * b);
  76. return 1;
  77. }
  78. EOT
  79. }
  80. test_uclibc() {
  81. local sysroot="$("$CC" $CFLAGS -print-sysroot 2>/dev/null)"
  82. if [ -d "${sysroot:-$TOOLCHAIN}" ]; then
  83. local lib
  84. for lib in "${sysroot:-$TOOLCHAIN}"/{lib,usr/lib,usr/local/lib}/ld*-uClibc*.so*; do
  85. if [ -f "$lib" ] && [ ! -h "$lib" ]; then
  86. return 0
  87. fi
  88. done
  89. fi
  90. return 1
  91. }
  92. test_feature() {
  93. local feature="$1"; shift
  94. # find compilers, libc type
  95. probe_cc
  96. probe_cxx
  97. probe_libc
  98. # common toolchain feature tests
  99. case "$feature" in
  100. c) test_c; return $? ;;
  101. c++) test_cxx; return $? ;;
  102. soft*) test_softfloat; return $? ;;
  103. esac
  104. # assume eglibc/glibc supports all libc features
  105. if [ "$LIBC_TYPE" != "uclibc" ]; then
  106. return 0
  107. fi
  108. # uclibc feature tests
  109. local inc
  110. local sysroot="$("$CC" "$@" -muclibc -print-sysroot 2>/dev/null)"
  111. for inc in "include" "usr/include" "usr/local/include"; do
  112. local conf="${sysroot:-$TOOLCHAIN}/$inc/bits/uClibc_config.h"
  113. if [ -f "$conf" ]; then
  114. case "$feature" in
  115. lfs) grep -q '__UCLIBC_HAS_LFS__ 1' "$conf"; return $?;;
  116. ipv6) grep -q '__UCLIBC_HAS_IPV6__ 1' "$conf"; return $?;;
  117. rpc) grep -q '__UCLIBC_HAS_RPC__ 1' "$conf"; return $?;;
  118. locale) grep -q '__UCLIBC_HAS_LOCALE__ 1' "$conf"; return $?;;
  119. wchar) grep -q '__UCLIBC_HAS_WCHAR__ 1' "$conf"; return $?;;
  120. threads) grep -q '__UCLIBC_HAS_THREADS__ 1' "$conf"; return $?;;
  121. esac
  122. fi
  123. done
  124. return 1
  125. }
  126. find_libs() {
  127. local spec="$(echo "$LIB_SPECS" | sed -ne "s#^[[:space:]]*$1:##ip")"
  128. if [ -n "$spec" ] && probe_cpp; then
  129. local libdir libdirs
  130. for libdir in $(
  131. "$CPP" $CFLAGS -v -x c /dev/null 2>&1 | \
  132. sed -ne 's#:# #g; s#^LIBRARY_PATH=##p'
  133. ); do
  134. if [ -d "$libdir" ]; then
  135. libdirs="$libdirs $(cd "$libdir"; pwd)/"
  136. fi
  137. done
  138. local pattern
  139. for pattern in $(eval echo $spec); do
  140. find $libdirs -name "$pattern.so*" | sort -u
  141. done
  142. return 0
  143. fi
  144. return 1
  145. }
  146. find_bins() {
  147. local spec="$(echo "$BIN_SPECS" | sed -ne "s#^[[:space:]]*$1:##ip")"
  148. if [ -n "$spec" ] && probe_cpp; then
  149. local sysroot="$("$CPP" -print-sysroot)"
  150. local bindir bindirs
  151. for bindir in $(
  152. echo "${sysroot:-$TOOLCHAIN}/bin";
  153. echo "${sysroot:-$TOOLCHAIN}/usr/bin";
  154. echo "${sysroot:-$TOOLCHAIN}/usr/local/bin";
  155. "$CPP" $CFLAGS -v -x c /dev/null 2>&1 | \
  156. sed -ne 's#:# #g; s#^COMPILER_PATH=##p'
  157. ); do
  158. if [ -d "$bindir" ]; then
  159. bindirs="$bindirs $(cd "$bindir"; pwd)/"
  160. fi
  161. done
  162. local pattern
  163. for pattern in $(eval echo $spec); do
  164. find $bindirs -name "$pattern" | sort -u
  165. done
  166. return 0
  167. fi
  168. return 1
  169. }
  170. find_gcc_version() {
  171. if [ -f $TOOLCHAIN/info.mk ]; then
  172. GCC_VERSION=$(grep GCC_VERSION $TOOLCHAIN/info.mk | sed 's/GCC_VERSION=//')
  173. return 0
  174. fi
  175. echo "Warning! Can't find info.mk, trying to detect with alternative way."
  176. # Very fragile detection
  177. GCC_VERSION=$(find $TOOLCHAIN/bin | grep -oE "gcc-[0-9]+\.[0-9]+\.[0-9]+$" | \
  178. head -1 | sed 's/gcc-//')
  179. }
  180. wrap_bin_cc() {
  181. local out="$1"
  182. local bin="$2"
  183. echo '#!/bin/sh' > "$out"
  184. echo 'for arg in "$@"; do' >> "$out"
  185. echo ' case "$arg" in -l*|-L*|-shared|-static)' >> "$out"
  186. echo -n ' exec "'"$bin"'" '"$CFLAGS"' ${STAGING_DIR:+' >> "$out"
  187. echo -n '-idirafter "$STAGING_DIR/usr/include" ' >> "$out"
  188. echo -n '-L "$STAGING_DIR/usr/lib" ' >> "$out"
  189. echo '-Wl,-rpath-link,"$STAGING_DIR/usr/lib"} "$@" ;;' >> "$out"
  190. echo ' esac' >> "$out"
  191. echo 'done' >> "$out"
  192. echo -n 'exec "'"$bin"'" '"$CFLAGS"' ${STAGING_DIR:+' >> "$out"
  193. echo '-idirafter "$STAGING_DIR/usr/include"} "$@"' >> "$out"
  194. chmod +x "$out"
  195. }
  196. wrap_bin_ld() {
  197. local out="$1"
  198. local bin="$2"
  199. echo '#!/bin/sh' > "$out"
  200. echo -n 'exec "'"$bin"'" ${STAGING_DIR:+' >> "$out"
  201. echo -n '-L "$STAGING_DIR/usr/lib" ' >> "$out"
  202. echo '-rpath-link "$STAGING_DIR/usr/lib"} "$@"' >> "$out"
  203. chmod +x "$out"
  204. }
  205. wrap_bin_other() {
  206. local out="$1"
  207. local bin="$2"
  208. echo '#!/bin/sh' > "$out"
  209. echo 'exec "'"$bin"'" "$@"' >> "$out"
  210. chmod +x "$out"
  211. }
  212. wrap_bins() {
  213. if probe_cc; then
  214. mkdir -p "$1" || return 1
  215. local cmd
  216. for cmd in "${CC%-*}-"*; do
  217. if [ -x "$cmd" ]; then
  218. local out="$1/${cmd##*/}"
  219. local bin="$cmd"
  220. if [ -x "$out" ] && ! grep -q STAGING_DIR "$out"; then
  221. mv "$out" "$out.bin"
  222. bin='$(dirname "$0")/'"${out##*/}"'.bin'
  223. fi
  224. case "${cmd##*/}" in
  225. *-*cc|*-*cc-*|*-*++|*-*++-*|*-cpp)
  226. wrap_bin_cc "$out" "$bin"
  227. ;;
  228. *-ld)
  229. wrap_bin_ld "$out" "$bin"
  230. ;;
  231. *)
  232. wrap_bin_other "$out" "$bin"
  233. ;;
  234. esac
  235. fi
  236. done
  237. return 0
  238. fi
  239. return 1
  240. }
  241. print_config() {
  242. local mktarget="$1"
  243. local mksubtarget
  244. local target="$("$CC" $CFLAGS -dumpmachine)"
  245. local version="$("$CC" $CFLAGS -dumpversion)"
  246. local cpuarch="${target%%-*}"
  247. # get CC; strip version; strip gcc and add - suffix
  248. local prefix="${CC##*/}"; prefix="${prefix%-$version}"; prefix="${prefix%-*}-"
  249. local config="${0%/scripts/*}/.config"
  250. # if no target specified, print choice list and exit
  251. if [ -z "$mktarget" ]; then
  252. # prepare metadata
  253. if [ ! -f "${0%/scripts/*}/tmp/.targetinfo" ]; then
  254. "${0%/*}/scripts/config/mconf" prepare-tmpinfo
  255. fi
  256. local mktargets=$(
  257. sed -ne "
  258. /^Target: / { h };
  259. /^Target-Arch: $cpuarch\$/ { x; s#^Target: ##p }
  260. " "${0%/scripts/*}/tmp/.targetinfo" | sort -u
  261. )
  262. for mktarget in $mktargets; do
  263. case "$mktarget" in */*)
  264. mktargets=$(echo "$mktargets" | sed -e "/^${mktarget%/*}\$/d")
  265. esac
  266. done
  267. if [ -n "$mktargets" ]; then
  268. echo "Available targets:" >&2
  269. echo $mktargets >&2
  270. else
  271. echo -e "Could not find a suitable OpenWrt target for " >&2
  272. echo -e "CPU architecture '$cpuarch' - you need to " >&2
  273. echo -e "define one first!" >&2
  274. fi
  275. return 1
  276. fi
  277. # bail out if there is a .config already
  278. if [ -f "$config" ]; then
  279. if [ "$OVERWRITE_CONFIG" == "" ]; then
  280. echo "There already is a .config file, refusing to overwrite!" >&2
  281. return 1
  282. else
  283. echo "There already is a .config file, trying to overwrite!"
  284. fi
  285. fi
  286. case "$mktarget" in */*)
  287. mksubtarget="${mktarget#*/}"
  288. mktarget="${mktarget%/*}"
  289. ;; esac
  290. if [ ! -f "$config" ]; then
  291. touch "$config"
  292. fi
  293. echo "CONFIG_TARGET_${mktarget}=y" >> "$config"
  294. if [ -n "$mksubtarget" ]; then
  295. echo "CONFIG_TARGET_${mktarget}_${mksubtarget}=y" >> "$config"
  296. fi
  297. if test_feature "softfloat"; then
  298. echo "CONFIG_SOFT_FLOAT=y" >> "$config"
  299. else
  300. echo "# CONFIG_SOFT_FLOAT is not set" >> "$config"
  301. fi
  302. if test_feature "ipv6"; then
  303. echo "CONFIG_IPV6=y" >> "$config"
  304. else
  305. echo "# CONFIG_IPV6 is not set" >> "$config"
  306. fi
  307. if test_feature "locale"; then
  308. echo "CONFIG_BUILD_NLS=y" >> "$config"
  309. else
  310. echo "# CONFIG_BUILD_NLS is not set" >> "$config"
  311. fi
  312. echo "CONFIG_DEVEL=y" >> "$config"
  313. echo "CONFIG_EXTERNAL_TOOLCHAIN=y" >> "$config"
  314. echo "CONFIG_TOOLCHAIN_ROOT=\"$TOOLCHAIN\"" >> "$config"
  315. echo "CONFIG_TOOLCHAIN_PREFIX=\"$prefix\"" >> "$config"
  316. echo "CONFIG_TARGET_NAME=\"$target\"" >> "$config"
  317. if [ -f "$config" ]; then
  318. sed -i '/CONFIG_EXTERNAL_TOOLCHAIN_LIBC_USE_MUSL/d' "$config"
  319. sed -i '/CONFIG_EXTERNAL_TOOLCHAIN_LIBC_USE_GLIBC/d' "$config"
  320. fi
  321. if [ "$LIBC_TYPE" == glibc ]; then
  322. echo "CONFIG_EXTERNAL_TOOLCHAIN_LIBC_USE_GLIBC=y" >> "$config"
  323. elif [ "$LIBC_TYPE" == musl ]; then
  324. echo "CONFIG_EXTERNAL_TOOLCHAIN_LIBC_USE_MUSL=y" >> "$config"
  325. else
  326. echo "Can't detect LIBC type. Aborting!" >&2
  327. return 1
  328. fi
  329. if [ -n "$GCC_VERSION" ]; then
  330. echo "CONFIG_EXTERNAL_GCC_VERSION=\"$GCC_VERSION\"" >> "$config"
  331. else
  332. echo "Can't detect GCC version. Aborting!" >&2
  333. return 1
  334. fi
  335. local lib
  336. for lib in C RT PTHREAD GCC STDCPP SSP GFORTRAN GOMP; do
  337. local file
  338. local spec=""
  339. local llib="$(echo "$lib" | sed -e 's#.*#\L&#')"
  340. for file in $(find_libs "$lib"); do
  341. spec="${spec:+$spec }$(echo "$file" | sed -e "s#^$TOOLCHAIN#.#")"
  342. done
  343. if [ -n "$spec" ]; then
  344. echo "CONFIG_PACKAGE_lib${llib}=y" >> "$config"
  345. echo "CONFIG_LIB${lib}_FILE_SPEC=\"$spec\"" >> "$config"
  346. else
  347. echo "# CONFIG_PACKAGE_lib${llib} is not set" >> "$config"
  348. fi
  349. done
  350. local bin
  351. for bin in LDD LDCONFIG; do
  352. local file
  353. local spec=""
  354. local lbin="$(echo "$bin" | sed -e 's#.*#\L&#')"
  355. for file in $(find_bins "$bin"); do
  356. spec="${spec:+$spec }$(echo "$file" | sed -e "s#^$TOOLCHAIN#.#")"
  357. done
  358. if [ -n "$spec" ]; then
  359. echo "CONFIG_PACKAGE_${lbin}=y" >> "$config"
  360. echo "CONFIG_${bin}_FILE_SPEC=\"$spec\"" >> "$config"
  361. else
  362. echo "# CONFIG_PACKAGE_${lbin} is not set" >> "$config"
  363. fi
  364. done
  365. # inflate
  366. make -C "${0%/scripts/*}" defconfig
  367. return 0
  368. }
  369. probe_cc() {
  370. if [ -z "$CC" ]; then
  371. local bin
  372. for bin in "bin" "usr/bin" "usr/local/bin"; do
  373. local cmd
  374. for cmd in "$TOOLCHAIN/$bin/"*-*cc*; do
  375. if [ -x "$cmd" ] && [ ! -h "$cmd" ]; then
  376. CC="$(cd "${cmd%/*}"; pwd)/${cmd##*/}"
  377. return 0
  378. fi
  379. done
  380. done
  381. return 1
  382. fi
  383. return 0
  384. }
  385. probe_cxx() {
  386. if [ -z "$CXX" ]; then
  387. local bin
  388. for bin in "bin" "usr/bin" "usr/local/bin"; do
  389. local cmd
  390. for cmd in "$TOOLCHAIN/$bin/"*-*++*; do
  391. if [ -x "$cmd" ] && [ ! -h "$cmd" ]; then
  392. CXX="$(cd "${cmd%/*}"; pwd)/${cmd##*/}"
  393. return 0
  394. fi
  395. done
  396. done
  397. return 1
  398. fi
  399. return 0
  400. }
  401. probe_cpp() {
  402. if [ -z "$CPP" ]; then
  403. local bin
  404. for bin in "bin" "usr/bin" "usr/local/bin"; do
  405. local cmd
  406. for cmd in "$TOOLCHAIN/$bin/"*-cpp*; do
  407. if [ -x "$cmd" ] && [ ! -h "$cmd" ]; then
  408. CPP="$(cd "${cmd%/*}"; pwd)/${cmd##*/}"
  409. return 0
  410. fi
  411. done
  412. done
  413. return 1
  414. fi
  415. return 0
  416. }
  417. probe_libc() {
  418. if [ -f $TOOLCHAIN/info.mk ]; then
  419. LIBC_TYPE=$(grep LIBC_TYPE $TOOLCHAIN/info.mk | sed 's/LIBC_TYPE=//')
  420. return 0
  421. fi
  422. echo "Warning! Can't find info.mk, trying to detect with alternative way."
  423. if [ -z "$LIBC_TYPE" ]; then
  424. if test_uclibc; then
  425. LIBC_TYPE="uclibc"
  426. else
  427. LIBC_TYPE="glibc"
  428. fi
  429. fi
  430. return 0
  431. }
  432. while [ -n "$1" ]; do
  433. arg="$1"; shift
  434. case "$arg" in
  435. --toolchain)
  436. [ -d "$1" ] || {
  437. echo "Toolchain directory '$1' does not exist." >&2
  438. exit 1
  439. }
  440. TOOLCHAIN="$(cd "$1"; pwd)"; shift
  441. ;;
  442. --cflags)
  443. CFLAGS="${CFLAGS:+$CFLAGS }$1"; shift
  444. ;;
  445. --print-libc)
  446. if probe_cc; then
  447. probe_libc
  448. echo "$LIBC_TYPE"
  449. exit 0
  450. fi
  451. echo "No C compiler found in '$TOOLCHAIN'." >&2
  452. exit 1
  453. ;;
  454. --print-target)
  455. if probe_cc; then
  456. exec "$CC" $CFLAGS -dumpmachine
  457. fi
  458. echo "No C compiler found in '$TOOLCHAIN'." >&2
  459. exit 1
  460. ;;
  461. --print-bin)
  462. if [ -z "$1" ]; then
  463. echo "Available programs:" >&2
  464. echo $(echo "$BIN_SPECS" | sed -ne 's#:.*$##p') >&2
  465. exit 1
  466. fi
  467. find_bins "$1" || exec "$0" --toolchain "$TOOLCHAIN" --print-bin
  468. exit 0
  469. ;;
  470. --print-libs)
  471. if [ -z "$1" ]; then
  472. echo "Available libraries:" >&2
  473. echo $(echo "$LIB_SPECS" | sed -ne 's#:.*$##p') >&2
  474. exit 1
  475. fi
  476. find_libs "$1" || exec "$0" --toolchain "$TOOLCHAIN" --print-libs
  477. exit 0
  478. ;;
  479. --test)
  480. test_feature "$1"
  481. exit $?
  482. ;;
  483. --wrap)
  484. [ -n "$1" ] || exec "$0" --help
  485. wrap_bins "$1"
  486. exit $?
  487. ;;
  488. --overwrite-config)
  489. OVERWRITE_CONFIG=y
  490. ;;
  491. --config)
  492. if probe_cc; then
  493. probe_libc
  494. find_gcc_version
  495. print_config "$1"
  496. exit $?
  497. fi
  498. echo "No C compiler found in '$TOOLCHAIN'." >&2
  499. exit 1
  500. ;;
  501. -h|--help)
  502. me="$(basename "$0")"
  503. echo -e "\nUsage:\n" >&2
  504. echo -e " $me --toolchain {directory} --print-libc" >&2
  505. echo -e " Print the libc implementation and exit.\n" >&2
  506. echo -e " $me --toolchain {directory} --print-target" >&2
  507. echo -e " Print the GNU target name and exit.\n" >&2
  508. echo -e " $me --toolchain {directory} --print-bin {program}" >&2
  509. echo -e " Print executables belonging to given program," >&2
  510. echo -e " omit program argument to get a list of names.\n" >&2
  511. echo -e " $me --toolchain {directory} --print-libs {library}" >&2
  512. echo -e " Print shared objects belonging to given library," >&2
  513. echo -e " omit library argument to get a list of names.\n" >&2
  514. echo -e " $me --toolchain {directory} --test {feature}" >&2
  515. echo -e " Test given feature, exit code indicates success." >&2
  516. echo -e " Possible features are 'c', 'c++', 'softfloat'," >&2
  517. echo -e " 'lfs', 'rpc', 'ipv6', 'wchar', 'locale' and " >&2
  518. echo -e " 'threads'.\n" >&2
  519. echo -e " $me --toolchain {directory} --wrap {directory}" >&2
  520. echo -e " Create wrapper scripts for C and C++ compiler, " >&2
  521. echo -e " linker, assembler and other key executables in " >&2
  522. echo -e " the directory given with --wrap.\n" >&2
  523. echo -e " $me --toolchain {directory} --config {target}" >&2
  524. echo -e " Analyze the given toolchain and print a suitable" >&2
  525. echo -e " .config for the given target. Omit target " >&2
  526. echo -e " argument to get a list of names.\n" >&2
  527. echo -e " $me --help" >&2
  528. echo -e " Display this help text and exit.\n\n" >&2
  529. echo -e " Most commands also take a --cflags parameter which " >&2
  530. echo -e " is used to specify C flags to be passed to the " >&2
  531. echo -e " cross compiler when performing tests." >&2
  532. echo -e " This parameter may be repeated multiple times." >&2
  533. echo -e " Use --overwrite-config before --config to overwrite" >&2
  534. echo -e " an already present config with the required changes.">&2
  535. exit 1
  536. ;;
  537. *)
  538. echo "Unknown argument '$arg'" >&2
  539. exec $0 --help
  540. ;;
  541. esac
  542. done
  543. exec $0 --help