#!/bin/sh

# Name:   check-mkfile
# Author: PABourdin
# Date:   05-Nov-2016
# Description:
#   Remove trailing white spaces in Makefile assignment lines.
# Usage:
#   check-mkfile file1 [file2 [file3 [...]]]

for arg in "$@"
do
	grep -qP '^\s*[^#=]+=.*?\S\s+$' "${arg}"
	if [ $? -eq 0 ] ; then
		sed --follow-symlinks -i -e's/^\(\s*[^#=]\+=.*\S\)\s\+$/\1/g' "${arg}"
	fi
done