|
1 | 1 | # @license Apache-2.0 |
2 | 2 | # |
3 | | -# Copyright (c) 2025 The Stdlib Authors. |
| 3 | +# Copyright (c) 2024 The Stdlib Authors. |
4 | 4 | # |
5 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
6 | 6 | # you may not use this file except in compliance with the License. |
|
14 | 14 | # See the License for the specific language governing permissions and |
15 | 15 | # limitations under the License. |
16 | 16 |
|
17 | | -# A `.gyp` file for building a Node.js native add-on. |
| 17 | +# A GYP include file for building a Node.js native add-on. |
| 18 | +# |
| 19 | +# Note that nesting variables is required due to how GYP processes a configuration. Any variables defined within a nested 'variables' section is defined in the outer scope. Thus, conditions in the outer variable scope are free to use these variables without running into "variable undefined" errors. |
| 20 | +# |
| 21 | +# Main documentation: |
18 | 22 | # |
19 | 23 | # [1]: https://gyp.gsrc.io/docs/InputFormatReference.md |
20 | 24 | # [2]: https://gyp.gsrc.io/docs/UserDocumentation.md |
| 25 | +# |
| 26 | +# Variable nesting hacks: |
| 27 | +# |
| 28 | +# [3]: https://chromium.googlesource.com/external/skia/gyp/+/master/common_variables.gypi |
| 29 | +# [4]: https://src.chromium.org/viewvc/chrome/trunk/src/build/common.gypi?revision=127004 |
21 | 30 | { |
22 | | - # List of files to include in this file: |
23 | | - 'includes': [ |
24 | | - './include.gypi', |
25 | | - ], |
26 | | - |
27 | 31 | # Define variables to be used throughout the configuration for all targets: |
28 | 32 | 'variables': { |
29 | | - # Target name should match the add-on export name: |
30 | | - 'addon_target_name%': 'addon', |
31 | | - |
32 | | - # Fortran compiler (to override -Dfortran_compiler=<compiler>): |
33 | | - 'fortran_compiler%': 'gfortran', |
| 33 | + 'variables': { |
| 34 | + # Host BLAS library (to override -Dblas=<blas>): |
| 35 | + 'blas%': '', |
34 | 36 |
|
35 | | - # Fortran compiler flags: |
36 | | - 'fflags': [ |
37 | | - # Specify the Fortran standard to which a program is expected to conform: |
38 | | - '-std=f95', |
| 37 | + # Path to BLAS library (to override -Dblas_dir=<path>): |
| 38 | + 'blas_dir%': '', |
| 39 | + }, # end variables |
39 | 40 |
|
40 | | - # Indicate that the layout is free-form source code: |
41 | | - '-ffree-form', |
| 41 | + # Source directory: |
| 42 | + 'src_dir': './src', |
42 | 43 |
|
43 | | - # Aggressive optimization: |
44 | | - '-O3', |
45 | | - |
46 | | - # Enable commonly used warning options: |
47 | | - '-Wall', |
48 | | - |
49 | | - # Warn if source code contains problematic language features: |
50 | | - '-Wextra', |
51 | | - |
52 | | - # Warn if a procedure is called without an explicit interface: |
53 | | - '-Wimplicit-interface', |
| 44 | + # Include directories: |
| 45 | + 'include_dirs': [ |
| 46 | + '<@(blas_dir)', |
| 47 | + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{\'os\':\'<(OS)\',\'blas\':\'<(blas)\'},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).include; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', |
| 48 | + ], |
54 | 49 |
|
55 | | - # Do not transform names of entities specified in Fortran source files by appending underscores (i.e., don't mangle names, thus allowing easier usage in C wrappers): |
56 | | - '-fno-underscoring', |
| 50 | + # Add-on destination directory: |
| 51 | + 'addon_output_dir': './src', |
57 | 52 |
|
58 | | - # Warn if source code contains Fortran 95 extensions and C-language constructs: |
59 | | - '-pedantic', |
| 53 | + # Source files: |
| 54 | + 'src_files': [ |
| 55 | + '<(src_dir)/addon.c', |
| 56 | + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{\'os\':\'<(OS)\',\'blas\':\'<(blas)\'},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', |
| 57 | + ], |
60 | 58 |
|
61 | | - # Compile but do not link (output is an object file): |
62 | | - '-c', |
| 59 | + # Library dependencies: |
| 60 | + 'libraries': [ |
| 61 | + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{\'os\':\'<(OS)\',\'blas\':\'<(blas)\'},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libraries; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', |
63 | 62 | ], |
64 | 63 |
|
65 | | - # Set variables based on the host OS: |
66 | | - 'conditions': [ |
67 | | - [ |
68 | | - 'OS=="win"', |
69 | | - { |
70 | | - # Define the object file suffix: |
71 | | - 'obj': 'obj', |
72 | | - }, |
73 | | - { |
74 | | - # Define the object file suffix: |
75 | | - 'obj': 'o', |
76 | | - } |
77 | | - ], # end condition (OS=="win") |
78 | | - ], # end conditions |
| 64 | + # Library directories: |
| 65 | + 'library_dirs': [ |
| 66 | + '<@(blas_dir)', |
| 67 | + '<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{\'os\':\'<(OS)\',\'blas\':\'<(blas)\'},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")', |
| 68 | + ], |
79 | 69 | }, # end variables |
80 | | - |
81 | | - # Define compile targets: |
82 | | - 'targets': [ |
83 | | - |
84 | | - # Target to generate an add-on: |
85 | | - { |
86 | | - # The target name should match the add-on export name: |
87 | | - 'target_name': '<(addon_target_name)', |
88 | | - |
89 | | - # Define dependencies: |
90 | | - 'dependencies': [], |
91 | | - |
92 | | - # Define directories which contain relevant include headers: |
93 | | - 'include_dirs': [ |
94 | | - # Local include directory: |
95 | | - '<@(include_dirs)', |
96 | | - ], |
97 | | - |
98 | | - # List of source files: |
99 | | - 'sources': [ |
100 | | - '<@(src_files)', |
101 | | - ], |
102 | | - |
103 | | - # Settings which should be applied when a target's object files are used as linker input: |
104 | | - 'link_settings': { |
105 | | - # Define libraries: |
106 | | - 'libraries': [ |
107 | | - '<@(libraries)', |
108 | | - ], |
109 | | - |
110 | | - # Define library directories: |
111 | | - 'library_dirs': [ |
112 | | - '<@(library_dirs)', |
113 | | - ], |
114 | | - }, |
115 | | - |
116 | | - # C/C++ compiler flags: |
117 | | - 'cflags': [ |
118 | | - # Enable commonly used warning options: |
119 | | - '-Wall', |
120 | | - |
121 | | - # Aggressive optimization: |
122 | | - '-O3', |
123 | | - ], |
124 | | - |
125 | | - # C specific compiler flags: |
126 | | - 'cflags_c': [ |
127 | | - # Specify the C standard to which a program is expected to conform: |
128 | | - '-std=c99', |
129 | | - ], |
130 | | - |
131 | | - # C++ specific compiler flags: |
132 | | - 'cflags_cpp': [ |
133 | | - # Specify the C++ standard to which a program is expected to conform: |
134 | | - '-std=c++11', |
135 | | - ], |
136 | | - |
137 | | - # Linker flags: |
138 | | - 'ldflags': [], |
139 | | - |
140 | | - # Apply conditions based on the host OS: |
141 | | - 'conditions': [ |
142 | | - [ |
143 | | - 'OS=="mac"', |
144 | | - { |
145 | | - # Linker flags: |
146 | | - 'ldflags': [ |
147 | | - '-undefined dynamic_lookup', |
148 | | - '-Wl,-no-pie', |
149 | | - '-Wl,-search_paths_first', |
150 | | - ], |
151 | | - }, |
152 | | - ], # end condition (OS=="mac") |
153 | | - [ |
154 | | - 'OS!="win"', |
155 | | - { |
156 | | - # C/C++ flags: |
157 | | - 'cflags': [ |
158 | | - # Generate platform-independent code: |
159 | | - '-fPIC', |
160 | | - ], |
161 | | - }, |
162 | | - ], # end condition (OS!="win") |
163 | | - ], # end conditions |
164 | | - |
165 | | - # Define custom build actions for particular inputs: |
166 | | - 'rules': [ |
167 | | - { |
168 | | - # Define a rule for processing Fortran files: |
169 | | - 'extension': 'f', |
170 | | - |
171 | | - # Define the pathnames to be used as inputs when performing processing: |
172 | | - 'inputs': [ |
173 | | - # Full path of the current input: |
174 | | - '<(RULE_INPUT_PATH)' |
175 | | - ], |
176 | | - |
177 | | - # Define the outputs produced during processing: |
178 | | - 'outputs': [ |
179 | | - # Store an output object file in a directory for placing intermediate results (only accessible within a single target): |
180 | | - '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).<(obj)' |
181 | | - ], |
182 | | - |
183 | | - # Define the rule for compiling Fortran based on the host OS: |
184 | | - 'conditions': [ |
185 | | - [ |
186 | | - 'OS=="win"', |
187 | | - |
188 | | - # Rule to compile Fortran on Windows: |
189 | | - { |
190 | | - 'rule_name': 'compile_fortran_windows', |
191 | | - 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Windows...', |
192 | | - |
193 | | - 'process_outputs_as_sources': 0, |
194 | | - |
195 | | - # Define the command-line invocation: |
196 | | - 'action': [ |
197 | | - '<(fortran_compiler)', |
198 | | - '<@(fflags)', |
199 | | - '<@(_inputs)', |
200 | | - '-o', |
201 | | - '<@(_outputs)', |
202 | | - ], |
203 | | - }, |
204 | | - |
205 | | - # Rule to compile Fortran on non-Windows: |
206 | | - { |
207 | | - 'rule_name': 'compile_fortran_linux', |
208 | | - 'message': 'Compiling Fortran file <(RULE_INPUT_PATH) on Linux...', |
209 | | - |
210 | | - 'process_outputs_as_sources': 1, |
211 | | - |
212 | | - # Define the command-line invocation: |
213 | | - 'action': [ |
214 | | - '<(fortran_compiler)', |
215 | | - '<@(fflags)', |
216 | | - '-fPIC', # generate platform-independent code |
217 | | - '<@(_inputs)', |
218 | | - '-o', |
219 | | - '<@(_outputs)', |
220 | | - ], |
221 | | - } |
222 | | - ], # end condition (OS=="win") |
223 | | - ], # end conditions |
224 | | - }, # end rule (extension=="f") |
225 | | - ], # end rules |
226 | | - }, # end target <(addon_target_name) |
227 | | - |
228 | | - # Target to copy a generated add-on to a standard location: |
229 | | - { |
230 | | - 'target_name': 'copy_addon', |
231 | | - |
232 | | - # Declare that the output of this target is not linked: |
233 | | - 'type': 'none', |
234 | | - |
235 | | - # Define dependencies: |
236 | | - 'dependencies': [ |
237 | | - # Require that the add-on be generated before building this target: |
238 | | - '<(addon_target_name)', |
239 | | - ], |
240 | | - |
241 | | - # Define a list of actions: |
242 | | - 'actions': [ |
243 | | - { |
244 | | - 'action_name': 'copy_addon', |
245 | | - 'message': 'Copying addon...', |
246 | | - |
247 | | - # Explicitly list the inputs in the command-line invocation below: |
248 | | - 'inputs': [], |
249 | | - |
250 | | - # Declare the expected outputs: |
251 | | - 'outputs': [ |
252 | | - '<(addon_output_dir)/<(addon_target_name).node', |
253 | | - ], |
254 | | - |
255 | | - # Define the command-line invocation: |
256 | | - 'action': [ |
257 | | - 'cp', |
258 | | - '<(PRODUCT_DIR)/<(addon_target_name).node', |
259 | | - '<(addon_output_dir)/<(addon_target_name).node', |
260 | | - ], |
261 | | - }, |
262 | | - ], # end actions |
263 | | - }, # end target copy_addon |
264 | | - ], # end targets |
265 | 70 | } |
0 commit comments