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