-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
74 lines (50 loc) · 1.3 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
66
67
68
69
70
71
72
73
74
CC = gcc
CFLAGS = -Wall -Wextra -std=c11 -fwrapv -fPIC
ifdef DEBUG
CFLAGS += -g
else
CFLAGS += -O2
endif
# Set to /usr/local to install in the system directories
PREFIX = $(HOME)/prefix
# ---------------------------------------------------------
ifeq ($(PREFIX),)
PREFIX = /usr/local
endif
SRC_FILES = $(wildcard *.c)
HEADER_FILES = $(wildcard *.h)
OBJECT_FILES = $(patsubst %.c,%.o,$(SRC_FILES))
UNAME = $(shell uname)
ifeq ($(UNAME),Darwin)
DYLIB_EXT = dylib
DYLIB_FLAGS = -dynamiclib -install_name '$(PREFIX)/lib/libtermio.$(DYLIB_EXT)'
else
DYLIB_EXT = so
DYLIB_FLAGS = -shared
endif
# Don't remove intermediate files
.SECONDARY:
.PHONY: all clean install uninstall remake reinstall dynamiclib staticlib
all: dynamiclib staticlib
clean:
rm -f *.$(DYLIB_EXT) *.a *.o
install: all
install libtermio.$(DYLIB_EXT) $(PREFIX)/lib
install libtermio.a $(PREFIX)/lib
install termio.h $(PREFIX)/include
uninstall:
rm -f $(PREFIX)/lib/libtermio.$(DYLIB_EXT)
rm -f $(PREFIX)/lib/libtermio.a
rm -f $(PREFIX)/include/termio.h
remake: clean
$(MAKE) all
reinstall: clean
$(MAKE) install
dynamiclib: libtermio.$(DYLIB_EXT)
staticlib: libtermio.a
%.o: %.c $(HEADER_FILES)
$(CC) $(CFLAGS) -c -o $@ $<
%.$(DYLIB_EXT): $(OBJECT_FILES)
$(CC) $(CFLAGS) $(DYLIB_FLAGS) -o $@ $^
%.a: $(OBJECT_FILES)
ar -cr $@ $^