Table of Contents

Scripted makefile generator reference

This chapter contains description of functions and classes WinGDB adds to Lua for generating build files. Before starting wrtiting scripts, you can familiarize yourself with Lua syntax by reading this section. Full language manual is contained here.

Classes

The script language is object-oriented. Each variable can have a scalar type (integer, boolean or string) or a class type. In Lua you do not specify type of variable explicitly -- it is determined from the expression type.

Thich section describes various classes that WinGDB makefile generator adds to Lua. There are several categories of the classes, listed in subsections below.

Utility classes

VSUtils class is the class of the root object used to access Visual Studio functionality. There is one global instance of VSUtils, named just vs. It offers the means to access project hierarchy, diagnostic functions (printing to Visual Studio console) and path manipulation functions.

Regex class offers regular expression matching for strings.

Core project model classes

Those classes provide access to essential bits of Visual Studio project model. They are likely to be used in all of makefile-generating scripts.

VSSolution provides access to Visual Studio solution, its properties and contained projects.

VSProject represents a Visual Studio project, with extended support for Visual C++ projects.

VSProjectItem represents an item inside a Visual Studio project, typically a file or folder.

VSProjects is a collection of projects.

VSProjectItems is a collection of project items.

Additional project model classes

Those classes provide additional access to Visual Studio project model, but are not frequently used.

VSConfigurationManager: access to DTE ConfigurationManager object.

VSConfigurations: access to DTE Configurations collection.

VSConfiguration: access to DTE Configuration object.

VSOutputGroups: access to DTE OutputGroups collection.

VSOutputGroup: access to DTE OutputGroup object.

VSProperties: access to DTE Properties collection.

VSProperty: access to DTE Property object.

Method reference

All WinGDB-specific functions called from scripts are methods. Particularly, some "global" functions are methods of the VSUtils class, which has a single instance named vs. In all cases, use the : Lua operator to access the methods.

Methods are presented in C-like syntax. Argument and return types are either references to classes, or scalar types. In the latter case, bool, int and string represent standard Lua boolean, integer and string types. The strings type is standard lua array (a table indexed with 1-based numbers) containing strings.

Some of methods returning classes may return nil value, however it is expected only in error condition and should not normally occur. It might be reasonable to test returned class references against nil however, if you want absolute robustness.

If argument name is presented inside square brackets (e.g. [cfgName]), then it is optional. You may omit the argument, and WinGDB will assume default value (e.g. currently selected configuration).

Some collection classes have a method called item. It returns the item having specified index. Note that the index in these item is zero based, like in C/C++ and not like in Lua tables (where indexes are 1-based).

Other method names are self-descriptive, so the method purpose is not repeated explicitly. Many methods of classes VSProject and VSProjectItem return values of project (or file) properties, specific to Visual Studio C/C++ projects. These properties have CL or LN letters in names, denoting a compiler or linker property. The WG tag denotes a WinGDB-specific property, configured on WinGDB property page.

The VSUtils class has a method named evaluate. This method allows to evaluate all variables ($(name) constructs) within given string. You must specify project and configuration name, as it is important to determine the context of the evaluation.

The filter argument (in getProjectSources) accepts a list of file name wildcards separated by semicolons, e.g. *.c;*.cpp.

Regex

    bool matches ( string text );
    strings match ( string text );
    strings search ( string text );

VSConfiguration

    VSConfigurationManager getCollection();
    string getConfigurationName();
    string getPlatformName();
    int getType();
    VSProperties getProperties();
    bool getIsBuildable();
    bool getIsRunnable();
    bool getIsDeployable();
    VSOutputGroups getOutputGroups();

VSConfigurationManager

    VSConfiguration item ( int index, string platform );
    int getCount();
    VSConfigurations configurationRow ( string name );
    VSConfigurations platform ( string name );
    VSConfiguration getActiveConfiguration();
    strings getConfigurationRowNames();
    strings getPlatformNames();
    strings getSupportedPlatforms();

VSConfigurations

    unsigned int count();
    VSConfiguration item ( unsigned int index );

VSOutputGroup

    VSOutputGroups getCollection();
    int getFileCount();
    string getDisplayName();
    string getCanonicalName();
    string getDescription();
    strings getFileNames();
    strings getFileURLs();

