Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOWTO: Build tweaks for macOS and FreeBSD #4

Open
modest opened this issue May 10, 2024 · 0 comments
Open

HOWTO: Build tweaks for macOS and FreeBSD #4

modest opened this issue May 10, 2024 · 0 comments

Comments

@modest
Copy link

modest commented May 10, 2024

Putting this into a PR would require some opinions about the right way to handle multi-platform. So I'll just share the build steps that seemed necessary to get this to compile on macOS and FreeBSD.

(My FreeBSD target was a router running pfSense, a gateway/firewall.)

macOS

macOS only needs Makefile changes.

./src/Makefile

PROGNAME = repeater
SRC = repeater.c parseconfig.c json.c

OBJS = $(patsubst %.c,%.o,$(SRC))

CC = gcc
CFLAGS = -Wall -Werror -std=c99 -I../include -D_POSIX_SOURCE

build-release: $(OBJS)
        echo "$(OBJS)"
        mkdir -p ../bin
        $(CC) $(CFLAGS) -o ../bin/$(PROGNAME) $(OBJS) -lm

build-debug: CFLAGS += -g -DDEBUG
build-debug: $(OBJS)
        mkdir -p ../bin
        $(CC) $(CFLAGS) -o ../bin/$(PROGNAME) $(OBJS) -lm

%.o: %.c ../include/%.h
        $(CC) $(CFLAGS) -c $<

clean:
        rm -f ./*.o
        rm -rf ../bin
  • macOS gcc (which is really clang) takes -pedantic more seriously than gcc and had complaints, so that argument is removed.
  • clang also didn't like -lm being used in the initial compile, so it's been removed there (but remains in linking)

FreeBSD

FreeBSD needs Makefile tweaks and adding a couple of missing headers.

./src/Makefile

PROGNAME = repeater
SRC = repeater.c parseconfig.c json.c
OBJS = repeater.o parseconfig.o json.o

CC = cc
CFLAGS = -Wall -Werror -std=c99 -pedantic -I../include -D_POSIX_SOURCE

build-release: $(OBJS)
        mkdir -p ../bin
        $(CC) $(CFLAGS) -o ../bin/$(PROGNAME) $(OBJS) -lm

build-debug: CFLAGS += -g -DDEBUG
build-debug: $(OBJS)
        mkdir -p ../bin
        $(CC) $(CFLAGS) -o ../bin/$(PROGNAME) $(OBJS) -lm

%.o: %.c ../include/%.h
        $(CC) $(CFLAGS) -c $< -lm

clean:
        rm -f ./*.o
        rm -rf ../bin
  • CC set to cc for FreeBSD
  • OBJS changed to an string list instead of being generated. BSD make didn't like the patsubst, and didn't bother trying to find out why.

./src/repeater.c

Needs these headers added:

#include <sys/socket.h>
#include <netinet/in.h>

./src/parseconfig.c

Needs this header added:

#include <sys/socket.h>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant