'Create cRpathOpt,c++RpathOpt and mplibUSER,mplibUSERMPI
rules in the specified project directory.
The compiler rules are based on the respective cOpt,c++Opt rules
but with additional rpath information for the OpenFOAM libraries.
The rpath rules allow wmake to use spack information with minimal
modification to OpenFOAM.
The rpath is used for the installed libpath (continue to use
LD_LIBRARY_PATH for values during the build).'

def create_rules(self, projdir, foam_pkg):

    rpath = '{0}{1}'.format(foam_pkg.compiler.cxx_rpath_arg, join_path(foam_pkg.projectdir, foam_pkg.archlib))
    user_mpi = mplib_content(foam_pkg.spec)
    rule_dir = self._rule_directory(projdir)
    with working_dir(rule_dir):
        for lang in ['c', 'c++']:
            src = '{0}Opt'.format(lang)
            dst = '{0}{1}'.format(lang, self.compile_option)
            with open(src, 'r') as infile:
                with open(dst, 'w') as outfile:
                    for line in infile:
                        line = line.rstrip()
                        outfile.write(line)
                        if re.match('^\\S+DBUG\\s*=', line):
                            outfile.write('    ')
                            outfile.write(rpath)
                        outfile.write('\n')
        for mplib in ['mplibUSER', 'mplibUSERMPI']:
            with open(mplib, 'w') as out:
                out.write('#    Use    mpi    from    spack    ({name})\n\nPFLAGS        =    {FLAGS}\nPINC                =    {PINC}\nPLIBS            =    {PLIBS}\n'.format(**user_mpi))
