2009-09-02 20:45:53 +02:00
|
|
|
#!/usr/bin/python
|
2009-09-23 12:51:27 +02:00
|
|
|
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
|
|
|
|
# the Implicit Reference to Parameters (IRP) method.
|
|
|
|
# Copyright (C) 2009 Anthony SCEMAMA
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# Anthony Scemama
|
|
|
|
# LCPQ - IRSAMC - CNRS
|
|
|
|
# Universite Paul Sabatier
|
|
|
|
# 118, route de Narbonne
|
|
|
|
# 31062 Toulouse Cedex 4
|
2009-09-25 00:04:49 +02:00
|
|
|
# scemama@irsamc.ups-tlse.fr
|
2009-09-23 12:51:27 +02:00
|
|
|
|
2009-09-02 20:45:53 +02:00
|
|
|
|
2010-10-02 20:53:22 +02:00
|
|
|
import os,sys
|
2009-09-02 20:45:53 +02:00
|
|
|
import irpf90_t
|
2011-05-26 11:14:48 +02:00
|
|
|
from command_line import command_line
|
2009-09-02 20:45:53 +02:00
|
|
|
irpdir = irpf90_t.irpdir
|
|
|
|
mandir = irpf90_t.mandir
|
|
|
|
|
|
|
|
FILENAME = "Makefile"
|
2014-04-02 13:46:43 +02:00
|
|
|
FILENAME_GITIGNORE = ".gitignore"
|
2014-04-02 17:07:27 +02:00
|
|
|
IRPF90_MAKE = "irpf90.make"
|
2009-09-02 20:45:53 +02:00
|
|
|
|
2009-09-09 00:46:42 +02:00
|
|
|
######################################################################
|
2009-09-02 20:45:53 +02:00
|
|
|
def create():
|
|
|
|
has_makefile = True
|
|
|
|
try:
|
|
|
|
file = open(FILENAME,"r")
|
2009-09-03 23:12:32 +02:00
|
|
|
except IOError:
|
2009-09-02 20:45:53 +02:00
|
|
|
has_makefile = False
|
|
|
|
if has_makefile:
|
|
|
|
return
|
|
|
|
file = open(FILENAME,"w")
|
|
|
|
t = """IRPF90 = irpf90 #-a -d
|
|
|
|
FC = gfortran
|
2009-10-21 14:49:35 +02:00
|
|
|
FCFLAGS= -O2
|
2009-09-02 20:45:53 +02:00
|
|
|
|
|
|
|
SRC=
|
|
|
|
OBJ=
|
|
|
|
LIB=
|
|
|
|
|
2014-04-02 13:46:43 +02:00
|
|
|
include %s
|
2009-09-02 20:45:53 +02:00
|
|
|
|
2014-04-02 13:46:43 +02:00
|
|
|
%s: $(filter-out %s%%, $(wildcard */*.irp.f)) $(wildcard *.irp.f) $(wildcard *.inc.f) Makefile
|
2009-09-02 20:45:53 +02:00
|
|
|
\t$(IRPF90)
|
2014-04-02 13:46:43 +02:00
|
|
|
"""%(IRPF90_MAKE,IRPF90_MAKE,irpdir)
|
|
|
|
file.write(t)
|
|
|
|
file.close()
|
|
|
|
create_gitignore()
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
def create_gitignore():
|
|
|
|
has_makefile = True
|
|
|
|
try:
|
|
|
|
file = open(FILENAME_GITIGNORE,"r")
|
|
|
|
except IOError:
|
|
|
|
has_makefile = False
|
|
|
|
if has_makefile:
|
|
|
|
return
|
|
|
|
file = open(FILENAME_GITIGNORE,"w")
|
2014-04-02 17:07:27 +02:00
|
|
|
t = "\n".join([ irpdir, mandir, IRPF90_MAKE, 'irpf90_entities', 'tags' ])
|
2009-09-02 20:45:53 +02:00
|
|
|
file.write(t)
|
|
|
|
file.close()
|
|
|
|
|
2009-09-09 00:46:42 +02:00
|
|
|
######################################################################
|
|
|
|
def run():
|
2014-01-07 17:01:40 +01:00
|
|
|
from modules import modules
|
2010-10-02 20:53:22 +02:00
|
|
|
mod = []
|
2011-04-09 23:45:50 +02:00
|
|
|
for m in modules.values():
|
|
|
|
mod.append(m)
|
2010-10-02 20:53:22 +02:00
|
|
|
|
2014-04-02 13:46:43 +02:00
|
|
|
file = open(IRPF90_MAKE,'w')
|
2013-12-11 14:00:27 +01:00
|
|
|
result = ""
|
|
|
|
result += "FC+=-I %s "%(irpdir)
|
|
|
|
for i in command_line.include_dir:
|
|
|
|
result += "-I %s%s "%(irpdir,i)
|
|
|
|
result += "\n"
|
|
|
|
result += "SRC += %sirp_stack.irp.F90"%(irpdir)
|
2010-10-02 20:53:22 +02:00
|
|
|
result += " %sirp_touches.irp.F90"%(irpdir)
|
2011-05-26 11:14:48 +02:00
|
|
|
if command_line.do_openmp:
|
|
|
|
result += " %sirp_locks.irp.F90"%(irpdir)
|
2011-09-30 19:10:18 +02:00
|
|
|
if command_line.do_profile:
|
|
|
|
result += " %sirp_profile.irp.F90"%(irpdir)
|
2010-10-02 20:53:22 +02:00
|
|
|
for m in mod:
|
2013-12-11 14:00:27 +01:00
|
|
|
result += " %s%s.irp.F90"%(irpdir,m.filename)
|
|
|
|
result += " %s%s.irp.module.F90"%(irpdir,m.filename)
|
2010-10-02 20:53:22 +02:00
|
|
|
print >>file, result
|
|
|
|
|
2014-03-24 17:05:52 +01:00
|
|
|
result = "OBJ_IRP = "
|
2010-10-02 20:53:22 +02:00
|
|
|
for m in mod:
|
|
|
|
if not m.is_main:
|
2013-12-11 14:00:27 +01:00
|
|
|
result += " %s%s.irp.o"%(irpdir,m.filename)
|
|
|
|
result += " %s%s.irp.module.o"%(irpdir,m.filename)
|
2010-10-02 20:53:22 +02:00
|
|
|
print >>file, result
|
|
|
|
|
2014-03-24 17:05:52 +01:00
|
|
|
print >>file, "OBJ1 = $(OBJ_IRP) $(OBJ) %sirp_touches.irp.o"%(irpdir),
|
2011-09-30 19:10:18 +02:00
|
|
|
if command_line.do_profile:
|
2011-10-21 09:10:40 +02:00
|
|
|
print >>file, " %sirp_profile.irp.o"%(irpdir), " irp_rdtsc.o",
|
2014-01-07 17:01:40 +01:00
|
|
|
if command_line.do_codelet:
|
|
|
|
print >>file, " irp_rdtsc.o",
|
2011-05-26 11:14:48 +02:00
|
|
|
if command_line.do_openmp:
|
2011-09-30 19:10:18 +02:00
|
|
|
print >>file, " %sirp_locks.irp.o"%(irpdir),
|
2011-05-26 11:14:48 +02:00
|
|
|
else:
|
|
|
|
print >>file, ""
|
2010-10-02 20:53:22 +02:00
|
|
|
|
|
|
|
all = filter(lambda x: modules[x].is_main, modules)
|
|
|
|
all = map(lambda x: x[:-6], all)
|
2010-10-11 19:43:14 +02:00
|
|
|
all_o = map(lambda x: "%s.irp.module.o %s.irp.o"%(x,x), all)
|
2010-10-02 20:53:22 +02:00
|
|
|
print >>file, "ALL = %s"%(" ".join(all))
|
|
|
|
print >>file, "ALL_OBJ = %s"%(" ".join(all_o))
|
|
|
|
print >>file, "ALL_OBJ1 = $(patsubst %%, %s%%,$(notdir $(ALL_OBJ)))"%(irpdir)
|
|
|
|
print >>file, "all:$(ALL)"
|
2010-10-11 20:14:17 +02:00
|
|
|
print >>file, "\t@$(MAKE) -s move"
|
2013-01-17 10:45:26 +01:00
|
|
|
print >>file, "ifdef USE_IRPF90_A"
|
|
|
|
for m in mod:
|
|
|
|
if m.is_main:
|
2013-12-11 14:00:27 +01:00
|
|
|
exe = m.filename
|
2013-01-17 10:45:26 +01:00
|
|
|
print >>file, "%s: %s%s.irp.o %s%s.irp.module.o irpf90.a"%(exe,irpdir,exe,irpdir,exe)
|
|
|
|
print >>file, "\t$(FC) -o $@ %s$@.irp.o %s$@.irp.module.o irpf90.a $(LIB)"%(irpdir,irpdir)
|
|
|
|
print >>file, "\t@$(MAKE) -s move"
|
|
|
|
print >>file, "else"
|
2010-10-02 20:53:22 +02:00
|
|
|
for m in mod:
|
|
|
|
if m.is_main:
|
2013-12-11 14:00:27 +01:00
|
|
|
exe = m.filename
|
2010-10-11 19:43:14 +02:00
|
|
|
print >>file, "%s: %s%s.irp.o %s%s.irp.module.o $(OBJ1)"%(exe,irpdir,exe,irpdir,exe)
|
|
|
|
print >>file, "\t$(FC) -o $@ %s$@.irp.o %s$@.irp.module.o $(OBJ1) $(LIB)"%(irpdir,irpdir)
|
2010-10-11 20:14:17 +02:00
|
|
|
print >>file, "\t@$(MAKE) -s move"
|
2013-01-17 10:45:26 +01:00
|
|
|
print >>file, "endif"
|
2010-10-02 20:53:22 +02:00
|
|
|
|
|
|
|
buffer = ""
|
|
|
|
for m in mod:
|
2014-03-24 17:05:52 +01:00
|
|
|
filename = "%s%s.irp.o: $(OBJ) %s%s.irp.module.o"%(irpdir,m.filename,irpdir,m.filename)
|
2013-12-11 14:00:27 +01:00
|
|
|
needed_modules = filter( lambda x: modules[x].name in m.needed_modules, modules )
|
|
|
|
needed_files = map(lambda x: modules[x].filename, needed_modules)
|
|
|
|
mds = map (lambda x: " %s%s.irp.module.o"%(irpdir,x),needed_files)
|
2010-11-22 11:48:11 +01:00
|
|
|
print >>file, filename," ".join(mds)," ".join(m.includes)
|
2010-10-02 20:53:22 +02:00
|
|
|
if not m.is_main:
|
|
|
|
buffer += "\t - @echo '"+filename+" ".join(mds)+"' >> %sdist_Makefile\n"%(irpdir)
|
2014-04-01 11:57:54 +02:00
|
|
|
print >>file, "%sirp_touches.irp.o: $(OBJ) "%(irpdir),
|
2010-10-02 20:53:22 +02:00
|
|
|
mds = filter(lambda x: not x.is_main,mod)
|
2013-12-11 14:00:27 +01:00
|
|
|
mds = map(lambda x: " %s%s.irp.o %s%s.irp.o"%(irpdir,x.filename,irpdir,x.filename),mds)
|
2010-10-02 20:53:22 +02:00
|
|
|
print >>file," ".join(mds)
|
2011-09-30 19:10:18 +02:00
|
|
|
if command_line.do_profile:
|
|
|
|
print >>file, "%sirp_profile.irp.o:"%(irpdir),
|
|
|
|
print >>file," ".join(mds)
|
2011-05-26 11:14:48 +02:00
|
|
|
if command_line.do_openmp:
|
|
|
|
print >>file, "%sirp_locks.irp.o:"%(irpdir),
|
|
|
|
print >>file," ".join(mds)
|
2010-10-02 20:53:22 +02:00
|
|
|
|
|
|
|
|
2011-05-26 11:14:48 +02:00
|
|
|
# print >>file, "%sdist_Makefile:"%(irpdir)
|
|
|
|
# print >>file, "\t- @echo FC=$(FC) > %sdist_Makefile"%(irpdir)
|
|
|
|
# print >>file, "\t- @echo FCFLAGS=$(FCFLAGS) >> %sdist_Makefile"%(irpdir)
|
|
|
|
# print >>file, "\t- @echo LIB=$(LIB) >> %sdist_Makefile"%(irpdir)
|
|
|
|
# print >>file, "\t- @echo .DEFAULT_GOAL: exe >> %sdist_Makefile"%(irpdir)
|
2014-03-24 17:05:52 +01:00
|
|
|
# print >>file, "\t- @echo 'exe: $$(EXE).irp.F90 $(OBJ_IRP) $(OBJ) irp_touches.irp.o' >> %sdist_Makefile"%(irpdir)
|
|
|
|
# print >>file, "\t- @echo '\t$$(FC) -o $$(EXE) $$(EXE).irp.F90 $(OBJ_IRP) $(OBJ) irp_touches.irp.o $$(LIB)' >> %sdist_Makefile"%(irpdir)
|
2011-05-26 11:14:48 +02:00
|
|
|
# print >>file, "\t- @echo '%%.o: %%.F90' >> %sdist_Makefile"%(irpdir)
|
|
|
|
# print >>file, "\t- @echo '\t$$(FC) $$(FCFLAGS) -c $$*.F90 -o $$*.o' >> %sdist_Makefile"%(irpdir)
|
|
|
|
# print >>file, "\t- @echo 'clean:' >> %sdist_Makefile"%(irpdir)
|
|
|
|
# print >>file, "\t- @echo '\trm *.o *.mod $$(EXE) 2>/dev/null' >> %sdist_Makefile"%(irpdir)
|
|
|
|
# print >>file, buffer
|
2014-03-24 17:05:52 +01:00
|
|
|
# print >>file, "\t- @echo '\tirp_touches.irp.o: irp_touches.irp.F90 $(OBJ_IRP) $(OBJ) >> %sdist_Makefile"%(irpdir)
|
2011-05-26 11:14:48 +02:00
|
|
|
|
|
|
|
# print >>file, "%%.dist: %sdist_Makefile"%(irpdir)
|
|
|
|
# print >>file, "\t- @mkdir -p dist/$*| DO_NOTHING="
|
|
|
|
# print >>file, "\t- @cp %s* dist/$*/| DO_NOTHING="%(irpdir)
|
|
|
|
# print >>file, "\t- @for i in $(ALL) $(OBJ) irp_touches.irp.o $(ALL_OBJ); do rm dist/$*/$$i ; done| DO_NOTHING="
|
|
|
|
# print >>file, "\t- @for i in $(ALL) ; do rm dist/$*/$$i.irp.F90 ; done| DO_NOTHING="
|
|
|
|
# print >>file, "\t- @rm dist/$*/{*.irp.f,*.mod,irpf90_entities}| DO_NOTHING="
|
|
|
|
# print >>file, "\t- @rm dist/$*/*.mod 2>/dev/null| DO_NOTHING="
|
|
|
|
# print >>file, "\t- @echo 'EXE = $*' > dist/$*/Makefile| DO_NOTHING="
|
|
|
|
# print >>file, "\t- @cat dist/$*/dist_Makefile >> dist/$*/Makefile| DO_NOTHING="
|
|
|
|
# print >>file, "\t- @rm dist/$*/dist_Makefile| DO_NOTHING="
|
|
|
|
# print >>file, "\t- @cp %s$*.irp.F90 dist/$*/| DO_NOTHING="%(irpdir)
|
|
|
|
# print >>file, "\t- cd dist ; tar -zcvf ../$*.tar.gz $*\n"
|
2010-10-02 20:53:22 +02:00
|
|
|
|
2013-12-11 14:00:27 +01:00
|
|
|
for dir in [ irpdir ] + map(lambda x: irpdir+x, command_line.include_dir):
|
2014-04-01 11:57:54 +02:00
|
|
|
print >>file, dir+"%.irp.module.o: $(OBJ) "+dir+"%.irp.module.F90"
|
2013-12-11 14:00:27 +01:00
|
|
|
print >>file, "\t$(FC) $(FCFLAGS) -c "+dir+"$*.irp.module.F90 -o "+dir+"$*.irp.module.o"
|
2014-04-01 11:57:54 +02:00
|
|
|
print >>file, dir+"%.irp.o: $(OBJ) "+dir+"%.irp.module.o "+dir+"%.irp.F90"
|
2013-12-11 14:00:27 +01:00
|
|
|
print >>file, "\t$(FC) $(FCFLAGS) -c "+dir+"$*.irp.F90 -o "+dir+"$*.irp.o"
|
2014-04-01 11:57:54 +02:00
|
|
|
print >>file, dir+"%.irp.o: $(OBJ) "+dir+"%.irp.F90"
|
2013-12-11 14:00:27 +01:00
|
|
|
print >>file, "\t$(FC) $(FCFLAGS) -c "+dir+"$*.irp.F90 -o "+dir+"$*.irp.o"
|
|
|
|
print >>file, dir+"%.o: %.F90"
|
|
|
|
print >>file, "\t$(FC) $(FCFLAGS) -c $*.F90 -o "+dir+"$*.o"
|
|
|
|
print >>file, dir+"%.o: %.f90\n\t$(FC) $(FCFLAGS) -c $*.f90 -o "+dir+"$*.o"
|
|
|
|
print >>file, dir+"%.o: %.f\n\t$(FC) $(FCFLAGS) -c $*.f -o "+dir+"$*.o"
|
|
|
|
print >>file, dir+"%.o: %.F\n\t$(FC) $(FCFLAGS) -c $*.F -o "+dir+"$*.o"
|
2014-04-02 17:07:27 +02:00
|
|
|
print >>file, dir+"%.irp.F90: "+IRPF90_MAKE+"\n"
|
2010-10-02 20:53:22 +02:00
|
|
|
print >>file, "move:\n\t@mv -f *.mod IRPF90_temp/ 2> /dev/null | DO_NOTHING=\n"
|
2014-03-24 17:05:52 +01:00
|
|
|
print >>file, "irpf90.a: $(OBJ) $(OBJ1)\n\t$(AR) crf irpf90.a $(OBJ1)\n"
|
2013-01-17 10:45:26 +01:00
|
|
|
print >>file, "clean:\n\trm -rf $(EXE) $(OBJ1) irpf90.a $(ALL_OBJ1) $(ALL)\n"
|
2010-10-11 20:14:17 +02:00
|
|
|
print >>file, "veryclean:\n\t- $(MAKE) clean\n"
|
2014-04-25 17:21:04 +02:00
|
|
|
print >>file, "\t- rm -rf "+irpdir+" "+mandir+" "+IRPF90_MAKE+" irpf90_entities dist tags\n"
|
2010-10-02 20:53:22 +02:00
|
|
|
|
|
|
|
file.close()
|