Skip to content

Commit

Permalink
kern: Misc build system and dependency updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsuki committed Sep 12, 2024
1 parent cbdda24 commit 50bb13e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
27 changes: 20 additions & 7 deletions kernel/GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GNUmakefile: Makefile of the kernel.
# Code is governed by the GPL-2.0 license.
# Copyright (C) 2021-2022 The Vinix authors.
# Copyright (C) 2021-2024 The Vinix authors.

# Nuke built-in rules and variables.
MAKEFLAGS += -rR
Expand All @@ -13,6 +13,12 @@ override OUTPUT := vinix
# Convenience macro to reliably declare user overridable variables.
override USER_VARIABLE = $(if $(filter $(origin $(1)),default undefined),$(eval override $(1) := $(2)))

# Destination directory on install (should always be empty by default).
$(call USER_VARIABLE,DESTDIR,)

# Install prefix; /usr/local is a good, standard default pick.
$(call USER_VARIABLE,PREFIX,/usr/local)

# User controllable C compiler command.
$(call USER_VARIABLE,KCC,cc)

Expand All @@ -39,6 +45,13 @@ $(call USER_VARIABLE,KLDFLAGS,)

$(call USER_VARIABLE,VINIX_PROD,)

# Ensure the dependencies have been obtained.
ifneq ($(shell ( test '$(MAKECMDGOALS)' = clean || test '$(MAKECMDGOALS)' = distclean ) && echo 1),1)
ifeq ($(shell ( ! test -d freestanding-headers || ! test -f c/cc-runtime.c || ! test -d c/flanterm || ! test -f c/printf/printf.c || ! test -f c/printf/printf.h ) && echo 1),1)
$(error Please run the ./get-deps script first)
endif
endif

# Internal C flags that should not be changed by the user.
override KCFLAGS += \
-g \
Expand Down Expand Up @@ -113,12 +126,6 @@ override ASFILES := $(shell cd asm && find -L * -type f -name '*.S' | LC_ALL=C s
override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o))
override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))

# Ensure the dependencies have been obtained.
override MISSING_DEPS := $(shell if ! test -d freestanding-headers || ! test -f c/cc-runtime.c || ! test -f c/printf/printf.c || ! test -f c/printf/printf.h; then echo 1; fi)
ifeq ($(MISSING_DEPS),1)
$(error Please run the ./get-deps script first)
endif

# Default target.
.PHONY: all
all: bin/$(OUTPUT)
Expand Down Expand Up @@ -166,3 +173,9 @@ distclean: clean
install: all
install -d "$(DESTDIR)$(PREFIX)/share/$(OUTPUT)"
install -m 644 bin/$(OUTPUT) "$(DESTDIR)$(PREFIX)/share/$(OUTPUT)/"

# Try to undo whatever the "install" target did.
.PHONY: uninstall
uninstall:
rm -f "$(DESTDIR)$(PREFIX)/share/$(OUTPUT)/$(OUTPUT)"
-rmdir "$(DESTDIR)$(PREFIX)/share/$(OUTPUT)"
36 changes: 21 additions & 15 deletions kernel/get-deps
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ test -z "$srcdir" && srcdir=.
cd "$srcdir"

clone_repo_commit() {
if test -d $2/.git; then
git -C $2 reset --hard
git -C $2 clean -fd
if ! git -C $2 checkout $3; then
rm -rf $2
if test -d "$2/.git"; then
git -C "$2" reset --hard
git -C "$2" clean -fd
if ! git -C "$2" checkout $3; then
rm -rf "$2"
fi
else
if test -d $2; then
if test -d "$2"; then
echo "error: '$2' is not a Git repository"
exit 1
fi
fi
if ! test -d $2; then
git clone $1 $2
git -C $2 checkout $3
if ! test -d "$2"; then
git clone $1 "$2"
if ! git -C "$2" checkout $3; then
rm -rf "$2"
exit 1
fi
fi
}

Expand All @@ -43,12 +46,15 @@ download_by_hash() {
exit 1
fi
fi
if ! test -f $2 || ! $SHA256_COMMAND $2 | grep $3 >/dev/null 2>&1; then
rm -f $2
mkdir -p $2 && rm -rf $2
$DOWNLOAD_COMMAND $2 $1
if ! $SHA256_COMMAND $2 | grep $3 >/dev/null 2>&1; then
if ! test -f "$2" || ! $SHA256_COMMAND "$2" | grep $3 >/dev/null 2>&1; then
rm -f "$2"
mkdir -p "$2" && rm -rf "$2"
$DOWNLOAD_COMMAND "$2" $1
if ! $SHA256_COMMAND "$2" | grep $3 >/dev/null 2>&1; then
echo "error: Cannot download file '$2' by hash"
echo "incorrect hash:"
$SHA256_COMMAND "$2"
rm -f "$2"
exit 1
fi
fi
Expand All @@ -58,7 +64,7 @@ if ! test -f version; then
clone_repo_commit \
https://github.com/osdev0/freestanding-headers.git \
freestanding-headers \
4b8b78007533dec6ae3bd8dddcc302f22a21c140
f890bb927859719061fe020119f3d5439d90aecf

download_by_hash \
https://github.com/osdev0/cc-runtime/raw/dcdf5d82973e77edee597a047a3ef66300903de9/cc-runtime.c \
Expand Down

0 comments on commit 50bb13e

Please sign in to comment.