# SPDX-License-Identifier: MIT CC = gcc CFLAGS = -Wall -Wextra -Werror -Wno-unused-parameter CFLAGS += -Wno-unused-variable -Wno-unused-function CFLAGS += -Wno-unused-but-set-variable -Wno-unused-value -Wno-unused-label CFLAGS += -Wno-unused-result -Wno-unused-const-variable ifneq ($(DEBUG), 1) CFLAGS += -fno-exceptions -fno-asynchronous-unwind-tables -fno-ident CFLAGS += -fno-unwind-tables -fno-stack-protector -fno-plt -fno-pic CFLAGS += -O3 -std=c99 -march=native -mtune=native -fomit-frame-pointer CFLAGS += -fshort-enums else CFLAGS += -g -O0 -std=c99 -march=native -mtune=native CFLAGS += -DDEBUG endif # Include debug flags CFLAGS += -g -O0 -std=c99 -march=native -mtune=native C_SOURCES = $(wildcard *.c) C_HEADERS = $(wildcard *.h) OBJECTS = $(C_SOURCES:.c=.o) ASMS = $(C_SOURCES:.c=.s) all: $(OBJECTS) %.o: %.c $(C_HEADERS) @echo "CC $<" @$(CC) $(CFLAGS) -c $< -o $@ %.s: %.c $(C_HEADERS) @echo "CC $<" @$(CC) $(CFLAGS) -S -masm=intel $< driver: $(OBJECTS) @$(CC) $(CFLAGS) $^ -o $@ run: driver @./driver lib: $(OBJECTS) @ar rcs librbuf.a ringbuf.o dylib: $(OBJECTS) @$(CC) $(CFLAGS) -fPIC -shared -o librbuf.so ringbuf.o install: @cp librbuf.a /usr/local/lib @cp ringbuf.h /usr/local/include clean: rm -f $(OBJECTS) $(ASMS) driver librbuf.a librbuf.so asm: $(ASMS) $(OBJECTS) wc -l $(ASMS) size $(OBJECTS) format: clang-format -i $(C_SOURCES) $(C_HEADERS) .PHONY: all clean format asm