add new sigc++2 directory
[ardour.git] / libs / cairomm / MSVC / gendef / gendef.cc
1 /*
2  *  MICO --- an Open Source CORBA implementation
3  *  Copyright (c) 2003 Harald B�hme
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  *  For more information, visit the MICO Home Page at
20  *  http://www.mico.org/
21  */
22
23 /* Modified by Cedric Gustin <cedric.gustin@gmail.com> on 2006/01/13 :
24  * Redirect the output of dumpbin to dumpbin.out instead of reading the
25  * output stream of popen, as it fails with Visual Studio 2005 in 
26  * pre-link build events.
27  */
28
29 #include <iostream>
30 #include <fstream>
31 #include <stdio.h>
32
33 using namespace std;
34
35 int main(int argc,char** argv)
36 {
37   if (argc < 4) {
38           cerr << "Usage: " << argv[0] << " <def-file-name> <dll-base-name> <obj-file> ...." << endl;
39           return 2;
40   }
41
42   // CG : Explicitly redirect stdout to dumpbin.out.
43   string dumpbin = "dumpbin /SYMBOLS /OUT:dumpbin.out";
44   int i = 3;
45
46   for(;i<argc;) {
47           dumpbin += " ";
48           dumpbin += argv[i++];
49   }
50
51   FILE * dump; 
52   
53   if( (dump = _popen(dumpbin.c_str(),"r")) == NULL ) {
54           cerr << "could not popen dumpbin" << endl;
55           return 3;
56   }
57
58   // CG : Wait for the dumpbin process to finish and open dumpbin.out.
59   _pclose(dump);
60   dump=fopen("dumpbin.out","r");
61
62   ofstream def_file(argv[1]);
63
64   def_file << "LIBRARY " << argv[2] << endl;
65   def_file << "EXPORTS" << endl;
66
67   i=0;
68   while( !feof(dump)) {
69           char buf [65000]; 
70           
71           if( fgets( buf, 64999, dump ) != NULL ) {
72                   if(!strstr(buf," UNDEF ") && strstr(buf," External ")) {
73                           char *s = strchr(buf,'|') + 1;
74                           while(*s == ' ' || *s == '\t') s++;
75                           char *e=s;
76                           while(*e != ' ' && *e != '\t' && *e != '\0' && *e!= '\n') e++;
77                           *e = '\0';
78                         
79                         if(strchr(s,'?')==0 && s[0]=='_' && strchr(s,'@') == 0 )//this is a C export type: _fct -> fct
80                                   def_file << "    " << (s+1) << endl;                  
81                         else
82                         if(strchr(s,'?')!=0 && strncmp(s,"??_G",4)!=0 && strncmp(s,"??_E",4)!=0) {
83                                   def_file << "    " << s << endl;
84                           }
85                   }
86           }
87   }
88
89   // CG : Close dumpbin.out and delete it.
90   fclose(dump);
91   remove("dumpbin.out");
92
93   cout << dumpbin.c_str() << endl;
94 }