mirror of
https://github.com/libtom/libtomcrypt
synced 2026-08-25 20:26:07 -04:00
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>
This commit is contained in:
parent
a9bb1c1525
commit
88dcebdbf5
9 changed files with 114 additions and 56 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -22,6 +22,7 @@ doc/crypt.pdf
|
|||
doc/refman.pdf
|
||||
|
||||
# *nix/windows test executables
|
||||
ltc-*
|
||||
aesgcm
|
||||
aesgcm.exe
|
||||
constants
|
||||
|
|
|
|||
|
|
@ -3,79 +3,97 @@
|
|||
# -----------------------------------------------------------------------------
|
||||
option(BUILD_USEFUL_DEMOS "Build useful demos (hashsum)" FALSE)
|
||||
option(BUILD_USABLE_DEMOS "Build usable demos (crypt sizes constants pem-info)" FALSE)
|
||||
option(BUILD_BROKEN_DEMOS "Build broken demos (aesgcm openssh-privkey openssl-enc timing)" FALSE)
|
||||
option(BUILD_TEST_DEMOS "Build test demos (small tv_gen)" FALSE)
|
||||
|
||||
option(INSTALL_DEMOS "Install enabled demos (USEFUL and/or USABLE) and ltc wrapper script" FALSE)
|
||||
option(INSTALL_BROKEN_DEMOS "Install broken demos and ltc wrapper script" FALSE)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Useful demos
|
||||
#
|
||||
# Demos that are even somehow useful and could be installed as a system-tool
|
||||
#
|
||||
# * USEFUL_DEMOS = hashsum
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if(BUILD_USEFUL_DEMOS)
|
||||
|
||||
list(APPEND ALL_DEMOS_TARGETS hashsum)
|
||||
|
||||
# hashsum
|
||||
add_executable(hashsum ${CMAKE_CURRENT_SOURCE_DIR}/hashsum.c)
|
||||
|
||||
target_link_libraries(hashsum PRIVATE ${PROJECT_NAME})
|
||||
|
||||
list(APPEND USABLE_DEMOS_TARGETS hashsum)
|
||||
endif()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Usable demos
|
||||
#
|
||||
# Demos that are usable but only rarely make sense to be installed
|
||||
#
|
||||
# USEABLE_DEMOS = crypt sizes constants pem-info
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if(BUILD_USABLE_DEMOS)
|
||||
list(APPEND USABLE_DEMOS_TARGETS crypt sizes constants pem-info)
|
||||
endif()
|
||||
|
||||
list(APPEND ALL_DEMOS_TARGETS crypt sizes constants pem-info)
|
||||
|
||||
# ltcrypt
|
||||
add_executable(crypt ${CMAKE_CURRENT_SOURCE_DIR}/crypt.c)
|
||||
|
||||
target_link_libraries(crypt PRIVATE ${PROJECT_NAME})
|
||||
|
||||
# sizes
|
||||
add_executable(sizes ${CMAKE_CURRENT_SOURCE_DIR}/sizes.c)
|
||||
|
||||
target_link_libraries(sizes PRIVATE ${PROJECT_NAME})
|
||||
|
||||
# constants
|
||||
add_executable(constants ${CMAKE_CURRENT_SOURCE_DIR}/constants.c)
|
||||
|
||||
target_link_libraries(constants PRIVATE ${PROJECT_NAME})
|
||||
|
||||
# pem-info
|
||||
add_executable(pem-info ${CMAKE_CURRENT_SOURCE_DIR}/pem-info.c)
|
||||
|
||||
target_link_libraries(pem-info PRIVATE ${PROJECT_NAME})
|
||||
# -----------------------------------------------------------------------------
|
||||
# Broken demos
|
||||
#
|
||||
# Demos that are kind of useful, but in some way broken
|
||||
#
|
||||
# * aesgcm - can't be built with LTC_EASY
|
||||
# * openssl-enc - can't be built with LTC_EASY
|
||||
# * openssh-privkey - can't be built with LTC_EASY
|
||||
# * timing - not really broken, but older gcc builds spit warnings
|
||||
#
|
||||
# BROKEN_DEMOS = aesgcm openssl-enc openssh-privkey timing
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if(BUILD_BROKEN_DEMOS AND INSTALL_BROKEN_DEMOS)
|
||||
list(APPEND USABLE_DEMOS_TARGETS aesgcm openssh-privkey openssl-enc timing)
|
||||
elseif(BUILD_BROKEN_DEMOS)
|
||||
list(APPEND ALL_DEMOS_TARGETS aesgcm openssh-privkey openssl-enc timing)
|
||||
endif()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Test demos
|
||||
#
|
||||
# Demos that are used for testing or measuring
|
||||
#
|
||||
# * TEST_DEMOS = small tv_gen
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if(BUILD_TEST_DEMOS)
|
||||
|
||||
list(APPEND ALL_DEMOS_TARGETS tv_gen)
|
||||
|
||||
# small
|
||||
add_executable(small ${CMAKE_CURRENT_SOURCE_DIR}/small.c)
|
||||
|
||||
target_link_libraries(small PRIVATE ${PROJECT_NAME})
|
||||
|
||||
# tv_gen
|
||||
add_executable(tv_gen ${CMAKE_CURRENT_SOURCE_DIR}/tv_gen.c)
|
||||
|
||||
target_link_libraries(tv_gen PRIVATE ${PROJECT_NAME})
|
||||
|
||||
list(APPEND ALL_DEMOS_TARGETS small tv_gen)
|
||||
endif()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Generate executables
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# USABLE_DEMOS can get installed, so they're prefixed with `ltc-`
|
||||
foreach(target ${USABLE_DEMOS_TARGETS})
|
||||
list(APPEND ALL_DEMOS_INSTALL_TARGETS ltc-${target})
|
||||
|
||||
add_executable(ltc-${target} ${CMAKE_CURRENT_SOURCE_DIR}/${target}.c)
|
||||
|
||||
target_link_libraries(ltc-${target} PRIVATE ${PROJECT_NAME})
|
||||
endforeach()
|
||||
|
||||
foreach(target ${ALL_DEMOS_TARGETS})
|
||||
add_executable(${target} ${CMAKE_CURRENT_SOURCE_DIR}/${target}.c)
|
||||
|
||||
target_link_libraries(${target} PRIVATE ${PROJECT_NAME})
|
||||
endforeach()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Install targets
|
||||
# -----------------------------------------------------------------------------
|
||||
if(INSTALL_DEMOS)
|
||||
install(
|
||||
TARGETS ${ALL_DEMOS_TARGETS}
|
||||
TARGETS ${ALL_DEMOS_INSTALL_TARGETS}
|
||||
COMPONENT "runtime"
|
||||
EXPORT ${TARGETS_EXPORT_NAME}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
# Also install the `ltc` wrapper script
|
||||
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/ltc DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
|
|
|||
34
demos/ltc
Executable file
34
demos/ltc
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/sh
|
||||
|
||||
RELDIR="/$0"
|
||||
RELDIR="${RELDIR%/*}"
|
||||
RELDIR="${RELDIR:-.}"
|
||||
RELDIR="${RELDIR##/}/"
|
||||
|
||||
BINDIR=`cd "$RELDIR"; pwd`
|
||||
|
||||
err_out() {
|
||||
err=$1
|
||||
shift
|
||||
echo $* >&2
|
||||
exit $err
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat >&$(($1 + 1)) << EOF
|
||||
Available commands are:
|
||||
`ls -1 $BINDIR/ltc-* | sed "s@$BINDIR/ltc-@ @g"`
|
||||
help
|
||||
EOF
|
||||
exit $1
|
||||
}
|
||||
|
||||
[ $# -gt 0 ] || usage 1
|
||||
|
||||
TOOL="$1"
|
||||
shift
|
||||
[ "$TOOL" == "help" ] || [ "$TOOL" == "--help" ] || [ "$TOOL" == "-h" ] && usage 0
|
||||
|
||||
test -x "$BINDIR/ltc-$TOOL" || err_out 1 "Unknown command: $TOOL"
|
||||
|
||||
[ $# -gt 0 ] && "$BINDIR/ltc-$TOOL" "$@" || "$BINDIR/ltc-$TOOL"
|
||||
2
makefile
2
makefile
|
|
@ -84,7 +84,7 @@ $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).
|
|||
ifneq ($V,1)
|
||||
@echo " * $${CC} $$@" ${silent_echo}
|
||||
endif
|
||||
$${silent} $$(CC) $$(LTC_LDFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(LTC_EXTRALIBS) -o $(1)
|
||||
$${silent} $$(CC) $$(LTC_LDFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(LTC_EXTRALIBS) -o $$@
|
||||
endef
|
||||
|
||||
$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
|
||||
|
|
|
|||
|
|
@ -321,9 +321,9 @@ install: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D)
|
|||
copy /Y src\headers\tomcrypt*.h "$(PREFIX)\include"
|
||||
|
||||
#Install useful tools
|
||||
install_bins: hashsum
|
||||
install_bins: hashsum.exe
|
||||
cmd /c if not exist "$(PREFIX)\bin" mkdir "$(PREFIX)\bin"
|
||||
copy /Y hashsum.exe "$(PREFIX)\bin"
|
||||
copy /Y hashsum.exe "$(PREFIX)\bin\ltc-hashsum.exe"
|
||||
|
||||
#Install documentation
|
||||
install_docs: doc/crypt.pdf
|
||||
|
|
|
|||
|
|
@ -306,9 +306,9 @@ install: $(LIBMAIN_S)
|
|||
copy /Y src\headers\tomcrypt*.h "$(PREFIX)\include"
|
||||
|
||||
#Install useful tools
|
||||
install_bins: hashsum
|
||||
install_bins: hashsum.exe
|
||||
cmd /c if not exist "$(PREFIX)\bin" mkdir "$(PREFIX)\bin"
|
||||
copy /Y hashsum.exe "$(PREFIX)\bin"
|
||||
copy /Y hashsum.exe "$(PREFIX)\bin\ltc-hashsum.exe"
|
||||
|
||||
#Install documentation
|
||||
install_docs: doc/crypt.pdf
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ test: $(call print-help,test,Builds the library and the 'test' application to ru
|
|||
# build the demos from a template
|
||||
define DEMO_template
|
||||
$(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).o $$(LIBNAME)
|
||||
$$(TGTLIBTOOL) --mode=link --tag=CC $$(CC) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $(1)
|
||||
$$(TGTLIBTOOL) --mode=link --tag=CC $$(CC) $$(LTC_LDFLAGS) $$^ $$(EXTRALIBS) -o $$@
|
||||
endef
|
||||
|
||||
$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
|
||||
|
|
|
|||
|
|
@ -336,7 +336,8 @@ install: $(LIBMAIN_S)
|
|||
#Install useful tools
|
||||
install_bins: hashsum
|
||||
@mkdir -p $(DESTDIR)$(BINPATH)
|
||||
@cp hashsum $(DESTDIR)$(BINPATH)/
|
||||
@cp hashsum $(DESTDIR)$(BINPATH)/ltc-hashsum
|
||||
@cp demos/ltc $(DESTDIR)$(BINPATH)/ltc
|
||||
|
||||
#Install documentation
|
||||
install_docs: doc/crypt.pdf
|
||||
|
|
|
|||
|
|
@ -82,6 +82,9 @@ endif
|
|||
ifneq ($(shell echo $(CFLAGS) | grep TFM_DESC),)
|
||||
LTC_CFLAGS+=$(shell PKG_CONFIG_PATH=$(LIBPATH)/pkgconfig pkg-config --cflags-only-I tomsfastmath)
|
||||
endif
|
||||
ifneq ($(shell echo $(CFLAGS) | grep GMP_DESC),)
|
||||
LTC_CFLAGS+=$(shell PKG_CONFIG_PATH=$(LIBPATH)/pkgconfig pkg-config --cflags-only-I gmp)
|
||||
endif
|
||||
LTC_CFLAGS += -I./src/headers/ -DLTC_SOURCE -Wall -Wsign-compare -Wshadow
|
||||
|
||||
ifdef OLD_GCC
|
||||
|
|
@ -485,7 +488,8 @@ $(DESTDIR)$(BINPATH):
|
|||
install -p -d $(DESTDIR)$(BINPATH)
|
||||
|
||||
.common_install_bins: $(USEFUL_DEMOS) $(DESTDIR)$(BINPATH)
|
||||
$(INSTALL_CMD) -p -m 775 $(USEFUL_DEMOS) $(DESTDIR)$(BINPATH)
|
||||
for d in $(USEFUL_DEMOS); do $(INSTALL_CMD) -p -m 775 $$d $(DESTDIR)$(BINPATH)/ltc-$$d
|
||||
$(INSTALL_CMD) -p -m 775 demos/ltc $(DESTDIR)$(BINPATH)
|
||||
|
||||
install_docs: $(call print-help,install_docs,Installs the Developer Manual) doc/crypt.pdf
|
||||
install -p -d $(DESTDIR)$(DATAPATH)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue