set(PACKAGE base-ant_utils-po)
set(SUBDIR base-ant_utils)
cmake_minimum_required(VERSION 3.20)

message(STATUS ${PACKAGE})

list(APPEND LINGUAS ru fi es)

file(GLOB POFILES "*.po")
file(GLOB GMOFILES "*.gmo")
file(GLOB UPDATEPOFILES "*.po-update")
file(GLOB DUMMYPOFILES "*.nop")
file(GLOB INSERT_HEADER "insert-header.sin")

add_custom_target(
  ${SUBDIR}-update-gmo
  COMMAND ${echo} ${MSGFMT} -c -o $@ $< ${MSGFMT} -c -o t-$@ $< && ${mv} -f t-$@ $@
  COMMENT "Target update-gmo")

add_custom_target(
  ${SUBDIR}-.po.mo
  COMMAND ${echo} ${MSGFMT} -c -o $@ $< ${MSGFMT} -c -o t-$@ $< && ${mv} -f t-$@ $@
  COMMENT "Target .po.mo")

foreach(LINGUA ${LINGUAS})
  add_custom_target(
    ${SUBDIR}-${LINGUA}.po.gmo ALL
    COMMAND
      rm -f ${CMAKE_CURRENT_SOURCE_DIR}/${LINGUA}.gmo && ${GMSGFMT} -c -o
      ${CMAKE_CURRENT_BINARY_DIR}/t-${LINGUA}.gmo
      ${CMAKE_CURRENT_SOURCE_DIR}/${LINGUA}.po && mv -f
      ${CMAKE_CURRENT_BINARY_DIR}/t-${LINGUA}.gmo
      ${CMAKE_CURRENT_BINARY_DIR}/${LINGUA}.gmo
    COMMENT "Target .po.gmo")
endforeach()

add_custom_target(
  ${SUBDIR}-.sin.sed
  COMMAND ${sed} -e "/^#/d" $< > t-$@ ${mv} -f t-$@ $@
  COMMENT "Target .sin.sed")

add_custom_target(
  ${SUBDIR}-stamp-po ALL
  COMMAND ${echo} timestamp > stamp-poT ${mv} -f stamp-poT stamp-po
  COMMENT "Target stamp-po")

add_custom_target(
  ${SUBDIR}-.insert-header.po-update-en ALL
  COMMAND # ${sed} -e "/^#/d" -e "s/HEADER/en@boldquot.header/g"
          # ${INSERT_HEADER} > en@boldquot.insert-header
  COMMENT "Target .insert-header.po-update-en")

add_custom_target(
  ${SUBDIR}-en-quot.insert-header ALL
  COMMAND ${sed} -e "/^#/d" -e "s/HEADER/en@boldquot.header/g" ${INSERT_HEADER}
          > en@boldquot.insert-header
  COMMENT "Target en@quot.insert-header")

add_custom_target(
  ${SUBDIR}-en-boldquot.insert-header ALL
  COMMAND ${sed} -e "/^#/d" -e "s/HEADER/en@boldquot.header/g" ${INSERT_HEADER}
          > en@boldquot.insert-header
  COMMENT "Target en@boldquot.insert-header")

foreach(LINGUA ${LINGUAS})
  install(
    PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${LINGUA}.gmo
    DESTINATION ${IRIS_LOCALE}/${LINGUA}/LC_MESSAGES
    RENAME ${SUBDIR}.mo
    COMPONENT base)
endforeach()
