Browse Source

replace the remaining occurences of sed with emacs scripts, implement mkdir with install

* UTILITIES/org-fixup.el (org-make-local-mk): New function to create a
  local.mk template from default.mk.

* UTILITIES/org-fixup.el (org-make-letterformat): New function to
  replace the format string for A4 with one for Letter.

* default.mk: Few cosmetic changes to the template section.  Add
  definition MAKE_LOCAL_MK for call to org-make-local-mk.  Remove
  definition for SED, which is not used anymore.  Implement MKDIR with
  'install -d' by default.  Since both CP and MKDIR are now
  implemented with install, this reduces the number of external
  dependencies.  Add mode settings to both invocations of install to
  keep the modes of installed files sane even if umask is set to a
  strange value.

* targets.mk: Remove sed script and use $(MAKE_LOCAL_MK) instead.

* doc/Makefile: Remove sed script and replace with emacs script.  This
  script can not be placed into a variable since it would expand $<
  and $@ in the context of the "card" target rather than the pattern
  rule.
Achim Gratz 12 years ago
parent
commit
0db8233460
4 changed files with 65 additions and 27 deletions
  1. 42 1
      UTILITIES/org-fixup.el
  2. 16 14
      default.mk
  3. 6 4
      doc/Makefile
  4. 1 8
      targets.mk

+ 42 - 1
UTILITIES/org-fixup.el

@@ -4,7 +4,7 @@
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
 ;;
-;; This file is not yet part of GNU Emacs.
+;; This file is not part of GNU Emacs.
 ;;
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -92,6 +92,47 @@
 	  (byte-recompile-directory dirlisp 0 force))
       (cd origin))))
 
