subst.in 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/awk
  2. function which(c,path) {
  3. cmd = "test -x " c;
  4. if (system(cmd)==0) {
  5. return c;
  6. }
  7. sub(/\/.*\//,"",c);
  8. for (dir in path) {
  9. cmd = "test -x " path[dir] "/" c;
  10. if (system(cmd)==0) {
  11. return path[dir] "/" c;
  12. }
  13. }
  14. return c;
  15. }
  16. # used to replace "use lib utils.pm" with "use lib @libexecdir"
  17. #
  18. function led() {
  19. led1 = "@libexecdir@";
  20. led2 = "@exec_prefix@";
  21. led3 = "@prefix@";
  22. if ( match(led1, /^\$\{exec_prefix\}/ ) != 0 ) {
  23. return "\"" led3 "/libexec\" " ;
  24. }
  25. return "\"" led1 "\"" ;
  26. }
  27. BEGIN {
  28. split(ENVIRON["PATH"] ":/sbin:/usr/sbin",path,/:/);
  29. }
  30. # Plugin revision
  31. /@NP_VERSION@/ {sub(/@NP_VERSION@/,ENVIRON["NP_VERSION"]);}
  32. # scripting language (first line)
  33. /^#! ?\/.*\/python/ {sub(/^#! ?\/.*\/python/,"#! @PYTHON@");}
  34. /^#! ?\/.*\/perl/ {sub(/^#! ?\/.*\/perl/,"#! @PERL@");}
  35. /^#! ?\/.*\/[a-z]{0,2}awk/ {sub(/^#! ?\/.*\/[a-z]{0,2}awk/,"#! @AWK@");}
  36. /^#! ?\/.*\/sh/ {sub(/^#! ?\/.*\/sh/,"#! @SHELL@");}
  37. # If a script contains a reference to a fully qualified command,
  38. # subst will replace the fully qualified command with whatever is
  39. # returned from the which subroutine. run before changes to INC to add libexecdir
  40. # FIXME: Prepend executables with a substitution keyword instead.
  41. #
  42. /^[^#]/ && /(\/.*)?\/(bin|sbin|lib|libexec)\// {
  43. match($0,/(\/.*)?\/(bin|sbin|lib|libexec)\/[-_a-zA-Z0-9]+/);
  44. c=substr($0,RSTART,RLENGTH);
  45. sub(c,which(c,path));
  46. }
  47. # add to libexecdir to INC for perl utils.pm
  48. /^use/ { if (/lib/) { if (/utils.pm|"."/ ) {sub(/utils.pm|"."/,led() )} } }
  49. # Trusted path mechanism (deprecated)
  50. /^[ \t]*\$ENV[ \t]*\{[ \t'"]*PATH[ \t"']*\}[ \t]*=/ {
  51. sub(/\=[ \t]*['"][^"']+["']/,"='@with_trusted_path@' # autoconf-derived");
  52. }
  53. /^[\t ]*(export[\t ]*)?PATH[\t ]*=['"]+.+["']$/ {
  54. sub(/\=.*$/,"='@with_trusted_path@' # autoconf-derived");
  55. }
  56. {
  57. print;
  58. }