link.lsp - universal version

For the Compleat Fan
Locked
itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

link.lsp - universal version

Post by itistoday »

If you need to generate a universal binary from you .lsp file, and you have a universal version of newlisp compiled, I've gone ahead and hacked out a new version of 'link' to copy over the 'ppc' and 'i386' parts, as the version currently shipping with newlisp only copies one of them.

This is unfinished, but it works, and I haven't had the time to clean it up (partly because it's worked so well). If you'd like to improve it, the most important part that needs to be checked is whether or not the MACH-O order is always 'i386', followed by 'ppc', as this script assumes it is, and if for some reason it's not the script won't work properly because of the endian issues (you'll need to flip the '>' to '<' where it says ">ld"):

Code: Select all

(define (link orgExe newExeName lispSourceName)
	(println "original newlisp executable:" orgExe)
	(println "new executable:" newExeName)
	(println "source:" lispSourceName)

    (set 'size (first (file-info orgExe)))

    ;; copy newLISP.exe to the newExeName
    (copy-file orgExe newExeName)

    ;; get the binary representation of size
    (set 'buff (pack "ld" size))

    ;; open the new exe for update
    (set 'handle (open newExeName "u"))
	(println "search: " (search handle "@@@@@@@@"))

    ;; this field gets read by the newLISP startup
    (write-buffer handle buff 4)
    (set 'buff (read-file lispSourceName))
    (set 'keylen (pack "ld" (length buff)))
    (write-buffer handle keylen 4)

    ;; append lisp source encrypted at the end
    (seek handle size)
    (set 'buff (encrypt buff (string (length buff))))
    (write-buffer handle buff (length buff))
	
	;; ppc
	;; TODO: check to see if the order matters, it could be that ppc is first
	;;       you could probably figure this out from the order that lipo spits out
	(unless (find "ppc" (first (exec (append "lipo -info " orgExe))))
		(println "ERROR: PPC not found in newLISP!")
		(close handle)
		(remove-file newExeName)
		(exit 1)
	)
	
	(println "ppc found!")
	;; seek back to the beginning
	(seek handle 0)
	
	(when (println "search: " (search handle "@@@@@@@@"))
		(set 'buff (pack ">ld" size))
	
	    ;; this field gets read by the newLISP startup
	    (write-buffer handle buff 4)
	    (set 'buff (read-file lispSourceName))
	    (set 'keylen (pack ">ld" (length buff)))
	    (write-buffer handle keylen 4)
	)
	;; don't need to reprint the source, it's at the end of the file	
    (close handle)
)
Get your Objective newLISP groove on.

Locked