blob: b88cd20ea1f0e8a8e5ed8f86fa8bec6b98c62eed [file] [log] [blame]
Patrick Georgib3db79e2011-04-21 18:48:50 +02001##
2## This file is part of the libpayload project.
3##
4## Copyright (C) 2008 Advanced Micro Devices, Inc.
5## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
6## Copyright (C) 2011 secunet Security Networks AG
7##
8## Redistribution and use in source and binary forms, with or without
9## modification, are permitted provided that the following conditions
10## are met:
11## 1. Redistributions of source code must retain the above copyright
12## notice, this list of conditions and the following disclaimer.
13## 2. Redistributions in binary form must reproduce the above copyright
14## notice, this list of conditions and the following disclaimer in the
15## documentation and/or other materials provided with the distribution.
16## 3. The name of the author may not be used to endorse or promote products
17## derived from this software without specific prior written permission.
18##
19## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29## SUCH DAMAGE.
30##
31
32export KERNELVERSION := 0.2.0
33
Gabe Black51edd542013-09-30 23:00:33 -070034ARCHDIR-$(CONFIG_LP_ARCH_ARM) := arm
Furquan Shaikh8c8c3772014-02-19 11:35:30 -080035ARCHDIR-$(CONFIG_LP_ARCH_ARM64) := arm64
Ionela Voinescuce22c022014-09-24 17:05:33 +010036ARCHDIR-$(CONFIG_LP_ARCH_MIPS) := mips
Gabe Black1ee2c6d2013-08-09 04:27:35 -070037ARCHDIR-$(CONFIG_LP_ARCH_X86) := x86
Tadas Slotkus09ea8ea2011-07-15 03:41:11 +030038DESTDIR ?= install
Patrick Georgib3db79e2011-04-21 18:48:50 +020039
40real-target: lib
41
Gabe Black1ee2c6d2013-08-09 04:27:35 -070042classes-$(CONFIG_LP_PCI) += libpci
43classes-$(CONFIG_LP_LIBC) += libc
44classes-$(CONFIG_LP_CURSES) += libcurses
45classes-$(CONFIG_LP_PDCURSES) += libmenu libform libpanel
46classes-$(CONFIG_LP_CBFS) += libcbfs
47classes-$(CONFIG_LP_LZMA) += liblzma
Julius Wernerbf273912015-06-30 10:30:30 -070048classes-$(CONFIG_LP_LZ4) += liblz4
Julius Werner50a81742014-05-15 11:57:38 -070049classes-$(CONFIG_LP_REMOTEGDB) += libgdb
Patrick Georgib3db79e2011-04-21 18:48:50 +020050libraries := $(classes-y)
51classes-y += head.o
52
Patrick Georgib3db79e2011-04-21 18:48:50 +020053subdirs-y := arch/$(ARCHDIR-y)
Julius Werner50a81742014-05-15 11:57:38 -070054subdirs-y += crypto libc drivers libpci gdb
Gabe Black1ee2c6d2013-08-09 04:27:35 -070055subdirs-$(CONFIG_LP_CURSES) += curses
56subdirs-$(CONFIG_LP_CBFS) += libcbfs
57subdirs-$(CONFIG_LP_LZMA) += liblzma
Julius Wernerbf273912015-06-30 10:30:30 -070058subdirs-$(CONFIG_LP_LZ4) += liblz4
Patrick Georgib3db79e2011-04-21 18:48:50 +020059
Stefan Reinauer1b4d3942015-06-29 15:47:34 -070060INCLUDES := -Iinclude -Iinclude/$(ARCHDIR-y) -I$(obj) -include include/kconfig.h
61
Patrick Georgi9b8c7382015-07-06 09:09:30 +000062CFLAGS += $(EXTRA_CFLAGS) $(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
Stefan Reinauer08c41502013-05-21 14:45:28 -070065CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
Patrick Georgib3db79e2011-04-21 18:48:50 +020066CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
Vadim Bendebury19c3da52014-05-15 14:12:54 -070067CFLAGS += -Wstrict-aliasing -Wshadow -Werror
Patrick Georgib3db79e2011-04-21 18:48:50 +020068
69$(obj)/libpayload-config.h: $(KCONFIG_AUTOHEADER)
70 cmp $@ $< 2>/dev/null || cp $< $@
71
72library-targets = $(addsuffix .a,$(addprefix $(obj)/,$(libraries))) $(obj)/libpayload.a
73lib: $$(library-targets) $(obj)/head.o
74
Patrick Georgi3b77b722011-07-07 15:41:53 +020075extract_nth=$(word $(1), $(subst |, ,$(2)))
76
77#######################################################################
Martin Roth6116f362016-03-08 12:32:40 -070078# Add handler for special include files
Patrick Georgi3b77b722011-07-07 15:41:53 +020079$(call add-special-class,includes)
80includes-handler= \
81 $(if $(wildcard $(1)$(call extract_nth,1,$(2))), \
82 $(eval includes += $(1)$(2)))
83
Patrick Georgib3db79e2011-04-21 18:48:50 +020084$(obj)/libpayload.a: $(foreach class,$(libraries),$$($(class)-objs))
Martin Roth6116f362016-03-08 12:32:40 -070085 printf " AR $(subst $(CURDIR)/,,$(@))\n"
Patrick Georgib3db79e2011-04-21 18:48:50 +020086 $(AR) rc $@ $^
87
88$(obj)/%.a: $$(%-objs)
Martin Roth6116f362016-03-08 12:32:40 -070089 printf " AR $(subst $(CURDIR)/,,$(@))\n"
Patrick Georgib3db79e2011-04-21 18:48:50 +020090 $(AR) rc $@ $^
91
92$(obj)/head.o: $(obj)/arch/$(ARCHDIR-y)/head.head.o.o
Martin Roth6116f362016-03-08 12:32:40 -070093 printf " CP $(subst $(CURDIR)/,,$(@))\n"
Patrick Georgib3db79e2011-04-21 18:48:50 +020094 cp $^ $@
95
96install: real-target
97 printf " INSTALL $(DESTDIR)/libpayload/lib\n"
98 install -m 755 -d $(DESTDIR)/libpayload/lib
99 for lib in $(library-targets); do \
100 install -m 644 $$lib $(DESTDIR)/libpayload/lib/; \
101 done
Ronald G. Minnichc2e8cf52013-02-14 11:32:29 -0800102 install -m 644 arch/$(ARCHDIR-y)/libpayload.ldscript $(DESTDIR)/libpayload/lib/
Patrick Georgib3db79e2011-04-21 18:48:50 +0200103 install -m 755 -d $(DESTDIR)/libpayload/lib/$(ARCHDIR-y)
104 install -m 644 $(obj)/head.o $(DESTDIR)/libpayload/lib/$(ARCHDIR-y)
105 printf " INSTALL $(DESTDIR)/libpayload/include\n"
106 install -m 755 -d $(DESTDIR)/libpayload/include
107 for file in `find include -name *.h -type f`; do \
108 install -m 755 -d $(DESTDIR)/libpayload/`dirname $$file`; \
109 install -m 644 $$file $(DESTDIR)/libpayload/$$file; \
110 done
111 install -m 644 $(obj)/libpayload-config.h $(DESTDIR)/libpayload/include
Patrick Georgi3b77b722011-07-07 15:41:53 +0200112 $(foreach item,$(includes), \
113 install -m 755 -d $(DESTDIR)/libpayload/include/$(call extract_nth,2,$(item)); \
114 install -m 644 $(call extract_nth,1,$(item)) $(DESTDIR)/libpayload/include/$(call extract_nth,2,$(item)); )
Patrick Georgib3db79e2011-04-21 18:48:50 +0200115 printf " INSTALL $(DESTDIR)/libpayload/bin\n"
116 install -m 755 -d $(DESTDIR)/libpayload/bin
117 install -m 755 bin/lpgcc $(DESTDIR)/libpayload/bin
118 install -m 755 bin/lpas $(DESTDIR)/libpayload/bin
119 install -m 644 bin/lp.functions $(DESTDIR)/libpayload/bin
Stefan Reinauer658e4d32013-01-17 12:29:51 -0800120 install -m 644 $(DOTCONFIG) $(DESTDIR)/libpayload/libpayload.config
Stefan Reinauer5d866212015-07-08 17:09:49 -0700121 install -m 755 .xcompile $(DESTDIR)/libpayload/libpayload.xcompile
Patrick Georgib3db79e2011-04-21 18:48:50 +0200122
123clean-for-update-target:
124 rm -f $(addsuffix .a,$(addprefix $(obj)/,$(libraries))) $(obj)/libpayload.a
125
126clean-target:
127prepare:
Patrick Georgi34286b82013-12-21 21:08:53 +0100128
129junit.xml:
130 echo '<?xml version="1.0" encoding="utf-8"?><testsuite>' > $@.tmp
131 for i in $(filter-out %.old,$(wildcard configs/*)); do \
132 $(MAKE) clean; \
Martin Roth6959f5c2016-03-23 16:07:54 -0600133 cp "$$i" junit_config; \
134 $(MAKE) olddefconfig DOTCONFIG=junit_config V=$(V) Q=$(Q) 2>/dev/null >/dev/null; \
Patrick Georgi34286b82013-12-21 21:08:53 +0100135 echo "<testcase classname='libpayload' name='$$i'>" >> $@.tmp; \
Martin Roth6959f5c2016-03-23 16:07:54 -0600136 $(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 +0100137 if [ $$type = "failure" ]; then \
138 echo "<failure type='buildFailed'>" >> $@.tmp; \
139 else \
140 echo "<$$type>" >> $@.tmp; \
141 fi; \
142 echo '<![CDATA[' >> $@.tmp; \
143 cat $@.tmp.2 >> $@.tmp; \
144 echo "]]></$$type>" >>$@.tmp; \
145 rm -f $@.tmp.2; \
146 echo "</testcase>" >> $@.tmp; \
147 done
148 echo "</testsuite>" >> $@.tmp
149 mv $@.tmp $@