-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
136 lines (108 loc) · 3.79 KB
/
Makefile
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
##
## This file is part of the sortbootorder project.
##
## Copyright (C) 2008 Advanced Micro Devices, Inc.
## Copyright (C) 2016 PC Engines GmbH
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; version 2 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
# compilation for coreboot mainline (4.5,4.6) or legacy (4.0)
COREBOOT_REL ?= mainline
VERSION ?= $(shell git describe --tags --dirty)
src := $(CURDIR)
# Assuming src path payloads/external/sortbootorder/sortbootorder/ by default
KDIR ?= $(src)/../../../../
srctree := $(src)
build_dir := $(src)/build
export V := $(V)
CONFIG_SHELL := sh
UNAME_RELEASE := $(shell uname -r)
MAKEFLAGS += -rR --no-print-directory
# Make is silent per default, but 'make V=1' will show all compiler calls.
ifneq ($(V),1)
.SILENT:
endif
HOSTCC ?= gcc
HOSTCXX ?= g++
HOSTCFLAGS := -I$(src)
HOSTCXXFLAGS := -I$(src)
LIBPAYLOAD_PATH := $(realpath $(KDIR)/payloads/libpayload)
LIBPAYLOAD_OBJ := $(build_dir)/libpayload
HAVE_LIBPAYLOAD := $(wildcard $(LIBPAYLOAD_OBJ)/lib/libpayload.a)
LIBPAYLOAD_CONFIG ?= $(src)/defconfig-apu
OBJCOPY ?= objcopy
INCLUDES = -I$(src)/include -I$(KDIR)/src/commonlib/include
SRC_DIRS = spi utils
SRC_FILES = $(wildcard *.c)
SRC_FILES += $(wildcard spi/*.c)
SRC_FILES += $(wildcard utils/*.c)
OBJECTS = $(patsubst %.c,%.o,$(SRC_FILES))
OBJS = $(patsubst %,$(build_dir)/%,$(OBJECTS))
DIRS = $(patsubst %,$(build_dir)/%,$(SRC_DIRS))
TARGET = sortbootorder.elf
all: real-all
# in addition to the dependency below, create the file if it doesn't exist
# to silence warnings about a file that would be generated anyway.
$(if $(wildcard .xcompile),,$(eval $(shell $(KDIR)/util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
.xcompile: $(KDIR)/util/xcompile/xcompile
$< $(XGCCPATH) > [email protected]
\mv -f [email protected] $@ 2> /dev/null || rm -f [email protected] $@
CONFIG_COMPILER_GCC := y
ARCH-y := x86_32
include .xcompile
CC := $(CC_$(ARCH-y))
AS := $(AS_$(ARCH-y))
OBJCOPY := $(OBJCOPY_$(ARCH-y))
LPCC := CC="$(CC)" $(LIBPAYLOAD_OBJ)/bin/lpgcc
LPAS := AS="$(AS)" $(LIBPAYLOAD_OBJ)/bin/lpas
CFLAGS += -Wall -Werror -Os -fno-builtin $(CFLAGS_$(ARCH-y)) $(INCLUDES)
ifeq ($(COREBOOT_REL),legacy)
CFLAGS += -DCOREBOOT_LEGACY
endif
ifeq ($(SPI_DEBUG),1)
CFLAGS += -DSPI_DEBUG -DSPI_TRACE_ENABLED
endif
ifeq ($(APU1),y)
CFLAGS += -DTARGET_APU1
else
CFLAGS += -DFCH_YANGTZEE
endif
real-all: version $(TARGET)
version:
sed -e "s/@version@/\"$(lastword $(subst /, ,$(VERSION)))\"/" version.h.in > version.h
$(TARGET): $(OBJS) libpayload $(DIRS)
printf " LPCC $(subst $(CURDIR)/,,$(@)) (LINK)\n"
$(LPCC) -o $@ $(OBJS)
$(OBJCOPY) --only-keep-debug $@ $(TARGET).debug
$(OBJCOPY) --strip-debug $@
$(OBJCOPY) --add-gnu-debuglink=$(TARGET).debug $@
$(build_dir)/%.o: $(src)/%.c libpayload $(DIRS)
printf " LPCC $(subst $(CURDIR)/,,$(@))\n"
$(LPCC) $(CFLAGS) -c -o $@ $<
$(DIRS):
mkdir -p $(DIRS)
defaultbuild:
$(MAKE) all
ifneq ($(strip $(HAVE_LIBPAYLOAD)),)
libpayload:
printf "Found Libpayload $(LIBPAYLOAD_OBJ).\n"
else
LPOPTS=obj="$(CURDIR)/lpbuild" DOTCONFIG="$(CURDIR)/lp.config"
libpayload:
printf "Building libpayload @ $(LIBPAYLOAD_PATH).\n"
$(MAKE) -C $(LIBPAYLOAD_PATH) $(LPOPTS) distclean coreinfo_obj=$(build_dir)/libptmp
$(MAKE) -C $(LIBPAYLOAD_PATH) $(LPOPTS) defconfig KBUILD_DEFCONFIG=$(LIBPAYLOAD_CONFIG)
$(MAKE) -C $(LIBPAYLOAD_PATH) $(LPOPTS) install DESTDIR=$(build_dir)
endif
clean:
rm -rf *.elf *.elf.debug build/*.o .xcompile
distclean: clean
rm -rf build lpbuild lp.config*
.PHONY: clean distclean