#
#   
#
# Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
#

# Build configuration for linux_arm. The build host is a Linux/x86 PC,
# the build target is a Linux/ARM device.
#
# Use the GNU_TOOLS_DIR environment variable to choose the cross
# compiler for the device you want to compile for. For example,
# if your system installs the cross compilers at:
#
#   /micro/tools/i686-redhat-linux/gnu/arm-netwinder-linux
#   /micro/tools/i686-redhat-linux/gnu/arm-zaurus-linux
#   /micro/tools/i686-redhat-linux/gnu/arm-familiar-linux
#
# To choose to compile for zaurus, the command line would be
#
#   setenv GNU_TOOLS_DIR /micro/tools/i686-redhat-linux/gnu/arm-zaurus-linux
#   gnumake

ifndef GNU_TOOLS_DIR 
ifeq ($(ENABLE_THUMB_VM), true)
GNU_TOOLS_DIR = /opt/thumb/arm-linux
else
GNU_TOOLS_DIR = /micro/tools/i686-redhat-linux/gnu/arm-netwinder-linux
endif
endif

#----------------------------------------------------------------------
# Host configuration. Note that Solaris hosts are tagged as 'linux'
#----------------------------------------------------------------------
archExpr = case "`uname -m`" in  \
            i[3-6]86) \
                echo i386 \
                ;; \
            i86pc) \
                echo i386 \
                ;; \
            sparc*)  \
                echo sparc \
                ;; \
            sun4u) \
                echo sparc \
                ;; \
            *) \
                uname -m  \
                ;; \
          esac
host_arch = $(shell $(archExpr) )

osExpr = case "`uname`" in  \
            Linux) \
                echo linux \
                ;; \
            SunOS) \
                echo solaris \
                ;; \
            *) \
                uname  \
                ;; \
          esac
host_os = $(shell $(osExpr) )

ifneq ($(IsTarget), true)
    ifeq ($(host_os), solaris)
        CPP_DEF_FLAGS += -DSOLARIS -munaligned-doubles
        LINK_FLAGS    += -lsocket -lnsl -lposix4 
    endif

    ifeq ($(host_arch), sparc)
        export HOST_LITTLE_ENDIAN := false
    endif
endif

#----------------------------------------------------------------------

LOOP_GEN_FLAGS = +GenerateGNUCode
ROM_GEN_FLAGS  = +GenerateGNUCode

ifndef ENABLE_TIMER_THREAD
ifeq ($(ENABLE_THUMB_VM), true)
export ENABLE_TIMER_THREAD     = false
else
export ENABLE_TIMER_THREAD     = true
endif
export ENABLE_TIMER_THREAD__BY = linux_arm.cfg
endif

ifneq ($(ENABLE_FLOAT), false)
ifndef ENABLE_SOFT_FLOAT
export ENABLE_SOFT_FLOAT     = true
export ENABLE_SOFT_FLOAT__BY = linux_arm.cfg
endif
endif

ifeq ($(IsLoopGen),true)
    # LoopGen: an a.out that runs on the HOST. It has
    # an ARM assembler loop generator and will generate the ARM
    # assembler loop.
    os_family = linux
    arch      = arm
    compiler  = gcc

    export MSW_FIRST_FOR_DOUBLE     := true
    export MSW_FIRST_FOR_DOUBLE__BY := linux_arm.cfg

    CPP_DEF_FLAGS += -DARM -DCROSS_GENERATOR=1

    ifeq ($(host_arch), sparc)
        CPP_DEF_FLAGS += -DSPARC
    endif
endif

