# Boost.Geometry (aka GGL, Generic Geometry Library)
#
# Copyright (c) 2018 Mateusz Loskot <mateusz@loskot.net>
#
# This file was modified by Oracle on 2023.
# Modifications copyright (c) 2023 Oracle and/or its affiliates.
# Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
#
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

import os ;
import path ;
import regex ;

path-constant HEADERS : ../../include/boost/geometry ;

rule generate_self_contained_headers ( headers_subpath )
{
    # This rule is based on script copied from similar rule in Boost.GIL
    # On CI services, test the self-contained headers on-demand only to avoid build timeouts
    # CI environment is common for Travis CI, AppVeyor, CircleCI, etc.
    # For example:
    # if ! [ os.environ CI ] || [ os.environ TEST_HEADERS ] {
    #    alias self_contained_headers : [ generate_self_contained_headers ] ;
    # }

    local targets ;

    # NOTE: All '/' in test names are replaced with '-' because apparently
    #       test scripts have a problem with test names containing slashes.

    local top_headers_path = [ path.make $(HEADERS) ] ;

    # Skip the OpenGL visualization related header
    for local file in [ path.glob-tree $(top_headers_path)/$(headers_subpath) : *.hpp : gl_draw.hpp  ]
    {
        local rel_file = [ path.relative-to $(top_headers_path) $(file) ] ;
        local target_name = [ regex.replace h/$(rel_file) "/" "-" ] ;
        local target_name = [ regex.replace $(target_name) "\.hpp" "" ] ;
        targets += [
            compile main.cpp
            : <define>"BOOST_GEOMETRY_TEST_HEADER=$(rel_file)" <dependency>$(file)
            : $(target_name)
        ] ;
    }

    return $(targets) ;
}

# TODO: Review sorting to get as close as possible from general to specific

# Core
alias core : [ generate_self_contained_headers core ] ;
alias util : [ generate_self_contained_headers util ] ;
alias policies : [ generate_self_contained_headers policies ] ;
alias geometries : [ generate_self_contained_headers geometries ] ;
alias concepts : [ generate_self_contained_headers concepts ] ;
alias arithmetic : [ generate_self_contained_headers arithmetic ] ;
alias formulas : [ generate_self_contained_headers formulas ] ;
alias iterators : [ generate_self_contained_headers iterators ] ;
alias strategies : [ generate_self_contained_headers strategies ] ;
alias srs : [ generate_self_contained_headers srs ] ;
alias algorithms : [ generate_self_contained_headers algorithms ] ;
alias views : [ generate_self_contained_headers views ] ;
# Even though index is a separate submodule test headers here
alias index : [ generate_self_contained_headers index ] ;
