Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 1 | ## |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 2 | ## |
| 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 Chin | cc8be37a | 2022-06-18 14:06:59 -0600 | [diff] [blame] | 31 | ifneq ($(NOCOMPILE),1) |
| 32 | GIT:=$(shell git -C "$(top)" rev-parse --git-dir 1>/dev/null 2>&1 \ |
| 33 | && command -v git) |
| 34 | else |
| 35 | GIT:= |
| 36 | endif |
| 37 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 38 | export KERNELVERSION := 0.2.0 |
| 39 | |
Gabe Black | 51edd54 | 2013-09-30 23:00:33 -0700 | [diff] [blame] | 40 | ARCHDIR-$(CONFIG_LP_ARCH_ARM) := arm |
Furquan Shaikh | 8c8c377 | 2014-02-19 11:35:30 -0800 | [diff] [blame] | 41 | ARCHDIR-$(CONFIG_LP_ARCH_ARM64) := arm64 |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 42 | ARCHDIR-$(CONFIG_LP_ARCH_X86) := x86 |
Jakub Czapiga | 3d91b47 | 2021-09-15 14:52:45 +0200 | [diff] [blame] | 43 | ARCHDIR-$(CONFIG_LP_ARCH_MOCK) := mock |
Tadas Slotkus | 09ea8ea | 2011-07-15 03:41:11 +0300 | [diff] [blame] | 44 | DESTDIR ?= install |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 45 | |
| 46 | real-target: lib |
| 47 | |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 48 | classes-$(CONFIG_LP_PCI) += libpci |
| 49 | classes-$(CONFIG_LP_LIBC) += libc |
| 50 | classes-$(CONFIG_LP_CURSES) += libcurses |
| 51 | classes-$(CONFIG_LP_PDCURSES) += libmenu libform libpanel |
| 52 | classes-$(CONFIG_LP_CBFS) += libcbfs |
| 53 | classes-$(CONFIG_LP_LZMA) += liblzma |
Julius Werner | bf27391 | 2015-06-30 10:30:30 -0700 | [diff] [blame] | 54 | classes-$(CONFIG_LP_LZ4) += liblz4 |
Julius Werner | 50a8174 | 2014-05-15 11:57:38 -0700 | [diff] [blame] | 55 | classes-$(CONFIG_LP_REMOTEGDB) += libgdb |
Jakub Czapiga | 1fa3da4 | 2021-12-06 09:01:50 +0000 | [diff] [blame] | 56 | classes-$(CONFIG_LP_VBOOT_LIB) += vboot_fw |
| 57 | classes-$(CONFIG_LP_VBOOT_LIB) += tlcl |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 58 | libraries := $(classes-y) |
| 59 | classes-y += head.o |
| 60 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 61 | subdirs-y := arch/$(ARCHDIR-y) |
Julius Werner | 50a8174 | 2014-05-15 11:57:38 -0700 | [diff] [blame] | 62 | subdirs-y += crypto libc drivers libpci gdb |
Gabe Black | 1ee2c6d | 2013-08-09 04:27:35 -0700 | [diff] [blame] | 63 | subdirs-$(CONFIG_LP_CURSES) += curses |
| 64 | subdirs-$(CONFIG_LP_CBFS) += libcbfs |
| 65 | subdirs-$(CONFIG_LP_LZMA) += liblzma |
Julius Werner | bf27391 | 2015-06-30 10:30:30 -0700 | [diff] [blame] | 66 | subdirs-$(CONFIG_LP_LZ4) += liblz4 |
Jakub Czapiga | 1fa3da4 | 2021-12-06 09:01:50 +0000 | [diff] [blame] | 67 | subdirs-$(CONFIG_LP_VBOOT_LIB) += vboot |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 68 | |
Jacob Garber | c98baa7 | 2020-11-04 21:49:49 -0700 | [diff] [blame] | 69 | INCLUDES := -Iinclude -Iinclude/$(ARCHDIR-y) -I$(obj) |
Julius Werner | 23d2465 | 2022-05-27 19:07:14 -0700 | [diff] [blame] | 70 | INCLUDES += -include include/kconfig.h |
| 71 | INCLUDES += -include $(coreboottop)/src/commonlib/bsd/include/commonlib/bsd/compiler.h |
Jakub Czapiga | 39b2e7a | 2021-11-23 09:21:30 +0000 | [diff] [blame] | 72 | INCLUDES += -I$(coreboottop)/src/commonlib/bsd/include |
Patrick Georgi | 49f0f9a | 2022-01-27 15:28:13 +0100 | [diff] [blame] | 73 | INCLUDES += -I$(VBOOT_SOURCE)/firmware/include |
Stefan Reinauer | 1b4d394 | 2015-06-29 15:47:34 -0700 | [diff] [blame] | 74 | |
Jakub Czapiga | c35659d | 2021-08-26 14:35:10 +0200 | [diff] [blame] | 75 | CFLAGS += $(INCLUDES) -Os -pipe -nostdinc -ggdb3 |
Stefan Reinauer | 08c4150 | 2013-05-21 14:45:28 -0700 | [diff] [blame] | 76 | CFLAGS += -nostdlib -fno-builtin -ffreestanding -fomit-frame-pointer |
Stefan Reinauer | e559536 | 2015-07-01 11:30:03 -0700 | [diff] [blame] | 77 | CFLAGS += -ffunction-sections -fdata-sections |
Jacob Garber | 9cd53c5 | 2019-06-27 13:23:38 -0600 | [diff] [blame] | 78 | CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wvla |
Jacob Garber | 5f7b116 | 2019-07-19 17:35:28 -0600 | [diff] [blame] | 79 | CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs -Wimplicit-fallthrough |
Vadim Bendebury | 19c3da5 | 2014-05-15 14:12:54 -0700 | [diff] [blame] | 80 | CFLAGS += -Wstrict-aliasing -Wshadow -Werror |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 81 | |
Jacob Garber | 04540f1 | 2019-10-02 18:55:07 -0600 | [diff] [blame] | 82 | ifeq ($(CONFIG_LP_LTO),y) |
| 83 | CFLAGS += -flto |
| 84 | endif |
| 85 | |
Nicholas Chin | cc8be37a | 2022-06-18 14:06:59 -0600 | [diff] [blame] | 86 | # Some of the commonlib cbfs headers include vboot headers, so initialize the |
| 87 | # submodule in case we are building a payload outside the main coreboot build |
| 88 | forgetthis:=$(if $(GIT),$(shell git submodule update --init ../../3rdparty/vboot $(quiet_errors))) |
| 89 | |
Nico Huber | 1dba2ed | 2020-11-14 23:46:10 +0100 | [diff] [blame] | 90 | $(obj)/libpayload.config: $(DOTCONFIG) |
| 91 | cp $< $@ |
| 92 | |
| 93 | $(obj)/libpayload-config.h: $(KCONFIG_AUTOHEADER) $(obj)/libpayload.config |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 94 | cmp $@ $< 2>/dev/null || cp $< $@ |
| 95 | |
| 96 | library-targets = $(addsuffix .a,$(addprefix $(obj)/,$(libraries))) $(obj)/libpayload.a |
| 97 | lib: $$(library-targets) $(obj)/head.o |
| 98 | |
Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 99 | extract_nth=$(word $(1), $(subst |, ,$(2))) |
| 100 | |
| 101 | ####################################################################### |
Martin Roth | 6116f36 | 2016-03-08 12:32:40 -0700 | [diff] [blame] | 102 | # Add handler for special include files |
Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 103 | $(call add-special-class,includes) |
| 104 | includes-handler= \ |
| 105 | $(if $(wildcard $(1)$(call extract_nth,1,$(2))), \ |
| 106 | $(eval includes += $(1)$(2))) |
| 107 | |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 108 | $(obj)/libpayload.a: $(foreach class,$(libraries),$$($(class)-objs)) |
Martin Roth | 6116f36 | 2016-03-08 12:32:40 -0700 | [diff] [blame] | 109 | printf " AR $(subst $(CURDIR)/,,$(@))\n" |
Jakub Czapiga | 28a97a2 | 2022-01-18 14:22:22 +0000 | [diff] [blame] | 110 | printf "create $@\n$(foreach objc,$(filter-out %.a,$^),addmod $(objc)\n)$(foreach lib,$(filter %.a,$^),addlib $(lib)\n)save\nend\n" | $(AR) -M |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 111 | |
| 112 | $(obj)/%.a: $$(%-objs) |
Martin Roth | 6116f36 | 2016-03-08 12:32:40 -0700 | [diff] [blame] | 113 | printf " AR $(subst $(CURDIR)/,,$(@))\n" |
Jakub Czapiga | 28a97a2 | 2022-01-18 14:22:22 +0000 | [diff] [blame] | 114 | printf "create $@\n$(foreach objc,$(filter-out %.a,$^),addmod $(objc)\n)$(foreach lib,$(filter %.a,$^),addlib $(lib)\n)save\nend\n" | $(AR) -M |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 115 | |
| 116 | $(obj)/head.o: $(obj)/arch/$(ARCHDIR-y)/head.head.o.o |
Martin Roth | 6116f36 | 2016-03-08 12:32:40 -0700 | [diff] [blame] | 117 | printf " CP $(subst $(CURDIR)/,,$(@))\n" |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 118 | cp $^ $@ |
| 119 | |
| 120 | install: real-target |
| 121 | printf " INSTALL $(DESTDIR)/libpayload/lib\n" |
| 122 | install -m 755 -d $(DESTDIR)/libpayload/lib |
| 123 | for lib in $(library-targets); do \ |
| 124 | install -m 644 $$lib $(DESTDIR)/libpayload/lib/; \ |
| 125 | done |
Ronald G. Minnich | c2e8cf5 | 2013-02-14 11:32:29 -0800 | [diff] [blame] | 126 | install -m 644 arch/$(ARCHDIR-y)/libpayload.ldscript $(DESTDIR)/libpayload/lib/ |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 127 | install -m 755 -d $(DESTDIR)/libpayload/lib/$(ARCHDIR-y) |
| 128 | install -m 644 $(obj)/head.o $(DESTDIR)/libpayload/lib/$(ARCHDIR-y) |
| 129 | printf " INSTALL $(DESTDIR)/libpayload/include\n" |
| 130 | install -m 755 -d $(DESTDIR)/libpayload/include |
| 131 | for file in `find include -name *.h -type f`; do \ |
| 132 | install -m 755 -d $(DESTDIR)/libpayload/`dirname $$file`; \ |
| 133 | install -m 644 $$file $(DESTDIR)/libpayload/$$file; \ |
| 134 | done |
Jakub Czapiga | 0b25e00 | 2021-12-06 13:03:56 +0000 | [diff] [blame] | 135 | for file in `find $(coreboottop)/src/commonlib/bsd/include -name *.h -type f`; do \ |
| 136 | dest_file=$$(realpath --relative-to=$(coreboottop)/src/commonlib/bsd/ $$file); \ |
| 137 | install -m 755 -d "$(DESTDIR)/libpayload/`dirname $$dest_file`"; \ |
| 138 | install -m 644 "$$file" "$(DESTDIR)/libpayload/$$dest_file"; \ |
| 139 | done |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 140 | install -m 644 $(obj)/libpayload-config.h $(DESTDIR)/libpayload/include |
Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 141 | $(foreach item,$(includes), \ |
| 142 | install -m 755 -d $(DESTDIR)/libpayload/include/$(call extract_nth,2,$(item)); \ |
| 143 | install -m 644 $(call extract_nth,1,$(item)) $(DESTDIR)/libpayload/include/$(call extract_nth,2,$(item)); ) |
Jakub Czapiga | 395f5b3 | 2022-01-12 09:59:39 +0000 | [diff] [blame] | 144 | printf " INSTALL $(DESTDIR)/libpayload/vboot\n" |
| 145 | install -m 755 -d $(DESTDIR)/libpayload/vboot |
| 146 | for file in `find $(VBOOT_SOURCE)/firmware/include \ |
| 147 | $(VBOOT_SOURCE)/firmware/2lib/include \ |
| 148 | -iname '*.h' -type f \ |
| 149 | | sed 's,$(VBOOT_SOURCE)/firmware/,,'`; do \ |
| 150 | install -m 755 -d $(DESTDIR)/libpayload/vboot/$$(dirname $$file); \ |
| 151 | install -m 644 $(VBOOT_SOURCE)/firmware/$$file $(DESTDIR)/libpayload/vboot/$$file ; \ |
| 152 | done |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 153 | printf " INSTALL $(DESTDIR)/libpayload/bin\n" |
| 154 | install -m 755 -d $(DESTDIR)/libpayload/bin |
| 155 | install -m 755 bin/lpgcc $(DESTDIR)/libpayload/bin |
| 156 | install -m 755 bin/lpas $(DESTDIR)/libpayload/bin |
| 157 | install -m 644 bin/lp.functions $(DESTDIR)/libpayload/bin |
Stefan Reinauer | 658e4d3 | 2013-01-17 12:29:51 -0800 | [diff] [blame] | 158 | install -m 644 $(DOTCONFIG) $(DESTDIR)/libpayload/libpayload.config |
Nico Huber | 1823d53 | 2020-11-16 22:50:49 +0100 | [diff] [blame] | 159 | install -m 755 $(xcompile) $(DESTDIR)/libpayload/libpayload.xcompile |
Patrick Georgi | b3db79e | 2011-04-21 18:48:50 +0200 | [diff] [blame] | 160 | |
| 161 | clean-for-update-target: |
| 162 | rm -f $(addsuffix .a,$(addprefix $(obj)/,$(libraries))) $(obj)/libpayload.a |
| 163 | |
| 164 | clean-target: |
| 165 | prepare: |
Patrick Georgi | 34286b8 | 2013-12-21 21:08:53 +0100 | [diff] [blame] | 166 | |
| 167 | junit.xml: |
| 168 | echo '<?xml version="1.0" encoding="utf-8"?><testsuite>' > $@.tmp |
Jakub Czapiga | 12ae850 | 2021-10-08 09:57:14 +0000 | [diff] [blame] | 169 | for i in $(filter-out %.old %.unit-tests,$(wildcard configs/*)); do \ |
Patrick Georgi | 34286b8 | 2013-12-21 21:08:53 +0100 | [diff] [blame] | 170 | $(MAKE) clean; \ |
Keith Short | 31af70d | 2019-07-11 17:54:57 -0600 | [diff] [blame] | 171 | echo "Building libpayload for $$i"; \ |
Martin Roth | 6959f5c | 2016-03-23 16:07:54 -0600 | [diff] [blame] | 172 | cp "$$i" junit_config; \ |
| 173 | $(MAKE) olddefconfig DOTCONFIG=junit_config V=$(V) Q=$(Q) 2>/dev/null >/dev/null; \ |
Patrick Georgi | 34286b8 | 2013-12-21 21:08:53 +0100 | [diff] [blame] | 174 | echo "<testcase classname='libpayload' name='$$i'>" >> $@.tmp; \ |
Martin Roth | 6959f5c | 2016-03-23 16:07:54 -0600 | [diff] [blame] | 175 | $(MAKE) V=$(V) Q=$(Q) CONFIG_LP_CCACHE=$(CONFIG_LP_CCACHE) DOTCONFIG=junit_config >> $@.tmp.2 2>&1 && type="system-out" || type="failure"; \ |
Patrick Georgi | 34286b8 | 2013-12-21 21:08:53 +0100 | [diff] [blame] | 176 | if [ $$type = "failure" ]; then \ |
| 177 | echo "<failure type='buildFailed'>" >> $@.tmp; \ |
| 178 | else \ |
| 179 | echo "<$$type>" >> $@.tmp; \ |
| 180 | fi; \ |
| 181 | echo '<![CDATA[' >> $@.tmp; \ |
| 182 | cat $@.tmp.2 >> $@.tmp; \ |
| 183 | echo "]]></$$type>" >>$@.tmp; \ |
| 184 | rm -f $@.tmp.2; \ |
| 185 | echo "</testcase>" >> $@.tmp; \ |
| 186 | done |
| 187 | echo "</testsuite>" >> $@.tmp |
Keith Short | 31af70d | 2019-07-11 17:54:57 -0600 | [diff] [blame] | 188 | echo "libpayload build complete, test results in $@" |
Patrick Georgi | 34286b8 | 2013-12-21 21:08:53 +0100 | [diff] [blame] | 189 | mv $@.tmp $@ |
Martin Roth | 6c9c196 | 2017-08-03 09:25:43 -0600 | [diff] [blame] | 190 | |
| 191 | test-configs: |
Jakub Czapiga | 12ae850 | 2021-10-08 09:57:14 +0000 | [diff] [blame] | 192 | for config in $(filter-out %.old %.unit-tests,$(wildcard configs/*)); do \ |
Martin Roth | 6c9c196 | 2017-08-03 09:25:43 -0600 | [diff] [blame] | 193 | $(MAKE) clean; \ |
| 194 | cp "$$config" test_config; \ |
| 195 | echo "*** Making libpayload config $$config ***"; \ |
| 196 | $(MAKE) olddefconfig DOTCONFIG=test_config V=$(V) Q=$(Q) ; \ |
| 197 | $(MAKE) V=$(V) Q=$(Q) CONFIG_LP_CCACHE=$(CONFIG_LP_CCACHE) DOTCONFIG=test_config; \ |
| 198 | done |