diff options
Diffstat (limited to 'mps/code/expgen.sh')
| -rwxr-xr-x | mps/code/expgen.sh | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/mps/code/expgen.sh b/mps/code/expgen.sh new file mode 100755 index 00000000000..54c8daca2dc --- /dev/null +++ b/mps/code/expgen.sh | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # $Header$ | ||
| 3 | # | ||
| 4 | # Copyright (C) 2004 Ravenbrook Limited. All rights reserved. | ||
| 5 | # | ||
| 6 | # expgen.sh | ||
| 7 | # | ||
| 8 | # Export Generator | ||
| 9 | # | ||
| 10 | # This is a script to generate the a list of exports that is required | ||
| 11 | # for Windows DLL creation. | ||
| 12 | # | ||
| 13 | # It processed the mps header files and produces a .DEF file that is | ||
| 14 | # suitable for use with the linker when producing a DLL file on Windows. | ||
| 15 | # | ||
| 16 | # When run, this script produces the following output files: | ||
| 17 | # expgen - a plain text list of functions declared in the header files. | ||
| 18 | # w3gen.def - a .def file suitable for use in the linker stage when | ||
| 19 | # building a Windows .DLL. | ||
| 20 | # | ||
| 21 | # | ||
| 22 | # Design | ||
| 23 | # | ||
| 24 | # The script works by using the -fdump-translation-unit option of gcc. | ||
| 25 | # This produces a more easily parseable rendering of the header files. | ||
| 26 | # A fairly simple awk script is used to process the output. | ||
| 27 | # | ||
| 28 | # | ||
| 29 | # Dependencies | ||
| 30 | # | ||
| 31 | # This script currently depends fairly heavily on being run in a | ||
| 32 | # Unix-like environment with access to the GNU compiler. | ||
| 33 | # | ||
| 34 | # It's also fairly sensitive to changes in the undocumented format | ||
| 35 | # produced by gcc -fdump-translation-unit. Hopefully it is fairly easy | ||
| 36 | # to adapt to changes in this output. | ||
| 37 | # | ||
| 38 | # Assumes it can freely write to the files "fun", "name-s". | ||
| 39 | # | ||
| 40 | # | ||
| 41 | # Awk crash course | ||
| 42 | # | ||
| 43 | # Awk processes files line-by-line, thus the entire script is executed | ||
| 44 | # for each line of the input file (more complex awk scripts can control | ||
| 45 | # this using "next" and "getline" and so on). | ||
| 46 | # | ||
| 47 | # In awk $exp identifies a field within the line. $1 is the first | ||
| 48 | # field, $2 is the second and so on. $0 is the whole line. By default | ||
| 49 | # fields are separated by whitespace. | ||
| 50 | # | ||
| 51 | # string ~ RE is a matching expression and evaulated to true iff the | ||
| 52 | # string is matched by the regular expression. | ||
| 53 | # | ||
| 54 | # REFERENCES | ||
| 55 | # | ||
| 56 | # [SUSV3] Single UNIX Specification Version 3, | ||
| 57 | # http://www.unix.org/single_unix_specification/ | ||
| 58 | # | ||
| 59 | # For documenation of the standard utilities: sh, awk, join, sort, sed | ||
| 60 | # | ||
| 61 | # [MSDN-LINKER-DEF] Module-Definition (.def) files, | ||
| 62 | # http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_module.2d.definition_files.asp | ||
| 63 | # | ||
| 64 | # For documentation on the format of .def files. | ||
| 65 | |||
| 66 | tu () { | ||
| 67 | # if invoked on a file called spong.h will produce a file named | ||
| 68 | # spong.h.tu | ||
| 69 | gcc -fdump-translation-unit -o /dev/null "$@" | ||
| 70 | } | ||
| 71 | |||
| 72 | # This list of header files is produced by | ||
| 73 | # awk '/^copy.*\.h/{print $2}' w3build.bat | ||
| 74 | # followed by manual removal of mpsw3.h mpswin.h. | ||
| 75 | # The functions declared in mpsw3.h have to be added to the .def file by | ||
| 76 | # hand later in this script. | ||
| 77 | f='mps.h | ||
| 78 | mpsavm.h | ||
| 79 | mpsacl.h | ||
| 80 | mpscamc.h | ||
| 81 | mpscams.h | ||
| 82 | mpscawl.h | ||
| 83 | mpsclo.h | ||
| 84 | mpscmv.h | ||
| 85 | mpscmvff.h | ||
| 86 | mpscsnc.h | ||
| 87 | mpsio.h | ||
| 88 | mpslib.h | ||
| 89 | mpstd.h' | ||
| 90 | |||
| 91 | tu $f | ||
| 92 | |||
| 93 | >expgen | ||
| 94 | |||
| 95 | for a in $f | ||
| 96 | do | ||
| 97 | >fun | ||
| 98 | awk ' | ||
| 99 | $2=="function_decl" && $7=="srcp:" && $8 ~ /^'$a':/ {print $4 >"fun"} | ||
| 100 | $2=="identifier_node"{print $1,$4} | ||
| 101 | ' $a.tu | | ||
| 102 | sort -k 1 >name-s | ||
| 103 | |||
| 104 | echo ';' $a >>expgen | ||
| 105 | sort -k 1 fun | | ||
| 106 | join -o 2.2 - name-s >>expgen | ||
| 107 | done | ||
| 108 | |||
| 109 | { | ||
| 110 | printf '%sHeader%s\n' '$' '$' | ||
| 111 | echo '; DO NOT EDIT. Automatically generated by $Header$' | sed 's/\$/!/g' | ||
| 112 | echo 'EXPORTS' | ||
| 113 | cat expgen | ||
| 114 | # This is where we manually the functions declared in mpsw3.h | ||
| 115 | echo ';' mpsw3.h - by hand | ||
| 116 | echo mps_SEH_filter | ||
| 117 | echo mps_SEH_handler | ||
| 118 | } > w3gen.def | ||