Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #include <stdio.h>
  9. #ifdef _WIN32
  10. #include <windows.h>
  11. #elif _LINUX
  12. #define stricmp strcasecmp
  13. #endif
  14. #include "tier1/strtools.h"
  15. #include "tier0/dbg.h"
  16. #include "KeyValues.h"
  17. #include "cmdlib.h"
  18. #include "tier0/icommandline.h"
  19. #include "vcprojconvert.h"
  20. #include "makefilecreator.h"
  21. SpewRetval_t SpewFunc( SpewType_t type, char const *pMsg )
  22. {
  23. printf( "%s", pMsg );
  24. #ifdef _WIN32
  25. OutputDebugString( pMsg );
  26. #endif
  27. if ( type == SPEW_ERROR )
  28. {
  29. printf( "\n" );
  30. #ifdef _WIN32
  31. OutputDebugString( "\n" );
  32. #endif
  33. }
  34. else if (type == SPEW_ASSERT)
  35. {
  36. return SPEW_DEBUGGER;
  37. }
  38. return SPEW_CONTINUE;
  39. }
  40. class MyFileSystem : public IBaseFileSystem
  41. {
  42. public:
  43. int Read( void* pOutput, int size, FileHandle_t file ) { return fread( pOutput, 1, size, (FILE *)file); }
  44. int Write( void const* pInput, int size, FileHandle_t file ) { return fwrite( pInput, 1, size, (FILE *)file); }
  45. FileHandle_t Open( const char *pFileName, const char *pOptions, const char *pathID = 0 ) { return (FileHandle_t)fopen( pFileName, pOptions); }
  46. void Close( FileHandle_t file ) { fclose( (FILE *)file ); }
  47. void Seek( FileHandle_t file, int pos, FileSystemSeek_t seekType ) {}
  48. unsigned int Tell( FileHandle_t file ) { return 0;}
  49. unsigned int Size( FileHandle_t file ) { return 0;}
  50. unsigned int Size( const char *pFileName, const char *pPathID = 0 ) { return 0; }
  51. void Flush( FileHandle_t file ) { fflush((FILE *)file); }
  52. bool Precache( const char *pFileName, const char *pPathID = 0 ) {return false;}
  53. bool FileExists( const char *pFileName, const char *pPathID = 0 ) {return false;}
  54. bool IsFileWritable( char const *pFileName, const char *pPathID = 0 ) {return false;}
  55. bool SetFileWritable( char const *pFileName, bool writable, const char *pPathID = 0 ) {return false;}
  56. long GetFileTime( const char *pFileName, const char *pPathID = 0 ) { return 0; }
  57. bool ReadFile( const char *pFileName, const char *pPath, CUtlBuffer &buf, int nMaxBytes = 0, int nStartingByte = 0, FSAllocFunc_t pfnAlloc = NULL ) {return false;}
  58. bool WriteFile( const char *pFileName, const char *pPath, CUtlBuffer &buf ) {return false;}
  59. bool UnzipFile( const char *,const char *,const char * ) {return false;}
  60. };
  61. MyFileSystem g_MyFS;
  62. IBaseFileSystem *g_pFileSystem = &g_MyFS;
  63. //-----------------------------------------------------------------------------
  64. // Purpose: help text
  65. //-----------------------------------------------------------------------------
  66. void printusage( void )
  67. {
  68. Msg( "usage: vcprojtomake <vcproj filename> \n" );
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Purpose: debug helper, spits out a human readable keyvalues version of the various configs
  72. //-----------------------------------------------------------------------------
  73. void OutputKeyValuesVersion( CVCProjConvert & proj )
  74. {
  75. KeyValues *kv = new KeyValues( "project" );
  76. for ( int projIndex = 0; projIndex < proj.GetNumConfigurations(); projIndex++ )
  77. {
  78. CVCProjConvert::CConfiguration & config = proj.GetConfiguration(projIndex);
  79. KeyValues *configKv = kv->FindKey( config.GetName().String(), true );
  80. int fileCount = 0;
  81. for( int fileIndex = 0; fileIndex < config.GetNumFileNames(); fileIndex++ )
  82. {
  83. if ( config.GetFileType(fileIndex) == CVCProjConvert::CConfiguration::FILE_SOURCE )
  84. {
  85. char num[20];
  86. Q_snprintf( num, sizeof(num), "%i", fileCount );
  87. fileCount++;
  88. configKv->SetString( num, config.GetFileName(fileIndex) );
  89. }
  90. }
  91. }
  92. kv->SaveToFile( g_pFileSystem, "files.vdf" );
  93. kv->deleteThis();
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose:
  97. // Input : argc -
  98. // argv[] -
  99. // Output : int
  100. //-----------------------------------------------------------------------------
  101. int main( int argc, char* argv[] )
  102. {
  103. SpewOutputFunc( SpewFunc );
  104. Msg( "Valve Software - vcprojtomake.exe (%s)\n", __DATE__ );
  105. CommandLine()->CreateCmdLine( argc, argv );
  106. if ( CommandLine()->ParmCount() < 2)
  107. {
  108. printusage();
  109. return 0;
  110. }
  111. CVCProjConvert proj;
  112. if ( !proj.LoadProject( CommandLine()->GetParm( 1 )) )
  113. {
  114. Msg( "Failed to parse project\n" );
  115. return -1;
  116. }
  117. OutputKeyValuesVersion(proj);
  118. CMakefileCreator makefile;
  119. makefile.CreateMakefiles( proj );
  120. return 0;
  121. }