CC = LC_ALL=C gcc
CFLAGS += -std=c99 -D_POSIX_SOURCE
CFLAGS += -Wall -Wextra -Werror -Wconversion -Wsign-conversion -Wformat-security -pedantic
CFLAGS += -D_FORTIFY_SOURCE=2 -fstack-protector-all -Wstack-protector -fPIE
CFLAGS += -mtune=generic -O2
LFLAGS += -Wl,-z,relro,-z,now -pie
LFLAGS += -static
TARGETS ?= dinit dcrond
SOURCES ?= $(wildcard *.c)
PREFIX ?= /usr/local
.PHONY: all
all: $(TARGETS)
dcrond: dcrond.o
dinit: dinit.o
dinit dcrond:
$(CC) -o $(@) $(^) $(LFLAGS)
@which checksec >/dev/null 2>&1 && checksec --format=cli --file=$(@) || true
%.o: %.c Makefile
$(CC) $(CFLAGS) -o $(@) -c $(<)
.PHONY: install
install: $(TARGETS)
@install --strip -v -t "$(DESTDIR)$(PREFIX)/bin" $(^)
.PHONY: check
check: $(SOURCES)
clang-tidy --quiet --warnings-as-errors='*' --checks='cert-*,bugprone-*,clang-analyzer-*,misc-*,-bugprone-easily-swappable-parameters,-bugprone-branch-clone' $(^) -- $(CFLAGS)
clang-format --dry-run -Werror -style='{BasedOnStyle: Google, IndentWidth: 4, TabWidth: 4, ColumnLimit: 120, MaxEmptyLinesToKeep: 2, SpacesBeforeTrailingComments: 1}' -- $(^)
.PHONY: clean
clean:
@rm -vf -- dinit dcrond $(wildcard *.o)