VSOutputGroups

    unsigned int count();
    VSOutputGroup item ( unsigned int index );

VSProject

    string getName();
    string getFileName();
    bool getIsDirty();
    bool getSaved();
    string getKind();
    VSProjectItems getProjectItems();
    string getUniqueName();
    string getFullName();
    VSProjectItem getParentProjectItem();
    VSProjects getCollection();
    VSProperties getProperties();
    VSConfigurationManager getConfigurationManager();
    strings getProjectSources ( string filter, string [cfgName] );
    VSProjectItem findItemByPath ( string filePath );
    int getIntProperty ( string cfgName, string propName );
    bool getBoolProperty ( string cfgName, string propName );
    string getStringProperty ( string cfgName, string propName );
    string getProjName ( string [cfgName] );
    string getProjDirectory ( string [cfgName] );
    string getProjFile ( string [cfgName] );
    string getProjFileEncoding ( string [cfgName] );
    string getProjProjGuid ( string [cfgName] );
    string getProjRootNamespace ( string [cfgName] );
    string getProjSccName ( string [cfgName] );
    string getProjSccAuxPath ( string [cfgName] );
    string getProjSccLocalPath ( string [cfgName] );
    string getProjSccProvider ( string [cfgName] );
    int getProjFileFormat ( string [cfgName] );
    int getProjMajorVersion ( string [cfgName] );
    int getProjMinorVersion ( string [cfgName] );
    bool getProjIsDirty ( string [cfgName] );
    bool getProjShowAllFiles ( string [cfgName] );
    bool getProjIsUpToDate ( string [cfgName] );
    bool getProjRegisterOutput ( string [cfgName] );
    int getProjConfigType ( string [cfgName] );
    int getProjUseOfMFC ( string [cfgName] );
    int getProjUseOfATL ( string [cfgName] );
    int getProjCharacterSet ( string [cfgName] );
    int getProjManagedExtensions ( string [cfgName] );
    int getProjWholeProgramOptimization ( string [cfgName] );
    string getProjOutputDirectory ( string [cfgName] );
    string getProjIntermediateDirectory ( string [cfgName] );
    string getProjPrimaryOutput ( string [cfgName] );
    string getProjImportLibrary ( string [cfgName] );
    string getProjProgramDatabase ( string [cfgName] );
    string getProjDeleteExtensionsOnClean ( string [cfgName] );
    string getProjExcludeBuckets ( string [cfgName] );
    string getCLAdditionalOptions ( string [cfgName] );
    string getCLAdditionalIncludeDirectories ( string [cfgName] );
    string getCLAdditionalUsingDirectories ( string [cfgName] );
    string getCLPreprocessorDefinitions ( string [cfgName] );
    string getCLPrecompiledHeaderThrough ( string [cfgName] );
    string getCLPrecompiledHeaderFile ( string [cfgName] );
    string getCLAssemblerListingLocation ( string [cfgName] );
    string getCLObjectFile ( string [cfgName] );
    string getCLProgramDataBaseFileName ( string [cfgName] );
    string getCLBrowseInformationFile ( string [cfgName] );
    string getCLDisableSpecificWarnings ( string [cfgName] );
    string getCLForcedIncludeFiles ( string [cfgName] );
    string getCLForcedUsingFiles ( string [cfgName] );
    string getCLUndefinePreprocessorDefinitions ( string [cfgName] );
    string getCLToolPath ( string [cfgName] );
    string getCLFullIncludePath ( string [cfgName] );
    string getCLToolKind ( string [cfgName] );
    string getCLXMLDocumentationFileName ( string [cfgName] );
    int getCLWarningLevel ( string [cfgName] );
    int getCLDebugInformationFormat ( string [cfgName] );
    int getCLCompileAsManaged ( string [cfgName] );
    int getCLOptimization ( string [cfgName] );
    int getCLInlineFunctionExpansion ( string [cfgName] );
    int getCLFavorSizeOrSpeed ( string [cfgName] );
    int getCLGeneratePreprocessedFile ( string [cfgName] );
    int getCLExceptionHandling ( string [cfgName] );
    int getCLBasicRuntimeChecks ( string [cfgName] );
    int getCLRuntimeLibrary ( string [cfgName] );
    int getCLStructMemberAlignment ( string [cfgName] );
    int getCLFloatingPointModel ( string [cfgName] );
    int getCLUsePrecompiledHeader ( string [cfgName] );
    int getCLAssemblerOutput ( string [cfgName] );
    int getCLBrowseInformation ( string [cfgName] );
    int getCLCallingConvention ( string [cfgName] );
    int getCLCompileAs ( string [cfgName] );
    int getCLEnableEnhancedInstructionSet ( string [cfgName] );
    int getCLErrorReporting ( string [cfgName] );
    bool getCLWarnAsError ( string [cfgName] );
    bool getCLSuppressStartupBanner ( string [cfgName] );
    bool getCLDetect64BitPortabilityProblems ( string [cfgName] );
    bool getCLEnableIntrinsicFunctions ( string [cfgName] );
    bool getCLOmitFramePointers ( string [cfgName] );
    bool getCLEnableFiberSafeOptimizations ( string [cfgName] );
    bool getCLWholeProgramOptimization ( string [cfgName] );
    bool getCLIgnoreStandardIncludePath ( string [cfgName] );
    bool getCLKeepComments ( string [cfgName] );
    bool getCLStringPooling ( string [cfgName] );
    bool getCLMinimalRebuild ( string [cfgName] );
    bool getCLSmallerTypeCheck ( string [cfgName] );
    bool getCLBufferSecurityCheck ( string [cfgName] );
    bool getCLEnableFunctionLevelLinking ( string [cfgName] );
    bool getCLFloatingPointExceptions ( string [cfgName] );
    bool getCLDisableLanguageExtensions ( string [cfgName] );
    bool getCLDefaultCharIsUnsigned ( string [cfgName] );
    bool getCLTreatWCharAsBuiltInType ( string [cfgName] );
    bool getCLForceConformanceInForLoopScope ( string [cfgName] );
    bool getCLRuntimeTypeInfo ( string [cfgName] );
    bool getCLOpenMP ( string [cfgName] );
    bool getCLExpandAttributedSource ( string [cfgName] );
    bool getCLShowIncludes ( string [cfgName] );
    bool getCLUndefineAllPreprocessorDefinitions ( string [cfgName] );
    bool getCLEnablePREfast ( string [cfgName] );
    bool getCLCompileOnly ( string [cfgName] );
    bool getCLUseUnicodeResponseFiles ( string [cfgName] );
    bool getCLGenerateXMLDocumentationFiles ( string [cfgName] );
    bool getCLUseFullPaths ( string [cfgName] );
    bool getCLOmitDefaultLibName ( string [cfgName] );
    bool getLNSuppressStartupBanner ( string [cfgName] );
    bool getLNIgnoreImportLibrary ( string [cfgName] );
    bool getLNRegisterOutput ( string [cfgName] );
    bool getLNLinkDLL ( string [cfgName] );
    bool getLNIgnoreAllDefaultLibraries ( string [cfgName] );
    bool getLNIgnoreEmbeddedIDL ( string [cfgName] );
    bool getLNGenerateDebugInformation ( string [cfgName] );
    bool getLNGenerateMapFile ( string [cfgName] );
    bool getLNMapExports ( string [cfgName] );
    bool getLNSwapRunFromCD ( string [cfgName] );
    bool getLNSwapRunFromNet ( string [cfgName] );
    bool getLNResourceOnlyDLL ( string [cfgName] );
    bool getLNSetChecksum ( string [cfgName] );
    bool getLNTurnOffAssemblyGeneration ( string [cfgName] );
    bool getLNSupportUnloadOfDelayLoadedDLL ( string [cfgName] );
    bool getLNProfile ( string [cfgName] );
    bool getLNLinkLibraryDependencies ( string [cfgName] );
    bool getLNDelaySign ( string [cfgName] );
    bool getLNUseUnicodeResponseFiles ( string [cfgName] );
    bool getLNGenerateManifest ( string [cfgName] );
    bool getLNAllowIsolation ( string [cfgName] );
    bool getLNUseLibraryDependencyInputs ( string [cfgName] );
    bool getLNCLRUnmanagedCodeCheck ( string [cfgName] );
    int getLNShowProgress ( string [cfgName] );
    int getLNLinkIncremental ( string [cfgName] );
    int getLNTypeLibraryResourceID ( string [cfgName] );
    int getLNSubSystem ( string [cfgName] );
    int getLNHeapReserveSize ( string [cfgName] );
    int getLNHeapCommitSize ( string [cfgName] );
    int getLNStackReserveSize ( string [cfgName] );
    int getLNStackCommitSize ( string [cfgName] );
    int getLNLargeAddressAware ( string [cfgName] );
    int getLNTerminalServerAware ( string [cfgName] );
    int getLNDriver ( string [cfgName] );
    int getLNOptimizeReferences ( string [cfgName] );
    int getLNEnableCOMDATFolding ( string [cfgName] );
    int getLNOptimizeForWindows98 ( string [cfgName] );
    int getLNLinkTimeCodeGeneration ( string [cfgName] );
    int getLNTargetMachine ( string [cfgName] );
    int getLNCLRThreadAttribute ( string [cfgName] );
    int getLNCLRImageType ( string [cfgName] );
    int getLNFixedBaseAddress ( string [cfgName] );
    int getLNAssemblyDebug ( string [cfgName] );
    int getLNExecutionBucket ( string [cfgName] );
    int getLNErrorReporting ( string [cfgName] );
    string getLNAdditionalOptions ( string [cfgName] );
    string getLNOutputFile ( string [cfgName] );
    string getLNVersion ( string [cfgName] );
    string getLNAdditionalLibraryDirectories ( string [cfgName] );
    string getLNAdditionalDependencies ( string [cfgName] );
    string getLNIgnoreDefaultLibraryNames ( string [cfgName] );
    string getLNModuleDefinitionFile ( string [cfgName] );
    string getLNAddModuleNamesToAssembly ( string [cfgName] );
    string getLNEmbedManagedResourceFile ( string [cfgName] );
    string getLNForceSymbolReferences ( string [cfgName] );
    string getLNDelayLoadDLLs ( string [cfgName] );
    string getLNMidlCommandFile ( string [cfgName] );
    string getLNMergedIDLBaseFileName ( string [cfgName] );
    string getLNTypeLibraryFile ( string [cfgName] );
    string getLNProgramDatabaseFile ( string [cfgName] );
    string getLNStripPrivateSymbols ( string [cfgName] );
    string getLNMapFileName ( string [cfgName] );
    string getLNFunctionOrder ( string [cfgName] );
    string getLNEntryPointSymbol ( string [cfgName] );
    string getLNBaseAddress ( string [cfgName] );
    string getLNImportLibrary ( string [cfgName] );
    string getLNMergeSections ( string [cfgName] );
    string getLNToolPath ( string [cfgName] );
    string getLNToolKind ( string [cfgName] );
    string getLNAssemblyLinkResource ( string [cfgName] );
    string getLNKeyFile ( string [cfgName] );
    string getLNKeyContainer ( string [cfgName] );
    string getLNProfileGuidedDatabase ( string [cfgName] );
    string getLNManifestFile ( string [cfgName] );
    string getLNAdditionalManifestDependencies ( string [cfgName] );
    string getWGMakefileGeneratorScriptName ( string [cfgName] );
    string getWGMakefileGeneratorScriptArgs ( string [cfgName] );
    string getWGMakefileName ( string [cfgName] );
    string getWGMakefileCompilerC ( string [cfgName] );
    string getWGMakefileCompilerCXX ( string [cfgName] );
    string getWGMakefileAR ( string [cfgName] );
    string getWGMakefileRM ( string [cfgName] );
    string getWGMakefileMKDIR ( string [cfgName] );
    string getWGMakefileCFLAGS ( string [cfgName] );
    string getWGMakefileCXXFLAGS ( string [cfgName] );
    string getWGMakefileLDFLAGS ( string [cfgName] );
    string getWGMakefileIntDir ( string [cfgName] );
    string getWGMakefileDestDir ( string [cfgName] );
    bool getWGMakefileAskBeforeOverwrite ( string [cfgName] );

