tag_dll.awk 4.31 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#! /usr/bin/env awk
#
# Create reference tags and WIN32 initialization functions for tags.
#
# --------------------------------------------------------------------
#
# This file is part of the Sofia-SIP package
#
# Copyright (C) 2005 Nokia Corporation.
#
# Contact: Pekka Pessi <pekka.pessi@nokia.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
#
# --------------------------------------------------------------------
#
# Author: Pekka Pessi <Pekka.Pessi@nokia.com>
#
# Created: Tue Feb 26 14:11:25 2002 ppessi
#

BEGIN {
  DEFS = 0;
  HEADER = 1;
}

HEADER {
  HEADER = 0;

  if (OUTNAME != "") {
    fn = OUTNAME;
  } else {
    fn = FILENAME;
  }

49 50 51 52
  if (REF == "") {
    REF = fn;
    sub(/[.]c(at)?/, "_ref.c", REF);
  }
Pekka Pessi's avatar
Pekka Pessi committed
53 54 55

  if (NODLL) DLL = "/dev/null";

56 57 58 59 60
  if (DLL == "") {
    DLL = fn;
    sub(/[.]c(at)?/, "_dll.c", DLL);
  }

Pekka Pessi's avatar
Pekka Pessi committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  base = fn;
  sub(/.*\//, "", base);

  printf("#ifdef _WIN32\n"\
	 "/*\n" \
	 " * PLEASE NOTE: \n" \
	 " * \n" \
	 " * This file is automatically generated by tag_dll.awk.\n"\
	 " * It contains magic required by Win32 DLLs to initialize\n"\
	 " * tag_typedef_t variables.\n"\
	 " * \n"\
	 " * Do not, repeat, do not edit this file. Edit '%s' instead.\n"\
	 " * \n"\
	 " */\n\n"\
	 "#define EXPORT __declspec(dllexport)\n\n", base) > DLL;

  if (DLLREF) {
    print \
      "#include \"config.h\"\n\n" \
80
      "#include <sofia-sip/su_tag_class.h>\n\n" > DLL;
Pekka Pessi's avatar
Pekka Pessi committed
81 82 83 84 85 86 87 88 89 90 91 92
  }

  printf("/*\n" \
	 " * PLEASE NOTE: \n" \
	 " * \n" \
	 " * This file is automatically generated by tag_dll.awk.\n"\
	 " * It contains tag_typedef_t for tag references.\n"\
	 " * \n"\
	 " * Do not, repeat, do not edit this file. Edit '%s' instead.\n"\
	 " * \n"\
	 " */\n\n"\
	 "#include \"config.h\"\n\n"\
93
	 "#include <sofia-sip/su_tag_class.h>\n"\
Pekka Pessi's avatar
Pekka Pessi committed
94
	 "\n"\
95
	 "#if defined _WIN32 || defined HAVE_OPEN_C\n"\
Pekka Pessi's avatar
Pekka Pessi committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
	 "#define EXPORT __declspec(dllexport)\n"\
	 "#else\n"\
	 "#define EXPORT\n"\
	 "#endif\n\n",
	 base) > REF;

  if (LIST) {
    print "#include <stddef.h>" >REF;
  }
  print "" > REF;
}

/^#define TAG_NAMESPACE/ { 
  print "#undef TAG_NAMESPACE" > REF; 
  print $0 > REF; 
111
  print "" > REF;
Pekka Pessi's avatar
Pekka Pessi committed
112 113
  print "#undef TAG_NAMESPACE" > DLL; 
  print $0 > DLL; 
114
  print "" > DLL;
Pekka Pessi's avatar
Pekka Pessi committed
115 116
}

117 118 119 120 121
/SU_HAVE_EXPERIMENTAL/ { 
  print $0 > REF; 
  print $0 > DLL; 
}

Pekka Pessi's avatar
Pekka Pessi committed
122 123 124 125 126
!DEFS && /^tag_typedef_t/ { DEFS = 1; }

DEFS && /tag_typedef_t/ {
  tag = $2;
  typedefs[tag] = $0;
127 128 129

  if ($0 !~ /NSTAG_TYPEDEF/) {
    print "extern tag_typedef_t "tag";" > REF;
130
    print "EXPORT tag_typedef_t "tag"_ref;" > DLL;
131
    print "EXPORT tag_typedef_t "tag"_ref = \n  REFTAG_TYPEDEF("tag");" > REF;
Pekka Pessi's avatar
Pekka Pessi committed
132
  }
133 134

  gsub(/ = .*$/, ";");
Pekka Pessi's avatar
Pekka Pessi committed
135 136
}

137
!DLLREF { print $0 > DLL; }
Pekka Pessi's avatar
Pekka Pessi committed
138 139 140 141 142 143

END {
  if (LIST) {
    print "\nEXPORT tag_type_t " LIST "[] =\n{" > REF;
    print "\nEXPORT tag_type_t " LIST "[] =\n{" > DLL; 
    for (tag in typedefs) {
144 145 146 147
      if (typedefs[tag] !~ /NSTAG_TYPEDEF/) {
        print "  " tag "," > REF;
        print "  " tag "," > DLL;
      }
Pekka Pessi's avatar
Pekka Pessi committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    }
    print "  NULL\n};" > REF;
    print "  NULL\n};" > DLL;
  }

  printf("\n" \
	 "#include <windows.h>\n"\
	 "\n"\
	 "BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fwdReason, LPVOID fImpLoad)\n"\
	 "{\n") > DLL;

   for (tag in typedefs) {
     def = typedefs[tag];
     if (!DLLREF) {
       sub(/^tag_typedef_t /, "  tag_typedef_t _", def);
       print def > DLL;
     }
     else {
       print "  extern tag_typedef_t "tag";" > DLL;
     }
     print "  tag_typedef_t _"tag"_ref =\n    REFTAG_TYPEDEF("tag");" > DLL;
   }

   print "" > DLL;

   for (tag in typedefs) {
     if (!DLLREF) {
       print "  *(struct tag_type_s *)" tag " = *_" tag ";" > DLL;
     }
     print "  *(struct tag_type_s *)" tag "_ref = *_" tag "_ref;" > DLL;
   }

   print "\n  return TRUE;" > DLL;
   print "}" > DLL;
   print "\n#endif" > DLL;
}