# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Copy configure.ac
file(INSTALL @PROJECT_SOURCE_DIR@/configure.ac
    DESTINATION @PROJECT_BINARY_DIR@/autotools
    )

# Copy m4 diretory
file(INSTALL @PROJECT_SOURCE_DIR@/m4
    DESTINATION @PROJECT_BINARY_DIR@/autotools
    )

# Create include/@PROJECT_NAME@
file(MAKE_DIRECTORY @PROJECT_BINARY_DIR@/autotools/include/@PROJECT_NAME@)

if(@BUILD_JAVA@)
    # Copy script to be installed with autotools
    file(INSTALL @PROJECT_SOURCE_DIR@/@PROJECT_NAME@gen/scripts/@PROJECT_NAME@gen.in
        DESTINATION @PROJECT_BINARY_DIR@/autotools/.bin
        )
endif()


# Run autoreconf
execute_process(COMMAND autoreconf -fi @PROJECT_BINARY_DIR@/autotools
    RESULT_VARIABLE EXECUTE_RESULT)

if(NOT EXECUTE_RESULT EQUAL 0)
    message(FATAL_ERROR "Failed the execution of autoreconf")
endif()

# Copy include/@PROJECT_NAME@/config.h.in
file(INSTALL @PROJECT_SOURCE_DIR@/include/@PROJECT_NAME@/config.h.in
    DESTINATION @PROJECT_BINARY_DIR@/autotools/include/@PROJECT_NAME@
    )

# Copy licenses
file(INSTALL @PROJECT_SOURCE_DIR@/LICENSE
    DESTINATION @PROJECT_BINARY_DIR@/autotools
    )
