diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -155,6 +155,7 @@ TGTS= all all-man buildenv buildenvvars buildetc buildkernel buildworld \ check check-old check-old-dirs check-old-files check-old-libs \ + check-symbols \ checkdpadd checkworld clean cleandepend cleandir cleankernel \ cleanworld cleanuniverse \ delete-old delete-old-dirs delete-old-files delete-old-libs \ diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk --- a/share/mk/bsd.lib.mk +++ b/share/mk/bsd.lib.mk @@ -375,6 +375,38 @@ ${SHLIB_NAME}.debug: ${SHLIB_NAME_FULL} ${OBJCOPY} --only-keep-debug ${SHLIB_NAME_FULL} ${.TARGET} .endif + +CLEANFILES+= ${SHLIB_NAME}.symbols +${SHLIB_NAME}.symbols: ${SHLIB_NAME_FULL} + (printf "%sgenerated by bsd.lib.mk\n" @; \ + objdump -T ${.ALLSRC} | grep -v '\*UND\*' | cut -f 2 | grep '^0' | \ + sed -e 's/^[0-9a-z]* *//' | \ + awk '{ if ($$2 == "") { print $$1 " " } else if ($$3 == "") { print $$2 " " $$1 } else { print $$3 " " $$1 } }' | \ + sort) > ${.TARGET} + +.if defined(SYMBOLS_REF_MD) +_SYMBOLS_REF_ARCH=-${MACHINE_ARCH} +.else +_SYMBOLS_REF_ARCH= +.endif +SYMBOLS_REF?= ${.CURDIR}/${SHLIB_NAME}.symref${_SYMBOLS_REF_ARCH} +.if ${.TARGETS:Mcheck-symbols} +_CHECK_SYMBOLS_WARNING?=echo +.else +_CHECK_SYMBOLS_WARNING?=true +.endif +check-symbols: ${SHLIB_NAME}.symbols ${_SYMBOLS_REF} + @if [ ! -e ${SYMBOLS_REF} ]; then \ + ${_CHECK_SYMBOLS_WARNING} "WARNING: no symbol reference (${SYMBOLS_REF:T}), run 'make update-symref'" 1>&2; \ + else \ + if ! diff ${SYMBOLS_REF} ${SHLIB_NAME}.symbols; then \ + echo "ERROR: symbol set changed, correct or run 'make update-symref'" 1>&2; \ + false; \ + fi \ + fi + +update-symref: ${SHLIB_NAME}.symbols + cp ${SHLIB_NAME}.symbols ${SYMBOLS_REF} .endif #defined(SHLIB_NAME) .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) diff --git a/share/mk/bsd.subdir.mk b/share/mk/bsd.subdir.mk --- a/share/mk/bsd.subdir.mk +++ b/share/mk/bsd.subdir.mk @@ -41,7 +41,8 @@ SUBDIR_TARGETS+= \ all all-man analyze buildconfig buildfiles buildincludes \ - checkdpadd clean cleandepend cleandir cleanilinks \ + checkdpadd check-symbols \ + clean cleandepend cleandir cleanilinks \ cleanobj depend distribute files includes installconfig \ installdirs \ installfiles installincludes print-dir realinstall \