summaryrefslogtreecommitdiff
path: root/man/CMakeLists.txt
blob: 50cb43c1744684183ff2293b6b0ca98bb990b913 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# Copyright © 2004-2013  Roger Leigh <rleigh@debian.org>
#
# schroot is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# schroot is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see
# <http://www.gnu.org/licenses/>.
#
#####################################################################

find_program(PO4A_EXECUTABLE po4a)
find_program(GROFFER_EXECUTABLE groffer)
find_program(SOELIM_EXECUTABLE soelim)

# generate config.man
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.man.cmake
               ${CMAKE_CURRENT_BINARY_DIR}/config.man)

set(common_dependencies
    ${CMAKE_CURRENT_BINARY_DIR}/config.man
    authors.man
    copyright.man)

set(manpage_sources
    dchroot.1.man
    dchroot-dsa.1.man
    schroot.1.man
    schroot-setup.5.man
    schroot.conf.5.man
    schroot-script-config.5.man
    schroot-faq.7.man)

# Translated manual pages

file(READ po/LINGUAS languages)
STRING(REGEX REPLACE "\n" ";" languages "${languages}")
foreach(lang ${languages})
  if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/po/${lang}.po")
    set(po_sources ${po_sources} "${CMAKE_CURRENT_SOURCE_DIR}/po/${lang}.po")
  endif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/po/${lang}.po")
endforeach(lang)

set(po4a_command
    ${PO4A_EXECUTABLE} --package-name ${CMAKE_PROJECT_NAME}
    --package-version ${GIT_RELEASE_VERSION}
    --copyright-holder "Roger Leigh <rleigh@debian.org>"
    "--srcdir=${CMAKE_CURRENT_SOURCE_DIR}"
    "--destdir=${CMAKE_CURRENT_BINARY_DIR}"
    "${CMAKE_CURRENT_SOURCE_DIR}/po4a.cfg")

