Adjust build system to be more flexible and to work with the new toolchain

This commit is contained in:
apio 2022-10-02 12:44:32 +02:00
parent ba52e389a5
commit f8a72f15c8
8 changed files with 69 additions and 71 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ initrd/bin/**
apps/bin/**
base/usr/include/**
base/usr/lib/**
**/*.a

View File

@ -1,13 +1,24 @@
build: $(LUNA_ROOT)/kernel/bin/moon.elf apps-build libc-build
CC := x86_64-luna-gcc
CXX := x86_64-luna-g++
ASM := nasm
AR := x86_64-luna-ar
LD := x86_64-luna-ld
clean: moon-clean initrd-clean apps-clean libc-clean
build:
@make -C kernel build
@make -C apps build
@make -C libs build
clean: initrd-clean
@make -C kernel clean
@make -C apps clean
@make -C libs clean
initrd-clean:
rm -f $(LUNA_ROOT)/initrd/boot/moon.elf $(LUNA_ROOT)/Luna.iso
rm -rf $(LUNA_ROOT)/initrd/bin
install: $(LUNA_ROOT)/initrd/boot/moon.elf apps-install libc-install
include kernel/Makefile
include apps/Makefile
include libs/libc/Makefile
install:
@make -C kernel install
@make -C apps install
@make -C libs install

View File

@ -4,28 +4,32 @@ APPS_DIR := $(LUNA_ROOT)/apps
APPS_OBJ := $(APPS_DIR)/lib
APPS_BIN := $(APPS_DIR)/bin
CC := x86_64-luna-gcc
CXX := x86_64-luna-g++
ASM := nasm
AR := x86_64-luna-ar
LD := x86_64-luna-ld
REAL_APPS := $(patsubst %, $(APPS_BIN)/%, $(APPS))
ASMC := nasm
ASMFLAGS := -felf64
LD := x86_64-elf-ld
APP_LDFLAGS := -T$(APPS_DIR)/apps.ld -nostdlib -z max-page-size=0x1000
APP_LDFLAGS := -nostdlib
$(APPS_OBJ)/%.o: $(APPS_DIR)/%.asm
@mkdir -p $(@D)
$(ASMC) $(ASMFLAGS) -o $@ $^
nasm $(ASMFLAGS) -o $@ $^
$(APPS_BIN)/%: $(APPS_OBJ)/%.o
@mkdir -p $(@D)
$(LD) $(APP_LDFLAGS) -o $@ $^
apps-build: $(REAL_APPS)
build: $(REAL_APPS)
apps-install: $(REAL_APPS)
install: $(REAL_APPS)
@mkdir -p $(LUNA_ROOT)/initrd/bin
cp $(REAL_APPS) $(LUNA_ROOT)/initrd/bin
apps-clean:
clean:
rm -f $(APPS_OBJ)/*
rm -f $(APPS_BIN)/*

View File

@ -1,22 +0,0 @@
ENTRY(_start)
OUTPUT_FORMAT(elf64-x86-64)
. = 0x2f00000000;
SECTIONS
{
.text : ALIGN(16) {
KEEP(*(.text.boot)) *(.text .text.*) /* code */
*(.rodata .rodata.*) /* data */
}
.data : ALIGN(16) {
*(.data .data.*)
}
.bss (NOLOAD) : { /* bss */
. = ALIGN(16);
*(.bss .bss.*)
*(COMMON)
}
/DISCARD/ : { *(.eh_frame) *(.comment) }
}

View File

