Libpayload: default DESTDIR for 'make install'
[coreboot.git] / payloads / libpayload / Makefile.inc
1 ##
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
32 export KERNELVERSION      := 0.2.0
33
34 ARCHDIR-$(CONFIG_TARGET_I386)    := i386
35 ARCHDIR-$(CONFIG_TARGET_POWERPC) := powerpc
36 DESTDIR ?= install
37
38 real-target: lib
39
40 classes-$(CONFIG_PCI) += libpci
41 classes-$(CONFIG_LIBC) += libc
42 classes-$(CONFIG_TINYCURSES) += libcurses
43 libraries := $(classes-y)
44 classes-y += head.o
45
46 libpci-c-deps = $(obj)/libpayload-config.h
47 libc-c-deps = $(obj)/libpayload-config.h
48 libcurses-c-deps = $(obj)/libpayload-config.h
49 head.o-S-deps = $(obj)/libpayload-config.h
50
51 subdirs-y := arch/$(ARCHDIR-y)
52 subdirs-y += crypto libc drivers libpci
53 subdirs-$(CONFIG_TINYCURSES) += curses
54
55 INCLUDES := -Iinclude -Iinclude/$(ARCHDIR-y) -I$(obj)
56 CFLAGS = $(INCLUDES) -O2 -pipe -g
57 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
58 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
59 CFLAGS += -Wstrict-aliasing -Wshadow -fno-builtin
60
61 $(obj)/libpayload-config.h: $(KCONFIG_AUTOHEADER)
62         cmp $@ $< 2>/dev/null || cp $< $@
63
64 library-targets = $(addsuffix .a,$(addprefix $(obj)/,$(libraries))) $(obj)/libpayload.a
65 lib: $$(library-targets) $(obj)/head.o
66
67 $(obj)/libpayload.a: $(foreach class,$(libraries),$$($(class)-objs))
68         printf "    AR         $(subst $(shell pwd)/,,$(@))\n"
69         $(AR) rc $@ $^
70
71 $(obj)/%.a: $$(%-objs)
72         printf "    AR         $(subst $(shell pwd)/,,$(@))\n"
73         $(AR) rc $@ $^
74
75 $(obj)/head.o: $(obj)/arch/$(ARCHDIR-y)/head.head.o.o
76         printf "    CP         $(subst $(shell pwd)/,,$(@))\n"
77         cp $^ $@
78
79 install: real-target
80         printf "    INSTALL    $(DESTDIR)/libpayload/lib\n"
81         install -m 755 -d $(DESTDIR)/libpayload/lib
82         for lib in $(library-targets); do \
83                 install -m 644 $$lib $(DESTDIR)/libpayload/lib/; \
84         done
85         install -m 644 lib/libpayload.ldscript $(DESTDIR)/libpayload/lib/
86         install -m 755 -d $(DESTDIR)/libpayload/lib/$(ARCHDIR-y)
87         install -m 644 $(obj)/head.o $(DESTDIR)/libpayload/lib/$(ARCHDIR-y)
88         printf "    INSTALL    $(DESTDIR)/libpayload/include\n"
89         install -m 755 -d $(DESTDIR)/libpayload/include
90         for file in `find include -name *.h -type f`; do \
91                 install -m 755 -d $(DESTDIR)/libpayload/`dirname $$file`; \
92                 install -m 644 $$file $(DESTDIR)/libpayload/$$file; \
93         done
94         install -m 644 $(obj)/libpayload-config.h $(DESTDIR)/libpayload/include
95         printf "    INSTALL    $(DESTDIR)/libpayload/bin\n"
96         install -m 755 -d $(DESTDIR)/libpayload/bin
97         install -m 755 bin/lpgcc $(DESTDIR)/libpayload/bin
98         install -m 755 bin/lpas $(DESTDIR)/libpayload/bin
99         install -m 644 bin/lp.functions $(DESTDIR)/libpayload/bin
100         install -m 644 .config $(DESTDIR)/libpayload/libpayload.config
101
102 clean-for-update-target:
103         rm -f $(addsuffix .a,$(addprefix $(obj)/,$(libraries))) $(obj)/libpayload.a
104
105 clean-target:
106 prepare: