diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-08-17 23:50:52 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-08-17 23:50:52 +0200 |
commit | 0e1d50c8f0faba9cf50a2e5c90f5e8e82e90e4b3 (patch) | |
tree | 018023ea77ecda64dcdb9402076b90ca61909cf0 /Makefile |
Initial working version
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 48 |
1 files changed, 48 insertions, 0 deletions
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) |