"What's the proper way to ask macports if it's installed and where to look for libraries/include headers?"

Jim DeLaHunt list+macports-dev at jdlh.com
Sat Mar 26 05:42:13 UTC 2022

On 2022-03-25 20:56, John Douglas Owens via macports-dev wrote:
> Would someone consider answering this on 
> https://github.com/pikepdf/pikepdf/issues/322 
> <https://github.com/pikepdf/pikepdf/issues/322> ? The proximate issue is 
> that pikepdf assumes Homebrew is installed and the install breaks on 
> MacPorts if Homebrew is not installed. The developer would like to fix this!

This is a good question. I am not enough of a MacPorts developer to be 
sure of the answer, but I will take it as an interesting riddle.

My guess: if there is a command `port` on the current path, then
MacPorts is likely installed. `which port` prints the absolute path
to a `port command`:

% which port

So have the program run `which port`.

• case exit code is not 0: MacPorts is not installed.
• case exit code is 0: stdout contains the absolute path to `port`

Then run that path with `version`.
Check that it runs without error, and that the output matches 
'''^Version: \d+\.\d+\.\d+$```. Though this check will be fragile if
MacPorts changes its version output.

The dirname of the dirname of the path returned by `which port` is 
likely to be the prefix which MacPorts is installed. Thus append `/lib` 
and `/include` to that prefix to get the MacPorts lib and include paths.

Is this reasonable, or is it a bad choice for reasons I don't yet know 

Best regards,
     --Jim DeLaHunt

More information about the macports-dev mailing list