-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
65 lines (49 loc) · 1.53 KB
/
makefile
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
CC ?= cc
PREFIX := /usr
LIBDIR := $(PREFIX)/lib
BUILDDIR := build
CFLAGS := -std=c17 -Werror -Wextra -O3 \
-march=native -fomit-frame-pointer -funroll-loops
LDFLAGS := -fpic -flto
CP := cp -f
ECHO := @echo
NAME := mleak
DESCRIPTION := Library for catching memory leaks, double-frees along with invalid pointers to free\(\) and realloc\(\).
VERSION := 0.1.1
SOURCE := src/mleak.c
HEADER := src/mleak.h
OBJECT := $(BUILDDIR)/mleak.o
STATIC := $(BUILDDIR)/libmleak.a
SHARED := $(BUILDDIR)/libmleak.so
PKGCFG := $(BUILDDIR)/libmleak.pc
all: $(SHARED) $(STATIC) $(PKGCFG)
$(OBJECT): $(BUILDDIR) $(SOURCE) $(HEADER)
$(CC) $(LDFLAGS) $(CFLAGS) $(SOURCE) -c -o $@
$(SHARED): $(OBJECT)
$(CC) $(LDFLAGS) $(OBJECT) -shared -o $@
$(STATIC): $(OBJECT)
ar rcs $@ $(OBJECT)
$(PKGCFG):
$(ECHO) prefix=$(PREFIX) > $(PKGCFG)
$(ECHO) libdir=$$\{prefix\}/$(notdir $(LIBDIR)) >> $(PKGCFG)
$(ECHO) Name: $(NAME) >> $(PKGCFG)
$(ECHO) Description: $(DESCRIPTION) >> $(PKGCFG)
$(ECHO) Version: $(VERSION) >> $(PKGCFG)
$(ECHO) Libs: -L$$\{libdir\} -lmleak >> $(PKGCFG)
$(BUILDDIR):
$(RM) $(BUILDDIR)
mkdir -p $(BUILDDIR)
install: $(SHARED) $(STATIC) $(PKGCFG)
$(CP) $(PKGCFG) $(LIBDIR)/pkgconfig
$(CP) $(SHARED) $(LIBDIR)
$(CP) $(STATIC) $(LIBDIR)
uninstall:
$(RM) $(LIBDIR)/$(notdir $(SHARED))
$(RM) $(LIBDIR)/$(notdir $(STATIC))
$(RM) $(LIBDIR)/pkgconfig/$(notdir $(PKGCFG))
clean:
$(RM) -r $(BUILDDIR)
$(RM) compile_flags.txt
compile_flags.txt:
$(ECHO) $(CFLAGS) | tr " " "\n" > compile_flags.txt
.PHONY: install uninstall clean compile_flags.txt