-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
53 lines (41 loc) · 916 Bytes
/
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
CC := gcc
CFLAGS := -Iinclude -Wall -Wextra -Werror -pedantic
RM := rm -vf
EXEC := hello
OBJS := hello.o main.o
INCL := hello.h
SHLIB := libhello.so
PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib
INCLDIR ?= $(PREFIX)/include
.PHONY: all
all: $(SHLIB) $(EXEC)
%.o: src/%.c
$(CC) -c $< -o $@ -fPIC $(CFLAGS)
$(SHLIB): hello.o
$(CC) $< -o $@ -shared $(CFLAGS)
$(EXEC): main.o $(SHLIB)
$(CC) $< -o $@ -L. -lhello $(CFLAGS)
.PHONY: lib
lib: $(SHLIB)
.PHONY: lib-install
lib-install: lib
install -m 0755 $(SHLIB) $(LIBDIR)
install -m 0644 $(INCL) $(INCLDIR)
.PHONY: test
test: lib
cd test && \
cmake -S . -B _build && \
make -C _build && \
./_build/hello_test
.PHONY: lib-uninstall
lib-uninstall:
@$(RM) $(LIBDIR)/$(SHLIB)
@$(RM) $(INCLDIR)/$(INCL)
.PHONY: clean
clean:
@$(RM) $(OBJS)
@$(RM) -r test/_build
.PHONY: mrproper
mrproper: clean
@$(RM) $(SHLIB) $(EXEC)