options.awk 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. #!/bin/awk -f
  2. # scripts/options.awk - library build configuration control
  3. #
  4. # last changed in libpng version 1.5.7 - December 15, 2011
  5. #
  6. # Copyright (c) 1998-2011 Glenn Randers-Pehrson
  7. #
  8. # This code is released under the libpng license.
  9. # For conditions of distribution and use, see the disclaimer
  10. # and license in png.h
  11. # The output of this script is written to the file given by
  12. # the variable 'out'. The script is run twice, once with
  13. # an intermediate output file, 'options.tmp' then again on
  14. # that file to produce the final output:
  15. #
  16. # awk -f scripts/options.awk out=options.tmp scripts/options.dfa 1>&2
  17. # awk -f scripts/options.awk out=options.dfn options.tmp 1>&2
  18. #
  19. # Some options may be specified on the command line:
  20. #
  21. # deb=1 Causes debugging to be output
  22. # logunsupported=1 Causes all options to be recorded in the output
  23. # everything=off Causes all options to be disabled by default
  24. # everything=on Causes all options to be enabled by default
  25. #
  26. # If awk fails on your platform, try nawk instead.
  27. #
  28. # These options may also be specified in the original input file (and
  29. # are copied to the preprocessed file).
  30. BEGIN{
  31. out="/dev/null" # intermediate, preprocessed, file
  32. pre=-1 # preprocess (first line)
  33. version="libpng version unknown" # version information
  34. version_file="" # where to find the version
  35. err=0 # in-line exit sets this
  36. start="PNG_DEFN_MAGIC-" # Arbitrary start
  37. end="-PNG_DEFN_END" # Arbitrary end
  38. ct="PNG_JOIN" # Join two tokens
  39. cx= "/" ct "*" # Open C comment for output file
  40. comment=start cx # Comment start
  41. cend="*/" end # Comment end
  42. def=start "#define PNG_" ct # Arbitrary define
  43. sup=ct "_SUPPORTED" end # end supported option
  44. und=comment "#undef PNG_" ct # Unsupported option
  45. une=ct "_SUPPORTED" cend # end unsupported option
  46. error=start "ERROR:" # error message
  47. # Variables
  48. deb=0 # debug - set on command line
  49. everything="" # do not override defaults
  50. logunsupported=0 # write unsupported options too
  51. # Precreate arrays
  52. option[""] = "" # list of all options: default enabled/disabled
  53. done[""] = 1 # marks option as having been output
  54. requires[""] = "" # requires by option
  55. iffs[""] = "" # if by option
  56. enabledby[""] = "" # options that enable it by option
  57. setting[""] = "" # requires by setting
  58. defaults[""] = "" # used for a defaulted value
  59. doneset[""] = 1 # marks setting as having been output
  60. r[""] = "" # Temporary array
  61. # For decorating the output file
  62. protect = ""
  63. }
  64. # The output file must be specified before any input:
  65. out == "/dev/null" {
  66. print "out=output.file must be given on the command line"
  67. err = 1
  68. exit 1
  69. }
  70. # The very first line indicates whether we are reading pre-processed
  71. # input or not, this must come *first* because 'PREPROCESSED' needs
  72. # to be the very first line in the temporary file.
  73. pre == -1{
  74. if ($0 == "PREPROCESSED") {
  75. pre = 0
  76. next
  77. } else {
  78. pre = 1
  79. print "PREPROCESSED" >out
  80. # And fall through to continue processing
  81. }
  82. }
  83. # While pre-processing if version is set to "search" look for a version string
  84. # in the following file.
  85. pre && version == "search" && version_file == ""{
  86. version_file = FILENAME
  87. }
  88. pre && version == "search" && version_file != FILENAME{
  89. print "version string not found in", version_file
  90. err = 1
  91. exit 1
  92. }
  93. pre && version == "search" && $0 ~ /^ \* libpng version/{
  94. version = substr($0, 4)
  95. print "version =", version >out
  96. next
  97. }
  98. pre && FILENAME == version_file{
  99. next
  100. }
  101. # variable=value
  102. # Sets the given variable to the given value (the syntax is fairly
  103. # free form, except for deb (you are expected to understand how to
  104. # set the debug variable...)
  105. #
  106. # This happens before the check on 'pre' below skips most of the
  107. # rest of the actions, so the variable settings happen during
  108. # preprocessing but are recorded in the END action too. This
  109. # allows them to be set on the command line too.
  110. $0 ~ /^[ ]*version[ ]*=/{
  111. sub(/^[ ]*version[ ]*=[ ]*/, "")
  112. version = $0
  113. next
  114. }
  115. $0 ~ /^[ ]*everything[ =]*off[ ]*$/{
  116. everything = "off"
  117. next
  118. }
  119. $0 ~ /^[ ]*everything[ =]*on[ ]*$/{
  120. everything = "on"
  121. next
  122. }
  123. $0 ~ /^[ ]*logunsupported[ =]*0[ ]*$/{
  124. logunsupported = 0
  125. next
  126. }
  127. $0 ~ /^[ ]*logunsupported[ =]*1[ ]*$/{
  128. logunsupported = 1
  129. next
  130. }
  131. $1 == "deb" && $2 == "=" && NF == 3{
  132. deb = $3
  133. next
  134. }
  135. # Preprocessing - this just copies the input file with lines
  136. # that need preprocessing (just chunk at present) expanded
  137. # The bare "pre" instead of "pre != 0" crashes under Sunos awk
  138. pre && $1 != "chunk"{
  139. print >out
  140. next
  141. }
  142. # The first characters of the line determine how it is processed,
  143. # leading spaces are ignored. In general tokens that are not
  144. # keywords are the names of options. An option 'name' is
  145. # controlled by the definition of the corresponding macros:
  146. #
  147. # PNG_name_SUPPORTED The option is turned on
  148. # PNG_NO_name
  149. # PNG_NO_name_SUPPORTED If the first macro is not defined
  150. # either of these will turn the option off
  151. #
  152. # If none of these macros are defined the option is turned on, unless
  153. # the keyword 'off' is given in a line relating to the option. The
  154. # keyword 'on' can also be given, but it will be ignored (since it is
  155. # the default.)
  156. #
  157. # In the syntax below a 'name' is indicated by "NAME", other macro
  158. # values are indicated by "MACRO", as with "NAME" the leading "PNG_"
  159. # is omitted, but in this case the "NO_" prefix and the "_SUPPORTED"
  160. # suffix are never used.
  161. #
  162. # Each line is introduced by a keyword - the first non-space characters
  163. # on the line. A line starting with a '#' is a comment - it is totally
  164. # ignored. Keywords are as follows, a NAME, is simply a macro name
  165. # without the leading PNG_, PNG_NO_ or the trailing _SUPPORTED.
  166. $1 ~ /^#/ || $0 ~ /^[ ]*$/{
  167. next
  168. }
  169. # com <comment>
  170. # The whole line is placed in the output file as a comment with
  171. # the preceding 'com' removed
  172. $1 == "com"{
  173. if (NF > 1) {
  174. # sub(/^[ ]*com[ ]*/, "")
  175. $1 = ""
  176. print comment, $0, cend >out
  177. } else
  178. print start end >out
  179. next
  180. }
  181. # version
  182. # Inserts a version comment
  183. $1 == "version" && NF == 1{
  184. if (version == "") {
  185. print "ERROR: no version string set"
  186. err = 1 # prevent END{} running
  187. exit 1
  188. }
  189. print comment, version, cend >out
  190. next
  191. }
  192. # file output input protect
  193. # Informational: the official name of the input file (without
  194. # make generated local directories), the official name of the
  195. # output file and, if required, a name to use in a protection
  196. # macro for the contents.
  197. $1 == "file" && NF >= 2{
  198. print comment, $2, cend >out
  199. print comment, "Machine generated file: DO NOT EDIT", cend >out
  200. if (NF >= 3)
  201. print comment, "Derived from:", $3, cend >out
  202. protect = $4
  203. if (protect != "") {
  204. print start "#ifndef", protect end >out
  205. print start "#define", protect end >out
  206. }
  207. next
  208. }
  209. # option NAME ( (requires|enables|if) NAME* | on | off | disabled )*
  210. # Declares an option 'NAME' and describes its default setting (disabled)
  211. # and its relationship to other options. The option is disabled
  212. # unless *all* the options listed after 'requires' are set and at
  213. # least one of the options listed after 'if' is set. If the
  214. # option is set then it turns on all the options listed after 'enables'.
  215. #
  216. # Note that "enables" takes priority over the required/if/disabled/off
  217. # setting of the target option.
  218. #
  219. # The definition file may list an option as 'disabled': off by default,
  220. # otherwise the option is enabled: on by default. A later (and it must
  221. # be later) entry may turn an option on or off explicitly.
  222. $1 == "option" && NF >= 2{
  223. onoff = option[$2] # records current (and the default is "", enabled)
  224. key = ""
  225. for (i=3; i<=NF; ++i) {
  226. if ($(i) == "on" || $(i) == "off" || $(i) == "disabled") {
  227. key = ""
  228. if (onoff != $(i)) {
  229. # on or off can zap disabled or enabled:
  230. if (onoff == "" || (onoff == "disabled" || onoff == "enabled") && ($(i) == "on" || $(i) == "off")) {
  231. # It's easy to mis-spell the option when turning it
  232. # on or off, so warn about it here:
  233. if (onoff == "" && ($(i) == "on" || $(i) == "off")) {
  234. print $2 ": ERROR: turning unrecognized option", $(i)
  235. # For the moment error out - it is safer
  236. err = 1 # prevent END{} running
  237. exit 1
  238. }
  239. onoff = $(i)
  240. } else {
  241. # Print a message, otherwise the error
  242. # below is incomprehensible
  243. print $2 ": currently", onoff ": attempt to turn", $(i)
  244. break
  245. }
  246. }
  247. } else if ($(i) == "requires" || $(i) == "if" || $(i) == "enables") {
  248. key = $(i)
  249. } else if (key == "requires") {
  250. requires[$2] = requires[$2] " " $(i)
  251. } else if (key == "if") {
  252. iffs[$2] = iffs[$2] " " $(i)
  253. } else if (key == "enables") {
  254. enabledby[$(i)] = enabledby[$(i)] " " $2
  255. } else
  256. break # bad line format
  257. }
  258. if (i > NF) {
  259. # Set the option, defaulting to 'enabled'
  260. if (onoff == "") onoff = "enabled"
  261. option[$2] = onoff
  262. next
  263. }
  264. # Else fall through to the error handler
  265. }
  266. # chunk NAME [requires OPT] [on|off|disabled]
  267. # Expands to the 'option' settings appropriate to the reading and
  268. # writing of an ancilliary PNG chunk 'NAME':
  269. #
  270. # option READ_NAME requires READ_ANCILLARY_CHUNKS [READ_OPT]
  271. # option READ_NAME enables NAME
  272. # [option READ_NAME off]
  273. # option WRITE_NAME requires WRITE_ANCILLARY_CHUNKS [WRITE_OPT]
  274. # option WRITE_NAME enables NAME
  275. # [option WRITE_NAME off]
  276. pre != 0 && $1 == "chunk" && NF >= 2{
  277. # 'chunk' is handled on the first pass by writing appropriate
  278. # 'option' lines into the intermediate file.
  279. onoff = ""
  280. reqread = ""
  281. reqwrite = ""
  282. i = 3 # indicates format error
  283. if (NF > 2) {
  284. # read the keywords/additional OPTS
  285. req = 0
  286. for (i=3; i<=NF; ++i) {
  287. if ($(i) == "on" || $(i) == "off" || $(i) == "disabled") {
  288. if (onoff != $(i)) {
  289. if (onoff == "")
  290. onoff = $(i)
  291. else
  292. break # on/off conflict
  293. }
  294. } else if ($(i) == "requires")
  295. req = 1
  296. else if (req != 1)
  297. break # bad line: handled below
  298. else {
  299. reqread = reqread " READ_" $(i)
  300. reqwrite = reqwrite " WRITE_" $(i)
  301. }
  302. }
  303. }
  304. if (i > NF) {
  305. # Output new 'option' lines to the intermediate file (out)
  306. print "option READ_" $2, "requires READ_ANCILLARY_CHUNKS" reqread, "enables", $2, onoff >out
  307. print "option WRITE_" $2, "requires WRITE_ANCILLARY_CHUNKS" reqwrite, "enables", $2, onoff >out
  308. next
  309. }
  310. # Else hit the error handler below - bad line format!
  311. }
  312. # setting MACRO ( requires MACRO* )* [ default VALUE ]
  313. # Behaves in a similar way to 'option' without looking for NO_ or
  314. # _SUPPORTED; the macro is enabled if it is defined so long as all
  315. # the 'requires' macros are also defined. The definitions may be
  316. # empty, an error will be issued if the 'requires' macros are
  317. # *not* defined. If given the 'default' value is used if the
  318. # macro is not defined. The default value will be re-tokenised.
  319. # (BTW: this is somewhat restrictive, it mainly exists for the
  320. # support of non-standard configurations and numeric parameters,
  321. # see the uses in scripts/options.dat
  322. $1 == "setting" && (NF == 2 || NF >= 3 && ($3 == "requires" || $3 == "default")){
  323. reqs = ""
  324. deflt = ""
  325. isdef = 0
  326. key = ""
  327. for (i=3; i<=NF; ++i)
  328. if ($(i) == "requires" || $(i) == "default") {
  329. key = $(i)
  330. if (key == "default") isdef = 1
  331. } else if (key == "requires")
  332. reqs = reqs " " $(i)
  333. else if (key == "default")
  334. deflt = deflt " " $(i)
  335. else
  336. break # Format error, handled below
  337. setting[$2] = reqs
  338. # NOTE: this overwrites a previous value silently
  339. if (isdef && deflt == "")
  340. deflt = " " # as a flag to force output
  341. defaults[$2] = deflt
  342. next
  343. }
  344. # The order of the dependency lines (option, chunk, setting) is irrelevant
  345. # - the 'enables', 'requires' and 'if' settings will be used to determine
  346. # the correct order in the output and the final values in pnglibconf.h are
  347. # not order dependent. 'requires' and 'if' entries take precedence over
  348. # 'enables' from other options; if an option requires another option it
  349. # won't be set regardless of any options that enable it unless the other
  350. # option is also enabled.
  351. #
  352. # Similarly 'enables' trumps a NO_ definition in CFLAGS or pngusr.h
  353. #
  354. # For simplicity cycles in the definitions are regarded as errors,
  355. # even if they are not ambiguous.
  356. # A given NAME can be specified in as many 'option' lines as required, the
  357. # definitions are additive.
  358. # For backwards compatibility equivalent macros may be listed thus:
  359. #
  360. # = [NO_]NAME MACRO
  361. # Makes -DMACRO equivalent to -DPNG_NO_NAME or -DPNG_NAME_SUPPORTED
  362. # as appropriate.
  363. #
  364. # The definition is injected into the C compiler input when encountered
  365. # in the second pass (so all these definitions appear *after* the @
  366. # lines!)
  367. #
  368. # 'NAME' is as above, but 'MACRO' is the full text of the equivalent
  369. # old, deprecated, macro.
  370. $1 == "=" && NF == 3{
  371. print "#ifdef PNG_" $3 >out
  372. if ($2 ~ /^NO_/)
  373. print "# define PNG_" $2 >out
  374. else
  375. print "# define PNG_" $2 "_SUPPORTED" >out
  376. print "#endif" >out
  377. next
  378. }
  379. # Lines may be injected into the C compiler input by preceding them
  380. # with an "@" character. The line is copied with just the leading
  381. # @ removed.
  382. $1 ~ /^@/{
  383. # sub(/^[ ]*@/, "")
  384. $1 = substr($1, 2)
  385. print >out
  386. next
  387. }
  388. # Check for unreognized lines, because of the preprocessing chunk
  389. # format errors will be detected on the first pass independent of
  390. # any other format errors.
  391. {
  392. print "options.awk: bad line (" NR "):", $0
  393. err = 1 # prevent END{} running
  394. exit 1
  395. }
  396. # For checking purposes names that start with "ok_" or "fail_" are
  397. # not output to pnglibconf.h and must be either enabled or disabled
  398. # respectively for the build to succeed. This allows interdependencies
  399. # between options of the form "at least one of" or "at most one of"
  400. # to be checked. For example:
  401. #
  402. # option FLOATING_POINT enables ok_math
  403. # option FIXED_POINT enables ok_math
  404. # This ensures that at least one of FLOATING_POINT and FIXED_POINT
  405. # must be set for the build to succeed.
  406. #
  407. # option fail_math requires FLOATING_POINT FIXED_POINT
  408. # This means the build will fail if *both* FLOATING_POINT and
  409. # FIXED_POINT are set (this is an example; in fact both are allowed.)
  410. #
  411. # If all these options were given the build would require exactly one
  412. # of the names to be enabled.
  413. END{
  414. # END{} gets run on an exit (a traditional awk feature)
  415. if (err) exit 1
  416. if (pre) {
  417. # Record the final value of the variables
  418. print "deb =", deb >out
  419. if (everything != "") {
  420. print "everything =", everything >out
  421. }
  422. print "logunsupported =", logunsupported >out
  423. exit 0
  424. }
  425. # Do the 'setting' values first, the algorithm the standard
  426. # tree walk (O(1)) done in an O(2) while/for loop; interations
  427. # settings x depth, outputing the deepest required macros
  428. # first.
  429. print "" >out
  430. print "/* SETTINGS */" >out
  431. print comment, "settings", cend >out
  432. finished = 0
  433. while (!finished) {
  434. finished = 1
  435. movement = 0 # done nothing
  436. for (i in setting) if (!doneset[i]) {
  437. nreqs = split(setting[i], r)
  438. if (nreqs > 0) {
  439. for (j=1; j<=nreqs; ++j) if (!doneset[r[j]]) {
  440. break
  441. }
  442. if (j<=nreqs) {
  443. finished = 0
  444. continue # try a different setting
  445. }
  446. }
  447. # All the requirements have been processed, output
  448. # this setting.
  449. if (deb) print "setting", i
  450. print "" >out
  451. print "/* setting: ", i >out
  452. print " * requires:" setting[i] >out
  453. print " * default: ", defaults[i], "*/" >out
  454. if (defaults[i] == "") { # no default, only check if defined
  455. print "#ifdef PNG_" i >out
  456. }
  457. for (j=1; j<=nreqs; ++j) {
  458. print "# ifndef PNG_" r[j] >out
  459. print error, i, "requires", r[j] end >out
  460. print "# endif" >out
  461. }
  462. if (defaults[i] != "") { # default handling
  463. print "#ifdef PNG_" i >out
  464. }
  465. print def i, "PNG_" i end >out
  466. if (defaults[i] != "") {
  467. print "#else /*default*/" >out
  468. # And add the default definition for the benefit
  469. # of later settings an options test:
  470. print "# define PNG_" i defaults[i] >out
  471. print def i defaults[i] end >out
  472. }
  473. print "#endif" >out
  474. doneset[i] = 1
  475. ++movement
  476. }
  477. if (!finished && !movement) {
  478. print "setting: loop or missing setting in 'requires', cannot process:"
  479. for (i in setting) if (!doneset[i]) {
  480. print " setting", i, "requires" setting[i]
  481. }
  482. exit 1
  483. }
  484. }
  485. print comment, "end of settings", cend >out
  486. # Now do the options - somewhat more complex. The dependency
  487. # tree is thus:
  488. #
  489. # name > name
  490. # name requires name
  491. # name if name
  492. # name enabledby name
  493. #
  494. # First build a list 'tree' by option of all the things on which
  495. # it depends.
  496. print "" >out
  497. print "/* OPTIONS */" >out
  498. print comment, "options", cend >out
  499. for (opt in enabledby) tree[opt] = 1 # may not be explicit options
  500. for (opt in option) if (opt != "") {
  501. o = option[opt]
  502. # option should always be one of the following values
  503. if (o != "on" && o != "off" && o != "disabled" && o != "enabled") {
  504. print "internal option error (" o ")"
  505. exit 1
  506. }
  507. tree[opt] = "" # so unlisted options marked
  508. }
  509. for (opt in tree) if (opt != "") {
  510. if (tree[opt] == 1) {
  511. tree[opt] = ""
  512. if (option[opt] != "") {
  513. print "internal error (1)"
  514. exit 1
  515. }
  516. # Macros only listed in 'enables' remain off unless
  517. # one of the enabling macros is on.
  518. option[opt] = "disabled"
  519. }
  520. split("", list) # clear 'list'
  521. # Now add every requires, iffs or enabledby entry to 'list'
  522. # so that we can add a unique list of requirements to tree[i]
  523. split(requires[opt] iffs[opt] enabledby[opt], r)
  524. for (i in r) list[r[i]] = 1
  525. for (i in list) tree[opt] = tree[opt] " " i
  526. }
  527. # print the tree for extreme debugging
  528. if (deb > 2) for (i in tree) if (i != "") print i, "depends-on" tree[i]
  529. # Ok, now check all options marked explicitly 'on' or 'off':
  530. #
  531. # If an option[opt] is 'on' then turn on all requires[opt]
  532. # If an option[opt] is 'off' then turn off all enabledby[opt]
  533. #
  534. # Error out if we have to turn 'on' an 'off' option or vice versa.
  535. npending = 0
  536. for (opt in option) if (opt != "") {
  537. if (option[opt] == "on" || option[opt] == "off") {
  538. pending[++npending] = opt
  539. }
  540. }
  541. err = 0 # set on error
  542. while (npending > 0) {
  543. opt = pending[npending--]
  544. if (option[opt] == "on") {
  545. nreqs = split(requires[opt], r)
  546. for (j=1; j<=nreqs; ++j) {
  547. if (option[r[j]] == "off") {
  548. print "option", opt, "turned on, but requirement", r[j], "is turned off"
  549. err = 1
  550. } else if (option[r[j]] != "on") {
  551. option[r[j]] = "on"
  552. pending[++npending] = r[j]
  553. }
  554. }
  555. } else {
  556. if (option[opt] != "off") {
  557. print "internal error (2)"
  558. exit 1
  559. }
  560. nreqs = split(enabledby[opt], r)
  561. for (j=1; j<=nreqs; ++j) {
  562. if (option[r[j]] == "on") {
  563. print "option", opt, "turned off, but enabled by", r[j], "which is turned on"
  564. err = 1
  565. } else if (option[r[j]] != "off") {
  566. option[r[j]] = "off"
  567. pending[++npending] = r[j]
  568. }
  569. }
  570. }
  571. }
  572. if (err) exit 1
  573. # option[i] is now the complete list of all the tokens we may
  574. # need to output, go through it as above, depth first.
  575. finished = 0
  576. while (!finished) {
  577. finished = 1
  578. movement = 0 # done nothing
  579. for (i in option) if (!done[i]) {
  580. nreqs = split(tree[i], r)
  581. if (nreqs > 0) {
  582. for (j=1; j<=nreqs; ++j) if (!done[r[j]]) {
  583. break
  584. }
  585. if (j<=nreqs) {
  586. finished = 0
  587. continue # next option
  588. }
  589. }
  590. # All the requirements have been processed, output
  591. # this option. An option is _SUPPORTED if:
  592. #
  593. # all 'requires' are _SUPPORTED AND
  594. # at least one of the 'if' options are _SUPPORTED AND
  595. # EITHER:
  596. # The name is _SUPPORTED (on the command line)
  597. # OR:
  598. # an 'enabledby' is _SUPPORTED
  599. # OR:
  600. # NO_name is not defined AND
  601. # the option is not disabled; an option is disabled if:
  602. # option == off
  603. # option == disabled && everything != on
  604. # option == "" && everything == off
  605. if (deb) print "option", i
  606. print "" >out
  607. print "/* option:", i, option[i] >out
  608. print " * requires: " requires[i] >out
  609. print " * if: " iffs[i] >out
  610. print " * enabled-by:" enabledby[i], "*/" >out
  611. print "#undef PNG_on" >out
  612. print "#define PNG_on 1" >out
  613. # requires
  614. nreqs = split(requires[i], r)
  615. for (j=1; j<=nreqs; ++j) {
  616. print "#ifndef PNG_" r[j] "_SUPPORTED" >out
  617. print "# undef PNG_on /*!" r[j] "*/" >out
  618. # this error appears in the final output if something
  619. # was switched 'on' but the processing above to force
  620. # the requires did not work
  621. if (option[i] == "on") {
  622. print error, i, "requires", r[j] end >out
  623. }
  624. print "#endif" >out
  625. }
  626. # if
  627. nreqs = split(iffs[i], r)
  628. print "#undef PNG_no_if" >out
  629. if (nreqs > 0) {
  630. print "/* if" iffs[i], "*/" >out
  631. print "#define PNG_no_if 1" >out
  632. for (j=1; j<=nreqs; ++j) {
  633. print "#ifdef PNG_" r[j] "_SUPPORTED" >out
  634. print "# undef PNG_no_if /*" r[j] "*/" >out
  635. print "#endif" >out
  636. }
  637. print "#ifdef PNG_no_if /*missing if*/" >out
  638. print "# undef PNG_on" >out
  639. # There is no checking above for this, because we
  640. # don't know which 'if' to choose, so whine about
  641. # it here:
  642. if (option[i] == "on") {
  643. print error, i, "needs one of:", iffs[i] end >out
  644. }
  645. print "#endif" >out
  646. }
  647. print "#ifdef PNG_on /*requires, if*/" >out
  648. # enables
  649. print "# undef PNG_not_enabled" >out
  650. print "# define PNG_not_enabled 1" >out
  651. print " /* enabled by" enabledby[i], "*/" >out
  652. nreqs = split(enabledby[i], r)
  653. for (j=1; j<=nreqs; ++j) {
  654. print "#ifdef PNG_" r[j] "_SUPPORTED" >out
  655. print "# undef PNG_not_enabled /*" r[j] "*/" >out
  656. # Oops, probably not intended (should be factored
  657. # out by the checks above).
  658. if (option[i] == "off") {
  659. print error, i, "enabled by:", r[j] end >out
  660. }
  661. print "#endif" >out
  662. }
  663. print "# ifndef PNG_" i "_SUPPORTED /*!command line*/" >out
  664. print "# ifdef PNG_not_enabled /*!enabled*/" >out
  665. if (option[i] == "off" || option[i] == "disabled" && everything != "on" || option[i] == "enabled" && everything == "off") {
  666. print "# undef PNG_on /*default off*/" >out
  667. } else {
  668. print "# ifdef PNG_NO_" i >out
  669. print "# undef PNG_on /*turned off*/" >out
  670. print "# endif" >out
  671. print "# ifdef PNG_NO_" i "_SUPPORTED" >out
  672. print "# undef PNG_on /*turned off*/" >out
  673. print "# endif" >out
  674. }
  675. print "# endif /*!enabled*/" >out
  676. print "# ifdef PNG_on" >out
  677. # The _SUPPORTED macro must be defined so that dependent
  678. # options output later work.
  679. print "# define PNG_" i "_SUPPORTED" >out
  680. print "# endif" >out
  681. print "# endif /*!command line*/" >out
  682. # If PNG_on is still set the option should be defined in
  683. # pnglibconf.h
  684. print "# ifdef PNG_on" >out
  685. if (i ~ /^fail_/) {
  686. print error, i, "is on: enabled by:" iffs[i] enabledby[i] ", requires" requires[i] end >out
  687. } else if (i !~ /^ok_/) {
  688. print def i sup >out
  689. }
  690. print "# endif /* definition */" >out
  691. print "#endif /*requires, if*/" >out
  692. if (logunsupported || i ~ /^ok_/) {
  693. print "#ifndef PNG_on" >out
  694. if (logunsupported) {
  695. print und i une >out
  696. }
  697. if (i ~ /^ok_/) {
  698. print error, i, "not enabled: requires:" requires[i] ", enabled by:" iffs[i] enabledby[i] end >out
  699. }
  700. print "#endif" >out
  701. }
  702. done[i] = 1
  703. ++movement
  704. }
  705. if (!finished && !movement) {
  706. print "option: loop or missing option in dependency tree, cannot process:"
  707. for (i in option) if (!done[i]) {
  708. print " option", i, "depends on" tree[i], "needs:"
  709. nreqs = split(tree[i], r)
  710. if (nreqs > 0) for (j=1; j<=nreqs; ++j) if (!done[r[j]]) {
  711. print " " r[j]
  712. }
  713. }
  714. exit 1
  715. }
  716. }
  717. print comment, "end of options", cend >out
  718. # Regular end - everything looks ok
  719. if (protect != "") {
  720. print start "#endif", cx, protect, "*/" end >out
  721. }
  722. }