###############################################################################
#
# MN10300 Kernel makefile system specifications
#
# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
# Modified by David Howells (dhowells@redhat.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public Licence
# as published by the Free Software Foundation; either version
# 2 of the Licence, or (at your option) any later version.
#
###############################################################################

#KBUILD_DEFCONFIG := asb2303_defconfig
KBUILD_DEFCONFIG :=

CCSPECS	:= $(shell $(CC) -v 2>&1 | grep "^Reading specs from " | head -1 | cut -c20-)
CCDIR	:= $(strip $(patsubst %/specs,%,$(CCSPECS)))
KBUILD_CPPFLAGS += -nostdinc -I$(CCDIR)/include

LDFLAGS		:=
OBJCOPYFLAGS	:= -O binary -R .note -R .comment -R .GCC-command-line -R .note.gnu.build-id -S
#LDFLAGS_vmlinux := -Map linkmap.txt
CHECKFLAGS	+=

PROCESSOR	:= unset
UNIT		:= unset

KBUILD_CFLAGS	+= -mam33 -DCPU=AM33
KBUILD_AFLAGS	+= -mam33 -DCPU=AM33

ifeq ($(CONFIG_MN10300_CURRENT_IN_E2),y)
KBUILD_CFLAGS	+= -ffixed-e2 -fcall-saved-e5
endif

ifeq ($(CONFIG_MN10300_PROC_MN103E010),y)
PROCESSOR	:= mn103e010
endif
ifeq ($(CONFIG_MN10300_PROC_MN2WS0030),y)
PROCESSOR	:= mn2ws0030
endif
ifeq ($(CONFIG_MN10300_PROC_MN2WS0038),y)
PROCESSOR	:= mn2ws0038
endif
ifeq ($(CONFIG_MN10300_PROC_MN2WS0050),y)
PROCESSOR	:= mn2ws0050
endif
ifeq ($(CONFIG_MN10300_PROC_MN2WS0044),y)
PROCESSOR	:= mn2ws0044
endif
ifeq ($(CONFIG_MN10300_PROC_MN2WS0120),y)
PROCESSOR	:= mn2ws0120
endif
ifeq ($(CONFIG_MN10300_PROC_MN2WS0140),y)
PROCESSOR	:= mn2ws0140
endif
ifeq ($(CONFIG_MN10300_PROC_MN2WS0150),y)
PROCESSOR	:= mn2ws0150
endif
ifeq ($(CONFIG_MN10300_PROC_MN2WS0170),y)
PROCESSOR	:= mn2ws0170
endif
ifeq ($(CONFIG_MN10300_PROC_MN2WS0210),y)
PROCESSOR	:= mn2ws0210
endif

ifeq ($(CONFIG_MN10300_UNIT_ASB2303),y)
UNIT		:= asb2303
endif
ifeq ($(CONFIG_MN10300_UNIT_ASB2305),y)
UNIT		:= asb2305
endif
ifeq ($(CONFIG_MN10300_UNIT_ASB2360),y)
UNIT		:= asb2360
endif
ifeq ($(CONFIG_MN10300_UNIT_PH1REF_PRO2),y)
UNIT		:= ph1ref_pro2
endif
ifeq ($(CONFIG_MN10300_UNIT_PRO2REF),y)
UNIT		:= pro2ref
endif
ifeq ($(CONFIG_MN10300_UNIT_LIEGE_GP),y)
UNIT		:= liege_gp
endif
ifeq ($(CONFIG_MN10300_UNIT_ASB2364),y)
UNIT		:= asb2364
endif
ifeq ($(CONFIG_MN10300_UNIT_CHIFFON),y)
UNIT		:= chiffon
endif
ifeq ($(CONFIG_MN10300_UNIT_SSBP1),y)
UNIT		:= ssbp1
endif
ifeq ($(CONFIG_MN10300_UNIT_PH1REF_PRO3),y)
UNIT		:= ph1ref_pro3
endif
ifeq ($(CONFIG_MN10300_UNIT_M1890),y)
UNIT		:= m1890
endif
ifeq ($(CONFIG_MN10300_UNIT_SSBP2),y)
UNIT		:= ssbp2
endif
ifeq ($(CONFIG_MN10300_UNIT_SSBP3),y)
UNIT		:= ssbp3
endif
ifeq ($(CONFIG_MN10300_UNIT_CHIFFON2),y)
UNIT		:= chiffon2
endif

head-y		:= arch/mn10300/kernel/head.o arch/mn10300/kernel/init_task.o

core-y		+= arch/mn10300/kernel/ arch/mn10300/mm/

ifneq ($(PROCESSOR),unset)
core-y		+= arch/mn10300/proc-$(PROCESSOR)/
endif
ifneq ($(UNIT),unset)
core-y		+= arch/mn10300/unit-$(UNIT)/
endif
libs-y		+= arch/mn10300/lib/

drivers-$(CONFIG_OPROFILE)	+= arch/mn10300/oprofile/

boot := arch/mn10300/boot

.PHONY: zImage

KBUILD_IMAGE := $(boot)/zImage

zImage: vmlinux
	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@

all: zImage

bootstrap:
	$(Q)$(MAKEBOOT) bootstrap

archclean:
	$(Q)$(MAKE) $(clean)=$(boot)

install: vmlinux
	$(Q)$(MAKE) $(build)=$(boot) PROCESSOR=$(PROCESSOR) UNIT=$(UNIT) $@ 

define archhelp
  echo  '* zImage        - Compressed kernel image (arch/$(ARCH)/boot/zImage)'
endef

# If you make sure the .S files get compiled with debug info,
# uncomment the following to disable optimisations
# that are unhelpful whilst debugging.
ifdef CONFIG_DEBUG_INFO
#KBUILD_CFLAGS	+= -O1
KBUILD_AFLAGS	+= -Wa,--gdwarf2
endif

#
# include the appropriate processor- and unit-specific headers
#
KBUILD_CPPFLAGS += -I$(srctree)/arch/mn10300/proc-$(PROCESSOR)/include
KBUILD_CPPFLAGS += -I$(srctree)/arch/mn10300/unit-$(UNIT)/include
