xref: /freebsd/crypto/libecc/Makefile (revision f0865ec9906d5a18fa2a3b61381f22ce16e606ad)
1.SUFFIXES:
2
3# Where to put generated objects
4BUILD_DIR ?= build
5# Default to the previous behaviour and keep generated .o & .d files next to the source code
6OBJ_DIR ?=.
7include common.mk
8
9
10# Static libraries to build
11LIBS = $(LIBARITH) $(LIBEC) $(LIBSIGN)
12
13# Compile dynamic libraries if the user asked to
14ifeq ($(WITH_DYNAMIC_LIBS),1)
15LIBS += $(LIBARITH_DYN) $(LIBEC_DYN) $(LIBSIGN_DYN)
16endif
17
18# Executables to build
19TESTS_EXEC = $(BUILD_DIR)/ec_self_tests $(BUILD_DIR)/ec_utils
20# We also compile executables with dynamic linking if asked to
21ifeq ($(WITH_DYNAMIC_LIBS),1)
22TESTS_EXEC += $(BUILD_DIR)/ec_self_tests_dyn $(BUILD_DIR)/ec_utils_dyn
23endif
24
25EXEC_TO_CLEAN = $(BUILD_DIR)/ec_self_tests $(BUILD_DIR)/ec_utils $(BUILD_DIR)/ec_self_tests_dyn $(BUILD_DIR)/ec_utils_dyn
26
27# all and clean, as you might expect
28all: $(LIBS) $(TESTS_EXEC)
29
30# Default object files extension
31OBJ_FILES_EXTENSION ?= o
32
33clean:
34	@rm -f $(LIBS) $(EXEC_TO_CLEAN)
35	@find $(OBJ_DIR)/ -name '*.$(OBJ_FILES_EXTENSION)' -exec rm -f '{}' \;
36	@find $(OBJ_DIR)/ -name '*.d' -exec rm -f '{}' \;
37	@find $(BUILD_DIR)/ -name '*.a' -exec rm -f '{}' \;
38	@find $(BUILD_DIR)/ -name '*.so' -exec rm -f '{}' \;
39	@find . -name '*~'  -exec rm -f '{}' \;
40
41
42
43# --- Source Code ---
44
45# external dependencies
46EXT_DEPS_SRC = $(wildcard src/external_deps/*.c)
47
48# utils module (for the ARITH layer, we only need
49# NN and FP - and not curves - related stuff. Same goes
50# for EC and SIGN. Hence the distinction between three
51# sets of utils objects.
52UTILS_ARITH_SRC = src/utils/utils.c src/utils/utils_rand.c
53UTILS_ARITH_SRC += $(wildcard src/utils/*_nn.c)
54UTILS_ARITH_SRC += $(wildcard src/utils/*_fp.c)
55UTILS_ARITH_SRC += $(wildcard src/utils/*_buf.c)
56UTILS_EC_SRC = $(wildcard src/utils/*_curves.c)
57UTILS_SIGN_SRC = $(wildcard src/utils/*_keys.c)
58
59# nn module
60NN_SRC = $(wildcard src/nn/n*.c)
61
62# fp module
63FP_SRC = $(wildcard src/fp/fp*.c)
64
65# curve module
66CURVES_SRC = $(wildcard src/curves/*.c)
67
68# Hash module
69HASH_SRC = $(wildcard src/hash/sha*.c) $(wildcard src/hash/bash*.c) src/hash/hash_algs.c src/hash/sm3.c src/hash/streebog.c src/hash/ripemd160.c src/hash/belt-hash.c src/hash/hmac.c
70
71# Key/Signature/Verification/ECDH module
72SIG_SRC = $(wildcard src/sig/*dsa.c) src/sig/ecdsa_common.c src/sig/ecsdsa_common.c src/sig/sig_algs.c src/sig/sm2.c src/sig/bign_common.c src/sig/bign.c src/sig/dbign.c src/sig/bip0340.c
73ECDH_SRC = $(wildcard src/ecdh/*.c)
74KEY_SRC = src/sig/ec_key.c
75
76# Test elements
77TESTS_OBJECTS_CORE_SRC = src/tests/ec_self_tests_core.c
78TESTS_OBJECTS_SELF_SRC = src/tests/ec_self_tests.c
79TESTS_OBJECTS_UTILS_SRC = src/tests/ec_utils.c
80
81
82
83# --- Static Libraries ---
84
85LIBARITH_SRC = $(FP_SRC) $(NN_SRC) $(UTILS_ARITH_SRC)
86LIBARITH_OBJECTS = $(patsubst %,$(OBJ_DIR)/%.$(OBJ_FILES_EXTENSION),$(basename $(LIBARITH_SRC)))
87$(LIBARITH): $(LIBARITH_OBJECTS)
88	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(AR) $(AR_FLAGS) $@ $^
89	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(RANLIB) $(RANLIB_FLAGS) $@
90
91LIBEC_SRC = $(LIBARITH_SRC) $(CURVES_SRC) $(UTILS_EC_SRC)
92LIBEC_OBJECTS = $(patsubst %,$(OBJ_DIR)/%.$(OBJ_FILES_EXTENSION),$(basename $(LIBEC_SRC)))
93$(LIBEC): $(LIBEC_OBJECTS)
94	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(AR) $(AR_FLAGS) $@ $^
95	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(RANLIB) $(RANLIB_FLAGS) $@
96
97LIBSIGN_SRC = $(LIBEC_SRC) $(HASH_SRC) $(SIG_SRC) $(KEY_SRC) $(UTILS_SIGN_SRC) $(ECDH_SRC)
98LIBSIGN_OBJECTS = $(patsubst %,$(OBJ_DIR)/%.$(OBJ_FILES_EXTENSION),$(basename $(LIBSIGN_SRC)))
99$(LIBSIGN): $(LIBSIGN_OBJECTS)
100	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(AR) $(AR_FLAGS) $@ $^
101	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(RANLIB) $(RANLIB_FLAGS) $@
102
103
104
105# --- Dynamic Libraries ---
106
107$(LIBARITH_DYN): $(LIBARITH_OBJECTS)
108	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(CC) $(LIB_CFLAGS) $(LIB_DYN_LDFLAGS) $^ -o $@
109
110$(LIBEC_DYN): $(LIBEC_OBJECTS)
111	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(CC) $(LIB_CFLAGS) $(LIB_DYN_LDFLAGS) $^ -o $@
112
113$(LIBSIGN_DYN): $(LIBSIGN_OBJECTS)
114	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(CC) $(LIB_CFLAGS) $(LIB_DYN_LDFLAGS) $^ -o $@
115
116
117
118# --- Executables (Static linkage with libsign object files) ---
119
120EC_SELF_TESTS_SRC = $(TESTS_OBJECTS_CORE_SRC) $(TESTS_OBJECTS_SELF_SRC) $(EXT_DEPS_SRC)
121EC_SELF_TESTS_OBJECTS = $(patsubst %,$(OBJ_DIR)/%.$(OBJ_FILES_EXTENSION),$(basename $(EC_SELF_TESTS_SRC)))
122$(BUILD_DIR)/ec_self_tests: $(EC_SELF_TESTS_OBJECTS) $(LIBSIGN_OBJECTS)
123	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(CC) $(BIN_CFLAGS) $(BIN_LDFLAGS) $^ -o $@
124
125EC_UTILS_SRC = $(TESTS_OBJECTS_CORE_SRC) $(TESTS_OBJECTS_UTILS_SRC) $(EXT_DEPS_SRC)
126EC_UTILS_OBJECTS = $(patsubst %,$(OBJ_DIR)/%.$(OBJ_FILES_EXTENSION),$(basename $(EC_UTILS_SRC)))
127$(BUILD_DIR)/ec_utils: $(EC_UTILS_SRC) $(LIBSIGN_OBJECTS)
128	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(CC) $(BIN_CFLAGS) $(BIN_LDFLAGS) -DWITH_STDLIB  $^ -o $@
129
130
131
132# --- Excutables (Dynamic linkage with libsign shared library) ---
133
134$(BUILD_DIR)/ec_self_tests_dyn: $(EC_SELF_TESTS_OBJECTS)
135	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(CC) $(BIN_CFLAGS) $(BIN_LDFLAGS) -L$(BUILD_DIR) $^ -lsign -o $@
136
137$(BUILD_DIR)/ec_utils_dyn: $(EC_UTILS_OBJECTS)
138	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(CC) $(BIN_CFLAGS) $(BIN_LDFLAGS) -L$(BUILD_DIR) -DWITH_STDLIB  $^ -lsign -o $@
139
140
141
142.PHONY: all clean 16 32 64 debug debug16 debug32 debug64 force_arch32 force_arch64
143
144# All source files, used to construct general rules
145SRC += $(EXT_DEPS_SRC) $(UTILS_ARITH_SRC) $(UTILS_EC_SRC) $(UTILS_SIGN_SRC)
146SRC += $(NN_SRC) $(FP_SRC) $(CURVES_SRC) $(HASH_SRC) $(SIG_SRC) $(ECDH_SRC)
147SRC += $(KEY_SRC) $(TESTS_OBJECTS_CORE_SRC) $(TESTS_OBJECTS_SELF_SRC)
148SRC += $(TESTS_OBJECTS_UTILS_SRC)
149
150# All object files
151OBJS = $(patsubst %,$(OBJ_DIR)/%.$(OBJ_FILES_EXTENSION),$(basename $(SRC)))
152
153# General dependency rule between .o and .d files
154DEPS = $(OBJS:.$(OBJ_FILES_EXTENSION)=.d)
155
156# General rule for creating .o (and .d) file from .c
157$(OBJ_DIR)/%.$(OBJ_FILES_EXTENSION): %.c
158	$(VERBOSE_MAKE)$(CROSS_COMPILE)$(CC) -c $(LIB_CFLAGS) -o $@ $<
159
160# Populate the directory structure to contain the .o and .d files, if necessary
161$(shell mkdir -p $(dir $(OBJS)) >/dev/null)
162$(shell mkdir -p $(BUILD_DIR) >/dev/null)
163
164# Make a note of the MAKEFILE_LIST at this stage of parsing the Makefile
165# It is important here to use the ':=' operator so it is evaluated only once,
166# and to do this before all the DEPS files are included as makefiles.
167MAKEFILES:=$(MAKEFILE_LIST)
168
169# Make object files depend on all makefiles used - this forces a rebuild if any
170# of the makefiles are changed
171$(OBJS) : $(MAKEFILES)
172
173# Dep files are makefiles that keep track of which header files are used by the
174# c source code. Include them to allow them to work correctly.
175-include $(DEPS)
176