Browse Source

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 <[email protected]>
Steffen Jaeckel 10 months ago
parent
commit
88dcebdbf5
9 changed files with 109 additions and 51 deletions
  1. 1 0
      .gitignore
  2. 61 43
      demos/CMakeLists.txt
  3. 34 0
      demos/ltc
  4. 1 1
      makefile
  5. 2 2
      makefile.mingw
  6. 2 2
      makefile.msvc
  7. 1 1
      makefile.shared
  8. 2 1
      makefile.unix
  9. 5 1
      makefile_include.mk

+ 1 - 0
.gitignore

@@ -22,6 +22,7 @@ doc/crypt.pdf
 doc/refman.pdf
 doc/refman.pdf
 
 
 # *nix/windows test executables
 # *nix/windows test executables
+ltc-*
 aesgcm
 aesgcm
 aesgcm.exe
 aesgcm.exe
 constants
 constants

+ 61 - 43
demos/CMakeLists.txt

@@ -3,79 +3,97 @@
 # -----------------------------------------------------------------------------
 # -----------------------------------------------------------------------------
 option(BUILD_USEFUL_DEMOS "Build useful demos (hashsum)" FALSE)
 option(BUILD_USEFUL_DEMOS "Build useful demos (hashsum)" FALSE)
 option(BUILD_USABLE_DEMOS "Build usable demos (crypt sizes constants pem-info)" 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(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
 # Useful demos
+#
+# Demos that are even somehow useful and could be installed as a system-tool
+#
+# * USEFUL_DEMOS   = hashsum
 # -----------------------------------------------------------------------------
 # -----------------------------------------------------------------------------
 
 
 if(BUILD_USEFUL_DEMOS)
 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()
 endif()
 
 
 # -----------------------------------------------------------------------------
 # -----------------------------------------------------------------------------
 # Usable demos
 # 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)
 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()
 endif()
 
 
 # -----------------------------------------------------------------------------
 # -----------------------------------------------------------------------------
 # Test demos
 # Test demos
+#
+# Demos that are used for testing or measuring
+#
+# * TEST_DEMOS     = small tv_gen
 # -----------------------------------------------------------------------------
 # -----------------------------------------------------------------------------
 
 
 if(BUILD_TEST_DEMOS)
 if(BUILD_TEST_DEMOS)
+    list(APPEND ALL_DEMOS_TARGETS small tv_gen)
+endif()
 
 
-    list(APPEND ALL_DEMOS_TARGETS tv_gen)
+# -----------------------------------------------------------------------------
+# Generate executables
+# -----------------------------------------------------------------------------
 
 
-    # small
-    add_executable(small ${CMAKE_CURRENT_SOURCE_DIR}/small.c)
+# USABLE_DEMOS can get installed, so they're prefixed with `ltc-`
+foreach(target ${USABLE_DEMOS_TARGETS})
+    list(APPEND ALL_DEMOS_INSTALL_TARGETS ltc-${target})
 
 
-    target_link_libraries(small PRIVATE ${PROJECT_NAME})
+    add_executable(ltc-${target} ${CMAKE_CURRENT_SOURCE_DIR}/${target}.c)
 
 
-    # tv_gen
-    add_executable(tv_gen ${CMAKE_CURRENT_SOURCE_DIR}/tv_gen.c)
+    target_link_libraries(ltc-${target} PRIVATE ${PROJECT_NAME})
+endforeach()
 
 
-    target_link_libraries(tv_gen PRIVATE ${PROJECT_NAME})
+foreach(target ${ALL_DEMOS_TARGETS})
+    add_executable(${target} ${CMAKE_CURRENT_SOURCE_DIR}/${target}.c)
 
 
-endif()
+    target_link_libraries(${target} PRIVATE ${PROJECT_NAME})
+endforeach()
 
 
 # -----------------------------------------------------------------------------
 # -----------------------------------------------------------------------------
 # Install targets
 # Install targets
 # -----------------------------------------------------------------------------
 # -----------------------------------------------------------------------------
-install(
-    TARGETS ${ALL_DEMOS_TARGETS}
-    COMPONENT "runtime"
-    EXPORT ${TARGETS_EXPORT_NAME}
-    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
-)
+if(INSTALL_DEMOS)
+    install(
+        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 - 0
demos/ltc

@@ -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"

+ 1 - 1
makefile

@@ -84,7 +84,7 @@ $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).
 ifneq ($V,1)
 ifneq ($V,1)
 	@echo "   * $${CC} $$@" ${silent_echo}
 	@echo "   * $${CC} $$@" ${silent_echo}
 endif
 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
 endef
 
 
 $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
 $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))

