source: abuse/tags/pd/macabuse/imlib/makelink.lsp @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 11 years ago
  • Imported original public domain release, for future reference.
File size: 12.4 KB
RevLine 
[49]1(setq watcom_include "$(%WATCOM)\\h")
2
3(defun app (head tail) (if (null head) tail (cons (car head) (app (cdr head) tail))))
4
5(defun get-string-section (string start end)
6  (if (> start end)
7      nil
8    (cons (elt string start) (get-string-section string (+ start 1) end))))
9
10(defun replace-string-section (string start end replacement)
11  (concatenate 'string
12               (get-string-section string 0 (- start 1))
13               replacement
14               (get-string-section string (+ end 1) (- (length string) 1))))
15 
16
17(defun replace..withdd (string)
18  (let ((find (search ".." string)))
19    (if find
20        (replace..withdd  (replace-string-section string find (+ find 1) "dd"))
21      string)))
22
23(defun replace.. (string)
24  (if (equal outdir ".")
25      string
26    (let ((find (search ".." string)))
27      (if find
28          (replace..withdd (replace-string-section string find (+ find 1) outdir))
29        string))))
30
31;(setq platform 'WATCOM)
32(setq dirs_to_make '("."))
33
34(defun get_includes (include_list)
35  (if (eq platform 'WATCOM)
36      (cons watcom_include include_list)
37    include_list))
38
39(defun add_dir_to_make (dir_list new_dir) 
40  (if dir_list
41      (if (equal (car dir_list) new_dir)
42          nil
43        (add_dir_to_make (cdr dir_list) new_dir))
44    (setq dirs_to_make (cons new_dir dirs_to_make))))
45
46(defun make_versions ()
47  (if (equal platform 'WATCOM)
48      '("debug" "opt")
49    '("debug" "opt" "profile")))
50
51(defun default_version ()         ;; make will build all targets of this verison 
52  (if (equal platform 'LINUX)      ;; linux is debug platform
53      "debug"                     
54    "opt"))
55
56
57(defun plat_dot_name (platform)
58  (if (eq platform 'SGI)
59      ".sgi"
60    (if (eq platform 'SUN)
61        ".sun"
62      (if (eq platform 'AIX)
63          ".aix"
64        ""))))
65       
66
67(defun get_version_extension (version platform)
68  (concatenate 'string
69               (select version
70                       ("debug"   "")
71                       ("opt"     "o")
72                       ("profile" "p"))
73               (plat_dot_name platform)))
74                   
75                 
76               
77
78
79;(setq o_files '("nfserver" "nfclient" "username" "clisp"    "gui"      "transp"
80;               "collide"  "trig"     "property" "lisp"     "cache"    "particle"
81;               "objects"  "server2"  "client"   "extend"   "console"  "ability"
82;               "items"    "dev"      "chars"    "level"    "smallfnt" "automap"
83;               "help"     "intsect"  "loader"   "seq"      "points"   "fnt6x13"
84;               "morpher"  "menu"     "director" "view"     "config"   "game"
85;               "light"    "devsel"   "crc"      "nnet/nnet"))
86
87
88(defun platform_name (plat)
89     (select plat
90          ('WATCOM "wat")
91          ('LINUX_X11  "linux_x11")
92          ('LINUX_SVGA  "linux_svga")
93          ('LINUX       "linux")
94          ('AIX    "AIX")
95          ('SGI    "SGI")
96          ('SUN    "SUN")))
97
98
99(defun slash ()
100  (if (equal platform 'WATCOM)
101      "\\"
102    "/"))
103
104(defun object_extension ()
105  (if (equal platform 'WATCOM)
106      ".obj"
107    ".o"))
108
109
110(defun version_dir (dir version_name plat)
111;  (let ((platform (if (or (equal plat 'LINUX_SVGA) (equal plat 'LINUX_X11))
112;                "LINUX"
113;              (platform_name plat))))
114    (concatenate 'string dir (platform_name plat) (slash) version_name))
115
116(defun make_obj_name (dir basename version_name plat)
117  (convert_slashes (concatenate 'string (version_dir dir version_name plat)
118               (slash) basename (object_extension)) (slash)))
119
120(defun make_file_name ()
121  (if (equal platform 'WATCOM)
122      "makefile"
123    "Makefile"))
124
125
126(defun link_flags (ver plat)
127  (select plat
128          ('LINUX_SVGA (if (equal ver "profile") "-lvga -lm" "-lvga -lm"))
129          ('LINUX_X11
130                           "/lib/libXext.a /lib/libX11.a -lm")
131          ('SUN "-lX11 -lXext -lm")
132          ('SGI "-lX11 -lXext -lm")
133          ('AIX "-lX11 -lXext -lm")
134          ('WATCOM "")))
135
136
137(defun get_cflags (ver platform)
138  (if (equal platform 'WATCOM)
139      (concatenate 'string
140                   (if (equal ver "debug")
141                       "/zq /d2"
142                     "/omaxne /zp1 /zq -DNO_CHECK")
143                   " -DMANAGE_MEM")
144    (if (equal ver "debug")
145        "-g -DMEM_CHECK -DMANAGE_MEM"
146      (if (equal ver "profile")
147          (if (eq platform 'SGI)
148              "-O2 -g -p -DMEM_CHECK -DMANAGE_MEM"    ; libcrt0 not supported on IRIX 5.3
149            "-O2 -g -pg -DMEM_CHECK -DMANAGE_MEM")
150        "-O2 -DMANAGE_MEM -DNO_CHECK"))))
151
152
153(defun get_compiler (file)
154        (if (equal platform 'WATCOM)
155            "wpp386"
156          "g++"))
157
158(defun line_delimiter ()
159  (if (equal platform 'WATCOM)
160      "&"
161    "\\"))
162
163(defun append_c (filename)
164  (concatenate 'string filename ".c"))
165
166(defun get_objs (list ver plat)
167  (if (null list) nil
168    (let ((x (split_filename (car list) (concatenate 'string outdir (slash)) )))
169      (cons (make_obj_name (car x) (cdr x) ver plat) (get_objs (cdr list) ver plat)))))
170
171
172
173(defun list_files (list)
174  (print "\t" (convert_slashes (car list) (slash)))
175  (if (cdr list)
176      (progn
177        (print " " (line_delimiter) "\n")
178        (list_files (cdr list)))
179    nil))
180
181
182(defun isa_target2 (list platform)
183  (if list
184      (if (eq platform (car list))
185          T
186        (isa_target2 (cdr list) platform))
187    nil))
188
189
190(defun isa_target (list platform)
191  (if list (isa_target2 list platform)
192    T))
193
194(defun add_out_dir (name)
195  (if (equal outdir ".")
196      name
197    (concatenate 'string outdir (slash) name)))
198
199(defun extend_name (name letter version do_it platform)
200  (if do_it   
201      (concatenate 'string name letter (get_version_extension version platform))
202    name))
203
204(defun expand_targets (targets version)
205
206  (if targets
207      (let ((plats (car (cdr (cdr (cdr (cdr (cdr (car targets))))))))
208            (extend (if (eq (car (cdr (cdr (car targets)))) 'self) nil T))
209            (target_name (car (car targets)))
210            (rest (cdr (car targets))))
211
212;       (open_file "/dev/tty" "wb" (print (concatenate 'string outdir target_name) "\n"))
213;                  (print targets))
214
215        (if (eq platform 'LINUX)         
216            (if (isa_target plats 'LINUX_X11)
217                (cons (cons 'LINUX_X11 (cons (extend_name target_name "x" version extend platform) rest))
218                      (if (isa_target plats 'LINUX_SVGA)
219                          (cons (cons 'LINUX_SVGA (cons (extend_name target_name "" version extend platform)
220                                                        rest))
221                                (expand_targets (cdr targets) version))
222                        (expand_targets (cdr targets) version)))
223              (if (isa_target plats 'LINUX_SVGA)
224                  (cons (cons 'LINUX_SVGA (cons (extend_name target_name "" version extend platform)
225                                                rest))
226                        (expand_targets (cdr targets) version))
227                (expand_targets (cdr targets) version)))
228          (if (isa_target plats platform)
229              (cons
230               (cons platform (cons (extend_name target_name "" version extend platform)  rest))
231               (expand_targets (cdr targets) version)
232               )
233             (expand_targets (cdr targets) version))))))
234           
235
236
237
238(defun make_lib_name (target platform version)
239  (let ((x (split_filename target (concatenate 'string "." (slash)))))
240    (replace.. (convert_slashes (concatenate 'string
241                                             (version_dir (car x) version platform)
242                                             (slash) (cdr x) (lib_ext)) (slash)))))
243
244
245(defun get_lib_list (target_list)
246  (nth 3 (car target_list)))
247
248(defun list_targets (targets version)
249  (if targets
250      (let ((platform      (car (car targets)))
251            (target   (nth 1 (car targets)))
252            (ofiles   (nth 2 (car targets)))
253            (libs     (nth 3 (car targets)))
254            (inc      (get_includes (nth 4 (car targets))))
255            (cflags   (nth 5 (car targets))))
256        (print " ")
257        (if (eq libs 'self)
258            (print (make_lib_name target platform version))
259          (if (eq platform 'WATCOM)
260              (print target ".exe")
261            (print target)))
262        (list_targets (cdr targets) version))))
263
264(defun list_depends (file version plat includes cflags libs type)
265  (let ((x (split_filename file (concatenate 'string outdir (slash)))))
266    (add_dir_to_make dirs_to_make
267                     (concatenate 'string (version_dir (car x) version plat) (slash)))
268
269    (let ((ofile (make_obj_name (car x) (cdr x) version plat)))
270      (print ofile " : ")     
271      (print file ".c\n")
272      (compile_to_object file version plat includes cflags type)
273      (for i in (get_depends (concatenate 'string file ".c") (slash) includes) do
274         (print ofile " : " i "\n")))
275    ))
276
277 
278(defun link_files (outname files version plat)
279  (print "\t")
280  (if (eq platform 'WATCOM)
281      (progn
282        (print "wlink @" outname ".lnk\n\n")
283        (open_file (concatenate 'string outname ".lnk") "wb"
284                   (if (eq version "debug")
285                       (print "debug line\n"))
286                   (print "system dos4gw\n")
287                   (print "option caseexact\n")
288                   (print "option map=" outname ".map\n")
289                   (print "debug all\n")
290                   (print "name " outname ".exe\n")
291                   (print "option stack=70k\n")
292                   (for i in files do (print "file " i "\n"))
293                   )
294        )
295    (progn
296      (print "g++ -o " outname " " (line_delimiter) "\n")
297      (list_files files)
298      (print " " (link_flags version plat))
299      (print "\n\n")
300      )))
301
302(defun get_include_string (list)
303  (if list
304      (concatenate 'string (car list) (get_include_string (cdr list)))
305    ""))
306
307(defun compile_to_object (file version plat includes cflags type)
308  (let ((x (split_filename file (concatenate 'string outdir (slash)))))
309    (let ((ofile (make_obj_name (car x) (cdr x) version plat)))
310      (if (eq platform 'WATCOM)
311          (progn
312            (make_compile_header includes)
313            (if (eq 'C type)
314                (print "\twcc386 ")
315              (print "\twpp386 "))
316            (print file ".c -fo=" ofile " " (get_cflags version plat) " " cflags "\n\n"))
317        (progn
318          (if (eq 'C type)
319              (print "\tgcc")
320            (print "\tg++"))
321          (progn
322            (print " -c -o " ofile " " file ".c")
323            (for i in includes do (print " -I" i))
324            (print " " (get_cflags version plat) " " cflags "\n\n" )
325            ))))))
326
327(defun lib_ext ()
328  (if (eq platform 'WATCOM) ".lib"
329    ".a"))
330
331(defun create_archive (target platform version objs)
332  (let ((x (split_filename target (concatenate 'string "." (slash)))))
333    (let ((outname (make_lib_name target platform version)))
334      (if (eq platform 'WATCOM)   
335          (let ((link_bat (concatenate 'string (version_dir (car x) version platform)
336                                    (slash) (cdr x) ".lnk")))
337            (make_dir (concatenate 'string (car x)  (platform_name platform)
338                                       (slash) version (slash)))
339            (open_file link_bat "wb"
340                       (print outname "\n")
341                       (for i in objs do
342                            (print "+ " (convert_slashes i (slash)) "\n")))
343            (print "\twlib /n @" link_bat "\n\n"))
344        (progn
345          (print "\tar ruvs " outname " " (line_delimiter) "\n")
346          (list_files objs)
347          (print "\n\n"))))))
348
349
350                           
351                                   
352                       
353
354(defun make_target (list version)
355  (if list
356      (let ((platform      (car (car list)))
357            (target   (nth 1 (car list)))
358            (ofiles   (nth 2 (car list)))
359            (libs     (nth 3 (car list)))
360            (inc      (get_includes (nth 4 (car list))))
361            (cflags   (nth 5 (car list)))
362            (type     (nth 7 (car list))) )
363        (let ((obj_list  (get_objs ofiles version platform)))
364         
365          (print platform "_" target "_" version "_o_files = " (line_delimiter) "\n")
366          (list_files obj_list)
367          (print "\n\n")
368
369          (make_target (cdr list) version)
370
371          (if (eq libs 'self)
372              (progn
373                (print (make_lib_name target platform version) " : $("
374                       platform "_" target "_" version "_o_files)\n")
375                (create_archive target platform version obj_list))
376            (progn
377              (if  (not (equal "." outdir))
378                  (print outdir (slash)))
379              (print target)
380
381              (if (and (not (eq libs 'self))
382                       (eq platform 'WATCOM))
383                  (print ".exe"))
384
385              (print " : $(" platform "_" target "_" version "_o_files)\n")
386              (link_files target (app obj_list (get_lib_files libs platform version))
387                          version platform)))
388
389
390          (for i in ofiles do
391               (list_depends (convert_slashes i (slash)) version platform inc
392                             (if cflags cflags "") libs type ))
393          (print "\n")
394          ))))
395       
396
397
398(defun get_ex_libs (libname plat version)
399  (if (eq plat 'WATCOM)
400      (if (equal libname "sound") "e:\\sos\\lib\\sosw1cr.lib" nil)
401    (if (eq plat 'LINUX_X11) (if (eq libname "winman") "-lX11 -lXext" nil)
402      (if (eq plat 'LINUX_SVGA) (if (eq libname "winman") "-lvga" nil)
403        nil))))
404                       
405
406(defun get_lib_files (libs plat version) 
407  (if libs
408      (let ((x (get_ex_libs (cdr (split_filename (car libs) "./")) plat version))
409            (rest (get_lib_files (cdr libs) plat version))
410            (this (make_lib_name (car libs) plat version)))
411        (if x
412            (cons x (cons this rest))
413          (cons  this rest)))
414    nil))
415
416   
417(defun make_include_string (list)
418  (if list
419      (concatenate 'string (car list)
420                   (if (cdr list)
421                       (concatenate 'string ";" (make_include_string (cdr list)))
422                     ""))
423    ""))
424     
425(defun make_compile_header (include)
426  (if (eq platform 'WATCOM)
427      (progn
428        (print "\tset include=" (make_include_string include) "\n")) nil))
429       
430
431
432(progn
433           (for i in (make_versions) do
434                (print i " :")
435                (list_targets (expand_targets targets i) i)
436                (print "\n\techo Made " i "\n\n")
437                )
438           (for i in (make_versions) do
439                (make_target (expand_targets targets i) i))
440
441
442)
443
444(print dirs_to_make)
445;(for i in dirs_to_make do (make_dir i))
446
Note: See TracBrowser for help on using the repository browser.