Search code examples
makefilegnu-makesolaris

Makefile error: Unexpected EOL seen on Solaris 11.4


Here's the problematic Makefile:

CFLAGS += -std=c11
CFLAGS += -fPIC
CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -Werror
CFLAGS += -Wwrite-strings
CFLAGS += -Wno-unused-variable
CFLAGS += -Wno-parentheses
CFLAGS += -Wpedantic
CFLAGS += -Warray-bounds
CFLAGS += -Wno-unused-function
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wdeprecated

CFLAGS += $(EXTRA_CFLAGS)

TARGET := arena
TEST_TARGET := tests
SLIB_TARGET := libarena.a
DLIB_TARGET := libarena.so

RM := /bin/rm -f

static: $(SLIB_TARGET)

$(SLIB_TARGET): $(TARGET).o
    $(AR) rcs $@ $(TARGET).o

shared: $(DLIB_TARGET)

$(DLIB_TARGET): $(TARGET).o
    $(CC) $(CFLAGS) $(TARGET).o -o $@ $(LDFLAGS) -shared

test: 
    $(MAKE) EXTRA_CFLAGS="-DDEBUG" $(TEST_TARGET)
    ./$(TEST_TARGET) --verbose=3

clean: 
    $(RM) $(TEST_TARGET) $(TARGET).o $(SLIB_TARGET) $(DLIB_TARGET)

.PHONY: release debug static shared test clean
.DELETE_ON_ERROR:

which results in:

make: Fatal error in reader: Makefile, line 18: Unexpected end of line seen

There are multiple duplicates to this question, but they all suggest using gmake instead of make. And whilst that works, I do not wish to use gmake.

Here's the man page for make for Solaris: make

Running with:

make -x SUN_MAKE_COMPAT_MODE=GNU test

outputs the same.


Solution

  • Changing all assignments of the form := to = solves the problem.

    Solaris make documentation defines := as a "conditional macro assignment", whilst the documentation for GNU make defines it as a "Simply Expanded Variable Assignment".