Skip to content

Commit 7a5daf2

Browse files
committed
Miscellaneous makefile improvements
1 parent 3f65e95 commit 7a5daf2

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

GNUmakefile

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ override OUTPUT := csmwrap
99
# Target architecture to build for. Default to x86_64.
1010
ARCH := x86_64
1111

12+
# Install prefix; /usr/local is a good, standard default pick.
13+
PREFIX := /usr/local
14+
1215
# Check if the architecture is supported.
1316
ifeq ($(filter $(ARCH),ia32 x86_64),)
1417
$(error Architecture $(ARCH) not supported)
@@ -17,28 +20,39 @@ endif
1720
# Default user QEMU flags. These are appended to the QEMU command calls.
1821
QEMUFLAGS := -m 2G
1922

20-
# User controllable cross compiler prefix.
21-
CROSS_COMPILE :=
22-
CROSS_PREFIX := $(CROSS_COMPILE)
23+
# User controllable toolchain and toolchain prefix.
24+
TOOLCHAIN :=
25+
TOOLCHAIN_PREFIX :=
26+
ifneq ($(TOOLCHAIN),)
27+
ifeq ($(TOOLCHAIN_PREFIX),)
28+
TOOLCHAIN_PREFIX := $(TOOLCHAIN)-
29+
endif
30+
endif
2331

2432
# User controllable C compiler command.
25-
ifneq ($(CROSS_PREFIX),)
26-
CC := $(CROSS_PREFIX)gcc
33+
ifneq ($(TOOLCHAIN_PREFIX),)
34+
CC := $(TOOLCHAIN_PREFIX)gcc
2735
else
2836
CC := cc
2937
endif
3038

3139
# User controllable linker command.
32-
LD := $(CROSS_PREFIX)ld
40+
LD := $(TOOLCHAIN_PREFIX)ld
3341

3442
# User controllable objcopy command.
35-
OBJCOPY := $(CROSS_PREFIX)objcopy
43+
OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
3644

3745
# User controllable objdump command.
38-
OBJDUMP := $(CROSS_PREFIX)objdump
46+
OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
3947

4048
# User controllable strip command.
41-
STRIP := $(CROSS_PREFIX)strip
49+
STRIP := $(TOOLCHAIN_PREFIX)strip
50+
51+
# Defaults overrides for variables if using "llvm" as toolchain.
52+
ifeq ($(TOOLCHAIN),llvm)
53+
CC := clang
54+
LD := ld.lld
55+
endif
4256

4357
# User controllable C flags.
4458
CFLAGS := -g -O2 -pipe
@@ -56,7 +70,7 @@ LDFLAGS :=
5670
BUILD_VERSION := $(shell git describe --tags --always 2>/dev/null || echo "Unknown")
5771

5872
# Check if CC is Clang.
59-
override CC_IS_CLANG := $(shell ! $(CC) --version 2>/dev/null | grep 'clang' >/dev/null 2>&1; echo $$?)
73+
override CC_IS_CLANG := $(shell ! $(CC) --version 2>/dev/null | grep -q '^Target: '; echo $$?)
6074

6175
# Save user CFLAGS, CPPFLAGS, and LDFLAGS before we append internal flags.
6276
override USER_CFLAGS := $(CFLAGS)
@@ -98,7 +112,7 @@ override NASMFLAGS += \
98112
ifeq ($(ARCH),ia32)
99113
ifeq ($(CC_IS_CLANG),1)
100114
override CC += \
101-
-target i686-unknown-none
115+
-target i686-unknown-none-elf
102116
endif
103117
override CFLAGS += \
104118
-m32 \
@@ -114,7 +128,7 @@ endif
114128
ifeq ($(ARCH),x86_64)
115129
ifeq ($(CC_IS_CLANG),1)
116130
override CC += \
117-
-target x86_64-unknown-none
131+
-target x86_64-unknown-none-elf
118132
endif
119133
override CFLAGS += \
120134
-m64 \
@@ -137,12 +151,12 @@ override LDFLAGS += \
137151
-pie \
138152
-z text \
139153
-z max-page-size=0x1000 \
140-
-gc-sections \
154+
--gc-sections \
141155
-T nyu-efi/$(ARCH)/link_script.lds
142156

143157
# Use "find" to glob all *.c, *.S, and *.asm{32,64} files in the tree and obtain the
144158
# object and header dependency file names.
145-
override SRCFILES := $(shell find -L src cc-runtime/src nyu-efi/$(ARCH) uACPI/source -type f | LC_ALL=C sort)
159+
override SRCFILES := $(shell find -L src cc-runtime/src nyu-efi/$(ARCH) uACPI/source -type f 2>/dev/null | LC_ALL=C sort)
146160
override CFILES := $(filter %.c,$(SRCFILES))
147161
override ASFILES := $(filter %.S,$(SRCFILES))
148162
ifeq ($(ARCH),ia32)
@@ -257,6 +271,18 @@ distclean: seabios/.config
257271
rm -rf src/bins
258272
rm -rf bin-* obj-* ovmf
259273

274+
# Install the final built executable to its final on-root location.
275+
.PHONY: install
276+
install: all
277+
install -d "$(DESTDIR)$(PREFIX)/share/$(OUTPUT)"
278+
install -m 644 bin-$(ARCH)/$(OUTPUT).efi "$(DESTDIR)$(PREFIX)/share/$(OUTPUT)/$(OUTPUT)-$(ARCH).efi"
279+
280+
# Try to undo whatever the "install" target did.
281+
.PHONY: uninstall
282+
uninstall:
283+
rm -f "$(DESTDIR)$(PREFIX)/share/$(OUTPUT)/$(OUTPUT)-$(ARCH).efi"
284+
-rmdir "$(DESTDIR)$(PREFIX)/share/$(OUTPUT)"
285+
260286
# SeaBIOS build targets.
261287
SEABIOS_EXTRAVERSION := -CSMWrap-$(BUILD_VERSION)
262288
.PHONY: seabios

0 commit comments

Comments
 (0)