diff options
author | aqua <aqua@iserlohn-fortress.net> | 2023-06-11 23:11:25 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2023-06-11 23:11:25 +0300 |
commit | cb6aa7dd9703eb3dba275905f98de682b57d3a78 (patch) | |
tree | 4b2b6ff65c148c5e9fe035e621496fcb2302dfb8 | |
parent | Make code ANSI C compatible (diff) | |
download | kernel-cb6aa7dd9703eb3dba275905f98de682b57d3a78.tar.xz |
Rework leaf makefiles to be included from top-level
- remove Makefile.all
-rw-r--r-- | .config | 9 | ||||
-rw-r--r-- | Kconfig | 22 | ||||
-rw-r--r-- | Makefile | 77 | ||||
-rw-r--r-- | Makefile.all | 61 | ||||
-rw-r--r-- | config.mk (renamed from Makefile.config) | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | devices/build.mk (renamed from devices/Makefile) | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | i686/build.mk (renamed from i686/Makefile) | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | lib/build.mk (renamed from lib/Makefile) | 4 | ||||
-rwxr-xr-x | mach | 21 | ||||
-rw-r--r-- | root.mk | 43 | ||||
-rw-r--r-- | rules.mk | 27 | ||||
-rwxr-xr-x[-rw-r--r--] | src/build.mk (renamed from src/Makefile) | 10 | ||||
-rwxr-xr-x[-rw-r--r--] | tools/kconfig/build.mk (renamed from tools/kconfig/Makefile) | 4 |
13 files changed, 151 insertions, 138 deletions
@@ -6,18 +6,15 @@ # # Toolchain # +CONFIG_ARCH_i686=y +# CONFIG_ARCH_mips is not set +CONFIG_TOOLCHAIN_i686_gcc=y CONFIG_CFLAGS="-g -Og" CONFIG_CXXFLAGS="-g -Og" CONFIG_LDFLAGS="" # end of Toolchain # -# Target -# -CONFIG_ARCH_i686=y -# end of Target - -# # Devices # CONFIG_PIC_8259=y @@ -1,4 +1,18 @@ menu "Toolchain" + choice + prompt "Target architecture" + config ARCH_i686 + bool "i686" + config ARCH_mips + bool "mips" + endchoice + choice + prompt "Toolchain" + config TOOLCHAIN_i686_gcc + bool "i686-elf-gcc" + depends on ARCH_i686 + endchoice + config CFLAGS string "Additional C compiler flags" config CXXFLAGS @@ -7,14 +21,6 @@ menu "Toolchain" string "Additional linker flags" endmenu -menu "Target" - choice - prompt "Target architecture" - config ARCH_i686 - bool "i686" - endchoice -endmenu - menu "Devices" config PIC_8259 bool "PIC 8259" @@ -9,56 +9,63 @@ MAKEFLAGS += -rR --no-print-directory ARCH := $(shell sed -nE "s/CONFIG_ARCH_(.+)=y/\1/p" .config) -.PHONY: all help info run doc clean test valgrind -all: Makefile.config - @${MAKE} -f Makefile.all +SUBDIRS := lib ${ARCH} devices src +.PHONY: help info run doc clean test valgrind help: - @echo "info: show current configuration" - @echo "all: build kernel image" @echo "run: run kernel image in qemu" @echo "test: run all tests" @echo "valgrind: run all tests in valgrind" -info: Makefile.config - @echo "- make:" - @echo " MAKE: ${MAKE}" - @echo " MAKEID: ${MAKEID}" - @echo " MAKEFLAGS: ${MAKEFLAGS}" - @${MAKE} -f Makefile.all $@ - -run: Makefile.config - @${MAKE} -f Makefile.all $@ - -doc: doxygen.config - doxygen $< +run: glitch.iso + qemu-system-i386 -accel kvm -machine pc -cdrom $^ -d cpu_reset -display gtk,zoom-to-fit=on clean: - @${MAKE} -C lib clean - @${MAKE} -C ${ARCH} clean - @${MAKE} -C devices clean - @${MAKE} -C src clean + @for d in ${SUBDIRS}; do make -C $$d -f ../root.mk clean; done test: - @make -C ${ARCH} test.quiet - @make -C lib test.quiet - @make -C devices test.quiet - @make -C src test.quiet + @for d in ${SUBDIRS}; do make -C $$d -f ../root.mk test.quiet; done valgrind: - @make -C ${ARCH} valgrind.quiet - @make -C lib valgrind.quiet - @make -C devices valgrind.quiet - @make -C src valgrind.quiet + @for d in ${SUBDIRS}; do make -C $$d -f ../root.mk valgrind.quiet; done # configure targets +kconfig: + @make -C tools/kconfig -f ../../root.mk + .config: Kconfig @alldefconfig -Makefile.config: .config ${ARCH}/toolchain.mk - @echo -e '## This is a generated file, manual edits might be lost' > Makefile.config - @echo -e '\n## .config' >> Makefile.config - @cat .config >> Makefile.config - @echo -e '\n## toolchain.mk' >> Makefile.config - @cat ${ARCH}/toolchain.mk >> Makefile.config +config.mk: .config ${ARCH}/toolchain.mk + @cat .config >> $@ + @echo -e '\n## toolchain.mk' >> $@ + @cat ${ARCH}/toolchain.mk >> $@ + +# build targets +lib/libk.a: + @${MAKE} -C lib -f ../root.mk libk.a +i686/arch.a: + @${MAKE} -C ${ARCH} -f ../root.mk arch.a +devices/devs.a: + @${MAKE} -C devices -f ../root.mk devs.a +src/kernel.a: + @${MAKE} -C src -f ../root.mk kernel.a + +src/glitch.elf: lib/libk.a i686/arch.a devices/devs.a src/kernel.a + @${MAKE} -C src -f ../root.mk glitch.elf + +# iso image +glitch.iso: src/glitch.elf grub/grub.cfg + @grub-file --is-x86-multiboot2 src/glitch.elf + @mkdir -p isodir/boot/grub + @mkdir -p isodir/boot/glitch + @grub-script-check grub/grub.cfg + @cp grub/grub.cfg isodir/boot/grub/grub.cfg + @cp src/glitch.elf isodir/boot/glitch/glitch.elf + @i686-elf-strip isodir/boot/glitch/glitch.elf + @rm -f isodir/boot/glitch/checksums + @sha512sum isodir/boot/glitch/* > isodir/boot/glitch/checksums + @sed -i s/isodir// isodir/boot/glitch/checksums + @grub-mkrescue -o glitch.iso isodir + diff --git a/Makefile.all b/Makefile.all deleted file mode 100644 index a92631f..0000000 --- a/Makefile.all +++ /dev/null @@ -1,61 +0,0 @@ -# ===================================================================== -# spdx-license-identifier: ISC -# glitch kernel binary and image generation -# ===================================================================== - -include Makefile.config - -${ARCH}_LDFLAGS += -T ${ARCH}/linker.ld - -TARGETBIN += glitch -glitch.OBJS += ${ARCH}/arch.a src/kernel.a devices/devs.a lib/libk.a - -include rules.mk - -.PHONY: run info -run: glitch.iso - @${QEMU} -cdrom $^ -d cpu_reset -display gtk,zoom-to-fit=on - -info: - @echo "- target:" - @echo " ARCH: ${ARCH}" - @echo " CC: ${${ARCH}_CC}" - @echo " CCID: ${${ARCH}_CCID}" - @echo " CFLAGS: ${${ARCH}_CFLAGS}" - @echo " CXX: ${${ARCH}_CXX}" - @echo " CXXID: ${${ARCH}_CXXID}" - @echo " CXXFLAGS: ${${ARCH}_CXXFLAGS}" - @echo " LD: ${${ARCH}_LD}" - @echo " LDID: ${${ARCH}_LDID}" - @echo " LDFLAGS: ${${ARCH}_LDFLAGS}" - @echo "- host:" - @echo " CC: ${HOST_CC}" - @echo " CFLAGS: ${HOST_CFLAGS}" - @echo " CXX: ${HOST_CXX}" - @echo " CXXFLAGS: ${HOST_CXXFLAGS}" - @echo " QEMU: ${QEMU}" - -# build targets - -glitch.iso: glitch.elf grub/grub.cfg - @grub-file --is-x86-multiboot2 glitch.elf - @mkdir -p isodir/boot/grub - @mkdir -p isodir/boot/glitch - @grub-script-check grub/grub.cfg - @cp grub/grub.cfg isodir/boot/grub/grub.cfg - @cp glitch.elf isodir/boot/glitch/glitch.elf - @i686-elf-strip isodir/boot/glitch/glitch.elf - @rm -f isodir/boot/glitch/checksums - @sha512sum isodir/boot/glitch/* > isodir/boot/glitch/checksums - @sed -i s/isodir// isodir/boot/glitch/checksums - @grub-mkrescue -o glitch.iso isodir - -lib/libk.a: FORCE - @${MAKE} -C lib libk.a -i686/arch.a: FORCE - @${MAKE} -C ${ARCH} arch.a -devices/devs.a: FORCE - @${MAKE} -C devices devs.a -src/kernel.a: FORCE - @${MAKE} -C src kernel.a - diff --git a/Makefile.config b/config.mk index 8ac0c3c..56039f0 100644 --- a/Makefile.config +++ b/config.mk @@ -1,6 +1,3 @@ -## This is a generated file, manual edits might be lost - -## .config # # Automatically generated file; DO NOT EDIT. # Main menu diff --git a/devices/Makefile b/devices/build.mk index 3222ad8..b27d945 100644..100755 --- a/devices/Makefile +++ b/devices/build.mk @@ -1,4 +1,4 @@ -include ../Makefile.config +#!../mach INCLUDES := -I../${ARCH} ${ARCH}_CFLAGS += ${INCLUDES} @@ -12,5 +12,3 @@ uart/test_uart_16550.SRCS = uart/uart_16550.c uart/unittest_uart_16550.cc TESTS += uart/test_uart_16550 -include ../rules.mk - diff --git a/i686/Makefile b/i686/build.mk index 3702bef..312e553 100644..100755 --- a/i686/Makefile +++ b/i686/build.mk @@ -1,4 +1,4 @@ -include ../Makefile.config +#!../mach INCLUDES := -isystem../grub ${ARCH}_CFLAGS += ${INCLUDES} @@ -14,5 +14,3 @@ test_gdt.SRCS = test_gdt.cc TESTS += test_gdt -include ../rules.mk - diff --git a/lib/Makefile b/lib/build.mk index 0494a85..06c6006 100644..100755 --- a/lib/Makefile +++ b/lib/build.mk @@ -1,4 +1,4 @@ -include ../Makefile.config +#!../mach # minimal C standard library TARGETLIB += libk @@ -34,5 +34,3 @@ blake2/test_blake2s_selftest.SRCS = blake2/test_blake2s_selftest.cc TESTS += blake2/test_blake2s_selftest -include ../rules.mk - @@ -0,0 +1,21 @@ +#!/bin/sh +# ===================================================================== +# filename: mach +# description: make wrapper used to run build.mk +# To use, add the relative path to this script as a +# shebang in build.mk and make it executable. +# spdx-license-identifier: ISC +# ===================================================================== + +if [[ $1 != "./build.mk" ]] +then + echo "Run from subdir" + exit 1 +fi + +# remove ./build.mk from args +ARGS=${@:2} +# root.mk should be next to this script +ROOT=`dirname $0` + +make --silent -f ${ROOT}/root.mk -C ${PWD} ${ARGS} @@ -0,0 +1,43 @@ +# glitch root makefile +# usage: make -C <part> -f <path to root.mk> <target(s)> + +# location of root makefile +ROOTDIR := $(dir $(abspath $(lastword ${MAKEFILE_LIST}))) +# include config and toolchain +include $(join ${ROOTDIR},config.mk) + +help: + @echo "info: show current configuration" + @echo "all: build kernel image" + @echo "run: run kernel image in qemu" + @echo "test: run all tests" + @echo "valgrind: run all tests in valgrind" + +info: + @echo "- target:" + @echo " ARCH: ${ARCH}" + @echo " CC: ${${ARCH}_CC}" + @echo " CCID: ${${ARCH}_CCID}" + @echo " CFLAGS: ${${ARCH}_CFLAGS}" + @echo " LD: ${${ARCH}_LD}" + @echo " LDID: ${${ARCH}_LDID}" + @echo " LDFLAGS: ${${ARCH}_LDFLAGS}" + @echo "- host:" + @echo " CC: ${HOST_CC}" + @echo " CFLAGS: ${HOST_CFLAGS}" + @echo " CXX: ${HOST_CXX}" + @echo " CXXFLAGS: ${HOST_CXXFLAGS}" + @echo " QEMU: ${QEMU}" + +# for auto-completion purposes +list-targets: + +# include build from current dir +include build.mk + +SUBDIR := $(dir $(abspath $(lastword ${MAKEFILE_LIST}))) +COMPONENT := $(lastword $(subst /, ,${SUBDIR})) + +# generate build rules +include $(join ${ROOTDIR},rules.mk) + @@ -1,3 +1,7 @@ +# generate build rules from variables +# This makefile defines the following targets: +# - all: default goal, build all default targets + # generate objects from sources # arg 1: target.SRCS # arg 2: object suffix prefix @@ -41,14 +45,19 @@ $(foreach T,${HOSTTARGETBIN},\ $(eval DEFAULT_TARGETS += $T) \ ) -debug: - @echo "TARGETBIN ${TARGETBIN}" - @echo "TARGETLIB ${TARGETLIB}" - @echo "HOSTTARGETBIN ${HOSTTARGETBIN}" - @echo "HOSTTARGETLIB ${HOSTTARGETLIB}" - @echo "DEFAULT_TARGETS ${DEFAULT_TARGETS}" - @echo "TESTS ${TESTS}" - @echo " DEPS ${TESTS.DEPS}" +list-targets: + @echo TARGETBIN + @echo ${TARGETBIN} | tr ' ' '\n' | xargs -n1 echo " " + @echo TARGETLIB + @echo ${TARGETLIB} | tr ' ' '\n' | xargs -n1 echo " " + @echo HOSTTARGETBIN + @echo ${HOSTTARGETBIN} | tr ' ' '\n' | xargs -n1 echo " " + @echo HOSTTARGETLIB + @echo ${HOSTTARGETLIB} | tr ' ' '\n' | xargs -n1 echo " " + @echo DEFAULT_TARGETS + @echo ${DEFAULT_TARGETS} | tr ' ' '\n' | xargs -n1 echo " " + @echo TESTS + @echo ${TESTS} | tr ' ' '\n' | xargs -n1 echo " " %.info: @echo "Target: $(basename $@)" @@ -58,7 +67,7 @@ debug: @echo " DEPS: ${$(basename $@).DEPS}" all: ${DEFAULT_TARGETS} - @echo " -> Built ${DEFAULT_TARGETS}" + @echo " -> Built all in ${COMPONENT}" # extra flags ${ARCH}_CFLAGS += -I../lib/libk \ diff --git a/src/Makefile b/src/build.mk index 0d02c5d..bdc1e3b 100644..100755 --- a/src/Makefile +++ b/src/build.mk @@ -1,8 +1,12 @@ -include ../Makefile.config +#!../mach -INCLUDES := -isystem../grub -I../${ARCH} -I../devices +INCLUDES := -isystem${ROOTDIR}grub -I${ROOTDIR}${ARCH} -I${ROOTDIR}devices ${ARCH}_CFLAGS += ${INCLUDES} ${ARCH}_CXXFLAGS += ${INCLUDES} +${ARCH}_LDFLAGS += -T ${ROOTDIR}${ARCH}/linker.ld + +TARGETBIN += glitch +glitch.OBJS += ${ROOTDIR}${ARCH}/arch.a kernel.a ${ROOTDIR}devices/devs.a ${ROOTDIR}lib/libk.a TARGETLIB += kernel kernel.SRCS := multiboot2.c mmap.c kernel.cpp mem/vmm.c @@ -16,8 +20,6 @@ sched/test_roundrobin.SRCS = sched/test_roundrobin.cc TESTS += \ sched/test_taskqueue sched/test_roundrobin -include ../rules.mk - kernel.c: conf.h conf.h: conf.h.in @echo ' GEN $@' diff --git a/tools/kconfig/Makefile b/tools/kconfig/build.mk index b7dd104..060dd99 100644..100755 --- a/tools/kconfig/Makefile +++ b/tools/kconfig/build.mk @@ -1,4 +1,4 @@ -include ../../Makefile.config +#!../../mach HOSTTARGETBIN += conf mconf @@ -16,8 +16,6 @@ mconf.SRCS := ${parser_srcs} ${lxdiag_srcs} mconf.c HOST_CFLAGS := -D_GNU_SOURCE $(shell pkg-config --cflags ncursesw) HOST_LDFLAGS := $(shell pkg-config --libs ncursesw) -include ../../rules.mk - %.tab.c: %.y bison --header --debug $< |