/
toolchain.mk
90 lines (76 loc) · 1.93 KB
/
toolchain.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
PREFIX=x86_64-linux-gnu-
NPROC=1
CLANG_BIN?=$(dir $(shell which clang))
CLANG_BIN?=/usr/bin
ifeq ($(OS),Windows_NT)
PREFIX=x86_64-w64-mingw32-
else
UNAME_S=$(shell uname -s)
ifeq ($(UNAME_S),Darwin)
PREFIX=x86_64-elf-
CLANG_BIN=/usr/local/opt/llvm/bin
NPROC=$(shell sysctl -n hw.ncpu)
else
NPROC=$(shell grep -c ^processor /proc/cpuinfo)
endif
endif
ifneq ($(PARALLEL),0)
MAKEFLAGS += "-j $(NPROC)"
endif
ifeq ($(VERBOSE),1)
Q=
QECHO=@ true
else
Q=@
QECHO=@ echo
endif
ifeq ($(wildcard $(CLANG_BIN)/clang),)
$(error CLANG not found in $(CLANG_BIN), make sure that it is installed and set CLANG_BIN environment variable)
endif
CC=$(CLANG_BIN)/clang --target=x86_64-none-elf
LD=$(CLANG_BIN)/ld.lld
AR=$(CLANG_BIN)/llvm-ar
OBJCOPY=$(PREFIX)objcopy
STRIP=$(PREFIX)strip
CLANG_VER=$(shell $(CLANG_BIN)/clang -v 2>&1 | head -n1 | perl -p -e 's/.*clang version (\d+)(\.\d+)*.*/$$1/g')
CLANG_5_GT=$(shell [ $(CLANG_VER) -gt 4 ] && echo true)
ifneq ($(CLANG_5_GT),true)
$(error CLANG v$(CLANG_VER) is not supported, use v5 or later)
endif
ifeq ($(UNAME_S),Darwin)
OBJCOPY=gobjcopy
endif
QEMU=qemu-system-x86_64
ifneq ($(shell which cpplint),)
LINT=$(shell which cpplint) --quiet
else
LINT=@ sh -c "echo No lint found"; true
endif
ifneq ($(shell which xorriso),)
MKISO := $(shell which xorriso) -as mkisofs
else
ifneq ($(shell which mkisofs),)
MKISO := $(shell which mkisofs)
else
ifneq ($(shell which genisoimage),)
MKISO := $(shell which genisoimage)
else
MKISO=@ sh -c "echo Neither xorriso nor mkisofs nor genisoimage was found"; false
endif
endif
endif
ifneq ($(shell which mformat),)
MKFAT := $(shell which mformat)
else
MKFAT := @ sh -c "echo mformat not found"; false
endif
ifneq ($(shell which mcopy),)
MCOPY := $(shell which mcopy)
else
MCOPY := @ sh -c "echo mcopy not found"; false
endif
ifneq ($(shell which mmd),)
MMD := $(shell which mmd)
else
MMD := @ sh -c "echo mmd not found"; false
endif