tag_dll.awk 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #! /usr/bin/env awk
  2. #
  3. # Create reference tags and WIN32 initialization functions for tags.
  4. #
  5. # --------------------------------------------------------------------
  6. #
  7. # This file is part of the Sofia-SIP package
  8. #
  9. # Copyright (C) 2005 Nokia Corporation.
  10. #
  11. # Contact: Pekka Pessi <pekka.pessi@nokia.com>
  12. #
  13. # This library is free software; you can redistribute it and/or
  14. # modify it under the terms of the GNU Lesser General Public License
  15. # as published by the Free Software Foundation; either version 2.1 of
  16. # the License, or (at your option) any later version.
  17. #
  18. # This library is distributed in the hope that it will be useful, but
  19. # WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. # Lesser General Public License for more details.
  22. #
  23. # You should have received a copy of the GNU Lesser General Public
  24. # License along with this library; if not, write to the Free Software
  25. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  26. # 02110-1301 USA
  27. #
  28. # --------------------------------------------------------------------
  29. #
  30. # Author: Pekka Pessi <Pekka.Pessi@nokia.com>
  31. #
  32. # Created: Tue Feb 26 14:11:25 2002 ppessi
  33. #
  34. BEGIN {
  35. DEFS = 0;
  36. HEADER = 1;
  37. }
  38. HEADER {
  39. HEADER = 0;
  40. if (OUTNAME != "") {
  41. fn = OUTNAME;
  42. } else {
  43. fn = FILENAME;
  44. }
  45. if (REF == "") {
  46. REF = fn;
  47. sub(/[.]c(at)?/, "_ref.c", REF);
  48. }
  49. if (NODLL) DLL = "/dev/null";
  50. if (DLL == "") {
  51. DLL = fn;
  52. sub(/[.]c(at)?/, "_dll.c", DLL);
  53. }
  54. base = fn;
  55. sub(/.*\//, "", base);
  56. printf("#ifdef _WIN32\n"\
  57. "/*\n" \
  58. " * PLEASE NOTE: \n" \
  59. " * \n" \
  60. " * This file is automatically generated by tag_dll.awk.\n"\
  61. " * It contains magic required by Win32 DLLs to initialize\n"\
  62. " * tag_typedef_t variables.\n"\
  63. " * \n"\
  64. " * Do not, repeat, do not edit this file. Edit '%s' instead.\n"\
  65. " * \n"\
  66. " */\n\n"\
  67. "#define EXPORT __declspec(dllexport)\n\n", base) > DLL;
  68. if (DLLREF) {
  69. print \
  70. "#include \"config.h\"\n\n" \
  71. "#include <sofia-sip/su_tag_class.h>\n\n" > DLL;
  72. }
  73. printf("/*\n" \
  74. " * PLEASE NOTE: \n" \
  75. " * \n" \
  76. " * This file is automatically generated by tag_dll.awk.\n"\
  77. " * It contains tag_typedef_t for tag references.\n"\
  78. " * \n"\
  79. " * Do not, repeat, do not edit this file. Edit '%s' instead.\n"\
  80. " * \n"\
  81. " */\n\n"\
  82. "#include \"config.h\"\n\n"\
  83. "#include <sofia-sip/su_tag_class.h>\n"\
  84. "\n"\
  85. "#if defined _WIN32 || defined HAVE_OPEN_C\n"\
  86. "#define EXPORT __declspec(dllexport)\n"\
  87. "#else\n"\
  88. "#define EXPORT\n"\
  89. "#endif\n\n",
  90. base) > REF;
  91. if (LIST) {
  92. print "#include <stddef.h>" >REF;
  93. }
  94. print "" > REF;
  95. }
  96. /^#define TAG_NAMESPACE/ {
  97. print "#undef TAG_NAMESPACE" > REF;
  98. print $0 > REF;
  99. print "" > REF;
  100. print "#undef TAG_NAMESPACE" > DLL;
  101. print $0 > DLL;
  102. print "" > DLL;
  103. }
  104. /SU_HAVE_EXPERIMENTAL/ {
  105. print $0 > REF;
  106. print $0 > DLL;
  107. }
  108. !DEFS && /^tag_typedef_t/ { DEFS = 1; }
  109. DEFS && /tag_typedef_t/ {
  110. tag = $2;
  111. typedefs[tag] = $0;
  112. if ($0 !~ /NSTAG_TYPEDEF/) {
  113. print "extern tag_typedef_t "tag";" > REF;
  114. print "EXPORT tag_typedef_t "tag"_ref;" > DLL;
  115. print "EXPORT tag_typedef_t "tag"_ref = \n REFTAG_TYPEDEF("tag");" > REF;
  116. }
  117. gsub(/ = .*$/, ";");
  118. }
  119. !DLLREF { print $0 > DLL; }
  120. END {
  121. if (LIST) {
  122. print "\nEXPORT tag_type_t " LIST "[] =\n{" > REF;
  123. print "\nEXPORT tag_type_t " LIST "[] =\n{" > DLL;
  124. for (tag in typedefs) {
  125. if (typedefs[tag] !~ /NSTAG_TYPEDEF/) {
  126. print " " tag "," > REF;
  127. print " " tag "," > DLL;
  128. }
  129. }
  130. print " NULL\n};" > REF;
  131. print " NULL\n};" > DLL;
  132. }
  133. printf("\n" \
  134. "#include <windows.h>\n"\
  135. "\n"\
  136. "BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fwdReason, LPVOID fImpLoad)\n"\
  137. "{\n") > DLL;
  138. for (tag in typedefs) {
  139. def = typedefs[tag];
  140. if (!DLLREF) {
  141. sub(/^tag_typedef_t /, " tag_typedef_t _", def);
  142. print def > DLL;
  143. }
  144. else {
  145. print " extern tag_typedef_t "tag";" > DLL;
  146. }
  147. print " tag_typedef_t _"tag"_ref =\n REFTAG_TYPEDEF("tag");" > DLL;
  148. }
  149. print "" > DLL;
  150. for (tag in typedefs) {
  151. if (!DLLREF) {
  152. print " *(struct tag_type_s *)" tag " = *_" tag ";" > DLL;
  153. }
  154. print " *(struct tag_type_s *)" tag "_ref = *_" tag "_ref;" > DLL;
  155. }
  156. print "\n return TRUE;" > DLL;
  157. print "}" > DLL;
  158. print "\n#endif" > DLL;
  159. }