+(defun org-make-local-mk ()
+  (let ((default "default.mk")
+	(local   "local.mk"))
+    (unwind-protect
+	(with-temp-buffer
+	  (insert-file-contents default)
+	  (goto-char (point-min))
+	  (when (search-forward "-8<-" nil t)
+	    (forward-line 1)
+	    (delete-region (point-min) (point)))
+	  (when (search-forward "->8-" nil t)
+	    (forward-line 0)
+	    (delete-region (point) (point-max)))
+	  (goto-char (point-min))
+	  (insert "
+# Remove \"oldorg:\" to switch to \"all\" as the default target.
+# Change \"oldorg:\" to an existing target to make that target the default,
+# or define your own target here to become the default target.
+oldorg:	# do what the old Makfile did by default
+
+##----------------------------------------------------------------------
+")
+	  (goto-char (point-max))
+	  (insert "\
+# See default.mk for further configuration options.
+")
+	  (toggle-read-only 0)
+	  (write-file local))
+      nil)))
+
+(defun org-make-letterformat (a4name lettername)
+  (unwind-protect
+      (with-temp-buffer
+	(insert-file-contents a4name)
+	(goto-char (point-min))
+	(while (search-forward "\\pdflayout=(0l)" nil t)
+	  (replace-match "\\pdflayout=(1l)" nil t))
+	(toggle-read-only 0)
+	(write-file lettername))
+    nil))
+
 (defmacro org-fixup ()
   (let* ((origin default-directory)
 	 (dirlisp (org-find-library-dir "org"))

+ 16 - 14
default.mk

@@ -1,11 +1,8 @@
 ##----------------------------------------------------------------------
 ##  NEVER EDIT THIS FILE, PUT ANY ADAPTATIONS INTO local.mk
-##----------------------------------------------------------------------
-##  CHECK AND ADAPT THE FOLLOWING DEFINITIONS
 ##-8<-------------------------------------------------------------------
-
-# Override default target if desired or define your own default target
-# oldorg:	# have plain "make" do the same things the old Makefile did
+##  CHECK AND ADAPT THE FOLLOWING DEFINITIONS
+##----------------------------------------------------------------------
 
 # Name of your emacs binary
 EMACS	= emacs
@@ -23,10 +20,10 @@ datadir = $(prefix)/emacs/etc/org
 infodir = $(prefix)/info
 
 # Define if you only need info documentation, the default includes html and pdf
-# ORG_MAKE_DOC = info # html pdf
+#ORG_MAKE_DOC = info # html pdf
 
 # Where to create temporary files for the testsuite
-TMPDIR ?= /tmp
+TMPDIR ?= /tmp # respect TMPDIR if it is already defined in the environment
 testdir = $(TMPDIR)/tmp-orgtest
 
 # Configuration for testing
@@ -61,6 +58,13 @@ BTEST	= $(BATCH) \
 # BATCH = $(EMACS) -batch -vanilla # XEmacs
 BATCH	= $(EMACS) -batch -Q
 
+# How to generate local.mk
+MAKE_LOCAL_MK = $(BATCH) \
+	  --eval '(add-to-list '"'"'load-path "./lisp")' \
+	  --eval '(load "org-compat.el")' \
+	  --eval '(load "../UTILITIES/org-fixup.el")' \
+	  --eval '(org-make-local-mk)'
+
 # Emacs must be started in lisp directory
 BATCHL	= $(BATCH) \
 	  --eval '(add-to-list '"'"'load-path ".")'
@@ -87,8 +91,9 @@ TEXI2PDF = texi2pdf --batch --clean
 # How to make a pdf file from a tex file
 PDFTEX = pdftex
 
-# How to create directories
-MKDIR	= mkdir -p
+# How to create directories with leading path components
+# MKDIR	= mkdir -m 755 -p # try this if you have no install
+MKDIR	= install -m 755 -d
 
 # How to create the info files from the texinfo file
 MAKEINFO = makeinfo
@@ -105,12 +110,9 @@ RM	= rm -f
 # How to remove files recursively
 RMR	= rm -fr
 
-# How to stream edit a file
-SED	= sed
-
 # How to copy the lisp files and elc files to their destination.
-# CP	= cp -p	# try this if there is no install
-CP	= install -p
+# CP	= cp -p	# try this if you have no install
+CP	= install -m 644 -p
 
 # How to obtain administrative privileges
 # SUDO	= 	# leave blank if you don't need this

+ 6 - 4
doc/Makefile

@@ -31,7 +31,6 @@ org-version.inc:	org.texi
 	@echo "@set VERSION $(ORGVERSION) ($(GITVERSION))" >> org-version.inc
 	@echo "@set DATE $(DATE)" >> org-version.inc
 
-
 install:	org
 	if [ ! -d $(DESTDIR)$(infodir) ]; then $(MKDIR) $(DESTDIR)$(infodir); else true; fi ;
 	$(CP) org $(DESTDIR)$(infodir)
@@ -48,7 +47,7 @@ clean-install:
 	$(RM) $(DESTDIR)$(infodir)/org*
 	$(INSTALL_INFO) --infodir=$(DESTDIR)$(infodir) --remove org
 
-.SUFFIXES:	.texi .tex .txt
+.SUFFIXES:	.texi .tex .txt _letter.tex
 
 %:		%.texi org-version.inc
 	$(MAKEINFO) --no-split $< -o $@
@@ -68,5 +67,8 @@ clean-install:
 	perl ../UTILITIES/orgcard2txt.pl $< > $@
 
 %_letter.tex:	%.tex
-	$(SED) -e 's/\\pdflayout=(0l)/\\pdflayout=(1l)/' \
-                   $< > $@
+	$(BATCH) \
+	  --eval '(add-to-list '"'"'load-path "../lisp")' \
+	  --eval '(load "org-compat.el")' \
+	  --eval '(load "../UTILITIES/org-fixup.el")' \
+	  --eval '(org-make-letterformat "$(<F)" "$(@F)")'

+ 1 - 8
targets.mk

@@ -41,14 +41,7 @@ local.mk:
 	$(info = Setting "oldorg" as the default target.            =)
 	$(info = Please adapt local.mk to your local setup!         =)
 	$(info ======================================================)
-	-@$(SED) -n \
-		-e '1 i ## Remove "oldorg:" to make "all" the default target,' \
-		-e '1 i ## change to your favourite default target' \
-		-e '1 i ## or provide your own defintion here' \
-		-e '1 i oldorg:' \
-		-e '/-8<-/,/->8-/ {s/^\(\s*[^#]\)/#\1/;p}' \
-		-e '$$ i ## See default.mk for further configuration options.' \
-		default.mk > $@
+	-@$(MAKE_LOCAL_MK)
 
 all compile::
 	$(foreach dir, doc lisp, $(MAKE) -C $(dir) clean;)