# Makefile
#
# Name       History
# Ken        Initiated the recursive makefile structure
# Ken        Imported configurations from the old makefile
# Ken        Supported one "make" to do a build instead of "make <menuconfig>; make"
# Ken        "make" is supported to do a build
# Ken        "make rootfs-path.env; make" is supported to do a build
# Ken        "make distclean; make" is supported to do a fresh build
# Ken        "make clean; make" is supported to do a rebuild
# Ken        "make install" is supported to do a build like a "make"
# Ken        "make uninstall; make install" is supported to do a reinstallation
# Ken        "make config-clean; make menuconfig" is supported to do a reconfiguration
#
#
# Contact Info:
# <ken_zhai@sdesigns.com>
#
# Sigma Designs
# 1778 McCarthy BLVD
# Milpitas CA 95035, USA
#
SHELL:=bash
#--------------------------------------------------------------
# 'make menuconfig' is for an advance user and less used.
#--------------------------------------------------------------
TOPDIR=.
CONFIG_CONFIG_IN:=Config.in
CONFIG_DEFCONFIG:=.defconfig
CONFIG_DOTCONFIG:=.config
CONFIG:=package/config
RMDIR:=$(RM) -r
MAKEFILE_PATH:=.makefile.in
ENV_FILE:=rootfs-path.env
FILELIST:=$(shell find . -perm 600)

noconfig_targets := menuconfig config oldconfig defconfig allyesconfig

# Check COMPILKIND to see if release mode or debug mode to be used
ifeq '$(filter release, $(COMPILKIND))' ''
ifeq '$(filter debug, $(COMPILKIND))' ''
$(warning Both release and debug are not specified in COMPILKIND)
$(warning The default setting 'release' is used)
endif
else
ifneq '$(filter debug, $(COMPILKIND))' ''
$(warning Both release and debug are specified in COMPILKIND)
$(warning The default setting 'release' is used)
endif
endif

# Check COMPILKIND to see which libc runtime to be used
ifeq '$(filter uclibc, $(COMPILKIND))' ''
ifeq '$(filter glibc, $(COMPILKIND))' ''
$(warning Please specify libc runtime in COMPILKIND: uclibc or glibc)
$(warning Otherwise, the default setting 'glibc' is used)
endif
else
ifneq '$(filter glibc, $(COMPILKIND))' ''
$(warning Both uclibc and glibc are specified in COMPILKIND)
$(warning The default setting 'glibc' is used)
endif
endif

# Check COMPILKIND to see which floating point mode to be used
ifeq '$(filter hardfloat, $(COMPILKIND))' ''
ifeq '$(filter softfloat, $(COMPILKIND))' ''
$(warning Please specify floating point mode in COMPILKIND: hardfloat or softfloat)
$(warning Otherwise, the default setting 'hardfloat' is used)
endif
else
ifneq '$(filter softfloat, $(COMPILKIND))' ''
$(warning Both hardfloat and softfloat are specified in COMPILKIND)
$(warning The default setting 'hardfloat' is used)
endif
endif

ifneq '$(wildcard $(CONFIG_DOTCONFIG))' '$(CONFIG_DOTCONFIG)'
$(shell cp $(CONFIG_DEFCONFIG) $(CONFIG_DOTCONFIG))
endif

CS_MIPS_GCC:=mips-linux-gnu-gcc
CS_MIPS_GCC_VERSION:="gcc version"
ifneq '$(shell $(CS_MIPS_GCC) -v 2>&1 | grep $(CS_MIPS_GCC_VERSION))' ''
CSTOOLCHAIN_VERSION:="$(shell $(CS_MIPS_GCC) -v 2>&1 | grep $(CS_MIPS_GCC_VERSION))"
SMP86XX_TOOLCHAIN_PATH:="$(shell which mips-linux-gnu-gcc | sed 's/\/\/*/\//g' | sed 's/\(.*\)\/bin\/mips-linux-gnu-gcc/\1/g')"
export SMP86XX_TOOLCHAIN_PATH
else
$(warning You have no codesourcery toolchain in your PATH)
$(warning Please specify your toolchain path, for instance)
$(warning *** 1. export SMP86XX_TOOLCHAIN_PATH=/utils/gcc/4.3.2/codesourcery/i386)
$(error 2. export PATH=$$SMP86XX_TOOLCHAIN_PATH/bin:$$PATH)
endif

-include makeconfig
