Browse Source

Fix packaging of ODT exporter (org-7.8.02) in Gentoo

* org-odt.el (org-odt-lib-dir): Add docstring.
(org-odt-data-dir): New variable.  Use this variable to
control the locations from which the ODT exporter picks the
OpenDocument styles and schema files from.  Set this variable
explicitly only if the in-built heuristics for locating the
above files fails.
(org-odt-styles-dir-list, org-odt-schema-dir-list): New
variables.  Pay specific attention to (eval-when-compile ...)
form through which Makefile's $(datadir) - contained in
`org-odt-data-dir' - gets compiled in as a "hard coded"
constant.
(org-odt-styles-dir, org-export-odt-schema-dir): Add messages
to aid debugging.

* Makefile (etcdir): Remove this.
(stylesdir): Rename to datadir.
(datadir): Was stylesdir.
(STYLESFILES): Rename to DATAFILES.
(DATAFILES): Was STYLESFILES.  Offer a menu of files that is
available.  Package maintainers can use this list and their
own discretion to cherry-pick what they are willing to install
in their distribution.
(CP): Add recursive flag so that directories listed in
DATAFILES can be copied enbloc.
(install-lisp): Use conditional flag BATCH_EXTRA
(BATCH_EXTRA): "Target-specific variable value" that plumbs
the value of $(datadir) in to org-odt.el via
`org-odt-data-dir'.  See ChangeLog entries for
`org-odt-styles-dir-list' and `org-odt-schema-dir-list'.
(BATCH): Add BATCH_EXTRA.
(lisp/org-odt.elc): Force re-generation of this target every
time so that $(datadir) gets plumbed in to org-odt.el through
`org-odt-data-dir'.
(org-odt-data-dir): "FORCE" target.  Also a variable defined
in org-odt.el.
(install-etc): Rename this target to install-data.
(install-data): Was install-etc.

Fix for the following report:
http://lists.gnu.org/archive/html/emacs-orgmode/2011-12/msg00799.html

Ulrich Mueller <ulm@gentoo.org> writes:
  In Gentoo we have an issue with the location of the
  OpenDocument style files, reported to us in bug 396269 [1].

  When org-mode is installed as a separate Gentoo package, its
  lisp files are installed in
  /usr/share/emacs/site-lisp/org-mode/.  According to our
  policy, non-lisp files would go to
  /usr/share/emacs/etc/org-mode/. We would pass this as the
  "etcdir" parameter to "make install", so the odt style files
  would be installed in stylesdir =
  /usr/share/emacs/etc/org-mode/styles/.

  Now org-odt.el currently defines org-odt-styles-dir in a
  defconst, and it searches only in ../etc/styles/,
  ./etc/styles/, and ./etc/org/ relative to lispdir. Obviously
  it cannot find the files in the Gentoo location.

  [1] <https://bugs.gentoo.org/show_bug.cgi?id=396269>
Jambunathan K 9 years ago
parent
commit
07f006e4fd
2 changed files with 127 additions and 42 deletions
  1. 39 12
      Makefile
  2. 88 30
      lisp/org-odt.el

+ 39 - 12
Makefile

@@ -19,11 +19,10 @@ prefix=/usr/local
 # Where local lisp files go
 lispdir   = $(prefix)/share/emacs/site-lisp
 
-# Where etc files go
-etcdir    = $(lispdir)/../etc
-
-# Where style files go
-stylesdir = $(etcdir)/styles
+# Where data files go
+# $(datadir) contains auxiliary files for use with ODT exporter.
+# See comments under DATAFILES.
+datadir = $(prefix)/share/emacs/etc
 
 # Where info files go
 infodir = $(prefix)/share/info
@@ -35,7 +34,7 @@ infodir = $(prefix)/share/info
 # Using emacs in batch mode.
 
 BATCH=$(EMACS) -batch -q -no-site-file -eval                             			\
-  "(setq load-path (cons (expand-file-name \"./lisp/\") (cons \"$(lispdir)\" load-path)))"
+  "(setq load-path (cons (expand-file-name \"./lisp/\") (cons \"$(lispdir)\" load-path)))" $(BATCH_EXTRA)
 
 # Specify the byte-compiler for compiling org-mode files
 ELC= $(BATCH) -f batch-byte-compile
@@ -54,7 +53,7 @@ TEXI2HTML = makeinfo --html --number-sections
 TEXI2HTMLNOPSLIT = makeinfo --html --no-split --number-sections
 
 # How to copy the lisp files and elc files to their distination.
-CP = cp -p
+CP = cp -pr
 
 # Name of the program to install info files
 INSTALL_INFO=install-info
@@ -182,7 +181,26 @@ DOCFILES    = doc/org.texi doc/org.pdf doc/org doc/dir \
 CARDFILES   = doc/orgcard.tex doc/orgcard.pdf doc/orgcard_letter.pdf
 TEXIFILES   = doc/org.texi
 INFOFILES   = doc/org
-STYLESFILES = etc/styles/OrgOdtContentTemplate.xml etc/styles/OrgOdtStyles.xml
+
+# etc/styles contains OpenDocument style files.  These files *must* be
+# installed for the ODT exporter to function.  These files are
+# distirbuted with GNU ELPA as well as with stock Emacs >= 24.1.
+
+# contrib/odt/etc/schema contains OpenDocument schema files.  It is
+# *desirable* but *not* mandatory that these files be installed.
+# These files are not distributed with stock Emacs.  This is because
+# the terms under which OASIS distributes these files are not
+# agreeable to FSF.
+
+# BasicODConverter-x.y.z.oxt is a LibreOffice extension for converting
+# OpenDocument files to numerous other formats.  It is similar to
+# unoconv and is implemented in StarBasic.  It is *desirable* but
+# *not* *mandatory* that the converter be installed.  It is
+# distributed under the same license as GNU Emacs.  This file is *not*
+# part of GNU Emacs.
+DATAFILES   = etc/styles \
+	      # contrib/odt/BasicODConverter/BasicODConverter*.oxt \
+	      # contrib/odt/etc/schema \
 
 # Package Manager (ELPA)
 PKG_TAG = $(shell date +%Y%m%d)
@@ -219,7 +237,7 @@ update:
 
 compile: $(ELCFILES0) $(ELCBFILES)
 
-install: install-lisp install-etc
+install: install-lisp install-data
 
 doc: doc/org.html doc/org.pdf doc/orgcard.pdf doc/orgcard_letter.pdf doc/orgguide.pdf doc/orgcard.txt
 
@@ -229,6 +247,15 @@ p:
 g:
 	${MAKE} pdf && open doc/orgguide.pdf
 
+# Always force re-compilation of org-odt
+lisp/org-odt.elc: org-odt-data-dir
+org-odt-data-dir:
+
+# Sleight of hand to "hard code" the value of $(datadir) in
+# org-odt.el.  See variables `org-odt-styles-dir-list' and
+# `org-odt-schema-dir-list'.
+install-lisp: BATCH_EXTRA = -eval "(setq org-odt-data-dir (expand-file-name \"$(datadir)\"))"
+
 install-lisp: $(LISPFILES) $(ELCFILES)
 	if [ ! -d $(lispdir) ]; then $(MKDIR) $(lispdir); else true; fi ;
 	$(CP) $(LISPFILES)  $(lispdir)
