summaryrefslogtreecommitdiffstats
path: root/scripts/lib/ptxd_make_license_report.sh
blob: 21135d0db9cde7ede001484c0f8dcb0b570b9de0 (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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/bash
#
# Copyright (C) 2011-2013 by Michael Olbrich <m.olbrich@pengutronix.de>
#
# For further information about the PTXdist project and license conditions
# see the README file.
#

ptxd_make_license_report_header() {
    local project_desc="$(ptxd_get_ptxconf PTXCONF_PROJECT_VENDOR)-$(ptxd_get_ptxconf PTXCONF_PROJECT)$(ptxd_get_ptxconf PTXCONF_PROJECT_VERSION)"
    cat <<- EOF
	\documentclass[pointlessnumbers,bibtotocnumbered,openany,DIV14,paper=a4,twoside=false,listof=totoc]{scrbook}

	\usepackage{graphicx}
	\usepackage{imakeidx}
	\usepackage[xetex]{hyperref}
	\usepackage{scrtime}
	\usepackage{tikz}
	\usepackage{adjustbox}
	\usepackage{spverbatim}
	\usepackage{pdfpages}
	\hypersetup{colorlinks=true,linkcolor=blue,urlcolor=blue}

	%% Something like this may be needed depending on the package list
	%\usepackage[CJK]{ucharclasses}
	%\usepackage{fontspec}
	%\newfontfamily\mycjk{VL-Gothic-Regular}
	%\setTransitionsForCJK{\mycjk}{}

	\newif\iflicensereport
	\licensereporttrue

	\makeindex[name=attribution,intoc,title=attribution Package Index]
	\makeindex[name=choice,intoc,title=choice Package Index]
	\makeindex[name=nosource,intoc,title=nosource Package Index]
	\makeindex[name=nopatches,intoc,title=nopatches Package Index]

	\begin{document}

	\thispagestyle{empty}
	\begin{titlepage}
	\null
	\vfill
	\begin{center}

	{\Huge \textbf{License Report}}
	{\huge \vfill for project \vfill $(ptxd_make_latex_escape "${project_desc}")}
	{\LARGE \vfill created \today, \thistime}

	\vskip 5cm

	{\huge !Attention!}
	\end{center}
	\vskip 0.5cm

	This list of licenses is automatically generated and asserts no claims to
	completeness or correctness. It is not legally binding, and comes without
	warranty of any kind. We advise a manual counter-check before
	publication or legal use.
	\vfill
	\vfill
	\end{titlepage}

	\phantomsection
	\pdfbookmark[1]{Contents}{toc}
	\tableofcontents
	EOF
}
export -f ptxd_make_license_report_header

ptxd_make_license_report_footer() {
    cat <<- EOF
	\appendix
	\chapter{Flags\label{Flags}}
	Note: This list of tags and the packages marked with them is meant
	as a starting point for further work. It is by no means complete.
	There are most likely packages that e.g. require attribution but
	are missing the corresponding flag.

	For individual packages, adding the flag name to
	\textless{}PKG\textgreater\_LICENSE
	sets the corresponding flag. To add flags to groups of packages,
	e.g. based on the package license,
	\emph{ptxd\_make\_world\_license\_expand()} can be overwritten and
	expanded.
	\section{nosource\label{nosource}}
	For packages marked with the {\it nosource} flag, the source
	archive(s) will not be part of the license compliance package.
	\section{nopatches\label{nopatches}}
	For packages marked with the {\it nopatches} flag, the patches
	for this package will not be part of the license compliance
	package.
	\section{attribution\label{attribution}}
	Packages marked with the {\it attribution} flag require some sort
	of attribution. Please refer to the package license for further
	details.
	\section{choice\label{choice}}
	Packages marked with the {\it choice} flag require the licensee to
	make some kind of license choice. Please refer to the package
	license for further details.

	\printindex[attribution]
	\printindex[choice]
	\printindex[nosource]
	\printindex[nopatches]

	\listoffigures

	\end{document}
	EOF
}
export -f ptxd_make_license_report_footer

ptxd_make_license_report_build() {
    local last_md5 md5

    cd "$(dirname "${ptx_license_target_tex}")"
    while true; do
	max_print_line=1000 xelatex -halt-on-error "${ptx_license_target_tex}" || return
	md5=$(md5sum "${ptx_license_target_tex%.tex}.aux")
	if [ "${md5}" == "${last_md5}" ]; then
	    break
	fi
	last_md5="${md5}"
    done
}
export -f ptxd_make_license_report_build

# $1 list of packages (short names)
# We are called twice here: once for the target packages, once for the host tools
# Note: the 'package.list' contains license info for both runs
ptxd_make_license_report() {
    local -a ptxd_reply
    local ptx_license_target_tex pkg_lic pkg
    local -A ptxd_package_license_association

    ptxd_make_world_init || return

    # regenerate license info and sort out unused packages
    for pkg in $(<"${ptx_report_dir}/package.list"); do
	ptxd_package_license_association[$(basename ${pkg})]=$(dirname ${pkg})
    done

    ptxd_in_path PTXDIST_PATH_SCRIPTS lib/ptxd_make_license_report.awk || return

    echo -n "Extracting package's license information and dependencies..."
    local make_license_report="${ptxd_reply}"
    (
	for pkg in "${@}"; do
	    pkg_lic=${ptxd_package_license_association[${pkg}]}
	    if [ -z ${pkg_lic} ]; then
		# sort out no used packages for this run
		continue
	    fi
	    echo "LICENSE:$(ptxd_name_to_NAME ${pkg}):${pkg}:$(<"${ptx_report_dir}/${pkg_lic}/${pkg}/license-name"):${pkg_lic}:"
	done
	for config in ptx platform; do
	    PTXDIST_DEP_TARGET="build" ptxd_kconfig dep ${config} || return
	done
    ) | gawk -f "${make_license_report}"
    check_pipe_status || return
    echo "done"

    echo -n "Generating license dependencies graphs..."
    {
	echo "SHELL = bash"
	echo "%.tex: %.dot"
	echo '	@echo "  DOT2TEX `ptxd_print_path $<`"'
	echo '	@dot2tex --docpreamble="\usepackage[xetex]{hyperref}" --figonly -fpgf --autosize -o $@ $<'
	for pkg in "${@}"; do
		pkg_lic="${ptxd_package_license_association[${pkg}]}"
		if [ -z "${pkg_lic}" ]; then
			continue
		fi
		echo "all: ${ptx_report_dir}/${pkg_lic}/${pkg}/graph.tex"
	done
   } | make -f - ${PTXDIST_PARALLELMFLAGS_INTERN} all || return
   echo "done"

#
# combine all package related info into one document
#
    ptx_license_target_tex="${ptx_report_dir}/${pkg_section}/$(basename "${ptx_license_target%.pdf}.tex")"
    (
	ptxd_make_license_report_header
	for pkg in ${@}; do
		pkg_lic="${ptxd_package_license_association[${pkg}]}"
		if [ -z ${pkg_lic} ]; then
			continue
		fi
		pkg_lic="${pkg_lic}/${pkg}"
		echo "\\input{${pkg_lic#${ptx_report_dir}/${pkg_section}}/license-report.tex}"
	done
	ptxd_make_license_report_footer
    ) > "${ptx_license_target_tex}"

    ptxd_make_license_report_build
#    mv "${ptx_license_target_tex%.tex}.pdf" "${ptx_license_target}"
}
export -f ptxd_make_license_report

ptxd_make_license_compliance_header() {
    local project_desc="$(ptxd_get_ptxconf PTXCONF_PROJECT_VENDOR)-$(ptxd_get_ptxconf PTXCONF_PROJECT)$(ptxd_get_ptxconf PTXCONF_PROJECT_VERSION)"
    cat <<- EOF
	\documentclass[pointlessnumbers,bibtotocnumbered,openany,DIV14,paper=a4,twoside=false,listof=totoc]{scrbook}

	\usepackage{graphicx}
	\usepackage[xetex]{hyperref}
	\usepackage{scrtime}
	\usepackage{tikz}
	\usepackage{adjustbox}
	\usepackage{spverbatim}
	\usepackage{pdfpages}
	\hypersetup{colorlinks=true,linkcolor=blue,urlcolor=blue}

	%% Something like this may be needed depending on the package list
	%\usepackage[CJK]{ucharclasses}
	%\usepackage{fontspec}
	%\newfontfamily\mycjk{VL-Gothic-Regular}
	%\setTransitionsForCJK{\mycjk}{}

	\newif\iflicensereport
	\licensereportfalse

	\begin{document}

	\thispagestyle{empty}
	\begin{titlepage}
	\null
	\vfill
	\begin{center}

	{\Huge \textbf{Open Source Software Licenses}}
	{\huge \vfill for project \vfill $(ptxd_make_latex_escape "${project_desc}")}
	{\LARGE \vfill created \today, \thistime}

	\vskip 5cm

	{\huge !Attention!}
	\end{center}
	\vskip 0.5cm

	This list of licenses is automatically generated and asserts no claims to
	completeness or correctness. It is not legally binding, and comes without
	warranty of any kind. We advise a manual counter-check before
	publication or legal use.
	\vfill
	\vfill
	\end{titlepage}

	\phantomsection
	\pdfbookmark[1]{Contents}{toc}
	\tableofcontents
	EOF
}
export -f ptxd_make_license_compliance_header

ptxd_make_license_compliance_footer() {
    cat <<- EOF
	\end{document}
	EOF
}
export -f ptxd_make_license_compliance_footer

ptxd_make_license_compliance_pdf() {
    local ptx_license_target_tex pkg_lic pkg
    local -A ptxd_package_license_association

    # regenerate license info and sort out unused packages
    for pkg in $(<"${ptx_report_dir}/package.list"); do
	ptxd_package_license_association[$(basename ${pkg})]=$(dirname ${pkg})
    done

#
# combine all package related info into one document
#
    ptx_license_target_tex="${ptx_report_dir}/${pkg_section}/$(basename "${ptx_license_target%.pdf}.tex")"
    (
	ptxd_make_license_compliance_header
	for pkg in ${@}; do
		pkg_lic="${ptxd_package_license_association[${pkg}]}"
		if [ -z "${pkg_lic}" -o "${pkg_lic}" = "proprietary" -o "${pkg_lic}" = "ignore" ]; then
			continue
		fi
		pkg_lic="${pkg_lic}/${pkg}"
		echo "\\input{${pkg_lic#${ptx_report_dir}/${pkg_section}}/license-report.tex}"
	done
	ptxd_make_license_compliance_footer
    ) > "${ptx_license_target_tex}"

    ptxd_make_license_report_build &&
    cp "${ptx_license_target_tex%.tex}.pdf" "${ptx_license_target}"
}
export -f ptxd_make_license_compliance_pdf

ptxd_make_license_compliance_yaml() {
    local pkg_lic pkg
    local -A ptxd_package_license_association

    # regenerate license info and sort out unused packages
    for pkg in $(<"${ptx_report_dir}/package.list"); do
	ptxd_package_license_association[$(basename ${pkg})]=$(dirname ${pkg})
    done

#
# combine all package related info into one document
#
    (
	for pkg in ${@}; do
		pkg_lic="${ptxd_package_license_association[${pkg}]}"
		if [ -z "${pkg_lic}" ]; then
			continue
		fi
		pkg_lic="${pkg_lic}/${pkg}"
		echo "${pkg}:"
		sed 's/^/  /' "${ptx_report_dir}/${pkg_lic}/license-report.yaml"
	done
    ) > "${ptx_license_target}.tmp" &&
    mv "${ptx_license_target}.tmp" "${ptx_license_target}"
}
export -f ptxd_make_license_compliance_yaml