PyXMake Developer Guide  1.0
PyXMake
D:/03_Workspaces/01_Eclipse/pyx_core/PyXMake/VTL/ifort.py
1 # -*- coding: utf-8 -*-
2 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 # % PyXMake - Build environment for PyXMake %
4 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 """
6 Triple-use minimum working example for PyXMake. This script can be
7 executed in three different ways in varying levels of accessibility
8 
9 @note: Compile a static Fortran library using Intel Fortran.
10 Created on 20.03.2018
11 
12 @version: 1.0
13 ----------------------------------------------------------------------------------------------
14 @requires:
15  - PyXMake
16 
17 @change:
18  - Added 3rd party dependencies to build process. Requires
19  PyCODAC in PYTHONPATH.
20 
21 @author: garb_ma [DLR-FA,STM Braunschweig]
22 ----------------------------------------------------------------------------------------------
23 """
24 import os, sys
25 import argparse
26 
27 try:
28  import PyXMake as _
29 except ImportError:
30  # Script is executed as a plug-in
31  sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
32 finally:
33  from PyXMake.Build import Make as pyx #@UnresolvedImport
34  from PyXMake.Tools import Utility #@UnresolvedImport
35  from PyXMake import VTL #@UnresolvedImport
36 
37 # Predefined script local variables
38 __arch = Utility.GetArchitecture()
39 
40 try:
41  # Import PyCODAC to build library locally during setup.
42  from PyCODAC.Tools.Utility import GetPyCODACPath
43  # Import and set local path to PyCODAC
44  __mcd_core_path = os.path.join(GetPyCODACPath(),"Core")
45 except ImportError:
46  # This script is not executed as plug-in
47  __mcd_core_path = ""
48 except:
49  # Something else went wrong.
50  from PyXMake.Tools import ErrorHandling
51  ErrorHandling.InputError(20)
52 
53 def main(
54  BuildID,
55  # Build MCODAC by default
56  files=VTL.GetSourceCode(0),
57  command = VTL.GetBuildCommand(2),
58  libs = VTL.GetLinkDependency(0, 2, __arch),
59  # Resource paths
60  source=os.path.join(__mcd_core_path,"src"),
61  include=[os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, __arch)],
62  dependency=os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch),
63  make=[os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch),
64  os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch)],
65  # Architecture, verbose and scratch directory
66  architecture=__arch,scratch=VTL.Scratch, verbosity=2,
67  # Activate / deactivate incremental compilation. Does deactivate preprocessing.
68  incremental = False,
69  # Additional keyword arguments
70  **kwargs):
71  """
72  Main function to execute the script.
73  """
74  # Evaluate input parameters
75  makelist = list([]); makelist.append(make); makelist = list(Utility.ArbitraryFlattening(makelist))
76  replace = kwargs.get('replace', False)
77  # Build a static library using the Intel Fortran Compiler
78  FBuild = pyx.Fortran(BuildID, files, scratch=scratch, msvsc='vs2015', arch=architecture, verbose=verbosity, incremental=incremental)
79  # Combine source code using wrapper module
80  if not incremental:
81  FBuild.Wrapper(BuildID)
82  # Add source, module and library paths
83  FBuild.SourcePath(source)
84  FBuild.AddIncludePath(include)
85  FBuild.AddDependencyPath(dependency)
86  # Define output paths
87  try:
88  # Module & library path are not relative to each other
89  FBuild.OutputPath(modulepath=makelist[0], libpath=makelist[1])
90  except:
91  # Module & library path are relative to each other.
92  FBuild.OutputPath(modulepath=os.path.join(makelist[0],"include"), libpath=os.path.join(makelist[0],"lib"))
93  if isinstance(replace,dict):
94  FBuild.Preprocessing(inend='.for', outend='.f90', replace=replace)
95  elif incremental:
96  FBuild.Preprocessing(copyfiles=files)
97  else:
98  FBuild.Preprocessing(inend='.for', outend='.f90')
99  # Define libraries used during linking
100  FBuild.UseLibraries(libs)
101  FBuild.Build(command)
102  # Pass additional keywords to command
103  FBuild.create(**kwargs)
104 
105 if __name__ == "__main__":
106 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 # % Access command line inputs %
108 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109  parser = argparse.ArgumentParser(description="Build a static Fortran library remotely on the current machine")
110 
111  try:
112  _ = sys.argv[1]
113  args, _ = parser.parse_known_args()
114  # Extract command line option to identify the requested make operation
115  make_opt = args.make[0]
116  except:
117  # This is the default build option
118  make_opt = -1
119  # Build all supported features
120  if make_opt == -1:
121 
122  # Build BoxBeam; Define files to be processed for BoxBeam
123  BuildID = "bbeam"
124  box_source = os.path.join(__mcd_core_path,"external","boxbeam")
125  box_make = [os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch,"boxbeam"),
126  os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch)]
127  main(BuildID, files=VTL.GetSourceCode(1), source=box_source, include=[], make=box_make, libs=[])
128 
129  # Build Beos; Define files to be processed for Beos
130  BuildID = "beos"
131  beos_source = os.path.join(__mcd_core_path,"external",BuildID)
132  beos_make = [None, os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch)]
133  main(BuildID, files=VTL.GetSourceCode(2), command=VTL.GetBuildCommand(2,"mixed"), source=beos_source,
134  include=[], make=beos_make, libs=[], incremental=True)
135 
136  # Build CompDam; Define files to be processed for CompDam
137  BuildID = "compdam"; sep = " "
138  dam_make = [os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch,BuildID),
139  os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch)]
140  main(BuildID,
141  files=VTL.GetSourceCode(4),
142  # Add custom directive to command line to activate usage without ABAQUS
143  command=sep.join([VTL.GetBuildCommand(2,"free"),"-DPYEXT"]),
144  source=os.path.join(__mcd_core_path,"external",BuildID,"for"),
145  include=[], make=dam_make, libs=[])
146 
147  # Build DispModule
148  BuildID = "dispmodule"
149  disp_make = [os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch,BuildID),
150  os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch)]
151  main(BuildID,
152  files=VTL.GetSourceCode(5),
153  command=VTL.GetBuildCommand(2,"free"),
154  source=os.path.join(__mcd_core_path,"external",BuildID,"Fortran90","Src"),
155  include=[], make=disp_make, libs=[])
156 
157  # Compile all low-level external libraries used by MCODAC using Intel Fortran.
158  # Files to be processed by low-level libraries
159  BuildIDs = [os.path.splitext(x)[0].lower() for x in VTL.GetSourceCode(6)]
160  for BuildID in BuildIDs:
161  srcfile = [x for x in VTL.GetSourceCode(6) if x.startswith(BuildID)]
162  # Mixed format compilation
163  style = "fixed"; combine=False
164  if not BuildID.endswith("790"):
165  style = "free"
166  combine=True
167  # Define files to be processed for TOMS
168  source = os.path.join(__mcd_core_path,"external","toms")
169  make = [os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch, "toms"),
170  os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch)]
171  main(BuildID, files=srcfile, command=VTL.GetBuildCommand(2, style+" -DPYX_WRAPPER"), make=make,
172  combine=combine, source=source, include=[], libs=[])
173 
174  # Name mangling without changing the original source code. Rename procedures to avoid conflicts in final software.
175  pchip_replace = {'FUNCTION RAND ( R )':'FUNCTION RAND ( R ) BIND(C, NAME="pchip_rand")',
176  'subroutine timestamp ( )':'subroutine timestamp ( ) BIND(C, NAME="pchip_timestamp")'}
177 
178  # Compile all low-level external libraries used by MCODAC using Intel Fortran.
179  # Files to be processed by low-level libraries
180  BuildIDs = [os.path.splitext(x)[0].lower() for x in VTL.GetSourceCode(7)]
181  for BuildID in BuildIDs:
182  srcfile = [x for x in VTL.GetSourceCode(7) if x.startswith(BuildID)]
183  # Define files to be processed for NMS, PCHIP, SLATEC & INTERP
184  source = os.path.join(__mcd_core_path,"external",BuildID)
185  make = [os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch, BuildID),
186  os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch)]
187  if BuildID == "pchip":
188  main(BuildID, files=srcfile, command=VTL.GetBuildCommand(2, "free"), source=source,
189  include=[], libs=[], replace=pchip_replace)
190  else:
191  main(BuildID, files=srcfile, command=VTL.GetBuildCommand(2, "free"), source=source, include=[], libs=[], verbose=2)
192 
193  # Build MCODAC (default settings)
194  BuildID = "mcd_core"; main(BuildID)
195  else:
196  # This is not implemented yet
197  raise NotImplementedError
198 
199  # Finish
200  print('==================================')
201  print('Finished')
202  print('==================================')
203  sys.exit()
Module containing basic functionalities defined for convenience.
Definition: __init__.py:1
Module containing all relevant modules and scripts associated with the building process.
Definition: __init__.py:1
def main(BuildID, files=VTL.GetSourceCode(0), command=VTL.GetBuildCommand(2), libs=VTL.GetLinkDependency(0, 2, __arch), source=os.path.join(__mcd_core_path,"src"), include=[os.path.join(__mcd_core_path,"include", Utility.GetPlatform(), __arch, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, __arch)], dependency=os.path.join(__mcd_core_path,"lib", Utility.GetPlatform(), __arch), make=[os.path.join(__mcd_core_path,"include", Utility.GetPlatform(), __arch), os, path, join, __mcd_core_path, lib, Utility, GetPlatform, __arch, architecture=__arch, scratch=VTL.Scratch, verbosity=2, incremental=False, kwargs)
Definition: ifort.py:70