From: Amelia Coutard Date: Thu, 23 Nov 2023 08:58:39 +0000 (+0100) Subject: Made the build system work with guix (and my channel, which will be updated at some... X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=18009efb295141fd1ddef8f9bc3ade62a12f85df;p=voyage-au-centre-des-fichiers.git Made the build system work with guix (and my channel, which will be updated at some point to include this --- diff --git a/.gitignore b/.gitignore index 7d7afd0..064c840 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ out dep isodir isos.iso +Makefile-conf diff --git a/Makefile b/Makefile index d67df89..fadfa31 100644 --- a/Makefile +++ b/Makefile @@ -5,14 +5,14 @@ # You should have received a copy of the CC0 Public Domain Dedication along with # this file. If not, see . -# So, about the license. I don't think I have a copyright on this file's code, but, -# since I gave it the CC0 license in case I do, that doesn't matter either way. +ifneq ($(MAKECMDGOALS),clean) + include Makefile-conf +endif .PHONY: build qemu clean build: # Build as default target -CXX := x86_64-elf-g++ CXXFLAGS ?= -O2 CXXFLAGS := $(CXXFLAGS) -std=c++20 -fno-strict-aliasing -Wall -Wextra -Werror -Wfatal-errors \ -mgeneral-regs-only -fno-exceptions -fno-rtti -ffreestanding @@ -27,8 +27,11 @@ include **/module.mk build: isos.iso qemu: build qemu-system-x86_64 -cdrom isos.iso -serial stdio -cpu qemu64,pdpe1gb -no-reboot $(QEMUFLAGS) +check: clean: -rm -rf $(TO_CLEAN) +install: + install -D isos.iso -t "$(PREFIX)" isos.iso: $(TO_ISO) grub-mkrescue -o "$@" isodir diff --git a/configure b/configure new file mode 100755 index 0000000..50bab00 --- /dev/null +++ b/configure @@ -0,0 +1,62 @@ +#!/bin/sh + +# Written in 2023 by Amélia COUTARD +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this file to the +# public domain worldwide. This file is distributed without any warranty. +# You should have received a copy of the CC0 Public Domain Dedication along +# with this software. If not, see . + +printf '' > Makefile-conf + +TEMP=$(getopt -o 'h' --long 'prefix:,c++-includes-stdlib:,build:,enable-fast-install,help' -n 'download-playlist' -- "$@") || (echo 'Terminating.' >&2; exit 1) +eval set -- "$TEMP" +unset TEMP + +while true; do + case "$1" in + '--c++-includes-stdlib') + INCLUDES="$2" + shift 2 + continue + ;; + '--prefix') + PREFIX="$2" + shift 2 + continue + ;; + '--build') # Ignored, but accepted. + shift 2 + continue + ;; + '--enable-fast-install') # Ignored, but accepted. + shift 1 + continue + ;; + '-h'|'--help') + echo '--prefix Install prefix' + echo '--c++-includes-stdlib C++ standard library include files location' + shift + exit 0 + ;; + '--') + shift + break + ;; + esac +done + +if test "$PREFIX" = ""; then + echo 'Missing argument: --prefix.' >&2 + echo 'See --help for more detail.' >&2 + exit 1 +fi + +if test "$INCLUDES" = ""; then + echo 'Missing argument: --c++-includes-stdlib.' >&2 + echo 'See --help for more detail.' >&2 + exit 1 +fi + +echo "PREFIX = $PREFIX" >> Makefile-conf +echo "INCLUDES = $INCLUDES" >> Makefile-conf diff --git a/grub.cfg b/grub.cfg index fee1476..f71586a 100644 --- a/grub.cfg +++ b/grub.cfg @@ -5,9 +5,6 @@ # You should have received a copy of the CC0 Public Domain Dedication along with # this file. If not, see . -# So, about the license. I don't think I have a copyright on this file's code, but, -# since I gave it the CC0 license in case I do, that doesn't matter either way. - menuentry "isos" { multiboot2 /boot/kernel.elf64 module2 /boot/test-module.elf64 test-module diff --git a/kernel/linker.ld b/kernel/linker.ld index 11aa47e..b99ff70 100644 --- a/kernel/linker.ld +++ b/kernel/linker.ld @@ -4,9 +4,6 @@ * This file is distributed without any warranty. * You should have received a copy of the CC0 Public Domain Dedication along with * this file. If not, see . - - * So, about the license. I don't think I have a copyright on this file's code, but, - * since I gave it the CC0 license in case I do, that doesn't matter either way. */ ENTRY(_start) diff --git a/kernel/module.mk b/kernel/module.mk index a918f4f..c867969 100644 --- a/kernel/module.mk +++ b/kernel/module.mk @@ -5,9 +5,6 @@ # You should have received a copy of the CC0 Public Domain Dedication along with # this file. If not, see . -# So, about the license. I don't think I have a copyright on this file's code, but, -# since I gave it the CC0 license in case I do, that doesn't matter either way. - SRC_DIR := kernel/src/ OUT_DIR := kernel/out/ DEP_DIR := kernel/dep/ @@ -16,10 +13,10 @@ EXEC_NAME := kernel.elf64 TO_ISO += isodir/boot/$(EXEC_NAME) TO_CLEAN += $(OUT_DIR) $(DEP_DIR) +LOCAL_CXX := g++-system LOCAL_CXXFLAGS := $(CXXFLAGS) -mcmodel=kernel -mno-red-zone \ - -isystem /usr/include -isystem /usr/include/c++/13.1.1 \ - -isystem /usr/include/c++/13.1.1/x86_64-pc-linux-gnu - # The previous two lines are a dirty hack. But not that much, because it doesn't allow me to include non-freestanding headers anyways + -isystem $(INCLUDES) -isystem $(INCLUDES)/c++ -isystem $(INCLUDES)/c++/x86_64-unknown-linux-gnu + # The previous line is a dirty hack. But not that much, because it doesn't allow me to include non-freestanding headers anyways LOCAL_LDFLAGS := $(LDFLAGS) -T kernel/linker.ld -z max-page-size=0x1000 \ -mno-red-zone -mcmodel=kernel @@ -29,8 +26,8 @@ ASMSRCS := $(shell find $(SRC_DIR) -name '*.S' | grep -v crt) ASMOBJS := $(ASMSRCS:$(SRC_DIR)%=$(OUT_DIR)%.o) CRTI_OBJ := $(OUT_DIR)/lib/crti.S.o -CRTBEGIN_OBJ := $(shell $(CXX) $(LOCAL_LDFLAGS) -print-file-name=crtbegin.o) -CRTEND_OBJ := $(shell $(CXX) $(LOCAL_LDFLAGS) -print-file-name=crtend.o) +CRTBEGIN_OBJ := $(shell $(LOCAL_CXX) $(LOCAL_LDFLAGS) -print-file-name=crtbegin.o) +CRTEND_OBJ := $(shell $(LOCAL_CXX) $(LOCAL_LDFLAGS) -print-file-name=crtend.o) CRTN_OBJ := $(OUT_DIR)/lib/crtn.S.o OBJS := $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(CPPOBJS) $(ASMOBJS) $(CRTEND_OBJ) $(CRTN_OBJ) @@ -42,12 +39,14 @@ isodir/boot/$(EXEC_NAME): $(OUT_DIR)$(EXEC_NAME) $(OUT_DIR)$(EXEC_NAME): OBJS := $(OBJS) $(OUT_DIR)$(EXEC_NAME): LDLIBS := -nostdlib -lgcc $(OUT_DIR)$(EXEC_NAME): LDFLAGS := $(LOCAL_LDFLAGS) +$(OUT_DIR)$(EXEC_NAME): CXX := $(LOCAL_CXX) $(OUT_DIR)$(EXEC_NAME): $(OBJS) kernel/linker.ld mkdir -p "$(@D)" $(CXX) $(LDFLAGS) -o "$@" $(OBJS) $(LDLIBS) $(OUT_DIR)%.o: DEP_DIR := $(DEP_DIR) $(OUT_DIR)%.o: CXXFLAGS := $(LOCAL_CXXFLAGS) +$(OUT_DIR)%.o: CXX := $(LOCAL_CXX) $(OUT_DIR)%.o: $(SRC_DIR)% mkdir -p $(@D) mkdir -p $(dir $(DEP_DIR)$*) diff --git a/test_module/module.mk b/test_module/module.mk index 194a4f0..a0d8d0b 100644 --- a/test_module/module.mk +++ b/test_module/module.mk @@ -5,9 +5,6 @@ # You should have received a copy of the CC0 Public Domain Dedication along with # this file. If not, see . -# So, about the license. I don't think I have a copyright on this file's code, but, -# since I gave it the CC0 license in case I do, that doesn't matter either way. - SRC_DIR := test_module/src/ OUT_DIR := test_module/out/ DEP_DIR := test_module/dep/ @@ -16,6 +13,7 @@ EXEC_NAME := test-module.elf64 TO_ISO += isodir/boot/$(EXEC_NAME) TO_CLEAN += $(OUT_DIR) $(DEP_DIR) +LOCAL_CXX := g++-user LOCAL_CXXFLAGS := $(CXXFLAGS) LOCAL_LDFLAGS := $(LDFLAGS) @@ -32,12 +30,14 @@ isodir/boot/$(EXEC_NAME): $(OUT_DIR)$(EXEC_NAME) $(OUT_DIR)$(EXEC_NAME): OBJS := $(OBJS) $(OUT_DIR)$(EXEC_NAME): LDLIBS := -nostdlib -lgcc $(OUT_DIR)$(EXEC_NAME): LDFLAGS := $(LOCAL_LDFLAGS) +$(OUT_DIR)$(EXEC_NAME): CXX := $(LOCAL_CXX) $(OUT_DIR)$(EXEC_NAME): $(OBJS) mkdir -p "$(@D)" $(CXX) $(LDFLAGS) -o "$@" $+ $(LDLIBS) $(OUT_DIR)%.o: DEP_DIR := $(DEP_DIR) $(OUT_DIR)%.o: CXXFLAGS := $(LOCAL_CXXFLAGS) +$(OUT_DIR)%.o: CXX := $(LOCAL_CXX) $(OUT_DIR)%.o: $(SRC_DIR)% mkdir -p $(@D) mkdir -p $(dir $(DEP_DIR)$*) diff --git a/test_module_2/module.mk b/test_module_2/module.mk index 9b92895..159547f 100644 --- a/test_module_2/module.mk +++ b/test_module_2/module.mk @@ -5,9 +5,6 @@ # You should have received a copy of the CC0 Public Domain Dedication along with # this file. If not, see . -# So, about the license. I don't think I have a copyright on this file's code, but, -# since I gave it the CC0 license in case I do, that doesn't matter either way. - SRC_DIR := test_module_2/src/ OUT_DIR := test_module_2/out/ DEP_DIR := test_module_2/dep/ @@ -16,6 +13,7 @@ EXEC_NAME := test-module-2.elf64 TO_ISO += isodir/boot/$(EXEC_NAME) TO_CLEAN += $(OUT_DIR) $(DEP_DIR) +LOCAL_CXX := g++-user LOCAL_CXXFLAGS := $(CXXFLAGS) LOCAL_LDFLAGS := $(LDFLAGS) @@ -32,12 +30,14 @@ isodir/boot/$(EXEC_NAME): $(OUT_DIR)$(EXEC_NAME) $(OUT_DIR)$(EXEC_NAME): OBJS := $(OBJS) $(OUT_DIR)$(EXEC_NAME): LDLIBS := -nostdlib -lgcc $(OUT_DIR)$(EXEC_NAME): LDFLAGS := $(LOCAL_LDFLAGS) +$(OUT_DIR)$(EXEC_NAME): CXX := $(LOCAL_CXX) $(OUT_DIR)$(EXEC_NAME): $(OBJS) mkdir -p "$(@D)" $(CXX) $(LDFLAGS) -o "$@" $+ $(LDLIBS) $(OUT_DIR)%.o: DEP_DIR := $(DEP_DIR) $(OUT_DIR)%.o: CXXFLAGS := $(LOCAL_CXXFLAGS) +$(OUT_DIR)%.o: CXX := $(LOCAL_CXX) $(OUT_DIR)%.o: $(SRC_DIR)% mkdir -p $(@D) mkdir -p $(dir $(DEP_DIR)$*)