@ -3,15 +3,15 @@ MOON_SRC := $(MOON_DIR)/src
MOON_OBJ := $(MOON_DIR)/lib
MOON_BIN := $(MOON_DIR)/bin
CC := x86_64-elf-gcc
CXX := x86_64-elf-g++
AS := x86_64-elf-as
NASM := nasm
CC := x86_64-luna-gcc
CXX := x86_64-luna-g++
ASM := nasm
AR := x86_64-luna-ar
LD := x86_64-luna-ld
CFLAGS := -Wall -Wextra -Werror -Os -ffreestanding -fstack-protector-all -fno-omit-frame-pointer -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fshort-wchar -mcmodel=kernel -I$(MOON_DIR)/include -isystem $(MOON_DIR)/include/std
CXXFLAGS := -fno-rtti -fno-exceptions
NASMFLAGS := -felf64
ASFLAGS :=
LDFLAGS := -T$(MOON_DIR)/moon.ld -nostdlib -lgcc -Wl,--build-id=none -z max-page-size=0x1000
ifneq ($(MOON_BUILD_STABLE), 1)
@ -26,12 +26,10 @@ rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(su
CXX_SRC = $(call rwildcard,$(MOON_SRC),*.cpp)
C_SRC = $(call rwildcard,$(MOON_SRC),*.c)
AS_SRC = $(call rwildcard,$(MOON_SRC),*.S)
NASM_SRC = $(call rwildcard,$(MOON_SRC),*.asm)
OBJS = $(patsubst $(MOON_SRC)/%.cpp, $(MOON_OBJ)/%.cpp.o, $(CXX_SRC))
OBJS += $(patsubst $(MOON_SRC)/%.c, $(MOON_OBJ)/%.c.o, $(C_SRC))
OBJS += $(patsubst $(MOON_SRC)/%.S, $(MOON_OBJ)/%.S.o, $(AS_SRC))
OBJS += $(patsubst $(MOON_SRC)/%.asm, $(MOON_OBJ)/%.asm.o, $(NASM_SRC))
default: $(MOON_BIN)/moon.elf
@ -56,23 +54,19 @@ $(MOON_OBJ)/%.c.o: $(MOON_SRC)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -o $@ -c $^
$(MOON_OBJ)/%.S.o: $(MOON_SRC)/%.S
@mkdir -p $(@D)
$(AS) $(ASFLAGS) -o $@ $^
$(MOON_OBJ)/%.asm.o: $(MOON_SRC)/%.asm
@mkdir -p $(@D)
$(NASM) $(NASMFLAGS) -o $@ $^
nasm $(NASMFLAGS) -o $@ $^
$(MOON_BIN)/moon.elf: $(OBJS)
build: $(OBJS)
@mkdir -p $(@D)
$(CC) $(OBJS) $(CFLAGS) $(LDFLAGS) -o $@
$(CC) $(OBJS) $(CFLAGS) $(LDFLAGS) -o $(MOON_BIN)/moon.elf
moon-clean:
clean:
rm -rf $(MOON_OBJ)/*
rm -rf $(MOON_BIN)/*
$(LUNA_ROOT)/initrd/boot/moon.elf: $(MOON_BIN)/moon.elf
install: $(MOON_BIN)/moon.elf
@mkdir -p $(@D)
cp $^ $@
tools/generate-symbols.sh
cp $^ $(LUNA_ROOT)/initrd/boot/moon.elf
$(LUNA_ROOT)/tools/generate-symbols.sh

8
libs/Makefile Normal file
View File

@ -0,0 +1,8 @@
build:
@make -C libc build
install:
@make -C libc install
clean:
@make -C libc clean

View File

@ -3,12 +3,13 @@ LIBC_SRC := $(LIBC_DIR)/src
LIBC_OBJ := $(LIBC_DIR)/lib
LIBC_BIN := $(LIBC_DIR)/bin
LIBC_CC := x86_64-elf-gcc
LIBC_CXX := x86_64-elf-g++
LIBC_NASM := nasm
LIBC_AR := x86_64-elf-ar
CC := x86_64-luna-gcc
CXX := x86_64-luna-g++
ASM := nasm
AR := x86_64-luna-ar
LD := x86_64-luna-ld
LIBC_CFLAGS := -Wall -Wextra -Werror -Os -ffreestanding -nostdlib -fno-omit-frame-pointer -mno-mmx -mno-sse -mno-sse2 -I$(LIBC_DIR)/include -isystem $(LIBC_DIR)/include
LIBC_CFLAGS := -Wall -Wextra -Werror -Os -nostdlib -fno-omit-frame-pointer -mno-mmx -mno-sse -mno-sse2 -I$(LIBC_DIR)/include -isystem $(LIBC_DIR)/include
LIBC_CXXFLAGS := -fno-rtti -fno-exceptions
LIBC_NASMFLAGS := -felf64
@ -24,33 +25,33 @@ LIBC_OBJS += $(patsubst $(LIBC_SRC)/%.asm, $(LIBC_OBJ)/%.asm.o, $(LIBC_NASM_SRC)
$(LIBC_OBJ)/%.cpp.o: $(LIBC_SRC)/%.cpp
@mkdir -p $(@D)
$(LIBC_CXX) $(LIBC_CFLAGS) $(LIBC_CXXFLAGS) -o $@ -c $^
$(CXX) $(LIBC_CFLAGS) $(LIBC_CXXFLAGS) -o $@ -c $^
$(LIBC_OBJ)/%.c.o: $(LIBC_SRC)/%.c
@mkdir -p $(@D)
$(LIBC_CC) $(LIBC_CFLAGS) -o $@ -c $^
$(CC) $(LIBC_CFLAGS) -o $@ -c $^
$(LIBC_OBJ)/%.asm.o: $(LIBC_SRC)/%.asm
@mkdir -p $(@D)
$(LIBC_NASM) $(LIBC_NASMFLAGS) -o $@ $^
$(ASM) $(LIBC_NASMFLAGS) -o $@ $^
$(LIBC_BIN)/libc.a: $(LIBC_OBJS)
@mkdir -p $(@D)
$(LIBC_AR) rcs $@ $(LIBC_OBJS)
$(AR) rcs $@ $(LIBC_OBJS)
$(LIBC_BIN)/crt0.o: $(LIBC_DIR)/crt0.asm
@mkdir -p $(@D)
$(LIBC_NASM) $(LIBC_NASMFLAGS) -o $@ $^
$(ASM) $(LIBC_NASMFLAGS) -o $@ $^
$(LIBC_BIN)/crti.o: $(LIBC_DIR)/crti.asm
@mkdir -p $(@D)
$(LIBC_NASM) $(LIBC_NASMFLAGS) -o $@ $^
$(ASM) $(LIBC_NASMFLAGS) -o $@ $^
$(LIBC_BIN)/crtn.o: $(LIBC_DIR)/crtn.asm
@mkdir -p $(@D)
$(LIBC_NASM) $(LIBC_NASMFLAGS) -o $@ $^
$(ASM) $(LIBC_NASMFLAGS) -o $@ $^
libc-build: $(LIBC_BIN)/crt0.o $(LIBC_BIN)/crti.o $(LIBC_BIN)/crtn.o $(LIBC_BIN)/libc.a
build: $(LIBC_BIN)/crt0.o $(LIBC_BIN)/crti.o $(LIBC_BIN)/crtn.o $(LIBC_BIN)/libc.a
$(LUNA_ROOT)/base/usr/lib/libc.a: $(LIBC_BIN)/libc.a
@mkdir -p $(@D)
@ -68,9 +69,10 @@ $(LUNA_ROOT)/base/usr/lib/crtn.o: $(LIBC_BIN)/crtn.o
@mkdir -p $(@D)
cp $^ $@
libc-install: $(LUNA_ROOT)/base/usr/lib/libc.a $(LUNA_ROOT)/base/usr/lib/crt0.o $(LUNA_ROOT)/base/usr/lib/crti.o $(LUNA_ROOT)/base/usr/lib/crtn.o
install: $(LUNA_ROOT)/base/usr/lib/libc.a $(LUNA_ROOT)/base/usr/lib/crt0.o $(LUNA_ROOT)/base/usr/lib/crti.o $(LUNA_ROOT)/base/usr/lib/crtn.o
libc-clean:
clean:
rm -rf $(LIBC_OBJ)/*
rm -rf $(LIBC_BIN)/*
rm -f $(LUNA_ROOT)/base/usr/lib/libc.a
rm -f $(LUNA_ROOT)/base/usr/lib/crt*.o

Binary file not shown.