1# MAKEFILE for linux GCC
2#
3# Tom St Denis
4# Modified by Clay Culver
5#
6#  (GNU make only)
7
8ifeq ($V,1)
9silent=
10silent_stdout=
11else
12silent=@
13silent_stdout= > /dev/null
14endif
15
16PLATFORM := $(shell uname | sed -e 's/_.*//')
17
18# ranlib tools
19ifndef RANLIB
20RANLIB:=$(CROSS_COMPILE)ranlib
21endif
22INSTALL_CMD = install
23UNINSTALL_CMD = rm
24
25#Output filenames for various targets.
26ifndef LIBNAME
27   LIBNAME=libtomcrypt.a
28endif
29
30
31include makefile_include.mk
32
33ifeq ($(COVERAGE),1)
34all_test: LIB_PRE = -Wl,--whole-archive
35all_test: LIB_POST = -Wl,--no-whole-archive
36LTC_CFLAGS += -fprofile-arcs -ftest-coverage
37EXTRALIBS += -lgcov
38endif
39
40#AES comes in two flavours... enc+dec and enc
41src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
42	${silent} ${CC} ${LTC_CFLAGS} -DENCRYPT_ONLY -c $< -o $@
43
44.c.o:
45ifneq ($V,1)
46	@echo "   * ${CC} $@"
47endif
48	${silent} ${CC} ${LTC_CFLAGS} -c $< -o $@
49
50$(LIBNAME): $(OBJECTS)
51ifneq ($V,1)
52	@echo "   * ${AR} $@"
53endif
54	${silent} $(AR) $(ARFLAGS) $@ $(OBJECTS)
55ifneq ($V,1)
56	@echo "   * ${RANLIB} $@"
57endif
58	${silent} $(RANLIB) $@
59
60test: $(call print-help,test,Builds the library and the 'test' application to run all self-tests) $(LIBNAME) $(TOBJECTS)
61ifneq ($V,1)
62	@echo "   * ${CC} $@"
63endif
64	${silent} $(CC) $(LTC_LDFLAGS) $(TOBJECTS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TEST)
65
66# build the demos from a template
67define DEMO_template
68$(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).o $$(LIBNAME)
69ifneq ($V,1)
70	@echo "   * $${CC} $$@"
71endif
72	$${silent} $$(CC) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(EXTRALIBS) -o $(1)
73endef
74
75$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
76
77
78#This rule installs the library and the header files. This must be run
79#as root in order to have a high enough permission to write to the correct
80#directories and to set the owner and group to root.
81install: $(call print-help,install,Installs the library and headers) .common_install
82
83install_bins: $(call print-help,install_bins,Installs the useful demos ($(USEFUL_DEMOS))) .common_install_bins
84
85uninstall: $(call print-help,uninstall,Uninstalls the library and headers) .common_uninstall
86
87profile:
88	LTC_CFLAGS="$(LTC_CFLAGS) -fprofile-generate" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov"
89	./timing
90	rm -f timing `find . -type f | grep [.][ao] | xargs`
91	LTC_CFLAGS="$(LTC_CFLAGS) -fprofile-use" $(MAKE) timing EXTRALIBS="$(EXTRALIBS) -lgcov"
92
93# target that pre-processes all coverage data
94lcov-single-create:
95	lcov --capture --no-external --directory src -q --output-file coverage_std.info
96
97# target that removes all coverage output
98cleancov-clean:
99	rm -f `find . -type f -name "*.info" | xargs`
100	rm -rf coverage/
101
102# merges all coverage_*.info files into coverage.info
103coverage.info:
104	lcov `find -name 'coverage_*.info' -exec echo -n " -a {}" \;` -o coverage.info
105
106# generates html output from all coverage_*.info files
107lcov-html: coverage.info
108	genhtml coverage.info --output-directory coverage -q
109
110# combines all necessary steps to create the coverage from a single testrun with e.g.
111# CFLAGS="-DUSE_LTM -DLTM_DESC -I../libtommath" EXTRALIBS="../libtommath/libtommath.a" make coverage -j9
112lcov-single:
113	$(MAKE) cleancov-clean
114	$(MAKE) lcov-single-create
115	$(MAKE) coverage.info
116
117
118#make the code coverage of the library
119coverage: LTC_CFLAGS += -fprofile-arcs -ftest-coverage
120coverage: EXTRALIBS += -lgcov
121coverage: LIB_PRE = -Wl,--whole-archive
122coverage: LIB_POST = -Wl,--no-whole-archive
123
124coverage: $(call print-help,coverage,Create code-coverage of the library - but better use coverage.sh) test
125	./test
126
127# cleans everything - coverage output and standard 'clean'
128cleancov: cleancov-clean clean
129
130# ref:         HEAD -> master, tag: v1.18.2
131# git commit:  7e7eb695d581782f04b24dc444cbfde86af59853
132# commit time: 2018-07-01 22:49:01 +0200
133