VSProjectItem

    bool getIsDirty();
    bool getSaved();
    string getFileNames ( int index );
    bool getIsOpen ( string vsViewKind );
    int getFileCount();
    string getName();
    string getKind();
    VSProjectItems getCollection();
    VSProperties getProperties();
    VSProjectItems getProjectItems();
    VSConfigurationManager getConfigurationManager();
    int getIntProperty ( string cfgName, string propName );
    bool getBoolProperty ( string cfgName, string propName );
    string getStringProperty ( string cfgName, string propName );
    string getGenItemName ( string [cfgName] );
    string getGenItemKindName ( string [cfgName] );
    string getGenName ( string [cfgName] );
    string getGenRelativePath ( string [cfgName] );
    string getGenExtension ( string [cfgName] );
    string getGenFullPath ( string [cfgName] );
    string getGenSubType ( string [cfgName] );
    string getGenUnexpandedRelativePath ( string [cfgName] );
    string getCBCommandLine ( string [cfgName] );
    string getCBDescription ( string [cfgName] );
    string getCBOutputs ( string [cfgName] );
    string getCBDependencies ( string [cfgName] );
    string getCBToolPath ( string [cfgName] );
    string getCBToolKind ( string [cfgName] );
    bool getGenDeploymentContent ( string [cfgName] );
    bool getGenExcludedFromBuild ( string [cfgName] );
    int getGenFileType ( string [cfgName] );
    string getCLAdditionalOptions ( string [cfgName] );
    string getCLAdditionalIncludeDirectories ( string [cfgName] );
    string getCLAdditionalUsingDirectories ( string [cfgName] );
    string getCLPreprocessorDefinitions ( string [cfgName] );
    string getCLPrecompiledHeaderThrough ( string [cfgName] );
    string getCLPrecompiledHeaderFile ( string [cfgName] );
    string getCLAssemblerListingLocation ( string [cfgName] );
    string getCLObjectFile ( string [cfgName] );
    string getCLProgramDataBaseFileName ( string [cfgName] );
    string getCLBrowseInformationFile ( string [cfgName] );
    string getCLDisableSpecificWarnings ( string [cfgName] );
    string getCLForcedIncludeFiles ( string [cfgName] );
    string getCLForcedUsingFiles ( string [cfgName] );
    string getCLUndefinePreprocessorDefinitions ( string [cfgName] );
    string getCLToolPath ( string [cfgName] );
    string getCLFullIncludePath ( string [cfgName] );
    string getCLToolKind ( string [cfgName] );
    string getCLXMLDocumentationFileName ( string [cfgName] );
    int getCLWarningLevel ( string [cfgName] );
    int getCLDebugInformationFormat ( string [cfgName] );
    int getCLCompileAsManaged ( string [cfgName] );
    int getCLOptimization ( string [cfgName] );
    int getCLInlineFunctionExpansion ( string [cfgName] );
    int getCLFavorSizeOrSpeed ( string [cfgName] );
    int getCLGeneratePreprocessedFile ( string [cfgName] );
    int getCLExceptionHandling ( string [cfgName] );
    int getCLBasicRuntimeChecks ( string [cfgName] );
    int getCLRuntimeLibrary ( string [cfgName] );
    int getCLStructMemberAlignment ( string [cfgName] );
    int getCLFloatingPointModel ( string [cfgName] );
    int getCLUsePrecompiledHeader ( string [cfgName] );
    int getCLAssemblerOutput ( string [cfgName] );
    int getCLBrowseInformation ( string [cfgName] );
    int getCLCallingConvention ( string [cfgName] );
    int getCLCompileAs ( string [cfgName] );
    int getCLEnableEnhancedInstructionSet ( string [cfgName] );
    int getCLErrorReporting ( string [cfgName] );
    bool getCLWarnAsError ( string [cfgName] );
    bool getCLSuppressStartupBanner ( string [cfgName] );
    bool getCLDetect64BitPortabilityProblems ( string [cfgName] );
    bool getCLEnableIntrinsicFunctions ( string [cfgName] );
    bool getCLOmitFramePointers ( string [cfgName] );
    bool getCLEnableFiberSafeOptimizations ( string [cfgName] );
    bool getCLWholeProgramOptimization ( string [cfgName] );
    bool getCLIgnoreStandardIncludePath ( string [cfgName] );
    bool getCLKeepComments ( string [cfgName] );
    bool getCLStringPooling ( string [cfgName] );
    bool getCLMinimalRebuild ( string [cfgName] );
    bool getCLSmallerTypeCheck ( string [cfgName] );
    bool getCLBufferSecurityCheck ( string [cfgName] );
    bool getCLEnableFunctionLevelLinking ( string [cfgName] );
    bool getCLFloatingPointExceptions ( string [cfgName] );
    bool getCLDisableLanguageExtensions ( string [cfgName] );
    bool getCLDefaultCharIsUnsigned ( string [cfgName] );
    bool getCLTreatWCharAsBuiltInType ( string [cfgName] );
    bool getCLForceConformanceInForLoopScope ( string [cfgName] );
    bool getCLRuntimeTypeInfo ( string [cfgName] );
    bool getCLOpenMP ( string [cfgName] );
    bool getCLExpandAttributedSource ( string [cfgName] );
    bool getCLShowIncludes ( string [cfgName] );
    bool getCLUndefineAllPreprocessorDefinitions ( string [cfgName] );
    bool getCLEnablePREfast ( string [cfgName] );
    bool getCLCompileOnly ( string [cfgName] );
    bool getCLUseUnicodeResponseFiles ( string [cfgName] );
    bool getCLGenerateXMLDocumentationFiles ( string [cfgName] );
    bool getCLUseFullPaths ( string [cfgName] );
    bool getCLOmitDefaultLibName ( string [cfgName] );

