aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile48
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)