language: c

matrix:
  include:
  - os: linux
    compiler: clang
  - os: linux
    compiler: gcc
  - os: osx
  - os: linux
    dist: trusty
    env:
    - MAKEFILE_TARGET=distcheck
    - AUTOMAKE_VER=1.15
    - M4_VER=1.4.18
    - LIBTOOL_VER=2.4.6
  - os: linux
    env:
    - MAKEFILE_TARGET=dist
  - os: linux
    compiler: clang
    env:
    - CFLAGS_EXTRA="-O3 -march=native"
    - CONF_OPTIONS="--enable-assertions"
  - os: linux
    compiler: gcc
    env:
    - CFLAGS_EXTRA="-O3 -march=native"
    - CONF_OPTIONS="--enable-assertions"
  - os: osx
    env:
    - CFLAGS_EXTRA="-O3 -march=native -D AO_USE_ALMOST_LOCK_FREE"
    - CONF_OPTIONS="--enable-assertions"
  - os: linux
    compiler: clang
    dist: trusty
    env:
    - CFLAGS_EXTRA="-march=native -std=c11"
  - os: linux
    compiler: gcc
    env:
    - CFLAGS_EXTRA="-march=native -D _FORTIFY_SOURCE=2 -std=c89"
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    compiler: clang
    env:
    - CFLAGS_EXTRA="-m32 -march=native"
    - CONF_OPTIONS="--enable-assertions"
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    compiler: clang
    env:
    - CFLAGS_EXTRA="-m32 -march=native"
    - CONF_OPTIONS="--disable-atomic-intrinsics"
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    compiler: gcc
    env:
    - CFLAGS_EXTRA="-m32 -march=native -D AO_USE_ALMOST_LOCK_FREE"
    - CONF_OPTIONS="--enable-assertions"
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    compiler: gcc
    env:
    - CFLAGS_EXTRA="-m32 -march=native"
    - CONF_OPTIONS="--disable-atomic-intrinsics"
  - os: osx
    env:
    - CFLAGS_EXTRA="-m32 -march=native -D _FORTIFY_SOURCE=2"
    - CONF_OPTIONS="--enable-assertions"
  - os: linux
    compiler: gcc
    env:
    - CFLAGS_EXTRA="-D AO_GENERALIZE_ASM_BOOL_CAS -D AO_USE_NANOSLEEP -D AO_USE_NO_SIGNALS"
    - CONF_OPTIONS="--enable-assertions"
  - os: linux
    compiler: clang
    env:
    - CFLAGS_EXTRA="-D AO_STACK_PREFER_CAS_DOUBLE -D AO_USE_PTHREAD_DEFS"
    - CONF_OPTIONS="--enable-assertions"
  - os: linux
    compiler: clang
    env:
    - CFLAGS_EXTRA="-D DONT_USE_MMAP -O3"
    - CONF_OPTIONS="--enable-assertions --enable-shared"
  - os: linux
    addons:
      apt:
        packages:
        - clang-4.0
        sources:
        - llvm-toolchain-trusty-4.0
    compiler: clang-4.0
    dist: trusty
    env:
    - CFLAGS_EXTRA="-O3 -march=native -std=c11 -D AO_BL_SIZE=4 -D DEFAULT_NTHREADS=32"
  - os: linux
    addons:
      apt:
        packages:
        - clang-4.0
        - gcc-multilib
        sources:
        - llvm-toolchain-trusty-4.0
    compiler: clang-4.0
    dist: trusty
    env:
    - CFLAGS_EXTRA="-m32 -O3 -march=native"
  - os: linux
    addons:
      apt:
        packages:
        - gcc-5
        sources:
        - ubuntu-toolchain-r-test
    compiler: gcc-5
    dist: trusty
    env:
    - CFLAGS_EXTRA="-O3 -march=native"
  - os: linux
    addons:
      apt:
        packages:
        - gcc-5
        - gcc-5-multilib
        sources:
        - ubuntu-toolchain-r-test
    compiler: gcc-5
    dist: trusty
    env:
    - CFLAGS_EXTRA="-m32 -O3 -march=native"
  - os: linux
    addons:
      apt:
        packages:
        - gcc-5
        - gcc-5-multilib
        sources:
        - ubuntu-toolchain-r-test
    compiler: gcc-5
    dist: trusty
    env:
    - CFLAGS_EXTRA="-mx32 -march=native -D _FORTIFY_SOURCE=2"
    - CONF_OPTIONS="--enable-assertions --enable-shared"
  - os: linux
    addons:
      apt:
        packages:
        - gcc-5
        - gcc-5-multilib
        sources:
        - ubuntu-toolchain-r-test
    compiler: gcc-5
    dist: trusty
    env:
    - CFLAGS_EXTRA="-mx32 -march=native"
    - CONF_OPTIONS="--disable-atomic-intrinsics --disable-docs"
  - os: linux
    compiler: clang
    env:
    - CFLAGS_EXTRA="-fsanitize=address -D AO_USE_ALMOST_LOCK_FREE -fno-omit-frame-pointer"
    - TESTS_CUSTOM_RUN=true
  - os: linux
    addons:
      apt:
        packages:
        - clang-4.0
        sources:
        - llvm-toolchain-trusty-4.0
    compiler: clang-4.0
    env:
    - CFLAGS_EXTRA="-fsanitize=address -march=native -fno-common -fno-omit-frame-pointer"
    - CONF_OPTIONS="--enable-assertions"
  - os: linux
    compiler: gcc
    env:
    - CFLAGS_EXTRA="-fsanitize=address -fno-omit-frame-pointer -D AO_USE_ALMOST_LOCK_FREE -D USE_STANDARD_MALLOC"
    - CONF_OPTIONS="--enable-assertions"
  - os: linux
    addons:
      apt:
        packages:
        - gcc-5
        - gcc-5-multilib
        sources:
        - ubuntu-toolchain-r-test
    compiler: gcc-5
    dist: trusty
    env:
    - CFLAGS_EXTRA="-fsanitize=address -m32 -march=native -fno-omit-frame-pointer"
    - LDFLAGS="-fuse-ld=gold"
  - os: osx
    env:
    - CFLAGS_EXTRA="-fsanitize=address -m32 -fno-omit-frame-pointer"
  - os: linux
    compiler: clang
    env:
    - CFLAGS_EXTRA="-fsanitize=memory,undefined -march=native -fno-omit-frame-pointer"
    - TESTS_CUSTOM_RUN=true
    sudo: required
  - os: linux
    compiler: clang
    env:
    - CFLAGS_EXTRA="-fsanitize=thread -D AO_USE_ALMOST_LOCK_FREE -fno-omit-frame-pointer"
  - os: linux
    compiler: clang
    env:
    - CFLAGS_EXTRA="-fsanitize=thread -march=native -fno-omit-frame-pointer"
    - CONF_OPTIONS="--enable-assertions"
  - os: linux
    compiler: clang
    env:
    - CONF_OPTIONS="--disable-atomic-intrinsics"
    - CFLAGS_EXTRA="-march=native"
  - os: linux
    addons:
      apt:
        packages:
        - lcov
    compiler: gcc
    env:
    - CONF_OPTIONS="--enable-gcov --enable-shared"
    - REPORT_COVERAGE=true
    - CFLAGS_EXTRA="-march=native -D DEBUG_RUN_ONE_TEST -D VERBOSE"
  - os: linux
    env:
    - CPPCHECK_ENABLE="-j16 -q --enable=information,performance,portability,style,warning"
    - MAKEFILE_TARGET=all
    sudo: required
  - os: linux
    env:
    - CPPCHECK_ENABLE="-q --enable=unusedFunction -D AO_TEST_EMULATION"
    - MAKEFILE_TARGET=all
    sudo: required
  - os: linux
    addons:
      apt:
        packages:
        - clang-4.0
        sources:
        - llvm-toolchain-trusty-4.0
    compiler: clang-4.0
    dist: trusty
    env:
    - CSA_CHECK=true
    - MAKEFILE_TARGET=all
    - CFLAGS_EXTRA="-D AO_TRACE_MALLOC -D HAVE_MMAP -D VERBOSE"
  - os: linux
    addons:
      apt:
        packages:
        - musl-tools
    compiler: musl-gcc
    dist: trusty
    env:
    - CFLAGS_EXTRA="-march=native"
    - CONF_OPTIONS="--enable-assertions"
  - os: linux
    addons:
      apt:
        packages:
        - gcc-mingw-w64
    compiler: x86_64-w64-mingw32-gcc
    dist: trusty
    env:
    - CONF_OPTIONS="--host=x86_64-w64-mingw32 --enable-shared"
    - MAKEFILE_TARGET=all
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=aarch64-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=alpha-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=arm-unknown-linux-gnueabi
  - os: linux
    addons:
      apt:
        packages:
        - gcc-4.6
        - gcc-multilib
        sources:
        - ubuntu-toolchain-r-test
    compiler: gcc-4.6
    env:
    - CROSS_GCC_VER=4.2.4
    - NOLIBC_ARCH_ABI=avr32-linux
    - CFLAGS_EXTRA="-fno-strict-aliasing"
  - os: linux
    addons:
      apt:
        packages:
        - gcc-4.6
        - gcc-multilib
        sources:
        - ubuntu-toolchain-r-test
    compiler: gcc-4.6
    env:
    - CROSS_GCC_VER=4.6.3
    - NOLIBC_ARCH_ABI=cris-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=hppa-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=ia64-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=m68k-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=mips-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=mips64-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=powerpc-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=powerpc64-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=ppc64le-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=s390x-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-4.6
        - gcc-multilib
        sources:
        - ubuntu-toolchain-r-test
    compiler: gcc-4.6
    env:
    - CROSS_GCC_VER=4.6.3
    - NOLIBC_ARCH_ABI=sh4-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=sparc-linux
    - CFLAGS_EXTRA="-D AO_NO_SPARC_V9"
  - os: linux
    addons:
      apt:
        packages:
        - gcc-multilib
    env:
    - CROSS_GCC_VER=4.9.0
    - NOLIBC_ARCH_ABI=sparc64-linux
  - os: linux
    addons:
      apt:
        packages:
        - gcc-4.6
        - gcc-multilib
        sources:
        - ubuntu-toolchain-r-test
    compiler: gcc-4.6
    env:
    - CROSS_GCC_VER=4.6.2
    - NOLIBC_ARCH_ABI=tilegx-linux

