b862f8da0f8159bfeb3bfadfd6306bb256162a40
[coreboot.git] / payloads / libpayload / Makefile
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 ##
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
31 export src := $(shell pwd)
32 export srctree := $(src)
33 export srck := $(src)/util/kconfig
34 export obj := $(src)/build
35 export objk := $(src)/build/util/kconfig
36
37 export KERNELVERSION      := 0.1.0
38 export KCONFIG_AUTOHEADER := $(obj)/config.h
39 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
40
41 CONFIG_SHELL := sh
42 KBUILD_DEFCONFIG := configs/defconfig
43 UNAME_RELEASE := $(shell uname -r)
44 HAVE_DOTCONFIG := $(wildcard .config)
45 MAKEFLAGS += -rR --no-print-directory
46
47 # Make is silent per default, but 'make V=1' will show all compiler calls.
48 ifneq ($(V),1)
49 Q := @
50 endif
51
52 HOSTCC = gcc
53 HOSTCXX = g++
54 HOSTCFLAGS := -I$(srck) -I$(objk)
55 HOSTCXXFLAGS := -I$(srck) -I$(objk)
56
57 DESTDIR = /opt
58
59 ifeq ($(strip $(HAVE_DOTCONFIG)),)
60
61 all: config
62
63 else
64
65 include $(src)/.config
66
67 ARCHDIR-$(CONFIG_TARGET_I386) := i386
68
69 PLATFORM-y += $(ARCHDIR-y)/Makefile.inc
70 TARGETS-y :=
71
72 BUILD-y := crypto/Makefile.inc libc/Makefile.inc drivers/Makefile.inc
73 BUILD-$(CONFIG_TINYCURSES) += curses/Makefile.inc
74
75 include $(PLATFORM-y) $(BUILD-y)
76
77 OBJS     := $(patsubst %,$(obj)/%,$(TARGETS-y))
78 INCLUDES := -Iinclude -Ibuild
79 INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
80
81 try-run= $(shell set -e; \
82 TMP=".$$$$.tmp"; \
83 if ($(1)) > /dev/null 2>&1; \
84 then echo "$(2)"; \
85 else echo "$(3)"; \
86 fi; rm -rf "$$TMP")
87
88 cc-option= $(call try-run,\
89 $(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2))
90
91 STACKPROTECT += $(call cc-option, -fno-stack-protector,)
92
93 # TODO: Re-add -Os as soon as we find out why it caused problems.
94 CFLAGS := -Wall -Werror $(STACKPROTECT) -nostdinc $(INCLUDES)
95
96 all: lib
97
98 lib: prepare $(obj)/lib/libpayload.a copystuff
99
100 # Copy libpayload.a and head.o into $(src)/lib where lpgcc et al expect them.
101 copystuff:
102         $(Q)cp $(obj)/$(ARCHDIR-y)/head.S.o $(src)/lib/$(ARCHDIR-y)/head.o
103         $(Q)cp $(obj)/lib/libpayload.a $(src)/lib
104
105 $(obj)/lib/libpayload.a: $(OBJS)
106         $(Q)printf "  AR      $(subst $(shell pwd)/,,$(@))\n"
107         $(Q)$(AR) rc $@ $(OBJS)
108
109 $(obj)/%.o: $(src)/%.c
110         $(Q)printf "  CC      $(subst $(shell pwd)/,,$(@))\n"
111         $(Q)$(CC) -m32 $(CFLAGS) -c -o $@ $<
112
113 $(obj)/%.S.o: $(src)/%.S
114         $(Q)printf "  AS      $(subst $(shell pwd)/,,$(@))\n"
115         $(Q)$(AS) --32 -o $@ $<
116
117 endif
118
119 install: lib
120         $(Q)printf "  INSTALL $(DESTDIR)/libpayload/lib\n"
121         $(Q)install -m 755 -d $(DESTDIR)/libpayload/lib
122         $(Q)cp -r lib/* $(DESTDIR)/libpayload/lib/
123         $(Q)printf "  INSTALL $(DESTDIR)/libpayload/include\n"
124         $(Q)install -m 755 -d $(DESTDIR)/libpayload/include
125         $(Q)for file in `find include -name *.h -type f`; do \
126                 install -m 644 -D $$file $(DESTDIR)/libpayload/$$file; \
127         done
128         $(Q)printf "  INSTALL $(DESTDIR)/libpayload/bin\n"
129         $(Q)install -m 755 -d $(DESTDIR)/libpayload/bin
130         $(Q)install -m 755 bin/lpgcc $(DESTDIR)/libpayload/bin
131         $(Q)install -m 755 bin/lpas $(DESTDIR)/libpayload/bin
132         $(Q)install -m 644 bin/lp.functions $(DESTDIR)/libpayload/bin
133
134 prepare:
135         $(Q)mkdir -p $(obj)/util/kconfig/lxdialog
136         $(Q)mkdir -p $(obj)/crypto $(obj)/curses $(obj)/drivers/video
137         $(Q)mkdir -p $(obj)/i386 $(obj)/lib/$(ARCHDIR-y) $(obj)/libc 
138         $(Q)mkdir -p $(src)/lib/$(ARCHDIR-y)
139
140 clean:
141         $(Q)rm -rf $(obj)/crypto $(obj)/curses $(obj)/drivers
142         $(Q)rm -rf $(obj)/i386 $(obj)/lib $(obj)/libc 
143         $(Q)rm -rf $(src)/lib/i386 $(src)/lib/libpayload.a
144
145 distclean: clean
146         $(Q)rm -rf build
147         $(Q)rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig*
148
149 include util/kconfig/Makefile
150
151 .PHONY: $(PHONY) prepare clean distclean
152