10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-11-08 15:13:42 +01:00

Cleaned ninja

This commit is contained in:
Anthony Scemama 2015-06-01 14:21:41 +02:00
parent 59c1dc363a
commit 9a8335fee3

View File

@ -31,11 +31,14 @@ from command_line import command_line
from modules import modules from modules import modules
irpdir = irpf90_t.irpdir irpdir = irpf90_t.irpdir
mandir = irpf90_t.mandir mandir = irpf90_t.mandir
irp_id = irpf90_t.irp_id
FILENAME = os.path.join(irpdir,"build.ninja") FILENAME = os.path.join(irpdir,"build.ninja")
cwd = os.getcwd() cwd = os.getcwd()
PRINT_WIDTH=50
def dress(f,in_root=False): def dress(f,in_root=False):
""" """
Transfoms the filename f into $PWD/IRPF90_temp/f Transfoms the filename f into $PWD/IRPF90_temp/f
@ -52,23 +55,31 @@ def create_build_touches(list_of_other_o):
Create the build command for the irp_touches.o file. Create the build command for the irp_touches.o file.
""" """
name = "irp_touches" name = "irp_touches"
target_o = dress("%s.irp.o"%name) short_target_o = "%s.irp.o"%name
target_F90 = dress("%s.irp.F90"%name) short_target_F90 = "%s.irp.F90"%name
target_o = dress(short_target_o)
target_F90 = dress(short_target_F90)
needed_modules = [ "%s.irp.module.o"%(modules[x].filename) for x in modules ] needed_modules = [ "%s.irp.module.o"%(modules[x].filename) for x in modules ]
list_of_modules = map(dress, needed_modules) + list_of_other_o list_of_modules = map(dress, needed_modules) + list_of_other_o
list_of_modules = ' '.join(list_of_modules) list_of_modules = ' '.join(list_of_modules)
result = '\n\n'.join( result = '\n'.join(
[ [
"build {target_o}: compile_touches {target_F90} | {list_of_modules}", "build {target_o}: compile_touches_{id} {target_F90} | {list_of_modules}",
" short_in = {short_target_F90}",
" short_out = {short_target_o}",
"",
] ) ] )
result = result.format( result = result.format(
target_o = target_o , id = irp_id ,
list_of_modules = list_of_modules ,
short_target_F90 = os.path.split(short_target_F90)[1] ,
short_target_o = os.path.split(short_target_o)[1] ,
target_F90 = target_F90 , target_F90 = target_F90 ,
list_of_modules = list_of_modules target_o = target_o
) )
return result return result
@ -79,10 +90,14 @@ def create_build_target(t,list_of_other_o):
name = t.filename name = t.filename
target = dress(name,in_root=True) target = dress(name,in_root=True)
target_o = dress("%s.irp.o"%name) short_target_o = "%s.irp.o"%name
target_F90 = dress("%s.irp.F90"%name) short_target_F90 = "%s.irp.F90"%name
target_module_o = dress("%s.irp.module.o"%name) short_target_module_F90 = "%s.irp.module.F90"%name
target_module_F90 = dress("%s.irp.module.F90"%name) short_target_module_o = "%s.irp.module.o"%name
target_o = dress(short_target_o)
target_F90 = dress(short_target_F90)
target_module_o = dress(short_target_module_o)
target_module_F90 = dress(short_target_module_F90)
needed_modules = [ "%s.irp.module.o"%(modules[x].filename) for x in modules \ needed_modules = [ "%s.irp.module.o"%(modules[x].filename) for x in modules \
if modules[x].name in t.needed_modules ] + [ target_module_o ] if modules[x].name in t.needed_modules ] + [ target_module_o ]
@ -95,21 +110,35 @@ def create_build_target(t,list_of_other_o):
list_of_includes = ' '.join(map(lambda x: dress(x,in_root=True), t.includes)) list_of_includes = ' '.join(map(lambda x: dress(x,in_root=True), t.includes))
result = '\n\n'.join( result = '\n'.join(
[ "build {target}: link {list_of_o}", [ "build {target}: link_{id} {list_of_o}",
"build {target_o}: compile_fortran {target_F90} | {list_of_modules} {list_of_includes}", " short_out = {short_target}",
"build {target_module_o}: compile_fortran {target_module_F90}" "",
"build {target_o}: compile_fortran_{id} {target_F90} | {list_of_modules} {list_of_includes}",
" short_in = {short_target_F90}",
" short_out = {short_target_o}",
"",
"build {target_module_o}: compile_fortran_{id} {target_module_F90}",
" short_in = {short_target_module_F90}",
" short_out = {short_target_module_o}",
"",
] ) ] )
result = result.format( result = result.format(
target = target , id = irp_id ,
target_o = target_o , list_of_includes = list_of_includes ,
target_F90 = target_F90 , list_of_modules = list_of_modules ,
target_module_o = target_module_o , list_of_o = list_of_o ,
target_module_F90 = target_module_F90 , short_target_F90 = os.path.split(short_target_F90)[1] ,
list_of_o = list_of_o , short_target_module_F90 = os.path.split(short_target_module_F90)[1] ,
list_of_modules = list_of_modules , short_target_module_o = os.path.split(short_target_module_o)[1] ,
list_of_includes = list_of_includes short_target = name ,
short_target_o = os.path.split(short_target_o)[1] ,
target_F90 = target_F90 ,
target_module_F90 = target_module_F90 ,
target_module_o = target_module_o ,
target_o = target_o ,
target = target
) )
return result return result
@ -120,10 +149,15 @@ def create_build_non_target(t,list_of_other_o):
""" """
name = t.filename name = t.filename
target_o = dress("%s.irp.o"%name) target = dress(name,in_root=True)
target_F90 = dress("%s.irp.F90"%name) short_target_o = "%s.irp.o"%name
target_module_o = dress("%s.irp.module.o"%name) short_target_F90 = "%s.irp.F90"%name
target_module_F90 = dress("%s.irp.module.F90"%name) short_target_module_F90 = "%s.irp.module.F90"%name
short_target_module_o = "%s.irp.module.o"%name
target_o = dress(short_target_o)
target_F90 = dress(short_target_F90)
target_module_o = dress(short_target_module_o)
target_module_F90 = dress(short_target_module_F90)
needed_modules = [ "%s.irp.module.o"%(modules[x].filename) for x in modules \ needed_modules = [ "%s.irp.module.o"%(modules[x].filename) for x in modules \
if modules[x].name in t.needed_modules ] + [ target_module_o ] if modules[x].name in t.needed_modules ] + [ target_module_o ]
@ -133,20 +167,30 @@ def create_build_non_target(t,list_of_other_o):
list_of_externals = ' '.join([ dress(x,in_root=True) for x in list_of_other_o ]) list_of_externals = ' '.join([ dress(x,in_root=True) for x in list_of_other_o ])
list_of_includes = ' '.join(map(lambda x: dress(x,in_root=True), t.includes)) list_of_includes = ' '.join(map(lambda x: dress(x,in_root=True), t.includes))
result = '\n\n'.join( result = '\n'.join(
[ [
"build {target_o}: compile_fortran {target_F90} | {list_of_modules} {list_of_externals}", "build {target_o}: compile_fortran_{id} {target_F90} | {list_of_modules} {list_of_externals}",
"build {target_module_o}: compile_fortran {target_module_F90} | {list_of_externals} {list_of_includes}" " short_in = {short_target_F90}",
" short_out = {short_target}",
"",
"build {target_module_o}: compile_fortran_{id} {target_module_F90} | {list_of_externals} {list_of_includes}",
" short_in = {short_target_F90}",
" short_out = {short_target_o}",
"",
] ) ] )
result = result.format( result = result.format(
target_o = target_o , id = irp_id ,
target_F90 = target_F90 ,
target_module_o = target_module_o ,
target_module_F90 = target_module_F90 ,
list_of_modules = list_of_modules ,
list_of_externals = list_of_externals , list_of_externals = list_of_externals ,
list_of_includes = list_of_includes list_of_includes = list_of_includes ,
list_of_modules = list_of_modules ,
short_target_F90 = os.path.split(short_target_F90)[1] ,
short_target = name ,
short_target_o = os.path.split(short_target_o)[1] ,
target_F90 = target_F90 ,
target_module_F90 = target_module_F90 ,
target_module_o = target_module_o ,
target_o = target_o
) )
return result return result
@ -164,15 +208,16 @@ def create_build_remaining(f):
target_o = target_o.replace(cwd,os.path.join(cwd,irpdir)) target_o = target_o.replace(cwd,os.path.join(cwd,irpdir))
if extension.lower() in [ 'f', 'f90' ]: if extension.lower() in [ 'f', 'f90' ]:
result = "build {target_o}: compile_fortran {target_i}" result = "build {target_o}: compile_fortran_{id} {target_i}"
elif extension.lower() in [ 'c' ]: elif extension.lower() in [ 'c' ]:
result = "build {target_o}: compile_c {target_i}" result = "build {target_o}: compile_c_{id} {target_i}"
elif extension.lower() in [ 'cxx', 'cpp' ]: elif extension.lower() in [ 'cxx', 'cpp' ]:
result = "build {target_o}: compile_cxx {target_i}" result = "build {target_o}: compile_cxx_{id} {target_i}"
result = result.format( result = result.format(
target_o = target_o, target_o = target_o,
target_i = target_i target_i = target_i,
id = irp_id
) )
return result return result
@ -253,22 +298,28 @@ def run():
# Rules # Rules
t = [ "rule compile_fortran" , t = [ "rule compile_fortran_{id}",
" command = {FC} {FCFLAGS} -c $in -o $out".format(FC=FC, FCFLAGS=FCFLAGS), " command = {FC} {FCFLAGS} -c $in -o $out",
" description = F : $short_in -> $short_out",
"", "",
"rule compile_touches" , "rule compile_touches_{id}",
" command = {FC} -c $in -o $out".format(FC=FC, FCFLAGS=FCFLAGS), " command = {FC} -c $in -o $out",
" description = F : $short_in -> $short_out",
"", "",
"rule compile_c" ,
" command = {CC} {CFLAGS} -c $in -o $out".format(CC=CC, CFLAGS=CFLAGS),
"", "",
"rule compile_cxx" , "rule compile_c_{id}" ,
" command = {CXX} {CXXFLAGS} -c $in -o $out".format(CXX=CXX, CXXFLAGS=CXXFLAGS), " command = {CC} {CFLAGS} -c $in -o $out",
" description = C : $short_in -> $short_out",
"", "",
"rule link", "rule compile_cxx_{id}",
" command = {FC} $in {LIB} -o $out".format(FC=FC, LIB=LIB) ] " command = {CXX} {CXXFLAGS} -c $in -o $out",
" description = C++ : $short_in -> $short_out",
"",
"rule link_{id}",
" command = {FC} $in {LIB} -o $out" ,
" description = Link: $short_out"]
output = [ '\n'.join(t) ] output = [ '\n'.join(t).format(id=irp_id, FC=FC, FCFLAGS=FCFLAGS, LIB=LIB, CXX=CXX, CXXFLAGS=CXXFLAGS, CC=CC, CFLAGS=CFLAGS) ]
# All modules : list of Fmodule objects # All modules : list of Fmodule objects