File: make-makefiles-binaries

package info (click to toggle)
abinit 9.10.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 518,712 kB
  • sloc: xml: 877,568; f90: 577,240; python: 80,760; perl: 7,019; ansic: 4,585; sh: 1,925; javascript: 601; fortran: 557; cpp: 454; objc: 323; makefile: 77; csh: 42; pascal: 31
file content (288 lines) | stat: -rwxr-xr-x 7,666 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/env python3
#
# Copyright (C) 2005-2022 ABINIT Group (Yann Pouillon)
#
# This file is part of the ABINIT software package. For license information,
# please see the COPYING file in the top-level directory of the ABINIT source
# distribution.
#
from __future__ import print_function, division, absolute_import #, unicode_literals

try:
    from ConfigParser import ConfigParser,NoOptionError
except ImportError:
    from configparser import ConfigParser,NoOptionError
from time import gmtime,strftime

import os
import re
import sys

class MyConfigParser(ConfigParser):

  def optionxform(self,option):
    return str(option)

# ---------------------------------------------------------------------------- #

#
# Subroutines
#

# Makefile header
def makefile_header(name,stamp):

  return """#
# Makefile for ABINIT                                      -*- Automake -*-
# Generated by %s on %s

#
# IMPORTANT NOTE
#
# Any manual change to this file will systematically be overwritten.
# Please modify the %s script or its config file instead.
#

AM_CFLAGS  = @ABI_CPPFLAGS@
AM_FCFLAGS = @FPPFLAGS@ @FCFLAGS_FREEFORM@ @FCFLAGS_MODDIR@ @fc_mod_fcflags@ @fcflags_opt_98_main@
AM_LDFLAGS = @FC_LDFLAGS@

""" % (name,stamp,name)



# ---------------------------------------------------------------------------- #

#
# Main program
#

# Initial setup
my_name    = "make-makefiles-binaries"
my_configs = {
  "libs":"config/specs/corelibs.conf",
  "bins":"config/specs/binaries.conf",
  "deps":"config/specs/dependencies.conf"}
my_output  = "src/98_main/Makefile.am"

# Check if we are in the top of the ABINIT source tree
if ( not os.path.exists("configure.ac") or
     not os.path.exists("src/98_main/abinit.F90") ):
  print("%s: You must be in the top of an ABINIT source tree." % my_name)
  print("%s: Aborting now." % my_name)
  sys.exit(1)

# Read config file(s)
for cnf_file in my_configs.values():
  if ( os.path.exists(cnf_file) ):
    if ( re.search("\.cf$",cnf_file) ):
      exec(compile(open(cnf_file).read(), cnf_file, 'exec'))
  else:
    print("%s: Could not find config file (%s)." % (my_name,cnf_file))
    print("%s: Aborting now." % my_name)
    sys.exit(2)

# What time is it?
now = strftime("%Y/%m/%d %H:%M:%S +0000",gmtime())

# Init corelibs
lib_cnf = MyConfigParser()
lib_cnf.read(my_configs["libs"])
abinit_corelibs = lib_cnf.sections()
abinit_corelibs.sort()

# Init binaries
bin_cnf = MyConfigParser()
bin_cnf.read(my_configs["bins"])
main_bins = bin_cnf.sections()
main_bins.sort()

# Init deps
dep_cnf = MyConfigParser()
dep_cnf.read(my_configs["deps"])

# Generate library and include lists
lib_list = ""
inc_list = ""

# Main binary includes
cnf_file = "src/98_main/abinit.dir"
if ( os.path.exists(cnf_file) ):
  exec(compile(open(cnf_file).read(), cnf_file, 'exec'))
else:
  include_dirs = []

# Common and core include lists
include_dirs = ["common", "core", "libpaw"]

for tmp in include_dirs:
  inc_list += " \\\n\t@src_%s_fcflags@" % (tmp)

# Core libraries
for lib in abinit_corelibs:
  # Init
  lib_opt = lib_cnf.get(lib,"optional")
  lib_rul = lib_cnf.get(lib,"abirules")
  try:
    lib_deps = lib_cnf.get(lib,"dependencies").split()
  except NoOptionError:
    lib_deps = None

  # Add sequential and parallel libraries
  if ( lib_opt == "yes" ):
    lib_list += "if DO_BUILD_%s\n" % (lib.upper())
    lib_list += " LIB_%s = $(top_builddir)/src/%s/lib%s.a\n" % \
      (lib.upper(),lib,lib)
    lib_list += "else\n LIB_%s =\nendif\n" % (lib.upper())
  else:
    lib_list += "LIB_%s = $(top_builddir)/src/%s/lib%s.a\n" % \
      (lib.upper(),lib,lib)

lib_list += "\n"

# Generate binary list
bin_list = "bin_PROGRAMS ="
opt_list = ""
cln_list = "CLEANFILES ="