VSProjectItems

    unsigned int count();
    VSProjectItem item ( unsigned int index );
    string getKind();

VSProjects

    unsigned int count();
    VSProject item ( unsigned int index );
    VSProject itemByName ( string name );

VSProperties

    unsigned int count();
    VSProperty item ( unsigned int index );
    VSProperty itemByName ( string name );

VSProperty

    int getNumIndices();
    VSProperties getCollection();
    string getName();
    string getType();
    int getIntValue();
    bool getBoolValue();
    string getStringValue();

VSSolution

    VSProjects getProjects();

VSUtils

    void print ( string text );
    void println ( string text );
    VSSolution getSolution();
    VSProject getProject ( string projectName );
    VSProject getSelectedProject();
    VSProject getStartupProject();
    string evaluate ( string value, string project, string cfgName );
    string getPathDirectory ( string path );
    string getPathFileName ( string path );
    string getPathBaseName ( string path );
    string getPathExtension ( string path );
    string getRelativePath ( string basePath, string targetPath );
    void ensureDirectoryExists ( string path );
    void ensureDirectoryDoesNotExist ( string path );
    string makeTemporaryPath();
    string changeExtension ( string path, string newExtension );
    string getCurrentSolutionConfiguration();
    string getCurrentSolutionPlatform();
    string getCurrentProjectConfiguration ( string projectName );
    string getCurrentProjectPlatform ( string projectName );