if(PO4A_EXECUTABLE)
  # We need to run po4a initially to see what it generates, prior to
  # generating the rule to autogenerate from source.
  execute_process(COMMAND ${po4a_command})

  file(GLOB translated_dirs RELATIVE
       ${CMAKE_CURRENT_BINARY_DIR}/translated
       ${CMAKE_CURRENT_BINARY_DIR}/translated/*)
  foreach(lang ${translated_dirs})
    if(IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/translated/${lang}")
      set(languages {languages} ${lang})
      file(GLOB translated_files
           ${CMAKE_CURRENT_BINARY_DIR}/translated/${lang}/*.man)
        set(translated_manpage_sources
            ${translated_manpage_sources}
            ${translated_files})
    endif(IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/translated/${lang}")
  endforeach(lang)

  add_custom_command(OUTPUT ${translated_manpage_sources}
                     COMMAND ${po4a_command}
                     DEPENDS ${common_dependencies} ${manpage_sources}
                             ${po_sources}
                             "${CMAKE_CURRENT_SOURCE_DIR}/po4a.cfg"
                     VERBATIM)
else(PO4A_EXECUTABLE)
  warn("po4a not available; not translating manual pages")
endif(PO4A_EXECUTABLE)

set(manpage_sources
    ${manpage_sources}
    ${translated_manpage_sources})

add_custom_target(manpage-sources ALL DEPENDS ${manpage_sources})
if(GIT_RELEASE_ENABLE)
  add_dependencies(git-release manpage-sources)
endif(GIT_RELEASE_ENABLE)

foreach(manpage_source ${manpage_sources})
  unset(lang)
  unset(pagename)
  unset(section)
  string(REGEX MATCH ".*/translated/([^/]+)/(.+)\\.([0-9])\\.man\$" is_translation ${manpage_source})
  if(is_translation)
    string(REGEX REPLACE ".*/translated/([^/]+)/(.+)\\.([0-9])\\.man\$" "\\1;\\2;\\3" translation_matches ${manpage_source})
    list(GET translation_matches 0 lang)
    list(GET translation_matches 1 pagename)
    list(GET translation_matches 2 section)
      set(manpage_source_file ${manpage_source})
  else(is_translation)
    string(REGEX MATCH "^(.+)\\.([0-9])\\.man\$" is_manpage ${manpage_source})
    if (is_manpage)
      string(REGEX REPLACE "^(.+)\\.([0-9])\\.man\$" "\\1;\\2" manpage_matches ${manpage_source})
      unset(lang)
      list(GET manpage_matches 0 pagename)
      list(GET manpage_matches 1 section)
      set(manpage_source_file "${CMAKE_CURRENT_SOURCE_DIR}/${manpage_source}")
    endif (is_manpage)
  endif(is_translation)

  if(pagename AND NOT BUILD_DCHROOT)
    string(REGEX MATCH "^dchroot\$" dchroot_match ${pagename})
    if (dchroot_match)
      unset(pagename)
    endif (dchroot_match)
  endif(pagename AND NOT BUILD_DCHROOT)
  if(pagename AND NOT BUILD_DCHROOT_DSA)
    string(REGEX MATCH "^dchroot-dsa\$" dchroot_dsa_match ${pagename})
    if (dchroot_dsa_match)
      unset(pagename)
    endif (dchroot_dsa_match)
  endif(pagename AND NOT BUILD_DCHROOT_DSA)

  if(pagename)
    # Filter out manpages which should not be built or installed.  We
    # have to do this here due to the translated manpage sources being
    # created whether we want all of them or not.

    set(manpage_includes
        -I${CMAKE_CURRENT_BINARY_DIR}
        -I${CMAKE_CURRENT_SOURCE_DIR})
    if (lang)
      set(manpage "${CMAKE_CURRENT_BINARY_DIR}/translated/${lang}/${pagename}.${section}")
      set(manpage_path "${lang}/man${section}")
      set(manpage_includes
          -I${CMAKE_CURRENT_BINARY_DIR}/translated/${lang}
          ${manpage_includes})
    else (lang)
      set(lang "en")
      set(manpage "${CMAKE_CURRENT_BINARY_DIR}/${pagename}.${section}")
      set(manpage_path "man${section}")
    endif (lang)

    add_custom_command(OUTPUT ${manpage}
                       COMMAND ${SOELIM_EXECUTABLE}
                               ${manpage_includes}
                               < "${manpage_source_file}"
                               > "${manpage}"
                       DEPENDS "${manpage_source_file}"
                               ${common_dependencies}
                       VERBATIM)
    install(FILES "${manpage}"
            DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/${manpage_path}")

    set(manpages ${manpages} ${manpage})
    set(schroot-${lang} ${schroot-${lang}} ${manpage})
    list(FIND combined "schroot-${lang}" combined_exists)
    if (combined_exists EQUAL -1)
      set(combined ${combined} "schroot-${lang}")
    endif(combined_exists EQUAL -1)
  endif(pagename)
endforeach(manpage_source)

add_custom_target(manpages ALL DEPENDS ${manpages})

if(GROFFER_EXECUTABLE)
  foreach(manpage ${manpages})
    set(manpages_ps ${manpages_ps} "${manpage}.ps")
    add_custom_command(OUTPUT "${manpage}.ps"
                       COMMAND ${GROFFER_EXECUTABLE} -K utf8 --ps -man --to-stdout "${manpage}" > "${manpage}.ps"
                       DEPENDS "${manpage}" ${common_dependencies}
                       VERBATIM)

    set(manpages_pdf ${manpages_pdf} "${manpage}.pdf")
    add_custom_command(OUTPUT "${manpage}.pdf"
                       COMMAND ${GROFFER_EXECUTABLE} -K utf8 --pdf -man --to-stdout "${manpage}" > "${manpage}.pdf"
                       DEPENDS "${manpage}" ${common_dependencies}
                       VERBATIM)
  endforeach(manpage)

  add_custom_target(manpages-ps DEPENDS ${manpages_ps})
  add_custom_target(manpages-pdf DEPENDS ${manpages_pdf})

  file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/combined)
  foreach(combined_lang ${combined})
    list(SORT ${combined_lang})

    add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/combined/${combined_lang}.ps"
                       COMMAND ${GROFFER_EXECUTABLE} -K UTF8 -T ps -man --to-stdout ${${combined_lang}} > "${CMAKE_CURRENT_BINARY_DIR}/combined/${combined_lang}.ps"
                       DEPENDS ${${combined_lang}}
                       VERBATIM)
    set(combined_ps ${combined_ps} "${CMAKE_CURRENT_BINARY_DIR}/combined/${combined_lang}.ps")

    add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/combined/${combined_lang}.pdf"
                       COMMAND ${GROFFER_EXECUTABLE} -K UTF8 -T pdf -man --to-stdout ${${combined_lang}} > "${CMAKE_CURRENT_BINARY_DIR}/combined/${combined_lang}.pdf"
                       DEPENDS ${${combined_lang}}
                       VERBATIM)
    set(combined_pdf ${combined_pdf} "${CMAKE_CURRENT_BINARY_DIR}/combined/${combined_lang}.pdf")

  endforeach(combined_lang)

  add_custom_target(manpages-combined-ps DEPENDS ${combined_ps})
  add_custom_target(manpages-combined-pdf DEPENDS ${combined_pdf})

  add_custom_target(man-po-notify
                    COMMAND ${po4a_command}
                    COMMAND podebconf-report-po --call --withtranslators --noforce --podir=${CMAKE_CURRENT_SOURCE_DIR}/po)

endif(GROFFER_EXECUTABLE)