Adjust build system to be more flexible and to work with the new toolchain
This commit is contained in:
parent
ba52e389a5
commit
f8a72f15c8
3
.gitignore
vendored
3
.gitignore
vendored
@ -8,4 +8,5 @@ initrd/sys/moon.sym
|
|||||||
initrd/bin/**
|
initrd/bin/**
|
||||||
apps/bin/**
|
apps/bin/**
|
||||||
base/usr/include/**
|
base/usr/include/**
|
||||||
base/usr/lib/**
|
base/usr/lib/**
|
||||||
|
**/*.a
|
25
Makefile
25
Makefile
@ -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:
|
initrd-clean:
|
||||||
rm -f $(LUNA_ROOT)/initrd/boot/moon.elf $(LUNA_ROOT)/Luna.iso
|
rm -f $(LUNA_ROOT)/initrd/boot/moon.elf $(LUNA_ROOT)/Luna.iso
|
||||||
rm -rf $(LUNA_ROOT)/initrd/bin
|
rm -rf $(LUNA_ROOT)/initrd/bin
|
||||||
|
|
||||||
install: $(LUNA_ROOT)/initrd/boot/moon.elf apps-install libc-install
|
install:
|
||||||
|
@make -C kernel install
|
||||||
include kernel/Makefile
|
@make -C apps install
|
||||||
include apps/Makefile
|
@make -C libs install
|
||||||
include libs/libc/Makefile
|
|
@ -4,28 +4,32 @@ APPS_DIR := $(LUNA_ROOT)/apps
|
|||||||
APPS_OBJ := $(APPS_DIR)/lib
|
APPS_OBJ := $(APPS_DIR)/lib
|
||||||
APPS_BIN := $(APPS_DIR)/bin
|
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))
|
REAL_APPS := $(patsubst %, $(APPS_BIN)/%, $(APPS))
|
||||||
|
|
||||||
ASMC := nasm
|
|
||||||
ASMFLAGS := -felf64
|
ASMFLAGS := -felf64
|
||||||
|
|
||||||
LD := x86_64-elf-ld
|
APP_LDFLAGS := -nostdlib
|
||||||
APP_LDFLAGS := -T$(APPS_DIR)/apps.ld -nostdlib -z max-page-size=0x1000
|
|
||||||
|
|
||||||
$(APPS_OBJ)/%.o: $(APPS_DIR)/%.asm
|
$(APPS_OBJ)/%.o: $(APPS_DIR)/%.asm
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(ASMC) $(ASMFLAGS) -o $@ $^
|
nasm $(ASMFLAGS) -o $@ $^
|
||||||
|
|
||||||
$(APPS_BIN)/%: $(APPS_OBJ)/%.o
|
$(APPS_BIN)/%: $(APPS_OBJ)/%.o
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(LD) $(APP_LDFLAGS) -o $@ $^
|
$(LD) $(APP_LDFLAGS) -o $@ $^
|
||||||
|
|
||||||
apps-build: $(REAL_APPS)
|
build: $(REAL_APPS)
|
||||||
|
|
||||||
apps-install: $(REAL_APPS)
|
install: $(REAL_APPS)
|
||||||
@mkdir -p $(LUNA_ROOT)/initrd/bin
|
@mkdir -p $(LUNA_ROOT)/initrd/bin
|
||||||
cp $(REAL_APPS) $(LUNA_ROOT)/initrd/bin
|
cp $(REAL_APPS) $(LUNA_ROOT)/initrd/bin
|
||||||
|
|
||||||
apps-clean:
|
clean:
|
||||||
rm -f $(APPS_OBJ)/*
|
rm -f $(APPS_OBJ)/*
|
||||||
rm -f $(APPS_BIN)/*
|
rm -f $(APPS_BIN)/*
|
22
apps/apps.ld
22
apps/apps.ld
@ -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) }
|
|
||||||
}
|
|
@ -3,15 +3,15 @@ MOON_SRC := $(MOON_DIR)/src
|
|||||||
MOON_OBJ := $(MOON_DIR)/lib
|
MOON_OBJ := $(MOON_DIR)/lib
|
||||||
MOON_BIN := $(MOON_DIR)/bin
|
MOON_BIN := $(MOON_DIR)/bin
|
||||||
|
|
||||||
CC := x86_64-elf-gcc
|
CC := x86_64-luna-gcc
|
||||||
CXX := x86_64-elf-g++
|
CXX := x86_64-luna-g++
|
||||||
AS := x86_64-elf-as
|
ASM := nasm
|
||||||
NASM := 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
|
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
|
CXXFLAGS := -fno-rtti -fno-exceptions
|
||||||
NASMFLAGS := -felf64
|
NASMFLAGS := -felf64
|
||||||
ASFLAGS :=
|
|
||||||
LDFLAGS := -T$(MOON_DIR)/moon.ld -nostdlib -lgcc -Wl,--build-id=none -z max-page-size=0x1000
|
LDFLAGS := -T$(MOON_DIR)/moon.ld -nostdlib -lgcc -Wl,--build-id=none -z max-page-size=0x1000
|
||||||
|
|
||||||
ifneq ($(MOON_BUILD_STABLE), 1)
|
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)
|
CXX_SRC = $(call rwildcard,$(MOON_SRC),*.cpp)
|
||||||
C_SRC = $(call rwildcard,$(MOON_SRC),*.c)
|
C_SRC = $(call rwildcard,$(MOON_SRC),*.c)
|
||||||
AS_SRC = $(call rwildcard,$(MOON_SRC),*.S)
|
|
||||||
NASM_SRC = $(call rwildcard,$(MOON_SRC),*.asm)
|
NASM_SRC = $(call rwildcard,$(MOON_SRC),*.asm)
|
||||||
|
|
||||||
OBJS = $(patsubst $(MOON_SRC)/%.cpp, $(MOON_OBJ)/%.cpp.o, $(CXX_SRC))
|
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)/%.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))
|
OBJS += $(patsubst $(MOON_SRC)/%.asm, $(MOON_OBJ)/%.asm.o, $(NASM_SRC))
|
||||||
|
|
||||||
default: $(MOON_BIN)/moon.elf
|
default: $(MOON_BIN)/moon.elf
|
||||||
@ -56,23 +54,19 @@ $(MOON_OBJ)/%.c.o: $(MOON_SRC)/%.c
|
|||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(CC) $(CFLAGS) -o $@ -c $^
|
$(CC) $(CFLAGS) -o $@ -c $^
|
||||||
|
|
||||||
$(MOON_OBJ)/%.S.o: $(MOON_SRC)/%.S
|
|
||||||
@mkdir -p $(@D)
|
|
||||||
$(AS) $(ASFLAGS) -o $@ $^
|
|
||||||
|
|
||||||
$(MOON_OBJ)/%.asm.o: $(MOON_SRC)/%.asm
|
$(MOON_OBJ)/%.asm.o: $(MOON_SRC)/%.asm
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(NASM) $(NASMFLAGS) -o $@ $^
|
nasm $(NASMFLAGS) -o $@ $^
|
||||||
|
|
||||||
$(MOON_BIN)/moon.elf: $(OBJS)
|
build: $(OBJS)
|
||||||
@mkdir -p $(@D)
|
@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_OBJ)/*
|
||||||
rm -rf $(MOON_BIN)/*
|
rm -rf $(MOON_BIN)/*
|
||||||
|
|
||||||
$(LUNA_ROOT)/initrd/boot/moon.elf: $(MOON_BIN)/moon.elf
|
install: $(MOON_BIN)/moon.elf
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
cp $^ $@
|
cp $^ $(LUNA_ROOT)/initrd/boot/moon.elf
|
||||||
tools/generate-symbols.sh
|
$(LUNA_ROOT)/tools/generate-symbols.sh
|
8
libs/Makefile
Normal file
8
libs/Makefile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
build:
|
||||||
|
@make -C libc build
|
||||||
|
|
||||||
|
install:
|
||||||
|
@make -C libc install
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@make -C libc clean
|
@ -3,12 +3,13 @@ LIBC_SRC := $(LIBC_DIR)/src
|
|||||||
LIBC_OBJ := $(LIBC_DIR)/lib
|
LIBC_OBJ := $(LIBC_DIR)/lib
|
||||||
LIBC_BIN := $(LIBC_DIR)/bin
|
LIBC_BIN := $(LIBC_DIR)/bin
|
||||||
|
|
||||||
LIBC_CC := x86_64-elf-gcc
|
CC := x86_64-luna-gcc
|
||||||
LIBC_CXX := x86_64-elf-g++
|
CXX := x86_64-luna-g++
|
||||||
LIBC_NASM := nasm
|
ASM := nasm
|
||||||
LIBC_AR := x86_64-elf-ar
|
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_CXXFLAGS := -fno-rtti -fno-exceptions
|
||||||
LIBC_NASMFLAGS := -felf64
|
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
|
$(LIBC_OBJ)/%.cpp.o: $(LIBC_SRC)/%.cpp
|
||||||
@mkdir -p $(@D)
|
@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
|
$(LIBC_OBJ)/%.c.o: $(LIBC_SRC)/%.c
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(LIBC_CC) $(LIBC_CFLAGS) -o $@ -c $^
|
$(CC) $(LIBC_CFLAGS) -o $@ -c $^
|
||||||
|
|
||||||
$(LIBC_OBJ)/%.asm.o: $(LIBC_SRC)/%.asm
|
$(LIBC_OBJ)/%.asm.o: $(LIBC_SRC)/%.asm
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(LIBC_NASM) $(LIBC_NASMFLAGS) -o $@ $^
|
$(ASM) $(LIBC_NASMFLAGS) -o $@ $^
|
||||||
|
|
||||||
$(LIBC_BIN)/libc.a: $(LIBC_OBJS)
|
$(LIBC_BIN)/libc.a: $(LIBC_OBJS)
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(LIBC_AR) rcs $@ $(LIBC_OBJS)
|
$(AR) rcs $@ $(LIBC_OBJS)
|
||||||
|
|
||||||
$(LIBC_BIN)/crt0.o: $(LIBC_DIR)/crt0.asm
|
$(LIBC_BIN)/crt0.o: $(LIBC_DIR)/crt0.asm
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(LIBC_NASM) $(LIBC_NASMFLAGS) -o $@ $^
|
$(ASM) $(LIBC_NASMFLAGS) -o $@ $^
|
||||||
|
|
||||||
$(LIBC_BIN)/crti.o: $(LIBC_DIR)/crti.asm
|
$(LIBC_BIN)/crti.o: $(LIBC_DIR)/crti.asm
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(LIBC_NASM) $(LIBC_NASMFLAGS) -o $@ $^
|
$(ASM) $(LIBC_NASMFLAGS) -o $@ $^
|
||||||
|
|
||||||
$(LIBC_BIN)/crtn.o: $(LIBC_DIR)/crtn.asm
|
$(LIBC_BIN)/crtn.o: $(LIBC_DIR)/crtn.asm
|
||||||
@mkdir -p $(@D)
|
@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
|
$(LUNA_ROOT)/base/usr/lib/libc.a: $(LIBC_BIN)/libc.a
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
@ -68,9 +69,10 @@ $(LUNA_ROOT)/base/usr/lib/crtn.o: $(LIBC_BIN)/crtn.o
|
|||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
cp $^ $@
|
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_OBJ)/*
|
||||||
rm -rf $(LIBC_BIN)/*
|
rm -rf $(LIBC_BIN)/*
|
||||||
rm -f $(LUNA_ROOT)/base/usr/lib/libc.a
|
rm -f $(LUNA_ROOT)/base/usr/lib/libc.a
|
||||||
|
rm -f $(LUNA_ROOT)/base/usr/lib/crt*.o
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user