Example script

This is a simple example of a generator script. It is much simplified generator of GNU makefiles. The script shows the following aspects of writing generators in Lua:

-- Makefile template

makefileTemplate = [[
CC= @{CC}
CXX= @{CXX}
AR= @{AR}
CFLAGS= @{CFLAGS}
CXXFLAGS= @{CXXFLAGS}
ARFLAGS= @{ARFLAGS}
LDFLAGS= @{LDFLAGS}
RESULT= @{RESULT}
INTERMEDIATE_DIR= @{INTERMEDIATE_DIR}
DESTINATION_DIR= @{DESTINATION_DIR}
RM= @{RM}
MKDIR= @{MKDIR}
INTERMEDIATE_DIR_MK= @{INTERMEDIATE_DIR_MK}
DESTINATION_DIR_MK= @{DESTINATION_DIR_MK}

SOURCES= \
@{SOURCES}

SOURCEPATHS= \
@{SOURCEPATHS}

HEADERS= \
@{HEADERS}

VPATH= @{VPATH}

OBJECTNAMES=$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES)))
OBJECTPATHS=$(addprefix $(INTERMEDIATE_DIR)/,$(OBJECTNAMES))

$(DESTINATION_DIR)/$(RESULT): $(OBJECTNAMES)
ifeq ("$(wildcard $(DESTINATION_DIR) )","")
	-$(MKDIR) $(DESTINATION_DIR_MK)