for bin in main_bins:

  # Init
  bin_opt = bin_cnf.get(bin,"optional")

  # Regular binaries
  if ( not os.path.exists("src/98_main/%s.F90" % (bin)) ):
    sys.stderr.write("Error: No such file or directory: 'src/98_main/%s.F90'\n" % \
      (bin))
    sys.exit(4)
  cln_list += " \\\n\t%s_cpp.f90" % (bin)

  # Sequential/parallel binaries
  if ( bin_opt == "yes" ):
    opt_list += "if DO_BUILD_%s\n bin_PROGRAMS += %s\nendif\n" % \
      (bin.upper(),bin)
  else:
    bin_list += " \\\n\t%s" % (bin)

cln_list += "\n"
bin_list += "\n\n"
opt_list += "\n"

# Start generating makefile content
makefile = makefile_header(my_name,now)

if ( inc_list != "" ):
  makefile += "AM_CPPFLAGS =%s\n\n" % (inc_list)
makefile += "# Internal libraries\n" + lib_list
makefile += "# Binary list\n" + bin_list + opt_list

# Process each binary
for bin in main_bins:

  # Init
  try:
    bin_deps = bin_cnf.get(bin,"dependencies").split()
  except NoOptionError:
    bin_deps = list()
  bin_opt = bin_cnf.get(bin,"optional")
  bin_cppflags = ""
  bin_fcflags = "@src_common_fcflags@ @src_core_fcflags@ @src_libpaw_fcflags@"
  bin_ldflags = ""
  bin_libs = ""

  # Check all libraries the binary depends on
  for lib in bin_cnf.get(bin,"libraries").split():
    # Add library pointer
    bin_libs += " $(LIB_%s)" % (lib.upper())

  # Check whether the binary may use external libraries
  for dep in bin_deps:
    if ( dep in dep_cnf.sections() ):
      if ( dep_cnf.get(dep, "detector") == "steredeg" ):
        dep_pfx = "sd"
      else:
        dep_pfx = "abi"
      dep_lngs = dep_cnf.get(dep, "languages").split()
      if ( ("c" in dep_lngs) or ("c++" in dep_lngs) ):
        bin_cppflags += " @%s_%s_cppflags@" % (dep_pfx, dep)
      if ( "fortran" in dep_lngs ):
        bin_fcflags += " @%s_%s_fcflags@" % (dep_pfx, dep)
      bin_ldflags += " @%s_%s_ldflags@" % (dep_pfx, dep)
      bin_libs += " @%s_%s_libs@" % (dep_pfx, dep)
    else:
      raise ValueError("invalid external dependency: '%s'" % dep)
  bin_fcflags += " @sd_sys_fcflags@"

  # Finish setting build-time parameters
  bin_libs += " $(FC_LIBS)"

  # Write results
  indent = ""
  makefile += "# %s.F90 ---> %s\n" % (bin,bin)

  # Optional build
  if ( bin_opt == "yes" ):
    makefile += "if DO_BUILD_%s\n" % (bin.upper())
    indent = " "

  # Binary sources
  makefile += "%s%s_SOURCES = %s.F90\n" % (indent,bin,bin)

  # Additional preprocessing flags
  if ( bin_cppflags != "" ):
    bin_cppflags = re.sub(r"[ ]+"," ",bin_cppflags.strip())
    bin_cppflags = re.sub(" "," \\\n\t",bin_cppflags)
    makefile += "%s%s_CPPFLAGS = \\\n\t%s\n" % (indent,bin,bin_cppflags)

  # Additional compile flags
  if ( bin_fcflags != "" ):
    bin_fcflags = re.sub(r"[ ]+"," ",bin_fcflags.strip())
    bin_fcflags = re.sub(" "," \\\n\t",bin_fcflags)
    makefile += "%s%s_FCFLAGS = \\\n\t%s\n" % (indent,bin,bin_fcflags)

  # LDFLAGS and additional libraries
  if ( (bin_ldflags != "") or (bin_libs != "") ):
    bin_ldflags += bin_libs
    bin_ldflags = re.sub(r"[ ]+"," ",bin_ldflags.strip())
    bin_ldflags = re.sub(" "," \\\n\t",bin_ldflags)
    makefile += "%s%s_LDADD = \\\n\t%s\n" % (indent,bin,bin_ldflags)

  # Close conditionals
  if ( bin_opt == "yes" ):
    makefile += "endif\n\n"
  else:
    makefile += "\n"

# Write list of files to clean
makefile += cln_list

# Init list of extra files
ext       = "EXTRA_DIST ="
ext_print = 0

# Include additional hand-made information
add = "src/98_main/abinit.amf"
if ( os.path.exists(add) ):
  ext += " \\\n\tabinit.amf"
  ext_print = 1

# Include RoboDOC header
hdr = "src/98_main/_main_"
if ( os.path.exists(hdr) ):
  ext += " \\\n\t_98_main_"
  ext_print = 1

# Finish list of extra files
ext += "\n"

# Write list of extra files
if ( ext_print == 1 ):
  makefile += "\n"+ext+"\n"

# Write additional hand-made information
if ( os.path.exists(add) ):
  makefile += "\n" + open(add, "rt").read()

mf = open(my_output, "wt")
mf.write(makefile)
mf.close()