blob: 6dd33e11974446af515dc5b7ca1b80dd3c86c6a2 [file] [log] [blame]
Patrick Georgib3db79e2011-04-21 18:48:50 +02001##
Patrick Georgib3db79e2011-04-21 18:48:50 +02002##
3## Copyright (C) 2008 Advanced Micro Devices, Inc.
4## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
5## Copyright (C) 2011 secunet Security Networks AG
6##
7## Redistribution and use in source and binary forms, with or without
8## modification, are permitted provided that the following conditions
9## are met:
10## 1. Redistributions of source code must retain the above copyright
11## notice, this list of conditions and the following disclaimer.
12## 2. Redistributions in binary form must reproduce the above copyright
13## notice, this list of conditions and the following disclaimer in the
14## documentation and/or other materials provided with the distribution.
15## 3. The name of the author may not be used to endorse or promote products
16## derived from this software without specific prior written permission.
17##
18## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28## SUCH DAMAGE.
29##
30
Nicholas Chincc8be37a2022-06-18 14:06:59 -060031ifneq ($(NOCOMPILE),1)
32GIT:=$(shell git -C "$(top)" rev-parse --git-dir 1>/dev/null 2>&1 \
33 && command -v git)
34else
35GIT:=
36endif
37
Patrick Georgib3db79e2011-04-21 18:48:50 +020038export KERNELVERSION := 0.2.0
39
Gabe Black51edd542013-09-30 23:00:33 -070040ARCHDIR-$(CONFIG_LP_ARCH_ARM) := arm
Furquan Shaikh8c8c3772014-02-19 11:35:30 -080041ARCHDIR-$(CONFIG_LP_ARCH_ARM64) := arm64
Gabe Black1ee2c6d2013-08-09 04:27:35 -070042ARCHDIR-$(CONFIG_LP_ARCH_X86) := x86
Jakub Czapiga3d91b472021-09-15 14:52:45 +020043ARCHDIR-$(CONFIG_LP_ARCH_MOCK) := mock
Tadas Slotkus09ea8ea2011-07-15 03:41:11 +030044DESTDIR ?= install
Patrick Georgib3db79e2011-04-21 18:48:50 +020045
46real-target: lib
47
Gabe Black1ee2c6d2013-08-09 04:27:35 -070048classes-$(CONFIG_LP_PCI) += libpci
49classes-$(CONFIG_LP_LIBC) += libc
50classes-$(CONFIG_LP_CURSES) += libcurses
51classes-$(CONFIG_LP_PDCURSES) += libmenu libform libpanel
52classes-$(CONFIG_LP_CBFS) += libcbfs
53classes-$(CONFIG_LP_LZMA) += liblzma
Julius Wernerbf273912015-06-30 10:30:30 -070054classes-$(CONFIG_LP_LZ4) += liblz4
Julius Werner50a81742014-05-15 11:57:38 -070055classes-$(CONFIG_LP_REMOTEGDB) += libgdb
Jakub Czapiga1fa3da42021-12-06 09:01:50 +000056classes-$(CONFIG_LP_VBOOT_LIB) += vboot_fw
57classes-$(CONFIG_LP_VBOOT_LIB) += tlcl
Patrick Georgib3db79e2011-04-21 18:48:50 +020058libraries := $(classes-y)
Patrick Georgib3db79e2011-04-21 18:48:50 +020059
Patrick Georgib3db79e2011-04-21 18:48:50 +020060subdirs-y := arch/$(ARCHDIR-y)
Julius Werner50a81742014-05-15 11:57:38 -070061subdirs-y += crypto libc drivers libpci gdb
Gabe Black1ee2c6d2013-08-09 04:27:35 -070062subdirs-$(CONFIG_LP_CURSES) += curses
63subdirs-$(CONFIG_LP_CBFS) += libcbfs
64subdirs-$(CONFIG_LP_LZMA) += liblzma
Julius Wernerbf273912015-06-30 10:30:30 -070065subdirs-$(CONFIG_LP_LZ4) += liblz4
Jakub Czapiga1fa3da42021-12-06 09:01:50 +000066subdirs-$(CONFIG_LP_VBOOT_LIB) += vboot
Patrick Georgib3db79e2011-04-21 18:48:50 +020067
Jacob Garberc98baa72020-11-04 21:49:49 -070068INCLUDES := -Iinclude -Iinclude/$(ARCHDIR-y) -I$(obj)
Julius Werner23d24652022-05-27 19:07:14 -070069INCLUDES += -include include/kconfig.h
70INCLUDES += -include $(coreboottop)/src/commonlib/bsd/include/commonlib/bsd/compiler.h
Jakub Czapiga39b2e7a2021-11-23 09:21:30 +000071INCLUDES += -I$(coreboottop)/src/commonlib/bsd/include
Maximilian Brunea99b5802023-09-16 19:56:45 +020072ifeq ($(CONFIG_LP_GPL),y)
73INCLUDES += -I$(coreboottop)/src/commonlib/include
74endif
Patrick Georgi49f0f9a2022-01-27 15:28:13 +010075INCLUDES += -I$(VBOOT_SOURCE)/firmware/include
Stefan Reinauer1b4d3942015-06-29 15:47:34 -070076
Jakub Czapigac35659d2021-08-26 14:35:10 +020077CFLAGS += $(INCLUDES) -Os -pipe -nostdinc -ggdb3
Stefan Reinauer08c41502013-05-21 14:45:28 -070078CFLAGS += -nostdlib -fno-builtin -ffreestanding -fomit-frame-pointer
Stefan Reinauere5595362015-07-01 11:30:03 -070079CFLAGS += -ffunction-sections -fdata-sections
Jacob Garber9cd53c52019-06-27 13:23:38 -060080CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wvla
Jacob Garber5f7b1162019-07-19 17:35:28 -060081CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs -Wimplicit-fallthrough
Vadim Bendebury19c3da52014-05-15 14:12:54 -070082CFLAGS += -Wstrict-aliasing -Wshadow -Werror
Patrick Georgib3db79e2011-04-21 18:48:50 +020083
Jacob Garber04540f12019-10-02 18:55:07 -060084ifeq ($(CONFIG_LP_LTO),y)
85CFLAGS += -flto
86endif
87
Nicholas Chincc8be37a2022-06-18 14:06:59 -060088# Some of the commonlib cbfs headers include vboot headers, so initialize the
89# submodule in case we are building a payload outside the main coreboot build
90forgetthis:=$(if $(GIT),$(shell git submodule update --init ../../3rdparty/vboot $(quiet_errors)))
91
Nico Huber1dba2ed2020-11-14 23:46:10 +010092$(obj)/libpayload.config: $(DOTCONFIG)
93 cp $< $@
94
95$(obj)/libpayload-config.h: $(KCONFIG_AUTOHEADER) $(obj)/libpayload.config
Patrick Georgib3db79e2011-04-21 18:48:50 +020096 cmp $@ $< 2>/dev/null || cp $< $@
97
98library-targets = $(addsuffix .a,$(addprefix $(obj)/,$(libraries))) $(obj)/libpayload.a
Subrata Banikafa39102024-05-18 12:26:40 +000099lib: $$(library-targets) $(obj)/libpayload.ldscript
Patrick Georgib3db79e2011-04-21 18:48:50 +0200100
Patrick Georgi3b77b722011-07-07 15:41:53 +0200101extract_nth=$(word $(1), $(subst |, ,$(2)))
102
103#######################################################################
Martin Roth6116f362016-03-08 12:32:40 -0700104# Add handler for special include files
Patrick Georgi3b77b722011-07-07 15:41:53 +0200105$(call add-special-class,includes)
106includes-handler= \
107 $(if $(wildcard $(1)$(call extract_nth,1,$(2))), \
108 $(eval includes += $(1)$(2)))
109
Patrick Georgib3db79e2011-04-21 18:48:50 +0200110$(obj)/libpayload.a: $(foreach class,$(libraries),$$($(class)-objs))
Martin Roth6116f362016-03-08 12:32:40 -0700111 printf " AR $(subst $(CURDIR)/,,$(@))\n"
Jakub Czapiga28a97a22022-01-18 14:22:22 +0000112 printf "create $@\n$(foreach objc,$(filter-out %.a,$^),addmod $(objc)\n)$(foreach lib,$(filter %.a,$^),addlib $(lib)\n)save\nend\n" | $(AR) -M
Patrick Georgib3db79e2011-04-21 18:48:50 +0200113
114$(obj)/%.a: $$(%-objs)
Martin Roth6116f362016-03-08 12:32:40 -0700115 printf " AR $(subst $(CURDIR)/,,$(@))\n"
Jakub Czapiga28a97a22022-01-18 14:22:22 +0000116 printf "create $@\n$(foreach objc,$(filter-out %.a,$^),addmod $(objc)\n)$(foreach lib,$(filter %.a,$^),addlib $(lib)\n)save\nend\n" | $(AR) -M
Patrick Georgib3db79e2011-04-21 18:48:50 +0200117
Subrata Banik93ca6b62024-05-28 18:16:02 +0000118$(obj)/libpayload.ldscript: arch/$(ARCHDIR-y)/libpayload.ldscript $(obj)/libpayload-config.h
Subrata Banikafa39102024-05-18 12:26:40 +0000119 @printf " LDSCRIPT $@\n"
120 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -E -P -x assembler-with-cpp -undef -o $@ $<
121
Patrick Georgib3db79e2011-04-21 18:48:50 +0200122install: real-target
123 printf " INSTALL $(DESTDIR)/libpayload/lib\n"
124 install -m 755 -d $(DESTDIR)/libpayload/lib
Patrick Georgiee53dfd02021-12-08 15:48:25 +0100125 install -m 644 $(library-targets) $(DESTDIR)/libpayload/lib/
Subrata Banikafa39102024-05-18 12:26:40 +0000126 install -m 644 $(obj)/libpayload.ldscript $(DESTDIR)/libpayload/lib/
Patrick Georgib3db79e2011-04-21 18:48:50 +0200127 install -m 755 -d $(DESTDIR)/libpayload/lib/$(ARCHDIR-y)
Patrick Georgib3db79e2011-04-21 18:48:50 +0200128 printf " INSTALL $(DESTDIR)/libpayload/include\n"
129 install -m 755 -d $(DESTDIR)/libpayload/include
Patrick Georgiee53dfd02021-12-08 15:48:25 +0100130 find include -type d -exec install -m755 -d $(DESTDIR)/libpayload/{} \;
131 find include -type f -exec install -m644 {} $(DESTDIR)/libpayload/{} \;
Nico Huberd0437812024-01-11 23:09:37 +0100132 cd $(coreboottop)/src/commonlib/bsd && find include -type d -exec install -m755 -d $(abspath $(DESTDIR))/libpayload/{} \;
133 cd $(coreboottop)/src/commonlib/bsd && find include -type f -exec install -m644 {} $(abspath $(DESTDIR))/libpayload/{} \;
Julius Wernerc00c1402024-03-15 14:08:14 -0700134ifeq ($(CONFIG_LP_GPL),y)
135 cd $(coreboottop)/src/commonlib && find include -type d -exec install -m755 -d $(abspath $(DESTDIR))/libpayload/{} \;
136 cd $(coreboottop)/src/commonlib && find include -type f -exec install -m644 {} $(abspath $(DESTDIR))/libpayload/{} \;
137endif
Patrick Georgib3db79e2011-04-21 18:48:50 +0200138 install -m 644 $(obj)/libpayload-config.h $(DESTDIR)/libpayload/include
Patrick Georgi3b77b722011-07-07 15:41:53 +0200139 $(foreach item,$(includes), \
140 install -m 755 -d $(DESTDIR)/libpayload/include/$(call extract_nth,2,$(item)); \
141 install -m 644 $(call extract_nth,1,$(item)) $(DESTDIR)/libpayload/include/$(call extract_nth,2,$(item)); )
Jakub Czapiga395f5b32022-01-12 09:59:39 +0000142 printf " INSTALL $(DESTDIR)/libpayload/vboot\n"
143 install -m 755 -d $(DESTDIR)/libpayload/vboot
144 for file in `find $(VBOOT_SOURCE)/firmware/include \
145 $(VBOOT_SOURCE)/firmware/2lib/include \
146 -iname '*.h' -type f \
147 | sed 's,$(VBOOT_SOURCE)/firmware/,,'`; do \
148 install -m 755 -d $(DESTDIR)/libpayload/vboot/$$(dirname $$file); \
149 install -m 644 $(VBOOT_SOURCE)/firmware/$$file $(DESTDIR)/libpayload/vboot/$$file ; \
150 done
Patrick Georgib3db79e2011-04-21 18:48:50 +0200151 printf " INSTALL $(DESTDIR)/libpayload/bin\n"
152 install -m 755 -d $(DESTDIR)/libpayload/bin
153 install -m 755 bin/lpgcc $(DESTDIR)/libpayload/bin
154 install -m 755 bin/lpas $(DESTDIR)/libpayload/bin
155 install -m 644 bin/lp.functions $(DESTDIR)/libpayload/bin
Stefan Reinauer658e4d32013-01-17 12:29:51 -0800156 install -m 644 $(DOTCONFIG) $(DESTDIR)/libpayload/libpayload.config
Nico Huber1823d532020-11-16 22:50:49 +0100157 install -m 755 $(xcompile) $(DESTDIR)/libpayload/libpayload.xcompile
Patrick Georgib3db79e2011-04-21 18:48:50 +0200158
159clean-for-update-target:
160 rm -f $(addsuffix .a,$(addprefix $(obj)/,$(libraries))) $(obj)/libpayload.a
161
162clean-target:
163prepare:
Patrick Georgi34286b82013-12-21 21:08:53 +0100164
165junit.xml:
166 echo '<?xml version="1.0" encoding="utf-8"?><testsuite>' > $@.tmp
Jakub Czapiga12ae8502021-10-08 09:57:14 +0000167 for i in $(filter-out %.old %.unit-tests,$(wildcard configs/*)); do \
Patrick Georgi34286b82013-12-21 21:08:53 +0100168 $(MAKE) clean; \
Keith Short31af70d2019-07-11 17:54:57 -0600169 echo "Building libpayload for $$i"; \
Martin Roth6959f5c2016-03-23 16:07:54 -0600170 cp "$$i" junit_config; \
171 $(MAKE) olddefconfig DOTCONFIG=junit_config V=$(V) Q=$(Q) 2>/dev/null >/dev/null; \
Patrick Georgi34286b82013-12-21 21:08:53 +0100172 echo "<testcase classname='libpayload' name='$$i'>" >> $@.tmp; \
Martin Roth6959f5c2016-03-23 16:07:54 -0600173 $(MAKE) V=$(V) Q=$(Q) CONFIG_LP_CCACHE=$(CONFIG_LP_CCACHE) DOTCONFIG=junit_config >> $@.tmp.2 2>&1 && type="system-out" || type="failure"; \
Patrick Georgi34286b82013-12-21 21:08:53 +0100174 if [ $$type = "failure" ]; then \
175 echo "<failure type='buildFailed'>" >> $@.tmp; \
176 else \
177 echo "<$$type>" >> $@.tmp; \
178 fi; \
179 echo '<![CDATA[' >> $@.tmp; \
180 cat $@.tmp.2 >> $@.tmp; \
181 echo "]]></$$type>" >>$@.tmp; \
182 rm -f $@.tmp.2; \
183 echo "</testcase>" >> $@.tmp; \
184 done
185 echo "</testsuite>" >> $@.tmp
Keith Short31af70d2019-07-11 17:54:57 -0600186 echo "libpayload build complete, test results in $@"
Patrick Georgi34286b82013-12-21 21:08:53 +0100187 mv $@.tmp $@
Martin Roth6c9c1962017-08-03 09:25:43 -0600188
189test-configs:
Jakub Czapiga12ae8502021-10-08 09:57:14 +0000190 for config in $(filter-out %.old %.unit-tests,$(wildcard configs/*)); do \
Martin Roth6c9c1962017-08-03 09:25:43 -0600191 $(MAKE) clean; \
192 cp "$$config" test_config; \
193 echo "*** Making libpayload config $$config ***"; \
194 $(MAKE) olddefconfig DOTCONFIG=test_config V=$(V) Q=$(Q) ; \
195 $(MAKE) V=$(V) Q=$(Q) CONFIG_LP_CCACHE=$(CONFIG_LP_CCACHE) DOTCONFIG=test_config; \
196 done