:: commit 7cca9dd42f2f0b83da81a483c8eb3ad64c92aa12

mintsuki <mintsuki@protonmail.com> — 2021-08-07 05:26

parents: 5ffce7c42e

build: Misc build system improvements

diff --git a/Makefile b/Makefile
index ff79a0c3..d77e0ae5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,27 @@
-PREFIX = /usr/local
-DESTDIR =
+PREFIX ?= /usr/local
+DESTDIR ?=
 
-PATH := $(shell pwd)/toolchain/bin:$(PATH)
+export PATH := $(shell pwd)/toolchain/bin:$(PATH)
 
 NCPUS := $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)
 
-TOOLCHAIN = limine
+TOOLCHAIN ?= limine
 
-TOOLCHAIN_CC = $(TOOLCHAIN)-gcc
+TOOLCHAIN_CC ?= $(TOOLCHAIN)-gcc
 
-ifeq ($(shell export "PATH=$(PATH)"; command -v $(TOOLCHAIN_CC) ; ), )
-TOOLCHAIN_CC := cc
+ifeq ($(shell PATH="$(PATH)" command -v $(TOOLCHAIN_CC) ; ), )
+override TOOLCHAIN_CC := cc
 endif
 
-CC_MACHINE := $(shell export "PATH=$(PATH)"; $(TOOLCHAIN_CC) -dumpmachine | dd bs=6 count=1 2>/dev/null)
+ifeq ($(TOOLCHAIN_CC), clang)
+TOOLCHAIN_CC += --target=x86_64-elf
+ifeq ($(TOOLCHAIN_CC), clang)
+override TOOLCHAIN_CC += --target=x86_64-elf
+MAKEOVERRIDES += TOOLCHAIN_CC+=--target=x86_64-elf
+endif
+endif
+
+CC_MACHINE := $(shell PATH="$(PATH)" $(TOOLCHAIN_CC) -dumpmachine | dd bs=6 count=1 2>/dev/null)
 
 ifneq ($(MAKECMDGOALS), toolchain)
 ifneq ($(MAKECMDGOALS), distclean)
diff --git a/decompressor/Makefile b/decompressor/Makefile
index d9cb8fe1..07caef48 100644
--- a/decompressor/Makefile
+++ b/decompressor/Makefile
@@ -4,23 +4,24 @@ ifeq ($(BUILDDIR), )
 	$(error BUILDDIR not specified)
 endif
 
-TOOLCHAIN = limine
+TOOLCHAIN ?= limine
 
-TOOLCHAIN_CC = $(TOOLCHAIN)-gcc
-TOOLCHAIN_LD = $(TOOLCHAIN)-ld
-TOOLCHAIN_OBJCOPY = $(TOOLCHAIN)-objcopy
+TOOLCHAIN_CC ?= $(TOOLCHAIN)-gcc
+TOOLCHAIN_LD ?= $(TOOLCHAIN)-ld
+TOOLCHAIN_OBJCOPY ?= $(TOOLCHAIN)-objcopy
 
 ifeq ($(shell command -v $(TOOLCHAIN_CC) ; ), )
-TOOLCHAIN_CC := cc
+override TOOLCHAIN_CC := cc
 endif
 ifeq ($(shell command -v $(TOOLCHAIN_LD) ; ), )
-TOOLCHAIN_LD := ld
+override TOOLCHAIN_LD := ld
 endif
 ifeq ($(shell command -v $(TOOLCHAIN_OBJCOPY) ; ), )
-TOOLCHAIN_OBJCOPY := objcopy
+override TOOLCHAIN_OBJCOPY := objcopy
 endif
 
-CFLAGS = -Os -pipe -Wall -Wextra -Werror
+WERROR = -Werror
+CFLAGS ?= -Os -pipe -Wall -Wextra $(WERROR)
 
 INTERNAL_CFLAGS = \
 	-m32 \
@@ -41,7 +42,7 @@ INTERNAL_CFLAGS = \
 	-MMD \
 	-I.
 
-LDFLAGS =
+LDFLAGS ?=
 
 INTERNAL_LDFLAGS = \
 	-melf_i386 \
@@ -71,7 +72,7 @@ $(BUILDDIR)/decompressor.bin: $(OBJ)
 -include $(HEADER_DEPS)
 
 $(BUILDDIR)/%.o: %.c
