macOS symbol/conditional for Makefiles (porting)

Richard L. Hamilton rlhamil at smart.net
Mon Dec 28 14:24:04 UTC 2020


The following script will show you the predefined symbols.
#! /bin/sh
EMPTY_FILE="${TMPDIR:-/tmp}/t$$.c"
rm -f "${EMPTY_FILE}"
touch "${EMPTY_FILE}"
clang ${1+"${@}"} -E -dM "${EMPTY_FILE}"
rm -f "${EMPTY_FILE}"

You can change clang to gcc,  or to the full path of either, and it will show you for that particular compiler. Anything on the command line when running the script will be expected to be additional compiler options, if you're trying to simulate some particular usage.

__APPLE__ and __MACH__ are predefined. That's what I usually use, since that effectively implies macOS (or iOS, iPadOS, etc, as far as that goes; not sure how to tell them apart); i.e.

#if defined(__APPLE__) && defined(__MACH__)


note: /opt/local/whatever isn't just macOS, it's typically macOS plus MacPorts. Clearly a compiler won't predefine something for MacPorts. I don't know if there's a convention that other MacPorts Portfile creators are using for a -DSOME_NAME to pass on compile lines to identify MacPorts-specific code in an executable. Probably not; a lot of things (but not everything) use configure scripts, that have their own approach; typically an option to configure that looks like --includedir=DIR

However, I would imagine (but haven't checked) that the MacPorts port compilers might have been tweaked to know about /opt/local/include etc, and might not need to be told to use it. For best practices advice in the situation, you probably would do best with someone who has created Portfiles before that may have had to deal with such issues.

> On Dec 28, 2020, at 07:12, Christoph Kukulies <kuku at kukulies.org> wrote:
> 
> I’m trying to compile a package „blackmagic“ (a microcontroller gdb debugging and flashing program addendum to gdb).
> 
> It has some issues like missing packages (libftdi1 - I was able to add that via macports)
> 
> Now I want to add some condional in the Makefile like this:
> 
> ifdef macOS
> 
> CFLAGS += -I/opt/local/include
> 
> endif
> 
> Only, macOS isn’t just the variable that works. Does macOS supply any built-in variable for building that if block?
> 
> Christoph
> 
> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2814 bytes
Desc: not available
URL: <http://lists.macports.org/pipermail/macports-users/attachments/20201228/48e0b726/attachment.bin>


More information about the macports-users mailing list