genconfigheader: use lazysponge for file management
Remove file management from `genconfigheader` script and use `lazysponge` in Makefile.include. Use --verbose option when in non QUIET building mode.
This commit is contained in:
parent
94f2a499a3
commit
cc63d2d21c
@ -680,7 +680,8 @@ include $(RIOTTOOLS)/desvirt/Makefile.desvirt
|
|||||||
# The script will only touch the file if anything has changed since last time.
|
# The script will only touch the file if anything has changed since last time.
|
||||||
$(RIOTBUILD_CONFIG_HEADER_C): FORCE
|
$(RIOTBUILD_CONFIG_HEADER_C): FORCE
|
||||||
@mkdir -p '$(dir $@)'
|
@mkdir -p '$(dir $@)'
|
||||||
$(Q)'$(RIOTTOOLS)/genconfigheader/genconfigheader.sh' '$@' $(CFLAGS_WITH_MACROS)
|
$(Q)'$(RIOTTOOLS)/genconfigheader/genconfigheader.sh' $(CFLAGS_WITH_MACROS) \
|
||||||
|
| '$(LAZYSPONGE)' $(LAZYSPONGE_FLAGS) '$@'
|
||||||
|
|
||||||
CFLAGS_WITH_MACROS := $(CFLAGS)
|
CFLAGS_WITH_MACROS := $(CFLAGS)
|
||||||
|
|
||||||
|
|||||||
60
dist/tools/genconfigheader/genconfigheader.sh
vendored
60
dist/tools/genconfigheader/genconfigheader.sh
vendored
@ -7,43 +7,18 @@
|
|||||||
# Public License v2.1. See the file LICENSE in the top level directory for more
|
# Public License v2.1. See the file LICENSE in the top level directory for more
|
||||||
# details.
|
# details.
|
||||||
#
|
#
|
||||||
|
# Usage: $0 [CFLAGS]...
|
||||||
DEBUG=0
|
#
|
||||||
if [ "${QUIET}" != "1" ]; then
|
# Extract all macros from CFLAGS and generate a header file format"
|
||||||
DEBUG=1
|
#
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $# -lt 1 ]; then
|
|
||||||
echo "Usage: $0 <output.h> [CFLAGS]..."
|
|
||||||
echo "Extract all macros from CFLAGS and generate a header file"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
OUTPUTFILE="$1"
|
|
||||||
shift
|
|
||||||
|
|
||||||
MD5SUM=md5sum
|
|
||||||
if [ "$(uname -s)" = "Darwin" -o "$(uname -s)" = "FreeBSD" ]; then
|
|
||||||
MD5SUM="md5 -r"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# atomically update the file
|
|
||||||
TMPFILE=
|
|
||||||
trap '[ -n "${TMPFILE}" ] && rm -f "${TMPFILE}"' EXIT
|
|
||||||
# Create temporary output file
|
|
||||||
TMPFILE=$(mktemp ${OUTPUTFILE}.XXXXXX)
|
|
||||||
|
|
||||||
if [ -z "${TMPFILE}" ]; then
|
|
||||||
echo "Error creating temporary file, aborting"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# exit on any errors below this line
|
# exit on any errors below this line
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "/* DO NOT edit this file, your changes will be overwritten and won't take any effect! */" > "${TMPFILE}"
|
echo "/* DO NOT edit this file, your changes will be overwritten and won't take any effect! */"
|
||||||
echo "/* Generated from CFLAGS: $@ */" >> "${TMPFILE}"
|
echo "/* Generated from CFLAGS: $@ */"
|
||||||
|
|
||||||
[ -n "${LTOFLAGS}" ] && echo "/* LTOFLAGS=${LTOFLAGS} */" >> "${TMPFILE}"
|
[ -n "${LTOFLAGS}" ] && echo "/* LTOFLAGS=${LTOFLAGS} */"
|
||||||
|
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
case ${arg} in
|
case ${arg} in
|
||||||
@ -54,34 +29,19 @@ for arg in "$@"; do
|
|||||||
# key=value pairs
|
# key=value pairs
|
||||||
key=${d%%=*}
|
key=${d%%=*}
|
||||||
value=${d#*=}
|
value=${d#*=}
|
||||||
echo "#define $key $value" >> "${TMPFILE}"
|
echo "#define $key $value"
|
||||||
else
|
else
|
||||||
# simple #define
|
# simple #define
|
||||||
echo "#define $d 1" >> "${TMPFILE}"
|
echo "#define $d 1"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-U*)
|
-U*)
|
||||||
# Strip leading -U
|
# Strip leading -U
|
||||||
d=${arg#-U}
|
d=${arg#-U}
|
||||||
echo "#undef $d" >> "${TMPFILE}"
|
echo "#undef $d"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Only replace old file if the new file differs. This allows make to check the
|
|
||||||
# date of the config header for dependency calculations.
|
|
||||||
NEWMD5=$(${MD5SUM} ${TMPFILE} | cut -c -32)
|
|
||||||
OLDMD5=$(${MD5SUM} ${OUTPUTFILE} 2>/dev/null | cut -c -32)
|
|
||||||
if [ "${NEWMD5}" != "${OLDMD5}" ]; then
|
|
||||||
if [ "${DEBUG}" -eq 1 ]; then echo "Replacing ${OUTPUTFILE} (${NEWMD5} != ${OLDMD5})"; fi
|
|
||||||
# Set mode according to umask
|
|
||||||
chmod +rw "${TMPFILE}"
|
|
||||||
mv -f "${TMPFILE}" "${OUTPUTFILE}"
|
|
||||||
else
|
|
||||||
if [ "${DEBUG}" -eq 1 ]; then echo "Keeping old ${OUTPUTFILE}"; fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# $TMPFILE will be deleted by the EXIT trap above if it still exists when we exit
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user