Download raw body.
portcheck, check Makefile variables are set in the same order as Makefile.template
portcheck, check Makefile variables are set in the same order as Makefile.template
I think this is going too far
--
Sent from a phone, apologies for poor formatting.
On 21 May 2024 21:19:08 Fabien ROMANO <fabienromano@gmail.com> wrote:
> I would like to bring more consistencies in ports' Makefile by following
> Makefile.template.
>
> /usr/ports/infrastructure/bin/portcheck -A
>> scanning ports under the /usr/ports
>> ...
>> archivers/ancient/Makefile : CONFIGURE_STYLE should be before
>> AUTOCONF_VERSION and after BUILD_DEPENDS
>> archivers/arc/Makefile : WANTLIB should be before SITES and after
>> PERMIT_PACKAGE
>> archivers/bzip2/Makefile : SHARED_LIBS should be before CATEGORIES and
>> after DISTNAME
>> archivers/bzip2/Makefile : TEST_FLAGS should be before DEBUG_PACKAGES and
>> after MAKE_FLAGS
>> archivers/cabextract/Makefile : SEPARATE_BUILD should be before
>> CONFIGURE_STYLE and after LIB_DEPENDS
>> archivers/freeze/Makefile : PERMIT_PACKAGE should be before SITES and after
>> CATEGORIES
>> archivers/freeze/Makefile : PERMIT_DISTFILES should be before SITES and
>> after CATEGORIES
>> archivers/freeze/Makefile : WANTLIB should be before SITES and after CATEGORIES
>> archivers/freeze/Makefile : MAKE_FLAGS should be before CONFIGURE_STYLE and
>> after WANTLIB
>> ...
>
> First time on ksh and I have limited knowledge on awk/sed.
> It's a poc at this stage, at least I would like to rewrite
> makefile_template definition.
>
> Any opinion on the feature or other checks which would be of interest ?
>
>
> Index: portcheck
> ===================================================================
> RCS file: /cvs/ports/infrastructure/bin/portcheck,v
> diff -u -p -r1.146 portcheck
> --- portcheck 12 Oct 2023 05:41:27 -0000 1.146
> +++ portcheck 21 May 2024 18:14:08 -0000
> @@ -320,6 +320,29 @@ EOF
> )
>
> ############################################################
> +# List of variables from Makefile.template
> +#
> +
> +rootdir=$portsdir
> +makefile_template=
> +while [[ ! -e $rootdir/infrastructure/templates/Makefile.template ]]; do
> + rootdir="${rootdir%/*}"
> + if [[ -z $rootdir ]]; then
> + break
> + fi
> +done
> +if [[ ! -z $rootdir ]]; then
> + set -A makefile_template $(
> + grep '=' $rootdir/infrastructure/templates/Makefile.template |
> + grep -v -e '# ' -e '==' |
> + awk '{ print $1; }' |
> + sed -e 's/#//' -e 's/=//' |
> + awk '!seen[$0]++')
> +else
> + echo "no Makefile.template found, skip Makefile variables order check"
> +fi
> +
> +############################################################
> # Check and fail routines
> #
>
> @@ -1808,6 +1831,7 @@ check_subst_vars() {
> # * No user settings present.
> # * SHARED_ONLY not defined
> # * Check for usage of obsolete PERMIT_PACKAGE_* and PERMIT_DISTFILES_FTP
> +# * Check variables are set in the same order as Makefile.template
> check_makefile() {
> $debugging && echo "CALLED: check_makefile($*)" >&2
>
> @@ -1818,7 +1842,8 @@ check_makefile() {
> grep -q '\$OpenBSD.*\$' "$F" &&
> err "$F should not contain \$OpenBSD\$ tag"
>
> - local iflevel=0 l lnum=0 revs= t r mkvars= var duprevfound
> + local iflevel=0 l lnum=0 t r var duprevfound p i j
> + local revs= mkvars= tplvars= tplidx=
> # do not unset mkvars, having empty element(-s) is fine
> unset revs[0]
> local tab="$(print '\t')"
> @@ -1891,6 +1916,43 @@ check_makefile() {
> mkvars[${#mkvars[@]}]=$var
> fi
> done <"$F"
> +
> + if [[ -z ${makefile_template[@]} ]]; then
> + return
> + fi
> +
> + for v in "${mkvars[@]}"; do
> + for t in `jot $((${#makefile_template[@]}-1))`; do
> + if [[ $v == ${makefile_template[$t]} ]]; then
> + tplvars[${#tplvars[@]}]=$v
> + tplidx[${#tplidx[@]}]=$t
> + fi
> + done
> + done
> + if [[ -z ${tplvars[@]} ]]; then
> + return
> + fi
> +
> + p=0
> + for i in `jot $((${#tplvars[@]}-1))`; do
> + if [[ ${tplidx[$i]} -lt $p ]]; then
> + if [[ ${tplidx[$i]} -lt ${tplidx[1]} ]]; then
> + err "$F : ${tplvars[$i]} should be" \
> + "before ${tplvars[1]}"
> + continue
> + fi
> + for j in `jot $((${#tplvars[@]}-1))`; do
> + if [[ ${tplidx[$i]} -lt ${tplidx[$j]} ]]; then
> + err "$F : ${tplvars[$i]} should be" \
> + "before ${tplvars[$j]} and" \
> + "after ${tplvars[$(($j-1))]}"
> + break
> + fi
> + done
> + else
> + p=${tplidx[$i]}
> + fi
> + done
> }
>
> # Checks made:
portcheck, check Makefile variables are set in the same order as Makefile.template
portcheck, check Makefile variables are set in the same order as Makefile.template