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

#----------------------------------------------------------------------
# This file contains common definitions for the build/ads_*/
# directories.
#----------------------------------------------------------------------

# If the makefile guess incorrectly, set ADS_LINUX_HOST explicitly in
# your environment.
ifndef ADS_LINUX_HOST
ifneq (${OS}, Windows_NT)
ADS_LINUX_HOST = true
endif
endif

ifneq ($(ADS_LINUX_HOST), true)
    #
    # Rules for win32-hosted build
    #
    ifeq ($(ADS_CYGWIN_HOST), true)
	host_os        = cygwin
	host_arch      = i386
	os_family      = win32
	host_compiler  = gcc

        ifndef MERGE_SOURCE_FILES
            MERGE_SOURCE_FILES   = true
        endif

        ifndef SOURCE_MERGER_SIZE
            SOURCE_MERGER_SIZE   = 35
        endif

    else
	host_os        = win32
	host_arch      = i386
	os_family      = win32
	host_compiler  = visCPP
    endif
    CPP_DEF_FLAGS += -DADS_LINUX_HOST=0
else
    #
    # Rules for linux- or solaris-hosted builds.
    #
    os_family            = linux
    host_compiler        = gcc

    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

        ifndef MERGE_SOURCE_FILES
            MERGE_SOURCE_FILES   = true
        endif

        ifndef SOURCE_MERGER_SIZE
            SOURCE_MERGER_SIZE   = 35
        endif

        # Always disable timer thread on Unices
        export ENABLE_TIMER_THREAD     := false
        export ENABLE_TIMER_THREAD__BY := generic_ads.cfg

        CPP_DEF_FLAGS += -DADS_LINUX_HOST=1
    endif
endif

#----------------------------------------------------------------------
# The following two flags tells jvm.make to include the alternative
# platform/compiler makefiles:
#
# $(JVMWorkSpace)/build/ads/alt_platform.make
# $(JVMWorkSpace)/build/ads/alt_compiler.make
#----------------------------------------------------------------------
ALT_PLATFORM = ads
ALT_COMPILER = ads

#----------------------------------------------------------------------
# LoopGen: an .exe that runs on the HOST. It has an ARM assembler loop
# generator and will generate the ARM assembler loop.
#----------------------------------------------------------------------
ifeq ($(IsLoopGen),true)   
    arch               = arm
    compiler           = $(host_compiler)
    CPP_DEF_FLAGS      += -DARM -DCROSS_GENERATOR=1

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

    ifndef ENABLE_SOFT_FLOAT
    export ENABLE_SOFT_FLOAT     = true
    export ENABLE_SOFT_FLOAT__BY = generic_ads.cfg
    endif
endif

#----------------------------------------------------------------------
# RomGen: an .exe that runs on the HOST. It has an i386 assembler or C
# loop. It runs on the HOST to generate ROMImage.cpp.
#----------------------------------------------------------------------
ifeq ($(IsRomGen),true)
    ifeq ($(host_arch), sparc)
        export HARDWARE_LITTLE_ENDIAN := false
        CPP_DEF_FLAGS += -DSPARC -DHARDWARE_LITTLE_ENDIAN=0
    endif

    export ENABLE_C_INTERPRETER             := true
    export ENABLE_C_INTERPRETER__BY         := generic_ads.cfg
    export ENABLE_INTERPRETER_GENERATOR     := false
    export ENABLE_INTERPRETER_GENERATOR__BY := generic_ads.cfg
    # SOFT_FLOAT is enabled to have GP offsets in romgen the same as
    # those at run-time.
    ifndef ENABLE_SOFT_FLOAT
    export ENABLE_SOFT_FLOAT                := true
    export ENABLE_SOFT_FLOAT__BY            := generic_ads.cfg
    endif
    override arch                           := c
    carch                                    = arm
    iarch                                    = c
    CPP_DEF_FLAGS                           += -DARM -DCROSS_GENERATOR=1

    compiler                                 = $(host_compiler)
    ROM_GEN_FLAGS                            =

    ifeq ($(ADS_LINUX_HOST),true)
        LOOP_GEN_ARG   = +GenerateGNUCode +GenerateAssemblyCode
    endif

    ifeq ($(ADS_CYGWIN_HOST), true)
        LOOP_GEN_ARG   = +GenerateGNUCode  +AddExternCUnderscore \
                         +GenerateAssemblyCode
    endif

    ifneq ($(ADS_BIG_ENDIAN_TARGET), "true")
    export TARGET_MSW_FIRST_FOR_LONG        := false
    export TARGET_MSW_FIRST_FOR_LONG__BY    := generic_ads.cfg
    export TARGET_MSW_FIRST_FOR_DOUBLE      := false
    export TARGET_MSW_FIRST_FOR_DOUBLE__BY  := generic_ads.cfg
    endif
endif

#----------------------------------------------------------------------
# Target: target/bin/{cldc_vm.axf, cldc_vm_r.axf, cldc_vm_g.axf}.
# These are pure ADS/ARM binaries that run on the TARGET.
#----------------------------------------------------------------------
ifeq ($(IsTarget),true)
    os_family = ads
    arch      = arm
    compiler  = ads


    # 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         = generic_ads.cfg
    endif
    endif
    ifndef ENABLE_INTERPRETER_GENERATOR
    export ENABLE_INTERPRETER_GENERATOR     = false
    export ENABLE_INTERPRETER_GENERATOR__BY = generic_ads.cfg
    endif

    ifndef ENABLE_SOFT_FLOAT
    export ENABLE_SOFT_FLOAT     = true
    export ENABLE_SOFT_FLOAT__BY = generic_ads.cfg
    endif

    ifndef MERGE_SOURCE_FILES
           MERGE_SOURCE_FILES  = true
    endif

    ifndef SOURCE_MERGER_SIZE
           SOURCE_MERGER_SIZE  = 35
    endif

    ifeq ($(ENABLE_THUMB_VM), true)
        LOOP_GEN_FLAGS += +GenerateThumbInterwork
    endif

    ifeq ($(ENABLE_SOFT_FLOAT), true)
        CPP_DEF_FLAGS +=
        LINK_FLAGS    += 
    endif

    # Always disable timer thread on ads
    export ENABLE_TIMER_THREAD     := false
    export ENABLE_TIMER_THREAD__BY := generic_ads.cfg
endif
