Skip to content

Commit

Permalink
Makefile: Auto-generate LICENSE file
Browse files Browse the repository at this point in the history
Build license file from buildroot legal info.

Signed-off-by: Michael Hennerich <[email protected]>
  • Loading branch information
mhennerich committed Apr 17, 2018
1 parent bd13416 commit fe5dc06
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CROSS_COMPILE ?= arm-xilinx-linux-gnueabi-

NCORES = $(shell grep -c ^processor /proc/cpuinfo)
VIVADO_SETTINGS ?= /opt/Xilinx/Vivado/2016.4/settings64.sh
VSUBDIRS = hdl buildroot linux
VSUBDIRS = hdl buildroot linux u-boot-xlnx

VERSION=$(shell git describe --abbrev=4 --dirty --always --tags)
LATEST_TAG=$(shell git describe --abbrev=0 --tags)
Expand All @@ -25,7 +25,7 @@ TARGETS += build/boot.dfu build/boot.frm jtag-bootstrap
endif
endif

all: $(TARGETS) zip-all
all: $(TARGETS) zip-all legal-info

build:
mkdir -p $@
Expand Down Expand Up @@ -76,6 +76,9 @@ buildroot/output/images/rootfs.cpio.gz:
@echo device-fw $(VERSION)> $(CURDIR)/buildroot/board/pluto/VERSIONS
@$(foreach dir,$(VSUBDIRS),echo $(dir) $(shell cd $(dir) && git describe --abbrev=4 --dirty --always --tags) >> $(CURDIR)/buildroot/board/pluto/VERSIONS;)
make -C buildroot ARCH=arm zynq_pluto_defconfig
make -C buildroot legal-info
scripts/legal_info_html.sh "PlutoSDR" "$(CURDIR)/buildroot/board/pluto/VERSIONS"
cp build/LICENSE.html buildroot/board/pluto/msd/LICENSE.html
make -C buildroot TOOLCHAIN_EXTERNAL_INSTALL_DIR= ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) BUSYBOX_CONFIG_FILE=$(CURDIR)/buildroot/board/pluto/busybox-1.25.0.config all

.PHONY: buildroot/output/images/rootfs.cpio.gz
Expand Down Expand Up @@ -178,7 +181,6 @@ sysroot: buildroot/output/images/rootfs.cpio.gz
tar czfh build/sysroot-$(VERSION).tar.gz --hard-dereference --exclude=usr/share/man -C buildroot/output staging

legal-info: buildroot/output/images/rootfs.cpio.gz
make -C buildroot legal-info
tar czvf build/legal-info-$(VERSION).tar.gz -C buildroot/output legal-info

git-update-all:
Expand Down
161 changes: 161 additions & 0 deletions scripts/legal_info_html.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#!/bin/bash

TARGET=$1
TARGET_VERSIONS=$2

MANIFEST=buildroot/output/legal-info/manifest.csv

PACKAGE=1
VERSION=2
LICENSE=3
LICENSE_FILES=4
SOURCE_ARCHIVE=5
SOURCE_SITE=6

FILE=build/LICENSE.html

html_header () {
echo "<!DOCTYPE html>" > ${FILE}
echo "<html>" >> ${FILE}
echo "<head>" >> ${FILE}
echo "<title>$1</title>" >> ${FILE}
echo "<link type=\"text/css\" href=\"./img/style.css\" rel=\"stylesheet\">" >> ${FILE}
echo "</head>" >> ${FILE}
echo "<body>" >> ${FILE}
}

html_footer () {
echo "</body>" >> ${FILE}
echo "</html>" >> ${FILE}
}

html_h1 () {
echo "<h1>$1</h1>" >> ${FILE}
}

html_h1_id () {
echo "<h1 id=\"P$2\">$1</h1>" >> ${FILE}
}

html_h2 () {
echo "<h2>$1</h2>" >> ${FILE}
}

html_p () {
echo "<p>$1</p>" >> ${FILE}
}

html_pre_file () {
echo "<pre>" >> ${FILE}
find $1 -type f -exec cat {} + >> ${FILE}
echo "</pre>" >> ${FILE}
}

html_li () {
echo "<li>$1</li>" >> ${FILE}
}

html_li_start () {
echo "<ul>" >> ${FILE}
}

html_li_stop () {
echo "</ul>" >> ${FILE}
}

html_hr () {
echo "<hr>" >> ${FILE}
}

get_column () {
echo ${1} | cut -d \" -f $(expr ${2} \* 2)
}

get_version () {
cat ${TARGET_VERSIONS} | grep ${1} | cut -d ' ' -f2
}

package_list_items () {
html_li_start
html_li "Version: ${1}"
html_li "License: ${2}"
html_li "Source Site: ${3}"
html_li_stop
}

### main

html_header "${TARGET} Legal Information"

html_h1 "Legal Information"
html_h1 "${TARGET} Firmware $(get_version device-fw)"

echo "<pre>" >> ${FILE}
cat LICENSE.md | sed -n '/#/I,/#/I { s/#.*//g; p }' >> ${FILE}
echo "</pre>" >> ${FILE}

html_h2 "NO WARRANTY"

echo "<pre>" >> ${FILE}
cat LICENSE.md | sed -n '1,/# NO WARRANTY/!p' >> ${FILE}
echo "</pre>" >> ${FILE}

### Table of packages
html_h1 "Open source components/packages:"

var=0
html_li_start
# Buidlroot external or local packages
html_li "<a href=\"#P$((var++))\">linux</a>"
html_li "<a href=\"#P$((var++))\">u-boot</a>"

while read -r line
do
package=$(get_column "${line}" $PACKAGE)

if [ "$package" == "PACKAGE" ];then
continue
fi
html_li "<a href=\"#P$((var++))\">$package</a>"
done < "$MANIFEST"
html_li_stop
html_hr

var=0
### Linux
html_h1_id "Package: linux" "$((var++))"
package_list_items $(get_version linux) "GPLv2" "https://github.com/analogdevicesinc/linux"
html_h2 "License:"
html_pre_file linux/COPYING
html_hr
### U-Boot
html_h1_id "Package: u-boot" "$((var++))"
package_list_items $(get_version u-boot-xlnx) "GPLv2" "https://github.com/analogdevicesinc/u-boot-xlnx"
html_h2 "License:"
html_pre_file u-boot-xlnx/Licenses/gpl-2.0.txt
html_hr

#### All other Buildroot Packages
while read -r line
do
package=$(get_column "${line}" $PACKAGE)

if [ "$package" == "PACKAGE" ];then
continue
fi

version=$(get_column "${line}" $VERSION)
license_file=$(get_column "${line}" $LICENSE_FILES)
license=$(get_column "${line}" $LICENSE)
source_site=$(get_column "${line}" $SOURCE_SITE)

html_h1_id "Package: $package" "$((var++))"

package_list_items $version $license $source_site

html_h2 "License:"
html_pre_file "$(dirname $MANIFEST)/licenses/$package-$version/"
html_hr
done < "$MANIFEST"

html_footer

0 comments on commit fe5dc06

Please sign in to comment.