endif
	$(CXX) $(SYSROOTFLAGS) $(OBJECTPATHS) -o $@ $(LDFLAGS)

$(INTERMEDIATE_DIR)/@{DEPFILENAME}: $(SOURCES) $(HEADERS)
ifeq ("$(wildcard $(DESTINATION_DIR) )","")
	-$(MKDIR) $(DESTINATION_DIR_MK)
endif
ifeq ("$(wildcard $(INTERMEDIATE_DIR) )","")
	-$(MKDIR) $(INTERMEDIATE_DIR_MK)
endif
	$(CXX) $(CXXFLAGS) -MM $(SOURCEPATHS) > $@

-include $(INTERMEDIATE_DIR)/@{DEPFILENAME}

clean:
	$(RM) $(DESTINATION_DIR)/$(RESULT)
	$(RM) $(INTERMEDIATE_DIR)/@{DEPFILENAME}
	$(RM) $(OBJECTPATHS)

%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c -o $(INTERMEDIATE_DIR)/$@ $<

%.o: %.c
	$(CC) $(CFLAGS) -c -o $(INTERMEDIATE_DIR)/$@ $<
]]

-- Generator code

hSolution = vs:getSolution()
hProject = vs:getSelectedProject()
projectFilePath = hProject:getFullName()
projectName = hProject:getName()
projectDir = vs:getPathDirectory ( projectFilePath )
makefileName = hProject:getWGMakefileName()
destPath = projectDir .. "/" .. makefileName

