diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk --- a/sys/conf/kmod.mk +++ b/sys/conf/kmod.mk @@ -223,6 +223,13 @@ SRCS+=${SRCS.${_o}} .endfor +# Add in version information +VERSION_MODNAME=${KMOD:S/-/_/g} +VERSION_FILE=${VERSION_MODNAME}_vers.c +VERSION_OBJ=${VERSION_FILE:R:S/$/.o/} +SRCS+=${VERSION_FILE} +CLEANFILES+=${VERSION_FILE} + OBJS+= ${SRCS:N*.h:R:S/$/.o/g} .if !defined(PROG) @@ -417,6 +424,15 @@ # Respect configuration-specific C flags. CFLAGS+= ${ARCH_FLAGS} ${CONF_CFLAGS} +NEWVERS_ENV+= MAKE="${MAKE}" +NEWVERS_ARGS= -m "${VERSION_MODNAME}" +.if ${MK_REPRODUCIBLE_BUILD} != "no" +NEWVERS_ARGS+= -R +.endif +${VERSION_FILE}: .NOMETA_CMP ${SYSDIR}/conf/newvers.sh ${SYSDIR}/sys/param.h \ + ${OBJS:N${VERSION_OBJ}} ${BLOB_OBJS} + ${NEWVERS_ENV} sh ${SYSDIR}/conf/newvers.sh ${NEWVERS_ARGS} + .if !empty(SRCS:Mvnode_if.c) CLEANFILES+= vnode_if.c vnode_if.c: ${SYSDIR}/tools/vnode_if.awk ${SYSDIR}/kern/vnode_if.src diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh --- a/sys/conf/newvers.sh +++ b/sys/conf/newvers.sh @@ -33,6 +33,8 @@ # # -c Print the copyright / license statement as a C comment and exit # +# -m Module to build version information for. +# # -r Reproducible build. Do not embed directory names, user names, # time stamps or other dynamic information into the output file. # This is intended to allow two builds done at different times @@ -112,12 +114,16 @@ # future value of modified. include_metadata=yes modified=no -while getopts crRvV: opt; do +modv= +while getopts cm:rRvV: opt; do case "$opt" in c) echo "$COPYRIGHT" exit 0 ;; + m) + modv="$OPTARG" + ;; r) include_metadata=no ;; @@ -298,8 +304,19 @@ VERSTR="${VERINFO}\\n ${u}@${h}:${d}\\n" fi +if [ -n "$modv" ]; then + modinfo=1 + modprefix="${modv}_" +else + modinfo=0 + modprefix="" +fi + vers_content_new=$(cat << EOF $COPYRIGHT + +#define VERS_C_MODINFO ${modinfo} + /* * The SCCS stuff is a marker that by convention identifies the kernel. While * the convention originated with SCCS, the current use is more generic and is @@ -312,18 +329,29 @@ #define VERSTR "${VERSTR}" #define RELSTR "${RELEASE}" -const char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR; -const char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR; -const char compiler_version[] = "${compiler_v}"; -const char ostype[] = "${TYPE}"; -const char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR; -const int osreldate = ${RELDATE}; +#if VERS_C_MODINFO +extern const char ${modprefix}sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128]; +extern const char ${modprefix}version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256]; +extern const char ${modprefix}compiler_version[]; +extern const char ${modprefix}ostype[]; +extern const char ${modprefix}osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32]; +extern const int ${modprefix}osreldate; +#endif + +const char ${modprefix}sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR; +const char ${modprefix}version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR; +const char ${modprefix}compiler_version[] = "${compiler_v}"; +const char ${modprefix}ostype[] = "${TYPE}"; +const char ${modprefix}osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR; +const int ${modprefix}osreldate = ${RELDATE}; +#if !VERS_C_MODINFO const char kern_ident[] = "${i}"; +#endif EOF ) -vers_content_old=$(cat vers.c 2>/dev/null || true) +vers_content_old=$(cat ${modprefix}vers.c 2>/dev/null || true) if [ "$vers_content_new" != "$vers_content_old" ]; then - printf "%s\n" "$vers_content_new" > vers.c + printf "%s\n" "$vers_content_new" > ${modprefix}vers.c fi echo $((v + 1)) > version