@@ -62,6 +62,12 @@ include="${INCLUDE}"
6262# Define a list of external source files:
6363source_files=" ${SOURCE_FILES} "
6464
65+ # Define a list of libraries (e.g., `-lopenblas -lpthreads`):
66+ libraries=" ${LIBRARIES} "
67+
68+ # Define a list of library paths (e.g., `-L /foo/bar -L /beep/boop`):
69+ libpath=" ${LIBPATH} "
70+
6571
6672# FUNCTIONS #
6773
@@ -97,9 +103,12 @@ usage() {
97103resolve_includes () {
98104 local includes
99105 local script
106+ local opts
107+
108+ opts=" {'wasm':true}"
100109
101110 # Generate the script for resolving external include directories:
102- script=' "' " var path = require('path'); var arr = require('@stdlib/tools/library-manifest')(path.join('$1 ','manifest.json'),{ },{'basedir':'$1 ','paths':'posix'}).include; var str = ''; for (var i = 0; i < arr.length; i++){var p = path.resolve('$1 ', arr[i]); if (p.indexOf('$1 ') === 0) {continue;}; str += '-I '+p+' ';}; console.log(str.substring(0, str.length-1));" ' "'
111+ script=' "' " var path = require('path'); var arr = require('@stdlib/tools/library-manifest')(path.join('$1 ','manifest.json'),${opts } ,{'basedir':'$1 ','paths':'posix'}).include; var str = ''; for (var i = 0; i < arr.length; i++){var p = path.resolve('$1 ', arr[i]); if (p.indexOf('$1 ') === 0) {continue;}; str += '-I '+p+' ';}; console.log(str.substring(0, str.length-1));" ' "'
103112
104113 # Resolve include directories:
105114 includes=$( eval NODE_PATH=" ${node_path} " " ${node_cmd} " -e " ${script} " )
@@ -113,21 +122,62 @@ resolve_includes() {
113122resolve_source_files () {
114123 local source_files
115124 local script
125+ local opts
126+
127+ opts=" {'wasm':true}"
116128
117129 # Generate the script for resolving external source files:
118- script=' "' " var path = require('path'); var arr = require('@stdlib/tools/library-manifest')(path.join('$1 ','manifest.json'),{ },{'basedir':'$1 ','paths':'posix'}).src; var str = ''; for (var i = 0; i < arr.length; i++){var p = path.resolve('$1 ', arr[i]); if (p.indexOf('$1 ') === 0) {continue;}; str += p+' ';}; console.log(str.substring(0, str.length-1));" ' "'
130+ script=' "' " var path = require('path'); var arr = require('@stdlib/tools/library-manifest')(path.join('$1 ','manifest.json'),${opts } ,{'basedir':'$1 ','paths':'posix'}).src; var str = ''; for (var i = 0; i < arr.length; i++){var p = path.resolve('$1 ', arr[i]); if (p.indexOf('$1 ') === 0) {continue;}; str += p+' ';}; console.log(str.substring(0, str.length-1));" ' "'
119131
120132 # Resolve files:
121133 source_files=$( eval NODE_PATH=" ${node_path} " " ${node_cmd} " -e " ${script} " )
122134
123135 echo " ${source_files} "
124136}
125137
138+ # Resolves libraries.
139+ #
140+ # $1 - package directory
141+ resolve_libraries () {
142+ local libraries
143+ local script
144+ local opts
145+
146+ opts=" {'wasm':true}"
147+
148+ # Generate the script for resolving libraries:
149+ script=' "' " var path = require('path'); var arr = require('@stdlib/tools/library-manifest')(path.join('$1 ','manifest.json'),${opts} ,{'basedir':'$1 ','paths':'posix'}).libraries; var str = ''; for (var i = 0; i < arr.length; i++){str += arr[i]+' ';}; console.log(str.substring(0, str.length-1));" ' "'
150+
151+ # Resolve libraries:
152+ libraries=$( eval NODE_PATH=" ${node_path} " " ${node_cmd} " -e " ${script} " )
153+
154+ echo " ${libraries} "
155+ }
156+
157+ # Resolves library paths.
158+ #
159+ # $1 - package directory
160+ resolve_libpaths () {
161+ local libpath
162+ local script
163+ local opts
164+
165+ opts=" {'wasm':true}"
166+
167+ # Generate the script for resolving library paths:
168+ script=' "' " var path = require('path'); var arr = require('@stdlib/tools/library-manifest')(path.join('$1 ','manifest.json'),${opts} ,{'basedir':'$1 ','paths':'posix'}).libpath; var str = ''; for (var i = 0; i < arr.length; i++){var p = path.resolve('$1 ', arr[i]); str += '-L '+p+' ';}; console.log(str.substring(0, str.length-1));" ' "'
169+
170+ # Resolve library paths:
171+ libpath=$( eval NODE_PATH=" ${node_path} " " ${node_cmd} " -e " ${script} " )
172+
173+ echo " ${libpath} "
174+ }
175+
126176# Compiles WebAssembly.
127177#
128178# $1 - source directory
129179compile () {
130- cd " $1 " && EMCC_COMPILER=" ${emcc_compiler} " WASM2WAT=" ${wasm_to_wat} " INCLUDE=" ${include} " SOURCE_FILES=" ${source_files} " make wasm 2>&1
180+ cd " $1 " && EMCC_COMPILER=" ${emcc_compiler} " WASM2WAT=" ${wasm_to_wat} " INCLUDE=" ${include} " SOURCE_FILES=" ${source_files} " LIBRARIES= " ${libraries} " LIBPATH= " ${libpath} " make wasm 2>&1
131181 if [[ " $? " -ne 0 ]]; then
132182 echo ' Error when attempting to compile WebAssembly.' >&2
133183 return 1
@@ -157,6 +207,20 @@ main() {
157207 on_error 1
158208 fi
159209 fi
210+ if [[ -z " ${libraries} " ]]; then
211+ echo ' Resolving libraries...' >&2
212+ libraries=$( resolve_libraries " ${pkg_path} " )
213+ if [[ " $? " -ne 0 ]]; then
214+ on_error 1
215+ fi
216+ fi
217+ if [[ -z " ${libpath} " ]]; then
218+ echo ' Resolving library paths...' >&2
219+ libpath=$( resolve_libpaths " ${pkg_path} " )
220+ if [[ " $? " -ne 0 ]]; then
221+ on_error 1
222+ fi
223+ fi
160224 echo ' Compiling WebAssembly...' >&2
161225 compile " ${src_dir} "
162226 if [[ " $? " -ne 0 ]]; then
0 commit comments