blob: 8e0a3d6f7758137168939dceaae16e779316d4d3 [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
31export KERNELVERSION := 0.2.0
32
Gabe Black51edd542013-09-30 23:00:33 -070033ARCHDIR-$(CONFIG_LP_ARCH_ARM) := arm
Furquan Shaikh8c8c3772014-02-19 11:35:30 -080034ARCHDIR-$(CONFIG_LP_ARCH_ARM64) := arm64
Gabe Black1ee2c6d2013-08-09 04:27:35 -070035ARCHDIR-$(CONFIG_LP_ARCH_X86) := x86
Jakub Czapiga3d91b472021-09-15 14:52:45 +020036ARCHDIR-$(CONFIG_LP_ARCH_MOCK) := mock
Tadas Slotkus09ea8ea2011-07-15 03:41:11 +030037DESTDIR ?= install
Patrick Georgib3db79e2011-04-21 18:48:50 +020038
39real-target: lib
40
Gabe Black1ee2c6d2013-08-09 04:27:35 -070041classes-$(CONFIG_LP_PCI) += libpci
42classes-$(CONFIG_LP_LIBC) += libc
43classes-$(CONFIG_LP_CURSES) += libcurses
44classes-$(CONFIG_LP_PDCURSES) += libmenu libform libpanel
45classes-$(CONFIG_LP_CBFS) += libcbfs
46classes-$(CONFIG_LP_LZMA) += liblzma
Julius Wernerbf273912015-06-30 10:30:30 -070047classes-$(CONFIG_LP_LZ4) += liblz4
Julius Werner50a81742014-05-15 11:57:38 -070048classes-$(CONFIG_LP_REMOTEGDB) += libgdb
Patrick Georgib3db79e2011-04-21 18:48:50 +020049libraries := $(classes-y)
50classes-y += head.o
51
Patrick Georgib3db79e2011-04-21 18:48:50 +020052subdirs-y := arch/$(ARCHDIR-y)
Julius Werner50a81742014-05-15 11:57:38 -070053subdirs-y += crypto libc drivers libpci gdb
Gabe Black1ee2c6d2013-08-09 04:27:35 -070054subdirs-$(CONFIG_LP_CURSES) += curses
55subdirs-$(CONFIG_LP_CBFS) += libcbfs
56subdirs-$(CONFIG_LP_LZMA) += liblzma
Julius Wernerbf273912015-06-30 10:30:30 -070057subdirs-$(CONFIG_LP_LZ4) += liblz4
Patrick Georgib3db79e2011-04-21 18:48:50 +020058
Jacob Garberc98baa72020-11-04 21:49:49 -070059INCLUDES := -Iinclude -Iinclude/$(ARCHDIR-y) -I$(obj)
60INCLUDES += -include include/kconfig.h -include include/compiler.h
Stefan Reinauer1b4d3942015-06-29 15:47:34 -070061
Jakub Czapigac35659d2021-08-26 14:35:10 +020062CFLAGS += $(INCLUDES) -Os -pipe -nostdinc -ggdb3
Stefan Reinauer08c41502013-05-21 14:45:28 -070063CFLAGS += -nostdlib -fno-builtin -ffreestanding -fomit-frame-pointer
Stefan Reinauere5595362015-07-01 11:30:03 -070064CFLAGS += -ffunction-sections -fdata-sections
Jacob Garber9cd53c52019-06-27 13:23:38 -060065CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wvla
Jacob Garber5f7b1162019-07-19 17:35:28 -060066CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs -Wimplicit-fallthrough
Vadim Bendebury19c3da52014-05-15 14:12:54 -070067CFLAGS += -Wstrict-aliasing -Wshadow -Werror
Patrick Georgib3db79e2011-04-21 18:48:50 +020068
Jacob Garber04540f12019-10-02 18:55:07 -060069ifeq ($(CONFIG_LP_LTO),y)
70CFLAGS += -flto
71endif
72
Nico Huber1dba2ed2020-11-14 23:46:10 +010073$(obj)/libpayload.config: $(DOTCONFIG)
74 cp $< $@
75
76$(obj)/libpayload-config.h: $(KCONFIG_AUTOHEADER) $(obj)/libpayload.config
Patrick Georgib3db79e2011-04-21 18:48:50 +020077 cmp $@ $< 2>/dev/null || cp $< $@
78
79library-targets = $(addsuffix .a,$(addprefix $(obj)/,$(libraries))) $(obj)/libpayload.a
80lib: $$(library-targets) $(obj)/head.o
81
Patrick Georgi3b77b722011-07-07 15:41:53 +020082extract_nth=$(word $(1), $(subst |, ,$(2)))
83
84#######################################################################
Martin Roth6116f362016-03-08 12:32:40 -070085# Add handler for special include files
Patrick Georgi3b77b722011-07-07 15:41:53 +020086$(call add-special-class,includes)
87includes-handler= \
88 $(if $(wildcard $(1)$(call extract_nth,1,$(2))), \
89 $(eval includes += $(1)$(2)))
90
Patrick Georgib3db79e2011-04-21 18:48:50 +020091$(obj)/libpayload.a: $(foreach class,$(libraries),$$($(class)-objs))
Martin Roth6116f362016-03-08 12:32:40 -070092 printf " AR $(subst $(CURDIR)/,,$(@))\n"
Patrick Georgib3db79e2011-04-21 18:48:50 +020093 $(AR) rc $@ $^
94
95$(obj)/%.a: $$(%-objs)
Martin Roth6116f362016-03-08 12:32:40 -070096 printf " AR $(subst $(CURDIR)/,,$(@))\n"
Patrick Georgib3db79e2011-04-21 18:48:50 +020097 $(AR) rc $@ $^
98
99$(obj)/head.o: $(obj)/arch/$(ARCHDIR-y)/head.head.o.o
Martin Roth6116f362016-03-08 12:32:40 -0700100 printf " CP $(subst $(CURDIR)/,,$(@))\n"
Patrick Georgib3db79e2011-04-21 18:48:50 +0200101 cp $^ $@
102
103install: real-target
104 printf " INSTALL $(DESTDIR)/libpayload/lib\n"
105 install -m 755 -d $(DESTDIR)/libpayload/lib
106 for lib in $(library-targets); do \
107 install -m 644 $$lib $(DESTDIR)/libpayload/lib/; \
108 done
Ronald G. Minnichc2e8cf52013-02-14 11:32:29 -0800109 install -m 644 arch/$(ARCHDIR-y)/libpayload.ldscript $(DESTDIR)/libpayload/lib/
Patrick Georgib3db79e2011-04-21 18:48:50 +0200110 install -m 755 -d $(DESTDIR)/libpayload/lib/$(ARCHDIR-y)
111 install -m 644 $(obj)/head.o $(DESTDIR)/libpayload/lib/$(ARCHDIR-y)
112 printf " INSTALL $(DESTDIR)/libpayload/include\n"
113 install -m 755 -d $(DESTDIR)/libpayload/include
114 for file in `find include -name *.h -type f`; do \
115 install -m 755 -d $(DESTDIR)/libpayload/`dirname $$file`; \
116 install -m 644 $$file $(DESTDIR)/libpayload/$$file; \
117 done
118 install -m 644 $(obj)/libpayload-config.h $(DESTDIR)/libpayload/include
Patrick Georgi3b77b722011-07-07 15:41:53 +0200119 $(foreach item,$(includes), \
120 install -m 755 -d $(DESTDIR)/libpayload/include/$(call extract_nth,2,$(item)); \
121 install -m 644 $(call extract_nth,1,$(item)) $(DESTDIR)/libpayload/include/$(call extract_nth,2,$(item)); )
Patrick Georgib3db79e2011-04-21 18:48:50 +0200122 printf " INSTALL $(DESTDIR)/libpayload/bin\n"
123 install -m 755 -d $(DESTDIR)/libpayload/bin
124 install -m 755 bin/lpgcc $(DESTDIR)/libpayload/bin
125 install -m 755 bin/lpas $(DESTDIR)/libpayload/bin
126 install -m 644 bin/lp.functions $(DESTDIR)/libpayload/bin
Stefan Reinauer658e4d32013-01-17 12:29:51 -0800127 install -m 644 $(DOTCONFIG) $(DESTDIR)/libpayload/libpayload.config
Nico Huber1823d532020-11-16 22:50:49 +0100128 install -m 755 $(xcompile) $(DESTDIR)/libpayload/libpayload.xcompile
Patrick Georgib3db79e2011-04-21 18:48:50 +0200129
130clean-for-update-target:
131 rm -f $(addsuffix .a,$(addprefix $(obj)/,$(libraries))) $(obj)/libpayload.a
132
133clean-target:
134prepare:
Patrick Georgi34286b82013-12-21 21:08:53 +0100135
136junit.xml:
137 echo '<?xml version="1.0" encoding="utf-8"?><testsuite>' > $@.tmp
Jakub Czapiga12ae8502021-10-08 09:57:14 +0000138 for i in $(filter-out %.old %.unit-tests,$(wildcard configs/*)); do \
Patrick Georgi34286b82013-12-21 21:08:53 +0100139 $(MAKE) clean; \
Keith Short31af70d2019-07-11 17:54:57 -0600140 echo "Building libpayload for $$i"; \
Martin Roth6959f5c2016-03-23 16:07:54 -0600141 cp "$$i" junit_config; \
142 $(MAKE) olddefconfig DOTCONFIG=junit_config V=$(V) Q=$(Q) 2>/dev/null >/dev/null; \
Patrick Georgi34286b82013-12-21 21:08:53 +0100143 echo "<testcase classname='libpayload' name='$$i'>" >> $@.tmp; \
Martin Roth6959f5c2016-03-23 16:07:54 -0600144 $(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 +0100145 if [ $$type = "failure" ]; then \
146 echo "<failure type='buildFailed'>" >> $@.tmp; \
147 else \
148 echo "<$$type>" >> $@.tmp; \
149 fi; \
150 echo '<![CDATA[' >> $@.tmp; \
151 cat $@.tmp.2 >> $@.tmp; \
152 echo "]]></$$type>" >>$@.tmp; \
153 rm -f $@.tmp.2; \
154 echo "</testcase>" >> $@.tmp; \
155 done
156 echo "</testsuite>" >> $@.tmp
Keith Short31af70d2019-07-11 17:54:57 -0600157 echo "libpayload build complete, test results in $@"
Patrick Georgi34286b82013-12-21 21:08:53 +0100158 mv $@.tmp $@
Martin Roth6c9c1962017-08-03 09:25:43 -0600159
160test-configs:
Jakub Czapiga12ae8502021-10-08 09:57:14 +0000161 for config in $(filter-out %.old %.unit-tests,$(wildcard configs/*)); do \
Martin Roth6c9c1962017-08-03 09:25:43 -0600162 $(MAKE) clean; \
163 cp "$$config" test_config; \
164 echo "*** Making libpayload config $$config ***"; \
165 $(MAKE) olddefconfig DOTCONFIG=test_config V=$(V) Q=$(Q) ; \
166 $(MAKE) V=$(V) Q=$(Q) CONFIG_LP_CCACHE=$(CONFIG_LP_CCACHE) DOTCONFIG=test_config; \
167 done