Skip to content

Commit 88dcebd

Browse files
committed
Rework demos building and installation
* add `ltc` wrapper script for installed demos * rework demos/CMakeLists.txt and add some more bells and whistles * prefix installed demos with `ltc-` Currently this makes the standard makefiles and CMake results diverge, but we can fix that later if required. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent a9bb1c1 commit 88dcebd

File tree

9 files changed

+109
-51
lines changed

9 files changed

+109
-51
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ doc/crypt.pdf
2222
doc/refman.pdf
2323

2424
# *nix/windows test executables
25+
ltc-*
2526
aesgcm
2627
aesgcm.exe
2728
constants

demos/CMakeLists.txt

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,97 @@
33
# -----------------------------------------------------------------------------
44
option(BUILD_USEFUL_DEMOS "Build useful demos (hashsum)" FALSE)
55
option(BUILD_USABLE_DEMOS "Build usable demos (crypt sizes constants pem-info)" FALSE)
6+
option(BUILD_BROKEN_DEMOS "Build broken demos (aesgcm openssh-privkey openssl-enc timing)" FALSE)
67
option(BUILD_TEST_DEMOS "Build test demos (small tv_gen)" FALSE)
78

9+
option(INSTALL_DEMOS "Install enabled demos (USEFUL and/or USABLE) and ltc wrapper script" FALSE)
10+
option(INSTALL_BROKEN_DEMOS "Install broken demos and ltc wrapper script" FALSE)
11+
812
# -----------------------------------------------------------------------------
913
# Useful demos
14+
#
15+
# Demos that are even somehow useful and could be installed as a system-tool
16+
#
17+
# * USEFUL_DEMOS = hashsum
1018
# -----------------------------------------------------------------------------
1119

1220
if(BUILD_USEFUL_DEMOS)
13-
14-
list(APPEND ALL_DEMOS_TARGETS hashsum)
15-
16-
# hashsum
17-
add_executable(hashsum ${CMAKE_CURRENT_SOURCE_DIR}/hashsum.c)
18-
19-
target_link_libraries(hashsum PRIVATE ${PROJECT_NAME})
20-
21+
list(APPEND USABLE_DEMOS_TARGETS hashsum)
2122
endif()
2223

2324
# -----------------------------------------------------------------------------
2425
# Usable demos
26+
#
27+
# Demos that are usable but only rarely make sense to be installed
28+
#
29+
# USEABLE_DEMOS = crypt sizes constants pem-info
2530
# -----------------------------------------------------------------------------
2631

2732
if(BUILD_USABLE_DEMOS)
33+
list(APPEND USABLE_DEMOS_TARGETS crypt sizes constants pem-info)
34+
endif()
2835

29-
list(APPEND ALL_DEMOS_TARGETS crypt sizes constants pem-info)
30-
31-
# ltcrypt
32-
add_executable(crypt ${CMAKE_CURRENT_SOURCE_DIR}/crypt.c)
33-
34-
target_link_libraries(crypt PRIVATE ${PROJECT_NAME})
35-
36-
# sizes
37-
add_executable(sizes ${CMAKE_CURRENT_SOURCE_DIR}/sizes.c)
38-
39-
target_link_libraries(sizes PRIVATE ${PROJECT_NAME})
40-
41-
# constants
42-
add_executable(constants ${CMAKE_CURRENT_SOURCE_DIR}/constants.c)
43-
44-
target_link_libraries(constants PRIVATE ${PROJECT_NAME})
45-
46-
# pem-info
47-
add_executable(pem-info ${CMAKE_CURRENT_SOURCE_DIR}/pem-info.c)
48-
49-
target_link_libraries(pem-info PRIVATE ${PROJECT_NAME})
36+
# -----------------------------------------------------------------------------
37+
# Broken demos
38+
#
39+
# Demos that are kind of useful, but in some way broken
40+
#
41+
# * aesgcm - can't be built with LTC_EASY
42+
# * openssl-enc - can't be built with LTC_EASY
43+
# * openssh-privkey - can't be built with LTC_EASY
44+
# * timing - not really broken, but older gcc builds spit warnings
45+
#
46+
# BROKEN_DEMOS = aesgcm openssl-enc openssh-privkey timing
47+
# -----------------------------------------------------------------------------
5048

