diff lisp/update-elc.el @ 1261:465bd3c7d932

[xemacs-hg @ 2003-02-06 06:35:47 by ben] various bug fixes mule/cyril-util.el: Fix compile warning. loadup.el, make-docfile.el, update-elc-2.el, update-elc.el: Set stack-trace-on-error, load-always-display-messages so we get better debug results. update-elc-2.el: Fix typo in name of lisp/mule, leading to compile failure. simple.el: Omit M-S-home/end from motion keys. update-elc.el: Overhaul: -- allow list of "early-compile" files to be specified, not hardcoded -- fix autoload checking to include all .el files, not just dumped ones -- be smarter about regenerating autoloads, so we don't need to use loadup-el if not necessary -- use standard methods for loading/not loading auto-autoloads.el (maybe fixes "Already loaded" error?) -- rename misleading NOBYTECOMPILE flag file. window-xemacs.el: Fix bug in default param. window-xemacs.el: Fix compile warnings. lwlib-Xm.c: Fix compile warning. lispref/mule.texi: Lots of Mule rewriting. internals/internals.texi: Major fixup. Correct for new names of Bytebpos, Ichar, etc. and lots of Mule rewriting. config.inc.samp: Various fixups. Makefile.in.in: NOBYTECOMPILE -> BYTECOMPILE_CHANGE. esd.c: Warning fixes. fns.c: Eliminate bogus require-prints-loading-message; use already existent load-always-display-messages instead. Make sure `load' knows we are coming from `require'. lread.c: Turn on `load-warn-when-source-newer' by default. Change loading message to indicate when we are `require'ing. Eliminate purify_flag hacks to display more messages; instead, loadup and friends specify this explicitly with `load-always-display-messages'. Add spaces when batch to clearly indicate recursive loading. Fassoc() does not GC so no need to gcpro. gui-x.c, gui-x.h, menubar-x.c: Fix up crashes when selecting menubar items due to lack of GCPROing of callbacks in lwlib structures. eval.c, lisp.h, print.c: Don't canonicalize to selected-frame when noninteractive, or backtraces get all screwed up as some values are printed through the stream console and some aren't. Export canonicalize_printcharfun() and use in Fbacktrace().
author ben
date Thu, 06 Feb 2003 06:36:17 +0000
parents c08a6fa181d1
children bada4b0bce3a
line wrap: on
line diff
--- a/lisp/update-elc.el	Wed Feb 05 22:53:04 2003 +0000
+++ b/lisp/update-elc.el	Thu Feb 06 06:36:17 2003 +0000
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 1997 Free Software Foundation, Inc.
 ;; Copyright (C) 1996 Sun Microsystems, Inc.
-;; Copyright (C) 2001 Ben Wing.
+;; Copyright (C) 2001, 2003 Ben Wing.
 
 ;; Author: Ben Wing <ben@xemacs.org>
 ;; Based On: Original by Steven L Baur <steve@xemacs.org>
@@ -31,6 +31,8 @@
 ;;; Commentary:
 
 ;; Byte compile the .EL files necessary to dump out xemacs.
+;; Also update the auto-autoloads.el files.
+
 ;; Use this file like this:
 
 ;; temacs -batch -l ../lisp/update-elc.el $lisp
@@ -46,12 +48,20 @@
 
 ;;; Code:
 
+;; Help debug problems.
+(setq stack-trace-on-error t
+      load-always-display-messages t)
+
 (defvar processed nil)
 (defvar update-elc-files-to-compile nil)
 (defvar need-to-rebuild-autoloads nil)
 (defvar need-to-rebuild-mule-autoloads nil)
 (defvar need-to-recompile-autoloads nil)
 (defvar need-to-recompile-mule-autoloads nil)
+(defvar undumped-exe nil)
+(defvar dumped-exe nil)
+(defvar dumped-exe-out-of-date-wrt-dump-files nil)
+(defvar dumped-exe-out-of-date-wrt-undumped-exe nil)
 
 ;(setq update-elc-files-to-compile
 ;      (delq nil
@@ -71,12 +81,36 @@
 (let ((build-root (expand-file-name ".." invocation-directory)))
   (setq load-path (list (expand-file-name "lisp" build-root))))
 
-(load "very-early-lisp" nil t)
-
+(load "very-early-lisp.el")
 (load "find-paths.el")
 (load "packages.el")
 (load "setup-paths.el")
-(load "dump-paths.el")
+(load "dump-paths.el") ;; #### take out in my fixup ws
+
+;; Lisp files loaded in order to byte compile anything.  If any are out of
+;; date, we need to load them as .el's, byte compile them, and reload as
+;; .elc's.
+(defvar lisp-files-needed-for-byte-compilation
+  '("bytecomp"
+    "byte-optimize"))
+
+;; "Lisp files, other than those in
+;; `lisp-files-needing-early-byte-compilation',packages that need early
+;; byte compilation.  These are files loaded by update-elc.el in order to
+;; do the compilation of all the rest of the files.
+(defvar lisp-files-needing-early-byte-compilation
+  '(;"easy-mmode"
+    "autoload"
+    "shadow"
+    "cl-macs"))
+
+(defvar unbytecompiled-lisp-files
+  '("paths.el"
+    "dumped-lisp.el"
+    "dumped-pkg-lisp.el"
+    "version.el"
+    "very-early-lisp.el")
+  "Lisp files that should not be byte compiled.")
 
 (defun update-elc-chop-extension (file)
   (if (string-match "\\.elc?$" file)
@@ -87,8 +121,7 @@
 ;; we need to handle each autoload file differently and there are only
 ;; two of them.
 
-(let (preloaded-file-list site-load-packages need-to-dump dumped-exe
-			  files-to-process)
+(let (preloaded-file-list site-load-packages files-to-process)
   
   (load (expand-file-name "../lisp/dumped-lisp.el"))
 
@@ -97,6 +130,31 @@
 	      ((file-exists-p "../src/xemacs") "../src/xemacs")
 	      (t nil)))
 
+  (let ((temacs-exe
+	 (cond ((file-exists-p "../src/temacs.exe") "../src/temacs.exe")
+	       ((file-exists-p "../src/temacs") "../src/temacs")
+	       (t nil)))
+	(data-file
+	 (cond ((file-exists-p "../src/xemacs.dmp") "../src/xemacs.dmp")
+	       (t nil))))
+
+    ;; two setups here:
+    ;; (1) temacs.exe is undumped, dumped into xemacs.exe.  Happens with
+    ;;     unexec, but also with pdump under MS Windows native, since
+    ;;     the dumped data is stored as a resource in the xemacs.exe
+    ;;     executable.
+    ;; (2) xemacs.exe is dumped or undumped.  Running `xemacs -nd' gets
+    ;;     you the equivalent of `temacs'.  Dumping creates a file
+    ;;     `xemacs.dmp'.
+
+    (setq dumped-exe-out-of-date-wrt-undumped-exe
+	  (cond ((not dumped-exe) t)
+		(temacs-exe (file-newer-than-file-p temacs-exe dumped-exe))
+		((not data-file) t)
+		(t (file-newer-than-file-p dumped-exe data-file))))
+    )
+                                                              
+
   ;; Path setup
   (let ((package-preloaded-file-list
 	 (packages-collect-package-dumped-lisps late-package-load-path)))
@@ -111,9 +169,11 @@
 	(append packages-hardcoded-lisp
 		preloaded-file-list
 		site-load-packages))
-  ;; bytecomp, byte-optimize, and autoload are mentioned in
-  ;; packages-useful-lisp.
-  (setq files-to-process (append packages-useful-lisp preloaded-file-list))
+  ;; bytecomp, byte-optimize, autoload, etc. are mentioned specially
+  ;; in the lisp-files-need* variables.
+  (setq files-to-process (append lisp-files-needed-for-byte-compilation
+				 lisp-files-needing-early-byte-compilation
+				 preloaded-file-list))
   (while files-to-process
     (let* ((arg (car files-to-process))
 	   (arg-is-preloaded (member arg preloaded-file-list))
@@ -123,6 +183,7 @@
 	    (if (null full-arg)
 		(progn
 		  (print (format "Error: Library file %s not found" arg))
+		  (backtrace)
 		  ;; Uncomment in case of trouble
 		  ;;(print (format "late-packages: %S" late-packages))
                   ;;(print (format "guessed-roots: %S"
@@ -132,9 +193,7 @@
 	      (update-elc-chop-extension full-arg)))
 	   (full-arg-el (concat full-arg-sans-extension ".el"))
 	   (full-arg-elc (concat full-arg-sans-extension ".elc"))
-	   (full-arg-dir (file-name-directory full-arg-el))
-	   (autoload-file (expand-file-name "auto-autoloads.el" full-arg-dir))
-	   (autoload-is-mule (string-match "[/\\]mule[/\\]$" full-arg-dir)))
+	   (full-arg-dir (file-name-directory full-arg-el)))
 	   
       ;; (print full-arg-el)
 
@@ -145,17 +204,10 @@
 			  (file-newer-than-file-p full-arg-el dumped-exe))
 		     (and (file-exists-p full-arg-elc)
 			  (file-newer-than-file-p full-arg-elc dumped-exe))))
-	(setq need-to-dump t))
-
-      (when (or (not (file-exists-p autoload-file))
-		(and (file-exists-p full-arg-el)
-		     (file-newer-than-file-p full-arg-el autoload-file)))
-	(if autoload-is-mule
-	    (setq need-to-rebuild-mule-autoloads t)
-	  (setq need-to-rebuild-autoloads t)))
+	(setq dumped-exe-out-of-date-wrt-dump-files t))
 
       (if (and (not (member (file-name-nondirectory arg)
-			    packages-unbytecompiled-lisp))
+			    unbytecompiled-lisp-files))
 	       (not (member full-arg-el processed))
 	       (file-exists-p full-arg-el)
 	       (or (not (file-exists-p full-arg-elc))
@@ -164,7 +216,28 @@
 
       (setq files-to-process (cdr files-to-process))))
 
-  (if need-to-dump
+  ;; Check if we need to rebuild the auto-autoloads.el files -- that is,
+  ;; if ANY .el files have changed.
+  (let ((dirs-to-check '("../lisp" "../lisp/mule")))
+    (while dirs-to-check
+      (let* ((dir (car dirs-to-check))
+	     (full-dir (expand-file-name dir))
+	     (all-files-in-dir (directory-files full-dir t "\\.el$" nil t))
+	     (autoload-file
+	      (expand-file-name "auto-autoloads.el" full-dir))
+	     (autoload-is-mule (equal dir "../lisp/mule")))
+	(while all-files-in-dir
+	  (let* ((full-arg (car all-files-in-dir)))
+	    (when (or (not (file-exists-p autoload-file))
+		      (and (file-exists-p full-arg)
+			   (file-newer-than-file-p full-arg autoload-file)))
+	      (if autoload-is-mule
+		  (setq need-to-rebuild-mule-autoloads t)
+		(setq need-to-rebuild-autoloads t))))
+	  (setq all-files-in-dir (cdr all-files-in-dir))))
+      (setq dirs-to-check (cdr dirs-to-check))))
+
+  (if dumped-exe-out-of-date-wrt-dump-files
       (condition-case nil
 	  (write-region-internal "foo" nil "../src/NEEDTODUMP")
 	(file-error nil)))
@@ -193,74 +266,127 @@
 (setq update-elc-files-to-compile (append update-elc-files-to-compile
 					  (nreverse processed)))
 
-;; (print update-elc-files-to-compile)
+;(print update-elc-files-to-compile)
 
-(if (and (not update-elc-files-to-compile)
-	 (not need-to-rebuild-autoloads)
-	 (not need-to-rebuild-mule-autoloads)
-	 (not need-to-recompile-autoloads)
-	 (not need-to-recompile-mule-autoloads))
-    (condition-case nil
-	(delete-file "../src/NOBYTECOMPILE")
-      (file-error nil))
-  (let* (
-	 (bytecomp-arg (concat (update-elc-chop-extension
-				(locate-library "bytecomp")) ".el"))
-	 (byte-opt-arg (concat (update-elc-chop-extension
-				(locate-library "byte-optimize")) ".el"))
-	 (autoload-arg (concat (update-elc-chop-extension
-				(locate-library "autoload")) ".el"))
-	 )
-    (setq inhibit-autoloads t)
-    (setq command-line-args
-	  (append
-	   '("-l" "loadup-el.el" "run-temacs" "-batch" "-q" "-no-site-file")
+(let ((do-autoload-commands
+       (append
+	(if (or need-to-rebuild-autoloads
+		need-to-rebuild-mule-autoloads)
+	    '("-l" "autoload"))
+	(if need-to-rebuild-autoloads
+	    '("-f" "autoload-update-directory-autoloads"
+	      "auto" "../lisp"))
+	(if need-to-rebuild-mule-autoloads
+	    '("-f" "autoload-update-directory-autoloads"
+	      "mule" "../lisp/mule"))
+	(if need-to-recompile-autoloads
+	    '("-f" "batch-byte-compile-one-file"
+	      "../lisp/auto-autoloads.el"))
+	(if need-to-recompile-mule-autoloads
+	    '("-f" "batch-byte-compile-one-file"
+		   "../lisp/mule/auto-autoloads.el")))))
+  (cond ((and (not update-elc-files-to-compile)
+	      (not need-to-rebuild-autoloads)
+	      (not need-to-rebuild-mule-autoloads)
+	      (not need-to-recompile-autoloads)
+	      (not need-to-recompile-mule-autoloads))
+	 ;; (1) Nothing to do at all.  BYTECOMPILE_CHANGE is used (only by
+	 ;;     the Unix makefile) to indicate whether some files needed
+	 ;;     for dump got recompiled, and hence the executable must be
+	 ;;     redumped.  We remove it if there were no files to compile.
+	 (condition-case nil
+	     (delete-file "../src/BYTECOMPILE_CHANGE")
+	   (file-error nil)))
+	 ;; (1) Nothing to do at all.  BYTECOMPILE_CHANGE is used (only by
+	 ;;     the Unix makefile) to indicate whether some files needed
+	 ;;     for dump got recompiled, and hence the executable must be
+	 ;;     redumped.  We remove it if there were no files to compile.
+	((and (not update-elc-files-to-compile)
+	      (not dumped-exe-out-of-date-wrt-dump-files)
+	      (not dumped-exe-out-of-date-wrt-undumped-exe))
+	 ;; (2) We have no files to byte-compile, but we do need to
+	 ;;     regenerate and compile the auto-autoloads file. (This will
+	 ;;     be needed to be up-to-date before we run update-elc-2.)
+	 ;;     If the dumped exe exists and is up-to-date, both with
+	 ;;     respect to the undumped exe and the files that will be dumped
+	 ;;     into it, then we can use the dumped exe to rebuild the
+	 ;;     autoloads.  Else, we have to do it the "hard way" by loading
+	 ;;     raw temacs, running loadup, then regenerating the autoloads.
+	 ;;     #### We should see whether it's possible to load up a
+	 ;;     minimal number of files in order to get autoload.el to work.
+	 (load "raw-process.el")
+	 (apply 'call-process-internal dumped-exe nil t nil
+		(append
+		 '("-batch -no-autoloads -no-packages")
+		 do-autoload-commands))
+	 (condition-case nil
+	     (delete-file "../src/BYTECOMPILE_CHANGE")
+	   (file-error nil)))
+	(t
+	 (let ((bc-bootstrap
+		(mapcar #'(lambda (arg) 
+			    (concat (update-elc-chop-extension
+				     (locate-library arg)) ".el"))
+			lisp-files-needed-for-byte-compilation))
+	       (bootstrap-other
+		(mapcar #'(lambda (arg) 
+			    (concat (update-elc-chop-extension
+				     (locate-library arg)) ".el"))
+			lisp-files-needing-early-byte-compilation)))
+	   (setq inhibit-autoloads t)
 	   ;; if bytecomp or byte-optimize need recompiling, then load
 	   ;; the .el version of them first, recompile them, and reload
 	   ;; the .elc versions to recompile everything else (so we won't
 	   ;; be waiting until the cows come home).  we need to set
 	   ;; load-ignore-elc-files because byte-optimize gets autoloaded
 	   ;; from bytecomp.
-	   (if (or (member bytecomp-arg update-elc-files-to-compile)
-		   (member byte-opt-arg update-elc-files-to-compile))
-	       (append
-		'("-eval" "(setq load-ignore-elc-files t)" "-l" "bytecomp")
-		(if (member bytecomp-arg update-elc-files-to-compile)
-		    (append '("-f" "batch-byte-compile-one-file")
-			    (list bytecomp-arg)))
-		(if (member byte-opt-arg update-elc-files-to-compile)
-		    (append '("-f" "batch-byte-compile-one-file")
-			    (list byte-opt-arg)))
-		'("-eval" "(setq load-ignore-elc-files nil)")))
-	   '("-l" "bytecomp")
-	   ;; likewise, recompile autoload.el if out-of-date.
-	   (if (member autoload-arg update-elc-files-to-compile)
-	       (append '("-f" "batch-byte-compile-one-file")
-		       (list autoload-arg)))
-	   ;; then generate autoloads for lisp and maybe lisp/mule.
-	   (if (or need-to-rebuild-autoloads
-		   need-to-rebuild-mule-autoloads)
-	       '("-l" "autoload"))
-	   (if need-to-rebuild-autoloads
-	       '("-f" "autoload-update-directory-autoloads" "auto" "../lisp"))
-	   (if need-to-rebuild-mule-autoloads
-	       '("-f" "autoload-update-directory-autoloads"
-		 "mule" "../lisp/mule"))
-	   (if need-to-recompile-autoloads
-	       '("-f" "batch-byte-compile-one-file"
-		 "../lisp/auto-autoloads.el"))
-	   (if need-to-recompile-mule-autoloads
-	       '("-f" "batch-byte-compile-one-file"
-		 "../lisp/mule/auto-autoloads.el"))
-	   ;; now load the autoloads and compile alles anderes.
-	   '("-eval" "(setq inhibit-autoloads nil)"
-	     "-f" "startup-load-autoloads"
-	     "-f" "batch-byte-compile")
-	   (delete autoload-arg
-		   (delete byte-opt-arg
-			   (delete bytecomp-arg
-				   update-elc-files-to-compile))))))
-  (load "loadup-el.el"))
+	   (let ((recompile-bc-bootstrap
+		  (apply #'nconc
+			 (mapcar
+			  #'(lambda (arg)
+			      (when (member arg update-elc-files-to-compile)
+				(append '("-f" "batch-byte-compile-one-file")
+					(list arg))))
+			  bc-bootstrap)))
+		 (recompile-bootstrap-other
+		  (apply #'nconc
+			 (mapcar
+			  #'(lambda (arg)
+			      (when (member arg update-elc-files-to-compile)
+				(append '("-f" "batch-byte-compile-one-file")
+					(list arg))))
+			  bootstrap-other))))
+	     (mapc-internal
+	      #'(lambda (arg)
+		  (setq update-elc-files-to-compile
+			(delete arg update-elc-files-to-compile)))
+	      (append bc-bootstrap bootstrap-other))
+	     (setq command-line-args
+		   (append
+		    '("-l" "loadup-el.el" "run-temacs"
+		      "-batch" "-no-packages" "-no-autoloads"
+		      "-eval" "(setq stack-trace-on-error t)"
+		      "-eval" "(setq load-always-display-messages t)")
+		    (when recompile-bc-bootstrap
+		      (append
+		       '("-eval" "(setq load-ignore-elc-files t)"
+			 "-l" "bytecomp")
+		       recompile-bc-bootstrap
+		       '("-eval" "(setq load-ignore-elc-files nil)")))
+		    '("-l" "bytecomp")
+		    ;; likewise, recompile autoload.el etc. if out-of-date.
+		    recompile-bootstrap-other
+		    ;; then generate autoloads for lisp and maybe lisp/mule.
+		    do-autoload-commands
+		    ;; now load the autoloads and compile alles anderes.
+		    '("-eval" "(setq inhibit-autoloads nil)"
+		      "-f" "startup-load-autoloads"
+		      "-f" "batch-byte-compile")
+		    update-elc-files-to-compile
+		    ))))
+
+	 ;;(print command-line-args)
+	 (load "loadup-el.el"))))
 
 (kill-emacs)