2 ## This file is part of the libpayload project.
4 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
5 ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
7 ## Redistribution and use in source and binary forms, with or without
8 ## modification, are permitted provided that the following conditions
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.
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
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
37 export KERNELVERSION := 0.2.0
38 export KCONFIG_AUTOHEADER := $(obj)/include/libpayload-config.h
39 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
42 KBUILD_DEFCONFIG := configs/defconfig
43 UNAME_RELEASE := $(shell uname -r)
44 HAVE_DOTCONFIG := $(wildcard .config)
45 MAKEFLAGS += -rR --no-print-directory
47 # Make is silent per default, but 'make V=1' will show all compiler calls.
52 $(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
58 HOSTCFLAGS := -I$(srck) -I$(objk) -pipe
59 HOSTCXXFLAGS := -I$(srck) -I$(objk) -pipe
61 DESTDIR = $(src)/install
64 DOXYGEN_OUTPUT_DIR := doxygen
66 ifeq ($(strip $(HAVE_DOTCONFIG)),)
72 include $(src)/.config
74 ARCHDIR-$(CONFIG_TARGET_I386) := i386
75 ARCHDIR-$(CONFIG_TARGET_POWERPC) := powerpc
77 PLATFORM-y += arch/$(ARCHDIR-y)/Makefile.inc
80 BUILD-y := crypto/Makefile.inc libc/Makefile.inc drivers/Makefile.inc libpci/Makefile.inc
81 BUILD-$(CONFIG_TINYCURSES) += curses/Makefile.inc
83 # The primary target needs to be here before we include the
88 include $(PLATFORM-y) $(BUILD-y)
90 OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
91 INCLUDES := -Iinclude -Iinclude/$(ARCHDIR-y) -I$(obj) -I$(obj)/include
92 INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
94 try-run= $(shell set -e; \
96 if ($(1)) > /dev/null 2>&1; \
101 cc-option= $(call try-run,\
102 $(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2))
104 STACKPROTECT += $(call cc-option, -fno-stack-protector,)
106 # TODO: Re-add -Os as soon as we find out why it caused problems.
107 CFLAGS := -Wall -Werror $(STACKPROTECT) -nostdinc $(INCLUDES) -ffreestanding -pipe
111 lib: $(obj)/lib/libpayload.a $(obj)/lib/$(ARCHDIR-y)/head.o
113 $(obj)/lib/$(ARCHDIR-y)/head.o: $(obj)/arch/$(ARCHDIR-y)/head.S.o
114 $(Q)printf " CP $(subst $(shell pwd)/,,$(@))\n"
117 $(obj)/lib/libpayload.a: prepare $(OBJS)
118 $(Q)printf " AR $(subst $(shell pwd)/,,$(@))\n"
119 $(Q)$(AR) rc $@ $(OBJS)
124 $(Q)printf " INSTALL $(DESTDIR)/libpayload/lib\n"
125 $(Q)install -m 755 -d $(DESTDIR)/libpayload/lib
126 $(Q)install -m 644 $(obj)/lib/libpayload.a $(DESTDIR)/libpayload/lib/
127 $(Q)install -m 644 lib/libpayload.ldscript $(DESTDIR)/libpayload/lib/
128 $(Q)install -m 755 -d $(DESTDIR)/libpayload/lib/$(ARCHDIR-y)
129 $(Q)install -m 644 $(obj)/lib/$(ARCHDIR-y)/head.o $(DESTDIR)/libpayload/lib/$(ARCHDIR-y)
130 $(Q)printf " INSTALL $(DESTDIR)/libpayload/include\n"
131 $(Q)install -m 755 -d $(DESTDIR)/libpayload/include
132 $(Q)for file in `find include -name *.h -type f`; do \
133 install -m 755 -d $(DESTDIR)/libpayload/`dirname $$file`; \
134 install -m 644 $$file $(DESTDIR)/libpayload/$$file; \
136 $(Q)install -m 644 $(KCONFIG_AUTOHEADER) $(DESTDIR)/libpayload/include
137 $(Q)printf " INSTALL $(DESTDIR)/libpayload/bin\n"
138 $(Q)install -m 755 -d $(DESTDIR)/libpayload/bin
139 $(Q)install -m 755 bin/lpgcc $(DESTDIR)/libpayload/bin
140 $(Q)install -m 755 bin/lpas $(DESTDIR)/libpayload/bin
141 $(Q)install -m 644 bin/lp.functions $(DESTDIR)/libpayload/bin
142 $(Q)install -m 644 .config $(DESTDIR)/libpayload/libpayload.config
145 $(Q)mkdir -p $(obj)/util/kconfig/lxdialog
146 $(Q)mkdir -p $(obj)/crypto $(obj)/curses $(obj)/drivers/video
147 $(Q)mkdir -p $(obj)/drivers/usb
148 $(Q)mkdir -p $(obj)/arch/$(ARCHDIR-y) $(obj)/lib/$(ARCHDIR-y) $(obj)/libc $(obj)/libpci
149 $(Q)mkdir -p $(obj)/lib/$(ARCHDIR-y)
150 $(Q)mkdir -p $(obj)/include
154 $(Q)$(DOXYGEN) Doxyfile
156 doxyclean: doxygen-clean
158 $(Q)rm -rf $(DOXYGEN_OUTPUT_DIR)
161 $(Q)rm -rf $(obj)/crypto $(obj)/curses $(obj)/drivers
162 $(Q)rm -rf $(obj)/i386 $(obj)/powerpc $(obj)/lib $(obj)/libc
165 $(Q)rm -rf build # should be $(obj) ?
166 $(Q)rm -f .config .config.old .xcompile ..config.tmp .kconfig.d .tmpconfig*
168 # This include must come _before_ the pattern rules below!
169 # Order _does_ matter for pattern rules.
170 include util/kconfig/Makefile
172 ifeq ($(strip $(HAVE_DOTCONFIG)),)
175 $(obj)/%.o: $(src)/%.c
176 $(Q)printf " CC $(subst $(shell pwd)/,,$(@))\n"
177 $(Q)$(CC) -m32 $(CFLAGS) -c -o $@ $<
179 $(obj)/%.S.o: $(src)/%.S
180 $(Q)printf " CC $(subst $(shell pwd)/,,$(@))\n"
181 $(Q)$(CC) -m32 $(CFLAGS) -c -o $@ $<
185 .PHONY: $(PHONY) prepare install clean distclean doxygen doxy