blob: f63a25a9510b9acd4611b6ab14f74f55ac094102 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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)
|