view lisp/loadup.el @ 1315:70921960b980

[xemacs-hg @ 2003-02-20 08:19:28 by ben] check in makefile fixes et al Makefile.in.in: Major surgery. Move all stuff related to building anything in the src/ directory into src/. Simplify the dependencies -- everything in src/ is dependent on the single entry `src' in MAKE_SUBDIRS. Remove weirdo targets like `all-elc[s]', dump-elc[s], etc. mule/mule-msw-init.el: Removed. Delete this file. mule/mule-win32-init.el: New file, with stuff from mule-msw-init.el -- not just for MS Windows native, boys and girls! bytecomp.el: Change code inserted to catch trying to load a Mule-only .elc file in a non-Mule XEmacs. Formerly you got the rather cryptic "The required feature `mule' cannot be provided". Now you get "Loading this file requires Mule support". finder.el: Remove dependency on which directory this function is invoked from. update-elc.el: Don't mess around with ../src/BYTECOMPILE_CHANGE. Now that Makefile.in.in and xemacs.mak are in sync, both of them use NEEDTODUMP and the other one isn't used. dumped-lisp.el: Rewrite in terms of `list' and `nconc' instead of assemble-list, so we can have arbitrary forms, not just `when-feature'. very-early-lisp.el: Nuke this file. finder-inf.el, packages.el, update-elc.el, update-elc-2.el, loadup.el, make-docfile.el: Eliminate references to very-early-lisp. msw-glyphs.el: Comment clarification. xemacs.mak: Add macros DO_TEMACS, DO_XEMACS, and a few others; this macro section is now completely in sync with src/Makefile.in.in. Copy check-features, load-shadows, and rebuilding finder-inf.el from src/Makefile.in.in. The main build/dump/recompile process is now synchronized with src/Makefile.in.in. Change `WARNING' to `NOTE' and `error checking' to `error-checking' TO avoid tripping faux warnings and errors in the VC++ IDE. Makefile.in.in: Major surgery. Move all stuff related to building anything in the src/ directory from top-level Makefile.in.in to here. Simplify the dependencies. Rearrange into logical subsections. Synchronize the main compile/dump/build-elcs section with xemacs.mak, which is already clean and in good working order. Remove weirdo targets like `all-elc[s]', dump-elc[s], etc. Add additional levels of macros \(e.g. DO_TEMACS, DO_XEMACS, TEMACS_BATCH, XEMACS_BATCH, XEMACS_BATCH_PACKAGES) to factor out duplicated stuff. Clean up handling of "HEAP_IN_DATA" (Cygwin) so it doesn't need to ignore the return value from dumping. Add .NO_PARALLEL since various aspects of building and dumping must be serialized but do not always have dependencies between them (this is impossible in some cases). Everything related to src/ now gets built in one pass in this directory by just running `make' (except the Makefiles themselves and config.h, paths.h, Emacs.ad.h, and other generated .h files). console.c: Update list of possibly valid console types. emacs.c: Rationalize the specifying and handling of the type of the first frame. This was originally prompted by a workspace in which I got GTK to compile under C++ and in the process fixed it so it could coexist with X in the same build -- hence, a combined TTY/X/MS-Windows/GTK build is now possible under Cygwin. (However, you can't simultaneously *display* more than one kind of device connection -- but getting that to work is not that difficult. Perhaps a project for a bored grad student. I (ben) would do it but don't see the use.) To make sense of this, I added new switches that can be used to specifically indicate the window system: -x [aka --use-x], -tty \[aka --use-tty], -msw [aka --use-ms-windows], -gtk [aka --use-gtk], and -gnome [aka --use-gnome, same as --use-gtk]. -nw continues as an alias for -tty. When none have been given, XEmacs checks for other parameters implying particular device types (-t -> tty, -display -> x [or should it have same treatment as DISPLAY below?]), and has ad-hoc logic afterwards: if env var DISPLAY is set, use x (or gtk? perhaps should check whether gnome is running), else MS Windows if it exsits, else TTY if it exists, else stream, and you must be running in batch mode. This also fixes an existing bug whereby compiling with no x, no mswin, no tty, when running non- interactively (e.g. to dump) I get "sorry, must have TTY support". emacs.c: Turn on Vstack_trace_on_error so that errors are debuggable even when occurring extremely early in reinitialization. emacs.c: Try to make sure that the user can see message output under Windows (i.e. it doesn't just disappear right away) regardless of when it occurs, e.g. in the middle of creating the first frame. emacs.c: Define new function `emacs-run-status', indicating whether XEmacs is noninteractive or interactive, whether raw, post-dump/pdump-load or run-temacs, whether we are dumping, whether pdump is in effect. event-stream.c: It's "mommas are fat", not "momas are fat". Fix other typo. event-stream.c: Conditionalize in_menu_callback check on HAVE_MENUBARS, because it won't exist on w/o menubar support, lisp.h: More hackery on RETURN_NOT_REACHED. Cygwin v3.2 DOES complain here if RETURN_NOT_REACHED() is blank, as it is for GCC 2.5+. So make it blank only for GCC 2.5 through 2.999999999999999. Declare Vstack_trace_on_error. profile.c: Need to include "profile.h" to fix warnings. sheap.c: Don't fatal() when need to rerun Make, just stderr_out() and exit(0). That way we can distinguish between a dumping failing expectedly (due to lack of stack space, triggering another dump) and unexpectedly, in which case, we want to stop building. (or go on, if -K is given) syntax.c, syntax.h: Use ints where they belong, and enum syntaxcode's where they belong, and fix warnings thereby. syntax.h: Fix crash caused by an edge condition in the syntax-cache macros. text.h: Spacing fixes. xmotif.h: New file, to get around shadowing warnings. EmacsManager.c, event-Xt.c, glyphs-x.c, gui-x.c, input-method-motif.c, xmmanagerp.h, xmprimitivep.h: Include xmotif.h. alloc.c: Conditionalize in_malloc on ERROR_CHECK_MALLOC. config.h.in, file-coding.h, fileio.c, getloadavg.c, select-x.c, signal.c, sysdep.c, sysfile.h, systime.h, text.c, unicode.c: Eliminate HAVE_WIN32_CODING_SYSTEMS, use WIN32_ANY instead. Replace defined (WIN32_NATIVE) || defined (CYGWIN) with WIN32_ANY. lisp.h: More futile attempts to walk and chew gum at the same time when dealing with subr's that don't return.
author ben
date Thu, 20 Feb 2003 08:19:44 +0000
parents 465bd3c7d932
children 4542b72c005e
line wrap: on
line source

