CC ?= gcc

# Hardening flags for the interworx-c-helpers wrappers (process-runner,
# decoder). The legacy binaries above build with plain
# cc/g++ and are left as-is.
HELPER_CFLAGS  := -std=c99 -O2 -Wall -Wextra -Werror -Wformat -Wformat-security \
           -D_FORTIFY_SOURCE=2 -fPIE
HELPER_LDFLAGS := -pie -Wl,-z,relro,-z,now

# Prefer -fstack-protector-strong (distro security default; matches
# Fedora/RHEL hardened-rpm-config convention). Fall back to
# -fstack-protector-all on EL7's gcc 4.8.5, which predates -strong
# (added in gcc 4.9). -all costs marginally more cycles per function
# call than -strong but the difference is invisible at this binary's
# scale, and -all provides stronger coverage.
STACK_PROTECTOR := $(shell $(CC) -fstack-protector-strong -x c -E - </dev/null > /dev/null 2>&1 \
    && echo -fstack-protector-strong || echo -fstack-protector-all)
HELPER_CFLAGS += $(STACK_PROTECTOR)

all: fileman setvacation check-session repgrace iw-bw-logger process-runner decoder

fileman: fileman.src.c
	cc fileman.src.c -o fileman

setvacation: setvacation.c
	cc setvacation.c -o setvacation

check-session: check-session.c
	cc check-session.c -o check-session

repgrace: repgrace.c
	g++ repgrace.c -o repgrace

iw-bw-logger: iw-bw-logger.cpp
	g++ iw-bw-logger.cpp -o iw-bw-logger

process-runner: process-runner.c
	$(CC) $(HELPER_CFLAGS) $(HELPER_LDFLAGS) -o $@ $<

decoder: decoder.c
	$(CC) $(HELPER_CFLAGS) $(HELPER_LDFLAGS) -o $@ $<

clean:
	rm -rf fileman setvacation check-session repgrace iw-bw-logger process-runner decoder

