Search code examples
makefilefreebsd

Makefile .for and .if expansion


I'm wanting to run a Makefile with

.if "${WITH_DOT}" != "0"
VIS+=       day21.dot day21.pdf
.endif

but I'm getting

Makefile:17: *** missing separator.  Stop.

The only link I could find was https://lists.freebsd.org/pipermail/freebsd-hackers/2005-February/010281.html

Why isn't this working? How do I run this?

$ make --version
GNU Make 4.2.1

Solution

  • Your example is part of (Free)BSD Make's syntax. The GNU Make's syntax differs, see here:

    libs_for_gcc = -lgnu
    normal_libs =
    
    foo: $(objects)
    ifeq ($(CC),gcc)
            $(CC) -o foo $(objects) $(libs_for_gcc)
    else
            $(CC) -o foo $(objects) $(normal_libs)
    endif
    

    You can check FreeBSD's make manual page here (scroll down a little for .if). If you want use this make I think you should install bmake or bsdmake package.

    The loops, conditionals aren't part of POSIX so these features can be differ (if exists) in different make-variations.