Skip to content

Fix build on macOS#24

Open
Rangi42 wants to merge 2 commits intoaaaaaa123456789:masterfrom
Rangi42:macos
Open

Fix build on macOS#24
Rangi42 wants to merge 2 commits intoaaaaaa123456789:masterfrom
Rangi42:macos

Conversation

@Rangi42
Copy link
Contributor

@Rangi42 Rangi42 commented Sep 24, 2025

Fixes #16
Closes #17

To recap: macOS (and to a lesser extend BSD) has some out-of-the-box limitations that prevent a simple make command from building this repo for me.

  • /bin/bash is version 3.2.57 from 2007, which did not support declare -A.
    • Solution: use /usr/bin/env bash, which detects the newer Bash shell installed by Homebrew or MacPorts.
  • gcc and cc are links to clang, which does not support -Wl,--gc-sections.
    • Solution: check the OS with $(shell uname -s) and only add that to CFLAGS if it's not macOS. (If uname does not exist, assume Windows, or at least assume "not macOS with the system compiler".)
    • Better solution: do a test run of the compiler with $(shell $(CC) -Wl,--gc-sections ...), and only add that to CFLAGS if it succeeds. (Source: StackOverflow)
  • $(shell) is a GNU make feature, not supported by BSD make.
    • Solution: require GNU make (installed as gmake from Homebrew or MacPorts, also commonly installed as gmake on BSD) and rename Makefile to GNUmakefile to indicate this dependency.
  • realpath was not available on macOS until version 13 Ventura, and my hardware can't upgrade past 11.7 Big Sur.
    • Solution: if grealpath (another GNU utility commonly installed from Homebrew or MacPorts) exists, use that instead.

This also fixes a couple of things that shellcheck complained about in merge.sh:

  • local file="`realpath "$1"`"
    • SC2155 (warning): Declare and assign separately to avoid masking return values.
    • SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
  • [[ ! -n ${files[$file]} ]] || return 0
    • SC2236 (style): Use -z instead of ! -n.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

merge.sh fails on macOS

1 participant