1
0

envsetup.sh 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/bash
  2. #
  3. # Copyright 2026 Aarav Ravindra Kharade
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # ═══════════════════════════════════════════════════════════════════
  18. # ArkOS Build Environment Setup
  19. # ═══════════════════════════════════════════════════════════════════
  20. #
  21. # Usage:
  22. # source envsetup.sh
  23. # type arm64 # Select ARM64 target (Raspberry Pi 4)
  24. # type x86_64 # Select x86_64 target (PC / QEMU)
  25. # make # Build for the selected target
  26. #
  27. # This script mirrors Android's envsetup.sh / lunch workflow.
  28. # It must be sourced (not executed) so functions persist in your
  29. # shell session.
  30. #
  31. # ═══════════════════════════════════════════════════════════════════
  32. # Detect the directory this script lives in
  33. export ARKOS_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  34. export ARKOS_REPO="$(cd "$ARKOS_ROOT/.." && pwd)"
  35. export ARKOS_TOOLS="$ARKOS_REPO/tools"
  36. export ARKOS_OUT="$ARKOS_ROOT/out_staging"
  37. export ARKOS_FINISHED="$ARKOS_ROOT/finished"
  38. # ── Host Architecture Detection ───────────────────────────────────
  39. export HOST_ARCH="$(uname -m)"
  40. case "$HOST_ARCH" in
  41. x86_64|amd64) HOST_ARCH="x86_64" ;;
  42. aarch64|arm64) HOST_ARCH="aarch64" ;;
  43. *) HOST_ARCH="x86_64" ;;
  44. esac
  45. export HOST_ARCH
  46. # ── Clang Toolchain ───────────────────────────────────────────────
  47. # Prefer the prebuilt clang shipped with ArkOS, fall back to system clang
  48. if [ -x "$ARKOS_ROOT/prebuilts/clang/bin/clang" ]; then
  49. export ARKOS_CLANG="$ARKOS_ROOT/prebuilts/clang/bin/clang"
  50. export ARKOS_CLANGXX="$ARKOS_ROOT/prebuilts/clang/bin/clang++"
  51. else
  52. export ARKOS_CLANG="$(which clang 2>/dev/null || echo clang)"
  53. export ARKOS_CLANGXX="$(which clang++ 2>/dev/null || echo clang++)"
  54. fi
  55. # ── type() — Target Architecture Selector ─────────────────────────
  56. #
  57. # Works like Android's lunch command. Sets all compiler variables
  58. # for the selected target architecture.
  59. #
  60. # Supported targets:
  61. # arm64 — Raspberry Pi 4 (aarch64-linux-gnu)
  62. # x86_64 — Standard PC / QEMU (x86_64-linux-gnu)
  63. function type() {
  64. local target="$1"
  65. if [ -z "$target" ]; then
  66. echo ""
  67. echo " Usage: type <target>"
  68. echo ""
  69. echo " Available targets:"
  70. echo " arm64 — Raspberry Pi 4 Model B (aarch64-linux-gnu)"
  71. echo " x86_64 — Standard PC / QEMU (x86_64-linux-gnu)"
  72. echo ""
  73. return 1
  74. fi
  75. case "$target" in
  76. arm64|aarch64)
  77. export TARGET_ARCH="aarch64"
  78. export TARGET_TRIPLE="aarch64-linux-gnu"
  79. export TARGET_DEVICE="rpi4"
  80. export TARGET_KERNEL="arm64"
  81. export TARGET_KERNEL_IMAGE="Image"
  82. export TARGET_SYSROOT="$ARKOS_ROOT/system/sysrootaarch64"
  83. export TARGET_MODULES_DIR="$ARKOS_ROOT/system/sysrootaarch64"
  84. export TARGET_SWIFT_TRIPLE="aarch64-swift-linux-musl"
  85. export TARGET_QEMU="qemu-system-aarch64"
  86. ;;
  87. x86_64|x86|amd64)
  88. export TARGET_ARCH="x86_64"
  89. export TARGET_TRIPLE="x86_64-linux-gnu"
  90. export TARGET_DEVICE="generic"
  91. export TARGET_KERNEL="x86_64"
  92. export TARGET_KERNEL_IMAGE="bzImage"
  93. export TARGET_SYSROOT="$ARKOS_ROOT/system/sysroot"
  94. export TARGET_MODULES_DIR="$ARKOS_ROOT/system/ark-sysroot"
  95. export TARGET_SWIFT_TRIPLE="x86_64-unknown-linux-gnu"
  96. export TARGET_QEMU="qemu-system-x86_64"
  97. ;;
  98. *)
  99. echo ""
  100. echo " ✗ Unknown target: '$target'"
  101. echo " Supported targets: arm64, x86_64"
  102. echo ""
  103. return 1
  104. ;;
  105. esac
  106. # Set compiler variables — everything uses clang
  107. export CC="$ARKOS_CLANG --target=$TARGET_TRIPLE"
  108. export CXX="$ARKOS_CLANGXX --target=$TARGET_TRIPLE"
  109. export AR="llvm-ar"
  110. export LD="ld.lld"
  111. export OBJCOPY="llvm-objcopy"
  112. export STRIP="llvm-strip"
  113. # Mark that a target has been selected
  114. export ARKOS_TARGET_SET=1
  115. # Print selection banner
  116. echo ""
  117. echo -e " \033[1;36m╔══════════════════════════════════════════╗\033[0m"
  118. echo -e " \033[1;36m║ ArkOS Build Target Selected ║\033[0m"
  119. echo -e " \033[1;36m╠══════════════════════════════════════════╣\033[0m"
  120. echo -e " \033[1;36m║\033[0m Architecture : \033[1;32m$TARGET_ARCH\033[0m"
  121. echo -e " \033[1;36m║\033[0m Triple : \033[1;33m$TARGET_TRIPLE\033[0m"
  122. echo -e " \033[1;36m║\033[0m Device : \033[1;35m$TARGET_DEVICE\033[0m"
  123. echo -e " \033[1;36m║\033[0m Kernel : \033[0;37m$TARGET_KERNEL_IMAGE\033[0m"
  124. echo -e " \033[1;36m║\033[0m Sysroot : \033[0;37m$TARGET_SYSROOT\033[0m"
  125. echo -e " \033[1;36m║\033[0m Compiler : \033[0;37mclang ($ARKOS_CLANG)\033[0m"
  126. echo -e " \033[1;36m╚══════════════════════════════════════════╝\033[0m"
  127. echo ""
  128. echo -e " Run \033[1mmake\033[0m to build ArkOS for \033[1m$TARGET_ARCH\033[0m."
  129. echo ""
  130. }
  131. # ── Helper Functions ──────────────────────────────────────────────
  132. function croot() {
  133. cd "$ARKOS_ROOT"
  134. }
  135. function cout() {
  136. cd "$ARKOS_OUT"
  137. }
  138. function goarkrt() {
  139. cd "$ARKOS_ROOT/arkrt"
  140. }
  141. # ── Startup Banner ────────────────────────────────────────────────
  142. echo ""
  143. echo -e " \033[1;35m╔══════════════════════════════════════════╗\033[0m"
  144. echo -e " \033[1;35m║ ArkOS Build Environment v4.0 ║\033[0m"
  145. echo -e " \033[1;35m║ Host: $HOST_ARCH ║\033[0m"
  146. echo -e " \033[1;35m╚══════════════════════════════════════════╝\033[0m"
  147. echo ""
  148. echo -e " Commands:"
  149. echo -e " \033[1mtype arm64\033[0m — Select ARM64 target (RPi4)"
  150. echo -e " \033[1mtype x86_64\033[0m — Select x86_64 target (PC)"
  151. echo -e " \033[1mmake\033[0m — Build for selected target"
  152. echo -e " \033[1mcroot\033[0m — cd to ArkOS root"
  153. echo ""