This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 9829 for ps


Ignore:
Timestamp:
07/15/11 19:48:21 (13 years ago)
Author:
philip
Message:

Non-standard Premake4 patches from Yves (plus minor tweaks).
Add nasm support.
Add cxxtest support.
Some other fixes.

Location:
ps/trunk/build/premake/premake4/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/build/premake/premake4/src/actions/make/make_cpp.lua

    r9828 r9829  
    2727        _p('OBJECTS := \\')
    2828        for _, file in ipairs(prj.files) do
    29             if path.iscppfile(file) then
     29            if path.iscppfile(file) or path.getextension(file) == ".asm" then
    3030                _p('\t$(OBJDIR)/%s.o \\', _MAKE.esc(path.getbasename(file)))
    3131            end
     
    5656
    5757        if os.is("MacOSX") and prj.kind == "WindowedApp" then
    58             _p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist')
     58            _p('all: $(TARGET) $(dir $(TARGETDIR))PkgInfo $(dir $(TARGETDIR))Info.plist')
    5959        else
    60             _p('all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)')
     60            _p('all: $(TARGET)')
    6161        end
    6262        _p('\t@:')
     
    6464
    6565        -- target build rule
    66         _p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)')
     66        _p('$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES) | prelink')
    6767        _p('\t@echo Linking %s', prj.name)
    6868        _p('\t$(SILENT) $(LINKCMD)')
     
    9898
    9999        -- custom build step targets
    100         _p('prebuild:')
     100        _p('prebuild: $(TARGETDIR) $(OBJDIR)')
    101101        _p('\t$(PREBUILDCMDS)')
    102102        _p('')
     
    112112        for _, file in ipairs(prj.files) do
    113113            if path.iscppfile(file) then
    114                 _p('$(OBJDIR)/%s.o: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))
     114                _p('$(OBJDIR)/%s.o: %s | prebuild', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))
    115115                _p('\t@echo $(notdir $<)')
    116116                if (path.iscfile(file)) then
     
    123123                _p('\t@echo $(notdir $<)')
    124124                _p('\t$(SILENT) windres $< -O coff -o "$@" $(RESFLAGS)')
    125             end
    126         end
    127         _p('')
     125            elseif (path.getextension(file) == ".asm") then
     126                _p('$(OBJDIR)/%s.o: %s', _MAKE.esc(path.getbasename(file)), _MAKE.esc(file))
     127                _p('\t@echo $(notdir $<)')
     128
     129                local opts = ''
     130                if os.is('windows') then
     131                    opts = ''
     132                elseif os.is('macosx') then
     133                    opts = '-D OS_UNIX=1'
     134                else
     135                    opts = '-D DONT_USE_UNDERLINE=1 -D OS_UNIX=1'
     136                end
     137
     138                if not (prj.solution.nasmpath) then
     139                    prj.solution.nasmpath = 'nasm'             
     140                end
     141
     142                _p('\t$(SILENT)'.._MAKE.esc(prj.solution.nasmpath)..' '..opts..' -i'.._MAKE.esc(path.getdirectory(file))..'/'..' -f '..
     143                   _MAKE.esc(prj.solution.nasmformat)..' -o $@ $<\n\t')
     144
     145                _p('\t$(SILENT)'.._MAKE.esc(prj.solution.nasmpath)..' '..opts..' -i'.._MAKE.esc(path.getdirectory(file))..'/'..
     146                   ' -M -o $@ $< >$(OBJDIR)/$(<F:%%.asm=%%.d)\n')
     147            end
     148           
     149        end
     150        _p('')     
     151
     152        -- output for test-generation
     153        -- test generation only works if all required parameters are set!
     154        if(prj.solution.cxxtestpath and prj.cxxtestrootfile and prj.cxxtesthdrfiles and prj.cxxtestsrcfiles) then
     155           
     156            if not(prj.cxxtestrootoptions) then
     157                prj.cxxtestrootoptions = ''
     158            end
     159            if not(prj.cxxtestoptions) then
     160                prj.cxxtestoptions = ''
     161            end
     162
     163            _p(prj.cxxtestrootfile..': ')
     164            _p('\t@echo $(notdir $<)')
     165            _p('\t$(SILENT)'.._MAKE.esc(prj.solution.cxxtestpath)..' --root '..prj.cxxtestrootoptions..' -o '.._MAKE.esc(prj.cxxtestrootfile)) 
     166            _p('') 
     167   
     168            for i, file in ipairs(prj.cxxtesthdrfiles) do
     169                _p('%s: %s', _MAKE.esc(prj.cxxtestsrcfiles[i]), _MAKE.esc(file))
     170                _p('\t@echo $(notdir $<)')
     171                _p('\t$(SILENT)'.._MAKE.esc(prj.solution.cxxtestpath)..' --part '..prj.cxxtestoptions..' -o ' .._MAKE.esc(prj.cxxtestsrcfiles[i])..' '.._MAKE.esc(file))
     172            end
     173            _p('')
     174        end
    128175       
    129176        -- include the dependencies, built by GCC (with the -MMD flag)
     
    175222
    176223        _p('ifeq ($(config),%s)', _MAKE.esc(cfg.shortname))
     224
    177225       
    178226        -- if this platform requires a special compiler or linker, list it now
     
    187235            _p('  AR         = %s', platform.ar)
    188236        end
     237        if not(cfg.gnuexternals) then
     238            cfg.gnuexternal = { }       
     239        end
    189240
    190241        _p('  OBJDIR     = %s', _MAKE.esc(cfg.objectsdir))     
     
    201252        _p('  CXXFLAGS  += $(CFLAGS) %s', table.concat(cc.getcxxflags(cfg), " "))
    202253        _p('  LDFLAGS   += %s', table.concat(table.join(cc.getldflags(cfg), cfg.linkoptions, cc.getlibdirflags(cfg)), " "))
    203         _p('  LIBS      += %s', table.concat(cc.getlinkflags(cfg), " "))
     254        _p('  LIBS      += %s %s', table.concat(cc.getlinkflags(cfg), " "), table.concat(cfg.gnuexternals, " "))
    204255        _p('  RESFLAGS  += $(DEFINES) $(INCLUDES) %s', table.concat(table.join(cc.getdefines(cfg.resdefines), cc.getincludedirs(cfg.resincludedirs), cfg.resoptions), " "))
    205256        _p('  LDDEPS    += %s', table.concat(_MAKE.esc(premake.getlinks(cfg, "siblings", "fullpath")), " "))
     
    214265            -- this was $(TARGET) $(LDFLAGS) $(OBJECTS) ... but was having trouble linking to certain
    215266            -- static libraries so $(OBJECTS) was moved up
    216             _p('  LINKCMD    = $(%s) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(ARCH) $(LIBS)', iif(cfg.language == "C", "CC", "CXX"))
     267            local lddeps = ''
     268
     269            -- on osx, --start-group and --end-group aren't supported by ld
     270            if os.is('macosx') then
     271                lddeps = '$(LDDEPS)'
     272            else
     273                lddeps = '-Xlinker --start-group $(LDDEPS) -Xlinker --end-group'
     274            end
     275            _p('  LINKCMD    = $(%s) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(ARCH) %s $(LIBS)',
     276            iif(cfg.language == "C", "CC", "CXX"), lddeps)
    217277        end
    218278       
     
    257317    function _.pchrules(prj)
    258318        _p('ifneq (,$(PCH))')
    259         _p('$(GCH): $(PCH)')
     319        _p('$(GCH): $(PCH) | $(OBJDIR)')
    260320        _p('\t@echo $(notdir $<)')
    261321        _p('\t-$(SILENT) cp $< $(OBJDIR)')
  • ps/trunk/build/premake/premake4/src/actions/vstudio/_vstudio.lua

    r9828 r9829  
    228228                end
    229229            end
     230
     231            if (path.getextension(fname) == ".asm") then
     232                for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
     233                    if cfginfo.isreal then
     234
     235                        -- set defaults if required parameters are not set
     236                        if not (prj.solution.nasmformat) then
     237                            prj.solution.nasmformat = 'win32'
     238                        end
     239                        if not (prj.solution.nasmpath) then
     240                            prj.solution.nasmpath = 'nasm'             
     241                        end
     242
     243                        local nasmpath = path.translate(path.getrelative(prj.location, prj.solution.nasmpath), "\\")
     244                        local command = nasmpath.." -i "..path.translate(path.getdirectory(fname), "\\").."\\ -f "..prj.solution.nasmformat..
     245                            " &quot;$(InputPath)&quot; -o &quot;$(IntDir)\$(InputName).obj&quot;"
     246
     247                        output(indent, "\t<FileConfiguration")
     248                        attrib(indent, "\tName", cfginfo.name)
     249                        output(indent, "\t\t>")
     250                        output(indent, "\t\t<Tool")
     251                        attrib(indent, "\t\tName", "VCCustomBuildTool")
     252                        attrib(indent, "\t\tDescription", "Assembling $(InputPath)")
     253                        attrib(indent, "\t\tCommandLine", command)
     254                        attrib(indent, "\t\tOutputs", "$(IntDir)\$(InputName).obj")
     255                        output(indent, "\t\t/>")
     256                        output(indent, "\t</FileConfiguration>")
     257                    end
     258                end
     259            end
     260
    230261            output(indent, "</File>")
    231262        end
  • ps/trunk/build/premake/premake4/src/actions/vstudio/vs2010_vcxproxj.lua

    r9828 r9829  
    55       
    66    function vs10_helpers.remove_relative_path(file)
    7         file = file:gsub("%.%.\\",'')
    8         file = file:gsub("%.\\",'')
     7        file = file:gsub("%.%./",'')
     8        file = file:gsub("%./",'')
     9        file = file:gsub("^source/",'')
    910        return file
    1011    end
     
    1213    function vs10_helpers.file_path(file)
    1314        file = vs10_helpers.remove_relative_path(file)
    14         local path = string.find(file,'\\[%w%.%_%-]+$')
     15        local path = string.find(file,'/[%w%.%_%-]+$')
    1516        if path then
    1617            return string.sub(file,1,path-1)
     
    2425        path = vs10_helpers.remove_relative_path(path)
    2526        if path then
    26             for dir in string.gmatch(path,"[%w%-%_%.]+\\")do
     27            for dir in string.gmatch(path,"[%w%-%_%.]+/")do
    2728                if #list == 0 then
    2829                    list[1] = dir:sub(1,#dir-1)
    2930                else
    30                     list[#list +1] = list[#list] .."\\" ..dir:sub(1,#dir-1)             
     31                    list[#list +1] = list[#list] .."/" ..dir:sub(1,#dir-1)             
    3132                end
    3233            end     
     
    6061   
    6162
    62    
    63     --also translates file paths from '/' to '\\'
    6463    function vs10_helpers.sort_input_files(files,sorted_container)
    6564        local types =
     
    7271            cxx = "ClCompile",
    7372            cc  = "ClCompile",
    74             rc  = "ResourceCompile"
     73            rc      = "ResourceCompile",
     74            asm     = "ClASM"
    7575        }
    7676
    7777        for _, current_file in ipairs(files) do
    78             local translated_path = path.translate(current_file, '\\')
    79             local ext = vs10_helpers.get_file_extension(translated_path)
     78            local ext = vs10_helpers.get_file_extension(current_file)
    8079            if ext then
    8180                local type = types[ext]
    8281                if type then
    83                     table.insert(sorted_container[type],translated_path)
     82                    table.insert(sorted_container[type],current_file)
    8483                else
    85                     table.insert(sorted_container.None,translated_path)
     84                    table.insert(sorted_container.None,current_file)
    8685                end
    8786            end
     
    389388
    390389
    391     local function event_hooks(cfg)
     390    local function event_hooks(cfg, prj)   
    392391        if #cfg.postbuildcommands> 0 then
    393392            _p(2,'<PostBuildEvent>')
     
    396395        end
    397396       
    398         if #cfg.prebuildcommands> 0 then
     397        if #cfg.prebuildcommands> 0 or prj.cxxtestrootfile then
    399398            _p(2,'<PreBuildEvent>')
    400399                _p(3,'<Command>%s</Command>',premake.esc(table.implode(cfg.prebuildcommands, "", "", "\r\n")))
     400               
     401                -- test generation only works if all required parameters are set!
     402                if(prj.solution.cxxtestpath and prj.cxxtestrootfile and prj.cxxtesthdrfiles and prj.cxxtestsrcfiles) then
     403                    local cxxtestpath = path.translate(path.getrelative(prj.location, prj.solution.cxxtestpath),"\\")
     404                    local cxxtestrootfile = path.translate(prj.cxxtestrootfile,"\\")
     405                    _p(3,'<Command>%s --root %s &gt; %s</Command>', cxxtestpath, prj.cxxtestrootoptions, cxxtestrootfile)
     406                end
    401407            _p(2,'</PreBuildEvent>')
    402408        end
     
    504510                item_def_lib(cfg)
    505511                item_link(cfg)
    506                 event_hooks(cfg)
     512                event_hooks(cfg, prj)
    507513            _p(1,'</ItemDefinitionGroup>')
    508 
    509            
    510514        end
    511515    end
     
    519523  --     </ProjectReference>
    520524  --   </ItemGroup>
    521     --
     525
     526    local function write_cxxtestgen_block(prj)
     527        -- test generation only works if all required parameters are set!
     528        if(prj.solution.cxxtestpath and prj.cxxtestrootfile and prj.cxxtesthdrfiles and prj.cxxtestsrcfiles) then
     529            local cxxtestpath = path.translate(path.getrelative(prj.location, prj.solution.cxxtestpath),"\\")
     530            _p(1,'<ItemGroup>')
     531            for i, file in ipairs(prj.cxxtesthdrfiles) do
     532                local cxxtesthdrfile = path.translate(file,"\\")
     533                local cxxtestsrcfile = path.translate(prj.cxxtestsrcfiles[i],"\\")
     534                _p(2,'<CustomBuild Include=\"%s\">', cxxtesthdrfile)
     535                      _p(3,'<Message>Generating %s</Message>', path.getname(prj.cxxtestsrcfiles[i]))
     536                      _p(3,'<Command>%s --part %s -o \"%s\" \"%s\"</Command>',
     537                    cxxtestpath, prj.cxxtestoptions, cxxtestsrcfile, cxxtesthdrfile)
     538                      _p(3,'<Outputs>%s;%%(Outputs)</Outputs>', cxxtestsrcfile)
     539                _p(2,'</CustomBuild>')
     540            end
     541            _p(1,'</ItemGroup>')
     542        end
     543    end
    522544   
    523545    local function write_file_type_block(files,group_type)
     
    525547            _p(1,'<ItemGroup>')
    526548            for _, current_file in ipairs(files) do
    527                 _p(2,'<%s Include=\"%s\" />', group_type,current_file)
     549                _p(2,'<%s Include=\"%s\" />', group_type,path.translate(current_file,"\\"))
    528550            end
    529551            _p(1,'</ItemGroup>')
     
    532554   
    533555    local function write_file_compile_block(files,prj,configs)
    534    
    535556        if #files > 0  then
    536        
    537557            local config_mappings = {}
    538558            for _, cfginfo in ipairs(configs) do
    539559                local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
    540560                if cfg.pchheader and cfg.pchsource and not cfg.flags.NoPCH then
    541                     config_mappings[cfginfo] = path.translate(cfg.pchsource, "\\")
     561                    config_mappings[cfginfo] = cfg.pchsource
    542562                end
    543563            end
     
    546566            _p(1,'<ItemGroup>')
    547567            for _, current_file in ipairs(files) do
    548                 _p(2,'<ClCompile Include=\"%s\">', current_file)
     568                _p(2,'<ClCompile Include=\"%s\">', path.translate(current_file, "\\"))
    549569                for _, cfginfo in ipairs(configs) do
    550570                    if config_mappings[cfginfo] and current_file == config_mappings[cfginfo] then
     
    560580        end
    561581    end
     582
     583    local function write_nasm_asm_block(files, prj, configs)
     584        -- set defaults if required parameters are not set
     585        if not (prj.solution.nasmformat) then
     586            prj.solution.nasmformat = 'win32'
     587        end
     588
     589        if not (prj.solution.nasmpath) then
     590            prj.solution.nasmpath = 'nasm'             
     591        end
     592
     593        if #files > 0 then
     594            _p(1,'<ItemGroup>')
     595            local nasmpath = path.translate(path.getrelative(prj.location, prj.solution.nasmpath),"\\")
     596            for _, current_file in ipairs(files) do
     597                _p(2,'<CustomBuild Include=\"%s\">', path.translate(current_file,"\\"))
     598                    _p(3,'<Message>Assembling %%(FullPath)</Message>')
     599                    _p(3,'<Command>%s -i %s -f %s \"%%(FullPath)\" -o \"$(IntDir)%%(Filename).obj\"</Command>',
     600                    nasmpath,
     601                    path.translate(path.getdirectory(current_file),"\\").."\\",
     602                    prj.solution.nasmformat)
     603                    _p(3,'<Outputs>$(IntDir)%%(Filename).obj;%%(Outputs)</Outputs>')
     604                _p(2,'</CustomBuild>')
     605            end
     606            _p(1,'</ItemGroup>')
     607        end
     608    end
    562609   
    563610   
     
    567614            ClCompile   ={},
    568615            ClInclude   ={},
     616            ClASM   ={},
    569617            None        ={},
    570618            ResourceCompile ={}
     
    573621        cfg = premake.getconfig(prj)
    574622        vs10_helpers.sort_input_files(cfg.files,sorted)
     623        write_cxxtestgen_block(prj)
    575624        write_file_type_block(sorted.ClInclude,"ClInclude")
    576625        write_file_compile_block(sorted.ClCompile,prj,prj.solution.vstudio_configs)
     626        write_nasm_asm_block(sorted.ClASM, prj, prj.solution.vstudion_configs)
    577627        write_file_type_block(sorted.None,'None')
    578628        write_file_type_block(sorted.ResourceCompile,'ResourceCompile')
     
    588638            _p(1,'<ItemGroup>')
    589639            for _, dir in pairs(directories) do
    590                 _p(2,'<Filter Include="%s">',dir)
     640                _p(2,'<Filter Include="%s">',path.translate(dir,"\\"))
    591641                    _p(3,'<UniqueIdentifier>{%s}</UniqueIdentifier>',os.uuid())
    592642                _p(2,'</Filter>')
     
    603653                if path_to_file then
    604654                    _p(2,'<%s Include=\"%s\">', group_type,path.translate(current_file, "\\"))
    605                         _p(3,'<Filter>%s</Filter>',path_to_file)
     655                        _p(3,'<Filter>%s</Filter>',path.translate(path_to_file,"\\"))
    606656                    _p(2,'</%s>',group_type)
    607657                else
     
    621671            ClCompile   ={},
    622672            ClInclude   ={},
     673            ClASM   ={},
    623674            None        ={},
    624675            ResourceCompile ={}
     
    634685            write_file_filter_block(sorted.ClInclude,"ClInclude")
    635686            write_file_filter_block(sorted.ClCompile,"ClCompile")
     687            write_file_filter_block(prj.cxxtesthdrfiles,"CustomBuild")
     688            write_file_filter_block(sorted.ClASM,"ClASM")
    636689            write_file_filter_block(sorted.None,"None")
    637690            write_file_filter_block(sorted.ResourceCompile,"ResourceCompile")
  • ps/trunk/build/premake/premake4/src/actions/xcode/xcode_common.lua

    r9828 r9829  
    3333            [".xib"] = "Resources",
    3434            [".icns"] = "Resources",
     35            [".asm"] = "Sources"
    3536        }
    3637        return categories[path.getextension(node.name)]
     
    8687            [".xib"]       = "file.xib",
    8788            [".icns"]      = "image.icns",
     89            [".asm"]       = "sourcecode.asm",
    8890        }
    8991        return types[path.getextension(node.path)] or "text"
     
    261263        _p('/* End PBXBuildFile section */')
    262264        _p('')
     265    end
     266
     267
     268    function xcode.PBXBuildRule(tr)
     269        if not (tr.project.solution.nasmpath) then
     270            tr.project.solution.nasmpath = 'nasm'               
     271        end
     272        _p('/* Begin PBXBuildRule section */')
     273            _p(2,'28AD1E6E1336798800207177 /* PBXBuildRule */ = {')
     274                _p(3,'isa = PBXBuildRule;')
     275                _p(3,'compilerSpec = com.apple.compilers.proxy.script;')
     276                _p(3,'fileType = sourcecode.asm;')
     277                _p(3,'isEditable = 1;')
     278                _p(3,'outputFiles = (')
     279                    _p(4,'"$(DERIVED_FILES_DIR)/$(INPUT_FILE_BASE).o",')
     280                _p(3,');')
     281                _p(3,'script = "%s -D OS_UNIX=1 -i${INPUT_FILE_DIR}/ -f %s ${INPUT_FILE_PATH} -o ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}.o";', tr.project.solution.nasmpath, tr.project.solution.nasmformat)
     282            _p(2,'};')
     283        _p('/* End PBXBuildRule section */')
    263284    end
    264285
     
    433454            _p(3,');')
    434455            _p(3,'buildRules = (')
     456            _p(4,'28AD1E6E1336798800207177 /* PBXBuildRule */,')
    435457            _p(3,');')
    436458           
  • ps/trunk/build/premake/premake4/src/actions/xcode/xcode_project.lua

    r9828 r9829  
    148148        xcode.Header(tr)
    149149        xcode.PBXBuildFile(tr)
     150        xcode.PBXBuildRule(tr)
    150151        xcode.PBXContainerItemProxy(tr)
    151152        xcode.PBXFileReference(tr)
  • ps/trunk/build/premake/premake4/src/base/api.lua

    r9828 r9829  
    4141            kind  = "list",
    4242            scope = "solution",
     43        },
     44
     45        cxxtesthdrfiles =
     46        {
     47            kind = "filelist",
     48            scope = "config",       
     49        },
     50
     51        cxxtestsrcfiles =
     52        {
     53            kind  = "filelist",
     54            scope = "config",
     55        },
     56
     57        cxxtestoptions =
     58        {
     59            kind  = "string",
     60            scope = "config",
     61        },
     62
     63        cxxtestpath =
     64        {
     65            kind  = "path",
     66            scope = "solution",             
     67        },
     68
     69        cxxtestrootfile =
     70        {
     71            kind  = "path",
     72            scope = "config",
     73        },
     74
     75        cxxtestrootoptions =
     76        {
     77            kind  = "string",
     78            scope = "config",
    4379        },
    4480       
     
    117153            }
    118154        },
     155
     156        gnuexternals =
     157        {
     158            kind  = "list",
     159            scope = "config",
     160        },
    119161       
    120162        imagepath =
     
    219261            kind  = "path",
    220262            scope = "container",
     263        },
     264
     265        nasmformat =
     266        {
     267            kind  = "string",
     268            scope = "solution",
     269        },
     270
     271        nasmpath =
     272        {
     273            kind  = "path",
     274            scope = "solution"
    221275        },
    222276       
Note: See TracChangeset for help on using the changeset viewer.