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