PyXMake Developer Guide 1.0
PyXMake
Loading...
Searching...
No Matches
gfortran.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 Mingw64/GFortran on windows.
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', arch=architecture, verbose=verbosity, incremental=incremental, bash=True, **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 os.environ["pyx_cflags"] = '-fcray-pointer'
140 dam_make = [os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch,BuildID),
141 os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch)]
142 dam_replace = collections.OrderedDict([('(valueLogical .NE. saveTo)',"(valueLogical .NEQV. saveTo)"), #@UndefinedVariable
143 ('EOF(unit)',"IS_IOSTAT_END(iostat)")])
144 main(BuildID,
145 files=VTL.GetSourceCode(4),
146 # Add custom directive to command line to activate usage without ABAQUS
147 command=sep.join([VTL.GetBuildCommand(2,"free"),"-DPYEXT"]),
148 source=os.path.join(__mcd_core_path,"external",BuildID,"for"),
149 include=[], make=dam_make, libs=[], replace=dam_replace)
150
151 # Build DispModule
152 BuildID = "dispmodule"
153 disp_make = [os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch,BuildID),
154 os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch)]
155 main(BuildID,
156 files=VTL.GetSourceCode(5),
157 command=VTL.GetBuildCommand(2,"free"),
158 source=os.path.join(__mcd_core_path,"external",BuildID,"Fortran90","Src"),
159 include=[], make=disp_make, libs=[])
160
161 # Compile all low-level external libraries used by MCODAC using Intel Fortran.
162 # Files to be processed by low-level libraries
163 BuildIDs = [os.path.splitext(x)[0].lower() for x in VTL.GetSourceCode(6)]
164 for BuildID in BuildIDs:
165 srcfile = [x for x in VTL.GetSourceCode(6) if x.startswith(BuildID)]
166 # Mixed format compilation
167 style = "fixed"; combine=False
168 if not BuildID.endswith("790"):
169 style = "free"
170 combine=True
171 # Define files to be processed for TOMS
172 source = os.path.join(__mcd_core_path,"external","toms")
173 make = [os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch, "toms"),
174 os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch)]
175 main(BuildID, files=srcfile, command=VTL.GetBuildCommand(2, style+" -DPYX_WRAPPER"), make=make,
176 combine=combine, source=source, include=[], libs=[])
177
178 ## Name mangling without changing the original source code. Rename procedures to avoid conflicts in final software.
179 # Update: Rename explicitly to avoid linking errors using GCC/GFortran.
180 pchip_replace = collections.OrderedDict([('rand',"pchip_rand"), ('RAND',"pchip_rand"), ('subroutine timestamp ( )','subroutine timestamp ( ) BIND(C, NAME="pchip_timestamp")')]) #@UndefinedVariable
181
182 # Compile all low-level external libraries used by MCODAC using Intel Fortran.
183 # Files to be processed by low-level libraries
184 BuildIDs = [os.path.splitext(x)[0].lower() for x in VTL.GetSourceCode(7)]
185 for BuildID in BuildIDs:
186 srcfile = [x for x in VTL.GetSourceCode(7) if x.startswith(BuildID)]
187 # Define files to be processed for NMS, PCHIP, SLATEC & INTERP
188 source = os.path.join(__mcd_core_path,"external",BuildID)
189 make = [os.path.join(__mcd_core_path,"include",Utility.GetPlatform(),__arch, BuildID),
190 os.path.join(__mcd_core_path,"lib",Utility.GetPlatform(),__arch)]
191 if BuildID == "pchip":
192 main(BuildID, files=srcfile, command=VTL.GetBuildCommand(2, "free"), source=source, make=make,
193 include=[], libs=[], replace=pchip_replace)
194 else:
195 main(BuildID, files=srcfile, command=VTL.GetBuildCommand(2, "free"), source=source, make=make, include=[], libs=[])
196
197 # Build MCODAC (default settings)
198 BuildID = "mcd_core"; main(BuildID)
199 else:
200 # This is not implemented yet
201 raise NotImplementedError
202
203 # Finish
204 print('==================================')
205 print('Finished')
206 print('==================================')
207 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 gfortran.py:71