Refactor Makefile and enhance cleanup scripts to improve dependency management and cleanup processes

This commit is contained in:
Anduin Xue 2025-05-15 12:56:23 +00:00
parent a932e17ff3
commit d31d9eee8f
No known key found for this signature in database
GPG Key ID: D33FA9407A6BE728
3 changed files with 73 additions and 12 deletions

View File

@ -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."

View File

@ -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"
}

32
src/clean.sh Executable file
View File

@ -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