Skip to content

Commit

Permalink
Makefile: Fix for {Net,Free,Open}BSD and generic $CFLAGS in environ
Browse files Browse the repository at this point in the history
- `CFLAGS ?=` inherits from the environment, so shouldn't have -std=c99
- In practice everything but Darwin uses `-shared`
- NetBSD has a broken CMSG_DATA macro when -D_POSIX_C_SOURCE=200809L is set
their bug but probably better to make it work for now
  • Loading branch information
lanodan committed Jan 22, 2024
1 parent 71a21be commit f8d5812
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@ 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
# c_src/spawner.c fails to compile on NetBSD with -D_POSIX_C_SOURCE=200809L
# Meanwhile *-linux-gnu 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
ifeq ($(UNAME), Darwin)
TARGET_CFLAGS ?= -undefined dynamic_lookup -dynamiclib -Wextra
else
TARGET_CFLAGS ?= -shared
endif

all: priv/exile.so priv/spawner
@echo > /dev/null

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

0 comments on commit f8d5812

Please sign in to comment.