--------------------------------------------------------------------------
-- Copyright (c) 2016, ETH Zurich.
-- All rights reserved.
--
-- This file is distributed under the terms in the attached LICENSE file.
-- If you do not find this file, copies can be found by writing to:
-- ETH Zurich D-INFK, Universitaetstrasse 4, CH-8092 Zurich. Attn: Systems Group.
--
-- Hakefile for /lib/compiler-rt/test
--
--------------------------------------------------------------------------

let
  builtins_unittest_files = [
      "absvdi2_test.c",
      "absvsi2_test.c",
      "absvti2_test.c",
      "adddf3vfp_test.c",
      "addsf3vfp_test.c",
      "addtf3_test.c",
      "addvdi3_test.c",
      "addvsi3_test.c",
      "addvti3_test.c",
      "ashldi3_test.c",
      "ashlti3_test.c",
      "ashrdi3_test.c",
      "ashrti3_test.c",
      "bswapdi2_test.c",
      "bswapsi2_test.c",
      -- "clear_cache_test.c",
      "clzdi2_test.c",
      "clzsi2_test.c",
      "clzti2_test.c",
      "cmpdi2_test.c",
      "cmpti2_test.c",
      "comparedf2_test.c",
      "comparesf2_test.c",
      "compiler_rt_logb_test.c",
      "compiler_rt_logbf_test.c",
      "compiler_rt_logbl_test.c",
      "cpu_model_test.c",
      "ctzdi2_test.c",
      "ctzsi2_test.c",
      "ctzti2_test.c",
      "divdc3_test.c",
      "divdf3_test.c",
      "divdf3vfp_test.c",
      "divdi3_test.c",
      "divmodsi4_test.c",
      "divsc3_test.c",
      "divsf3_test.c",
      "divsf3vfp_test.c",
      "divsi3_test.c",
      -- "divtc3_test.c", error: conflicting types for built-in function '__divtc3' [-Werror=builtin-declaration-mismatch]
      "divtf3_test.c",
      "divti3_test.c",
      "divxc3_test.c",
      -- "enable_execute_stack_test.c",
      "eqdf2vfp_test.c",
      "eqsf2vfp_test.c",
      "eqtf2_test.c",
      "extebdsfdf2vfp_test.c",
      "extenddftf2_test.c",
      -- "extendhfsf2_test.c",
      "extendsftf2_test.c",
      "ffsdi2_test.c",
      "ffssi2_test.c",
      "ffsti2_test.c",
      "fixdfdi_test.c",
      "fixdfsivfp_test.c",
      "fixdfti_test.c",
      "fixsfdi_test.c",
      "fixsfsivfp_test.c",
      "fixsfti_test.c",
      "fixtfdi_test.c",
      "fixtfsi_test.c",
      "fixtfti_test.c",
      "fixunsdfdi_test.c",
      "fixunsdfsi_test.c",
      "fixunsdfsivfp_test.c",
      "fixunsdfti_test.c",
      "fixunssfdi_test.c",
      "fixunssfsi_test.c",
      "fixunssfsivfp_test.c",
      "fixunssfti_test.c",
      "fixunstfdi_test.c",
      "fixunstfsi_test.c",
      "fixunstfti_test.c",
      "fixunsxfdi_test.c",
      "fixunsxfsi_test.c",
      "fixunsxfti_test.c",
      "fixxfdi_test.c",
      "fixxfti_test.c",
      "floatdidf_test.c",
      "floatdisf_test.c",
      "floatditf_test.c",
      "floatdixf_test.c",
      "floatsidfvfp_test.c",
      "floatsisfvfp_test.c",
      "floatsitf_test.c",
      "floattidf_test.c",
      "floattisf_test.c",
      "floattitf_test.c",
      "floattixf_test.c",
      "floatundidf_test.c",
      "floatundisf_test.c",
      "floatunditf_test.c",
      "floatundixf_test.c",
      "floatunsitf_test.c",
      "floatunssidfvfp_test.c",
      "floatunssisfvfp_test.c",
      "floatuntidf_test.c",
      "floatuntisf_test.c",
      "floatuntitf_test.c",
      "floatuntixf_test.c",
      "gedf2vfp_test.c",
      "gesf2vfp_test.c",
      "getf2_test.c",
      "gtdf2vfp_test.c",
      "gtsf2vfp_test.c",
      "gttf2_test.c",
      "ledf2vfp_test.c",
      "lesf2vfp_test.c",
      "letf2_test.c",
      "lshrdi3_test.c",
      "lshrti3_test.c",
      "ltdf2vfp_test.c",
      "ltsf2vfp_test.c",
      "lttf2_test.c",
      "moddi3_test.c",
      "modsi3_test.c",
      "modti3_test.c",
      "muldc3_test.c",
      "muldf3vfp_test.c",
      "muldi3_test.c",
      "mulodi4_test.c",
      "mulosi4_test.c",
      "muloti4_test.c",
      "mulsc3_test.c",
      "mulsf3vfp_test.c",
      "multc3_test.c",
      "multf3_test.c",
      "multi3_test.c",
      "mulvdi3_test.c",
      "mulvsi3_test.c",
      "mulvti3_test.c",
      "mulxc3_test.c",
      "nedf2vfp_test.c",
      "negdf2vfp_test.c",
      "negdi2_test.c",
      "negsf2vfp_test.c",
      "negti2_test.c",
      "negvdi2_test.c",
      "negvsi2_test.c",
      "negvti2_test.c",
      "nesf2vfp_test.c",
      "netf2_test.c",
      "paritydi2_test.c",
      "paritysi2_test.c",
      "parityti2_test.c",
      "popcountdi2_test.c",
      "popcountsi2_test.c",
      "popcountti2_test.c",
      "powidf2_test.c",
      "powisf2_test.c",
      "powitf2_test.c",
      "powixf2_test.c",
      "subdf3vfp_test.c",
      "subsf3vfp_test.c",
      "subtf3_test.c",
      "subvdi3_test.c",
      "subvsi3_test.c",
      "subvti3_test.c",
      "trampoline_setup_test.c",
      -- "truncdfhf2_test.c",
      "truncdfsf2_test.c",
      "truncdfsf2vfp_test.c",
      -- "truncsfhf2_test.c",
      "trunctfdf2_test.c",
      "trunctfsf2_test.c",
      "ucmpdi2_test.c",
      "ucmpti2_test.c",
      "udivdi3_test.c",
      "udivmoddi4_test.c",
      "udivmodsi4_test.c",
      "udivmodti4_test.c",
      "udivsi3_test.c",
      "udivti3_test.c",
      "umoddi3_test.c",
      "umodsi3_test.c",
      "umodti3_test.c",
      "unorddf2vfp_test.c",
      "unordsf2vfp_test.c",
      "unordtf2_test.c"
    ]

  common_cFlags = [
    "-Wno-missing-prototypes",
    "-Wno-missing-declarations",
    "-Wno-strict-prototypes",
    "-Wno-old-style-definition",
    "-Wno-redundant-decls"
    ]

  arch_cFlags arch = case arch of "x86_64"  -> common_cFlags
                                  "k1om"    -> common_cFlags
                                  "armv7"   -> common_cFlags ++ [ "-D__ARM_EABI__" ]
                                  "armv8"   -> common_cFlags

  builtins_unittest_dir = "test/builtins/Unit/"

in [ build application {
        target = "compiler-rt/" ++ builtins_unittest_dir ++
                                   (take ((length f) - 2) f),
        cFiles = [ f ],
        addCFlags = arch_cFlags arch,
        addLibraries = libDeps [
            "compiler-rt",
            "m"
        ],
        architectures = [
            arch
        ],
        addIncludes = [
            "/lib/compiler-rt/builtins/"
        ]
    } | f <- builtins_unittest_files, arch <- allArchitectures ]  ++ [

    build application {
      target = "compiler-rt/" ++ builtins_unittest_dir ++ "gcc_personality_test",
        cxxFiles = ["gcc_personality_test_helper.cxx"],
        cFiles = [ "gcc_personality_test.c" ],
        addCFlags = arch_cFlags arch,
        addLibraries = libDeps [
            "compiler-rt",
            "m"
        ],
        architectures = [
            arch
        ],
        addIncludes = [
            "/lib/compiler-rt/builtins/"
        ]
    } |  arch <- allArchitectures]
