From cd74549840be5bba43c502ebfeb01c1b820c2eea Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Wed, 28 Apr 2010 07:52:16 -0500 Subject: [PATCH] [devel] Improved the options.awk script; added an "everything off" option. --- ANNOUNCE | 1 + CHANGES | 1 + scripts/README.txt | 12 +- scripts/checksym.awk | 2 +- scripts/libpng-config-head.in | 2 +- scripts/libpng.pc.in | 2 +- scripts/makefile.ne12bsd | 2 +- scripts/makefile.netbsd | 2 +- scripts/makefile.openbsd | 2 +- scripts/makefile.std | 6 +- scripts/options.awk | 221 ++++++++++++++++++++++++++++------ scripts/pnglibconf.dfa | 45 ++++--- scripts/pnglibconf.h | 4 +- scripts/pnglibconf.mak | 12 +- scripts/pngwin.def | 2 +- scripts/pngwin.dfn | 2 +- scripts/sym.dfn | 2 +- scripts/symbols.def | 2 +- scripts/symbols.dfn | 2 +- scripts/vers.dfn | 2 +- 20 files changed, 247 insertions(+), 79 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index aef209b78..4c12ae5f3 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -199,6 +199,7 @@ version 1.5.0beta21 [April 27, 2010] version 1.5.0beta22 [April 28, 2010] Fixed dependencies of GET_INT_32 - it does not require READ_INT_FUNCTIONS because it has a macro equivalent. + Improved the options.awk script; added an "everything off" option. Send comments/corrections/commendations to png-mng-implement at lists.sf.net: (subscription required; visit diff --git a/CHANGES b/CHANGES index b736e7572..19edcaf39 100644 --- a/CHANGES +++ b/CHANGES @@ -2681,6 +2681,7 @@ version 1.5.0beta21 [April 27, 2010] version 1.5.0beta22 [April 28, 2010] Fixed dependencies of GET_INT_32 - it does not require READ_INT_FUNCTIONS because it has a macro equivalent. + Improved the options.awk script; added an "everything off" option. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/scripts/README.txt b/scripts/README.txt index 2e995cbf7..fe26a80ae 100644 --- a/scripts/README.txt +++ b/scripts/README.txt @@ -1,9 +1,9 @@ -Makefiles for libpng version 1.5.0beta21 - April 27, 2010 +Makefiles for libpng version 1.5.0beta22 - April 28, 2010 pnglibconf.h => Stores configuration settings makefile.linux => Linux/ELF makefile - (gcc, creates libpng15.so.15.1.5.0beta21) + (gcc, creates libpng15.so.15.1.5.0beta22) makefile.gcc => Generic makefile (gcc, creates static libpng.a) makefile.knr => Archaic UNIX Makefile that converts files with ansi2knr (Requires ansi2knr.c from @@ -20,7 +20,7 @@ pnglibconf.h => Stores configuration settings makefile.dec => DEC Alpha UNIX makefile makefile.dj2 => DJGPP 2 makefile makefile.elf => Linux/ELF makefile symbol versioning, - gcc, creates libpng15.so.15.1.5.0beta21) + gcc, creates libpng15.so.15.1.5.0beta22) makefile.freebsd => FreeBSD makefile makefile.gcc => Generic gcc makefile makefile.hpgcc => HPUX makefile using gcc @@ -35,12 +35,12 @@ pnglibconf.h => Stores configuration settings makefile.os2 => OS/2 Makefile (gcc and emx, requires libpng.def) makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc makefile.sggcc => Silicon Graphics (gcc, - creates libpng15.so.15.1.5.0beta21) + creates libpng15.so.15.1.5.0beta22) makefile.sgi => Silicon Graphics IRIX makefile (cc, creates static lib) makefile.solaris => Solaris 2.X makefile (gcc, - creates libpng15.so.15.1.5.0beta21) + creates libpng15.so.15.1.5.0beta22) makefile.so9 => Solaris 9 makefile (gcc, - creates libpng15.so.15.1.5.0beta21) + creates libpng15.so.15.1.5.0beta22) makefile.std => Generic UNIX makefile (cc, creates static libpng.a) makefile.sunos => Sun makefile makefile.32sunu => Sun Ultra 32-bit makefile diff --git a/scripts/checksym.awk b/scripts/checksym.awk index d6f273122..20051d339 100755 --- a/scripts/checksym.awk +++ b/scripts/checksym.awk @@ -1,4 +1,4 @@ -#!/bin/awk +#!/bin/awk -f # Check a list of symbols against the master definition # (official) list. Arguments: # diff --git a/scripts/libpng-config-head.in b/scripts/libpng-config-head.in index 8fc242d4c..4a6552edf 100755 --- a/scripts/libpng-config-head.in +++ b/scripts/libpng-config-head.in @@ -11,7 +11,7 @@ # Modeled after libxml-config. -version=1.5.0beta21 +version=1.5.0beta22 prefix="" libdir="" libs="" diff --git a/scripts/libpng.pc.in b/scripts/libpng.pc.in index d388ac51f..904632cef 100644 --- a/scripts/libpng.pc.in +++ b/scripts/libpng.pc.in @@ -5,6 +5,6 @@ includedir=@includedir@/libpng15 Name: libpng Description: Loads and saves PNG files -Version: 1.5.0beta21 +Version: 1.5.0beta22 Libs: -L${libdir} -lpng15 Cflags: -I${includedir} diff --git a/scripts/makefile.ne12bsd b/scripts/makefile.ne12bsd index c5a3688e0..8ace21299 100644 --- a/scripts/makefile.ne12bsd +++ b/scripts/makefile.ne12bsd @@ -17,7 +17,7 @@ INCSDIR=${LOCALBASE}/include/libpng15 LIB= png15 SHLIB_MAJOR= 0 -SHLIB_MINOR= 1.5.0beta21 +SHLIB_MINOR= 1.5.0beta22 SRCS= png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \ pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \ pngwtran.c pngmem.c pngerror.c pngpread.c diff --git a/scripts/makefile.netbsd b/scripts/makefile.netbsd index 0005c684c..329b08d9d 100644 --- a/scripts/makefile.netbsd +++ b/scripts/makefile.netbsd @@ -17,7 +17,7 @@ INCSDIR=${LOCALBASE}/include LIB= png SHLIB_MAJOR= 3 -SHLIB_MINOR= 1.5.0beta21 +SHLIB_MINOR= 1.5.0beta22 SRCS= png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \ pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \ pngwtran.c pngmem.c pngerror.c pngpread.c diff --git a/scripts/makefile.openbsd b/scripts/makefile.openbsd index 5cfba3722..64cd2474c 100644 --- a/scripts/makefile.openbsd +++ b/scripts/makefile.openbsd @@ -11,7 +11,7 @@ LIBDIR= ${PREFIX}/lib MANDIR= ${PREFIX}/man/cat SHLIB_MAJOR= 0 -SHLIB_MINOR= 1.5.0beta21 +SHLIB_MINOR= 1.5.0beta22 LIB= png SRCS= png.c pngerror.c pngget.c pngmem.c pngpread.c \ diff --git a/scripts/makefile.std b/scripts/makefile.std index d773b71c3..08b4092d7 100644 --- a/scripts/makefile.std +++ b/scripts/makefile.std @@ -52,9 +52,9 @@ all: libpng.a pngtest # copy this if the following doesn't work. pnglibconf.dfn: scripts/pnglibconf.dfa scripts/options.awk $(RM_F) $@ dfn?.out - $(AWK) -f scripts/options.awk pre=1 out=dfn1.out\ - scripts/pnglibconf.dfa 1>&2 - $(AWK) -f scripts/options.awk pre=0 out=dfn2.out dfn1.out 1>&2 + $(AWK) -f scripts/options.awk out=dfn1.out\ + scripts/pnglibconf.dfa $(DFA_XTRA) 1>&2 + $(AWK) -f scripts/options.awk out=dfn2.out dfn1.out 1>&2 cp dfn2.out $@ $(RM_F) dfn?.out diff --git a/scripts/options.awk b/scripts/options.awk index 48967983d..898a1aec9 100755 --- a/scripts/options.awk +++ b/scripts/options.awk @@ -1,7 +1,7 @@ #!/bin/awk -f # scripts/options.awk - library build configuration control # -# last changed in libpng version 1.5.0 - April 27, 2010 +# last changed in libpng version 1.5.0 - April 28, 2010 # # Copyright (c) 1998-2010 Glenn Randers-Pehrson # @@ -12,16 +12,25 @@ # The output of this script is written to the file given by # the variable 'out'. The script is run twice, once with # an intermediate output file, 'options.tmp' then again on -# that file to produce the final output. Each time the -# output files and whether or not to pre-prrocess must be -# specified: +# that file to produce the final output: # -# awk -f scripts/options.awk pre=1 out=options.tmp scripts/options.dat 1>&2 -# awk -f scripts/options.awk pre=0 out=options.dfn options.tmp 1>&2 +# awk -f scripts/options.awk out=options.tmp scripts/options.dfa 1>&2 +# awk -f scripts/options.awk out=options.dfn options.tmp 1>&2 +# +# Some options may be specified on the command line: +# +# deb=1 Causes debugging to be output +# logunsupported=1 Causes all options to be recorded in the output +# everything=off Causes all options to be disabled by default +# everything=on Causes all options to be enabled by default +# +# These options may also be specified in the original input file (and +# are copied to the preprocessed file). BEGIN{ out="/dev/null" # intermediate, preprocessed, file - pre=-1 # preprocess + pre=-1 # preprocess (first line) + err=0 # in-line exit sets this start="PNG_DEFN_MAGIC-" # Arbitrary start end="-PNG_DEFN_END" # Arbitrary end cx= "/@@@*" # Open C comment for output file @@ -32,11 +41,14 @@ BEGIN{ und=comment "#undef PNG_@@@" # Unsupported option une="@@@_SUPPORTED" cend # end unsupported option error=start "ERROR:" # error message + + # Variables deb=0 # debug - set on command line + everything="" # do not override defaults logunsupported=0 # write unsupported options too # Precreate arrays - option[""] = "" # list of all options: default on/off/"" + option[""] = "" # list of all options: default enabled/disabled done[""] = 1 # marks option as having been output requires[""] = "" # requires by option iffs[""] = "" # if by option @@ -50,6 +62,27 @@ BEGIN{ protect = "" } +# The output file must be specified before any input: +out == "/dev/null" { + print "out=output.file must be given on the command line" + err = 1 + exit 1 +} + +# The very first line indicates whether we are reading pre-processed +# input or not, this must come *first* because 'PREPROCESSED' needs +# to be the very first line in the temporary file. +pre == -1{ + if ($0 == "PREPROCESSED") { + pre = 0 + next + } else { + pre = 1 + print "PREPROCESSED" >out + # And fall through to continue processing + } +} + # Preprocessing - this just copies the input file with lines # that need preprocessing (just chunk at present) expanded pre && $1 != "chunk"{ @@ -116,23 +149,66 @@ $1 == "file" && NF >= 2{ next } -# option NAME ( (requires|enables|if) NAME* | on | off )* -# Declares an option 'NAME' and describes its default setting (on|off) +# variable=value +# Sets the given variable to the given value (the syntax is fairly +# free form, except for deb (you are expected to understand how to +# set the debug variable...) +$0 ~ /^[ ]*everything[ =]*off[ ]*$/{ + everything = "off" + next +} +$0 ~ /^[ ]*everything[ =]*on[ ]*$/{ + everything = "on" + next +} +$0 ~ /^[ ]*logunsupported[ =]*0[ ]*$/{ + logunsupported = 0 + next +} +$0 ~ /^[ ]*logunsupported[ =]*1[ ]*$/{ + logunsupported = 1 + next +} +$1 == "deb" && $2 == "=" && NF == 3{ + deb = $3 + next +} + +# option NAME ( (requires|enables|if) NAME* | on | off | disabled )* +# Declares an option 'NAME' and describes its default setting (disabled) # and its relationship to other options. The option is disabled # unless *all* the options listed after 'requires' are set and at # least one of the options listed after 'if' is set. If the # option is set then it turns on all the options listed after 'enables'. +# +# Note that "enables" takes priority over the required/if/disabled/off +# setting of the target option. +# +# The definition file may list an option as 'disabled': off by default, +# otherwise the option is enabled: on by default. A later (and it must +# be later) entry may turn an option on or off explicitly. $1 == "option" && NF >= 2{ - onoff = option[$2] # records default on or default off + onoff = option[$2] # records current (and the default is "", enabled) key = "" for (i=3; i<=NF; ++i) { - if ($(i) == "on" || $(i) == "off") { + if ($(i) == "on" || $(i) == "off" || $(i) == "disabled") { key = "" if (onoff != $(i)) { - if (onoff == "") + # on or off can zap disabled or enabled: + if (onoff == "" || + (onoff == "disabled" || onoff == "enabled") && + ($(i) == "on" || $(i) == "off")) { + # It's easy to mis-spell the option when turning it + # on or off, so warn about it here: + if (onoff == "" && ($(i) == "on" || $(i) == "off")) { + print $2 ": ERROR: turning unrecognized option", $(i) + # For the moment error out - it is safer + err = 1 # prevent END{} running + exit 1 + } onoff = $(i) - else { + } else { # Print a message, otherwise the error # below is incomprehensible print $2 ": currently", onoff ": attempt to turn", $(i) @@ -152,17 +228,15 @@ $1 == "option" && NF >= 2{ } if (i > NF) { - # Set the option - this may explicitly set it to "", that's good - # becaue we need to ensure it exists and we can't rely on some - # actually quite sensible awk implementation not optimising the - # read above away (gawk doesn't) + # Set the option, defaulting to 'enabled' + if (onoff == "") onoff = "enabled" option[$2] = onoff next } # Else fall through to the error handler } -# chunk NAME [requires OPT] [off] +# chunk NAME [requires OPT] [on|off|disabled] # Expands to the 'option' settings appropriate to the reading and # writing of an ancilliary PNG chunk 'NAME': # @@ -184,7 +258,7 @@ pre && $1 == "chunk" && NF >= 2{ # read the keywords/additional OPTS req = 0 for (i=3; i<=NF; ++i) { - if ($(i) == "on" || $(i) == "off") { + if ($(i) == "on" || $(i) == "off" || $(i) == "disabled") { if (onoff != $(i)) { if (onoff == "") onoff = $(i) @@ -243,6 +317,7 @@ $1 == "setting" && (NF == 2 || NF >= 3 && ($3 == "requires" || $3 == "default")) break # Format error, handled below setting[$2] = reqs + # NOTE: this overwrites a previous value silently if (isdef && deflt == "") deflt = " " # as a flag to force output defaults[$2] = deflt @@ -302,6 +377,7 @@ $1 ~ /^@/{ # any other format errors. { print "options.awk: bad line (" NR "):", $0 + err = 1 # prevent END{} running exit 1 } @@ -324,15 +400,15 @@ $1 ~ /^@/{ # of the names to be enabled. END{ - if (out == "/dev/null") { - print "out=output.file must be given on the command line" - exit 1 - } + # END{} gets run on an exit (a traditional awk feature) + if (err) exit 1 + if (pre) { - if (pre != 1) { - print "pre=0 or pre=1 must be given on command line" - exit 1 - } + # Record the variables + print "deb =", deb + if (everything != "") + print "everything =", everything + print "logunsupported =", logunsupported exit 0 } @@ -377,6 +453,9 @@ END{ print def i, "PNG_" i end >out if (defaults[i] != "") { print "#else /*default*/" >out + # And add the default definition for the benefit + # of later settings an options test: + print "# define PNG_" i defaults[i] >out print def i defaults[i] end >out } print "#endif" >out @@ -408,8 +487,16 @@ END{ print "/* OPTIONS */" >out print comment, "options", cend >out for (opt in enabledby) tree[opt] = 1 # may not be explicit options - for (opt in option) tree[opt] = "" # so unlisted options marked - for (opt in tree) { + for (opt in option) if (opt != "") { + o = option[opt] + # option should always be one of the following values + if (o != "on" && o != "off" && o != "disabled" && o != "enabled") { + print "internal option error (" o ")" + exit 1 + } + tree[opt] = "" # so unlisted options marked + } + for (opt in tree) if (opt != "") { if (tree[opt] == 1) { tree[opt] = "" if (option[opt] != "") { @@ -418,7 +505,7 @@ END{ } # Macros only listed in 'enables' remain off unless # one of the enabling macros is on. - option[opt] = "off" + option[opt] = "disabled" } split("", list) # clear 'list' @@ -432,6 +519,51 @@ END{ # print the tree for extreme debugging if (deb > 2) for (i in tree) if (i != "") print i, "depends-on" tree[i] + # Ok, now check all options marked explicitly 'on' or 'off': + # + # If an option[opt] is 'on' then turn on all requires[opt] + # If an option[opt] is 'off' then turn off all enabledby[opt] + # + # Error out if we have to turn 'on' an 'off' option or vice versa. + npending = 0 + for (opt in option) if (opt != "") { + if (option[opt] == "on" || option[opt] == "off") + pending[++npending] = opt + } + + err = 0 # set on error + while (npending > 0) { + opt = pending[npending--] + if (option[opt] == "on") { + nreqs = split(requires[opt], r) + for (j=1; j<=nreqs; ++j) { + if (option[r[j]] == "off") { + print "option", opt, "turned on, but requirement", r[j], "is turned off" + err = 1 + } else if (option[r[j]] != "on") { + option[r[j]] = "on" + pending[++npending] = r[j] + } + } + } else { + if (option[opt] != "off") { + print "internal error (2)" + exit 1 + } + nreqs = split(enabledby[opt], r) + for (j=1; j<=nreqs; ++j) { + if (option[r[j]] == "on") { + print "option", opt, "turned off, but enabled by", r[j], "which is turned on" + err = 1 + } else if (option[r[j]] != "off") { + option[r[j]] = "off" + pending[++npending] = r[j] + } + } + } + } + if (err) exit 1 + # option[i] is now the complete list of all the tokens we may # need to output, go through it as above, depth first. finished = 0 @@ -460,7 +592,10 @@ END{ # an 'enabledby' is _SUPPORTED # OR: # NO_name is not defined AND - # the option is not marked "off" + # the option is not disabled; an option is disabled if: + # option == off + # option == disabled && everything != on + # option == "" && everything == off if (deb) print "option", i print "" >out print "/* option:", i, option[i] >out @@ -475,6 +610,11 @@ END{ for (j=1; j<=nreqs; ++j) { print "#ifndef PNG_" r[j] "_SUPPORTED" >out print "# undef PNG_on /*!" r[j] "*/" >out + # this error appears in the final output if something + # was switched 'on' but the processing above to force + # the requires did not work + if (option[i] == "on") + print error, i, "requires", r[j] end >out print "#endif" >out } @@ -491,6 +631,11 @@ END{ } print "#ifdef PNG_no_if /*missing if*/" >out print "# undef PNG_on" >out + # There is no checking above for this, because we + # don't know which 'if' to choose, so whine about + # it here: + if (option[i] == "on") + print error, i, "needs one of:", iffs[i] end >out print "#endif" >out } @@ -503,12 +648,18 @@ END{ for (j=1; j<=nreqs; ++j) { print "#ifdef PNG_" r[j] "_SUPPORTED" >out print "# undef PNG_not_enabled /*" r[j] "*/" >out + # Oops, probably not intended (should be factored + # out by the checks above). + if (option[i] == "off") + print error, i, "enabled by:", r[j] end >out print "#endif" >out } print "# ifndef PNG_" i "_SUPPORTED /*!command line*/" >out print "# ifdef PNG_not_enabled /*!enabled*/" >out - if (option[i] == "off") { + if (option[i] == "off" || + option[i] == "disabled" && everything != "on" || + option[i] == "enabled" && everything == "off") { print "# undef PNG_on /*default off*/" >out } else { print "# ifdef PNG_NO_" i >out @@ -529,7 +680,7 @@ END{ # pnglibconf.h print "# ifdef PNG_on" >out if (i ~ /^fail_/) - print error, i, "if" iffs[i], "requires" requires[i] end >out + print error, i, "is on: enabled by:" iffs[i] enabledby[i] ", requires" requires[i] end >out else if (i !~ /^ok_/) print def i sup >out print "# endif /* definition */" >out @@ -539,7 +690,7 @@ END{ if (logunsupported) print und i une >out if (i ~ /^ok_/) - print error, i, "if" iffs[i], "requires" requires[i] end >out + print error, i, "not enabled: requires:" requires[i] ", enabled by:" iffs[i] enabledby[i] end >out print "#endif" >out } diff --git a/scripts/pnglibconf.dfa b/scripts/pnglibconf.dfa index dbd015e08..708f55337 100644 --- a/scripts/pnglibconf.dfa +++ b/scripts/pnglibconf.dfa @@ -6,7 +6,7 @@ # com pnglibconf.h - library build configuration com -com libpng version PNGLIB_VERSION - last changed on April 27, 2010 +com libpng version PNGLIB_VERSION - last changed on April 28, 2010 com com Copyright (c) 1998-2010 Glenn Randers-Pehrson com @@ -28,11 +28,15 @@ file pnglibconf.h scripts/pnglibconf.dfa PNGLCONF_H # # setting [requires ...] [default] # #define PNG_ /* value comes from current setting */ -# option [requires ...] [if ...] [enables ...] [on|off] +# option [requires ...] [if ...] [enables ...] [disabled] # #define PNG__SUPPORTED if the requirements are met and # enable the other options listed -# chunk [requires ...] [on|off] +# chunk [requires ...] [disabled] # Enable chunk processing for the given ancillary chunk +# +# Note that the 'on' and 'off' keywords, while valid on both option +# and chunk, should not be used in this file because they force the +# relevant options on or off. #---------------------------------------------------------------------- @@ -50,7 +54,7 @@ file pnglibconf.h scripts/pnglibconf.dfa PNGLCONF_H # decoding but does change the libpng API because some chunks # will be ignored. # -# There are three ways of disabling features, in order of correctness: +# There are three ways of disabling features, in no particular order: # # 1) Create 'pngusr.h', enter the required private build information # detailed below and #define PNG_NO_