forked from cs50/libcs50
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
147 lines (126 loc) · 3.88 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
VERSION := 10.1.3
MAJOR_VERSION := $(shell echo $(VERSION) | cut -d'.' -f1)
# installation directory (/usr/local by default)
DESTDIR ?= /usr/local
MANDIR ?= share/man/man3
SRC := src/cs50.c
INCLUDE := src/cs50.h
MANS := $(wildcard docs/*.3.gz)
CFLAGS=-Wall -Wextra -Werror -pedantic -std=c11
BASENAME=libcs50
LIB_STATIC=$(BASENAME).a
LIB_OBJ=$(BASENAME).o
OS := $(shell uname)
# Linux
ifeq ($(OS),Linux)
LIB_BASE := $(BASENAME).so
LIB_MAJOR := $(BASENAME).so.$(MAJOR_VERSION)
LIB_VERSION := $(BASENAME).so.$(VERSION)
LINKER_FLAGS := -Wl,-soname,$(LIB_MAJOR)
# Mac
else ifeq ($(OS),Darwin)
LIB_BASE := $(BASENAME).dylib
LIB_MAJOR := $(BASENAME)-$(MAJOR_VERSION).dylib
LIB_VERSION := $(BASENAME)-$(VERSION).dylib
LINKER_FLAGS := -Wl,-install_name,$(LIB_VERSION)
endif
LIBS := $(addprefix build/lib/, $(LIB_BASE) $(LIB_MAJOR) $(LIB_VERSION))
.PHONY: all
all: $(LIBS) $(MANS)
$(LIBS): $(SRC) $(INCLUDE) Makefile
$(CC) $(CFLAGS) -fPIC -shared $(LINKER_FLAGS) -o $(LIB_VERSION) $(SRC)
$(CC) $(CFLAGS) -c -o $(LIB_OBJ) $(SRC)
ar rcs $(LIB_STATIC) $(LIB_OBJ)
chmod 644 $(LIB_STATIC)
rm -f $(LIB_OBJ)
ln -sf $(LIB_VERSION) $(LIB_BASE)
mkdir -p $(addprefix build/, include lib src)
install -m 644 $(SRC) build/src
install -m 644 $(INCLUDE) build/include
mv $(LIB_VERSION) $(LIB_BASE) $(LIB_STATIC) build/lib
build/lib/$(LIB_BASE): build/lib/$(LIB_MAJOR)
build/lib/$(LIB_MAJOR): build/lib/$(LIB_VERSION)
.PHONY: install
install: all
mkdir -p $(addprefix $(DESTDIR)/, src lib include $(MANDIR))
cp -R $(filter-out deb, $(wildcard build/*)) $(DESTDIR)
cp -R $(MANS) $(DESTDIR)/$(MANDIR)
ifeq ($(OS),Linux)
ldconfig $(DESTDIR)/lib
endif
.PHONY: clean
clean:
rm -rf build
.PHONY: deb
deb: $(LIBS) $(MANS)
rm -rf build/deb
# temporary fpm source
mkdir -p build/deb/$(BASENAME)/usr
cp -r $(addprefix build/, include lib src) build/deb/$(BASENAME)/usr
mkdir -p build/deb/$(BASENAME)/usr/share/man/man3
chmod 755 build/deb/$(BASENAME)/usr/share/man/man3
cp -r $(MANS) build/deb/$(BASENAME)/usr/share/man/man3
chmod 644 build/deb/$(BASENAME)/usr/share/man/man3/*
fpm \
--after-install postinst \
--after-remove postrm \
--category libs \
--chdir build/deb/$(BASENAME) \
--conflicts lib50-c \
--conflicts $(BASENAME) \
--conflicts library50-c \
--deb-no-default-config-files \
--deb-priority optional \
--description "CS50 library for C" \
--input-type dir \
--license "MIT" \
--maintainer "CS50 <[email protected]>" \
--name $(BASENAME) \
--output-type deb \
--package build/deb \
--provides lib50-c \
--provides $(BASENAME) \
--provides library50-c \
--replaces lib50-c \
--replaces $(BASENAME) \
--replaces library50-c \
--url https://github.com/cs50/libcs50 \
--vendor CS50 \
--version $(VERSION) \
.
rm -rf build/deb/$(BASENAME)
rpm: $(LIBS) $(MANS)
rm -rf build/rpm
# Temporary fpm source
mkdir -p build/rpm/$(BASENAME)/usr
cp -r $(addprefix build/, include lib src) build/rpm/$(BASENAME)/usr
mkdir -p build/rpm/$(BASENAME)/usr/share/man/man3
cp -r $(MANS) build/rpm/$(BASENAME)/usr/share/man/man3
fpm \
--after-install post \
--after-remove postun \
--category libs \
--chdir build/rpm/$(BASENAME) \
--description "CS50 library for C" \
--input-type dir \
--license "MIT" \
--maintainer "CS50 <[email protected]>" \
--name $(BASENAME) \
--output-type rpm \
--package build/rpm \
--provides $(BASENAME) \
--url https://github.com/cs50/libcs50 \
--vendor CS50 \
--version $(VERSION) \
.
rm -rf build/rpm/$(BASENAME)
# Used by .travis.yml
.PHONY: version
version:
@echo $(VERSION)
.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)/include/cs50.h
rm -rf $(DESTDIR)/src/cs50.c
rm -f $(addprefix $(DESTDIR)/lib/, $(LIB_BASE) $(LIB_MAJOR) $(LIB_VERSION))
rm -f $(addprefix $(DESTDIR)/$(MANDIR)/, get_*.3)