aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: bd9b847e7322f6182b2d7597d03db5852a92b4bf (plain) (blame)
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
PREFIX = /usr
LIB = /lib
INCLUDE = /include

OPTIONS = 
# PASSPHRASE_ECHO:    Do not hide the passphrase
# PASSPHRASE_STAR:    Use '*' for each character instead of no echo
# PASSPHRASE_REALLOC: Soften security by using `realloc`

OPTIMISE = -Os
CPPFLAGS = $(foreach D, $(OPTIONS), -D'$(D)=1')
CFLAGS = -std=c99 -Wall -Wextra -fPIC
LDFLAGS = -shared

CC_FLAGS = $(CPPFLAGS) $(CFLAGS) $(OPTIMISE)
LD_FLAGS = $(LDFLAGS) $(CFLAGS) $(OPTIMISE)

SRC = passphrase
OBJ = $(foreach S, $(SRC), obj/$(S).o)


.PHONY: all
all: bin/libpassphrase.so


bin/libpassphrase.so: $(OBJ)
	@mkdir -p bin
	$(CC) $(LD_FLAGS) -o "$@" $^

obj/%.o: src/%.c src/%.h
	@mkdir -p "$(shell dirname "$@")"
	$(CC) $(CC_FLAGS) -o "$@" -c "$<"


.PHONY: install
install: bin/libpassphrase.so
	install -dm755 -- "$(DESTDIR)$(PREFIX)$(LIB)"
	install -dm755 -- "$(DESTDIR)$(PREFIX)$(INCLUDE)"
	install -m755 -- bin/libpassphrase.so "$(DESTDIR)$(PREFIX)$(LIB)"
	install -m755 -- src/passphrase.h "$(DESTDIR)$(PREFIX)$(INCLUDE)"


.PHONY: uninstall
uninstall:
	-rm -- "$(DESTDIR)$(PREFIX)$(LIB)/libpassphrase.so"
	-rm -- "$(DESTDIR)$(PREFIX)$(INCLUDE)/passphrase.h"


.PHONY: clean
clean:
	-rm -r bin obj