# Makefile for impl VERSION = @VERSION@ # Environment and values saved by the configure script CC = @CC@ CCOM = @CCOM@ AR = @AR@ RANLIB = @RANLIB@ RM = @RM@ INSTALL = @INSTALL@ OPTIMISE = @OPTIMISE@ PREFIX = @PREFIX@ SRCDIR = @SRCDIR@ # Find all .c files in src/ recursively SRCS := $(shell find $(SRCDIR)/src -name '*.c' -type f) # Generate object file names (strip SRCDIR/src/ prefix and change .c to .o) OBJS := $(patsubst $(SRCDIR)/src/%.c,%.o,$(SRCS)) # VPATH for finding source files VPATH = $(SRCDIR)/src:$(shell find $(SRCDIR)/src -type d 2>/dev/null | tr '\n' ':') # Compiler flags COPTFLAGS_gcc_debug = -O0 -g3 -Wall -Wextra COPTFLAGS_gcc_release = -O2 -DNDEBUG COPTFLAGS_clang_debug = -O0 -g3 -Wall -Wextra COPTFLAGS_clang_release = -O2 -DNDEBUG COPTFLAGS = $(COPTFLAGS_$(CCOM)_$(OPTIMISE)) CSTDFLAGS_gcc = -std=c11 -pedantic CSTDFLAGS_clang = -std=c11 -pedantic CSTDFLAGS = $(CSTDFLAGS_$(CCOM)) CFLAGS = $(CSTDFLAGS) $(COPTFLAGS) -I$(SRCDIR)/include -I$(SRCDIR)/thirdparty/utest -I. -DHAVE_CONFIG_H=1 LDFLAGS = # Targets BINARY = impl .PHONY: all clean install check all: $(BINARY) # Create subdirectories for object files if needed $(BINARY): $(OBJS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) # Suffix rule for compiling (uses VPATH to find .c files) .SUFFIXES: .c .o .c.o: @test -d $(dir $@) || mkdir -p $(dir $@) $(CC) $(CFLAGS) -c -o $@ $< clean: $(RM) -f $(BINARY) $(OBJS) $(RM) -f test_main test_main.o find . -type f -name '*.o' -delete 2>/dev/null || true install: $(BINARY) $(INSTALL) -d $(DESTDIR)$(PREFIX)/bin $(INSTALL) -m 755 $(BINARY) $(DESTDIR)$(PREFIX)/bin/ # Test target - links with all objects except main.o TEST_OBJS := $(filter-out main.o,$(OBJS)) check: test_main ./test_main test_main: test_main.o $(TEST_OBJS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ test_main.o: $(SRCDIR)/tests/test_main.c $(SRCDIR)/include/impl/base.h $(CC) $(CFLAGS) -c -o $@ $<