diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 273e985f8..4161da286 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -26,13 +26,39 @@ jobs: run: cd kernel && ./get-deps - name: Attempt to build the Vinix kernel (debug) - run: cd kernel && make PROD=false KCFLAGS="-D__vinix__ -O2 -g -pipe" KV="../v/v" && make clean + run: | + set -e + cd kernel + make PROD=false \ + CFLAGS="-Ulinux -U__linux -U__linux__ -U__gnu_linux__ -D__vinix__ -O2 -g -pipe" \ + V="$(realpath ../v/v)" + make clean - name: Attempt to build the Vinix kernel (prod) - run: cd kernel && make PROD=true KCFLAGS="-D__vinix__ -O2 -g -pipe" KV="../v/v" && make clean + run: | + set -e + cd kernel + make PROD=true \ + CFLAGS="-Ulinux -U__linux -U__linux__ -U__gnu_linux__ -D__vinix__ -O2 -g -pipe" \ + V="$(realpath ../v/v)" + make clean - name: Attempt to build the util-vinix (debug) - run: cd util-vinix && make PROD=false V="$(realpath ../v/v)" VFLAGS="-os vinix -gc none" CFLAGS="-D__vinix__ -O2 -g -pipe" && make clean + run: | + set -e + cd util-vinix + make PROD=false \ + VFLAGS="-os vinix -gc none" \ + CFLAGS="-Ulinux -U__linux -U__linux__ -U__gnu_linux__ -D__vinix__ -O2 -g -pipe" \ + V="$(realpath ../v/v)" + make clean - name: Attempt to build the util-vinix (prod) - run: cd util-vinix && make PROD=true V="$(realpath ../v/v)" VFLAGS="-os vinix -gc none" CFLAGS="-D__vinix__ -O2 -g -pipe" && make clean + run: | + set -e + cd util-vinix + make PROD=true \ + VFLAGS="-os vinix -gc none" \ + CFLAGS="-Ulinux -U__linux -U__linux__ -U__gnu_linux__ -D__vinix__ -O2 -g -pipe" \ + V="$(realpath ../v/v)" + make clean diff --git a/kernel/.gitignore b/kernel/.gitignore index 0a97ef4d2..c909c164a 100644 --- a/kernel/.gitignore +++ b/kernel/.gitignore @@ -1,5 +1,5 @@ /freestnd-c-hdrs-0bsd -/c/cc-runtime.c +/cc-runtime* /c/flanterm /c/printf /bin diff --git a/kernel/GNUmakefile b/kernel/GNUmakefile index 06ff3b582..9a99e7985 100644 --- a/kernel/GNUmakefile +++ b/kernel/GNUmakefile @@ -20,49 +20,52 @@ $(call USER_VARIABLE,DESTDIR,) $(call USER_VARIABLE,PREFIX,/usr/local) # User controllable C compiler command. -$(call USER_VARIABLE,KCC,cc) +$(call USER_VARIABLE,CC,cc) + +# User controllable archiver command. +$(call USER_VARIABLE,AR,ar) # User controllable linker command. -$(call USER_VARIABLE,KLD,ld) +$(call USER_VARIABLE,LD,ld) # User controllable objdump command. -$(call USER_VARIABLE,KOBJDUMP,objdump) +$(call USER_VARIABLE,OBJDUMP,objdump) # User controllable V command. -$(call USER_VARIABLE,KV,v) +$(call USER_VARIABLE,V,v) # User controllable C flags. -$(call USER_VARIABLE,KCFLAGS,-g -O2 -pipe) +$(call USER_VARIABLE,CFLAGS,-g -O2 -pipe) # User controllable C preprocessor flags. We set none by default. -$(call USER_VARIABLE,KCPPFLAGS,) +$(call USER_VARIABLE,CPPFLAGS,) # User controllable V flags. We set none by default. -$(call USER_VARIABLE,KVFLAGS,) +$(call USER_VARIABLE,VFLAGS,) # User controllable linker flags. We set none by default. -$(call USER_VARIABLE,KLDFLAGS,) +$(call USER_VARIABLE,LDFLAGS,) $(call USER_VARIABLE,VINIX_PROD,) # Ensure the dependencies have been obtained. ifneq ($(shell ( test '$(MAKECMDGOALS)' = clean || test '$(MAKECMDGOALS)' = distclean ); echo $$?),0) - ifeq ($(shell ( ! test -d freestnd-c-hdrs-0bsd || ! test -f c/cc-runtime.c || ! test -d c/flanterm || ! test -f c/printf/printf.c || ! test -f c/printf/printf.h ); echo $$?),0) + ifeq ($(shell ( ! test -d freestnd-c-hdrs-0bsd || ! test -d cc-runtime || ! test -d c/flanterm || ! test -f c/printf/printf.c || ! test -f c/printf/printf.h ); echo $$?),0) $(error Please run the ./get-deps script first) endif endif -# Check if KCC is Clang. -override KCC_IS_CLANG := $(shell ! $(KCC) --version 2>/dev/null | grep 'clang' >/dev/null 2>&1; echo $$?) +# Check if CC is Clang. +override CC_IS_CLANG := $(shell ! $(CC) --version 2>/dev/null | grep 'clang' >/dev/null 2>&1; echo $$?) # If the C compiler is Clang, set the target as needed. -ifeq ($(KCC_IS_CLANG),1) - override KCC += \ +ifeq ($(CC_IS_CLANG),1) + override CC += \ -target x86_64-unknown-none endif # Internal C flags that should not be changed by the user. -override KCFLAGS += \ +override CFLAGS += \ -g \ -Wall \ -Wextra \ @@ -87,22 +90,22 @@ override KCFLAGS += \ -mcmodel=kernel # Internal C preprocessor flags that should not be changed by the user. -override KCPPFLAGS := \ +override CPPFLAGS := \ -I c \ -isystem freestnd-c-hdrs-0bsd \ - $(KCPPFLAGS) \ + $(CPPFLAGS) \ -MMD \ -MP -obj/printf/printf.c.o: override KCPPFLAGS += \ +obj/printf/printf.c.o: override CPPFLAGS += \ -DPRINTF_SUPPORT_DECIMAL_SPECIFIERS=0 \ -DPRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS=0 -obj/flanterm/backends/fb.c.o: override KCPPFLAGS += \ +obj/flanterm/backends/fb.c.o: override CPPFLAGS += \ -DFLANTERM_FB_DISABLE_BUMP_ALLOC # Internal linker flags that should not be changed by the user. -override KLDFLAGS += \ +override LDFLAGS += \ -m elf_x86_64 \ -nostdlib \ -static \ @@ -110,7 +113,7 @@ override KLDFLAGS += \ -gc-sections \ -T linker.ld -override KVFLAGS += \ +override VFLAGS += \ -os vinix \ -enable-globals \ -nofloat \ @@ -121,10 +124,10 @@ override KVFLAGS += \ -d no_backtrace ifeq ($(VINIX_PROD),no) - override KVFLAGS += -warn-about-allocs + override VFLAGS += -warn-about-allocs else - override KVFLAGS += -prod - override KCPPFLAGS += -DPROD + override VFLAGS += -prod + override CPPFLAGS += -DPROD endif # Use "find" to glob all *.v, *.c, and *.S files in the tree and obtain the @@ -139,20 +142,30 @@ override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d)) .PHONY: all all: bin/$(OUTPUT) +# Link rules for building the C compiler runtime. +cc-runtime-x86_64/cc-runtime.a: cc-runtime/* + rm -rf cc-runtime-x86_64 + cp -r cc-runtime cc-runtime-x86_64 + $(MAKE) -C cc-runtime-x86_64 -f cc-runtime.mk \ + CC="$(CC)" \ + AR="$(AR)" \ + CFLAGS="$(CFLAGS)" \ + CPPFLAGS='-isystem ../freestnd-c-hdrs-0bsd -DCC_RUNTIME_NO_FLOAT' + # Link rules for the final executable. -bin/$(OUTPUT): GNUmakefile linker.ld obj/blob.c.o $(OBJ) +bin/$(OUTPUT): GNUmakefile linker.ld obj/blob.c.o $(OBJ) cc-runtime-x86_64/cc-runtime.a mkdir -p "$$(dirname $@)" - $(KLD) obj/blob.c.o $(OBJ) $(KLDFLAGS) -o $@ - ./gensyms.sh $(KOBJDUMP) $@ > obj/symbol_table.c - $(KCC) $(KCFLAGS) $(KCPPFLAGS) -c obj/symbol_table.c -o obj/symbol_table.c.o - $(KLD) obj/blob.c.o $(OBJ) $(KLDFLAGS) -o $@ + $(LD) obj/blob.c.o $(OBJ) cc-runtime-x86_64/cc-runtime.a $(LDFLAGS) -o $@ + ./gensyms.sh $(OBJDUMP) $@ > obj/symbol_table.c + $(CC) $(CFLAGS) $(CPPFLAGS) -c obj/symbol_table.c -o obj/symbol_table.c.o + $(LD) obj/blob.c.o $(OBJ) cc-runtime-x86_64/cc-runtime.a $(LDFLAGS) -o $@ obj/blob.c.o: $(VFILES) mkdir -p "$$(dirname $@)" - $(KV) $(KVFLAGS) -o obj/blob.c . + $(V) $(VFLAGS) -o obj/blob.c . sed 's/call 0(/call *(/g' < obj/blob.c > obj/blob.c.tmp mv obj/blob.c.tmp obj/blob.c - $(KCC) $(KCFLAGS) $(KCPPFLAGS) -w -c obj/blob.c -o $@ + $(CC) $(CFLAGS) $(CPPFLAGS) -w -c obj/blob.c -o $@ # Include header dependencies. -include $(HEADER_DEPS) @@ -160,22 +173,22 @@ obj/blob.c.o: $(VFILES) # Compilation rules for *.c files. obj/%.c.o: c/%.c GNUmakefile mkdir -p "$$(dirname $@)" - $(KCC) $(KCFLAGS) $(KCPPFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ # Compilation rules for *.S files. obj/%.S.o: asm/%.S GNUmakefile mkdir -p "$$(dirname $@)" - $(KCC) $(KCFLAGS) $(KCPPFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ # Remove object files and the final executable. .PHONY: clean clean: - rm -rf bin obj + rm -rf bin obj cc-runtime-x86_64 # Remove everything built and generated including downloaded dependencies. .PHONY: distclean distclean: clean - rm -rf freestnd-c-hdrs-0bsd c/cc-runtime.c c/flanterm c/printf + rm -rf freestnd-c-hdrs-0bsd cc-runtime c/flanterm c/printf # Install the final built executable to its final on-root location. .PHONY: install diff --git a/kernel/get-deps b/kernel/get-deps index 2be4f63d9..5cd7e42a1 100755 --- a/kernel/get-deps +++ b/kernel/get-deps @@ -69,10 +69,10 @@ clone_repo_commit \ freestnd-c-hdrs-0bsd \ 0353851fdebe0eb6a4d2c608c5393040d310bf35 -download_by_hash \ - https://github.com/osdev0/cc-runtime/raw/dcdf5d82973e77edee597a047a3ef66300903de9/cc-runtime.c \ - c/cc-runtime.c \ - 199907f5303ab15a963377fabcc1f2ee736e4ed18d54c59aab08345aa5485e8a +clone_repo_commit \ + https://github.com/osdev0/cc-runtime.git \ + cc-runtime \ + 13fe6383470f0e4982d926472448d6d3b80a851f clone_repo_commit \ https://github.com/mintsuki/flanterm.git \ diff --git a/recipes/kernel b/recipes/kernel index 03fa60523..a3e7d5f7a 100644 --- a/recipes/kernel +++ b/recipes/kernel @@ -16,7 +16,11 @@ prepare() { build() { cp -rpf "${source_dir}"/. ./ - make -j${parallelism} KCC=${OS_TRIPLET}-gcc KLD=${OS_TRIPLET}-ld KOBJDUMP=${OS_TRIPLET}-objdump + make -j${parallelism} \ + CC=${OS_TRIPLET}-gcc \ + LD=${OS_TRIPLET}-ld \ + AR=${OS_TRIPLET}-ar \ + OBJDUMP=${OS_TRIPLET}-objdump } package() { diff --git a/recipes/util-vinix b/recipes/util-vinix index 59b549b96..cc4439e9a 100644 --- a/recipes/util-vinix +++ b/recipes/util-vinix @@ -4,13 +4,17 @@ name=util-vinix version=0.0 revision=1 source_dir="util-vinix" -hostdeps="gcc binutils v" +hostdeps="gcc v" deps="core-libs" build() { - cp -r "${source_dir}"/. ./ + cp -rp "${source_dir}"/. ./ - make -j${parallelism} CC=${OS_TRIPLET}-gcc + make -j${parallelism} \ + CC=${OS_TRIPLET}-gcc \ + VFLAGS="-os vinix -gc none" \ + CFLAGS="$TARGET_CFLAGS" \ + LDFLAGS="$TARGET_LDFLAGS" } package() { diff --git a/util-vinix/GNUmakefile b/util-vinix/GNUmakefile index 5a1073078..70ace46d8 100644 --- a/util-vinix/GNUmakefile +++ b/util-vinix/GNUmakefile @@ -2,21 +2,27 @@ # Code is governed by the GPL-2.0 license. # Copyright (C) 2021-2022 The Vinix authors. -ifeq ($(origin CC), default) - CC := cc -endif -V ?= v +MAKEFLAGS += -rR +.SUFFIXES: + +override USER_VARIABLE = $(if $(filter $(origin $(1)),default undefined),$(eval override $(1) := $(2))) + +$(call USER_VARIABLE,CC,cc) +$(call USER_VARIABLE,V,v) + VINIX_PROD ?= ifeq ($(VINIX_PROD),no) override PROD := false else override PROD := true endif -VFLAGS ?= -gc none -CFLAGS ?= -O2 -pipe -g -PREFIX ?= /usr/local -override CFLAGS += -Wno-implicit-function-declaration -Wno-incompatible-pointer-types -Wno-int-conversion +$(call USER_VARIABLE,VFLAGS,) +$(call USER_VARIABLE,CFLAGS,-g -O2 -pipe) +$(call USER_VARIABLE,LDFLAGS,) + +$(call USER_VARIABLE,DESTDIR,) +$(call USER_VARIABLE,PREFIX,/usr/local) ifeq ($(PROD), true) override VFLAGS += -prod @@ -37,16 +43,16 @@ override MOUNT_TARGET := $(MOUNT_DIR)/mount all: $(CHSH_TARGET) $(FETCH_TARGET) $(LSCPU_TARGET) $(MOUNT_TARGET) $(CHSH_TARGET): $(CHSH_DIR)/* - cd $(CHSH_DIR) && VCROSS_COMPILER_NAME="$(CC)" $(V) $(VFLAGS) -cflags "$(CFLAGS)" -os vinix . + cd $(CHSH_DIR) && VCROSS_COMPILER_NAME="$(CC)" $(V) $(VFLAGS) -cflags "$(CFLAGS)" -ldflags "$(LDFLAGS)" . $(FETCH_TARGET): $(FETCH_DIR)/* - cd $(FETCH_DIR) && VCROSS_COMPILER_NAME="$(CC)" $(V) $(VFLAGS) -cflags "$(CFLAGS)" -os vinix . + cd $(FETCH_DIR) && VCROSS_COMPILER_NAME="$(CC)" $(V) $(VFLAGS) -cflags "$(CFLAGS)" -ldflags "$(LDFLAGS)" . $(LSCPU_TARGET): $(LSCPU_DIR)/* - cd $(LSCPU_DIR) && VCROSS_COMPILER_NAME="$(CC)" $(V) $(VFLAGS) -cflags "$(CFLAGS)" -os vinix . + cd $(LSCPU_DIR) && VCROSS_COMPILER_NAME="$(CC)" $(V) $(VFLAGS) -cflags "$(CFLAGS)" -ldflags "$(LDFLAGS)" . $(MOUNT_TARGET): $(MOUNT_DIR)/* - cd $(MOUNT_DIR) && VCROSS_COMPILER_NAME="$(CC)" $(V) $(VFLAGS) -cflags "$(CFLAGS)" -os vinix . + cd $(MOUNT_DIR) && VCROSS_COMPILER_NAME="$(CC)" $(V) $(VFLAGS) -cflags "$(CFLAGS)" -ldflags "$(LDFLAGS)" . clean: rm -rf $(CHSH_TARGET) $(FETCH_TARGET) $(LSCPU_TARGET) $(MOUNT_TARGET)