49+
if(BUILD_BROKEN_DEMOS AND INSTALL_BROKEN_DEMOS)
50+
list(APPEND USABLE_DEMOS_TARGETS aesgcm openssh-privkey openssl-enc timing)
51+
elseif(BUILD_BROKEN_DEMOS)
52+
list(APPEND ALL_DEMOS_TARGETS aesgcm openssh-privkey openssl-enc timing)
5153
endif()
5254

5355
# -----------------------------------------------------------------------------
5456
# Test demos
57+
#
58+
# Demos that are used for testing or measuring
59+
#
60+
# * TEST_DEMOS = small tv_gen
5561
# -----------------------------------------------------------------------------
5662

5763
if(BUILD_TEST_DEMOS)
64+
list(APPEND ALL_DEMOS_TARGETS small tv_gen)
65+
endif()
5866

59-
list(APPEND ALL_DEMOS_TARGETS tv_gen)
67+
# -----------------------------------------------------------------------------
68+
# Generate executables
69+
# -----------------------------------------------------------------------------
6070

61-
# small
62-
add_executable(small ${CMAKE_CURRENT_SOURCE_DIR}/small.c)
71+
# USABLE_DEMOS can get installed, so they're prefixed with `ltc-`
72+
foreach(target ${USABLE_DEMOS_TARGETS})
73+
list(APPEND ALL_DEMOS_INSTALL_TARGETS ltc-${target})
6374

64-
target_link_libraries(small PRIVATE ${PROJECT_NAME})
75+
add_executable(ltc-${target} ${CMAKE_CURRENT_SOURCE_DIR}/${target}.c)
6576

66-
# tv_gen
67-
add_executable(tv_gen ${CMAKE_CURRENT_SOURCE_DIR}/tv_gen.c)
77+
target_link_libraries(ltc-${target} PRIVATE ${PROJECT_NAME})
78+
endforeach()
6879

69-
target_link_libraries(tv_gen PRIVATE ${PROJECT_NAME})
80+
foreach(target ${ALL_DEMOS_TARGETS})
81+
add_executable(${target} ${CMAKE_CURRENT_SOURCE_DIR}/${target}.c)
7082

71-
endif()
83+
target_link_libraries(${target} PRIVATE ${PROJECT_NAME})
84+
endforeach()
7285

7386
# -----------------------------------------------------------------------------
7487
# Install targets
7588
# -----------------------------------------------------------------------------
76-
install(
77-
TARGETS ${ALL_DEMOS_TARGETS}
78-
COMPONENT "runtime"
79-
EXPORT ${TARGETS_EXPORT_NAME}
80-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
81-
)
89+
if(INSTALL_DEMOS)
90+
install(
91+
TARGETS ${ALL_DEMOS_INSTALL_TARGETS}
92+
COMPONENT "runtime"
93+
EXPORT ${TARGETS_EXPORT_NAME}
94+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
95+
)
96+
97+
# Also install the `ltc` wrapper script
98+
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/ltc DESTINATION ${CMAKE_INSTALL_BINDIR})
99+
endif()

demos/ltc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
2+
3+
RELDIR="/$0"
4+
RELDIR="${RELDIR%/*}"
5+
RELDIR="${RELDIR:-.}"
6+
RELDIR="${RELDIR##/}/"
7+
8+
BINDIR=`cd "$RELDIR"; pwd`
9+
10+
err_out() {
11+
err=$1
12+
shift
13+
echo $* >&2
14+
exit $err
15+
}
16+
17+
usage() {
18+
cat >&$(($1 + 1)) << EOF
19+
Available commands are:
20+
`ls -1 $BINDIR/ltc-* | sed "s@$BINDIR/ltc-@ @g"`
21+
help
22+
EOF
23+
exit $1
24+
}
25+
26+
[ $# -gt 0 ] || usage 1
27+
28+
TOOL="$1"
29+
shift
30+
[ "$TOOL" == "help" ] || [ "$TOOL" == "--help" ] || [ "$TOOL" == "-h" ] && usage 0
31+
32+
test -x "$BINDIR/ltc-$TOOL" || err_out 1 "Unknown command: $TOOL"
33+
34+
[ $# -gt 0 ] && "$BINDIR/ltc-$TOOL" "$@" || "$BINDIR/ltc-$TOOL"

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).
8484
ifneq ($V,1)
8585
@echo " * $${CC} $$@" ${silent_echo}
8686
endif
87-
$${silent} $$(CC) $$(LTC_LDFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(LTC_EXTRALIBS) -o $(1)
87+
$${silent} $$(CC) $$(LTC_LDFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(LTC_EXTRALIBS) -o $$@
8888
endef
8989

9090
$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))

makefile.mingw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ install: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D)
321321
copy /Y src\headers\tomcrypt*.h "$(PREFIX)\include"
322322

