summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile78
1 files changed, 50 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index 0b40df9..aebb9ac 100644
--- a/Makefile
+++ b/Makefile
@@ -3,9 +3,15 @@ PATH := $(shell pwd)/toolchain/bin/:$(PATH)
AS = x86_64-elf-as
CC = x86_64-elf-gcc
CHECK = sparse
-CFLAGS += -g -std=gnu99 -ffreestanding -O2 -Wall -Wextra -Wold-style-definition -Werror=implicit-function-declaration -ftrack-macro-expansion=0
+
+CFLAGS += -g -std=gnu99 -ffreestanding -O2 -ftrack-macro-expansion=0
+CFLAGS += -Wall -Wextra -Wold-style-definition -Werror=implicit-function-declaration
CFLAGS += -mgeneral-regs-only -Wno-address-of-packed-member
CFLAGS += -Isrc/ -Isrc/shared/include/
+
+KERNEL_CFLAGS = $(CFLAGS)
+USER_CFLAGS = $(CFLAGS)
+
SPARSEFLAGS = -Wno-non-pointer-null
LFLAGS = -ffreestanding -O2 -nostdlib -lgcc -Wl,-zmax-page-size=4096 -Wl,--no-warn-mismatch
QFLAGS = -no-reboot
@@ -13,9 +19,9 @@ ifndef QEMU_DISPLAY
QFLAGS += -display none
endif
+
define from_sources
- $(patsubst src/%.s,out/obj/%.s.o,$(shell find $(1) -type f,l -name '*.s')) \
- $(patsubst src/%.c,out/obj/%.c.o,$(shell find $(1) -type f,l -name '*.c'))
+ $(patsubst src/%,out/obj/%.o,$(shell find $(1) -type f,l -name '*.[cs]'))
endef
@@ -42,30 +48,49 @@ debug: all
@sleep 1
gdb
-lint:
- @tools/linter/main.rb
-
check: $(shell find src/kernel/ -type f -name *.c)
@echo $^ | xargs -n 1 sparse $(CFLAGS) $(SPARSEFLAGS)
+ @tools/linter/main.rb
clean:
- rm -r out/
+ rm -rf out/
-out/boot.iso: out/fs/boot/kernel.bin out/fs/boot/grub/grub.cfg out/fs/boot/init
+out/boot.iso: out/fs/boot/kernel out/fs/boot/grub/grub.cfg out/fs/boot/init
@grub-mkrescue -o $@ out/fs/ > /dev/null 2>&1
-out/fs/boot/kernel.bin: src/kernel/linker.ld $(call from_sources, src/kernel/) $(call from_sources, src/shared/)
+out/fs/boot/kernel: src/kernel/linker.ld \
+ $(call from_sources, src/kernel/) \
+ $(call from_sources, src/shared/)
@mkdir -p $(@D)
@$(CC) $(LFLAGS) -T $^ -o $@
- grub-file --is-x86-multiboot $@
+ @grub-file --is-x86-multiboot $@ || echo "$@ has an invalid multiboot header"
+ @grub-file --is-x86-multiboot $@ || rm $@; test -e $@
-out/bootstrap: src/user/bootstrap/linker.ld $(call from_sources, src/user/bootstrap/) $(call from_sources, src/user/lib/) $(call from_sources, src/shared/)
+out/bootstrap: src/user/bootstrap/linker.ld \
+ $(call from_sources, src/user/bootstrap/) \
+ $(call from_sources, src/user/lib/) \
+ $(call from_sources, src/shared/)
@mkdir -p $(@D)
@$(CC) $(LFLAGS) -T $^ -o $@
+out/fs/boot/init: out/bootstrap out/initrd.tar
+ @mkdir -p $(@D)
+ @cat $^ > $@
+
+out/fs/boot/grub/grub.cfg: grub.cfg
+ @mkdir -p $(@D)
+ @cp $< $@
+
+out/hdd:
+ @dd if=/dev/zero of=$@ bs=512 count=70000
+
+
define userbin_template =
-out/initrd/$(1).elf: src/user/linker.ld $(call from_sources, src/user/app/$(1)/) $(call from_sources, src/user/lib/) $(call from_sources, src/shared/)
+out/initrd/$(1).elf: src/user/linker.ld \
+ $(call from_sources, src/user/app/$(1)/) \
+ $(call from_sources, src/user/lib/) \
+ $(call from_sources, src/shared/)
@mkdir -p $$(@D)
@$(CC) $(LFLAGS) -Wl,-pie -Wl,-no-dynamic-linker -T $$^ -o $$@
endef
@@ -78,39 +103,36 @@ out/initrd/%: initrd/%
out/initrd.tar: $(patsubst %,out/%,$(shell find initrd/ -type f)) \
$(patsubst %,out/initrd/%.elf,$(USERBINS))
- cd out/initrd; tar chf ../initrd.tar *
+ @cd out/initrd; tar chf ../initrd.tar *
-out/fs/boot/init: out/bootstrap out/initrd.tar
- @mkdir -p $(@D)
- @cat $^ > $@
-out/fs/boot/grub/grub.cfg: grub.cfg
+out/obj/%.s.o: src/%.s
@mkdir -p $(@D)
- @cp $< $@
-
-out/hdd:
- @dd if=/dev/zero of=$@ bs=512 count=70000
+ @$(AS) $^ -o $@
+out/obj/shared/%.c.o: src/shared/%.c
+ @mkdir -p $(@D)
+ @$(CC) $(KERNEL_CFLAGS) -fPIC -c $^ -o $@
-out/obj/%.s.o: src/%.s
+out/obj/kernel/%.c.o: src/kernel/%.c
@mkdir -p $(@D)
- @$(AS) $^ -o $@
+ @$(CC) $(KERNEL_CFLAGS) -fPIC -c $^ -o $@
-out/obj/%.c.o: src/%.c
+out/obj/user/%.c.o: src/user/%.c
@mkdir -p $(@D)
- @$(CC) $(CFLAGS) -fPIC -c $^ -o $@
+ @$(CC) $(USER_CFLAGS) -fPIC -c $^ -o $@
out/obj/user/bootstrap/%.c.o: src/user/bootstrap/%.c
@mkdir -p $(@D)
- @$(CC) $(CFLAGS) -c $^ -o $@
+ @$(CC) $(USER_CFLAGS) -c $^ -o $@
out/obj/kernel/arch/amd64/32/%.c.o: src/kernel/arch/amd64/32/%.c
@mkdir -p $(@D)
- @$(CC) $(CFLAGS) -m32 -c $^ -o $@
+ @$(CC) $(KERNEL_CFLAGS) -m32 -c $^ -o $@
out/obj/kernel/arch/amd64/32/%.s.o: src/kernel/arch/amd64/32/%.s
@mkdir -p $(@D)
@$(CC) -m32 -c $^ -o $@
src/user/lib/syscall.c: src/user/lib/syscall.c.awk src/shared/include/camellia/syscalls.h
- awk -f $^ > $@
+ @awk -f $^ > $@