Debian Codegraph @

texk/kpathsea/cnf-to-paths.awk

raw
1 # $Id: cnf-to-paths.awk 46719 2018-02-23 19:30:01Z karl $
2 # cnf-to-paths.awk - convert texmf.cnf assignments to paths.h #define's.
3 # Public domain. Originally written 2011, Karl Berry.
4
5 # We assume comments have been stripped.
6 #
7 # we only care about definitions with a valid C identifier (e.g.,
8 # TEXINPUTS, not TEXINPUTS.latex), that is, lines that look like this:
9 # <name> = <value>
10 # (whitespace around the = is optional)
11 #
12 /^[ \t]*[A-Z0-9_]+[ \t]*=/ {
13 # On these lines, we distinguish three cases:
14 #
15 # 1) definitions referring to SELFAUTO*, which we want to keep. In
16 # particular, this is how the compile-time TEXMFCNF gets defined and
17 # thus how texmf.cnf gets found. In fact, TEXMFCNF is the only
18 # relevant compile-time value at all, and since its value is not used
19 # from texmf.cnf, we could simplify this whole process in both
20 # directions. Maybe someday.
21 #
22 # 2) definitions starting with a /, which we also want to keep. Here
23 # we assume a distro maintainer has changed a variable, e.g.,
24 # TEXMFMAIN=/usr/share/texmf, so keep it. (This also preserves the
25 # default values for OSFONTDIR and TRFONTS, but that's ok.)
26 #
27 # 3) anything else, which we want to convert to a constant /nonesuch.
28 # That way, the binaries don't get changed just because we change
29 # definitions in texmf.cnf.
30 #
31 # The definition of DEFAULT_TEXMFROOT (and other variables)
32 # that winds up in the final paths.h will not be used.
33
34 # Extract the identifier and the value from the line. Since
35 # gawk's subexpression matching is an extension, do it with copies.
36 ident = $0;
37 sub(/^[ \t]*/, "", ident);
38 sub(/[ \t]*=.*/, "", ident);
39
40 val = $0;
41 sub(/^.*=[ \t]*/, "", val);
42 sub(/[ \t]*$/, "", val);
43 #print "got ident", ident, "and val", val >"/dev/stderr";
44
45 if (val ~ /\$SELFAUTO/) {
46 # Replace all semicolons with colons in the SELFAUTO paths we're keeping.
47 # (The path-splitting code should be changed to understand both.)
48 gsub(/;/, ":", val);
49 } else if (val ~ /^\//) {
50 # If the value starts with /, presume we're compiling with changes
51 # made for a distro, and keep it. Likewise switch to :.
52 gsub(/;/, ":", val);
53 } else {
54 val = "/nonesuch";
55 }
56
57 print "#ifndef DEFAULT_" ident;
58 print "#define DEFAULT_" ident " \"" val "\"";
59 print "#endif";
60 print "";
61 }