Uses Reference if compiler has no port

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@48 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
tslettebo 2002-09-16 01:58:52 +00:00
parent 0b9d261d9b
commit ad7e89ad22
31 changed files with 509 additions and 470 deletions

View file

@ -1,9 +1,18 @@
///////////////////////////////////////////////////////////////
//Generates forwarding headers using the information
//in the header.lst & vendor.lst files
////////////////////////////////////////////////////////////////////////////////
// Generates forwarding headers using the information
// in the header.lst & vendor.lst files
//
//To create a header list from an existing directory of headers
//dir *.h /b > headers.lst
// To create a header list from an existing directory of headers
// dir *.h /b > headers.lst
//
// Copyright Shannon Barber 2002.
//
// Permission to use, copy, modify, distribute and sell this software for any
// purpose is hereby granted without fee, provided that the above copyright
// notice appear in all copies and that both that copyright notice and this
// permission notice appear in supporting documentation. It is provided "as is"
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <fstream>
@ -11,6 +20,7 @@
#include <sstream>
#include <vector>
#include <ctime>
using namespace std;
struct Compiler
@ -23,62 +33,49 @@ struct Compiler
string subdir;
};
typedef vector<Compiler> cv_t;
int main(int argc, char* argv[])
{
if(argc < 2)
if(argc != 3)
{
cout <<"Usage: <Header List> [Version/Vendor List]"<<endl;
cout <<"Usage: <Header List> <Version/Vendor List>"<<endl;
return -1;
}
typedef vector<Compiler> cv_type;
cv_t vendors;
cv_type vendors;
char buf[1024];
string check;
string subdir;
fstream vendor_file;
if(argc >= 3)
vendor_file.open(argv[2], ios::in);
if(!vendor_file.is_open())
{
vendor_file.open(argv[2], ios::in);
if(!vendor_file.is_open())
cout << "Unable to open vendor file: " << argv[2] << endl;
return -2;
}
else
{
vendors.reserve(10);
while(!vendor_file.eof())
{
cout << "Unable to open vendor file: " << argv[2] << endl;
return -2;
}
else
{
vendors.reserve(10);
while(!vendor_file.eof())
vendor_file.getline(buf, 1024, '\n');
check = buf;
vendor_file.getline(buf, 1024, '\n');
subdir = buf;
vendor_file.getline(buf, 1024, '\n');
if(!(check.empty() || subdir.empty()))
vendors.push_back(Compiler(check, subdir));
else
{
check = "";
subdir = "";
vendor_file.getline(buf, 1024, '\n');
check = buf;
vendor_file.getline(buf, 1024, '\n');
subdir = buf;
vendor_file.getline(buf, 1024, '\n');
if(!(check.empty() || subdir.empty()))
vendors.push_back(Compiler(check, subdir));
else
{
cout << "Error parsing vendors, check:" << check << "\tsubdir:" << subdir << endl;
}
cout << "Error parsing vendors, check:" << check << "\tsubdir:" << subdir << endl;
}
}
}
else //if(vendors.empty())
{
cout << "No vendor file provided, using defaults\n";
vendors.reserve(10);
vendors.push_back(Compiler("(_MSC_VER >= 1300)", "MSVC\\1300"));
vendors.push_back(Compiler("(__BORLANDC__)", "Borland"));
vendors.push_back(Compiler("( (__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ > 95)) )", "Reference"));
}
fstream header_list(argv[1]);
string header;
stringstream ss;
if(!header_list.is_open())
{
@ -96,49 +93,47 @@ int main(int argc, char* argv[])
}
else
{
ss.str("");
ss << "//Generated header: " << header << endl;
size_t n = ss.str().size();
for(size_t i=0; i<n; ++i)
header_file << "/";
header_file << endl;
header_file << ss.str();
header_file << "//Forwards to the appropriate code\n";
string start(string("// Generated header: ")+header+'\n');
string line(start.size(),'/');
header_file << line << '\n';
header_file << start;
header_file << "// Forwards to the appropriate code\n";
header_file << "// that works on the detected compiler\n";
time_t rawtime; time(&rawtime);
header_file << "//Generated on " << ctime(&rawtime);
header_file << endl << endl;
cv_t::iterator it=vendors.begin(), itEnd = vendors.end();
time_t rawtime;
time(&rawtime);
header_file << "// Generated on " << ctime(&rawtime);
header_file << line << "\n\n";
cv_type::iterator it=vendors.begin(), itEnd = vendors.end();
header_file << "#ifdef LOKI_USE_REFERENCE\n";
header_file << "#\tinclude \"./Reference/" << header << "\"\n";
//header_file << "#\tinclude \".\\Reference\\" << header << "\"\n";
header_file << "#\tinclude \"Reference/" << header << "\"\n";
header_file << "#else\n";
header_file << "#\tif " << it->version_test << endl;
//header_file << "#\t\tinclude \".\\" << it->subdir;
header_file << "#\t\tinclude \"./" << it->subdir;
//header_file << "\\" << header << "\"\n";
header_file << "/" << header << "\"\n";
header_file << "#\t\tinclude \"" << it->subdir << "/" << header << "\"\n";
++it;
for(; it!=itEnd; ++it)
{
header_file << "#\telif " << it->version_test << endl;
//header_file << "#\t\tinclude \".\\" << it->subdir;
header_file << "#\t\tinclude \"./" << it->subdir;
//header_file << "\\" << header << "\"\n";
header_file << "#\t\tinclude \"" << it->subdir;
header_file << "/" << header << "\"\n";
}
header_file << "#\telse\n";
header_file << "\t\t//Define LOKI_USE_REFERENCE and get back to us on the results\n";
header_file << "#\t\terror Compiler not tested with Loki, #define LOKI_USE_REFERENCE\n";
header_file << "#\t\tinclude \"Reference/" << header << "\"\n";
header_file << "#\tendif\n";
header_file << "#endif\n";
}
}
#ifdef _MSC_VER
system("PAUSE");
#endif
return 0;
}
}
////////////////////////////////////////////////////////////////////////////////
// Change log:
// September 16, 2002: Changed it to only test for compilers where ports exist,
// else use the Reference version. It used to give an error if used on a
// compiler that wasn't tested for. Also removed "./".
// It still needs to test for Intel and Metrowerks, as these define _MSC_VER,
// too. T.S.
////////////////////////////////////////////////////////////////////////////////