+ 2 - 2
makefile.mingw

@@ -321,9 +321,9 @@ install: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D)
 	copy /Y src\headers\tomcrypt*.h "$(PREFIX)\include"
 	copy /Y src\headers\tomcrypt*.h "$(PREFIX)\include"
 
 
 #Install useful tools
 #Install useful tools
-install_bins: hashsum
+install_bins: hashsum.exe
 	cmd /c if not exist "$(PREFIX)\bin" mkdir "$(PREFIX)\bin"
 	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 documentation
 install_docs: doc/crypt.pdf
 install_docs: doc/crypt.pdf

+ 2 - 2
makefile.msvc

@@ -306,9 +306,9 @@ install: $(LIBMAIN_S)
 	copy /Y src\headers\tomcrypt*.h "$(PREFIX)\include"
 	copy /Y src\headers\tomcrypt*.h "$(PREFIX)\include"
 
 
 #Install useful tools
 #Install useful tools
-install_bins: hashsum
+install_bins: hashsum.exe
 	cmd /c if not exist "$(PREFIX)\bin" mkdir "$(PREFIX)\bin"
 	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 documentation
 install_docs: doc/crypt.pdf
 install_docs: doc/crypt.pdf

+ 1 - 1
makefile.shared

@@ -94,7 +94,7 @@ test: $(call print-help,test,Builds the library and the 'test' application to ru
 # build the demos from a template
 # build the demos from a template
 define DEMO_template
 define DEMO_template
 $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).o $$(LIBNAME)
 $(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
 endef
 
 
 $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
 $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))

+ 2 - 1
makefile.unix

@@ -336,7 +336,8 @@ install: $(LIBMAIN_S)
 #Install useful tools
 #Install useful tools
 install_bins: hashsum
 install_bins: hashsum
 	@mkdir -p $(DESTDIR)$(BINPATH)
 	@mkdir -p $(DESTDIR)$(BINPATH)
-	@cp hashsum $(DESTDIR)$(BINPATH)/
+	@cp hashsum $(DESTDIR)$(BINPATH)/ltc-hashsum
+	@cp demos/ltc $(DESTDIR)$(BINPATH)/ltc
 
 
 #Install documentation
 #Install documentation
 install_docs: doc/crypt.pdf
 install_docs: doc/crypt.pdf

+ 5 - 1
makefile_include.mk

@@ -82,6 +82,9 @@ endif
 ifneq ($(shell echo $(CFLAGS) | grep TFM_DESC),)
 ifneq ($(shell echo $(CFLAGS) | grep TFM_DESC),)
 LTC_CFLAGS+=$(shell PKG_CONFIG_PATH=$(LIBPATH)/pkgconfig pkg-config --cflags-only-I tomsfastmath)
 LTC_CFLAGS+=$(shell PKG_CONFIG_PATH=$(LIBPATH)/pkgconfig pkg-config --cflags-only-I tomsfastmath)
 endif
 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
 LTC_CFLAGS += -I./src/headers/ -DLTC_SOURCE -Wall -Wsign-compare -Wshadow
 
 
 ifdef OLD_GCC
 ifdef OLD_GCC
@@ -485,7 +488,8 @@ $(DESTDIR)$(BINPATH):
 	install -p -d $(DESTDIR)$(BINPATH)
 	install -p -d $(DESTDIR)$(BINPATH)
 
 
 .common_install_bins: $(USEFUL_DEMOS) $(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_docs: $(call print-help,install_docs,Installs the Developer Manual) doc/crypt.pdf
 	install -p -d $(DESTDIR)$(DATAPATH)
 	install -p -d $(DESTDIR)$(DATAPATH)