@@ -239,9 +266,9 @@ install-info: $(INFOFILES)
 	$(CP) $(INFOFILES) $(infodir)
 	$(INSTALL_INFO) --infodir=$(infodir) $(INFOFILES)
 
-install-etc: $(STYLESFILES)
-	if [ ! -d $(stylesdir) ]; then $(MKDIR) $(stylesdir); else true; fi ;
-	$(CP) $(STYLESFILES) $(stylesdir)
+install-data: $(DATAFILES)
+	if [ ! -d $(datadir) ]; then $(MKDIR) $(datadir); else true; fi ;
+	$(CP) $(DATAFILES) $(datadir)
 
 autoloads: lisp/org-install.el
 

+ 88 - 30
lisp/org-odt.el

@@ -72,25 +72,52 @@
     ("\\.\\.\\." . "&#x2026;"))		; hellip
   "Regular expressions for special string conversion.")
 
-(defconst org-odt-lib-dir (file-name-directory load-file-name))
+(defconst org-odt-lib-dir (file-name-directory load-file-name)
+  "Location of ODT exporter.
+Use this to infer values of `org-odt-styles-dir' and
+`org-export-odt-schema-dir'.")
+
+(defvar org-odt-data-dir nil
+  "Data directory for ODT exporter.
+Use this to infer values of `org-odt-styles-dir' and
+`org-export-odt-schema-dir'.")
+
+(defconst org-odt-styles-dir-list
+  (list
+   (and org-odt-data-dir
+	(expand-file-name "./styles/" org-odt-data-dir)) ; bail out
+   (eval-when-compile
+     (and (boundp 'org-odt-data-dir) org-odt-data-dir ; see make install
+	  (expand-file-name "./styles/" org-odt-data-dir)))
+   (expand-file-name "../etc/styles/" org-odt-lib-dir) ; git
+   (expand-file-name "./etc/styles/" org-odt-lib-dir)  ; elpa
+   (expand-file-name "./org/" data-directory)	       ; system
+   )
+  "List of directories to search for OpenDocument styles files.
+See `org-odt-styles-dir'.  The entries in this list are populated
+heuristically based on the values of `org-odt-lib-dir' and
+`org-odt-data-dir'.")
+
 (defconst org-odt-styles-dir
-  (let* ((styles-dir1 (expand-file-name "../etc/styles/" org-odt-lib-dir)) ; git
-	 (styles-dir2 (expand-file-name "./etc/styles/" org-odt-lib-dir)) ; elpa
-	 (styles-dir3 (expand-file-name "./etc/org/" data-directory)) ; system
-	 (styles-dir
+  (let* ((styles-dir
 	  (catch 'styles-dir
+	    (message "Debug (org-odt): Searching for OpenDocument styles files...")
 	    (mapc (lambda (styles-dir)
-		    (when (and (file-readable-p
-				(expand-file-name
-				 "OrgOdtContentTemplate.xml" styles-dir))
-			       (file-readable-p
-				(expand-file-name
-				 "OrgOdtStyles.xml" styles-dir)))
-		      (throw 'styles-dir styles-dir)))
-		  (list styles-dir1 styles-dir2 styles-dir3))
+		    (when styles-dir
+		      (message "Debug (org-odt): Trying %s..." styles-dir)
+		      (when (and (file-readable-p
+				  (expand-file-name
+				   "OrgOdtContentTemplate.xml" styles-dir))
+				 (file-readable-p
+				  (expand-file-name
+				   "OrgOdtStyles.xml" styles-dir)))
+			(message "Debug (org-odt): Using styles under %s"
+				 styles-dir)
+			(throw 'styles-dir styles-dir))))
+		  org-odt-styles-dir-list)
 	    nil)))
     (unless styles-dir
-      (error "Cannot find factory styles file. Check package dir layout"))
+      (error "Error (org-odt): Cannot find factory styles files. Aborting."))
     styles-dir)
   "Directory that holds auxiliary XML files used by the ODT exporter.
 
@@ -101,21 +128,49 @@ This directory contains the following XML files -
  `org-export-odt-content-template-file'.
 
 The default value of this variable varies depending on the
-version of org in use.  Note that the user could be using org
+version of org in use and is initialized from
+`org-odt-styles-dir-list'.  Note that the user could be using org
 from one of: org's own private git repository, GNU ELPA tar or
 standard Emacs.")
 
+(defconst org-odt-schema-dir-list
+  (list
+   (and org-odt-data-dir
+	(expand-file-name "./schema/" org-odt-data-dir)) ; bail out
+   (eval-when-compile
+     (and (boundp 'org-odt-data-dir) org-odt-data-dir ; see make install
+	  (expand-file-name "./schema/" org-odt-data-dir)))
+   (expand-file-name "../contrib/odt/etc/schema/" org-odt-lib-dir) ; git
+   )
+  "List of directories to search for OpenDocument schema files.
+Use this list to set the default value of
+`org-export-odt-schema-dir'.  The entries in this list are
+populated heuristically based on the values of `org-odt-lib-dir'
+and `org-odt-data-dir'.")
+
 (defcustom org-export-odt-schema-dir
-  (let ((schema-dir (expand-file-name
-		     "../contrib/odt/etc/schema/" org-odt-lib-dir)))
-    (if (and (file-readable-p
-	      (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir))
-	     (file-readable-p
-	      (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir))
-	     (file-readable-p
-	      (expand-file-name "schemas.xml" schema-dir)))
-	schema-dir
-      (prog1 nil (message "Unable to locate OpenDocument schema files."))))
+  (let* ((schema-dir
+	  (catch 'schema-dir
+	    (message "Debug (org-odt): Searching for OpenDocument schema files...")
+	    (mapc
+	     (lambda (schema-dir)
+	       (when schema-dir
+		 (message "Debug (org-odt): Trying %s..." schema-dir)
+		 (when (and (file-readable-p
+			     (expand-file-name "od-manifest-schema-v1.2-cs01.rnc"
+					       schema-dir))
+			    (file-readable-p
+			     (expand-file-name "od-schema-v1.2-cs01.rnc"
+					       schema-dir))
+			    (file-readable-p
+			     (expand-file-name "schemas.xml" schema-dir)))
+		   (message "Debug (org-odt): Success. Using schema files under %s"
+			    schema-dir)
+		   (throw 'schema-dir schema-dir))))
+	     org-odt-schema-dir-list)
+	    (message "Debug (org-odt): No OpenDocument schema files installed")
+	    nil)))
+    schema-dir)
   "Directory that contains OpenDocument schema files.
 
 This directory contains:
@@ -129,9 +184,10 @@ of OpenDocument XML takes place based on the value
 `rng-nxml-auto-validate-flag'.
 
 The default value of this variable varies depending on the
-version of org in use.  The OASIS schema files are available only
-in the org's private git repository.  It is *not* bundled with
-GNU ELPA tar or standard Emacs distribution."
+version of org in use and is initialized from
+`org-odt-schema-dir-list'.  The OASIS schema files are available
+only in the org's private git repository.  It is *not* bundled
+with GNU ELPA tar or standard Emacs distribution."
   :type '(choice
 	  (const :tag "Not set" nil)
 	  (directory :tag "Schema directory"))
@@ -150,8 +206,10 @@ Also add it to `rng-schema-locating-files'."
 		(file-readable-p
 		 (expand-file-name "schemas.xml" schema-dir)))
 	       schema-dir
-	     (prog1 nil
-	       (message "Warning (org-odt): Unable to locate OpenDocument schema files.")))))
+	     (when value
+	       (message "Error (org-odt): %s has no OpenDocument schema files"
+			value))
+	     nil)))
     (when org-export-odt-schema-dir
       (eval-after-load 'rng-loc
 	'(add-to-list 'rng-schema-locating-files