language: c

compiler:
  - gcc
  - clang

install:
  - sudo apt-get update -qq
  # for unit tests
  - sudo apt-get install -y check
  - sudo apt-get install -y libsubunit-dev
  # for Redis support
  - sudo apt-get install -y libhiredis-dev
  # for OpenSSL support
  - sudo apt-get install -y libssl-dev
  # for mod_sql_sqlite
  - sudo apt-get install -y libsqlite3-dev sqlite3
  # for static code analysis
  # - sudo apt-get install -y cppcheck
  # - sudo apt-get install -y rats
  # for test code coverage
  - sudo apt-get install -y lcov
  - gem install coveralls-lcov
  # For reference
  - sqlite3 --version

before_script:
  - cd ${TRAVIS_BUILD_DIR}
  - lcov --directory . --zerocounters

script:
  # - find . -type f -name "*.c" -print | grep -v t\/ | xargs cppcheck 2>&1
  # - find . -type f -name "*.c" -print | grep -v t\/ | xargs rats --language=c
  - git clone --depth 10 https://github.com/proftpd/proftpd.git
  - mkdir -p proftpd/contrib/mod_proxy/
  - cp -R include/ proftpd/contrib/mod_proxy/include
  - cp -R lib/ proftpd/contrib/mod_proxy/lib/
  - cp -R t/ proftpd/contrib/mod_proxy/t/
  - cp mod_proxy.* proftpd/contrib/mod_proxy/
  - cp Makefile.in proftpd/contrib/mod_proxy/
  - cp config* proftpd/contrib/mod_proxy/
  - cp install-sh proftpd/contrib/mod_proxy/
  - cd proftpd
  # First, a build without mod_tls and without Redis
  - ./configure LIBS='-lm -lsubunit -lrt -pthread' --enable-devel=coverage --enable-tests --with-module=mod_proxy
  - make
  # Next, a build with Redis, without mod_tls
  - make clean
  - ./configure LIBS='-lm -lsubunit -lrt -pthread' --enable-devel=coverage --enable-redis --enable-tests --with-module=mod_proxy
  - make
  # Next, a build WITH mod_tls (as a shared module)
  - make clean
  - ./configure LIBS='-lm -lsubunit -lrt -pthread' --enable-devel=coverage --enable-dso --enable-redis --enable-tests --with-shared=mod_tls:mod_proxy
  - make
  # Last, a build with mod_tls (as a static module), and run the tests
  - make clean
  - ./configure LIBS='-lm -lsubunit -lrt -pthread' --enable-devel=coverage --enable-redis --enable-tests --with-modules=mod_tls:mod_proxy
  - make
  - cd contrib/mod_proxy && make TEST_VERBOSE=1 check && cd ../../
  # Run `tidy -e -q mod_proxy.html` for doc validation

after_success:
  - cd ${TRAVIS_BUILD_DIR}
  # capture the test coverage info
  - lcov --ignore-errors gcov,source --base-directory ${TRAVIS_BUILD_DIR}/proftpd/contrib/mod_proxy --directory proftpd/contrib/mod_proxy --capture --output-file coverage.info
  # filter out system and test code
  - lcov --remove coverage.info 'api/*' 't/*' '/usr/*' --output-file coverage.info
  # debug before upload
  - lcov --list coverage.info
  # upload coverage info to coveralls
  - coveralls-lcov coverage.info
