예제 #1
0
def _prepare_dir(parser, modnames, auxdir):
    """Prepares the directory with the necessary dependencies to compile the auxiliary
    module.

    :arg parser: a fortpy.code.CodeParser for accessing the dependency modules.
    :arg modnames: a list of module names that need to be included in the directory.
    """
    #We need to see whether to include the pre-compiler directive or not.
    precompile = False
    for needed in modnames:
        if parser.modules[needed].precompile:
            precompile = True
            break

    modnames.append("fpy_auxiliary")

    from os import path
    from fortpy.interop.make import makefile
    lines = []
    makepath = path.join(auxdir, "Makefile")
    makefile("fpy_aux",
             modnames,
             makepath,
             "fpy_auxiliary.all",
             precompile,
             parser=parser,
             executable="so",
             makefpyaux=True)
예제 #2
0
    def make(self,
             remake=False,
             dependencies=None,
             compiler="gfortran",
             debug=False,
             profile=False):
        """Generates a makefile to compile the wrapper module and link it with the shared
        library that can be compiled with self.makelib().
        """
        self._check_lib(remake, compiler, debug, profile)

        from os import path
        if self.link is None or not path.isfile(self.link):
            msg.err(
                "Can't create shared library; missing compiled original code: {}"
                .format(self.link))
            exit(0)

        if remake or not path.isfile(self.libpath):
            if dependencies is None:
                dependencies = ["{}_c".format(self.module.name)]
                identifier = self.name
            else:
                identifier = "ftypes.{}".format(self.library)
                #We don't need to reorder these *wrapper* modules before compilation because each of
                #them should be independent of all the others.
                #dependencies = self._process_module_needs(dependencies)

            #append the dependency for the deallocation module to be included in the shared lib.
            dependencies.append("ftypes_dealloc")

            makename = "Makefile.{}".format(
                self.library if self.library else self.name)
            makepath = path.join(self.f90path, makename)
            extralinks = list(self.dependencies.values())
            extralinks.append(self.link)
            makefile(identifier, dependencies, makepath,
                     "ftypes.{}".format(self.name), False, False,
                     self.module.parent, "so", extralinks)
            code = self._compile(self.f90path, makename, compiler, debug,
                                 profile)
            if code == 0:
                #Copy the shared library to the main directory out of the f90 directory
                from shutil import copy
                copy(path.join(self.f90path, "{}.so".format(identifier)),
                     self.dirpath)
            return code
        else:
            return 0
예제 #3
0
    def makefile(self, identifier):
        """Generates a makefile to create the unit testing executable
        for the specified test identifier.

        :arg identifier: the id of the test that this executable should be made for.
        """
        allneeds = self.needs()
        #We need to see whether to include the pre-compiler directive or not.
        precompile = False
        for needed in allneeds:
            if self.parser.modules[needed].precompile:
                precompile = True
                break

        lines = []
        makepath = path.join(self.folder, "Makefile.{}".format(identifier))
        makefile(identifier, allneeds, makepath, self.identifier, precompile, parser=self.parser)
예제 #4
0
    def makelib(self,
                remake=False,
                full=True,
                compiler="gfortran",
                debug=False,
                profile=False):
        """Generates a makefile for the code files that reside in the same directory as the source
        that was parsed by the code parser.

        :arg full: when True, the shared library is compiled for *all* the code files in the directory
          not just the one's that are dependencies of the source module.
        """
        if self.link is None or remake:
            from os import path
            if self.library is not None:
                outpath = path.join(self.dirpath, "{}.a".format(self.library))
            else:
                outpath = path.join(self.dirpath, "{}.a".format(self.name))

            if not remake and path.isfile(outpath):  #No need to recompile
                self.link = outpath
                return

            dependencies = self._get_lib_modules(full)
            makepath = path.join(path.dirname(self.module.filepath),
                                 "Makefile.ftypes")
            if full:
                compileid = "ftypes.all_libs"
                identifier = self.library
            else:
                compileid = "ftypes.{}_c".format(self.module.name)
                identifier = self.module.name

            makefile(identifier, dependencies, makepath, compileid,
                     self.module.precompile, False, self.module.parent, "a")
            code = self._compile(path.dirname(self.module.filepath),
                                 "Makefile.ftypes", compiler, debug, profile)
            if code == 0:
                self.link = path.join(path.dirname(self.module.filepath),
                                      "{}.a".format(identifier))
                self._copy_so(outpath)
                self.link = outpath
        else:
            #Just make sure it is copied over into the directory where we want to compile the wrapper
            #module for ftypes.
            self._copy_so(self.dirpath)
예제 #5
0
    def makefile(self, identifier):
        """Generates a makefile to create the unit testing executable
        for the specified test identifier.

        :arg identifier: the id of the test that this executable should be made for.
        """
        allneeds = self.needs()

        #We need to see whether to include the pre-compiler directive or not.
        precompile = False
        for needed in allneeds:
            if needed=="fortpy" or needed=="fpy_auxiliary":
                continue
            if self.parser.modules[needed].precompile:
                precompile = True
                break

        lines = []
        makepath = path.join(self.folder, "Makefile.{}".format(identifier))
        makefile(identifier, allneeds, makepath, self.identifier, precompile,
                 parser=self.parser, inclfpyaux=self.writer.autoclass)
