1
2
3(defun generate-obj-macro (mname &optional postfix &rest slist)
4  "Generates a macro definition for an OBJs dependency based on a list of source definitions"
5
6  (let*
7      ((replist (apply 'append (mapcar (lambda (sdef)
8                                         (goto-char 0)
9                                         (let*
10                                             ((def (buffer-substring-no-properties
11                                                    (search-forward (concat sdef " = \\\n") nil t)
12                                                    (search-forward "\n\n" nil t)))
13                                              (st (split-string
14                                                   (replace-regexp-in-string "^.*\\.h.*\n" "" def)
15                                                   "\\s-+\\\\?\\|\n" t)))
16                                           st)) slist)))
17       (def-start (search-forward (concat mname " = \\\n") nil t))
18       (def-end (search-forward "\n\n" nil t))
19
20       (repl (mapconcat
21              (lambda (s)
22                (concat "\t"
23                        (replace-regexp-in-string
24                         "\\(\\s-*\\)\\(.*\\)\\.c" "\\1$(OBJ)\\\\\\2.obj" s)
25                        " \\"))
26              replist "\n"))
27       (erepl (if postfix
28                  (concat repl "\n" postfix "\n\n")
29                (concat repl "\n\n")))
30       )
31    (delete-region def-start def-end)
32    (insert erepl))
33  )
34
35