;; loadup.el --- load up standardly loaded Lisp files for XEmacs.

;; Copyright (C) 1985, 1986, 1992, 1994, 1997 Free Software Foundation, Inc.
;; Copyright (C) 1996 Richard Mlynarik.
;; Copyright (C) 1995, 1996, 2003 Ben Wing.

;; Maintainer: XEmacs Development Team
;; Keywords: internal, dumped

;; This file is part of XEmacs.

;; XEmacs is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; XEmacs is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with XEmacs; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
;; 02111-1307, USA.

;;; Synched up with: Last synched with FSF 19.30, with wild divergence since.

;;; Commentary:

;; If you are wanting to add files to be dumped into your local version of
;; XEmacs, DO NOT add them here.  Use site-init.el or site-load.el instead.

;; This is loaded into a bare XEmacs to make a dumpable one.

;;; Code:

;; Help debug problems.
(setq stack-trace-on-error t
      load-always-display-messages t)

(when (fboundp 'error)
  (error "loadup.el already loaded!"))

(defvar running-xemacs t
  "Non-nil when the current emacs is XEmacs.")
(defvar preloaded-file-list nil
  "List of files preloaded into the XEmacs binary image.")

(defvar Installation-string nil
  "Description of XEmacs installation.")

;(start-profiling)

(let ((gc-cons-threshold
       ;; setting it low makes loadup incredibly fucking slow.
       ;; no need to do it when not dumping.
       (if (and purify-flag
		(not (memq 'quick-build internal-error-checking)))
	   30000 3000000)))

;; really-early-error-handler outputs a stack trace so let's not do it
;; twice.
(let ((stack-trace-on-error nil))
  
;; This is awfully damn early to be getting an error, right?
(call-with-condition-handler 'really-early-error-handler
    #'(lambda ()

	;; Initialize Installation-string.  We do it before loading
	;; anything so that dumped code can make use of its value.
	(setq Installation-string
	      (save-current-buffer
		(set-buffer (get-buffer-create (generate-new-buffer-name
						" *temp*")))
		;; insert-file-contents-internal bogusly calls
		;; format-decode without checking if it's defined.
		(fset 'format-decode #'(lambda (f l &optional v) l))
		(insert-file-contents-internal "../Installation")
		(fmakunbound 'format-decode)
		(prog1 (buffer-substring)
		  (kill-buffer (current-buffer)))))

	(let ((build-root (expand-file-name ".." invocation-directory)))
	  (setq load-path (list (expand-file-name "lisp" build-root)))
	  (setq module-load-path (list (expand-file-name "modules" build-root))))

	;; message not defined yet ...
	(external-debugging-output (format "\nUsing load-path %s" load-path))
	(external-debugging-output (format "\nUsing module-load-path %s"
					   module-load-path))

	;; We don't want to have any undo records in the dumped XEmacs.
	(buffer-disable-undo (get-buffer "*scratch*"))

	;; lread.c (or src/Makefile.in.in) has prepended
	;; "${srcdir}/../lisp/" to load-path, which is how this file
	;; has been found.  At this point, enough of XEmacs has been
	;; initialized that we can start dumping "standard" lisp.
	;; Dumped lisp from external packages is added when we search
	;; the package path.
	;; #### This code is duplicated in two other places.
	(let ((temp-path (expand-file-name "." (car load-path))))
	  (setq load-path (nconc (mapcar
				  #'(lambda (i) (concat i "/"))
				  (directory-files temp-path t "^[^-.]"
						   nil 'dirs-only))
				 (cons (file-name-as-directory temp-path)
				       load-path))))

	(setq load-warn-when-source-only  t) ; Set to nil at the end

	;; garbage collect after loading every file in an attempt to
	;; minimize the size of the dumped image (if we don't do this,
	;; there will be lots of extra space in the data segment filled
	;; with garbage-collected junk)
	(defun pureload (file)
	  (let ((full-path
		 (locate-file file load-path
			      (if load-ignore-elc-files
				  '(".el" "") '(".elc" ".el" "")))))
	    (if full-path
		(prog1
		  (load full-path)
		  ;; but garbage collection really slows down loading.
		  (unless (memq 'quick-build internal-error-checking)
		    (garbage-collect)))
	      (external-debugging-output (format "\nLoad file %s: not found\n"
						 file))
	      ;; Uncomment in case of trouble
	      ;;(print (format "late-packages: %S" late-packages))
	      ;;(print (format "guessed-roots: %S" (paths-find-emacs-roots invocation-directory invocation-name #'paths-emacs-root-p)))
	      ;;(print (format "guessed-data-roots: %S" (paths-find-emacs-roots invocation-directory invocation-name #'paths-emacs-data-root-p)))
	      nil)))

	(load (expand-file-name "../lisp/dumped-lisp.el"))

	(let ((files preloaded-file-list)
	      file)
	  (while (setq file (car files))
	    (unless (pureload file)
	      (external-debugging-output "Fatal error during load, aborting")
	      (kill-emacs 1))
	    (setq files (cdr files)))
	  (when (not (featurep 'toolbar))
	    ;; else still define a few functions.
	    (defun toolbar-button-p    (obj) "No toolbar support." nil)
	    (defun toolbar-specifier-p (obj) "No toolbar support." nil))
	  (fmakunbound 'pureload))

	(packages-load-package-dumped-lisps late-package-load-path)

	)) ;; end of call-with-condition-handler

) ; (let ((stack-trace-on-error nil)))

;; Fix up the preloaded file list
(setq preloaded-file-list (mapcar #'file-name-sans-extension
				  preloaded-file-list))

(setq load-warn-when-source-only nil)

(setq debugger 'debug)

(when (member "no-site-file" command-line-args)
  (setq site-start-file nil))

;; If you want additional libraries to be preloaded and their
;; doc strings kept in the DOC file rather than in core,
;; you may load them with a "site-load.el" file.
;; But you must also cause them to be scanned when the DOC file
;; is generated.  For MS Windows, you must edit ../nt/xemacs.mak.
;; For other systems, you must edit ../src/Makefile.in.in.
(when (load "site-load" t)
  (garbage-collect)
)

;;FSFmacs randomness
;;(if (fboundp 'x-popup-menu)
;;    (precompute-menubar-bindings))
;;; Turn on recording of which commands get rebound,
;;; for the sake of the next call to precompute-menubar-bindings.
;(setq define-key-rebound-commands nil)

;; Note: all compiled Lisp files loaded above this point
;; must be among the ones parsed by make-docfile
;; to construct DOC.  Any that are not processed
;; for DOC will not have doc strings in the dumped XEmacs.

;; Don't bother with these if we're running temacs, i.e. if we're
;; just debugging don't waste time finding doc strings.

;; purify-flag is nil if called from loadup-el.el.
(when purify-flag
  (message "Finding pointers to doc strings...")
  (Snarf-documentation "DOC")
  (message "Finding pointers to doc strings...done")
  (Verify-documentation))

;; Note: You can cause additional libraries to be preloaded
;; by writing a site-init.el that loads them.
;; See also "site-load" above.
(when (stringp site-start-file)
  (load "site-init" t))
(setq current-load-list nil)
(garbage-collect)

;;; At this point, we're ready to resume undo recording for scratch.
(buffer-enable-undo "*scratch*")

) ;; (let ((gc-cons-threshold [frequent garbage collection when dumping])))

;(stop-profiling)

;; yuck!  need to insert the function def here, and rewrite the dolist
;; loop below.

;(defun loadup-profile-results (&optional info stream)
;  "Print profiling info INFO to STREAM in a pretty format.
;If INFO is omitted, the current profiling info is retrieved using
; `get-profiling-info'.
;If STREAM is omitted, either a *Profiling Results* buffer or standard
; output are used, depending on whether the function was called
; interactively or not."
;  (interactive)
;  (setq info (if info
;		 (copy-alist info)
;	       (get-profiling-info)))
;  (when (and (not stream)
;	     (interactive-p))
;    (pop-to-buffer (get-buffer-create "*Profiling Results*"))
;    (erase-buffer))
;  (let ((standard-output (or stream (if (interactive-p)
;					(current-buffer)
;				      standard-output)))
;	;; Calculate the longest function
;	(maxfunlen (apply #'max
;			  (length "Function Name")
;			  (mapcar
;			   (lambda (el)
;			     ;; Functions longer than 50 characters (usually
;			     ;; anonymous functions) don't qualify
;			     (let ((l (length (format "%s" (car el)))))
;			       (if (< l 50)
;				   l 0)))
;			   info))))
;    (princ (format "%-*s    Ticks    %%/Total   Call Count\n"
;		   maxfunlen "Function Name"))
;    (princ (make-string maxfunlen ?=))
;    (princ "    =====    =======   ==========\n")
;    (let ((sum (float (apply #'+ (mapcar #'cdr info)))))
;      (let (entry
;	    (entry-list (nreverse (sort info #'cdr-less-than-cdr))))
;	(while entry-list
;	  (setq entry (car entry-list))
;	  (princ (format "%-*s    %-5d    %-6.3f    %s\n"
;			 maxfunlen (car entry) (cdr entry)
;			 (* 100 (/ (cdr entry) sum))
;			 (or (gethash (car entry) call-count-profile-table)
;			     "")))
;	  (setq entry-list (cdr entry-list))))
;      (princ (make-string maxfunlen ?-))
;      (princ "---------------------------------\n")
;      (princ (format "%-*s    %-5d    %-6.2f\n" maxfunlen "Total" sum 100.0))
;      (princ (format "\n\nOne tick = %g ms\n"
;		     (/ default-profiling-interval 1000.0)))
;      (and (boundp 'internal-error-checking)
;	   internal-error-checking
;	   (princ "
;WARNING: Error checking is turned on in this XEmacs.  This might make
;         the measurements very unreliable.\n"))))
;  (when (and (not stream)
;	     (interactive-p))
;    (goto-char (point-min))))

;(loadup-profile-results nil 'external-debugging-output)

;; Dump into the name `xemacs' (only)
(when (member "dump" command-line-args)
  (message "Dumping under the name xemacs")
  ;; This is handled earlier in the build process.
  ;; (condition-case () (delete-file "xemacs") (file-error nil))
  (when (fboundp 'really-free)
    (really-free))
  ;; Make sure we don't dump with debugging messages turned on.
  (setq stack-trace-on-error nil
	load-always-display-messages nil)
  (dump-emacs
   (cond
    ((featurep 'infodock) "infodock")
    ;; #### BILL!!!
    ;; If we want to dump under a name other than `xemacs', do that here!
    ;; ((featurep 'gtk) "xemacs-gtk")
    (t "xemacs"))
   "temacs")
  (kill-emacs))

;; Avoid error if user loads some more libraries now.
(setq purify-flag nil)

(when (member "run-temacs" command-line-args)
  (message "\nBootstrapping from temacs...")
  ;; Remove all args up to and including "run-temacs"
  (apply #'run-emacs-from-temacs (cdr (member "run-temacs" command-line-args)))
  ;; run-emacs-from-temacs doesn't actually return anyway.
  (kill-emacs))

;; XEmacs change
;; If you are using 'recompile', then you should have used -l loadup-el.el
;; so that the .el files always get loaded (the .elc files may be out-of-
;; date or bad).
(when (member "recompile" command-line-args)
  (setq command-line-args-left (cdr (member "recompile" command-line-args)))
  (batch-byte-recompile-directory)
  (kill-emacs))

;; For machines with CANNOT_DUMP defined in config.h,
;; this file must be loaded each time Emacs is run.
;; So run the startup code now.

(when (not (fboundp 'dump-emacs))
  ;; Avoid loading loadup.el a second time!
  (setq command-line-args (cdr (cdr command-line-args)))
  (eval top-level))

;;; loadup.el ends here