-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathMakefile
72 lines (60 loc) · 2.1 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
BIN_DIR := bin
OBJ_DIR := obj
SRC_DIR := src
CC := gcc
CPP := g++
CFLAGS := -O2 -fPIC -fno-stack-protector
OS := $(shell uname)
ifeq ($(OS),Darwin)
# for M1 machines with Rosetta homebrew in /opt
PKG_CONFIG_PATH = "$(shell echo $$PKG_CONFIG_PATH):/opt/homebrew/opt/openssl/lib/pkgconfig"
PC_LIBS := $(shell env PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --libs openssl)
PC_INCLUDES := $(shell env PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --cflags openssl)
SDK_PATH := /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
SDK_LIBS := -L$(SDK_PATH) -lSystem
LDLIB := -lpam -lSystem -L$(SDK_PATH)/usr/lib $(PC_LIBS)
LDINCLUDE := -I$(SDK_PATH)/usr/include $(PC_INCLUDES)
LDFLAGS := -x -dylib
# otherwise stdlib.h has hundreds of warnings...
CFLAGS := $(CFLAGS) -Wno-nullability-completeness -Wno-pointer-sign
PAM_DIR := /usr/local/lib/pam
else
LDLIB := -lpam -lpam_misc -lssl -lcrypto -lc
LDFLAGS := -x -shared
PAM_DIR := /lib/security
endif
BIN_INSTALL := /usr/local/bin
SRCS = $(wildcard $(SRC_DIR)/*.c)
OBJS = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS))
.PHONY: all
all: $(BIN_DIR)/duress_sign $(BIN_DIR)/pam_test $(BIN_DIR)/pam_duress.so
.PHONY: debug
debug: CFLAGS += -DDEBUG
debug: $(BIN_DIR)/duress_sign $(BIN_DIR)/pam_test $(BIN_DIR)/pam_duress.so
.PHONY: install
install: $(BIN_DIR)/pam_duress.so $(BIN_DIR)/duress_sign $(BIN_DIR)/pam_test
mkdir -p $(PAM_DIR)
strip $(BIN_DIR)/*
cp $(BIN_DIR)/pam_duress.so $(PAM_DIR)/
cp $(BIN_DIR)/duress_sign $(BIN_INSTALL)/
cp $(BIN_DIR)/pam_test $(BIN_INSTALL)/
$(OBJS): $(OBJ_DIR)/%.o : $(SRC_DIR)/%.c
mkdir -p $(OBJ_DIR)
$(CC) -o $@ $(CFLAGS) -c $< $(LDINCLUDE)
$(BIN_DIR)/duress_sign: $(OBJ_DIR)/duress_sign.o $(OBJ_DIR)/util.o
mkdir -p $(BIN_DIR)
$(CC) -o $@ $^ $(LDLIB)
$(BIN_DIR)/pam_duress.so: $(OBJ_DIR)/duress.o $(OBJ_DIR)/util.o
ld $(LDFLAGS) -o $@ $^ $(LDLIB)
$(BIN_DIR)/pam_test: $(SRC_DIR)/pam_test.c
mkdir -p $(BIN_DIR)
$(CC) -o $@ $^ $(LDLIB)
.PHONY: uninstall
uninstall:
rm -f $(PAM_DIR)/pam_duress.so
rm -f $(BIN_INSTALL)/duress_sign
rm -f $(BIN_INSTALL)/pam_test
.PHONY: clean
clean:
rm -rf $(OBJ_DIR)/
rm -rf $(BIN_DIR)/