323323
#Install useful tools
324-
install_bins: hashsum
324+
install_bins: hashsum.exe
325325
cmd /c if not exist "$(PREFIX)\bin" mkdir "$(PREFIX)\bin"
326-
copy /Y hashsum.exe "$(PREFIX)\bin"
326+
copy /Y hashsum.exe "$(PREFIX)\bin\ltc-hashsum.exe"
327327

328328
#Install documentation
329329
install_docs: doc/crypt.pdf

makefile.msvc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ install: $(LIBMAIN_S)
306306
copy /Y src\headers\tomcrypt*.h "$(PREFIX)\include"
307307

308308
#Install useful tools
309-
install_bins: hashsum
309+
install_bins: hashsum.exe
310310
cmd /c if not exist "$(PREFIX)\bin" mkdir "$(PREFIX)\bin"
311-
copy /Y hashsum.exe "$(PREFIX)\bin"
311+
copy /Y hashsum.exe "$(PREFIX)\bin\ltc-hashsum.exe"
312312

313313
#Install documentation
314314
install_docs: doc/crypt.pdf

makefile.shared

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ test: $(call print-help,test,Builds the library and the 'test' application to ru
9494
# build the demos from a template
9595
define DEMO_template
9696
$(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).o $$(LIBNAME)
97-
$$(TGTLIBTOOL) --mode=link --tag=CC $$(CC) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $(1)
97+
$$(TGTLIBTOOL) --mode=link --tag=CC $$(CC) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $$@
9898
endef
9999

100100
$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))

makefile.unix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ install: $(LIBMAIN_S)
336336
#Install useful tools
337337
install_bins: hashsum
338338
@mkdir -p $(DESTDIR)$(BINPATH)
339-
@cp hashsum $(DESTDIR)$(BINPATH)/
339+
@cp hashsum $(DESTDIR)$(BINPATH)/ltc-hashsum
340+
@cp demos/ltc $(DESTDIR)$(BINPATH)/ltc
340341

341342
#Install documentation
342343
install_docs: doc/crypt.pdf

makefile_include.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ endif
8282
ifneq ($(shell echo $(CFLAGS) | grep TFM_DESC),)
8383
LTC_CFLAGS+=$(shell PKG_CONFIG_PATH=$(LIBPATH)/pkgconfig pkg-config --cflags-only-I tomsfastmath)
8484
endif
85+
ifneq ($(shell echo $(CFLAGS) | grep GMP_DESC),)
86+
LTC_CFLAGS+=$(shell PKG_CONFIG_PATH=$(LIBPATH)/pkgconfig pkg-config --cflags-only-I gmp)
87+
endif
8588
LTC_CFLAGS += -I./src/headers/ -DLTC_SOURCE -Wall -Wsign-compare -Wshadow
8689

8790
ifdef OLD_GCC
@@ -485,7 +488,8 @@ $(DESTDIR)$(BINPATH):
485488
install -p -d $(DESTDIR)$(BINPATH)
486489

487490
.common_install_bins: $(USEFUL_DEMOS) $(DESTDIR)$(BINPATH)
488-
$(INSTALL_CMD) -p -m 775 $(USEFUL_DEMOS) $(DESTDIR)$(BINPATH)
491+
for d in $(USEFUL_DEMOS); do $(INSTALL_CMD) -p -m 775 $$d $(DESTDIR)$(BINPATH)/ltc-$$d
492+
$(INSTALL_CMD) -p -m 775 demos/ltc $(DESTDIR)$(BINPATH)
489493

490494
install_docs: $(call print-help,install_docs,Installs the Developer Manual) doc/crypt.pdf
491495
install -p -d $(DESTDIR)$(DATAPATH)

0 commit comments

Comments
 (0)