Function: ede-proj-makefile-create

ede-proj-makefile-create is a byte-compiled function defined in pmake.el.gz.

Signature

(ede-proj-makefile-create ARG &rest ARGS)

Implementations

(ede-proj-makefile-create (THIS ede-proj-project) MFILENAME) in `ede/pmake.el'.

Create a Makefile for all Makefile targets in THIS. MFILENAME is the makefile to generate.

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/ede/pmake.el.gz
;;; Code:
(cl-defmethod ede-proj-makefile-create ((this ede-proj-project) mfilename)
  "Create a Makefile for all Makefile targets in THIS.
MFILENAME is the makefile to generate."
  (require 'ede/srecode)
  (let ((mt nil)
	(isdist (string= mfilename (ede-proj-dist-makefile this)))
	(depth 0)
	(orig-buffer nil)
	(buff-to-kill nil)
	)
    ;; Find out how deep this project is.
    (let ((tmp this))
      (while (setq tmp (ede-parent-project tmp))
	(setq depth (1+ depth))))
    ;; Collect the targets that belong in a makefile.
    (mapc
     (lambda (obj)
       (if (and (obj-of-class-p obj 'ede-proj-target-makefile)
		(string= (oref obj makefile) mfilename))
	   (setq mt (cons obj mt))))
     (oref this targets))
    ;; Fix the order so things compile in the right direction.
    (setq mt (nreverse mt))
    ;; Add in the header part of the Makefile*
    (save-excursion
      (setq orig-buffer (get-file-buffer mfilename))
      (set-buffer (setq buff-to-kill (find-file-noselect mfilename)))
      (goto-char (point-min))
      (if (and
	   (not (eobp))
	   (not (looking-at "# Automatically Generated \\w+ by EDE.")))
	  (if (not (y-or-n-p (format "Really replace %s? " mfilename)))
	      (error "Not replacing Makefile"))
	(message "Replace EDE Makefile"))
      (erase-buffer)
      (ede-srecode-setup)
      ;; Insert a giant pile of stuff that is common between
      ;; one of our Makefiles, and a Makefile.in
      (ede-srecode-insert
       "file:ede-empty"
       "MAKETYPE"
       (with-slots (makefile-type) this
	 (cond ((eq makefile-type 'Makefile) "make")
	       ((eq makefile-type 'Makefile.in) "autoconf")
	       ((eq makefile-type 'Makefile.am) "automake")
	       (t (error ":makefile-type in project invalid")))))

      ;; Just this project's variables
      (ede-proj-makefile-insert-variables this)

      ;; Space
      (insert "\n")

      (cond
       ((eq (oref this makefile-type) 'Makefile)
	;; Make sure the user has the right kind of make
	(ede-make-check-version)

	(let* ((targ (if isdist (oref this targets) mt))
	       (sp (oref this subproj))
	       (df (apply #'append
			  (mapcar (lambda (tg)
				    (ede-proj-makefile-dependency-files tg))
				  targ))))
	  ;; Distribution variables
	  (ede-compiler-begin-unique
	    (mapc #'ede-proj-makefile-insert-variables targ))
	  ;; Only add the distribution stuff in when depth != 0
	  (let ((top  (ede-toplevel this))
		(tmp this)
		(subdir ""))
	    (insert "VERSION=" (oref top version) "\n"
		    "DISTDIR=$(top)" (oref top name) "-$(VERSION)")
	    (while (ede-parent-project tmp)
	      (setq subdir
		    (concat
		     "/"
		     (file-name-nondirectory
		      (directory-file-name
		       (file-name-directory (oref tmp file))))
		     subdir)
		    tmp (ede-parent-project tmp)))
	    (insert subdir "\n"))
	  ;; Some built in variables for C code
	  (if df
	      (let ((tc depth))
		(insert "top_builddir = ")
		(while (/= 0 tc)
		  (setq tc (1- tc))
		  (insert "..")
		  (if (/= tc 0) (insert "/")))
		(insert "\n")))
	  (insert "\n")
	  ;; Create a variable with all the dependency files to include
	  ;; These methods borrowed from automake.
	  (if (and (oref this automatic-dependencies) df)
	      (progn
		(insert "DEP_FILES="
			(mapconcat (lambda (f)
				     (concat ".deps/"
					     (file-name-nondirectory
					      (file-name-sans-extension
					       f))
					     ".P"))
				   df " "))))
	  ;;
	  ;; Insert ALL Rule
	  ;;
	  (insert "\n\nall:")
	  (mapc (lambda (c)
		  (if (and (slot-exists-p c 'partofall) (oref c partofall))
		      ;; Only insert this rule if it is a part of ALL.
		      (insert " " (ede-proj-makefile-target-name c))))
		targ)
	  (mapc (lambda (c)
		  (insert " " (ede-name c))
		  )
		sp)
	  (insert "\n\n")
	  ;;
	  ;; Add in the include files
	  ;;
	  (mapc (lambda (c)
		  (insert "include " c "\n\n"))
		(oref this include-file))
	  ;; Some C inference rules
	  ;; Dependency rules borrowed from automake.
	  ;;
	  ;; NOTE: This is GNU Make specific.
	  (if (and (oref this automatic-dependencies) df)
	      (insert "DEPS_MAGIC := $(shell mkdir .deps > " null-device " "
		      "2>&1 || :)\n"
		      "-include $(DEP_FILES)\n\n"))
	  ;;
	  ;; General makefile rules stored in the individual targets
	  ;;
	  (ede-compiler-begin-unique
	    (ede-proj-makefile-insert-rules this)
	    (mapc #'ede-proj-makefile-insert-rules targ))
	  ;;
	  ;; phony targets for sub projects
	  ;;
	  (mapc #'ede-proj-makefile-insert-subproj-rules sp)
	  ;;
	  ;; Distribution rules such as CLEAN and DIST
	  ;;
	  (when isdist
	    (ede-proj-makefile-tags this mt)
	    (ede-proj-makefile-insert-dist-rules this)))
	(save-buffer))
       ((eq (oref this makefile-type) 'Makefile.in)
	(error "Makefile.in is not supported"))
       ((eq (oref this makefile-type) 'Makefile.am)
	(require 'ede/pconf)
	;; Basic vars needed:
	(ede-proj-makefile-automake-insert-subdirs this)
	(ede-proj-makefile-automake-insert-extradist this)
	;; Distribution variables
	(let ((targ (if isdist (oref this targets) mt)))
	  (ede-compiler-begin-unique
	    (mapc #'ede-proj-makefile-insert-automake-pre-variables targ))
	  (ede-compiler-begin-unique
	    (mapc #'ede-proj-makefile-insert-source-variables targ))
	  (ede-compiler-begin-unique
	    (mapc #'ede-proj-makefile-insert-automake-post-variables targ))
	  (ede-compiler-begin-unique
	    (ede-proj-makefile-insert-user-rules this))
	  (insert "\n# End of Makefile.am\n")
	  (save-buffer))
	)
       (t (error "Unknown makefile type when generating Makefile")))
      ;; Put the cursor in a nice place
      (goto-char (point-min)))
    ;; If we have an original buffer, then don't kill it.
    (when (not orig-buffer)
      (kill-buffer buff-to-kill))
    ))