Makefile: help menu and gen .i files
This commit is contained in:
parent
bff24b2213
commit
a459111348
29
Makefile
29
Makefile
@ -4,6 +4,9 @@ AS=nasm
|
|||||||
ASFLAGS += -f elf32
|
ASFLAGS += -f elf32
|
||||||
LDFLAGS += -m elf_i386
|
LDFLAGS += -m elf_i386
|
||||||
CFLAGS += -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-pie -fno-stack-protector -fno-tree-vectorize -D__KERNEL__
|
CFLAGS += -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-pie -fno-stack-protector -fno-tree-vectorize -D__KERNEL__
|
||||||
|
#keep .i and .s
|
||||||
|
#CFLAGS += -save-temps
|
||||||
|
#CFLAGS += -fanalyzer -Wno-analyzer-malloc-leak -Wno-analyzer-out-of-bounds
|
||||||
CXXFLAGS += -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-rtti -fno-pie
|
CXXFLAGS += -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-rtti -fno-pie
|
||||||
DEBUG_FLAGS += -g -Og -DDEBUG -fno-omit-frame-pointer -fno-inline
|
DEBUG_FLAGS += -g -Og -DDEBUG -fno-omit-frame-pointer -fno-inline
|
||||||
LIBGCC = $(shell $(CC) -print-libgcc-file-name $(CFLAGS))
|
LIBGCC = $(shell $(CC) -print-libgcc-file-name $(CFLAGS))
|
||||||
@ -21,12 +24,13 @@ gasmsrc=$(wildcard arch/$(ARCH)/*.S arch/$(ARCH)/boot/*.S)
|
|||||||
gasmobj=$(gasmsrc:%.S=%.o)
|
gasmobj=$(gasmsrc:%.S=%.o)
|
||||||
csrc=$(shell find $(SUBDIRS) -type f -name "*.c")# $(wildcard *.c)
|
csrc=$(shell find $(SUBDIRS) -type f -name "*.c")# $(wildcard *.c)
|
||||||
cobj=$(csrc:%.c=%.o)
|
cobj=$(csrc:%.c=%.o)
|
||||||
|
cinc=$(csrc:%.c=%.i)
|
||||||
deps=$(csrc:%.c=%.d) $(gasmsrc:%.S=%.d)
|
deps=$(csrc:%.c=%.d) $(gasmsrc:%.S=%.d)
|
||||||
docsrc=$(wildcard docs/*.md)
|
docsrc=$(wildcard docs/*.md)
|
||||||
docobj=$(docsrc:%.md=%.html)
|
docobj=$(docsrc:%.md=%.html)
|
||||||
|
|
||||||
kernel kernel.sym &: $(asmobj) $(gasmobj) $(cobj) linker.ld
|
kernel kernel.sym &: $(asmobj) $(gasmobj) $(cobj) linker.ld
|
||||||
$(LD) $(LDFLAGS) $(asmobj) $(gasmobj) $(cobj) -o kernel -T linker.ld $(LIBGCC)
|
$(LD) $(LDFLAGS) $(asmobj) $(gasmobj) $(cobj) -o kernel -T linker.ld $(LIBGCC) -Map kernel.map
|
||||||
objcopy --only-keep-debug kernel kernel.sym
|
objcopy --only-keep-debug kernel kernel.sym
|
||||||
objcopy --strip-debug kernel
|
objcopy --strip-debug kernel
|
||||||
objcopy --add-gnu-debuglink=kernel.sym kernel
|
objcopy --add-gnu-debuglink=kernel.sym kernel
|
||||||
@ -45,6 +49,16 @@ FORCE:
|
|||||||
|
|
||||||
doc: $(docobj)
|
doc: $(docobj)
|
||||||
|
|
||||||
|
help: ## show this help
|
||||||
|
# regex for general help
|
||||||
|
@sed -ne "s/^##\(.*\)/\1/p" $(MAKEFILE_LIST)
|
||||||
|
# regex for makefile commands (targets)
|
||||||
|
@printf "────────────────────────`tput bold``tput setaf 2` Make Commands `tput sgr0`────────────────────────────────\n"
|
||||||
|
@sed -ne "/@sed/!s/\(^[^#?=]*:\).*##\(.*\)/`tput setaf 2``tput bold`\1`tput sgr0`\2/p" $(MAKEFILE_LIST)
|
||||||
|
# regex for makefile variables
|
||||||
|
@printf "────────────────────────`tput bold``tput setaf 4` Make Variables `tput sgr0`───────────────────────────────\n"
|
||||||
|
@sed -ne "/@sed/!s/\(.*\)?=\(.*\)##\(.*\)/`tput setaf 4``tput bold`\1:`tput setaf 5`\2`tput sgr0`\3/p" $(MAKEFILE_LIST)
|
||||||
|
|
||||||
disk.img: disk.sfdisk userspace
|
disk.img: disk.sfdisk userspace
|
||||||
qemu-img create -f raw $@ 32M
|
qemu-img create -f raw $@ 32M
|
||||||
sfdisk $@ < $<
|
sfdisk $@ < $<
|
||||||
@ -64,14 +78,17 @@ disk.img: disk.sfdisk userspace
|
|||||||
%.html: %.md
|
%.html: %.md
|
||||||
markdown -o $@ $<
|
markdown -o $@ $<
|
||||||
|
|
||||||
test: CFLAGS += -DRUN_TEST
|
%.i: %.c
|
||||||
|
$(CC) $(CFLAGS) $(CPPFLAGS) -E -c "$<" -o "$@"
|
||||||
|
|
||||||
|
test: CFLAGS += -DRUN_TEST ## Run the OS on qemu with the inner test activated
|
||||||
test: clean kernel disk.img
|
test: clean kernel disk.img
|
||||||
qemu-system-x86_64 -kernel kernel -serial stdio -m 32M $(QEMU_OPT)
|
qemu-system-x86_64 -kernel kernel -serial stdio -m 32M $(QEMU_OPT)
|
||||||
|
|
||||||
run:kernel disk.img
|
run:kernel disk.img ## Run the OS on qemu
|
||||||
qemu-system-x86_64 -kernel $< $(QEMU_OPT)
|
qemu-system-x86_64 -kernel $< -serial stdio $(QEMU_OPT)
|
||||||
|
|
||||||
debug: CFLAGS += $(DEBUG_FLAGS)
|
debug: CFLAGS += $(DEBUG_FLAGS) ## Run the OS on qemu and attach a debugger to it (may need a clean befor to have the debug symbols)
|
||||||
debug: CXXFLAGS += $(DEBUG_FLAGS)
|
debug: CXXFLAGS += $(DEBUG_FLAGS)
|
||||||
debug:kernel kernel.sym disk.img
|
debug:kernel kernel.sym disk.img
|
||||||
gdb -q -x debug.gdb
|
gdb -q -x debug.gdb
|
||||||
@ -83,7 +100,7 @@ screenshot:
|
|||||||
shutter --window=qemu -o screenshot_1.png -e && zopflipng screenshot_1.png screenshot_1.png
|
shutter --window=qemu -o screenshot_1.png -e && zopflipng screenshot_1.png screenshot_1.png
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) kernel $(asmobj) $(gasmobj) $(cobj) $(deps) fd.iso kernel.sym $(docobj)
|
$(RM) kernel $(asmobj) $(gasmobj) $(cobj) $(deps) $(cinc) fd.iso kernel.sym kernel.map $(docobj)
|
||||||
$(RM) -r isodir
|
$(RM) -r isodir
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
|
Loading…
Reference in New Issue
Block a user