oe-setup-builddir 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/sh
  2. # OE Build Environment Setup Script
  3. #
  4. # Copyright (C) 2006-2011 Linux Foundation
  5. #
  6. # SPDX-License-Identifier: GPL-2.0-or-later
  7. #
  8. die() {
  9. echo Error: "$@" >&2
  10. exit 1
  11. }
  12. [ -n "$BUILDDIR" ] || die "The build directory (BUILDDIR) must be set!"
  13. if [ "$1" = '--help' ] || [ "$1" = '-h' ]; then
  14. echo 'Usage: oe-setup-builddir'
  15. echo ''
  16. echo "OpenEmbedded setup-builddir - setup build directory $BUILDDIR"
  17. echo ''
  18. exit 2
  19. fi
  20. mkdir -p "$BUILDDIR/conf"
  21. [ -d "$BUILDDIR" ] || die "The build directory ($BUILDDIR) does not exist!"
  22. [ -w "$BUILDDIR" ] ||
  23. die "Cannot write to $BUILDDIR, perhaps try sourcing with a writable path? i.e. . oe-init-build-env ~/my-build"
  24. # Attempting removal of sticky,setuid bits from BUILDDIR, BUILDDIR/conf
  25. chmod -st "$BUILDDIR" 2>/dev/null || echo "WARNING: unable to chmod $BUILDDIR"
  26. chmod -st "$BUILDDIR/conf" 2>/dev/null || echo "WARNING: unable to chmod $BUILDDIR/conf"
  27. cd "$BUILDDIR" || die "Failed to change directory to $BUILDDIR!"
  28. . "$OEROOT/.templateconf"
  29. # Keep the original TEMPLATECONF before possibly prefixing it with $OEROOT below.
  30. ORG_TEMPLATECONF=$TEMPLATECONF
  31. #
  32. # $TEMPLATECONF can point to a directory for the template local.conf & bblayers.conf
  33. #
  34. if [ -n "$TEMPLATECONF" ]; then
  35. if [ ! -d "$TEMPLATECONF" ]; then
  36. # Allow TEMPLATECONF=meta-xyz/conf as a shortcut
  37. if [ -d "$OEROOT/$TEMPLATECONF" ]; then
  38. TEMPLATECONF="$OEROOT/$TEMPLATECONF"
  39. fi
  40. [ -d "$TEMPLATECONF" ] ||
  41. die "TEMPLATECONF value points to nonexistent directory '$TEMPLATECONF'"
  42. fi
  43. templatesdir=$(python3 -c "import sys; print(sys.argv[1].strip('/').split('/')[-2])" "$TEMPLATECONF")
  44. if [ "$templatesdir" != templates ] || [ ! -f "$TEMPLATECONF/../../layer.conf" ]; then
  45. die "TEMPLATECONF value (which is $TEMPLATECONF) must point to meta-some-layer/conf/templates/template-name"
  46. fi
  47. OECORELAYERCONF="$TEMPLATECONF/bblayers.conf.sample"
  48. OECORELOCALCONF="$TEMPLATECONF/local.conf.sample"
  49. OECORESUMMARYCONF="$TEMPLATECONF/conf-summary.txt"
  50. OECORENOTESCONF="$TEMPLATECONF/conf-notes.txt"
  51. fi
  52. unset SHOWYPDOC
  53. if [ -z "$OECORELOCALCONF" ]; then
  54. OECORELOCALCONF="$OEROOT/meta/conf/templates/default/local.conf.sample"
  55. fi
  56. if [ ! -r "$BUILDDIR/conf/local.conf" ]; then
  57. cat <<EOM
  58. You had no conf/local.conf file. This configuration file has therefore been
  59. created for you from $OECORELOCALCONF
  60. You may wish to edit it to, for example, select a different MACHINE (target
  61. hardware).
  62. EOM
  63. cp -f "$OECORELOCALCONF" "$BUILDDIR/conf/local.conf"
  64. SHOWYPDOC=yes
  65. fi
  66. if [ -z "$OECORELAYERCONF" ]; then
  67. OECORELAYERCONF="$OEROOT/meta/conf/templates/default/bblayers.conf.sample"
  68. fi
  69. if [ ! -r "$BUILDDIR/conf/bblayers.conf" ]; then
  70. cat <<EOM
  71. You had no conf/bblayers.conf file. This configuration file has therefore been
  72. created for you from $OECORELAYERCONF
  73. To add additional metadata layers into your configuration please add entries
  74. to conf/bblayers.conf.
  75. EOM
  76. # Put the absolute path to the layers in bblayers.conf so we can run
  77. # bitbake without the init script after the first run.
  78. # ##COREBASE## is deprecated as its meaning was inconsistent, but continue
  79. # to replace it for compatibility.
  80. sed -e "s|##OEROOT##|$OEROOT|g" \
  81. -e "s|##COREBASE##|$OEROOT|g" \
  82. "$OECORELAYERCONF" > "$BUILDDIR/conf/bblayers.conf"
  83. SHOWYPDOC=yes
  84. fi
  85. if [ -z "$OECORESUMMARYCONF" ]; then
  86. OECORESUMMARYCONF="$OEROOT/meta/conf/templates/default/conf-summary.txt"
  87. fi
  88. if [ ! -r "$BUILDDIR/conf/conf-summary.txt" ]; then
  89. [ ! -r "$OECORESUMMARYCONF" ] || cp "$OECORESUMMARYCONF" "$BUILDDIR/conf/conf-summary.txt"
  90. fi
  91. if [ -z "$OECORENOTESCONF" ]; then
  92. OECORENOTESCONF="$OEROOT/meta/conf/templates/default/conf-notes.txt"
  93. fi
  94. if [ ! -r "$BUILDDIR/conf/conf-notes.txt" ]; then
  95. [ ! -r "$OECORENOTESCONF" ] || cp "$OECORENOTESCONF" "$BUILDDIR/conf/conf-notes.txt"
  96. fi
  97. # Prevent disturbing a new GIT clone in same console
  98. unset OECORELOCALCONF
  99. unset OECORELAYERCONF
  100. unset OECORESUMMARYCONF
  101. unset OECORENOTESCONF
  102. # Ending the first-time run message. Show the YP Documentation banner.
  103. if [ -n "$SHOWYPDOC" ]; then
  104. cat <<EOM
  105. The Yocto Project has extensive documentation about OE including a reference
  106. manual which can be found at:
  107. https://docs.yoctoproject.org
  108. For more information about OpenEmbedded see the website:
  109. https://www.openembedded.org/
  110. EOM
  111. # unset SHOWYPDOC
  112. fi
  113. [ ! -r "$BUILDDIR/conf/conf-summary.txt" ] || cat "$BUILDDIR/conf/conf-summary.txt"
  114. [ ! -r "$BUILDDIR/conf/conf-notes.txt" ] || cat "$BUILDDIR/conf/conf-notes.txt"
  115. if [ ! -f "$BUILDDIR/conf/templateconf.cfg" ]; then
  116. echo "$ORG_TEMPLATECONF" >"$BUILDDIR/conf/templateconf.cfg"
  117. fi