source: abuse/tags/pd/macabuse/imlib/makemake.lsp @ 475

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