ringbuf/Makefile
2024-12-25 14:05:22 +01:00

73 lines
1.6 KiB
Makefile

# 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
CFLAGS += -I.
ifneq ($(RELEASE), 1)
CFLAGS += -g -O0 -std=c99 -march=native -mtune=native
CFLAGS += -DDEBUG
else
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
endif # DEBUG
LDFLAGS = -lm
C_SOURCES = $(wildcard *.c)
C_HEADERS = $(wildcard *.h)
OBJECTS = $(C_SOURCES:.c=.o)
ASMS = $(C_SOURCES:.c=.s)
all: $(OBJECTS)
test: test/test.elf
./test/test.elf
%.o: %.c $(C_HEADERS)
@echo "CC $<"
@$(CC) $(CFLAGS) -c $< -o $@
%.s: %.c $(C_HEADERS)
@echo "CC $<"
@$(CC) $(CFLAGS) -S -masm=intel $<
driver: $(OBJECTS)
@$(CC) $(LDFLAGS) $^ -o $@
run: driver
@./driver
test/test.elf: test/test_ringbuf.o ringbuf.o
@$(CC) $(CFLAGS) $^ -o $@ -lpthread -lcmocka
lib: $(OBJECTS)
@ar rcs librbuf.a ringbuf.o
dylib: $(OBJECTS)
@$(CC) $(LDLAGS) -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 **/*.o **/*.elf
asm: $(ASMS) $(OBJECTS)
wc -l $(ASMS)
size $(OBJECTS)
tidy:
@clang-tidy $(C_SOURCES) -- $(CFLAGS)
format:
clang-format -i $(C_SOURCES) $(C_HEADERS)
.PHONY: all clean format asm test