before_install:
- if [[ "$CPPCHECK_ENABLE" != "" ]]; then
    git clone --depth=3 https://github.com/danmar/cppcheck.git
              ~/cppcheck -b master;
    make --directory ~/cppcheck -j CXXFLAGS="-O3 -march=native -D NDEBUG";
  fi
- if [[ "$CROSS_GCC_VER" != "" ]]; then
    BUILD_ARCH=x86_64;
    TAR_FOLDER_URL=https://www.kernel.org/pub/tools/crosstool/files/bin/$BUILD_ARCH/$CROSS_GCC_VER;
    TARFILE=$BUILD_ARCH-gcc-$CROSS_GCC_VER-nolibc_$NOLIBC_ARCH_ABI.tar.xz;
    wget -O - $TAR_FOLDER_URL/$TARFILE | tar xf - --xz --directory ~;
    CROSS_CC=~/gcc-$CROSS_GCC_VER-nolibc/$NOLIBC_ARCH_ABI/bin/$NOLIBC_ARCH_ABI-gcc;
    export C_INCLUDE_PATH=/usr/include;
    MAKEFILE_TARGET=check-nolink;
  fi
- if [[ "$AUTOMAKE_VER" != "" || "$LIBTOOL_VER" != "" || "$M4_VER" != "" ]]; then
    GNUTOOLS_ROOT=`pwd`/../gnu-tools;
    export PATH=$GNUTOOLS_ROOT/bin:$PATH;
  fi
