Clone a tag rather than SeaBIOS stable branch HEAD
[coreboot.git] / payloads / libpayload / Makefile
index aa3f07d639deec916e811bcf66662b3df60b3689..4363590a143aa15f966f2bd4103bbc74ceebe528 100644 (file)
@@ -2,6 +2,7 @@
 ## This file is part of the libpayload project.
 ##
 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
+## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
 ##
 ## Redistribution and use in source and binary forms, with or without
 ## modification, are permitted provided that the following conditions
 ## SUCH DAMAGE.
 ##
 
-BASE_DIR=$(shell pwd)
-KCONFIG_DIR=util/kconfig
-
-ifeq (.config, $(wildcard .config))
-dot-config := 1
-else
-dot-config := 0
-config-targets := 1
+export src := $(shell pwd)
+export srctree := $(src)
+export srck := $(src)/util/kconfig
+export obj := $(src)/build
+export objk := $(src)/build/util/kconfig
+
+export KERNELVERSION      := 0.2.0
+export KCONFIG_AUTOHEADER := $(obj)/include/libpayload-config.h
+export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
+
+CONFIG_SHELL := sh
+KBUILD_DEFCONFIG := configs/defconfig
+UNAME_RELEASE := $(shell uname -r)
+HAVE_DOTCONFIG := $(wildcard .config)
+MAKEFLAGS += -rR --no-print-directory
+
+# Make is silent per default, but 'make V=1' will show all compiler calls.
+ifneq ($(V),1)
+Q := @
 endif
 
