  # Compress man pages
#
# Copyright 2014 <Giuseppe Marco Randazzo> gmrandazzo@gmail.com
#
# Redistribution AND use is allowed according to the terms of the New
# BSD license.

set(arpon_man_src "${CMAKE_SOURCE_DIR}/man8/arpon.8")

if(${CMAKE_INSTALL_PREFIX} STREQUAL "/")
  set(arpon_sarpi_file "/etc/arpon.sarpi")
else(${CMAKE_INSTALL_PREFIX} STREQUAL "/")
  set(arpon_sarpi_file "${CMAKE_INSTALL_PREFIX}/etc/arpon.sarpi")
endif(${CMAKE_INSTALL_PREFIX} STREQUAL "/")

FILE(READ ${arpon_man_src} FILE_CONTENT)
STRING(REGEX REPLACE "arpon_sarpi" "${arpon_sarpi_file}"  MODIFIED_FILE_CONTENT "${FILE_CONTENT}")
FILE(WRITE ${PROJECT_BINARY_DIR}/man8/arpon.8 "${MODIFIED_FILE_CONTENT}")

if(${CMAKE_INSTALL_PREFIX} STREQUAL "/")
  INSTALL(FILES ${PROJECT_BINARY_DIR}/man8/arpon.8 DESTINATION /usr/share/man/man8
    PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
    COMPONENT Man)
else(${CMAKE_INSTALL_PREFIX} STREQUAL "/")
  INSTALL(FILES ${PROJECT_BINARY_DIR}/man8/arpon.8 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man8
    PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
    COMPONENT Man)
endif(${CMAKE_INSTALL_PREFIX} STREQUAL "/")
