3 #==================================================================================
4 # Copyright (c) 2019 Nokia
5 # Copyright (c) 2018-2019 AT&T Intellectual Property.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #==================================================================================
22 # builds the man pages for the deb file (generates troff from {X}fm).
23 # also builds postscript files, but leaves them in the current build dir.
24 # but, ONLY if build_doc variable is true
27 # look for tfm to build the man pages with. if not found, then we pull
28 # and build in the current build environment setting tfm/pfm commands to
29 # point at the correct spot. If the user has {X}fm installed, we just
33 find_program( tfm NAMES tfm )
34 find_program( pfm NAMES pfm )
36 if( "${tfm}" MATCHES "tfm-NOTFOUND" ) # user doesn't have installed; set where we expect them
37 set( tfm ${CMAKE_CURRENT_BINARY_DIR}/xfm/.build/src/tfm/tfm )
38 set( pfm "${CMAKE_CURRENT_BINARY_DIR}/xfm/.build/src/pfm/pfm" )
40 if( NOT EXISTS ${tfm} ) # not yet built here, pull and build
41 # pull and build {X}fm tools needed to generate manpages
43 COMMAND "bash" "-c" "git clone https://gitlab.com/rouxware/xfm.git && cd xfm && mkdir .build && cd .build && cmake .. && make"
44 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
46 message( "+++ xfm pulled and built" )
48 message( "+++ found xfm in the build environment" )
53 # base filenames (with .xfm are input)
98 # initialise lists of files we generated
102 # for each source, build a specific command that runs tfm to generate the
103 # troff output as a gzipped file. Sed is needed to remove the leading blank
104 # that tfm likes to insert even if indention is 0. We also generate postscript
105 # markdown, plain ascii and rts output which are left in the build directory
106 # for the developer to use as needed.
108 foreach( nm IN LISTS man_names )
109 set( out ${CMAKE_BINARY_DIR}/${nm} )
110 set( in ${CMAKE_SOURCE_DIR}/doc/src/man/${nm}.xfm )
115 COMMAND bash -c "export LIB=${CMAKE_SOURCE_DIR}/doc/src; \
116 export OUTPUT_TYPE=troff; \
117 ${tfm} ${in} stdout | sed 's/^ //' | gzip >${out}.gz; \
118 export OUTPUT_TYPE=rst; \
119 ${tfm} ${in} ${out}.rst; \
120 export OUTPUT_TYPE=txt; \
121 ${tfm} ${in} ${out}.txt; \
122 export OUTPUT_TYPE=markdown; \
123 ${tfm} ${in} stdout | sed 's/^ //' >${out}.md; \
124 export OUTPUT_TYPE=postscript; \
125 ${pfm} ${in} ${out}.ps"
126 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
127 COMMENT "Building manpage ${out}"
130 if( ${out} MATCHES ".*\.3" )
131 list( APPEND man3_files ${out}.gz )
133 list( APPEND man7_files ${out}.gz )
137 # we must force these to install
138 # find all of the man pages in build and add them to the package
140 install( FILES ${man3_files} DESTINATION ${install_man}/man3/ )
141 install( FILES ${man7_files} DESTINATION ${install_man}/man7/ )
143 add_custom_target( man_pages ALL DEPENDS ${man3_files};${man7_files} )
146 message( "+++ not building doc, set -DBULID_DOC=1 on cmake command line to enable" )
148 unset( BUILD_DOC CACHE ) # prevent it from being applied next build unless specifically set on comd line