From 0d6337cf68e7fbc8a093cae000955aa93b067f91 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 22 Jan 2024 19:08:14 +0100 Subject: [PATCH] Makefile: Fix for {Net,Free,Open}BSD and generic $CFLAGS in environ - `CFLAGS ?=` inherits from the environment, so shouldn't have -std=c99 - In practice everything but Darwin uses `-shared` - NetBSD and MacOS have a broken CMSG_DATA macro when -D_POSIX_C_SOURCE=200809L is set their bug but probably better to make it work for now, specially in MacOS case --- Makefile | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 2e0a47f..11c1186 100644 --- a/Makefile +++ b/Makefile @@ -3,15 +3,18 @@ calling_from_make: UNAME := $(shell uname) -CFLAGS ?= -Wall -Werror -Wno-unused-parameter -pedantic -std=c99 -O2 +CFLAGS ?= -Wall -Werror -Wextra -Wno-unused-parameter -pedantic -O2 -fPIC ifeq ($(UNAME), Darwin) - TARGET_CFLAGS ?= -fPIC -undefined dynamic_lookup -dynamiclib -Wextra + TARGET_CFLAGS ?= -undefined dynamic_lookup -dynamiclib -Wextra +else + TARGET_CFLAGS ?= -shared + +# c_src/spawner.c fails to compile on NetBSD and Darwin with -D_POSIX_C_SOURCE=200809L +# Meanwhile *-linux-musl needs it +ifneq (${UNAME}, NetBSD) + CFLAGS += -D_POSIX_C_SOURCE=200809L endif - -ifeq ($(UNAME), Linux) - CFLAGS += -D_POSIX_C_SOURCE=200809L - TARGET_CFLAGS ?= -fPIC -shared endif all: priv/exile.so priv/spawner @@ -19,11 +22,11 @@ all: priv/exile.so priv/spawner priv/exile.so: c_src/exile.c mkdir -p priv - $(CC) -I$(ERL_INTERFACE_INCLUDE_DIR) $(TARGET_CFLAGS) $(CFLAGS) c_src/exile.c -o priv/exile.so + $(CC) -std=c99 -I$(ERL_INTERFACE_INCLUDE_DIR) $(TARGET_CFLAGS) $(CFLAGS) c_src/exile.c -o priv/exile.so priv/spawner: c_src/spawner.c mkdir -p priv - $(CC) $(CFLAGS) c_src/spawner.c -o priv/spawner + $(CC) -std=c99 $(CFLAGS) c_src/spawner.c -o priv/spawner clean: @rm -rf priv/exile.so priv/spawner