blob: 65d7d3d5a6adde4ade3536a09ec84f870bef54ed [file] [log] [blame]
Jordan Crousef6145c32008-03-19 23:56:58 +00001##
2## This file is part of the libpayload project.
3##
4## Copyright (C) 2008 Advanced Micro Devices, Inc.
Uwe Hermanne55b32a2008-08-08 07:56:07 +00005## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
Jordan Crousef6145c32008-03-19 23:56:58 +00006##
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
Uwe Hermanne55b32a2008-08-08 07:56:07 +000031export src := $(shell pwd)
32export srctree := $(src)
33export srck := $(src)/util/kconfig
34export obj := $(src)/build
35export objk := $(src)/build/util/kconfig
Jordan Crousef6145c32008-03-19 23:56:58 +000036
Uwe Hermanne55b32a2008-08-08 07:56:07 +000037export KERNELVERSION := 0.1.0
38export KCONFIG_AUTOHEADER := $(obj)/config.h
39export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
40
41CONFIG_SHELL := sh
42KBUILD_DEFCONFIG := configs/defconfig
43UNAME_RELEASE := $(shell uname -r)
44HAVE_DOTCONFIG := $(wildcard .config)
45MAKEFLAGS += -rR --no-print-directory
46
47# Make is silent per default, but 'make V=1' will show all compiler calls.
48ifneq ($(V),1)
49Q := @
Jordan Crousef6145c32008-03-19 23:56:58 +000050endif
51
Uwe Hermanne55b32a2008-08-08 07:56:07 +000052HOSTCC = gcc
53HOSTCXX = g++
54HOSTCFLAGS := -I$(srck) -I$(objk)
55HOSTCXXFLAGS := -I$(srck) -I$(objk)
Jordan Crousef6145c32008-03-19 23:56:58 +000056
Uwe Hermanne55b32a2008-08-08 07:56:07 +000057DESTDIR = /opt
Jordan Crousef6145c32008-03-19 23:56:58 +000058
Uwe Hermann3b641292008-08-27 12:53:47 +000059DOXYGEN := doxygen
60DOXYGEN_OUTPUT_DIR := doxygen
61
Uwe Hermanne55b32a2008-08-08 07:56:07 +000062ifeq ($(strip $(HAVE_DOTCONFIG)),)
63
64all: config
65
Jordan Crousef6145c32008-03-19 23:56:58 +000066else
Uwe Hermanne55b32a2008-08-08 07:56:07 +000067
68include $(src)/.config
Jordan Crousef6145c32008-03-19 23:56:58 +000069
Jordan Crousec3e728f2008-04-09 23:05:59 +000070ARCHDIR-$(CONFIG_TARGET_I386) := i386
71
72PLATFORM-y += $(ARCHDIR-y)/Makefile.inc
Jordan Crousef6145c32008-03-19 23:56:58 +000073TARGETS-y :=
74
Uwe Hermann39955932008-04-03 23:01:23 +000075BUILD-y := crypto/Makefile.inc libc/Makefile.inc drivers/Makefile.inc
Jordan Crousef6145c32008-03-19 23:56:58 +000076BUILD-$(CONFIG_TINYCURSES) += curses/Makefile.inc
77
78include $(PLATFORM-y) $(BUILD-y)
79
Uwe Hermanne55b32a2008-08-08 07:56:07 +000080OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
81INCLUDES := -Iinclude -Ibuild
Jordan Crousef6145c32008-03-19 23:56:58 +000082INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
Stefan Reinauer85c7aec2008-08-07 15:28:31 +000083
84try-run= $(shell set -e; \
85TMP=".$$$$.tmp"; \
86if ($(1)) > /dev/null 2>&1; \
87then echo "$(2)"; \
88else echo "$(3)"; \
89fi; rm -rf "$$TMP")
90
91cc-option= $(call try-run,\
92$(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2))
93
94STACKPROTECT += $(call cc-option, -fno-stack-protector,)
95
Uwe Hermann408c4e12008-03-27 19:11:44 +000096# TODO: Re-add -Os as soon as we find out why it caused problems.
Stefan Reinauer1d129fe2008-08-26 11:18:38 +000097CFLAGS := -Wall -Werror $(STACKPROTECT) -nostdinc $(INCLUDES) -ffreestanding
Jordan Crousef6145c32008-03-19 23:56:58 +000098
Uwe Hermanne55b32a2008-08-08 07:56:07 +000099all: lib
Jordan Crousec3e728f2008-04-09 23:05:59 +0000100
Uwe Hermanne55b32a2008-08-08 07:56:07 +0000101lib: prepare $(obj)/lib/libpayload.a copystuff
Jordan Crousec3e728f2008-04-09 23:05:59 +0000102
Uwe Hermanne55b32a2008-08-08 07:56:07 +0000103# Copy libpayload.a and head.o into $(src)/lib where lpgcc et al expect them.
Stefan Reinauer9368e4c2008-08-28 15:20:42 +0000104copystuff: $(obj)/$(ARCHDIR-y)/head.S.o $(obj)/lib/libpayload.a
Uwe Hermanne55b32a2008-08-08 07:56:07 +0000105 $(Q)cp $(obj)/$(ARCHDIR-y)/head.S.o $(src)/lib/$(ARCHDIR-y)/head.o
106 $(Q)cp $(obj)/lib/libpayload.a $(src)/lib
Jordan Crousef6145c32008-03-19 23:56:58 +0000107
Uwe Hermanne55b32a2008-08-08 07:56:07 +0000108$(obj)/lib/libpayload.a: $(OBJS)
109 $(Q)printf " AR $(subst $(shell pwd)/,,$(@))\n"
110 $(Q)$(AR) rc $@ $(OBJS)
Jordan Crousef6145c32008-03-19 23:56:58 +0000111
Uwe Hermanne55b32a2008-08-08 07:56:07 +0000112$(obj)/%.o: $(src)/%.c
113 $(Q)printf " CC $(subst $(shell pwd)/,,$(@))\n"
114 $(Q)$(CC) -m32 $(CFLAGS) -c -o $@ $<
115
116$(obj)/%.S.o: $(src)/%.S
117 $(Q)printf " AS $(subst $(shell pwd)/,,$(@))\n"
118 $(Q)$(AS) --32 -o $@ $<
119
120endif
Jordan Crousef6145c32008-03-19 23:56:58 +0000121
Jordan Crousec3e728f2008-04-09 23:05:59 +0000122install: lib
Uwe Hermanne55b32a2008-08-08 07:56:07 +0000123 $(Q)printf " INSTALL $(DESTDIR)/libpayload/lib\n"
124 $(Q)install -m 755 -d $(DESTDIR)/libpayload/lib
125 $(Q)cp -r lib/* $(DESTDIR)/libpayload/lib/
126 $(Q)printf " INSTALL $(DESTDIR)/libpayload/include\n"
127 $(Q)install -m 755 -d $(DESTDIR)/libpayload/include
128 $(Q)for file in `find include -name *.h -type f`; do \
Jordan Crousebac89d02008-04-10 17:57:42 +0000129 install -m 644 -D $$file $(DESTDIR)/libpayload/$$file; \
130 done
Uwe Hermanne55b32a2008-08-08 07:56:07 +0000131 $(Q)printf " INSTALL $(DESTDIR)/libpayload/bin\n"
132 $(Q)install -m 755 -d $(DESTDIR)/libpayload/bin
133 $(Q)install -m 755 bin/lpgcc $(DESTDIR)/libpayload/bin
134 $(Q)install -m 755 bin/lpas $(DESTDIR)/libpayload/bin
135 $(Q)install -m 644 bin/lp.functions $(DESTDIR)/libpayload/bin
136
137prepare:
138 $(Q)mkdir -p $(obj)/util/kconfig/lxdialog
139 $(Q)mkdir -p $(obj)/crypto $(obj)/curses $(obj)/drivers/video
140 $(Q)mkdir -p $(obj)/i386 $(obj)/lib/$(ARCHDIR-y) $(obj)/libc
141 $(Q)mkdir -p $(src)/lib/$(ARCHDIR-y)
Jordan Crousec3e728f2008-04-09 23:05:59 +0000142
Uwe Hermann3b641292008-08-27 12:53:47 +0000143doxy: doxygen
144doxygen:
145 $(Q)$(DOXYGEN) Doxyfile
146
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000147doxyclean: doxygen-clean
148doxygen-clean:
149 $(Q)rm -rf $(DOXYGEN_OUTPUT_DIR)
150
151clean: doxygen-clean
Uwe Hermanne55b32a2008-08-08 07:56:07 +0000152 $(Q)rm -rf $(obj)/crypto $(obj)/curses $(obj)/drivers
153 $(Q)rm -rf $(obj)/i386 $(obj)/lib $(obj)/libc
154 $(Q)rm -rf $(src)/lib/i386 $(src)/lib/libpayload.a
Jordan Crousef6145c32008-03-19 23:56:58 +0000155
156distclean: clean
Uwe Hermanne55b32a2008-08-08 07:56:07 +0000157 $(Q)rm -rf build
158 $(Q)rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig*
Jordan Crousec3e728f2008-04-09 23:05:59 +0000159
Uwe Hermanne55b32a2008-08-08 07:56:07 +0000160include util/kconfig/Makefile
Jordan Crousef6145c32008-03-19 23:56:58 +0000161
Uwe Hermann3b641292008-08-27 12:53:47 +0000162.PHONY: $(PHONY) prepare clean distclean doxygen doxy
Jordan Crousef6145c32008-03-19 23:56:58 +0000163