build: Misc Makefile improvements

This commit is contained in:
mintsuki 2021-12-22 22:08:19 +01:00
parent e9383335b4
commit 245bea9ef3
3 changed files with 24 additions and 22 deletions

View File

@ -9,9 +9,11 @@ BUILDDIR ?= $(shell pwd)/build
override BINDIR := $(BUILDDIR)/bin
override SPACE := $(subst ,, )
override COMMA := ,
MKESCAPE = $(subst $(SPACE),\ ,$(1))
SHESCAPE = $(subst ','\'',$(1))
NASMESCAPE = $(subst ','"'$(COMMA) \"'\"$(COMMA) '"',$(1))
override PATH := $(shell pwd)/toolchain/bin:$(PATH)
export PATH
@ -73,7 +75,7 @@ clean: limine-bios-clean limine-uefi-clean limine-uefi32-clean
.PHONY: install
install: all
install -d '$(DESTDIR)$(PREFIX)/bin'
install -s '$(call SHESCAPE,$(BINDIR))/limine-install' '$(DESTDIR)$(PREFIX)/bin/'
install -s '$(call SHESCAPE,$(BINDIR))/limine-install' '$(DESTDIR)$(PREFIX)/bin/' || true
install -d '$(DESTDIR)$(PREFIX)/share'
install -d '$(DESTDIR)$(PREFIX)/share/limine'
install -m 644 '$(call SHESCAPE,$(BINDIR))/limine.sys' '$(DESTDIR)$(PREFIX)/share/limine/' || true
@ -85,9 +87,9 @@ install: all
$(call MKESCAPE,$(BUILDDIR))/stage1: $(STAGE1_FILES) $(call MKESCAPE,$(BUILDDIR))/decompressor/decompressor.bin $(call MKESCAPE,$(BUILDDIR))/stage23-bios/stage2.bin.gz
mkdir -p '$(call SHESCAPE,$(BINDIR))'
cd stage1/hdd && nasm bootsect.asm -Werror -fbin -DBUILDDIR="'"'$(call SHESCAPE,$(BUILDDIR))'"'" -o '$(call SHESCAPE,$(BINDIR))/limine-hdd.bin'
cd stage1/cd && nasm bootsect.asm -Werror -fbin -DBUILDDIR="'"'$(call SHESCAPE,$(BUILDDIR))'"'" -o '$(call SHESCAPE,$(BINDIR))/limine-cd.bin'
cd stage1/pxe && nasm bootsect.asm -Werror -fbin -DBUILDDIR="'"'$(call SHESCAPE,$(BUILDDIR))'"'" -o '$(call SHESCAPE,$(BINDIR))/limine-pxe.bin'
cd stage1/hdd && nasm bootsect.asm -Werror -fbin -DBUILDDIR="'"'$(call NASMESCAPE,$(BUILDDIR))'"'" -o '$(call SHESCAPE,$(BINDIR))/limine-hdd.bin'
cd stage1/cd && nasm bootsect.asm -Werror -fbin -DBUILDDIR="'"'$(call NASMESCAPE,$(BUILDDIR))'"'" -o '$(call SHESCAPE,$(BINDIR))/limine-cd.bin'
cd stage1/pxe && nasm bootsect.asm -Werror -fbin -DBUILDDIR="'"'$(call NASMESCAPE,$(BUILDDIR))'"'" -o '$(call SHESCAPE,$(BINDIR))/limine-pxe.bin'
cp '$(call SHESCAPE,$(BUILDDIR))/stage23-bios/limine.sys' '$(call SHESCAPE,$(BINDIR))/'
touch '$(call SHESCAPE,$(BUILDDIR))/stage1'

View File

@ -86,17 +86,17 @@ $(call MKESCAPE,$(BUILDDIR))/tinf-copied: ../tinf/*
touch '$(call SHESCAPE,$(BUILDDIR))/tinf-copied'
$(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o: $(call MKESCAPE,$(BUILDDIR))/tinf-copied
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
$(TOOLCHAIN_CC) $(CFLAGS) -Os $(INTERNAL_CFLAGS) -c '$(call SHESCAPE,$(@:.o=.c))' -o '$(call SHESCAPE,$@)'
-include $(HEADER_DEPS)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
$(TOOLCHAIN_CC) $(CFLAGS) -Os $(INTERNAL_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asm
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -f elf32 -o '$(call SHESCAPE,$@)'
.PHONY: clean

View File

@ -212,16 +212,16 @@ all: $(call MKESCAPE,$(BUILDDIR))/BOOTIA32.EFI
endif
$(call MKESCAPE,$(BUILDDIR))/sys/smp_trampoline.bin: sys/smp_trampoline.real
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
nasm $< -f bin -o '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/sys/smp_trampoline.o: $(call MKESCAPE,$(BUILDDIR))/sys/smp_trampoline.bin
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
cd '$(call SHESCAPE,$(BUILDDIR))/sys' && \
$(TOOLCHAIN_OBJCOPY) -B i8086 -I binary -O $(OBJCOPY_ARCH) smp_trampoline.bin '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/font.o: font.bin
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
$(TOOLCHAIN_OBJCOPY) -B i8086 -I binary -O $(OBJCOPY_ARCH) font.bin '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/tinf-copied: ../tinf/*
@ -231,7 +231,7 @@ $(call MKESCAPE,$(BUILDDIR))/tinf-copied: ../tinf/*
touch '$(call SHESCAPE,$(BUILDDIR))/tinf-copied'
$(call MKESCAPE,$(BUILDDIR))/tinf/tinfgzip.o $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o: $(call MKESCAPE,$(BUILDDIR))/tinf-copied
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
$(TOOLCHAIN_CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c '$(call SHESCAPE,$(@:.o=.c))' -o '$(call SHESCAPE,$@)'
ifeq ($(TARGET), bios)
@ -332,19 +332,19 @@ endif
ifeq ($(TARGET), uefi)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied $(call MKESCAPE,$(BUILDDIR))/reduced-gnu-efi
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
$(TOOLCHAIN_CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
endif
ifeq ($(TARGET), uefi32)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied $(call MKESCAPE,$(BUILDDIR))/reduced-gnu-efi
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
$(TOOLCHAIN_CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
endif
ifeq ($(TARGET), bios)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
$(TOOLCHAIN_CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
endif
@ -352,7 +352,7 @@ endif
ifeq ($(TARGET), bios)
$(call MKESCAPE,$(BUILDDIR))/%.s2.o: %.s2.c
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
$(TOOLCHAIN_CC) $(S2CFLAGS) $(INTERNAL_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
endif
@ -360,7 +360,7 @@ endif
ifeq ($(TARGET), uefi)
$(call MKESCAPE,$(BUILDDIR))/%.32.o: %.32.c $(call MKESCAPE,$(BUILDDIR))/reduced-gnu-efi
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
$(TOOLCHAIN_CC) $(CFLAGS) $(INTERNAL_CFLAGS32) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@).32'
$(TOOLCHAIN_OBJCOPY) -I elf32-i386 -O elf64-x86-64 '$(call SHESCAPE,$@).32' '$(call SHESCAPE,$@)'
rm '$(call SHESCAPE,$@).32'
@ -368,31 +368,31 @@ endif
ifeq ($(TARGET), bios)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asm32
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -F dwarf -g -Werror -f elf32 -o '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asmb
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -F dwarf -g -Werror -f elf32 -o '$(call SHESCAPE,$@)'
endif
ifeq ($(TARGET), uefi)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asm64
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -F dwarf -g -Werror -f elf64 -o '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asm64u
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -F dwarf -g -Werror -f elf64 -o '$(call SHESCAPE,$@)'
endif
ifeq ($(TARGET), uefi32)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asm32
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -F dwarf -g -Werror -f elf32 -o '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asm32u
dirname '$(call SHESCAPE,$@)' | xargs -d '\n' mkdir -p
mkdir -p "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -F dwarf -g -Werror -f elf32 -o '$(call SHESCAPE,$@)'
endif