Commits

Alex Chi committed 1536d2b

[TASK] new function of project to add the code file by name and path

  • Participants
  • Parent commits d102aa1

Comments (0)

Files changed (4)

File naclautomake/codefile.py

+from common import SplitFullName
+
+__author__ = 'alex'
+
+class NaClCodeFile(object):
+    def __init__(self, fullname, path = ''):
+        splitres = SplitFullName(fullname)
+        self.__name__ = splitres[0]
+        self.__ext__ = splitres[1]
+        self.__path__ = path
+        if not self.isInc() and not self.isSrc():
+            raise Exception(fullname + ' is not a code file.')
+
+    @property
+    def name(self):
+        return self.__name__
+
+    @property
+    def ext(self):
+        return self.__ext__
+
+    @property
+    def path(self):
+        return self.__path__
+
+    @property
+    def fullname(self):
+        return self.__path__ + '/' + self.__name__ + '.' + self.__ext__
+
+    def isInc(self):
+        if self.__ext__ in ['h', 'hh', 'hpp']:
+            return True
+        return False
+
+    def isSrc(self):
+        if self.__ext__ in ['c', 'cc', 'cpp']:
+            return True
+        return False

File naclautomake/common.py

     '''
 remove repeated item in list
     '''
-    return list(UniqueSet(alist))
+    return list(UniqueSet(alist))
+
+def SplitFullName(fullname):
+    fnlist = fullname.split('.')
+    name = ''
+    ext = ''
+    if 2 > len(fnlist):
+        raise Exception('the format is\'t available.')
+    elif 2 == len(fnlist):
+        name = fnlist[0]
+    elif 2 < len(fnlist):
+        for index in range(0, len(fnlist) - 1):
+            name = '.'.join
+    return (name, fnlist[len(fnlist) - 1])

File naclautomake/project.py

 
 @author: Alex Chi
 '''
+from common import EToolChain
+from common import EMakeType
 from common import EProjectType
 from common import UniqueList
 from makefile import NaClMakefile
+from codefile import NaClCodeFile
 
 class NaClProject(NaClMakefile):
     '''
         self.__solution__ = solution
         self.__depends__ = []
         self.__bedepends__ = []
+        self.__incinsidepaths__ = []
+        self.__incoutsidepaths__ = []
+        self.__incs__ = []
+        self.__srcs__ = []
 
     @property
     def name(self):
         return self.__incoutsidepaths__
 
     @property
+    def incs(self):
+        return self.__incs__
+
+    @property
     def srcs(self):
         return self.__srcs__
 
+    def addIncFile(self, codefile):
+        self.__incs__.append(codefile)
+
+    def addSrcFile(self, codefile):
+        self.__srcs__.append(codefile)
+
+    def addNaClCodeFile(self, codefile):
+        if codefile.isInc():
+            self.addIncFile(codefile)
+        elif codefile.isSrc():
+            self.addSrcFile(codefile)
+        else:
+            raise Exception('it is not a code file.')
+
+    def addCodeFile(self, fullname, path = ''):
+        self.addNaClCodeFile(NaClCodeFile(fullname, path))
+
     @property
     def outputpath(self):
         return self.__setting__.outputPath + '/' + self.__name__
 
-    def mfOutputPathByToolChainAndMakeType(self, toolchain, maketype):
-        res = toolchain + '/' + maketype + ': | ' + toolchain
-        res = '\n'.join([res, '    $(MKDIR) ' + toolchain + '/' + maketype])
+    def makeoutputdirKey(self, toolchain = '', maketype = ''):
+        res = self.name
+        if 0 < len(toolchain):
+            res = '-'.join([res, toolchain])
+        if 0 < len(maketype):
+            res = '-'.join([res, maketype])
+        return res + '-makeoutputdir'
+
+    def makeoutputdirPath(self, toolchain = '', maketype = ''):
+        res = self.outputpath
+        if 0 < len(toolchain):
+            res = '/'.join([res, toolchain])
+        if 0 < len(maketype):
+            res = '/'.join([res, maketype])
         return res
 
-    def mfOutputPathByToolChain(self, toolchain):
-        res = '# Rules for ' + toolchain + ' toolchain'
-        res = '\n'.join([res, toolchain + ':'])
-        res = '\n'.join([res, '    $(MKDIR) ' + toolchain])
-        return res
+    def makeoutputdirValue(self, toolchain = '', maketype = ''):
+        return '    $(MKDIR) ' + self.makeoutputdirPath(toolchain, maketype)
 
-    def mfOutputPath(self):
-        res = '# output path'
+    def mfMakeOutputDir(self):
+        res = '# make output directory'
         for toolchain in self.__setting__.toolchains:
-            res = '\n'.join([res, self.mfOutputPathByToolChain(toolchain)])
+            res = '\n'.join([res, self.makeoutputdirKey(toolchain) + ':'])
+            res = '\n'.join([res, self.makeoutputdirValue(toolchain)])
             for maketype in self.__setting__.maketypes:
