/********************************************************************** * Premake - vs2002_cs.c * The Visual Studio 2002 and 2003 C# target * * Copyright (c) 2002-2005 Jason Perkins and the Premake project * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License in the file LICENSE.txt for details. **********************************************************************/ #include #include #include #include "premake.h" #include "vs.h" #include "vs2002.h" static const char* listReferences(const char* name); static const char* listFiles(const char* name); int vs2002_cs() { const char* outputType; int i; VsPkgData* data = (VsPkgData*)prj_get_data(); /* Figure out what I'm building */ prj_select_config(0); if (prj_is_kind("winexe")) outputType = "WinExe"; else if (prj_is_kind("exe")) outputType = "Exe"; else if (prj_is_kind("dll") || prj_is_kind("aspnet")) outputType = "Library"; else { printf("** Error: unknown package kind '%s'\n", prj_get_kind()); return 0; } /* Open the file and write the header */ if (!io_openfile(path_join(prj_get_pkgpath(), prj_get_pkgname(), "csproj"))) return 0; io_print("\n"); io_print("\tprojGuid); io_print("\t>\n"); io_print("\t\t\n"); io_print("\t\t\t\n"); for (i = 0; i < prj_get_numconfigs(); ++i) { int optimize; prj_select_config(i); optimize = prj_has_flag("optimize") || prj_has_flag("optimize-size") || prj_has_flag("optimize-speed"); io_print("\t\t\t\t\n"); } io_print("\t\t\t\n"); /* VS7 requires same references for all configurations */ prj_select_config(0); io_print("\t\t\t\n"); print_list(prj_get_links(), "\t\t\t\t\n", "", listReferences); io_print("\t\t\t\n"); io_print("\t\t\n"); io_print("\t\t\n"); io_print("\t\t\t\n"); print_list(prj_get_files(), "\t\t\t\t\n", "", listFiles); io_print("\t\t\t\n"); io_print("\t\t\n"); io_print("\t\n"); io_print("\n"); io_closefile(); /* Now write the .csproj.user file for non-web applications or * .csproj.webinfo for web applications */ if (!prj_is_kind("aspnet")) { if (!io_openfile(path_join(prj_get_pkgpath(), prj_get_pkgname(), "csproj.user"))) return 0; io_print("\n"); io_print("\t\n"); io_print("\t\t\n"); io_print("\t\t\t\n"); for (i = 0; i < prj_get_numconfigs(); ++i) { prj_select_config(i); io_print("\t\t\t\t\n"); } io_print("\t\t\t\n"); io_print("\t\t\n"); io_print("\t\t\n"); io_print("\t\n"); io_print("\n"); } else { if (!io_openfile(path_join(prj_get_pkgpath(), prj_get_pkgname(), "csproj.webinfo"))) return 0; io_print("\n"); io_print("\t\n", prj_get_pkgname()); io_print("\n"); } io_closefile(); return 1; } /************************************************************************ * Checks each entry in the list of package links. If the entry refers * to a sibling package, returns the path to that package's output ***********************************************************************/ static const char* listReferences(const char* name) { char assembly[8192]; char* comma; int i; /* Pull out the file name, the comma check is for full assembly names */ strcpy(assembly, name); comma = strchr(name, ','); if (comma != NULL) *comma = '\0'; strcpy(g_buffer, "\t\t\t\t\tName = \""); strcat(g_buffer, assembly); strcat(g_buffer, "\"\n"); /* Is this a sibling package? */ i = prj_find_package(name); if (i >= 0) { VsPkgData* data = (VsPkgData*)prj_get_data_for(i); strcat(g_buffer, "\t\t\t\t\tProject = \"{"); strcat(g_buffer, data->projGuid); strcat(g_buffer, "}\"\n"); strcat(g_buffer, "\t\t\t\t\tPackage = \"{"); strcat(g_buffer, data->toolGuid); strcat(g_buffer, "}\"\n"); return g_buffer; } strcat(g_buffer, "\t\t\t\t\tAssemblyName = \""); strcat(g_buffer, path_getname(assembly)); strcat(g_buffer, "\"\n"); if (!matches(assembly, path_getname(assembly))) { strcat(g_buffer, "\t\t\t\t\tHintPath = \""); strcat(g_buffer, assembly); strcat(g_buffer, ".dll\"\n"); } /* Tack on any extra information about the assembly */ while (comma != NULL) { char* start; for (start = comma + 1; *start == ' '; ++start); comma = strchr(start, '='); *comma = '\0'; strcat(g_buffer, "\t\t\t\t\t"); strcat(g_buffer, start); strcat(g_buffer, " = \""); start = comma + 1; comma = strchr(start, ','); if (comma != NULL) *comma = '\0'; strcat(g_buffer, start); strcat(g_buffer, "\"\n"); } return g_buffer; } /************************************************************************ * Builds an entry for each file in the project ***********************************************************************/ static const char* listFiles(const char* name) { io_print("\t\t\t\t\n"); return NULL; }