coreboot-v2/Makefile
<<
>>
Prefs
   1##
   2## This file is part of the coreboot 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$(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
  32include .xcompile
  33
  34export top := $(shell pwd)
  35export src := $(top)/src
  36export srck := $(top)/util/kconfig
  37export obj := $(top)/build
  38export objk := $(obj)/util/kconfig
  39export sconfig := $(top)/util/sconfig
  40export yapps2_py := $(sconfig)/yapps2.py
  41export config_g := $(sconfig)/config.g
  42
  43
  44export KERNELVERSION      := 2.3
  45export KCONFIG_AUTOHEADER := $(obj)/config.h
  46export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
  47export COREBOOT_V2      := 1
  48
  49CONFIG_SHELL := sh
  50KBUILD_DEFCONFIG := configs/defconfig
  51UNAME_RELEASE := $(shell uname -r)
  52HAVE_DOTCONFIG := $(wildcard .config)
  53MAKEFLAGS += -rR --no-print-directory
  54
  55# Make is silent per default, but 'make V=1' will show all compiler calls.
  56Q:=@
  57ifneq ($(V),1)
  58ifneq ($(Q),)
  59.SILENT:
  60endif
  61endif
  62
  63CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
  64HOSTCC = gcc
  65HOSTCXX = g++
  66HOSTCFLAGS := -I$(srck) -I$(objk) -g
  67HOSTCXXFLAGS := -I$(srck) -I$(objk)
  68LIBGCC_FILE_NAME := $(shell $(CC) -print-libgcc-file-name)
  69
  70DESTDIR = /opt
  71
  72DOXYGEN := doxygen
  73DOXYGEN_OUTPUT_DIR := doxygen
  74
  75ifeq ($(strip $(HAVE_DOTCONFIG)),)
  76
  77all: config
  78
  79else
  80
  81include $(top)/.config
  82
  83ARCHDIR-$(CONFIG_ARCH_X86)    := i386
  84ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
  85
  86MAINBOARDDIR=$(shell echo $(CONFIG_MAINBOARD_DIR))
  87export MAINBOARDDIR
  88
  89PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
  90TARGETS-y :=
  91
  92BUILD-y := src/lib src/boot src/console src/devices src/southbridge src/northbridge src/superio src/drivers util/x86emu
  93BUILD-y += util/cbfstool
  94BUILD-$(CONFIG_ARCH_X86) += src/pc80
  95
  96ifneq ($(CONFIG_LOCALVERSION),"")
  97COREBOOT_EXTRA_VERSION := -$(shell echo $(CONFIG_LOCALVERSION))
  98endif
  99
 100# The primary target needs to be here before we include the
 101# other files
 102
 103all: coreboot
 104
 105
 106#######################################################################
 107# Build the tools
 108
 109CBFSTOOL:=$(obj)/util/cbfstool/cbfstool
 110
 111$(obj)/mainboard/$(MAINBOARDDIR)/config.py: $(yapps2_py) $(config_g) 
 112        mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
 113        python $(yapps2_py) $(config_g) $(obj)/mainboard/$(MAINBOARDDIR)/config.py
 114
 115
 116# needed objects that every mainboard uses 
 117# Creation of these is architecture and mainboard independent
 118$(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb  $(obj)/mainboard/$(MAINBOARDDIR)/config.py
 119        mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
 120        (cd $(obj)/mainboard/$(MAINBOARDDIR) ; PYTHONPATH=$(top)/util/sconfig export PYTHONPATH; python config.py  $(MAINBOARDDIR) $(top) $(obj)/mainboard/$(MAINBOARDDIR))
 121
 122$(obj)/mainboard/$(MAINBOARDDIR)/static.o: $(obj)/mainboard/$(MAINBOARDDIR)/static.c
 123#
 124
 125objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o
 126initobjs:=
 127drivers:=
 128smmobjs:=
 129crt0s:=
 130ldscripts:=
 131types:=obj initobj driver smmobj
 132src_types:=crt0 ldscript
 133includemakefiles=$(foreach type,$(2), $(eval $(type)-y:=)) $(eval subdirs-y:=) $(eval include $(1)) $(if $(strip $(3)),$(foreach type,$(2),$(eval $(type)s+=$$(patsubst src/%,$(obj)/%,$$(addprefix $(dir $(1)),$$($(type)-y)))))) $(eval subdirs+=$$(subst $(PWD)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
 134evaluate_subdirs=$(eval cursubdirs:=$(subdirs)) $(eval subdirs:=) $(foreach dir,$(cursubdirs),$(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types) $(src_types),$(1)))) $(if $(subdirs),$(eval $(call evaluate_subdirs, $(1))))
 135
 136# collect all object files eligible for building
 137subdirs:=$(PLATFORM-y) $(BUILD-y)
 138$(eval $(call evaluate_subdirs, modify))
 139
 140allobjs:=$(foreach var, $(addsuffix s,$(types)), $($(var)))
 141alldirs:=$(sort $(abspath $(dir $(allobjs))))
 142source_with_ext=$(patsubst $(obj)/%.o,src/%.$(1),$(allobjs))
 143allsrc=$(wildcard $(call source_with_ext,c) $(call source_with_ext,S))
 144
 145POST_EVALUATION:=y
 146
 147# fetch rules (protected in POST_EVALUATION) that rely on the variables filled above
 148subdirs:=$(PLATFORM-y) $(BUILD-y)
 149$(eval $(call evaluate_subdirs))
 150
 151
 152define c_dsl_template
 153$(obj)/$(1)%.c: src/$(1)%.dsl
 154        @printf "    IASL       $$(subst $$(shell pwd)/,,$$(@))\n"
 155        iasl -p $$(basename $$@) -tc $$<
 156        perl -pi -e 's/AmlCode/AmlCode_$$(notdir $$(basename $$@))/g' $$(basename $$@).hex
 157        mv $$(basename $$@).hex $$@
 158endef
 159
 160define objs_c_template
 161$(obj)/$(1)%.o: src/$(1)%.c
 162        @printf "    CC         $$(subst $$(obj)/,,$$(@))\n"
 163        $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
 164endef
 165
 166define objs_S_template
 167$(obj)/$(1)%.o: src/$(1)%.S
 168        @printf "    CC         $$(subst $$(obj)/,,$$(@))\n"
 169        $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
 170endef
 171
 172define initobjs_c_template
 173$(obj)/$(1)%.o: src/$(1)%.c
 174        @printf "    CC         $$(subst $$(obj)/,,$$(@))\n"
 175        $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
 176endef
 177
 178define initobjs_S_template
 179$(obj)/$(1)%.o: src/$(1)%.S
 180        @printf "    CC         $$(subst $$(obj)/,,$$(@))\n"
 181        $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
 182endef
 183
 184define drivers_c_template
 185$(obj)/$(1)%.o: src/$(1)%.c
 186        @printf "    CC         $$(subst $$(obj)/,,$$(@))\n"
 187        $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
 188endef
 189
 190define drivers_S_template
 191$(obj)/$(1)%.o: src/$(1)%.S
 192        @printf "    CC         $$(subst $$(obj)/,,$$(@))\n"
 193        $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
 194endef
 195
 196define smmobjs_c_template
 197$(obj)/$(1)%.o: src/$(1)%.c
 198        @printf "    CC         $$(subst $$(obj)/,,$$(@))\n"
 199        $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
 200endef
 201
 202define smmobjs_S_template
 203$(obj)/$(1)%.o: src/$(1)%.S
 204        @printf "    CC         $$(subst $$(obj)/,,$$(@))\n"
 205        $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
 206endef
 207
 208usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
 209usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
 210$(eval $(call usetemplate,c,dsl))
 211$(eval $(call usetemplate,objs,c))
 212$(eval $(call usetemplate,objs,S))
 213$(eval $(call usetemplate,initobjs,c))
 214$(eval $(call usetemplate,initobjs,S))
 215$(eval $(call usetemplate,drivers,c))
 216$(eval $(call usetemplate,drivers,S))
 217$(eval $(call usetemplate,smmobjs,c))
 218$(eval $(call usetemplate,smmobjs,S))
 219
 220printall:
 221        @echo objs:=$(objs)
 222        @echo initobjs:=$(initobjs)
 223        @echo drivers:=$(drivers)
 224        @echo smmobjs:=$(smmobjs)
 225        @echo alldirs:=$(alldirs)
 226        @echo allsrc=$(allsrc)
 227
 228OBJS     := $(patsubst %,$(obj)/%,$(TARGETS-y))
 229INCLUDES := -I$(top)/src -I$(top)/src/include -I$(obj) -I$(top)/src/arch/$(ARCHDIR-y)/include 
 230INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
 231INCLUDES += -I$(top)/util/x86emu/include
 232INCLUDES += -include $(obj)/build.h
 233
 234try-run= $(shell set -e; \
 235TMP=".$$$$.tmp"; \
 236if ($(1)) > /dev/null 2>&1; \
 237then echo "$(2)"; \
 238else echo "$(3)"; \
 239fi; rm -rf "$$TMP")
 240
 241cc-option= $(call try-run,\
 242$(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2))
 243
 244STACKPROTECT += $(call cc-option, -fno-stack-protector,)
 245
 246CFLAGS = $(STACKPROTECT) $(INCLUDES) -Os -nostdinc
 247CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
 248CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs 
 249CFLAGS += -Wstrict-aliasing -Wshadow 
 250CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
 251
 252CBFS_COMPRESS_FLAG:=l
 253CBFS_PAYLOAD_COMPRESS_FLAG:=
 254ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
 255CBFS_PAYLOAD_COMPRESS_FLAG:=l
 256endif
 257
 258coreboot: prepare prepare2 $(obj)/coreboot.rom
 259
 260endif
 261
 262prepare:
 263        mkdir -p $(obj)
 264        mkdir -p $(obj)/util/kconfig/lxdialog
 265        test -n "$(alldirs)" && mkdir -p $(alldirs) || true
 266
 267prepare2:
 268        @printf "    GEN        build.h\n"
 269        printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" > $(obj)/build.h
 270        printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.h
 271        printf "#define COREBOOT_V2 \"$(COREBOOT_V2)\"\n" >> $(obj)/build.h
 272        printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.h
 273        printf "\n" >> $(obj)/build.h
 274        printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.h
 275        printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.h
 276        printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.h
 277        printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.h
 278        printf "#define COREBOOT_COMPILE_BY \"$(shell PATH=$$PATH:/usr/ucb whoami)\"\n" >> $(obj)/build.h
 279        printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname)\"\n" >> $(obj)/build.h
 280        printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname)\"\n" >> $(obj)/build.h
 281        printf "#include \"config.h\"\n" >> $(obj)/build.h
 282
 283doxy: doxygen
 284doxygen:
 285        $(DOXYGEN) Doxyfile
 286
 287doxyclean: doxygen-clean
 288doxygen-clean:
 289        rm -rf $(DOXYGEN_OUTPUT_DIR)
 290
 291clean: doxygen-clean
 292        rm -f $(allobjs) $(obj)/coreboot*
 293        rm -f $(obj)/option_table.* $(obj)/crt0_includes.h $(obj)/ldscript
 294        rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
 295        rm -f $(obj)/mainboard/$(MAINBOARDDIR)/auto.inc $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
 296        rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
 297        $(MAKE) -C util/sconfig clean
 298
 299distclean: clean
 300        rm -rf $(obj) .xcompile
 301        rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig*
 302
 303update:
 304        dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
 305
 306# This include must come _before_ the pattern rules below!
 307# Order _does_ matter for pattern rules.
 308include util/kconfig/Makefile
 309
 310$(obj)/ldoptions: $(obj)/config.h
 311#       cat $(obj)/config.h  | grep -v \" |grep -v AUTOCONF_INCLUDED | grep \#define | sed s/\#define\ // | sed s/\ /\ =\ / | sed 's/$$/;/' > $(obj)/ldoptions
 312        awk '/^#define ([^"])* ([^"])*$$/ {print $$2 " = " $$3 ";";}' $< > $@
 313
 314$(obj)/romcc: $(top)/util/romcc/romcc.c
 315        @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
 316        $(HOSTCC) -g -O2 -Wall -o $@ $<
 317
 318.PHONY: $(PHONY) prepare prepare2 clean distclean doxygen doxy coreboot
 319
 320
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.