mozconfig-find 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #! /bin/sh
  2. #
  3. # This Source Code Form is subject to the terms of the Mozilla Public
  4. # License, v. 2.0. If a copy of the MPL was not distributed with this
  5. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. # mozconfigfind - Loads options from .mozconfig onto configure's
  7. # command-line. The .mozconfig file is searched for in the
  8. # order:
  9. # If $MOZCONFIG is set, use that.
  10. # If one of $TOPSRCDIR/.mozconfig or $TOPSRCDIR/mozconfig exists, use it.
  11. # If both exist, or if various legacy locations contain a mozconfig, error.
  12. # Otherwise, use the default build options.
  13. #
  14. topsrcdir=$1
  15. abspath() {
  16. if uname -s | grep -q MINGW; then
  17. # We have no way to figure out whether we're in gmake or pymake right
  18. # now. gmake gives us Unix-style paths while pymake gives us Windows-style
  19. # paths, so attempt to handle both.
  20. regexes='^\([A-Za-z]:\|\\\\\|\/\) ^\/'
  21. else
  22. regexes='^\/'
  23. fi
  24. for regex in $regexes; do
  25. if echo $1 | grep -q $regex; then
  26. echo $1
  27. return
  28. fi
  29. done
  30. # If we're at this point, we have a relative path
  31. echo `pwd`/$1
  32. }
  33. if [ -n "$MOZCONFIG" ] && ! [ -f "$MOZCONFIG" ]; then
  34. echo "Specified MOZCONFIG \"$MOZCONFIG\" does not exist!" 1>&2
  35. exit 1
  36. fi
  37. if [ -n "$MOZ_MYCONFIG" ]; then
  38. echo "Your environment currently has the MOZ_MYCONFIG variable set to \"$MOZ_MYCONFIG\". MOZ_MYCONFIG is no longer supported. Please use MOZCONFIG instead." 1>&2
  39. exit 1
  40. fi
  41. if [ -z "$MOZCONFIG" ] && [ -f "$topsrcdir/.mozconfig" ] && [ -f "$topsrcdir/mozconfig" ]; then
  42. echo "Both \$topsrcdir/.mozconfig and \$topsrcdir/mozconfig are supported, but you must choose only one. Please remove the other." 1>&2
  43. exit 1
  44. fi
  45. for _config in "$MOZCONFIG" \
  46. "$topsrcdir/.mozconfig" \
  47. "$topsrcdir/mozconfig"
  48. do
  49. if test -f "$_config"; then
  50. abspath $_config
  51. exit 0
  52. fi
  53. done
  54. # We used to support a number of other implicit .mozconfig locations. We now
  55. # detect if we were about to use any of these locations and issue an error if we
  56. # find any.
  57. for _config in "$topsrcdir/mozconfig.sh" \
  58. "$topsrcdir/myconfig.sh" \
  59. "$HOME/.mozconfig" \
  60. "$HOME/.mozconfig.sh" \
  61. "$HOME/.mozmyconfig.sh"
  62. do
  63. if test -f "$_config"; then
  64. echo "You currently have a mozconfig at \"$_config\". This implicit location is no longer supported. Please move it to $topsrcdir/.mozconfig or specify it explicitly via \$MOZCONFIG." 1>&2
  65. exit 1
  66. fi
  67. done