- if [[ "$M4_VER" != "" ]]; then
    M4_XZ_URL=https://ftp.gnu.org/gnu/m4/m4-$M4_VER.tar.xz;
    wget -O - $M4_XZ_URL | tar xf - --xz --directory ~;
    (cd ~/m4-$M4_VER && ./configure --prefix=$GNUTOOLS_ROOT && make -j check && make install);
  fi
- if [[ "$LIBTOOL_VER" != "" ]]; then
    LIBTOOL_XZ_URL=https://ftp.gnu.org/gnu/libtool/libtool-$LIBTOOL_VER.tar.xz;
    wget -O - $LIBTOOL_XZ_URL | tar xf - --xz --directory ~;
    (cd ~/libtool-$LIBTOOL_VER && ./configure --prefix=$GNUTOOLS_ROOT && make -j && make install);
  fi
- if [[ "$AUTOMAKE_VER" != "" ]]; then
    AUTOMAKE_XZ_URL=https://ftp.gnu.org/gnu/automake/automake-$AUTOMAKE_VER.tar.xz;
    wget -O - $AUTOMAKE_XZ_URL | tar xf - --xz --directory ~;
    (cd ~/automake-$AUTOMAKE_VER && ./configure --prefix=$GNUTOOLS_ROOT && make -j && make install);
  fi