-ifneq ($(filter textconfig oldconfig defconfig menuconfig,$(MAKECMDGOALS)),)
-config-targets := 1
-dot-config := 0
-endif
+$(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
+include .xcompile
+
+CC ?= gcc
+HOSTCC = gcc
+HOSTCXX = g++
+HOSTCFLAGS := -I$(srck) -I$(objk) -pipe
+HOSTCXXFLAGS := -I$(srck) -I$(objk) -pipe
+
+DESTDIR = $(src)/install
+
+DOXYGEN := doxygen
+DOXYGEN_OUTPUT_DIR := doxygen
 
-ifeq ($(dot-config),0)
-all: .config
+ifeq ($(strip $(HAVE_DOTCONFIG)),)
+
+all: config
 
-.config: oldconfig
-       @echo "Configuration completed - type make to build libpayload"
 else
--include .config
-endif
 
-PLATFORM-$(CONFIG_TARGET_I386) += i386/Makefile.inc
+include $(src)/.config
+
+ARCHDIR-$(CONFIG_TARGET_I386)    := i386
+ARCHDIR-$(CONFIG_TARGET_POWERPC) := powerpc
+
+PLATFORM-y += arch/$(ARCHDIR-y)/Makefile.inc
 TARGETS-y :=
 
-BUILD-y := libc/Makefile.inc drivers/Makefile.inc
+BUILD-y := crypto/Makefile.inc libc/Makefile.inc drivers/Makefile.inc libpci/Makefile.inc
 BUILD-$(CONFIG_TINYCURSES) += curses/Makefile.inc
 
+# The primary target needs to be here before we include the
+# other files
+
+all: lib
+
 include $(PLATFORM-y) $(BUILD-y)
 
-INCLUDES := -I./include
+OBJS     := $(patsubst %,$(obj)/%,$(TARGETS-y))
+INCLUDES := -Iinclude -Iinclude/$(ARCHDIR-y) -I$(obj) -I$(obj)/include
 INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
-CFLAGS := -Wall -Werror -Os -fno-stack-protector -nostdinc $(INCLUDES)
 
-libpayload.a: $(TARGETS-y)
-       $(AR) rc $@ $(TARGETS-y)
+try-run= $(shell set -e; \
+TMP=".$$$$.tmp"; \
+if ($(1)) > /dev/null 2>&1; \
+then echo "$(2)"; \
+else echo "$(3)"; \
+fi; rm -rf "$$TMP")
 
-%.o: %.c
-       $(CC) -m32 $(CFLAGS) -c -o $@ $<
+cc-option= $(call try-run,\
+$(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2))
 
-%.o: %.S
-       $(AS) --32 -o $@ $<
+STACKPROTECT += $(call cc-option, -fno-stack-protector,)
 
-clean:
-       @ rm -f $(TARGETS-y)
-       @ rm -f libpayload.a
+# TODO: Re-add -Os as soon as we find out why it caused problems.
+CFLAGS := -Wall -Werror $(STACKPROTECT) -nostdinc $(INCLUDES) -ffreestanding -pipe
 
-distclean: clean
-       @ make -C $(KCONFIG_DIR) clean
-       @ rm -f $(KCONFIG_DIR)/lxdialog/lxdialog
-       @ rm -f .config .kconfig.d  include/autoconf.h
-       
-ifeq ($(config-targets),1)
+all: lib
+
+lib: $(obj)/lib/libpayload.a $(obj)/lib/$(ARCHDIR-y)/head.o
+
+$(obj)/lib/$(ARCHDIR-y)/head.o: $(obj)/arch/$(ARCHDIR-y)/head.S.o
+       $(Q)printf "  CP      $(subst $(shell pwd)/,,$(@))\n"
+       $(Q)cp $< $@
+
+$(obj)/lib/libpayload.a: prepare $(OBJS)
+       $(Q)printf "  AR      $(subst $(shell pwd)/,,$(@))\n"
+       $(Q)$(AR) rc $@ $(OBJS)
 
-$(KCONFIG_DIR)/conf:
-       make -C $(KCONFIG_DIR) conf
+endif
 
-$(KCONFIG_DIR)/mconf:
-       make -C $(KCONFIG_DIR) mconf
+install: lib
+       $(Q)printf "  INSTALL $(DESTDIR)/libpayload/lib\n"
+       $(Q)install -m 755 -d $(DESTDIR)/libpayload/lib
+       $(Q)install -m 644 $(obj)/lib/libpayload.a $(DESTDIR)/libpayload/lib/
+       $(Q)install -m 644 lib/libpayload.ldscript $(DESTDIR)/libpayload/lib/
+       $(Q)install -m 755 -d $(DESTDIR)/libpayload/lib/$(ARCHDIR-y)
+       $(Q)install -m 644 $(obj)/lib/$(ARCHDIR-y)/head.o $(DESTDIR)/libpayload/lib/$(ARCHDIR-y)
+       $(Q)printf "  INSTALL $(DESTDIR)/libpayload/include\n"
+       $(Q)install -m 755 -d $(DESTDIR)/libpayload/include
+       $(Q)for file in `find include -name *.h -type f`; do \
+               install -m 755 -d $(DESTDIR)/libpayload/`dirname $$file`; \
+               install -m 644 $$file $(DESTDIR)/libpayload/$$file; \
+       done
+       $(Q)install -m 644 $(KCONFIG_AUTOHEADER) $(DESTDIR)/libpayload/include
+       $(Q)printf "  INSTALL $(DESTDIR)/libpayload/bin\n"
+       $(Q)install -m 755 -d $(DESTDIR)/libpayload/bin
+       $(Q)install -m 755 bin/lpgcc $(DESTDIR)/libpayload/bin
+       $(Q)install -m 755 bin/lpas $(DESTDIR)/libpayload/bin
+       $(Q)install -m 644 bin/lp.functions $(DESTDIR)/libpayload/bin
+       $(Q)install -m 644 .config $(DESTDIR)/libpayload/libpayload.config
+
+prepare:
+       $(Q)mkdir -p $(obj)/util/kconfig/lxdialog
+       $(Q)mkdir -p $(obj)/crypto $(obj)/curses $(obj)/drivers/video
+       $(Q)mkdir -p $(obj)/drivers/usb
+       $(Q)mkdir -p $(obj)/arch/$(ARCHDIR-y) $(obj)/lib/$(ARCHDIR-y) $(obj)/libc $(obj)/libpci
+       $(Q)mkdir -p $(obj)/lib/$(ARCHDIR-y)
+       $(Q)mkdir -p $(obj)/include
+
+doxy: doxygen
+doxygen:
+       $(Q)$(DOXYGEN) Doxyfile
+
+doxyclean: doxygen-clean
+doxygen-clean:
+       $(Q)rm -rf $(DOXYGEN_OUTPUT_DIR)
+
+clean: doxygen-clean
+       $(Q)rm -rf $(obj)/crypto $(obj)/curses $(obj)/drivers
+       $(Q)rm -rf $(obj)/i386 $(obj)/powerpc $(obj)/lib $(obj)/libc
 
-$(KCONFIG_DIR)/lxdialog/lxdialog:
-       make -C $(KCONFIG_DIR)/lxdialog lxdialog
+distclean: clean
+       $(Q)rm -rf build # should be $(obj) ?
+       $(Q)rm -f .config .config.old .xcompile ..config.tmp .kconfig.d .tmpconfig*
 
-textconfig: $(KCONFIG_DIR)/conf
-       @$(KCONFIG_DIR)/conf $(BASE_DIR)/Config.in
+# This include must come _before_ the pattern rules below!
+# Order _does_ matter for pattern rules.
+include util/kconfig/Makefile
 
-oldconfig: $(KCONFIG_DIR)/conf
-       @$(KCONFIG_DIR)/conf -o $(BASE_DIR)/Config.in
+ifeq ($(strip $(HAVE_DOTCONFIG)),)
+else
 
-defconfig: $(KCONFIG_DIR)/conf
-       @$(KCONFIG_DIR)/conf -d $(BASE_DIR)/Config.in
+$(obj)/%.o: $(src)/%.c
+       $(Q)printf "  CC      $(subst $(shell pwd)/,,$(@))\n"
+       $(Q)$(CC) -m32 $(CFLAGS) -c -o $@ $<
 
-menuconfig: $(KCONFIG_DIR)/lxdialog/lxdialog $(KCONFIG_DIR)/mconf
-       @$(KCONFIG_DIR)/mconf $(BASE_DIR)/Config.in
+$(obj)/%.S.o: $(src)/%.S
+       $(Q)printf "  CC      $(subst $(shell pwd)/,,$(@))\n"
+       $(Q)$(CC) -m32 $(CFLAGS) -c -o $@ $<
 
 endif
+
+.PHONY: $(PHONY) prepare install clean distclean doxygen doxy
+