From f9d4a992d0fa722b53a269532456b8b41fe428bf Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 8 Jan 2013 14:58:54 -0500 Subject: fix tempdir in -PKGBUILD, write -mozconfig --- moz-normalize-PKGBUILD | 2 +- moz-normalize-mozconfig | 129 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 1 deletion(-) mode change 100644 => 100755 moz-normalize-mozconfig diff --git a/moz-normalize-PKGBUILD b/moz-normalize-PKGBUILD index f56639c..930c47b 100755 --- a/moz-normalize-PKGBUILD +++ b/moz-normalize-PKGBUILD @@ -1,6 +1,6 @@ #!/bin/bash -tempdir="$(mktemp -d --tmpdir mozilla-normalize.XXXXXXXXXXX)" +tempdir="$(mktemp -d --tmpdir ${0##*/}.XXXXXXXXXXX)" ################################################################################ diff --git a/moz-normalize-mozconfig b/moz-normalize-mozconfig old mode 100644 new mode 100755 index e69de29..62cce3f --- a/moz-normalize-mozconfig +++ b/moz-normalize-mozconfig @@ -0,0 +1,129 @@ +#!/bin/bash + +tempdir="$(mktemp -d --tmpdir ${0##*/}.XXXXXXXXXXX)" + +urlencode() { + perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$1" +} + +# outputs in the format +# class-id:line +classify-lines() { + while read line; do + _line="$(printf '%s' "$line"|sed -r 's/^#(\S)/\1/')" + class='other' + case "$_line" in + ac_add_options\ --enable-application=*) class=setapp;; + .\ *mozconfig) class=setapp;; + + *optimiz*) class=vendor;; + + ac_add_options\ --*-dirs) class=vendor;; + ac_add_options\ --*-home=*) class=vendor;; + ac_add_options\ --libdir=*) class=vendor;; + ac_add_options\ --prefix=*) class=vendor;; + *OFFICIAL*) class=vendor;; + + ac_add_options\ --with-*=*) class=appsetting;; + *MOZ_PHOENIX*) class=appsetting;; + + ac_add_options\ --*-system-*) class=system;; + ac_add_options\ --with-pthreads) class=system;; + + ac_add_options\ --build=*) class=platform;; + ac_add_options\ --host=*) class=platform;; + *SHORT_LIBNAME*) class=platform;; + + ac_add_options\ --*=*) class=other;; + ac_add_options\ --enable-toolkit-*) class=other;; + + ac_add_options\ --enable-*) class=feature;; + ac_add_options\ --disable-*) class=feature;; + ac_add_options\ --with-*) class=feature;; + + '# '*) + class=comment + echo "$line" >> "$tempdir/comments" + ;; + esac + if [[ $class != comment ]]; then + ci="$tempdir/comments" + co="$tempdir/comments-$(urlencode "$line")" + [[ -f $ci ]] && mv "$ci" "$co" + + class_id='' + case "$class" in + setapp) class_id=0;; + system) class_id=1;; + feature) class_id=2;; + vendor) class_id=3;; + platform) class_id=4;; + appsetting) class_id=5;; + other) class_id=6;; + *) libremessages error "INVALID CLASS: $class"; exit 1;; + esac + printf '%s:%s\n' "$class_id" "$line" + fi + done +} + +format-classes() ( + echo 0 > "$tempdir/prev_id" + IFS=: + while read class_id line; do + prev_id=$(cat "$tempdir/prev_id") + if [[ "$class_id" != "$prev_id" ]]; then + echo '' + case "$class_id" in + 0) echo '# Set the application';; + 1) echo '# System libraries';; + 2) echo '# Features';; + 3) echo '# Vendor settings';; + 4) echo '# Platform settings';; + 5) echo '# Application settings';; + 6) echo '# Other';; + esac + fi + printf '%s\n' "$line" + echo "$class_id" > "$tempdir/prev_id" + done + echo '' + echo '# Build-generated' +) + +add-comments() { + while read line; do + file="$tempdir/comments-$(urlencode "$line")" + if [[ -f $file ]]; then + cat "$file" + fi + echo "$line" + done + file="$tempdir/comments" + if [[ -f $file ]]; then + cat "$file" + fi +} + +hack() { + sed -r \ + -e '/^\s*$/d' \ + -e '/#\s*(System libraries|Features|Optimization|Build-generated)/d' \ + -e '/#\s*(Icecat|IceWeasel)/d' \ + -e '/#\s*(ConnochaetOS|Parabola)/d' \ + -e 's/# (ac_add_options)/#\1/' +} + +main() { + cat \ + | hack \ + | classify-lines "$file" \ + | sort \ + | format-classes \ + | add-comments \ + + # above line intentionally left blank + rm -rf "$tempdir" +} + +main "$@" -- cgit v1.2.3-2-g168b