build: Misc improvements to makefiles

This commit is contained in:
mintsuki 2022-08-15 17:41:04 +02:00
parent 1e9ac0ac01
commit 5f1680acc1
3 changed files with 172 additions and 166 deletions

View File

@ -27,8 +27,8 @@ override BUILD_LIMINE_DEPLOY := @BUILD_LIMINE_DEPLOY@
WERROR ?= @WERROR@
export WERROR
ifeq ($(origin CC), default)
CC := @CC@
ifeq ($(origin CC),default)
CC := @CC@
endif
export CC
@ -128,10 +128,10 @@ uninstall:
$(call MKESCAPE,$(BUILDDIR))/stage1.stamp: $(STAGE1_FILES) $(call MKESCAPE,$(BUILDDIR))/decompressor-build/decompressor.bin $(call MKESCAPE,$(BUILDDIR))/common-bios/stage2.bin.gz
$(MKDIR_P) '$(call SHESCAPE,$(BINDIR))'
cd '$(call SHESCAPE,$(SRCDIR))/stage1/hdd' && nasm bootsect.asm @WERROR@ -fbin -DBUILDDIR="'"'$(call NASMESCAPE,$(BUILDDIR))'"'" -o '$(call SHESCAPE,$(BINDIR))/limine-hdd.bin'
ifneq ($(BUILD_CD), no)
ifneq ($(BUILD_CD),no)
cd '$(call SHESCAPE,$(SRCDIR))/stage1/cd' && nasm bootsect.asm @WERROR@ -fbin -DBUILDDIR="'"'$(call NASMESCAPE,$(BUILDDIR))'"'" -o '$(call SHESCAPE,$(BINDIR))/limine-cd.bin'
endif
ifneq ($(BUILD_PXE), no)
ifneq ($(BUILD_PXE),no)
cd '$(call SHESCAPE,$(SRCDIR))/stage1/pxe' && nasm bootsect.asm @WERROR@ -fbin -DBUILDDIR="'"'$(call NASMESCAPE,$(BUILDDIR))'"'" -o '$(call SHESCAPE,$(BINDIR))/limine-pxe.bin'
endif
cp '$(call SHESCAPE,$(BUILDDIR))/common-bios/limine.sys' '$(call SHESCAPE,$(BINDIR))/'
@ -140,12 +140,12 @@ endif
.PHONY: limine-bios
limine-bios: common-bios decompressor
$(MAKE) '$(call SHESCAPE,$(BUILDDIR))/stage1.stamp'
ifneq ($(BUILD_LIMINE_DEPLOY), no)
ifneq ($(BUILD_LIMINE_DEPLOY),no)
$(MAKE) limine-deploy
endif
$(call MKESCAPE,$(BINDIR))/limine-cd-efi.bin: $(if @BUILD_UEFI_IA32@, $(call MKESCAPE,$(BUILDDIR))/common-uefi-ia32/BOOTIA32.EFI) $(if @BUILD_UEFI_X86_64@, $(call MKESCAPE,$(BUILDDIR))/common-uefi-x86-64/BOOTX64.EFI)
ifneq ($(BUILD_CD_EFI), no)
ifneq ($(BUILD_CD_EFI),no)
$(MKDIR_P) '$(call SHESCAPE,$(BINDIR))'
rm -f '$(call SHESCAPE,$(BINDIR))/limine-cd-efi.bin'
dd if=/dev/zero of='$(call SHESCAPE,$(BINDIR))/limine-cd-efi.bin' bs=512 count=2880 2>/dev/null
@ -163,18 +163,24 @@ endif
limine-cd-efi:
$(MAKE) '$(call SHESCAPE,$(BINDIR))/limine-cd-efi.bin'
.PHONY: limine-uefi-x86-64
limine-uefi-x86-64: $(call MKESCAPE,$(SRCDIR))/limine-efi
$(MAKE) common-uefi-x86-64
$(call MKESCAPE,$(BINDIR))/BOOTX64.EFI: $(call MKESCAPE,$(BUILDDIR))/common-uefi-x86-64/BOOTX64.EFI
$(MKDIR_P) '$(call SHESCAPE,$(BINDIR))'
cp '$(call SHESCAPE,$(BUILDDIR))/common-uefi-x86-64/BOOTX64.EFI' '$(call SHESCAPE,$(BINDIR))/'
.PHONY: limine-uefi-ia32
limine-uefi-ia32: $(call MKESCAPE,$(SRCDIR))/limine-efi
$(MAKE) common-uefi-ia32
.PHONY: limine-uefi-x86-64
limine-uefi-x86-64:
$(MAKE) common-uefi-x86-64
$(MAKE) '$(call SHESCAPE,$(BINDIR))/BOOTX64.EFI'
$(call MKESCAPE,$(BINDIR))/BOOTIA32.EFI: $(call MKESCAPE,$(BUILDDIR))/common-uefi-ia32/BOOTIA32.EFI
$(MKDIR_P) '$(call SHESCAPE,$(BINDIR))'
cp '$(call SHESCAPE,$(BUILDDIR))/common-uefi-ia32/BOOTIA32.EFI' '$(call SHESCAPE,$(BINDIR))/'
.PHONY: limine-uefi-ia32
limine-uefi-ia32:
$(MAKE) common-uefi-ia32
$(MAKE) '$(call SHESCAPE,$(BINDIR))/BOOTIA32.EFI'
.PHONY: limine-bios-clean
limine-bios-clean: common-bios-clean decompressor-clean

