fix building demos from makefile.shared
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
diff --git a/makefile.shared b/makefile.shared
index 70543c1..9319e65 100644
--- a/makefile.shared
+++ b/makefile.shared
@@ -74,16 +74,24 @@ uninstall:
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc
-test mtest_opponent: demo/shared.o $(LIBNAME) | demo/test.o demo/mtest_opponent.o
- $(LTLINK) $(LTM_LDFLAGS) -DLTM_TEST_DYNAMIC demo/$@.o $^ -o $@
+DEMOS=mtest_opponent test timing
+test: LTM_LDFLAGS+=-DLTM_TEST_DYNAMIC
+
+# build the demos from a template
+define DEMO_template
+$(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demo/$(1).o demo/shared.o $$(LIBNAME)
+ifneq ($V,1)
+ @echo " * $${CC} $$@" ${silent_echo}
+endif
+ $(LTLINK) $(LTM_CFLAGS) $(LTM_LDFLAGS) $$^ -o $(1)
+endef
+
+$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
.PHONY: mtest
mtest:
cd mtest ; $(CC) $(LTM_CFLAGS) -O0 mtest.c $(LTM_LDFLAGS) -o mtest
-timing: $(LIBNAME) demo/timing.c
- $(LTLINK) $(LTM_CFLAGS) $(LTM_LDFLAGS) -DTIMER demo/timing.c $(LIBNAME) -o timing
-
tune: $(LIBNAME)
$(LTCOMPILE) $(LTM_CFLAGS) -c etc/tune.c -o etc/tune.o
$(LTLINK) $(LTM_LDFLAGS) -o etc/tune etc/tune.o $(LIBNAME)
diff --git a/makefile_include.mk b/makefile_include.mk
index 0266da1..9a152d7 100644
--- a/makefile_include.mk
+++ b/makefile_include.mk
@@ -87,6 +87,7 @@ endif
ifdef COMPILE_LTO
LTM_CFLAGS += -flto
+LTM_LDFLAGS += -flto
AR = $(subst clang,llvm-ar,$(subst gcc,gcc-ar,$(CC)))
endif