#!/usr/bin/env sh # # This script is used for automatic generation of src/Makefile.am and fuzz/Makefile.am # That way it is not necessary anymore to use wildcard *.c includes. # Automake does not support it: https://www.gnu.org/software/automake/manual/html_node/Wildcards.html # # This script should run everytime a new *.c file should be part of the library. # set -e MYDIR="$(realpath "$(dirname "${0}")")" generate_src_am() { # enumerate all *.c sources below src/ with a max. depth of three cd "${MYDIR}/../src" C_INCLUDES_GEN=$(find include -iname "*.h.in" | sort) C_INCLUDES_PRV=$(find lib lib/protocols lib/third_party/include -maxdepth 1 -iname "*.h" -o -iname "*.c.inc" | sort) C_INCLUDES=$(find include -iname "*.h" | sort) C_SOURCES=$(find lib -maxdepth 3 -iname "*.c" | sort) C_THIRD_PARTY_HLL_SOURCES=$(find lib/third_party/src/hll -iname "*.c" | sort) # extra dist source files (required by nDPI through #include) printf '%s' 'EXTRA_DIST =' >Makefile.am # HLL sources for src in ${C_THIRD_PARTY_HLL_SOURCES}; do printf ' \\\n\t%s' "${src}" >>Makefile.am done # private headers for inc in ${C_INCLUDES_PRV}; do printf ' \\\n\t%s' "${inc}" >>Makefile.am done printf '\n\n' >>Makefile.am printf '%s\n\n' 'includendpidir = $(includedir)/ndpi' >>Makefile.am printf '%s' 'includendpi_HEADERS =' >>Makefile.am # generated headers for inc in ${C_INCLUDES_GEN}; do printf ' \\\n\t%s' "${inc%.in}" >>Makefile.am done # headers for inc in ${C_INCLUDES}; do SKIP_INC=0 for check_inc in ${C_INCLUDES_GEN}; do test "x${inc}.in" != "x${check_inc}" || SKIP_INC=1 done test ${SKIP_INC} -eq 0 || continue printf ' \\\n\t%s' "${inc}" >>Makefile.am done printf '\n\n' >>Makefile.am # libtool init printf '%s\n\n' 'lib_LTLIBRARIES = libndpi.la' >>Makefile.am printf '%s' 'libndpi_la_SOURCES =' >>Makefile.am # add all *.c files found to SOURCES for src in ${C_SOURCES}; do printf ' \\\n\t%s' "${src}" >>Makefile.am done printf '\n\n' >>Makefile.am # libtool CFLAGS / LDFLAGS cat >>Makefile.am <Makefile.am <>Makefile.am done printf '\n\n' >>Makefile.am printf '%s\n%s\n' \ 'fuzz_ndpi_reader_seed_corpus.zip: $(TESTPCAPS)' \ ' zip -r fuzz_ndpi_reader_seed_corpus.zip $(TESTPCAPS)' >>Makefile.am cd "${MYDIR}" } generate_src_am generate_fuzz_am