projHeaders = hProject:getProjectSources ( "*.h" )
projSources = hProject:getProjectSources ( "*.c;*.cpp" )

projSourceRelPaths = {}
projSourceNames = {}
projHeaderRelPaths = {}
vpathEntries = {}

for idx, sourcePath in ipairs ( projSources ) do
    fileName = vs:getPathFileName ( sourcePath )
    fileRelPath = vs:getRelativePath ( projectDir, sourcePath )
    table.insert ( projSourceNames, fileName )
    table.insert ( projSourceRelPaths, fileRelPath )
end

for idx, headerPath in ipairs ( projHeaders ) do
    fileRelPath = vs:getRelativePath ( projectDir, headerPath )
    table.insert ( projHeaderRelPaths, fileRelPath )
end

table.insert ( vpathEntries, "$(INTERMEDIATE_DIR)" )

sourceList = table.concat ( projSourceNames, " \\\n" )
sourcePathList = table.concat ( projSourceRelPaths, " \\\n" )
headerPathList = table.concat ( projHeaderRelPaths, " \\\n" )
vpathEntryList = table.concat ( vpathEntries, ":" )

variables = {
    CC = hProject:getWGMakefileCompilerC(),
    CXX = hProject:getWGMakefileCompilerCXX(),
    AR = hProject:getWGMakefileAR(),
    CFLAGS = hProject:getWGMakefileCFLAGS(),
    CXXFLAGS = hProject:getWGMakefileCXXFLAGS(),
    ARFLAGS = "cru",
    LDFLAGS = hProject:getWGMakefileLDFLAGS(),
    RESULT = projectName,
    INTERMEDIATE_DIR = hProject:getWGMakefileIntDir(),
    DESTINATION_DIR = hProject:getWGMakefileDestDir(),
    RM = hProject:getWGMakefileRM(),
    MKDIR = hProject:getWGMakefileMKDIR(),
    INTERMEDIATE_DIR_MK = hProject:getWGMakefileIntDir(),
    DESTINATION_DIR_MK = hProject:getWGMakefileDestDir(),
    SOURCES = sourceList,
    SOURCEPATHS = sourcePathList,
    HEADERS = headerPathList,
    VPATH = vpathEntryList,
    DEPFILENAME = projectName .. ".d"
}

-- Substitute pattens in the template.
makefileResult = string.gsub ( makefileTemplate, "@{([A-Z_]+)}", variables )

-- Save resulting file.
hOutputFile = io.output ( destPath )
hOutputFile:write ( makefileResult )
hOutputFile:close()

vs:println ( "Makefile has been generated to:" )
vs:println ( destPath )

Table of Contents


Copyright (C) 2008-2016 SOFT-ERG. All rights reserved.