runtimeos.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2022 The Syncthing Authors.
  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 file,
  5. # You can obtain one at https://mozilla.org/MPL/2.0/.
  6. #!/bin/sh
  7. # List known operating system/architecture combos, removing the
  8. # architecture, and making constants of them.
  9. osname() {
  10. echo "$1" | awk '{print toupper(substr($1, 1, 1)) substr($1, 2)}' \
  11. | sed s/aix/AIX/i \
  12. | sed s/bsd/BSD/i \
  13. | sed s/ios/IOS/i \
  14. | sed s/js/JS/i
  15. }
  16. osconstants() {
  17. echo "// Code generated by runtimeos.sh. DO NOT EDIT."
  18. echo "package build"
  19. echo "import \"runtime\""
  20. echo "const ("
  21. for OS in $(go tool dist list | sed 's|/.*||' | sort | uniq) ; do
  22. name=$(osname "$OS")
  23. echo "$name = \"$OS\""
  24. done
  25. echo ")"
  26. echo
  27. echo "const ("
  28. for OS in $(go tool dist list | sed 's|/.*||' | sort | uniq) ; do
  29. name=$(osname "$OS")
  30. echo "Is$name = runtime.GOOS == $name"
  31. done
  32. echo ")"
  33. }
  34. osconstants > runtimeos.gen.go
  35. gofmt -w -s runtimeos.gen.go