summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2011-02-07 16:34:53 +0100
committerMichael Olbrich <m.olbrich@pengutronix.de>2015-02-06 11:53:58 +0100
commit71e467c41089be03b03ee12c1500294144e47f23 (patch)
treebf7aa6e1d605edb895db7615e5f871ef5e3d1076 /scripts
parentfedc6e9856987e388c6029dc541d02c556cef6f4 (diff)
downloadptxdist-71e467c41089be03b03ee12c1500294144e47f23.tar.gz
ptxdist-71e467c41089be03b03ee12c1500294144e47f23.tar.xz
new command create a license report of all the selected packages
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/ptxd_lib_dgen.awk1
-rw-r--r--scripts/lib/ptxd_make_license_report.awk73
-rw-r--r--scripts/lib/ptxd_make_license_report.sh120
-rw-r--r--scripts/lib/ptxd_make_world_common.sh5
-rw-r--r--scripts/lib/ptxd_make_world_license.sh222
5 files changed, 421 insertions, 0 deletions
diff --git a/scripts/lib/ptxd_lib_dgen.awk b/scripts/lib/ptxd_lib_dgen.awk
index e67eda0ee..b96f3f776 100644
--- a/scripts/lib/ptxd_lib_dgen.awk
+++ b/scripts/lib/ptxd_lib_dgen.awk
@@ -272,6 +272,7 @@ function write_deps_pkg_active(this_PKG, this_pkg, prefix) {
print "$(STATEDIR)/" this_pkg ".targetinstall: " "$(STATEDIR)/" this_pkg ".install.post" > DGEN_DEPS_POST;
print "$(STATEDIR)/" this_pkg ".targetinstall.post: " "$(STATEDIR)/" this_pkg ".targetinstall" > DGEN_DEPS_POST;
}
+ print "$(STATEDIR)/" this_pkg ".report: " "$(STATEDIR)/" this_pkg ".extract" > DGEN_DEPS_POST;
#
# conditional dependencies
diff --git a/scripts/lib/ptxd_make_license_report.awk b/scripts/lib/ptxd_make_license_report.awk
new file mode 100644
index 000000000..a8d3476c6
--- /dev/null
+++ b/scripts/lib/ptxd_make_license_report.awk
@@ -0,0 +1,73 @@
+#!/usr/bin/gawk -f
+#
+# Copyright (C) 2011 by Michael Olbrich <m.olbrich@pengutronix.de>
+#
+# See CREDITS for details about who has contributed to this project.
+#
+# For further information about the PTXdist project and license conditions
+# see the README file.
+#
+
+BEGIN {
+ FS = ":"
+ report_dir = ENVIRON["ptx_report_dir"]
+}
+
+$1 == "DEP" {
+ pkg=$2
+ sub($1":"$2":", "")
+ pkg_deps[pkg] = $0
+}
+
+$1 == "LICENSE" {
+ # add newline after each second license
+ gsub("[^,]*,[^,]*,", "&\\\\ ", $4);
+ gsub("_", "\\_", $4);
+ licenses[$2] = $4
+ raw_names[$2] = $3
+ gsub("_", "\\_", $3);
+ gsub("^host-", "", $3);
+ gsub("^cross-", "", $3);
+ names[$2] = $3
+}
+
+function make_more_dot(pkg, file, level, deps, i) {
+ if (level > 3)
+ return
+ printf "\"%s\" [ shape=box style=\"rounded corners\" fixedsize=false texlbl=\"\\small\\begin{tabular}{c}{\\Large\\hyperref[%s]{%s}}\\\\%s\\end{tabular}\" ];\n", pkg, raw_names[pkg], gensub("_", "\\_", "g", names[pkg]), licenses[pkg] > file
+ if (!(pkg in pkg_deps))
+ return
+ split(pkg_deps[pkg], deps, ":")
+ for (i in deps) {
+ if (deps[i] == "")
+ continue
+ if (names[deps[i]] == "")
+ continue
+ if (pkg deps[i] in hit_deps)
+ continue
+ hit_deps[pkg deps[i]] = 1
+ printf "\"%s\" -> \"%s\"[dir=back];\n", pkg, deps[i] > file
+ make_more_dot(deps[i], file, level + 1)
+ }
+}
+
+function make_dot(pkg) {
+ file = report_dir"/"raw_names[pkg]"/graph.dot"
+ delete hit_deps
+ printf "digraph \"%s\" {\n", pkg > file
+ printf "rankdir=LR;\n" > file
+ printf "ratio=compress;\n" > file
+ printf "nodesep=0.1;\n" > file
+ printf "ranksep=0.1;\n" > file
+ printf "node [ shape=point fixedsize=true width=0.1 ];\n", pkg > file
+ make_more_dot(pkg, file, 0)
+ printf "}\n" > file
+ close(file)
+}
+
+END {
+ for (pkg in licenses) {
+ make_dot(pkg)
+ }
+}
+
diff --git a/scripts/lib/ptxd_make_license_report.sh b/scripts/lib/ptxd_make_license_report.sh
new file mode 100644
index 000000000..ad90c99b9
--- /dev/null
+++ b/scripts/lib/ptxd_make_license_report.sh
@@ -0,0 +1,120 @@
+#!/bin/bash
+#
+# Copyright (C) 2011-2013 by Michael Olbrich <m.olbrich@pengutronix.de>
+#
+# See CREDITS for details about who has contributed to this project.
+#
+# 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]{scrbook}
+
+ \usepackage{graphicx}
+ \usepackage{listings}
+ \usepackage[xetex]{hyperref}
+ \usepackage{tocbibind}
+ \usepackage{scrtime}
+ \usepackage{tikz}
+ \usepackage{adjustbox}
+ \hypersetup{colorlinks=true,linkcolor=blue,urlcolor=blue}
+
+
+ \lstset{breaklines=true,basicstyle=\footnotesize\ttfamily}
+
+ \begin{document}
+
+ \thispagestyle{empty}
+ \begin{titlepage}
+ \null
+ \vfill
+ \begin{center}
+
+ {\Huge \textbf{License Report}}
+ {\huge \vfill for project \vfill ${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}
+
+ \tableofcontents
+ EOF
+}
+export -f ptxd_make_license_report_header
+
+ptxd_make_license_report_footer() {
+ cat <<- EOF
+ \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
+
+ptxd_make_license_report() {
+ local -a ptxd_reply
+ local ptx_license_target_tex pkg
+ ptxd_in_path PTXDIST_PATH_SCRIPTS lib/ptxd_make_license_report.awk || return
+ local make_license_report="${ptxd_reply}"
+ (
+ for pkg in "${@}"; do
+ echo "LICENSE:$(ptxd_name_to_NAME ${pkg}):${pkg}:$(<"${ptx_report_dir}/${pkg}/license-name"):"
+ done
+ for config in ptx platform; do
+ PTXDIST_DEP_TARGET="build" ptxd_kconfig dep ${config} || return
+ done
+ ) | gawk -f "${make_license_report}" &&
+
+ {
+ 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
+ echo "all: ${ptx_report_dir}/${pkg}/graph.tex"
+ done
+ } | make -f - ${PTXDIST_PARALLELMFLAGS_INTERN} all || return
+
+ ptx_license_target_tex="${ptx_report_dir}/$(basename "${ptx_license_target%.pdf}.tex")"
+ (
+ ptxd_make_license_report_header
+ for file in "${@}"; do
+ echo "\\input{${file#${ptx_report_dir}/}/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
+
diff --git a/scripts/lib/ptxd_make_world_common.sh b/scripts/lib/ptxd_make_world_common.sh
index 4a7704d19..150d70c16 100644
--- a/scripts/lib/ptxd_make_world_common.sh
+++ b/scripts/lib/ptxd_make_world_common.sh
@@ -232,6 +232,11 @@ ptxd_make_world_init() {
pkg_fake_env="${ptx_state_dir}/${pkg_label}.fakeroot"
#
+ # license dir
+ #
+ pkg_license_dir="${ptx_state_dir}/report/${pkg_label}"
+
+ #
# path
#
local path_ptr="ptx_path_${pkg_type}"
diff --git a/scripts/lib/ptxd_make_world_license.sh b/scripts/lib/ptxd_make_world_license.sh
new file mode 100644
index 000000000..5e590c204
--- /dev/null
+++ b/scripts/lib/ptxd_make_world_license.sh
@@ -0,0 +1,222 @@
+#!/bin/bash
+#
+# Copyright (C) 2013 by Michael Olbrich <m.olbrich@pengutronix.de>
+#
+# See CREDITS for details about who has contributed to this project.
+#
+# For further information about the PTXdist project and license conditions
+# see the README file.
+#
+
+#
+# parse "license_files" line
+#
+# out:
+#
+# $file = path to file containing license
+# $startline = first line of license
+# $endline = last line of license
+# $md5 = md5sum of license
+# $guess = 'yes' if the file was not specified explicitly
+#
+ptxd_make_world_parse_license_files() {
+ local orig_ifs="${IFS}"
+ IFS=";"
+ set -- ${@}
+ IFS="${orig_ifs}"
+ unset orig_ifs
+
+ file=""
+ startline="1"
+ endline="$"
+ md5=""
+ guess=""
+
+ while [ ${#} -ne 0 ]; do
+ local arg="${1}"
+ shift
+
+ case "${arg}" in
+ "file://"*)
+ file="${arg##file://}"
+ ;;
+ "beginline="*)
+ startline="${arg##beginline=}"
+ ;;
+ "startline="*)
+ startline="${arg##startline=}"
+ ;;
+ "endline="*)
+ endline="${arg##endline=}"
+ ;;
+ "md5="*)
+ md5="${arg##md5=}"
+ ;;
+ "guess="*)
+ guess="${arg##guess=}"
+ ;;
+ *)
+ ptxd_bailout "unknown option '${arg}'"
+ ;;
+ esac
+ done
+
+ if [ ! -e "${pkg_dir}/${file}" ]; then
+ ptxd_bailout "
+
+license file '$(ptxd_print_path "${file}")'
+not found
+"
+ fi
+}
+export -f ptxd_make_world_parse_license_files
+
+#
+# Generate a "license_files" line for packages without it.
+# This is done searching for file names typically used for licenses.
+#
+# out:
+#
+# $pkg_license_files = new "license_files" line if empty before
+#
+ptxd_make_world_license_expand() {
+ local -a licenses
+
+ [ -n "${pkg_license_files}" ] && return
+
+ exec {fd}< <(md5sum "${pkg_dir}/COPYING"* "${pkg_dir}/LICENSE"* 2>/dev/null)
+ while read md5 file <&${fd}; do
+ file="${file#${pkg_dir}/}"
+ licenses[${#licenses[@]}]="file://${file};md5=${md5}"
+ pkg_license_files="${pkg_license_files} file://${file};md5=${md5};guess=yes"
+ done
+ exec {fd}<&-
+}
+export -f ptxd_make_world_license_expand
+
+#
+# escape string for latex
+#
+ptxd_make_latex_escape() {
+ local s="${1}"
+ s="${s//_/\\_}"
+ s="${s//&/\\&}"
+ echo "${s}"
+}
+export -f ptxd_make_latex_escape
+
+#
+# generate a latex chapter for the package
+#
+# in:
+#
+# $pkg_license = the license string
+# $pkg_license_texts/$pkg_license_texts_guessed = license text files
+#
+ptxd_make_world_license_write() {
+ local guess
+ local pkg_chapter="$(ptxd_make_latex_escape ${pkg_label})"
+ pkg_chapter="${pkg_chapter#host-}"
+ pkg_chapter="${pkg_chapter#cross-}"
+
+ case "${pkg_license}" in
+ *proprietary*)
+ pkg_chapter="${pkg_chapter} *** Proprietary License!"
+ ;;
+ *unknown*)
+ pkg_chapter="${pkg_chapter} *** Unknown License!"
+ ;;
+ *ignore*)
+ # ignore this package, e.g. do not list it in the report
+ return 0
+ ;;
+ esac
+
+ cat <<- EOF
+ \chapter{${pkg_chapter}\label{${pkg_label}}}
+
+ \begin{description}
+ \item[Package:] $(ptxd_make_latex_escape ${pkg_label}) $(ptxd_make_latex_escape ${pkg_version})
+ \item[License:] $(ptxd_make_latex_escape ${pkg_license})
+ \item[URL:] \begin{flushleft}$(ptxd_make_latex_escape ${pkg_url})\end{flushleft}
+ \item[MD5:] {\ttfamily ${pkg_md5}}
+ \end{description}
+ EOF
+
+ if [ -n "${pkg_dot}" ]; then
+ cat <<- EOF
+ \begin{figure}[!ht]
+ \centering
+ \hspace*{-0.5in}\maxsizebox{0.9\paperwidth}{!}{
+ \input{${pkg_tex}}}
+ \caption{Dependency tree for $(ptxd_make_latex_escape ${pkg_label})}
+ \label{${pkg_label}-deps}
+ \end{figure}
+ EOF
+ fi
+
+ for license in "${pkg_license_texts[@]}" - "${pkg_license_texts_guessed[@]}"; do
+ if [ "${license}" = "-" ]; then
+ guess=" [automatically found]"
+ continue
+ fi
+ title="$(basename "${license}")"
+ cat <<- EOF
+ \section{$(ptxd_make_latex_escape ${title})${guess}}
+ \begin{lstlisting}
+ EOF
+ cat "${license}" | sed -e 's/\f/\n/g'
+ cat <<- EOF
+ \end{lstlisting}
+ EOF
+ done
+}
+export -f ptxd_make_world_license_write
+
+#
+# extract and process all available license information
+#
+ptxd_make_world_license() {
+ ptxd_make_world_init || return
+
+ local arg
+ local -a ptxd_reply
+ local -a pkg_license_texts
+ local -a pkg_license_texts_guessed
+ local pkg_dot=${pkg_license_dir}/graph.dot
+ local pkg_tex=${pkg_license_dir}/graph.tex
+ pkg_license="${pkg_license:-unknown}"
+
+ rm -rf "${pkg_license_dir}" &&
+ mkdir -p "${pkg_license_dir}" &&
+
+ ptxd_make_world_license_expand
+
+ for arg in ${pkg_license_files}; do
+ local file startline endline md5 guess
+
+ ptxd_make_world_parse_license_files "${arg}" &&
+
+ local lic="${pkg_license_dir}/${file//\//_}" &&
+ sed -n "${startline},${endline}p" "${pkg_dir}/${file}" > "${lic}" &&
+
+ if ! echo "${md5} ${lic}" | md5sum --check > /dev/null 2>&1; then
+ ptxd_bailout "
+
+checksum of license file '$(ptxd_print_path "${file}")'
+changed: ${md5} -> $(md5sum "${lic}" | sed 's/ .*//')
+"
+ fi &&
+ if [ -z "${guess}" ]; then
+ pkg_license_texts[${#pkg_license_texts[@]}]="${lic}"
+ else
+ pkg_license_texts_guessed[${#pkg_license_texts_guessed[@]}]="${lic}"
+ fi
+ done &&
+
+ ptxd_make_world_license_write | \
+ sed -e 's/%/\\%/g' > "${pkg_license_dir}/license-report.tex" &&
+
+ echo "${pkg_license}" > "${pkg_license_dir}/license-name"
+}
+export -f ptxd_make_world_license