| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #!/bin/bash
- #
- # Copyright 2026 Aarav Ravindra Kharade
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- #
- # ═══════════════════════════════════════════════════════════════════
- # ArkOS Build Environment Setup
- # ═══════════════════════════════════════════════════════════════════
- #
- # Usage:
- # source envsetup.sh
- # type arm64 # Select ARM64 target (Raspberry Pi 4)
- # type x86_64 # Select x86_64 target (PC / QEMU)
- # make # Build for the selected target
- #
- # This script mirrors Android's envsetup.sh / lunch workflow.
- # It must be sourced (not executed) so functions persist in your
- # shell session.
- #
- # ═══════════════════════════════════════════════════════════════════
- # Detect the directory this script lives in
- export ARKOS_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
- export ARKOS_REPO="$(cd "$ARKOS_ROOT/.." && pwd)"
- export ARKOS_TOOLS="$ARKOS_REPO/tools"
- export ARKOS_OUT="$ARKOS_ROOT/out_staging"
- export ARKOS_FINISHED="$ARKOS_ROOT/finished"
- # ── Host Architecture Detection ───────────────────────────────────
- export HOST_ARCH="$(uname -m)"
- case "$HOST_ARCH" in
- x86_64|amd64) HOST_ARCH="x86_64" ;;
- aarch64|arm64) HOST_ARCH="aarch64" ;;
- *) HOST_ARCH="x86_64" ;;
- esac
- export HOST_ARCH
- # ── Clang Toolchain ───────────────────────────────────────────────
- # Prefer the prebuilt clang shipped with ArkOS, fall back to system clang
- if [ -x "$ARKOS_ROOT/prebuilts/clang/bin/clang" ]; then
- export ARKOS_CLANG="$ARKOS_ROOT/prebuilts/clang/bin/clang"
- export ARKOS_CLANGXX="$ARKOS_ROOT/prebuilts/clang/bin/clang++"
- else
- export ARKOS_CLANG="$(which clang 2>/dev/null || echo clang)"
- export ARKOS_CLANGXX="$(which clang++ 2>/dev/null || echo clang++)"
- fi
- # ── type() — Target Architecture Selector ─────────────────────────
- #
- # Works like Android's lunch command. Sets all compiler variables
- # for the selected target architecture.
- #
- # Supported targets:
- # arm64 — Raspberry Pi 4 (aarch64-linux-gnu)
- # x86_64 — Standard PC / QEMU (x86_64-linux-gnu)
- function type() {
- local target="$1"
- if [ -z "$target" ]; then
- echo ""
- echo " Usage: type <target>"
- echo ""
- echo " Available targets:"
- echo " arm64 — Raspberry Pi 4 Model B (aarch64-linux-gnu)"
- echo " x86_64 — Standard PC / QEMU (x86_64-linux-gnu)"
- echo ""
- return 1
- fi
- case "$target" in
- arm64|aarch64)
- export TARGET_ARCH="aarch64"
- export TARGET_TRIPLE="aarch64-linux-gnu"
- export TARGET_DEVICE="rpi4"
- export TARGET_KERNEL="arm64"
- export TARGET_KERNEL_IMAGE="Image"
- export TARGET_SYSROOT="$ARKOS_ROOT/system/sysrootaarch64"
- export TARGET_MODULES_DIR="$ARKOS_ROOT/system/sysrootaarch64"
- export TARGET_SWIFT_TRIPLE="aarch64-swift-linux-musl"
- export TARGET_QEMU="qemu-system-aarch64"
- ;;
- x86_64|x86|amd64)
- export TARGET_ARCH="x86_64"
- export TARGET_TRIPLE="x86_64-linux-gnu"
- export TARGET_DEVICE="generic"
- export TARGET_KERNEL="x86_64"
- export TARGET_KERNEL_IMAGE="bzImage"
- export TARGET_SYSROOT="$ARKOS_ROOT/system/sysroot"
- export TARGET_MODULES_DIR="$ARKOS_ROOT/system/ark-sysroot"
- export TARGET_SWIFT_TRIPLE="x86_64-unknown-linux-gnu"
- export TARGET_QEMU="qemu-system-x86_64"
- ;;
- *)
- echo ""
- echo " ✗ Unknown target: '$target'"
- echo " Supported targets: arm64, x86_64"
- echo ""
- return 1
- ;;
- esac
- # Set compiler variables — everything uses clang
- export CC="$ARKOS_CLANG --target=$TARGET_TRIPLE"
- export CXX="$ARKOS_CLANGXX --target=$TARGET_TRIPLE"
- export AR="llvm-ar"
- export LD="ld.lld"
- export OBJCOPY="llvm-objcopy"
- export STRIP="llvm-strip"
- # Mark that a target has been selected
- export ARKOS_TARGET_SET=1
- # Print selection banner
- echo ""
- echo -e " \033[1;36m╔══════════════════════════════════════════╗\033[0m"
- echo -e " \033[1;36m║ ArkOS Build Target Selected ║\033[0m"
- echo -e " \033[1;36m╠══════════════════════════════════════════╣\033[0m"
- echo -e " \033[1;36m║\033[0m Architecture : \033[1;32m$TARGET_ARCH\033[0m"
- echo -e " \033[1;36m║\033[0m Triple : \033[1;33m$TARGET_TRIPLE\033[0m"
- echo -e " \033[1;36m║\033[0m Device : \033[1;35m$TARGET_DEVICE\033[0m"
- echo -e " \033[1;36m║\033[0m Kernel : \033[0;37m$TARGET_KERNEL_IMAGE\033[0m"
- echo -e " \033[1;36m║\033[0m Sysroot : \033[0;37m$TARGET_SYSROOT\033[0m"
- echo -e " \033[1;36m║\033[0m Compiler : \033[0;37mclang ($ARKOS_CLANG)\033[0m"
- echo -e " \033[1;36m╚══════════════════════════════════════════╝\033[0m"
- echo ""
- echo -e " Run \033[1mmake\033[0m to build ArkOS for \033[1m$TARGET_ARCH\033[0m."
- echo ""
- }
- # ── Helper Functions ──────────────────────────────────────────────
- function croot() {
- cd "$ARKOS_ROOT"
- }
- function cout() {
- cd "$ARKOS_OUT"
- }
- function goarkrt() {
- cd "$ARKOS_ROOT/arkrt"
- }
- # ── Startup Banner ────────────────────────────────────────────────
- echo ""
- echo -e " \033[1;35m╔══════════════════════════════════════════╗\033[0m"
- echo -e " \033[1;35m║ ArkOS Build Environment v4.0 ║\033[0m"
- echo -e " \033[1;35m║ Host: $HOST_ARCH ║\033[0m"
- echo -e " \033[1;35m╚══════════════════════════════════════════╝\033[0m"
- echo ""
- echo -e " Commands:"
- echo -e " \033[1mtype arm64\033[0m — Select ARM64 target (RPi4)"
- echo -e " \033[1mtype x86_64\033[0m — Select x86_64 target (PC)"
- echo -e " \033[1mmake\033[0m — Build for selected target"
- echo -e " \033[1mcroot\033[0m — cd to ArkOS root"
- echo ""
|