-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
76 lines (54 loc) · 1.76 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
CFLAGS := -std=c99 -Wall -O2
TARGET ?= $(shell uname -s 2>/dev/null || echo unknown)
override TARGET := $(shell echo $(TARGET) | tr A-Z a-z)
JAVA_HOME ?= $(realpath $(dir $(realpath $(shell which java)))../)
ifeq ($(TARGET), darwin)
DYLIB := dylib
LDFLAGS := -dynamiclib -Wl,-undefined -Wl,dynamic_lookup -Wl,-single_module
CFLAGS += -I $(JAVA_HOME)/Headers/
else
DYLIB := so
LDFLAGS := -shared
CFLAGS += -fPIC
endif
ifeq ($(TARGET), linux)
CFLAGS += -D_POSIX_C_SOURCE=200809L -D_BSD_SOURCE
endif
CFLAGS += -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/$(TARGET)
CFLAGS += -I src/main/include
OBJ = $(patsubst src/main/c/%.c,$(OBJ_DIR)/%.o,$(wildcard src/main/c/*.c))
OBJ += $(patsubst src/main/asm/%.S,$(OBJ_DIR)/%.o,$(wildcard src/main/asm/*.S))
OBJ_DIR := target/obj
LIB := target/libcrypto.$(DYLIB)
all: $(LIB)
clean:
$(RM) $(LIB) $(OBJ)
$(LIB): $(OBJ)
$(CC) $(LDFLAGS) -o $@ $^
$(OBJ): | $(OBJ_DIR)
$(OBJ_DIR):
@mkdir -p $@
test: test_aes test_base64 test_compare test_rdrand test_zero
./test_aes
./test_base64
./test_compare
./test_rdrand
./test_zero
test_aes: target/obj/test_aes.o target/obj/aes_kat.o target/obj/gcm_kat.o \
target/obj/cbc_mct.o target/obj/aesavs.o $(OBJ)
$(CC) -o $@ $^
test_base64: target/obj/test_base64.o target/obj/tinymt64.o $(OBJ)
$(CC) -o $@ $^
test_compare: target/obj/test_compare.o target/obj/tinymt64.o $(OBJ)
$(CC) -o $@ $^
test_rdrand: target/obj/test_rdrand.o target/obj/tinymt64.o $(OBJ)
$(CC) -o $@ $^
test_zero: target/obj/test_zero.o target/obj/tinymt64.o $(OBJ)
$(CC) -o $@ $^
$(OBJ_DIR)/%.o : src/main/c/%.c
$(CC) $(CFLAGS) -c -o $@ $<
$(OBJ_DIR)/%.o : src/main/asm/%.S
$(CC) $(CFLAGS) -c -o $@ $<
$(OBJ_DIR)/%.o : src/test/c/%.c
$(CC) $(CFLAGS) -c -o $@ $<
.PHONY: all clean test