diff options
-rwxr-xr-x | moz-normalize-PKGBUILD | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | moz-normalize-mozconfig | 129 |
2 files changed, 130 insertions, 1 deletions
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 index e69de29..62cce3f 100644..100755 --- 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 "$@" |