-	$(TOOLCHAIN_CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
+	$(TOOLCHAIN_CC) $(CFLAGS) -Os $(INTERNAL_CFLAGS) -c $< -o $@
 
 $(BUILDDIR)/%.o: %.asm
 	nasm $< -f elf32 -o $@
diff --git a/stage23/Makefile b/stage23/Makefile
index c04d79d2..02c936dc 100644
--- a/stage23/Makefile
+++ b/stage23/Makefile
@@ -6,41 +6,41 @@ ifeq ($(BUILDDIR), )
 endif
 
 ifeq ($(TARGET), bios)
-	OBJCOPY_ARCH = elf32-i386
+	OBJCOPY_ARCH := elf32-i386
 else ifeq ($(TARGET), uefi)
-	OBJCOPY_ARCH = elf64-x86-64
+	OBJCOPY_ARCH := elf64-x86-64
 else ifeq ($(TARGET), uefi32)
-	OBJCOPY_ARCH = elf32-i386
+	OBJCOPY_ARCH := elf32-i386
 else
 	$(error Invalid target)
 endif
 
-TOOLCHAIN = limine
+TOOLCHAIN ?= limine
 
-TOOLCHAIN_CC = $(TOOLCHAIN)-gcc
-TOOLCHAIN_LD = $(TOOLCHAIN)-ld
-TOOLCHAIN_AR = $(TOOLCHAIN)-ar
-TOOLCHAIN_OBJCOPY = $(TOOLCHAIN)-objcopy
-TOOLCHAIN_OBJDUMP = $(TOOLCHAIN)-objdump
-TOOLCHAIN_READELF = $(TOOLCHAIN)-readelf
+TOOLCHAIN_CC ?= $(TOOLCHAIN)-gcc
+TOOLCHAIN_LD ?= $(TOOLCHAIN)-ld
+TOOLCHAIN_AR ?= $(TOOLCHAIN)-ar
+TOOLCHAIN_OBJCOPY ?= $(TOOLCHAIN)-objcopy
+TOOLCHAIN_OBJDUMP ?= $(TOOLCHAIN)-objdump
+TOOLCHAIN_READELF ?= $(TOOLCHAIN)-readelf
 
 ifeq ($(shell command -v $(TOOLCHAIN_CC) ; ), )
-TOOLCHAIN_CC := cc
+override TOOLCHAIN_CC := cc
 endif
 ifeq ($(shell command -v $(TOOLCHAIN_LD) ; ), )
-TOOLCHAIN_LD := ld
+override TOOLCHAIN_LD := ld
 endif
 ifeq ($(shell command -v $(TOOLCHAIN_AR) ; ), )
-TOOLCHAIN_AR := ar
+override TOOLCHAIN_AR := ar
 endif
 ifeq ($(shell command -v $(TOOLCHAIN_OBJCOPY) ; ), )
-TOOLCHAIN_OBJCOPY := objcopy
+override TOOLCHAIN_OBJCOPY := objcopy
 endif
 ifeq ($(shell command -v $(TOOLCHAIN_OBJDUMP) ; ), )
-TOOLCHAIN_OBJDUMP := objdump
+override TOOLCHAIN_OBJDUMP := objdump
 endif
 ifeq ($(shell command -v $(TOOLCHAIN_READELF) ; ), )
-TOOLCHAIN_READELF := readelf
+override TOOLCHAIN_READELF := readelf
 endif
 
 COM_OUTPUT = false
@@ -50,7 +50,7 @@ BUILD_ID := $(shell dd if=/dev/urandom count=8 bs=1 2>/dev/null | od -An -t x4 |
 LIMINE_VERSION := $(shell cat ../version 2>/dev/null || ( git describe --exact-match --tags `git log -n1 --pretty='%h'` 2>/dev/null || ( git log -n1 --pretty='%h' && echo -n "(`git branch --show-current`)" ) ) )
 
 WERROR = -Werror
-CFLAGS = -O3 -g -pipe -Wall -Wextra $(WERROR)
+CFLAGS ?= -O3 -g -pipe -Wall -Wextra $(WERROR)
 
 S2CFLAGS := $(CFLAGS) -Os
 
@@ -120,7 +120,7 @@ ifeq ($(TARGET), uefi32)
 		-fpie
 endif
 
-LDFLAGS =
+LDFLAGS ?=
 
 INTERNAL_LDFLAGS := \
 	-nostdlib \
diff --git a/stage23/gensyms.sh b/stage23/gensyms.sh
index 01628ba3..b32c9433 100755
--- a/stage23/gensyms.sh
+++ b/stage23/gensyms.sh
@@ -2,7 +2,9 @@
 
 set -e
 
-./test_pipefail.sh && set -o pipefail
+SCRIPT_PATH="$(dirname $0)"
+
+"$SCRIPT_PATH/test_pipefail.sh" && set -o pipefail
 
 TMP1=$(mktemp)
 TMP2=$(mktemp)
tab: 248 wrap: offon