예제 #6
0
def _prepare_dir(parser, modnames, auxdir):
    """Prepares the directory with the necessary dependencies to compile the auxiliary
    module.

    :arg parser: a fortpy.code.CodeParser for accessing the dependency modules.
    :arg modnames: a list of module names that need to be included in the directory.
    """
    #We need to see whether to include the pre-compiler directive or not.
    precompile = False
    for needed in modnames:
        if parser.modules[needed].precompile:
            precompile = True
            break
        
    modnames.append("fpy_auxiliary")

    from os import path
    from fortpy.interop.make import makefile
    lines = []
    makepath = path.join(auxdir, "Makefile.fpy_aux")
    makefile("fpy_aux", modnames, makepath, "fpy_auxiliary.all", precompile,
             parser=parser, executable="so", makefpyaux=True)
예제 #7
0
파일: ftypes.py 프로젝트: feifzhou/fortpy
    def make(self, remake=False, dependencies=None,
             compiler="gfortran", debug=False, profile=False):
        """Generates a makefile to compile the wrapper module and link it with the shared
        library that can be compiled with self.makelib().
        """
        self._check_lib(remake, compiler, debug, profile)
        
        from os import path
        if self.link is None or not path.isfile(self.link):
            msg.err("Can't create shared library; missing compiled original code: {}".format(self.link))
            exit(0)
        
        if remake or not path.isfile(self.libpath):
            if dependencies is None:
                dependencies = ["{}_c".format(self.module.name)]
                identifier = self.name
            else:
                identifier = "ftypes.{}".format(self.library)
                #We don't need to reorder these *wrapper* modules before compilation because each of
                #them should be independent of all the others.
                #dependencies = self._process_module_needs(dependencies)

            #append the dependency for the deallocation module to be included in the shared lib.
            dependencies.append("ftypes_dealloc")
                
            makename = "Makefile.{}".format(self.library if self.library else self.name)
            makepath = path.join(self.f90path, makename)
            extralinks = list(self.dependencies.values())
            extralinks.append(self.link)
            makefile(identifier, dependencies, makepath, "ftypes.{}".format(self.name),
                     False, False, self.module.parent, "so", extralinks)
            code = self._compile(self.f90path, makename, compiler, debug, profile)
            if code == 0:
                #Copy the shared library to the main directory out of the f90 directory
                from shutil import copy
                copy(path.join(self.f90path, "{}.so".format(identifier)), self.dirpath)
            return code
        else:
            return 0
예제 #8
0
파일: ftypes.py 프로젝트: feifzhou/fortpy
    def makelib(self, remake=False, full=True, compiler="gfortran", debug=False, profile=False):
        """Generates a makefile for the code files that reside in the same directory as the source
        that was parsed by the code parser.

        :arg full: when True, the shared library is compiled for *all* the code files in the directory
          not just the one's that are dependencies of the source module.
        """
        if self.link is None or remake:
            from os import path
            if self.library is not None:
                outpath = path.join(self.dirpath, "{}.a".format(self.library))
            else:
                outpath = path.join(self.dirpath, "{}.a".format(self.name))

            if not remake and path.isfile(outpath): #No need to recompile
                self.link = outpath
                return
                
            dependencies = self._get_lib_modules(full)
            makepath = path.join(path.dirname(self.module.filepath), "Makefile.ftypes")
            if full:
                compileid = "ftypes.all_libs"
                identifier = self.library
            else:
                compileid = "ftypes.{}_c".format(self.module.name)
                identifier = self.module.name
                
            makefile(identifier, dependencies, makepath, compileid,
                     self.module.precompile, False, self.module.parent, "a")
            code = self._compile(path.dirname(self.module.filepath), "Makefile.ftypes",
                                 compiler, debug, profile)
            if code == 0:
                self.link = path.join(path.dirname(self.module.filepath), "{}.a".format(identifier))
                self._copy_so(outpath)
                self.link = outpath
        else:
            #Just make sure it is copied over into the directory where we want to compile the wrapper
            #module for ftypes.
            self._copy_so(self.dirpath)
예제 #9
0
    def makefile(self, identifier):
        """Generates a makefile to create the unit testing executable
        for the specified test identifier.

        :arg identifier: the id of the test that this executable should be made for.
        """
        allneeds = self.needs()

        #We need to see whether to include the pre-compiler directive or not.
        precompile = False
        for needed in allneeds:
            if needed=="fortpy" or needed=="fpy_auxiliary":
                continue
            if self.parser.modules[needed].precompile:
                precompile = True
                break

        lines = []
        #Determine whether the compilation should produce headers on the output screen.
        from fortpy.msg import will_print
        verbose = will_print(2)
        makepath = path.join(self.folder, "Makefile.{}".format(identifier))
        makefile(identifier, allneeds, makepath, self.identifier, precompile,
                 parser=self.parser, inclfpyaux=self.writer.autoclass, verbose=verbose)