From 941c75a2b2b674e88bff25ad8f6333097306dcb0 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Tue, 26 May 2020 14:13:31 -0700 Subject: [PATCH] Makefile portability improvement, build nasmdoc.pdf.xz Significantly improve the portability/reliability of a general make command. Build a .pdf.xz version of the documentation, using an uncompressed pdf as basis. Signed-off-by: H. Peter Anvin (Intel) --- Makefile.in | 55 ++++++++++++++++++++++++++++++++++++++---------------- configure.ac | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++------ doc/Makefile.in | 49 ++++++++++++++++++++++++++++++++++++++---------- doc/pspdf.pl | 8 +++++--- 4 files changed, 135 insertions(+), 35 deletions(-) diff --git a/Makefile.in b/Makefile.in index 68ec9d45..7cc210e2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -47,13 +47,18 @@ INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ +# Optional tools NROFF = @NROFF@ ASCIIDOC = @ASCIIDOC@ XMLTO = @XMLTO@ +MAKENSIS = @MAKENSIS@ +XZ = @XZ@ -MAKENSIS = makensis +# Optional targets +MANPAGES = @MANPAGES@ +NSIS = @NSIS@ -MKDIR = mkdir -p +MKDIR_P = @MKDIR_P@ RM_F = rm -f RM_RF = rm -rf LN_S = @LN_S@ @@ -74,7 +79,7 @@ endif .PHONY: all doc rdf install clean distclean cleaner spotless install_rdf test .PHONY: install_doc everything install_everything strip perlreq dist tags TAGS -.PHONY: manpages nsis +.PHONY: nothing manpages nsis .c.$(O): $(CC) -c $(ALL_CFLAGS) -o $@ $< @@ -147,10 +152,14 @@ XSUBDIRS = test doc nsis rdoff DEPDIRS = . include config x86 rdoff $(SUBDIRS) #-- End File Lists --# -all: nasm$(X) ndisasm$(X) rdf +all: dirs + $(MAKE) nasm$(X) ndisasm$(X) rdf NASMLIB = libnasm.$(A) +dirs: + $(MKDIR_P) $(SUBDIRS) $(XSUBDIRS) + $(NASMLIB): $(LIBOBJ) $(RM_F) $(NASMLIB) $(AR) cq $(NASMLIB) $(LIBOBJ) @@ -249,7 +258,7 @@ x86/regs.h: x86/regs.dat x86/regs.pl WARNFILES = asm/warnings.c include/warnings.h doc/warnings.src warnings: - rm -f $(WARNFILES) + $(RM_F) $(WARNFILES) $(MAKE) $(WARNFILES) asm/warnings.c: asm/warnings.pl @@ -348,8 +357,6 @@ $(RDFLIB): $(RDFLIBOBJ) #-- Begin NSIS Rules --# -# NSIS is not built except by explicit request, as it only applies to -# Windows platforms nsis/arch.nsh: nsis/getpearch.pl nasm$(X) $(PERL) $(srcdir)/nsis/getpearch.pl nasm$(X) > nsis/arch.nsh @@ -365,10 +372,10 @@ nsis: nsis/nasm.nsi nsis/arch.nsh nsis/version.nsh manpages: nasm.1 ndisasm.1 install: nasm$(X) ndisasm$(X) - $(MKDIR) $(DESTDIR)$(bindir) + $(MKDIR_P) $(DESTDIR)$(bindir) $(INSTALL_PROGRAM) nasm$(X) $(DESTDIR)$(bindir)/nasm$(X) $(INSTALL_PROGRAM) ndisasm$(X) $(DESTDIR)$(bindir)/ndisasm$(X) - $(MKDIR) $(DESTDIR)$(mandir)/man1 + $(MKDIR_P) $(DESTDIR)$(mandir)/man1 $(INSTALL_DATA) $(srcdir)/nasm.1 $(DESTDIR)$(mandir)/man1/nasm.1 $(INSTALL_DATA) $(srcdir)/ndisasm.1 $(DESTDIR)$(mandir)/man1/ndisasm.1 @@ -417,7 +424,7 @@ cscope: cscope -b -f cscope.out rdf_install install_rdf install_rdoff: - $(MKDIR) $(DESTDIR)$(bindir) + $(MKDIR_P) $(DESTDIR)$(bindir) for f in $(RDFPROGS); do \ $(INSTALL_PROGRAM) "$$f" '$(DESTDIR)$(bindir)'/ ; \ done @@ -426,7 +433,7 @@ rdf_install install_rdf install_rdoff: bn=`basename "$$f"` && $(RM_F) "$$bn" && \ $(LN_S) rdf2bin$(X) "$$bn" ; \ done - $(MKDIR) $(DESTDIR)$(mandir)/man1 + $(MKDIR_P) $(DESTDIR)$(mandir)/man1 $(INSTALL_DATA) $(srcdir)/rdoff/*.1 $(DESTDIR)$(mandir)/man1/ doc: doc/warnings.src @@ -435,19 +442,27 @@ doc: doc/warnings.src doc_install install_doc: $(MAKE) -C doc install -everything: all manpages doc rdf +# Dummy target to prevent accidental invocation of the default "all" target +nothing: + +always_everything: all doc rdf + +everything: always_everything + $(MAKE) $(MANPAGES) $(NSIS) nothing install_everything: everything install install_doc install_rdf dist: $(MAKE) alldeps - $(MAKE) spotless perlreq manpages spec + $(MAKE) spotless perlreq manpages spec $(MANPAGES) autoheader autoconf $(RM_RF) ./autom4te*.cache tar: dist - tar -cvj --exclude CVS -C .. -f ../nasm-`cat version`-`date +%Y%m%d`.tar.bz2 `basename \`pwd\`` + tar -cv --exclude CVS -C .. -f - | \ + $(XZ) -9e > \ + ../nasm-`cat version`-`date +%Y%m%d`.tar.xz `basename \`pwd\`` spec: nasm.spec @@ -456,11 +471,11 @@ ALLPERLSRC := $(shell find $(srcdir) -type f -name '*.p[lh]') perlbreq.si: $(ALLPERLSRC) sed -n -r -e 's/^[[:space:]]*use[[:space:]]+([^[:space:];]+).*$$/BuildRequires: perl(\1)/p' $(ALLPERLSRC) | \ sed -r -e '/perl\((strict|warnings|Win32.*)\)/d' | \ - sort | uniq > perlbreq.si || ( rm -f perlbreq.si ; false ) + sort | uniq > perlbreq.si nasm.spec: nasm.spec.in nasm.spec.sed version.sed perlbreq.si sed -f version.sed -f nasm.spec.sed \ - < nasm.spec.in > nasm.spec || ( rm -f nasm.spec ; false ) + < nasm.spec.in > nasm.spec splint: splint -weak *.c @@ -495,6 +510,14 @@ doc/Makefile: Makefile config/config.h: config.status # +# Dummy rules that changes make behavior +# (at end to avoid confusing non-GNU makes) +# +.SECONDARY: + +.DELETE_ON_ERROR: + +# # Does this version of this file have external dependencies? This definition # will be automatically updated by mkdep.pl as needed. # diff --git a/configure.ac b/configure.ac index 600056da..777b364b 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,9 @@ dnl the best very slow and doesn't buy us a single thing at all. WINELOADER=/dev/null export WINELOADER +dnl Get the canonical target system name +AC_CANONICAL_HOST + dnl Checks for programs and enable necessary CC extensions AC_USE_SYSTEM_EXTENSIONS AC_SYS_LARGEFILE @@ -23,6 +26,7 @@ AC_PROG_CC_STDC AC_PROG_LN_S AC_PROG_MAKE_SET AC_PROG_INSTALL +AC_PROG_MKDIR_P pa_no_optimize=false @@ -87,14 +91,56 @@ dnl Look for programs... AC_CHECK_PROGS(NROFF, nroff, false) AC_CHECK_PROGS(ASCIIDOC, asciidoc, false) AC_CHECK_PROGS(XMLTO, xmlto, false) +AC_CHECK_PROGS(XZ, xz, false) dnl Check for progs needed for manpage generation -AS_IF([test $ASCIIDOC = false], - [AC_MSG_WARN([No asciidoc package found])] +MANPAGES=manpages +AS_IF([test x$ASCIIDOC = xfalse], + [AC_MSG_WARN([No asciidoc package found, cannot build man pages]) + MANPAGES=''] ) -AS_IF([test $XMLTO = false], - [AC_MSG_WARN([No xmlto package found])] +AS_IF([test x"$XMLTO" = xfalse], + [AC_MSG_WARN([No xmlto package found, cannot build man pages]) + MANPAGES=''] ) +AC_SUBST([MANPAGES]) + +dnl Don't create .pdf.xz if there is no xz +AS_IF([test x"$XZ" = xfalse], + [], + [XZFILES=xzfiles]) +AC_SUBST([XZFILES]) + +dnl Can't create NSIS package if there is no makensis +dnl ... but it only applies to a Windows target ... +dnl Note: AC_CHECK_TOOLS is supposed to check for the "plain" +dnl version of the program name, but it doesn't seem to. +AC_ARG_WITH([nsis], +[AS_HELP_STRING([[--with-nsis[=makensis]]], + [build an install .exe using NSIS on Windows hosts])], + [], [with_nsis=yes]) +AS_IF([test x"$MAKENSIS" = x], [], + [AS_IF([test x"$with_nsis" = xno], [] + [with_nsis="$MAKENSIS"])]) + +MAKENSIS=false + +AS_CASE([$host], + [*-win* | *-mingw*], + [AS_IF([test x"$with_nsis" = xno], [], + [NSIS=nsis + AS_IF([test x"$with_nsis" = xyes], + [AC_CHECK_TOOL(MAKENSIS_TOOL, makensis, false) + MAKENSIS="$MAKENSIS_TOOL" + AS_IF([test x"$MAKENSIS" = xfalse], + [AC_CHECK_PROGS(MAKENSIS_PLAIN, makensis, false) + MAKENSIS="$MAKENSIS_PLAIN"]) + AS_IF([test x"$MAKENSIS" = xfalse], + [AC_MSG_WARN([no makensis found, cannot build installer]) + NSIS=''])], + [MAKENSIS="$with_nsis"])])]) +AC_SUBST([MAKENSIS]) +AC_SUBST([NSIS]) dnl Check for host compiler tools AC_CHECK_TOOL(AR, ar) @@ -327,5 +373,5 @@ dnl support ccache dnl PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], []) -AC_OUTPUT_COMMANDS([mkdir -p config nasmlib nsis output stdlib x86 asm disasm rdoff macros common]) -AC_OUTPUT(Makefile doc/Makefile) +AC_CONFIG_FILES([Makefile doc/Makefile]) +AC_OUTPUT diff --git a/doc/Makefile.in b/doc/Makefile.in index a076300c..e92437a0 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -2,6 +2,8 @@ # UNIX Makefile for NASM documentation # +@SET_MAKE@ + top_srcdir = @top_srcdir@ srcdir = @srcdir@ VPATH = @srcdir@ @@ -22,29 +24,39 @@ PERL = perl -I$(srcdir) PDFOPT = @PDFOPT@ -MKDIR = mkdir +MKDIR_P = @MKDIR_P@ RM_F = rm -f RM_RF = rm -rf CP_F = cp -f -CP_UF = cp -ufv +CP_UF = cp -uf + +# Optional tools +XZ = @XZ@ + +# Optional targets +XZFILES = @XZFILES@ # Auxiliary files referenced by the HTML files HTMLAUX = nasmdoc.css local.css nasmlogw.png SRCS = nasmdoc.src inslist.src changes.src warnings.src version.src -OUT = html nasmdoc.txt nasmdoc.pdf +OUT = html nasmdoc.txt nasmdoc.pdf $(XZFILES) +XZOUT = nasmdoc.pdf.xz .SUFFIXES: .SUFFIXES: .pfa .ph +.PHONY: all xzfiles html clean spotless install + all: $(OUT) +xzfiles: $(XZOUT) + inslist.src: inslist.pl ../x86/insns.dat $(PERL) $(srcdir)/inslist.pl $(srcdir)/../x86/insns.dat -.PHONY: html nasmdoc.ps html: $(HTMLAUX) - $(MKDIR) -p html + $(MKDIR_P) html for f in $(HTMLAUX); do $(CP_UF) "$(srcdir)/$$f" html/; done $(MAKE) html/nasmdoc0.html @@ -79,20 +91,37 @@ Fontmap: nasmdoc.ps @: Generated by side effect nasmdoc.pdf: nasmdoc.ps pspdf.pl fontpath - $(PERL) $(srcdir)/pspdf.pl $(PDFOPT) nasmdoc.ps nasmdoc.pdf fontpath + $(PERL) $(srcdir)/pspdf.pl \ + $(PDFOPT) $< $@ fontpath + +nasmdoc-raw.pdf: nasmdoc.ps pspdf.pl fontpath + $(PERL) $(srcdir)/pspdf.pl -nocompress \ + $(PDFOPT) $< $@ fontpath + +nasmdoc.pdf.xz: nasmdoc-raw.pdf + $(RM_F) $@ + $(XZ) -9e < $< > $@ clean: -$(RM_F) *.rtf *.hpj *.texi *.gid *.ipf *.dip -$(RM_F) *.aux *.cp *.fn *.ky *.pg *.log *.toc *.tp *.vr -$(RM_F) inslist.src version.src fontpath Fontmap - -$(RM_F) nasmdoc*.ps + -$(RM_F) nasmdoc*.ps nasmdoc-raw.pdf spotless: clean -$(RM_RF) html info - -$(RM_F) *.hlp nasmdoc.txt *.inf *.pdf *.dvi + -$(RM_F) *.hlp nasmdoc.txt *.inf *.pdf *.pdf.xz *.dvi install: all - $(MKDIR) -p $(DESTDIR)$(htmldir) + $(MKDIR_P) $(DESTDIR)$(htmldir) $(INSTALL_DATA) html/* $(DESTDIR)$(htmldir) - $(MKDIR) -p $(DESTDIR)$(docdir) + $(MKDIR_P) $(DESTDIR)$(docdir) $(INSTALL_DATA) nasmdoc.pdf nasmdoc.txt $(DESTDIR)$(docdir) + +# +# Dummy rules that changes make behavior +# (at end to avoid confusing non-GNU makes) +# +.SECONDARY: + +.DELETE_ON_ERROR: diff --git a/doc/pspdf.pl b/doc/pspdf.pl index 569f974b..91986413 100755 --- a/doc/pspdf.pl +++ b/doc/pspdf.pl @@ -18,7 +18,7 @@ while ($ARGV[0] =~ /^-(.*)$/) { my $opt = $1; shift @ARGV; - if ($opt eq '-nocompress') { + if ($opt eq 'nocompress') { $compress = 0; } } @@ -114,11 +114,13 @@ if (defined($fontpath)) { $fpopt = "-sFONTPATH${o}" . join($p, @fplist); } -my $r = system($gs, "-dCompatibilityLevel${o}1.4", +my $r = system($gs, "-dCompatibilityLevel${o}1.3", "-I".File::Spec->curdir(), "-P-", "-dNOPAUSE", "-dBATCH", "-sDEVICE${o}pdfwrite", "-sstdout${o}%stderr", "-sOutputFile${o}${out}", - "-dOptimize${o}true", "-dEmbedAllFonts${o}true", + "-dOptimize${o}true", + "-dEmbedAllFonts${o}true", "-dSubsetFonts${o}true", + "-dMaxSubsetPct${o}100", $fpopt, "-dCompressPages${o}" . ($compress ? 'true' : 'false'), "-dUseFlateCompression${o}true", -- 2.11.4.GIT