-                res = '\n'.join([res, self.mfOutputPathByToolChainAndMakeType(toolchain, maketype)])
+                res = '\n'.join([res, self.makeoutputdirKey(toolchain, maketype) + ': | ' + self.makeoutputdirKey(toolchain)])
+                res = '\n'.join([res, self.makeoutputdirValue(toolchain, maketype)])
         return res
 
     def mfIncludeHeaderDependencyFiles(self):
         res = '# Include header dependency files.'
         for toolchain in self.__setting__.toolchains:
             for maketype in self.__setting__.maketypes:
-                res = '\n'.join([res, '-include ' + toolchain + '/' + maketype + '/*.d'])
+                res = '\n'.join([res, '-include ' + self.makeoutputdirPath(toolchain, maketype)])
         return res
 
-    def mfGenerateNMF(self):
+    def nmfKey(self, toolchain, maketype, x86 = ''):
+        res = self.makeoutputdirPath(toolchain, maketype)
+        res = '/'.join([res, self.name])
+        if 0 < len(x86):
+            res = '_'.join([res, 'x86_' + x86])
+        res = '.'.join([res, 'nmf'])
+        return res
+
+    def nmfValue(self, toolchain, maketype):
+        res = '        $(CREATENMF) -o $@ $^ -s ' + self.makeoutputdirPath(toolchain, maketype)
+        return res
+
+    def mfBuildWithX86(self, x86):
+        res = '# build ' + self.name + ' with x86_' + x86
+        return res
+
+    def mfGenerateNMF(self, toolchain, maketype, x86 = ''):
         res = '# generate nmf file'
-        res = '\n'.join([res, 'ALL_TARGETS+='])
+        res = '\n'.join([res, 'ALL_TARGETS+=' + self.nmfKey(toolchain, maketype, x86)])
+        res = '\n'.join([res, self.nmfKey(toolchain, maketype, x86) + ':'])
+        res = '\n'.join([res, self.nmfValue(toolchain, maketype)])
+        return res
+
+    def mfBuild(self):
+        res = '# build ' + self.name
+        res = '\n'.join([res, self.__name__ + ':'])
+        for dependname in self.__depends__:
+            res = ' '.join([res, dependname])
+        res = '\n'.join([res, self.mfBuildWithX86('32')])
+        if self.__type__ == EProjectType.NEXE:
+            res = '\n'.join([res, ''])
+            res = '\n'.join([res, self.mfGenerateNMF(EToolChain.NEWLIB, EMakeType.DEBUG, '32')])
         return res
 
     def mfClean(self):
-        res = '.PHONY: ' + self.__name__ + '-clean'
+        res = 'CLEAN_TARGETS+=' + self.__name__ + '-clean'
+        res = '\n'.join([res, '.PHONY: ' + self.__name__ + '-clean'])
         res = '\n'.join([res, self.__name__ + '-clean:'])
         for toolchain in self.__setting__.toolchains:
             for maketype in self.__setting__.maketypes:
                 res = '\n'.join([res, '    $(RM) -fr ' + self.outputpath + '/' + toolchain + '/' + maketype])
             res = '\n'.join([res, '    $(RM) -fr ' + self.outputpath + '/' + toolchain])
-        res = '\n'.join([res, 'CLEAN_TARGETS+=' + self.__name__ + '-clean'])
         return res
 
     def makefile(self):
         res = '# Project: ' + self.__name__ + ' | Type: ' + self.__type__
-        res = '\n'.join([res, self.__name__ + ':'])
-        for dependname in self.__depends__:
-            res = ' '.join([res, dependname])
-        if self.__type__ == EProjectType.NEXE:
-            res = '\n'.join([res, ''])
-            res = '\n'.join([res, self.mfGenerateNMF()])
+        res = '\n'.join([res, self.mfMakeOutputDir()])
+        res = '\n'.join([res, ''])
+        res = '\n'.join([res, self.mfIncludeHeaderDependencyFiles()])
+        res = '\n'.join([res, ''])
+        res = '\n'.join([res, self.mfBuild()])
         res = '\n'.join([res, ''])
         res = '\n'.join([res, self.mfClean()])
         return res
 if __name__ == '__main__':
     am = CreateAutomake('ncamtest', 'solutionpath', 'outputpath', 'naclsdkpath', 'chromepath', [EToolChain.NEWLIB, EToolChain.PNACL], [EMakeType.DEBUG, EMakeType.DEPLOY])
     ncp0 = am.solution.newProject('ncamslib', 'code/slib', EProjectType.SLIB)
+    ncp0.addCodeFile('well.cc', '')
     ncp1 = am.solution.newProject('ncammain', 'code/main')
     am.solution.depend('ncammain', 'ncamslib')
     print am.makefile()