ifeq ($(IsRomGen),true)
    # RomGem: an a.out that runs on the HOST. It has
    # C interpreter loop. It runs on the HOST to
    # generate the (machine independent) ROM.cpp file.
    os_family = linux
    arch      = c
    compiler  = gcc

    ifeq ($(host_arch), sparc)
        export HARDWARE_LITTLE_ENDIAN := false
        CPP_DEF_FLAGS += -DSPARC -DHARDWARE_LITTLE_ENDIAN=0
    else
        export MSW_FIRST_FOR_DOUBLE     := false
        export MSW_FIRST_FOR_DOUBLE__BY := linux_arm.cfg
    endif

    # AOT-related settings
    export ENABLE_C_INTERPRETER            := true
    export ENABLE_C_INTERPRETER__BY        := linux_arm.cfg
    export ENABLE_INTERPRETER_GENERATOR    := false
    export ENABLE_INTERPRETER_GENERATOR__BY:= linux_arm.cfg
    export TARGET_MSW_FIRST_FOR_DOUBLE     := true
    export TARGET_MSW_FIRST_FOR_DOUBLE__BY := linux_arm.cfg
    export TARGET_MSW_FIRST_FOR_LONG       := false
    export TARGET_MSW_FIRST_FOR_LONG__BY   := linux_arm.cfg
    carch                                   = arm
    iarch                                   = c
    CPP_DEF_FLAGS                          += -DARM -DCROSS_GENERATOR=1
endif

ifeq ($(IsTarget),true)
    # target/{cldc_vm, cldc_vm_r, cldc_vm_g}.
    # These are pure Linux/ARM binaries that run on the TARGET.
    os_family = linux
    arch      = arm
    compiler  = gcc

    # Turn off ROM and INTERPRETER generators if possible to reduce size
    # of release and product builds
    ifneq (${ENABLE_MONET}, true)
    ifndef ENABLE_ROM_GENERATOR
    export ENABLE_ROM_GENERATOR             = false
    export ENABLE_ROM_GENERATOR__BY         = linux_arm.cfg
    endif
    endif
    ifndef ENABLE_INTERPRETER_GENERATOR
    export ENABLE_INTERPRETER_GENERATOR     = false
    export ENABLE_INTERPRETER_GENERATOR__BY = linux_arm.cfg
    endif

    export MSW_FIRST_FOR_DOUBLE     := true
    export MSW_FIRST_FOR_DOUBLE__BY := linux_arm.cfg

    CPP_DEF_FLAGS += -DARM
    
    ifeq ($(ENABLE_SOFT_FLOAT), true)
        ifneq ($(ENABLE_ARM_VFP), true)
            CPP_DEF_FLAGS += -msoft-float
            ASM_FLAGS += -mno-fpu
            LINK_FLAGS += -Xlinker --no-warn-mismatch
        endif
    endif

    ifeq ($(ENABLE_OMAP), true)
	LINK_FLAGS += -Xlinker -static
    endif

    ifeq ($(ENABLE_THUMB_VM), true)

        THUMB_CFLAGS            = -mthumb -mthumb-interwork
        ARM_CFLAGS              = -mthumb-interwork

        ASM_FLAGS              += -mthumb-interwork
        LINK_FLAGS             += -mthumb-interwork

        LOOP_GEN_FLAGS         += +GenerateThumbInterwork

    else
        ifneq ($(ENABLE_THUMB_COMPILER), true)
            #CPP_DEF_FLAGS += -mcpu=strongarm
            #LINK_FLAGS    += -mcpu=strongarm
         endif
    endif

    ifeq ($(BAREBONE_LINUX_TARGET), true)
    CPP_DEF_FLAGS += -DSUPPORTS_MEMORY_MAPPED_FILES=0 \
                     -DSUPPORTS_ADJUSTABLE_MEMORY_CHUNK=0 \
                     -DSUPPORTS_TIMER_THREAD=0
    endif
endif

ifndef MERGE_SOURCE_FILES
MERGE_SOURCE_FILES  = true
endif

ifndef SOURCE_MERGER_SIZE
SOURCE_MERGER_SIZE  = 35
endif

export BUILD_ANI_LIB := true

# The following is to get linux_thumb to build on linux_bvd board
ifeq ($(ALWAYS_LSW_FIRST_FOR_DOUBLE), true)
    export MSW_FIRST_FOR_DOUBLE            := false
    export MSW_FIRST_FOR_DOUBLE__BY        := linux_bvd.cfg
    export TARGET_MSW_FIRST_FOR_DOUBLE     := false
    export TARGET_MSW_FIRST_FOR_DOUBLE__BY := linux_bvd.cfg
endif
