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