Makefile: added sysroot and improved other parts
Sysroot maybe needed in future when we will need to use other software
This commit is contained in:
parent
edf0613390
commit
45fc49d08c
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
*~
|
||||
src/build
|
||||
src/sysroot
|
||||
src/isodir
|
||||
|
64
src/Makefile
64
src/Makefile
@ -2,6 +2,11 @@ ARCH=i386
|
||||
CC=i686-elf-gcc
|
||||
|
||||
BUILDDIR=build
|
||||
ISODIR=isodir
|
||||
ORION_SYSROOT?=sysroot
|
||||
DESTDIR?=$(ORION_SYSROOT)
|
||||
BOOTDIR=/boot
|
||||
INCLUDEDIR=/usr/local/include
|
||||
|
||||
ASMFILES=$(wildcard arch/$(ARCH)/*.asm)
|
||||
ASMOBJS=$(patsubst %.asm, $(BUILDDIR)/%.o, $(ASMFILES))
|
||||
@ -12,8 +17,9 @@ COBJS=$(patsubst %.c, $(BUILDDIR)/%.o, $(CFILES))
|
||||
LIBKFILES=$(wildcard libk/*.c)
|
||||
LIBKOBJS=$(patsubst %.c, $(BUILDDIR)/%.o, $(LIBKFILES))
|
||||
|
||||
INCLUDEFLAGS=-Iinclude -Ilibk/include
|
||||
DEBUGFLAGS=
|
||||
INCLUDEFLAGS?=
|
||||
INCLUDEFLAGS:=-Iinclude -Ilibk/include
|
||||
DEBUGFLAGS?=
|
||||
CFLAGS=-std=c99 -ffreestanding -fstack-protector-all $(INCLUDEFLAGS) $(DEBUGFLAGS) -Wall -Wextra
|
||||
|
||||
CRTI_OBJ = $(BUILDDIR)/arch/$(ARCH)/crti.o
|
||||
@ -31,20 +37,21 @@ $(CRTEND_OBJ) \
|
||||
$(CRTN_OBJ)
|
||||
|
||||
DIRS = $(BUILDDIR)/arch/$(ARCH) $(BUILDDIR)/libk
|
||||
KERNELFILE = $(BUILDDIR)/orion.bin
|
||||
ISOFILE = $(BUILDDIR)/orion.iso
|
||||
KERNELFILE =orion-$(ARCH).bin
|
||||
ISOFILE =orion-$(ARCH).iso
|
||||
|
||||
.PHONY: all clean run run-grub
|
||||
.PHONY: all clean iso install install-headers run run-grub
|
||||
.SUFFIXES: .o .c .asm
|
||||
|
||||
all: $(DIRS) $(ASMOBJS) $(COBJS) $(LIBKOBJS) $(KERNELFILE)
|
||||
all: $(DIRS) $(ASMOBJS) $(COBJS) $(LIBKOBJS) $(BUILDDIR)/$(KERNELFILE)
|
||||
|
||||
$(DIRS):
|
||||
mkdir -p $(BUILDDIR)
|
||||
mkdir -p $(BUILDDIR)/arch/$(ARCH)
|
||||
mkdir -p $(BUILDDIR)/libk
|
||||
|
||||
$(KERNELFILE):
|
||||
$(CC) -T linker.ld -o $(KERNELFILE) $(CFLAGS) -nostdlib $(OBJFILES) -lgcc
|
||||
$(BUILDDIR)/$(KERNELFILE): $(OBJFILES)
|
||||
$(CC) -T linker.ld -o $@ $(CFLAGS) $(OBJFILES) -nostdlib -lgcc
|
||||
|
||||
$(BUILDDIR)/%.o: %.asm
|
||||
nasm -f elf32 $< -o $@
|
||||
@ -55,27 +62,40 @@ $(BUILDDIR)/%.o: %.c
|
||||
$(BUILDDIR)/%.o: libk/%.c
|
||||
$(CC) -c $< -o $@ $(CFLAGS) -lgcc
|
||||
|
||||
install: all install-headers install-kernel
|
||||
|
||||
install-headers:
|
||||
mkdir -p $(DESTDIR)$(INCLUDEDIR)
|
||||
cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/.
|
||||
cp -R --preserve=timestamps libk/include/. $(DESTDIR)$(INCLUDEDIR)/.
|
||||
|
||||
install-kernel: $(BUILDDIR)/$(KERNELFILE)
|
||||
mkdir -p $(DESTDIR)$(BOOTDIR)
|
||||
cp $(BUILDDIR)/$(KERNELFILE) $(DESTDIR)$(BOOTDIR)
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)/*
|
||||
rm -rf $(BUILDDIR)
|
||||
rm -rf $(ISODIR)
|
||||
rm -rf $(DESTDIR)
|
||||
|
||||
run:
|
||||
qemu-system-$(ARCH) -kernel $(KERNELFILE) -serial stdio -S -s
|
||||
run: install
|
||||
qemu-system-$(ARCH) -kernel $(BUILDDIR)/$(KERNELFILE) -serial stdio -S -s
|
||||
|
||||
$(ISOFILE): $(KERNELFILE)
|
||||
mkdir -p $(BUILDDIR)/isodir
|
||||
mkdir -p $(BUILDDIR)/isodir/boot
|
||||
mkdir -p $(BUILDDIR)/isodir/boot/grub
|
||||
$(BUILDDIR)/$(ISOFILE): install
|
||||
mkdir -p $(ISODIR)
|
||||
mkdir -p $(ISODIR)/boot
|
||||
mkdir -p $(ISODIR)/boot/grub
|
||||
|
||||
cp $(KERNELFILE) $(BUILDDIR)/isodir/boot/orion.kernel
|
||||
cp $(DESTDIR)$(BOOTDIR)/$(KERNELFILE) $(ISODIR)/boot/$(KERNELFILE)
|
||||
|
||||
echo 'menuentry "orion" { ' > $(BUILDDIR)/isodir/boot/grub/grub.cfg
|
||||
echo ' multiboot /boot/orion.kernel' >> $(BUILDDIR)/isodir/boot/grub/grub.cfg
|
||||
echo '}' >> $(BUILDDIR)/isodir/boot/grub/grub.cfg
|
||||
echo 'menuentry "orion" { ' > $(ISODIR)/boot/grub/grub.cfg
|
||||
echo ' multiboot /boot/$(KERNELFILE)' >> $(ISODIR)/boot/grub/grub.cfg
|
||||
echo '}' >> $(ISODIR)/boot/grub/grub.cfg
|
||||
|
||||
grub-mkrescue -o $(ISOFILE) $(BUILDDIR)/isodir
|
||||
grub-mkrescue -o $(BUILDDIR)/$(ISOFILE) $(ISODIR)
|
||||
|
||||
iso: $(ISOFILE)
|
||||
iso: $(BUILDDIR)/$(ISOFILE)
|
||||
|
||||
run-grub: iso
|
||||
qemu-system-$(ARCH) -cdrom $(BUILDDIR)/orion.iso -serial stdio -S -s
|
||||
qemu-system-$(ARCH) -cdrom $(BUILDDIR)/$(ISOFILE) -serial stdio -S -s
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user