Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makefiles: replace character class with plain char #4139

Merged
merged 1 commit into from
Mar 24, 2021

Conversation

kmk3
Copy link
Collaborator

@kmk3 kmk3 commented Mar 24, 2021

When using the "wildcard" internal functions.

This usage has been present since the first "real" commit in the
repository: commit 1379851 ("Baseline firejail 0.9.28").

H_FILE_LIST       = $(sort $(wildcard *.[h]))
C_FILE_LIST       = $(sort $(wildcard *.c))

There is only a single character (i.e.: "h") inside the character class,
so its usage should make no functional difference. It may stem from a
construct that could have originally looked something like this:

C_FILE_LIST       = $(sort $(wildcard *.[ch]))

Which would match both the implementation files and the headers.

From Section 4.4, Using Wildcard Characters in File Names of the
GNU make manual:

A single file name can specify many files using wildcard characters.
The wildcard characters in make are ‘*’, ‘?’ and ‘[…]’, the same as in
the Bourne shell. For example, *.c specifies a list of all the files
(in the working directory) whose names end in ‘.c’.

See also Section 2.13, Pattern Matching Notation of POSIX.1-2017.

Commands used to search, replace and clean up:

$ find . -name .git -prune -o -type f \
  \( -name Makefile -o -name Makefile.in \
  -o -name '*.mk' -o -name '*.mk.in' \) -print0 |
  xargs -0 grep -Fl '$(wildcard *.[h])' | tr '\n' '\000' |
  xargs -0 sed -i.bak -e \
  's/\$(wildcard \*.\[h\])/$(wildcard *.h)/'

$ find . -name .git -prune -o -type f \
  -name '*.bak' -exec rm '{}' +

Note: To make sure that this doesn't actually change anything
functionally, I built firejail-git (AUR) on Artix from master and from
this commit and diffing the resulting files produced no output (other
than showing changes related to the build timestamps).

Misc: Reference to the previous makefile-related changes: commit
2465f92 ("makefiles: make all, clean and distclean PHONY") /
#4024

When using the "wildcard" internal functions.

This usage has been present since the first "real" commit in the
repository: commit 1379851 ("Baseline firejail 0.9.28").

>     H_FILE_LIST       = $(sort $(wildcard *.[h]))
>     C_FILE_LIST       = $(sort $(wildcard *.c))

There is only a single character (i.e.: "h") inside the character class,
so its usage should make no functional difference.  It may stem from a
construct that could have originally looked something like this:

    C_FILE_LIST       = $(sort $(wildcard *.[ch]))

Which would match both the implementation files and the headers.

From Section 4.4, [Using Wildcard Characters in File Names][1] of the
GNU make manual:

> A single file name can specify many files using wildcard characters.
> The wildcard characters in make are ‘*’, ‘?’ and ‘[…]’, the same as in
> the Bourne shell.  For example, *.c specifies a list of all the files
> (in the working directory) whose names end in ‘.c’.

See also Section 2.13, [Pattern Matching Notation][2] of POSIX.1-2017.

Commands used to search, replace and clean up:

    $ find . -name .git -prune -o -type f \
      \( -name Makefile -o -name Makefile.in \
      -o -name '*.mk' -o -name '*.mk.in' \) -print0 |
      xargs -0 grep -Fl '$(wildcard *.[h])' | tr '\n' '\000' |
      xargs -0 sed -i.bak -e \
      's/\$(wildcard \*.\[h\])/$(wildcard *.h)/'

    $ find . -name .git -prune -o -type f \
      -name '*.bak' -exec rm '{}' +

Note: To make sure that this doesn't actually change anything
functionally, I built firejail-git (AUR) on Artix from master and from
this commit and diffing the resulting files produced no output (other
than showing changes related to the build timestamps).

Misc: Reference to the previous makefile-related changes: commit
2465f92 ("makefiles: make all, clean and distclean PHONY") /
netblue30#4024

[1]: https://www.gnu.org/software/make/manual/html_node/Wildcards.html
[2]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
@kmk3 kmk3 requested review from reinerh and netblue30 March 24, 2021 14:15
@kmk3
Copy link
Collaborator Author

kmk3 commented Mar 24, 2021

By the way, the message is rather verbose because I don't know much make and
this usage has confused me for a while, so I thought that I might as well
document my findings.

@netblue30
Copy link
Owner

Let's try it out, thanks!

@netblue30 netblue30 merged commit 20dce35 into netblue30:master Mar 24, 2021
@kmk3 kmk3 deleted the makefiles-rm-cclass branch March 24, 2021 17:35
@kmk3 kmk3 mentioned this pull request Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants