Skip to content

Commit 2a2210e

Browse files
committed
fix: build script for macOS development
1 parent 075f404 commit 2a2210e

File tree

1 file changed

+59
-27
lines changed

1 file changed

+59
-27
lines changed

scripts/build.sh

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -246,20 +246,37 @@ function run_package_std() {
246246
cp "$rel_dir/"*.a "$lib_dir" 2>/dev/null || log "$rel_dir does not contain *.a files"
247247
# Create an SO file from the copied a file
248248
log "Creating a shared library from the compiled static library"
249-
log "Running : $cc --shared -L$lib_dir \
250-
-Wl,--whole-archive -liec61131std \
251-
-o $lib_dir/out.so -Wl,--no-whole-archive \
252-
-lm \
253-
-fuse-ld=lld \
254-
--target=$val"
255-
$cc --shared -L"$lib_dir" \
256-
-Wl,--whole-archive -liec61131std \
257-
-o "$lib_dir/out.so" -Wl,--no-whole-archive \
258-
-lm \
259-
-fuse-ld=lld \
260-
--target="$val"
261-
262-
mv "$lib_dir/out.so" "$lib_dir/libiec61131std.so"
249+
# Check if we're on macOS and adjust linker flags accordingly
250+
unameOut="$(uname -s)"
251+
case "${unameOut}" in
252+
Darwin*)
253+
log "Running : $cc --shared -L$lib_dir \
254+
-Wl,-force_load,$lib_dir/libiec61131std.a \
255+
-o $lib_dir/libiec61131std.so \
256+
-lm -framework CoreFoundation \
257+
--target=$val"
258+
$cc --shared -L"$lib_dir" \
259+
-Wl,-force_load,"$lib_dir/libiec61131std.a" \
260+
-o "$lib_dir/libiec61131std.so" \
261+
-lm -framework CoreFoundation \
262+
--target="$val"
263+
;;
264+
*)
265+
log "Running : $cc --shared -L$lib_dir \
266+
-Wl,--whole-archive -liec61131std \
267+
-o $lib_dir/libiec61131std.so -Wl,--no-whole-archive \
268+
-lm \
269+
-fuse-ld=lld \
270+
--target=$val"
271+
$cc --shared -L"$lib_dir" \
272+
-Wl,--whole-archive -liec61131std \
273+
-o "$lib_dir/libiec61131std.so" -Wl,--no-whole-archive \
274+
-lm \
275+
-fuse-ld=lld \
276+
--target="$val"
277+
;;
278+
esac
279+
263280
done
264281
else
265282
lib_dir=$OUTPUT_DIR/lib
@@ -272,21 +289,36 @@ function run_package_std() {
272289
cp "$rel_dir/"*.a "$lib_dir" 2>/dev/null || log "$rel_dir does not contain *.a files"
273290
# Create an SO file from the copied a file
274291
log "Creating a shared library from the compiled static library"
275-
log "Running : $cc --shared -L"$lib_dir" \
276-
-Wl,--whole-archive -liec61131std \
277-
-o "$lib_dir/out.so" -Wl,--no-whole-archive \
278-
-lm \
279-
-fuse-ld=lld "
280-
$cc --shared -L"$lib_dir" \
281-
-Wl,--whole-archive -liec61131std \
282-
-o "$lib_dir/out.so" -Wl,--no-whole-archive \
283-
-lm \
284-
-fuse-ld=lld
285-
mv "$lib_dir/out.so" "$lib_dir/libiec61131std.so"
292+
# Check if we're on macOS and adjust linker flags accordingly
293+
unameOut="$(uname -s)"
294+
case "${unameOut}" in
295+
Darwin*)
296+
log "Running : $cc --shared -L"$lib_dir" \
297+
-Wl,-force_load,$lib_dir/libiec61131std.a \
298+
-o "$lib_dir/libiec61131std.so" \
299+
-lm -framework CoreFoundation"
300+
$cc --shared -L"$lib_dir" \
301+
-Wl,-force_load,"$lib_dir/libiec61131std.a" \
302+
-o "$lib_dir/libiec61131std.so" \
303+
-lm -framework CoreFoundation
304+
;;
305+
*)
306+
log "Running : $cc --shared -L"$lib_dir" \
307+
-Wl,--whole-archive -liec61131std \
308+
-o "$lib_dir/libiec61131std.so" -Wl,--no-whole-archive \
309+
-lm \
310+
-fuse-ld=lld "
311+
$cc --shared -L"$lib_dir" \
312+
-Wl,--whole-archive -liec61131std \
313+
-o "$lib_dir/libiec61131std.so" -Wl,--no-whole-archive \
314+
-lm \
315+
-fuse-ld=lld
316+
;;
317+
esac
286318
fi
287319

288320
log "Enabling read/write on the output folder"
289-
chmod a+rw $OUTPUT_DIR -R
321+
chmod -R a+rw $OUTPUT_DIR
290322

291323
}
292324

@@ -506,7 +538,7 @@ fi
506538

507539
if [[ -d $project_location/target/ ]]; then
508540
log "Allow access to target folders"
509-
chmod a+rw -R $project_location/target/
541+
chmod -R a+rw $project_location/target/
510542
fi
511543

512544
if [[ $offline -ne 0 ]]; then

0 commit comments

Comments
 (0)