Improve support for compressed man pages
cover Improve support for compressed man pages
Hi,
when I looked at the Makefile I noticed it has incomplete compression support. Most notably the screen and uninstall targets didn't support switching to a different compression type. More precisely, uninstall supported only switching from gz or bz2 (but not xz) to uncompressed. The screen target had no explicit compression support and when it worked for compressed files it was pure luck.
The patches 2 and 3 provide new recipes for both targets that can handle any combination of the supported compression types. Any file, installed or source, may be uncompressed or compressed with any of gz, bz2, or xz. Whether you compress before or after screen and uninstall doesn't matter any more.
The other patches add a few minor improvements I'd suggest.
So long,
Alex
---
Alexander Miller (7):
Makefile: Use better xz options
Makefile: Improve uninstall target for compressed man pages
Makefile: Support compressed files for screen target
Makefile: Skip already compressed files in gz/bz2/xz targets
Makefile: Add uncompress target to undo effect of gz/bz2/xz targets
Makefile: Avoid compressing very small files in gz/bz2/xz targets
Makefile: Mention xz in the instructive comment at top
Makefile | 54 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-)
Signature · 6 lines
2.7.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/7 Makefile: Use better xz options
In reply to a message not in the archiveQuoted 1 line
From xz(1):
The selected compression settings determine the memory requirements of the decompressor, thus using a too high preset level might make it painful to decompress the file on an old system with little RAM. Specifically, it's not a good idea to blindly use -9 for everything like it often is with gzip(1) and bzip2(1).
With small files like man pages, a large dictionary doesn't help at all; so set a small dictionary size (1MiB). Also, "with text files having one-byte alignment, setting pb=0 can improve compression slightly." Otherwise the defaults are fine (specifically, the extreme presets don't improve compression here and would be a waste of CPU cycles).
---
I made a few tests and the settings described above which should work well in theory also did so in practice. The only surprise was that the extreme presets actually compressed a little worse. Playing with the "nice" parameter could squeeze out a few more bits, but I don't think that would be appropriate; I don't want to optimize the settings for the current man pages content.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -9,7 +9,7 @@ MANDIR=$(prefix)/share/man GZIP=gzip -9 BZIP2=bzip2 -9 -LZMA=xz -9 +LZMA=xz --lzma2=dict=1M,pb=0 all: screen remove install
Signature · 6 lines
2.7.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/7 Makefile: Improve uninstall target for compressed man pages
In reply to a message not in the archiveNow sources and installed man pages may be in plain/gz/bz2/xz format (independently). Any combination works reliably.
---
I would have preferred find -print0, but sed is line-based. As long as there are no man page filenames with newlines, that's good enough.
--- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile +3 -3
@@ -29,9 +29,9 @@ screen: done uninstall remove: - for i in man?/*; do \ - rm -f $(MANDIR)/"$$i" $(MANDIR)/"$$i".gz $(MANDIR)/"$$i".bz2; \ - done + find man? -mindepth 1 -maxdepth 1 -print | \ + sed -e 's/\.\(gz\|bz2\|xz\)$$//; s/.*/&\n&.gz\n&.bz2\n&.xz/' | \ + (cd $(MANDIR) && xargs -d \\n rm -f) gz: for i in man?; do $(GZIP) "$$i"/*; done
Signature · 6 lines
2.7.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/7 Makefile: Support compressed files for screen target
In reply to a message not in the archiveNow, make screen supports (optional, possibly different) compression of the sources and installed man pages. Thus, allgz/allbz2/allxz/all targets should update correctly even when switching compression types.
---
The formatting of the script is a bit unusual, but I wanted to keep it compact and I think it's still readable. Feel free to add more line breaks to the if blocks or use longer variable names if you don't like it.
--- Makefile | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-)
Makefile +23 -5
@@ -22,11 +22,29 @@ allxz: xz all screen: mkdir -p not_installed for i in man?/*; do \ - if [ $(MANDIR)/"$$i" -nt "$$i" ]; then \ - cmp -s $(MANDIR)/"$$i" "$$i" > /dev/null 2>&1; \ - if [ "$$?" != 0 ]; then mv "$$i" not_installed; fi; \ - fi; \ - done + if b="$${i%.bz2}" && [ "$$b".bz2 = "$$i" ]; then c1=bunzip2; \ + elif b="$${i%.gz}" && [ "$$b".gz = "$$i" ]; then c1=gunzip; \ + elif b="$${i%.xz}" && [ "$$b".xz = "$$i" ]; then c1=unxz; \ + else b="$$i"; c1=; fi; \ + b=$(MANDIR)/"$$b"; \ + if [ "$$b" -nt "$$i" ]; then c2=; \ + elif [ "$$b".bz2 -nt "$$i" ]; then c2=bunzip2; b="$$b.bz2"; \ + elif [ "$$b".gz -nt "$$i" ]; then c2=gunzip; b="$$b.gz"; \ + elif [ "$$b".xz -nt "$$i" ]; then c2=unxz; b="$$b.xz"; \ + else continue; fi; \ + if [ -z "$$c1$$c2" ]; then \ + cmp -s "$$i" "$$b"; \ + elif [ -z "$$c1" ]; then \ + $$c2 -c "$$b" | cmp -s "$$i" -; \ + elif [ -z "$$c2" ]; then \ + $$c1 -c "$$i" | cmp -s - "$$b"; \ + else \ + [ "$$c1" = "$$c2" ] && cmp -s "$$i" "$$b" || \ + $$c1 -c "$$i" | { $$c2 -c "$$b" | \ + cmp -s /dev/fd/3 -; } 3<&0; \ + fi || mv "$$i" not_installed; \ + done; \ + rmdir not_installed 2> /dev/null; true uninstall remove: find man? -mindepth 1 -maxdepth 1 -print | \
Signature · 6 lines
2.7.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/7 Makefile: Skip already compressed files in gz/bz2/xz targets
In reply to a message not in the archive--- Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Makefile +6 -3
@@ -52,13 +52,16 @@ uninstall remove: (cd $(MANDIR) && xargs -d \\n rm -f) gz: - for i in man?; do $(GZIP) "$$i"/*; done + find man? -mindepth 1 -maxdepth 1 -name '*.[gx]z' -o -name '*.bz2' \ + -o -exec $(GZIP) '{}' + bz2: - for i in man?; do $(BZIP2) "$$i"/*; done + find man? -mindepth 1 -maxdepth 1 -name '*.[gx]z' -o -name '*.bz2' \ + -o -exec $(BZIP2) '{}' + xz: - for i in man?; do $(LZMA) "$$i"/*; done + find man? -mindepth 1 -maxdepth 1 -name '*.[gx]z' -o -name '*.bz2' \ + -o -exec $(LZMA) '{}' + # Use with # make HTDIR=/some/dir HTOPTS=whatever html
Signature · 6 lines
2.7.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 6/7 Makefile: Avoid compressing very small files in gz/bz2/xz targets
In reply to a message not in the archiveCompressing very small files has only disadvantages. There is the overhead of running a decompressor, and because of the added file headers they become even bigger.
Since the scan and uninstall targets now properly handle mixing compressed and uncompressed files, it becomes possible to avoid compression where it's not beneficial.
---
If you want to support this feature but disable it by default, you can set NOCOMPRESS_SIZE=0.
--- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Makefile +4 -3
@@ -10,6 +10,7 @@ MANDIR=$(prefix)/share/man GZIP=gzip -9 BZIP2=bzip2 -9 LZMA=xz --lzma2=dict=1M,pb=0 +NOCOMPRESS_SIZE=256 all: screen remove install
@@ -53,15 +54,15 @@ uninstall remove: gz: find man? -mindepth 1 -maxdepth 1 -name '*.[gx]z' -o -name '*.bz2' \ - -o -exec $(GZIP) '{}' + + -o -size +$(NOCOMPRESS_SIZE)c -exec $(GZIP) '{}' + bz2: find man? -mindepth 1 -maxdepth 1 -name '*.[gx]z' -o -name '*.bz2' \ - -o -exec $(BZIP2) '{}' + + -o -size +$(NOCOMPRESS_SIZE)c -exec $(BZIP2) '{}' + xz: find man? -mindepth 1 -maxdepth 1 -name '*.[gx]z' -o -name '*.bz2' \ - -o -exec $(LZMA) '{}' + + -o -size +$(NOCOMPRESS_SIZE)c -exec $(LZMA) '{}' + uncompress: find man? -name '*.gz' -exec gunzip '{}' + \
Signature · 6 lines
2.7.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 7/7 Makefile: Mention xz in the instructive comment at top
In reply to a message not in the archive--- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Makefile +2 -1
@@ -1,7 +1,8 @@ # Do "make screen" first, if you want to protect already installed, # more up-to-date manual pages than the ones included in this package. # Do "make install" to copy the pages to their destination. -# Do "make gz" or "make bz2" first if you use compressed source pages. +# Do "make gz", "make bz2", or "make xz" first if you use compressed +# source pages. DESTDIR= prefix?=/usr
Signature · 6 lines
2.7.3 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Alexander Miller
when I looked at the
MakefileI noticed it has incomplete compression support. Most notably the screen and uninstall targets didn't support switching to a different compression type. More precisely, uninstall supported only switching from gz or bz2 (but not xz) to uncompressed. The screen target had no explicit compression support and when it worked for compressed files it was pure luck.
The patches 2 and 3 provide new recipes for both targets that can handle any combination of the supported compression types. Any file, installed or source, may be uncompressed or compressed with any of gz, bz2, or xz. Whether you compress before or after screen and uninstall doesn't matter any more.
imo, we should just drop all compression support. distros already handle this properly and pick whatever they want/need. if no one is using this code, then it's just sucking up space. -mike
Quoted 2 lines · On Sat, 16 Apr 2016 00:50:58 -0400 Mike Frysinger…
imo, we should just drop all compression support. distros already handle this properly and pick whatever they want/need.
For distros this is useless, of course. I've never used it either. But I guess there are still people installing stuff from sources without using a package manager, and they might find it convenient.
Quoted 2 lines
if no one
is using this code, then it's just sucking up space.
I'm not concerned about the space, but code needs to be maintained. IMO, as long as it works, we can keep it; if it has issues we'd better remove it.
We can drop compression support or do it right - I'm fine with either option. We shouldn't keep the status quo, though.
Alex
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 13 lines · Alexander Miller
Quoted 2 lines · On Sat, 16 Apr 2016 00:50:58 -0400 Mike Frysinger…
imo, we should just drop all compression support. distros already handle this properly and pick whatever they want/need.
For distros this is useless, of course. I've never used it either. But I guess there are still people installing stuff from sources without using a package manager, and they might find it convenient.
Quoted 2 lines
if no one
is using this code, then it's just sucking up space.
Quoted 6 lines
I'm not concerned about the space, but code needs to be maintained. IMO, as long as it works, we can keep it; if it has issues we'd better remove it.
We can drop compression support or do it right - I'm fine with either option. We shouldn't keep the status quo, though.
I'm inclined to say drop it. Would you mind putting together a patch, Alex?
Cheers,
Michael
Signature · 7 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Alexander Miller
Quoted 2 lines · On Sat, 16 Apr 2016 00:50:58 -0400 Mike Frysinger…
if no one
is using this code, then it's just sucking up space.I'm not concerned about the space, but code needs to be maintained. IMO, as long as it works, we can keep it; if it has issues we'd better remove it.
sorry for the ambigious term ... i'm not referring to disk space, but to the code "sucking up space in the Makefiles and our eyes".
Quoted 2 lines
We can drop compression support or do it right - I'm fine with either option. We shouldn't keep the status quo, though.
i'm not advocating for the status quo ;)
-mike
Am 18.04.2016 16:49, schrieb Mike Frysinger:
Quoted 10 lines · Alexander Miller
Quoted 8 lines
Quoted 2 lines · On Sat, 16 Apr 2016 00:50:58 -0400 Mike Frysinger…
if no one
is using this code, then it's just sucking up space.I'm not concerned about the space, but code needs to be maintained. IMO, as long as it works, we can keep it; if it has issues we'd better remove it.
Quoted 8 lines
sorry for the ambigious term ... i'm not referring to disk space, but to the code "sucking up space in the Makefiles and our eyes".
Quoted 2 lines
We can drop compression support or do it right - I'm fine with either option. We shouldn't keep the status quo, though.
i'm not advocating for the status quo ;)
-mike
as one of those people that like to have it directly from source ...
I would advocate for having just one compression type .gz would be ok. space i nowadays not the main concern but it is convinced to have.
re,
wh
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 17 lines · walter harms
Am 18.04.2016 16:49, schrieb Mike Frysinger:
Quoted 16 lines · Alexander Miller
Quoted 8 lines
Quoted 2 lines · On Sat, 16 Apr 2016 00:50:58 -0400 Mike Frysinger…
if no one
is using this code, then it's just sucking up space.I'm not concerned about the space, but code needs to be maintained. IMO, as long as it works, we can keep it; if it has issues we'd better remove it.
sorry for the ambigious term ... i'm not referring to disk space, but to the code "sucking up space in the Makefiles and our eyes".
Quoted 2 lines
We can drop compression support or do it right - I'm fine with either option. We shouldn't keep the status quo, though.
Quoted 6 lines
Quoted 1 line
i'm not advocating for the status quo ;)
as one of those people that like to have it directly from source ...
I would advocate for having just one compression type .gz would be ok. space i nowadays not the main concern but it is convinced to have.
in my experience, the majority of packages nowadays don't try to "help" you out and automatically compress installed man pages. so why should man-pages do it ? you already either (1) have a custom solution or (2) have uncompressed pages installed.
-mike
Quoted 7 lines · On Mon, 18 Apr 2016 13:57:54 +0100 Michael Kerrisk wrote:
Quoted 6 lines · Alexander Miller
Quoted 2 lines · On Sat, 16 Apr 2016 00:50:58 -0400 Mike Frysinger…
imo, we should just drop all compression support. distros already handle this properly and pick whatever they want/need.
[...]
Quoted 6 lines
Quoted 3 lines
We can drop compression support or do it right - I'm fine with either option. We shouldn't keep the status quo, though.
I'm inclined to say drop it. Would you mind putting together a patch, Alex?
I'm not sure what exactly we should do.
The problem isn't really compressing the files, but the "screen" and "uninstall" targets.
If we drop support for compressing man pages ourselves, what shall we do with those targets? They aren't useful for distros either. And they *still* might have to deal with files compressed by the distro's package manager (if a user tries to update manually). We could
- drop "screen" and/or "uninstall", too
(getting rid of the problem and simplifying the Makefile but being inconvenient for users);
- fix them to handle man pages compressed by the distro (but not compressed sources, resulting in only slightly simpler patches than those I've posted);
- or explicitly state "screen" (and maybe "uninstall") don't support compressed files. This is problematic IMO, especially since they are used by "make all". Moreover, "uninstall" can remove .gz/.bz2 files but no .xz files right now; this could be changed to include .xz or to exclude .gz/.bz2.
What do you want me to drop/fix with a new patch?
Alex
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 20 lines · Alexander Miller
Quoted 7 lines · On Mon, 18 Apr 2016 13:57:54 +0100 Michael Kerrisk wrote:
Quoted 6 lines · Alexander Miller
Quoted 2 lines · On Sat, 16 Apr 2016 00:50:58 -0400 Mike Frysinger…
imo, we should just drop all compression support. distros already handle this properly and pick whatever they want/need.
[...]
Quoted 6 lines
Quoted 3 lines
We can drop compression support or do it right - I'm fine with either option. We shouldn't keep the status quo, though.
I'm inclined to say drop it. Would you mind putting together a patch, Alex?
I'm not sure what exactly we should do.
The problem isn't really compressing the files, but the "screen" and "uninstall" targets.
Quoted 16 lines
If we drop support for compressing man pages ourselves, what shall we do with those targets? They aren't useful for distros either. And they *still* might have to deal with files compressed by the distro's package manager (if a user tries to update manually). We could
- drop "screen" and/or "uninstall", too
(getting rid of the problem and simplifying theMakefilebut being inconvenient for users);
- fix them to handle man pages compressed by the distro (but not compressed sources, resulting in only slightly simpler patches than those I've posted);
- or explicitly state "screen" (and maybe "uninstall") don't support compressed files. This is problematic IMO, especially since they are used by "make all". Moreover, "uninstall" can remove .gz/.bz2 files but no .xz files right now; this could be changed to include .xz or to exclude .gz/.bz2.
imo, drop the screen target. for uninstall, that's a semi-common idiom that packages have (and autotools supports out of the box). keeping that sounds fine.
i don't think we need to worry about supporting make uninstall if the package was installed initially by the distro -- you have to deal with version skew of course which pretty much no one does. just make sure make install && make uninstall works sanely.
wrt compression, we could be lazy/greedy here too. when we uninstall locale.5, just rm locale.5*. in practice, this is unlikely to be an issue ...
-mike
Re: [PATCH] Makefile: Drop compression support and screen target
In reply to a message not in the archiveFixup.
---
Sorry, I messed it up.
I forgot to delete the part of the initial comment mentioning screen. please append this to the previous patch and apply them together.
---
Makefile +0 -2
@@ -1,5 +1,3 @@ -# Do "make screen" first, if you want to protect already installed, -# more up-to-date manual pages than the ones included in this package. # Do "make install" to copy the pages to their destination. DESTDIR=
Signature · 4 lines
-- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html