~njpatel/unity/fix-741652

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
# Copyright (C) 2009 Julian Andres Klode <jak@debian.org>.
# Licensed under the same terms as APT; i.e. GPL 2 or later.

macro(add_debiandoc target sourcefiles installdest)
	foreach(file ${sourcefiles})
		get_filename_component(relfile ${file} NAME)
		string(REPLACE ".sgml" "" manual ${relfile})
		get_filename_component(absolute ${file} ABSOLUTE)
		
		add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html
			COMMAND debiandoc2html ${absolute}
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
			DEPENDS ${file}
		)
		set(commands ${commands} ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html)
		if (NOT ${installdest} EQUAL "" )
		install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${manual}.html
			DESTINATION ${installdest})
		endif (NOT ${installdest} EQUAL "" )
	endforeach(file ${sourcefiles})

	add_custom_target(${target} ALL DEPENDS ${commands})
endmacro(add_debiandoc target sourcefiles installdest)


macro(add_po4a type master po target deps)
	add_custom_command(OUTPUT ${target}
		COMMAND po4a-translate --keep 0 -f ${type} -m ${master}
		                       -p ${po} -l ${target}
		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
		DEPENDS ${deps} ${master} ${po})
endmacro(add_po4a type master po target deps)


# Macro for XML man pages.
macro(add_xml_manpages target manpages translations entities)
	foreach(manpage ${manpages})
		string(LENGTH ${manpage} manpage_length)
		math(EXPR manpage_length ${manpage_length}-1)
		string(SUBSTRING ${manpage} ${manpage_length} 1 section)

		add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${manpage}
			COMMAND xmlto man ${CMAKE_CURRENT_SOURCE_DIR}/${manpage}.xml
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
			DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${manpage}.xml
		)
		
       
		set(commands ${commands} ${CMAKE_CURRENT_BINARY_DIR}/${manpage})
		
		install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${manpage}
				DESTINATION share/man/man${section})
				
		# Add the translations for the manpage.
		foreach(translation ${translations})
			set(entities)
			# transdir = shortcut to the output directory for translations.
			set(transdir ${CMAKE_CURRENT_BINARY_DIR}/${translation})
			
			foreach(entity ${entities})				
				add_custom_command(OUTPUT ${transdir}/${entity}
					WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
					COMMAND ${CMAKE_COMMAND} -E make_directory ${transdir}
					COMMAND ${CMAKE_COMMAND} -E copy ${entity} ${transdir})
				set(ent_cmds ${ent_cmds} ${transdir}/${entity})
			endforeach(entity ${entities})
		
		
		
			add_po4a(docbook ${manpage}.xml po/${translation}.po
			                 ${transdir}/${manpage}.xml "${ent_cmds}")

			
			add_custom_command(OUTPUT ${transdir}/${manpage}
				COMMAND xmlto -o ${transdir} man ${transdir}/${manpage}.xml
				WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
				DEPENDS ${transdir}/${manpage}.xml)
			
			set(nls-cmd ${nls-cmd} ${transdir}/${manpage})
			install(FILES ${transdir}/${manpage}
				    DESTINATION share/man/${translation}/man${section})
			
		endforeach(translation ${translations})
	endforeach(manpage ${manpages})
	
	add_custom_target(${target} ALL DEPENDS ${commands})
	# Sort the list of the translations.
	list(SORT nls-cmd)
	add_custom_target(nls-${target} ALL DEPENDS ${nls-cmd})
endmacro(add_xml_manpages manpages)


macro(add_manpages target manpages translations)
	foreach(man ${manpages})
		string(LENGTH ${man} manpage_length)
		math(EXPR manpage_length ${manpage_length}-1)
		string(SUBSTRING ${man} ${manpage_length} 1 section)	
		install(FILES ${man} DESTINATION share/man/man${section})
		
		if (USE_NLS)
			foreach(translation ${translations})
				set(transdir ${CMAKE_CURRENT_BINARY_DIR}/${translation})
				add_po4a(man ${man} po/${translation}.po ${transdir}/${man} "")
				install(FILES ${transdir}/${man}
						DESTINATION share/man/${translation}/man${section})
				set(files ${files} ${transdir}/${man})
			endforeach(translation ${translations})
		endif(USE_NLS)
	endforeach(man ${manpages})
	add_custom_target(${target} ALL DEPENDS ${files})
endmacro(add_manpages target manpages translations)