- if [[ "$MAKEFILE_TARGET" == "dist"* ]]; then
    autoconf --version;
    automake --version;
    m4 --version;
    libtool --version || true;
  fi
- if [[ "$MAKEFILE_TARGET" == "" ]]; then MAKEFILE_TARGET=check; fi

install:
- "./autogen.sh"
- if [[ "$REPORT_COVERAGE" == true ]]; then gem install coveralls-lcov; fi

script:
- ./configure $CONF_OPTIONS --enable-werror
- if [[ "$CSA_CHECK" != true && "$CPPCHECK_ENABLE" == "" ]]; then
    cat src/config.h;
  fi
- if [[ "$CROSS_GCC_VER" != "" ]]; then CC=$CROSS_CC; fi
- make -j $MAKEFILE_TARGET CC=$CC CFLAGS_EXTRA="$CFLAGS_EXTRA"
        LDFLAGS="$LDFLAGS"
- if [ -f tests/test_atomic.log ]; then cat tests/test_atomic*.log; fi
- if [[ "$CSA_CHECK" == true ]]; then
    ${CC} --analyze -Xanalyzer -analyzer-output=text -Werror -I src
          $CFLAGS_EXTRA tests/*.c src/*.c;
  fi
- if [[ "$CPPCHECK_ENABLE" != "" ]]; then
    ~/cppcheck/cppcheck -f --error-exitcode=2 -U long -D CPPCHECK -I src
                        $CPPCHECK_ENABLE tests/*.c src/*.c;
  fi
- if [[ "$TESTS_CUSTOM_RUN" == true ]]; then
    ASAN_OPTIONS="detect_leaks=1" UBSAN_OPTIONS="halt_on_error=1"
        make -C tests check-without-test-driver;
  fi

after_success:
- if [[ "$REPORT_COVERAGE" == true ]]; then
    lcov --capture --directory src --directory tests --output-file coverage.info;
    lcov --remove coverage.info '/usr/*' 'tests/*' --output-file coverage.info;
    lcov --list coverage.info;
    coveralls-lcov --repo-token ${COVERALLS_TOKEN} coverage.info;
  fi

deploy:
  provider: releases
  api_key:
    secure: wDAkRwV0lFrzLqdMhrnzD+fVZDODB32q2riJKXKZ3eC70VdliJzX59G60iJqIdN6YSSGGjpDTcaKTmim/T1zgAW+UIcXvpveX3jtocmsJJemZyFKAT++hHbeakNr4Mhgs0ddv3+JsgX375KOmL+ZkUzW0+5uIf9CXK80kE5v6E6p5LC6+Jg8Tqj2uSmUDfrYCFdIDQ901vAjxdPbFsFL8STy0ahBhUCrTThi9emAMR2vBwxf+0We58la936hMFmXs320ZtYN4fksuxNMgQu/3HL/UZIINT2IXgstWiNoU3yK6Z5IvOKWw0iPLMg7SS6L4WYJTu4Z26YnIlJ8XM3f7hO+c+jdffup59O1oklCl6JwlbqNFWtZhfJ+TW8fX8rpsvZIovBI4oOsZthpMNcvb3ZZ6UczUbhaInCvcYl5aTw/8K63Vh2HhKTFdMYMLn1X+qNIfXyKRL15C8VZOHB3Os14G03FNPlTqFE4IRnU3TyXTKBIwYOXf5Nb7fmOYZ11lHejco3rE0n3MiqIL0QJAAwExozV6Af/aJefyTWqfycgaGEfUzBQQpcMVlrDJg1I+LU7vExYYYYYoVPCKHn3CDsmdftUpJcPeKMHuasrfp54RBnY+B9s+hJQRtA7C70JbtoJpC+nxfwIzprBkdLudD+mI52zgFmU7JC1UeWDBik=
  file: libatomic_ops-*.tar.gz
  file_glob: true
  skip_cleanup: true
  on:
    condition: $MAKEFILE_TARGET = distcheck
    repo: ivmai/libatomic_ops
    tags: true
