Skip to content

Commit

Permalink
build: mkreq: rm duplicate -lfoo flags (re: d01798f, 7d75ed4)
Browse files Browse the repository at this point in the history
(See src/cmd/INIT/README-mamake.md for info on *.req files.)

I've been noticing a lot of duplicate -l flags to the compiler in
the build log, e.g. on macOS, '-last' and '-liconv' repeated three
times when linking ksh. This inelegance is due to how the *.req
files are generated. Now that the code to do that has been
consolidated into a couple of scripts, we can tweak this quite
easily and sanitise the *.req files (which are installed and used
as arch/*/lib/lib/* files).

For example, src/cmd/ksh93/shell.req a.k.a. arch/*/lib/lib/shell,
contents before this change (on macOS):

 -lshell
 -ldll -last -liconv
 -lcmd -lutil -last -liconv
 -last -liconv
 -lnetwork

...and after:

 -lshell
 -last
 -lcmd
 -ldll
 -liconv
 -lnetwork
 -lutil

src/cmd/INIT/mkreq-maplib.sh:
- At the end, do not insert an extra space before the '-l' output;
  a leading space is already present.

src/cmd/INIT/mkreq.sh:
- Instead of 'case' and 'echo', use 'grep' to look for lines that
  start with a space and '-l' (the dependencies of the current
  library). This keeps the results on one line each.
- Pipe the resulting lines through 'sort -u' to remove duplicates.
  • Loading branch information
McDutchie committed Feb 1, 2024
1 parent c4587d1 commit 385289a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/cmd/INIT/README-mamake.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ The effect of `bind` is global, not scoped; it takes effect for all commands
physically following it, regardless of `make``done` nesting level.

There is also a mechanism to communicate library dependency information across Mamfiles and `mamake` invocations.
If a file named *libraryname* in the current directory
or an `${INSTALLROOT}/lib/lib/`*libraryname*`.req` file
If a file named *libraryname*`.req` in the current directory
or an `${INSTALLROOT}/lib/lib/`*libraryname* file
exists, `mamake` processes each of the words in the form `-l`*libraryname* in its contents
as if they were arguments to `bind` commands
and the resulting values are appended to the value of `mam_lib`*libraryname*
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/INIT/mkreq-maplib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ trap 'set +o noglob; rm -rf "$req".exe*' 0
######### Main ##########
# Generate .req file. #
#########################
r='-'
r=' -'
for i in $src
do if $allcc -c $i >/dev/null 2>&1
then rm $(basename $i .c).o &
Expand All @@ -89,4 +89,4 @@ do if $allcc -c $i >/dev/null 2>&1
done
fi
done
echo " $r" > $req.req
echo "$r" > $req.req
9 changes: 3 additions & 6 deletions src/cmd/INIT/mkreq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# #
# This file is part of the ksh 93u+m package #
# Copyright (c) 1984-2012 AT&T Intellectual Property #
# Copyright (c) 2020-2023 Contributors to ksh 93u+m #
# Copyright (c) 2020-2024 Contributors to ksh 93u+m #
# and is licensed under the #
# Eclipse Public License, Version 2.0 #
# #
Expand Down Expand Up @@ -95,13 +95,10 @@ exec >$self.req
echo " -l$self"
for name
do if test -f $INSTALLROOT/lib/lib/$name
then y=$(cat $INSTALLROOT/lib/lib/$name)
case $y in
*-?*) echo "" $y ;;
esac
then grep '^ -l.' $INSTALLROOT/lib/lib/$name
continue
elif test ! -f $INSTALLROOT/lib/lib$name.a
then try_to_link $name -L$INSTALLROOT/lib || try_to_link $name || continue
fi
echo " -l$name"
done
done | sort -u

0 comments on commit 385289a

Please sign in to comment.