diff --git a/makefile b/makefile index 944c69e..39d0145 100644 --- a/makefile +++ b/makefile @@ -1,11 +1,22 @@ # Makefile —— AnduinOS build orchestrator -SHELL := /usr/bin/env bash +SHELL := /usr/bin/env bash .DEFAULT_GOAL := current -SRC_DIR := src -CONFIG_DIR := config +SRC_DIR := src +CONFIG_DIR := config -.PHONY: all fast current clean check-env help +DEPS := \ + binutils \ + debootstrap \ + squashfs-tools \ + xorriso \ + grub-pc-bin \ + grub-efi-amd64 \ + grub2-common \ + mtools \ + dosfstools + +.PHONY: all fast current clean bootstrap help help: @echo "Usage:" @@ -13,29 +24,45 @@ help: @echo " make all Build all languages" @echo " make fast Build fast config languages" @echo " make clean Remove build artifacts" - @echo " make check-env Validate environment" + @echo " make bootstrap Validate environment and deps" -check-env: +bootstrap: @if [ "$$(id -u)" -eq 0 ]; then \ - echo "Error: Do not run as root"; exit 1; \ + echo "Error: Do not run as root"; \ + exit 1; \ fi @if ! lsb_release -i | grep -qE "(Ubuntu|Debian|AnduinOS)"; then \ - echo "Error: Unsupported OS — only Ubuntu, Debian or AnduinOS allowed"; exit 1; \ + echo "Error: Unsupported OS — only Ubuntu, Debian or AnduinOS allowed"; \ + exit 1; \ fi -current: check-env + @missing="" ; \ + for pkg in $(DEPS); do \ + if ! dpkg -s $$pkg >/dev/null 2>&1; then \ + missing="$$missing $$pkg"; \ + fi; \ + done; \ + if [ -n "$$missing" ]; then \ + echo "Missing packages:$$missing"; \ + echo "Installing missing dependencies..."; \ + sudo apt-get update && sudo apt-get install -y$$missing; \ + else \ + echo "[MAKE] All required packages are already installed."; \ + fi + +current: bootstrap @echo "[MAKE] Building current language..." @cd $(SRC_DIR) && ./build.sh -all: check-env +all: bootstrap @echo "[MAKE] Building ALL languages (all.json)..." @./build_all.sh -c $(CONFIG_DIR)/all.json -fast: check-env +fast: bootstrap @echo "[MAKE] Building FAST languages (fast.json)..." @./build_all.sh -c $(CONFIG_DIR)/fast.json clean: @echo "[MAKE] Cleaning build artifacts..." - @rm -rf $(SRC_DIR)/dist/* $(SRC_DIR)/image + @cd $(SRC_DIR) && ./clean.sh @echo "[MAKE] Clean complete." diff --git a/src/build.sh b/src/build.sh index b312d6a..7a479fe 100755 --- a/src/build.sh +++ b/src/build.sh @@ -41,6 +41,8 @@ function clean() { judge "Clean up rootfs" sudo rm -rf image || true judge "Clean up image" + sudo rm -rf dist || true + judge "Clean up dist" || true sudo rm -f $TARGET_NAME.iso || true judge "Clean up iso" } diff --git a/src/clean.sh b/src/clean.sh new file mode 100755 index 0000000..e366061 --- /dev/null +++ b/src/clean.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +#========================== +# Set up the environment +#========================== +set -e # exit on error +set -o pipefail # exit on pipeline error +set -u # treat unset variable as error +export SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" +source $SCRIPT_DIR/shared.sh +source $SCRIPT_DIR/args.sh + +function clean() { + print_ok "Cleaning up..." + sudo umount new_building_os/sys || sudo umount -lf new_building_os/sys || true + sudo umount new_building_os/proc || sudo umount -lf new_building_os/proc || true + sudo umount new_building_os/dev || sudo umount -lf new_building_os/dev || true + sudo umount new_building_os/run || sudo umount -lf new_building_os/run || true + sudo rm -rf new_building_os || true + judge "Clean up rootfs" + sudo rm -rf image || true + judge "Clean up image" + sudo rm -rf dist || true + judge "Clean up dist" + sudo rm -f $TARGET_NAME.iso || true + judge "Clean up iso" +} + +# ============= main ================ +cd $SCRIPT_DIR + +clean