buildsystem.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh
  2. set -e
  3. NCPUS=$(sysctl hw.ncpufound | sed 's/.*=//')
  4. # Try to find a valid way to become root if not already
  5. SUDO=
  6. if [ -e '/etc/doas.conf' ]; then
  7. SUDO='/usr/bin/doas'
  8. elif [ -x '/usr/local/bin/sudo' ]; then
  9. SUDO='/usr/local/bin/sudo'
  10. fi
  11. # Bail out if not root and neither sudo or doas was found.
  12. _uid=$(id -u)
  13. if [ -z ${SUDO} -a \( ${_uid} -ne 0 \) ]; then
  14. echo 'Need a way to become root, neither sudo or doas found...' 1>&2
  15. exit 1
  16. elif [ ${_uid} -eq 0 ]; then
  17. # Clear SUDO if already root
  18. SUDO=
  19. fi
  20. # Find the source tree for the base system
  21. if [ -e /etc/mk.conf ]; then
  22. BSDSRCDIR=$(make -f /etc/mk.conf -V BSDSRCDIR)
  23. BSDOBJDIR=$(make -f /etc/mk.conf -V BSDOBJDIR)
  24. fi
  25. BSDSRCDIR=${BSDSRCDIR:=/usr/src}
  26. BSDOBJDIR=${BSDOBJDIR:=/usr/obj}
  27. START_TIME=$(date)
  28. cd ${BSDOBJDIR} && mkdir -p .old && ${SUDO} mv * .old && ${SUDO} rm -rf .old &
  29. cd ${BSDSRCDIR} && make obj
  30. cd ${BSDSRCDIR}/etc && ${SUDO} make DESTDIR=/ distrib-dirs
  31. cd ${BSDSRCDIR}
  32. make SUDO=${SUDO} build -j $((NCPUS * 2))
  33. RESULT=$?
  34. END_TIME=$(date)
  35. echo "Build started at ${START_TIME}, ended at ${END_TIME}"
  36. exit ${RESULT}