From 0e1d50c8f0faba9cf50a2e5c90f5e8e82e90e4b3 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 17 Aug 2020 23:50:52 +0200 Subject: Initial working version --- Makefile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Makefile (limited to 'Makefile') diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f63a25a --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +CC = gcc +CFLAGS = -Wall -Wextra -std=c11 -O2 -g +LDFLAGS = +LDFLAGS_LIB = $(LDFLAGS) -ldl +TARGET = exec-intercept + +OBJDIR = obj +GENDIR = gen + +SOURCES := $(sort $(wildcard *.c) $(GENDIR)/libintercept.so.c) +HEADERS_LIB := $(wildcard lib/*.h) +HEADERS := $(sort $(wildcard *.h) $(HEADERS_LIB) $(GENDIR)/libintercept.so.h) + +.PHONY: all clean + +all: $(TARGET) + +clean: + @echo "Cleaning" + @rm -f $(TARGET) + @rm -rf $(OBJDIR) $(GENDIR) + + +$(OBJDIR)/lib/libintercept.so: lib/libintercept.c $(HEADERS_LIB) + @mkdir -p $(dir $@) + @echo "CCLD -o $@" + @$(CC) $(CFLAGS) -fPIC -shared -o $@ $< $(LDFLAGS_LIB) + +$(GENDIR)/libintercept.so.c: $(OBJDIR)/lib/libintercept.so + @mkdir -p $(dir $@) + @echo "XXD -i $<" + @cd $(dir $<) && xxd -i $(notdir $<) >$(abspath $@) + +$(GENDIR)/libintercept.so.h: $(GENDIR)/libintercept.so.c + @echo "SED -o $@" + @sed -n 's/^\(.*\) =.*/extern \1;/p' $< >$@ + +$(OBJDIR)/%.o: %.c $(HEADERS) | $(OBJDIR) + @mkdir -p $(dir $@) + @echo "CC $<" + @$(CC) $(CFLAGS) -c -o $@ $< + +$(TARGET): $(patsubst %.c,$(OBJDIR)/%.o,$(SOURCES)) | $(OBJDIR) + @echo "LD -o $@" + @$(CC) -o $@ $^ $(LDFLAGS) + +$(OBJDIR): + @mkdir -p $(OBJDIR) -- cgit v1.2.3-70-g09d2