Is using TclX acceptable?
Elias Pipping
pipping at macports.org
Sat Apr 14 19:58:24 PDT 2007
I'll begin with a story - scroll down to the part
with exclamation marks in front if you're in a hurry
Working on openssl +universal, I needed a file list.
It'd have to consist of all the single-arch files
(except for the .o files) that end up in the worksrcdir
once compiling for a single architecture has finished.
It'd also come into play when lipo is called. See below
for the two procedures (you can skip that part if you're
only interested in what this mail is about, not the
details)
proc backup {arch} {
global archList fileList workpath
lappend archList ${arch}
foreach fullPath ${fileList} {
regexp {(.+/)([^/]+)} ./$fullPath dummy filePath fileName
xinstall -d ${workpath}/${arch}/${filePath}
xinstall ${fullPath} ${workpath}/${arch}/${filePath}
}
}
proc lipo {} {
global archList fileList workpath
foreach fullPath ${fileList} {
regexp {(.+/)([^/]+)} ./$fullPath dummy filePath fileName
xinstall -d ${filePath}
file delete ${fullPath}
set lipoSources ""
foreach a $archList {
append lipoSources "-arch ${a} ${workpath}/${a}/${fullPath} "
}
system "lipo ${lipoSources}-create -output ${fullPath}"
}
}
What i did to get such a list, worked, but it wasn't
pretty. I inspected the directory manually, looking
for archives (.a), libraries (.dylib, .so) and tests.
The list I ended up with was created through globbing
and explicitly adding files to it (see below)
set binList "apps/openssl"
set enList [glob engines/*.so]
set libList [glob lib*.a lib*.*.*.*.dylib]
set testList [concat test/sha256t test/sha512t [glob test/*test]]
global fileList
set fileList [concat $binList $enList $libList $testList]
As I said before, this is horrible. Instead of creating
such a list manually I though 'why note automate it?'.
In bash it's easy - find files and check their file type
(with /usr/bin/find and /usr/bin/file), see below:
for i in `find * \! -name \*.o`;
do if [ `$FILE $i | $EGREP -c "(Mach-O|ar archive)"` -gt 0 ]
then echo $i
fi
done;
(thanks to Eric Hall for pointing the '\! -name \*.o'
syntax out to me)
It's harder to have that in tcl. Tcl has globbing but
globbing is *not* recursive. I've found recursive
globbing in tcl, though[1]. globrecur.tcl is part
of TclX (BSD license). It even comes with Mac OS X:
/System/Library/Tcl/tclx8.4/globrecur.tcl
! So, the question is, can I savely depend on
! globrecur.tcl? If not, would it be possible to
! somehow include the file in the MacPorts
! distribution (it's under the BSD license after all)
[1] http://tclx.cvs.sourceforge.net/*checkout*/tclx/tclx/library/
globrecur.tcl?revision=1.1
Regards,
Elias
More information about the macports-dev
mailing list