Bug 181436 - file(1) cannot detect BSD makefiles
Summary: file(1) cannot detect BSD makefiles
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 9.0-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Xin LI
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-20 19:50 UTC by Slaven Rezic
Modified: 2019-01-21 09:21 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Slaven Rezic 2013-08-20 19:50:00 UTC
	Most BSD makefiles are not recognized by /usr/bin/file as
	such. Worse, if less is configured to use lesspipe from the
	ports (misc/lesspipe), then many BSD makefiles are recognized
	as troff files, causing unreadable input.

Fix: 

Maybe adding keywords as ".if", ".include", ".else" etc. as
	BSD makefile keywords before the troff section could help.
How-To-Repeat: 	For example:

	    cd /usr/share/mk
	    /usr/bin/file * | grep -i troff | wc -l

	Or configure less to use lesspipe as per lesspipe's manpage
	(see FILTER ACTIVATION section) and try to use less on any of
	misrecognized BSD makefiles.
Comment 1 eserte12 2015-08-14 19:54:23 UTC
FreeBSD 10.1 is also affected.
Comment 2 Xin LI freebsd_committer freebsd_triage 2015-08-25 05:23:20 UTC
This is still reproducible on -HEAD (file-5.23).

Looks like I can extend magic/Magdir/make to add a few regex to work around this, but it's not clear if that's the right thing to do so I think it's reasonable to add the file(1) author.

The following regex may be useful:

\^PROG=
\^PROG_CXX=
\^MAN
\^\.include\ <

etc.
Comment 3 Christos Zoulas 2015-08-25 07:37:14 UTC
I aded some patterns on HEAD of magic/Magdir/make...
Comment 4 commit-hook freebsd_committer freebsd_triage 2015-09-04 05:57:16 UTC
A commit references this bug:

Author: delphij
Date: Fri Sep  4 05:56:18 UTC 2015
New revision: 287453
URL: https://svnweb.freebsd.org/changeset/base/287453

Log:
  MFV r287451 + 287452: file 5.24 + fix for bin/181436.

  PR:		181436
  MFC after:	2 weeks

Changes:
_U  head/contrib/file/
  head/contrib/file/ChangeLog
  head/contrib/file/configure
  head/contrib/file/configure.ac
  head/contrib/file/magic/Magdir/database
  head/contrib/file/magic/Magdir/elf
  head/contrib/file/magic/Magdir/fortran
  head/contrib/file/magic/Magdir/mail.news
  head/contrib/file/magic/Magdir/make
  head/contrib/file/magic/Magdir/map
  head/contrib/file/src/file.c
  head/contrib/file/src/funcs.c
  head/contrib/file/src/readelf.c
  head/lib/libmagic/config.h
Comment 5 Xin LI freebsd_committer freebsd_triage 2015-09-04 05:58:10 UTC
Patched in -HEAD.
Comment 6 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:42:11 UTC
batch change:

For bugs that match the following
-  Status Is In progress 
AND
- Untouched since 2018-01-01.
AND
- Affects Base System OR Documentation

DO:

Reset to open status.


Note:
I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.
Comment 7 eserte12 2018-05-28 20:10:43 UTC
(In reply to Christos Zoulas from comment #3)

While the situation is a little bit better now (especially with inclusion of ".include") still many (all?) ".if" containing BSD makefiles are recognized as troff files --- I guess this is due to the magic line

    0       regex/20l       \^\\.[A-Za-z0-9][A-Za-z0-9][\ \t]       troff or preprocessor input text
Comment 8 Christos Zoulas 2018-05-29 17:36:57 UTC
should be fixed in HEAD.
Comment 9 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2019-01-21 09:21:02 UTC
There is a commit referencing this PR, but it's still not closed and has been inactive for some time. Closing the PR as fixed but feel free to re-open it if the issue hasn't been completely resolved.

Thanks