View File

@ -11,18 +11,18 @@ MKESCAPE = $(subst $(SPACE),\ ,$(1))
SHESCAPE = $(subst ','\'',$(1))
OBJESCAPE = $(subst .a ,.a' ',$(subst .o ,.o' ',$(call SHESCAPE,$(1))))
ifeq ($(call MKESCAPE,$(BUILDDIR)), )
$(error BUILDDIR not specified)
ifeq ($(call MKESCAPE,$(BUILDDIR)),)
$(error BUILDDIR not specified)
endif
ifeq ($(TARGET), bios)
override OBJCOPY_ARCH := elf32-i386
else ifeq ($(TARGET), uefi-x86-64)
override OBJCOPY_ARCH := elf64-x86-64
else ifeq ($(TARGET), uefi-ia32)
override OBJCOPY_ARCH := elf32-i386
ifeq ($(TARGET),bios)
override OBJCOPY_ARCH := elf32-i386
else ifeq ($(TARGET),uefi-x86-64)
override OBJCOPY_ARCH := elf64-x86-64
else ifeq ($(TARGET),uefi-ia32)
override OBJCOPY_ARCH := elf32-i386
else
$(error Invalid target)
$(error Invalid target)
endif
COM_OUTPUT ?= false
@ -31,134 +31,134 @@ E9_OUTPUT ?= false
override S2CFLAGS := -Os
override CROSS_CFLAGS += \
-g \
$(WERROR) \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fno-omit-frame-pointer \
-fno-strict-aliasing \
-fno-lto \
-nostdinc \
-Wno-address-of-packed-member \
-Wshadow \
-Wvla \
-mno-80387 \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-MMD \
-DCOM_OUTPUT=$(COM_OUTPUT) \
-DE9_OUTPUT=$(E9_OUTPUT) \
-I../freestanding-headers \
-I'$(call SHESCAPE,$(BUILDDIR))/..' \
-I. \
-I.. \
-I'$(call SHESCAPE,$(BUILDDIR))/tinf'
-g \
$(WERROR) \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fno-omit-frame-pointer \
-fno-strict-aliasing \
-fno-lto \
-nostdinc \
-Wno-address-of-packed-member \
-Wshadow \
-Wvla \
-mno-80387 \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-MMD \
-DCOM_OUTPUT=$(COM_OUTPUT) \
-DE9_OUTPUT=$(E9_OUTPUT) \
-I../freestanding-headers \
-I'$(call SHESCAPE,$(BUILDDIR))/..' \
-I. \
-I.. \
-I'$(call SHESCAPE,$(BUILDDIR))/tinf'
ifeq ($(TARGET), bios)
override CROSS_CFLAGS += \
-Dbios=1 \
-Duefi=0 \
-m32 \
-march=i686 \
-mtune=generic \
-mabi=sysv \
-fno-pie \
-fno-pic
ifeq ($(TARGET),bios)
override CROSS_CFLAGS += \
-Dbios=1 \
-Duefi=0 \
-m32 \
-march=i686 \
-mtune=generic \
-mabi=sysv \
-fno-pie \
-fno-pic
endif
ifeq ($(TARGET), uefi-x86-64)
override CROSS_CFLAGS += \
-Dbios=0 \
-Duefi=1 \
-m64 \
-march=x86-64 \
-mtune=generic \
-mabi=sysv \
-DGNU_EFI_USE_MS_ABI \
-I'$(call SHESCAPE,$(BUILDDIR))/limine-efi/inc' \
-I'$(call SHESCAPE,$(BUILDDIR))/limine-efi/inc/x86_64' \
-fpie \
-mno-red-zone
ifeq ($(TARGET),uefi-x86-64)
override CROSS_CFLAGS += \
-Dbios=0 \
-Duefi=1 \
-m64 \
-march=x86-64 \
-mtune=generic \
-mabi=sysv \
-DGNU_EFI_USE_MS_ABI \
-I'$(call SHESCAPE,$(BUILDDIR))/limine-efi/inc' \
-I'$(call SHESCAPE,$(BUILDDIR))/limine-efi/inc/x86_64' \
-fpie \
-mno-red-zone
endif
ifeq ($(TARGET), uefi-ia32)
override CROSS_CFLAGS += \
-Dbios=0 \
-Duefi=1 \
-m32 \
-march=i686 \
-mtune=generic \
-mabi=sysv \
-DGNU_EFI_USE_MS_ABI \
-I'$(call SHESCAPE,$(BUILDDIR))/limine-efi/inc' \
-I'$(call SHESCAPE,$(BUILDDIR))/limine-efi/inc/ia32' \
-fpie
ifeq ($(TARGET),uefi-ia32)
override CROSS_CFLAGS += \
-Dbios=0 \
-Duefi=1 \
-m32 \
-march=i686 \
-mtune=generic \
-mabi=sysv \
-DGNU_EFI_USE_MS_ABI \
-I'$(call SHESCAPE,$(BUILDDIR))/limine-efi/inc' \
-I'$(call SHESCAPE,$(BUILDDIR))/limine-efi/inc/ia32' \
-fpie
endif
override CROSS_LDFLAGS += \
-nostdlib \
-z max-page-size=0x1000
-nostdlib \
-z max-page-size=0x1000
ifeq ($(TARGET), bios)
override CROSS_LDFLAGS += \
-melf_i386 \
-static \
--build-id=sha1
ifeq ($(TARGET),bios)
override CROSS_LDFLAGS += \
-melf_i386 \
-static \
--build-id=sha1
endif
ifeq ($(TARGET), uefi-x86-64)
override CROSS_LDFLAGS += \
-melf_x86_64 \
-static \
-pie \
--no-dynamic-linker \
-ztext
ifeq ($(TARGET),uefi-x86-64)
override CROSS_LDFLAGS += \
-melf_x86_64 \
-static \
-pie \
--no-dynamic-linker \
-ztext
endif
ifeq ($(TARGET), uefi-ia32)
override CROSS_LDFLAGS += \
-melf_i386 \
-static \
-pie \
--no-dynamic-linker \
-ztext
ifeq ($(TARGET),uefi-ia32)
override CROSS_LDFLAGS += \
-melf_i386 \
-static \
-pie \
--no-dynamic-linker \
-ztext
endif
.PHONY: all
override C_FILES := $(shell find ./ -type f -name '*.c')
ifeq ($(TARGET), bios)
override ASMX86_FILES := $(shell find ./ -type f -name '*.asm_x86')
override ASM32_FILES := $(shell find ./ -type f -name '*.asm_ia32')
override ASMB_FILES := $(shell find ./ -type f -name '*.asm_bios_ia32')
ifeq ($(TARGET),bios)
override ASMX86_FILES := $(shell find ./ -type f -name '*.asm_x86')
override ASM32_FILES := $(shell find ./ -type f -name '*.asm_ia32')
override ASMB_FILES := $(shell find ./ -type f -name '*.asm_bios_ia32')
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(C_FILES:.c=.o) $(ASM32_FILES:.asm_ia32=.o) $(ASMB_FILES:.asm_bios_ia32=.o) $(ASMX86_FILES:.asm_x86=.o))
override OBJ_S2 := $(filter %.s2.o,$(OBJ))
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(C_FILES:.c=.o) $(ASM32_FILES:.asm_ia32=.o) $(ASMB_FILES:.asm_bios_ia32=.o) $(ASMX86_FILES:.asm_x86=.o))
override OBJ_S2 := $(filter %.s2.o,$(OBJ))
endif
ifeq ($(TARGET), uefi-x86-64)
override ASMX86_FILES := $(shell find ./ -type f -name '*.asm_x86')
override ASM64_FILES := $(shell find ./ -type f -name '*.asm_x86_64')
override ASM64U_FILES := $(shell find ./ -type f -name '*.asm_uefi_x86_64')
ifeq ($(TARGET),uefi-x86-64)
override ASMX86_FILES := $(shell find ./ -type f -name '*.asm_x86')
override ASM64_FILES := $(shell find ./ -type f -name '*.asm_x86_64')
override ASM64U_FILES := $(shell find ./ -type f -name '*.asm_uefi_x86_64')
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(C_FILES:.c=.o) $(ASM64_FILES:.asm_x86_64=.o) $(ASM64U_FILES:.asm_uefi_x86_64=.o) $(ASMX86_FILES:.asm_x86=.o))
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(C_FILES:.c=.o) $(ASM64_FILES:.asm_x86_64=.o) $(ASM64U_FILES:.asm_uefi_x86_64=.o) $(ASMX86_FILES:.asm_x86=.o))
endif
ifeq ($(TARGET), uefi-ia32)
override ASMX86_FILES := $(shell find ./ -type f -name '*.asm_x86')
override ASM32_FILES := $(shell find ./ -type f -name '*.asm_ia32')
override ASM32U_FILES := $(shell find ./ -type f -name '*.asm_uefi_ia32')
ifeq ($(TARGET),uefi-ia32)
override ASMX86_FILES := $(shell find ./ -type f -name '*.asm_x86')
override ASM32_FILES := $(shell find ./ -type f -name '*.asm_ia32')
override ASM32U_FILES := $(shell find ./ -type f -name '*.asm_uefi_ia32')
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(C_FILES:.c=.o) $(ASM32_FILES:.asm_ia32=.o) $(ASM32U_FILES:.asm_uefi_ia32=.o) $(ASMX86_FILES:.asm_x86=.o))
override OBJ := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(C_FILES:.c=.o) $(ASM32_FILES:.asm_ia32=.o) $(ASM32U_FILES:.asm_uefi_ia32=.o) $(ASMX86_FILES:.asm_x86=.o))
endif
override HEADER_DEPS := $(addprefix $(call MKESCAPE,$(BUILDDIR))/, $(C_FILES:.c=.d))
ifeq ($(TARGET), bios)
.PHONY: all
ifeq ($(TARGET),bios)
all: $(call MKESCAPE,$(BUILDDIR))/limine.sys $(call MKESCAPE,$(BUILDDIR))/stage2.bin.gz
else ifeq ($(TARGET), uefi-x86-64)
else ifeq ($(TARGET),uefi-x86-64)
all: $(call MKESCAPE,$(BUILDDIR))/BOOTX64.EFI
else ifeq ($(TARGET), uefi-ia32)
else ifeq ($(TARGET),uefi-ia32)
all: $(call MKESCAPE,$(BUILDDIR))/BOOTIA32.EFI
endif
@ -180,7 +180,7 @@ $(call MKESCAPE,$(BUILDDIR))/tinf/tinflate.o: $(call MKESCAPE,$(BUILDDIR))/tinf-
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
$(CROSS_CC) $(CROSS_CFLAGS) -c '$(call SHESCAPE,$(@:.o=.c))' -o '$(call SHESCAPE,$@)'
ifeq ($(TARGET), bios)
ifeq ($(TARGET),bios)
$(call MKESCAPE,$(BUILDDIR))/stage2.bin.gz: $(call MKESCAPE,$(BUILDDIR))/stage2.bin
gzip -n -9 < '$(call SHESCAPE,$<)' > '$(call SHESCAPE,$@)'
@ -249,7 +249,7 @@ $(call MKESCAPE,$(BUILDDIR))/limine-efi: ../limine-efi/*
$(MKDIR_P) '$(call SHESCAPE,$(BUILDDIR))'
cp -r ../limine-efi '$(call SHESCAPE,$(BUILDDIR))/'
ifeq ($(TARGET), uefi-x86-64)
ifeq ($(TARGET),uefi-x86-64)
$(call MKESCAPE,$(BUILDDIR))/full.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf
cd '$(call SHESCAPE,$(BUILDDIR))' && \
@ -290,7 +290,7 @@ $(call MKESCAPE,$(BUILDDIR))/limine.elf: $(call MKESCAPE,$(BUILDDIR))/limine-efi
endif
ifeq ($(TARGET), uefi-ia32)
ifeq ($(TARGET),uefi-ia32)
$(call MKESCAPE,$(BUILDDIR))/full.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf
cd '$(call SHESCAPE,$(BUILDDIR))' && \
@ -333,19 +333,19 @@ endif
-include $(HEADER_DEPS)
ifeq ($(TARGET), uefi-x86-64)
ifeq ($(TARGET),uefi-x86-64)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied $(call MKESCAPE,$(BUILDDIR))/limine-efi
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
$(CROSS_CC) $(CROSS_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
endif
ifeq ($(TARGET), uefi-ia32)
ifeq ($(TARGET),uefi-ia32)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied $(call MKESCAPE,$(BUILDDIR))/limine-efi
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
$(CROSS_CC) $(CROSS_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
endif
ifeq ($(TARGET), bios)
ifeq ($(TARGET),bios)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.c $(call MKESCAPE,$(BUILDDIR))/tinf-copied
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
$(CROSS_CC) $(CROSS_CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
@ -353,7 +353,7 @@ endif
-include $(HEADER_DEPS)
ifeq ($(TARGET), bios)
ifeq ($(TARGET),bios)
$(call MKESCAPE,$(BUILDDIR))/%.s2.o: %.s2.c
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
$(CROSS_CC) $(CROSS_CFLAGS) $(S2CFLAGS) -c '$(call SHESCAPE,$<)' -o '$(call SHESCAPE,$@)'
@ -361,7 +361,7 @@ endif
-include $(HEADER_DEPS)
ifeq ($(TARGET), bios)
ifeq ($(TARGET),bios)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asm_ia32
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -F dwarf -g $(WERROR) -f elf32 -o '$(call SHESCAPE,$@)'
@ -375,7 +375,7 @@ $(call MKESCAPE,$(BUILDDIR))/%.o: %.asm_x86
nasm '$(call SHESCAPE,$<)' -F dwarf -g $(WERROR) -f elf32 -o '$(call SHESCAPE,$@)'
endif
ifeq ($(TARGET), uefi-x86-64)
ifeq ($(TARGET),uefi-x86-64)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asm_x86_64
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -F dwarf -g $(WERROR) -f elf64 -o '$(call SHESCAPE,$@)'
@ -389,7 +389,7 @@ $(call MKESCAPE,$(BUILDDIR))/%.o: %.asm_x86
nasm '$(call SHESCAPE,$<)' -F dwarf -g $(WERROR) -f elf64 -o '$(call SHESCAPE,$@)'
endif
ifeq ($(TARGET), uefi-ia32)
ifeq ($(TARGET),uefi-ia32)
$(call MKESCAPE,$(BUILDDIR))/%.o: %.asm_ia32
$(MKDIR_P) "$$(dirname '$(call SHESCAPE,$@)')"
nasm '$(call SHESCAPE,$<)' -F dwarf -g $(WERROR) -f elf32 -o '$(call SHESCAPE,$@)'

View File

@ -8,45 +8,45 @@ MKESCAPE = $(subst $(SPACE),\ ,$(1))
SHESCAPE = $(subst ','\'',$(1))
OBJESCAPE = $(subst .a ,.a' ',$(subst .o ,.o' ',$(call SHESCAPE,$(1))))
ifeq ($(call MKESCAPE,$(BUILDDIR)), )
$(error BUILDDIR not specified)
ifeq ($(call MKESCAPE,$(BUILDDIR)),)
$(error BUILDDIR not specified)
endif
override CROSS_CFLAGS += \
$(WERROR) \
$(WERROR) \
-Os \
-m32 \
-march=i686 \
-mtune=generic \
-mabi=sysv \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fno-strict-aliasing \
-fno-lto \
-fno-pie \
-fno-pic \
-fomit-frame-pointer \
-nostdinc \
-Wno-address-of-packed-member \
-Wshadow \
-Wvla \
-mno-80387 \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-MMD \
-I../freestanding-headers \
-I. \
-I'$(call SHESCAPE,$(BUILDDIR))/tinf'
-m32 \
-march=i686 \
-mtune=generic \
-mabi=sysv \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fno-strict-aliasing \
-fno-lto \
-fno-pie \
-fno-pic \
-fomit-frame-pointer \
-nostdinc \
-Wno-address-of-packed-member \
-Wshadow \
-Wvla \
-mno-80387 \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-MMD \
-I../freestanding-headers \
-I. \
-I'$(call SHESCAPE,$(BUILDDIR))/tinf'
override CROSS_LDFLAGS += \
-melf_i386 \
-nostdlib \
-z max-page-size=0x1000 \
-static \
-Tlinker.ld
-melf_i386 \
-nostdlib \
-z max-page-size=0x1000 \
-static \
-Tlinker.ld
override C_FILES := $(shell find ./ -type f -name '*.c')
override ASM_FILES := $(shell find ./ -type f -name '*.asm')