ADDED .fossil-settings/ignore-glob Index: .fossil-settings/ignore-glob ================================================================== --- /dev/null +++ .fossil-settings/ignore-glob @@ -0,0 +1,27 @@ +aclocal.m4 +aclocal/shobj.m4 +aclocal/tcl.m4 +aclocal/versionscript.m4 +config.guess +config.sub +config.log +config.status +configure +install-sh +Makefile +pkgIndex.tcl +tcc/* +work/* +INST/* +tcc4tcl.o +tcc4tcl-static.a +tcc4tcl.so +tcc4tcl.sl +tcc4tcl.dll +tcc4tcl.dll.def +tcc4tcl.dll.a +tcc4tcl.dylib +tcc4tcl.syms +tcc4tcl.vers +TEST-STATUS +__TMP__ ADDED COPYING Index: COPYING ================================================================== --- /dev/null +++ COPYING @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + Index: build/autogen.sh ================================================================== --- build/autogen.sh +++ build/autogen.sh @@ -1,9 +1,10 @@ #! /bin/bash # Download latest copy of autoconf macros ( + mkdir aclocal >/dev/null 2>/dev/null cd aclocal || exit 1 for file in shobj.m4 tcl.m4 versionscript.m4; do rm -f "${file}" ADDED build/makearch.info Index: build/makearch.info ================================================================== --- /dev/null +++ build/makearch.info @@ -0,0 +1,44 @@ +# This is the name of the utility, it will be prefixed to the tarball name +UTIL="tcc4tcl" + +# This is the name of output files that should exist after configure +# procedures. +BINS="tcc4tcl.so" + +# This lists the name of files that are required to exist +## TEST-STATUS is only created if "make test" succeeds +REQS="pkgIndex.tcl TEST-STATUS" + +# Version of utility, if empty it will be guessed. +# If set to "auto" it will be maintained in a file called .version +# in the source directory and the revision will be incremented +# each time a "makearch" is done. +# +# If @@SVNLCR@@ is used anywhere in this version number, it will be +# replaced with the highest last-changed-rev from the output of +# svn info -R (or 0) +VERS="0.3" + +# Space sperated list of documents, if they exist, they will be +# prefixed with the contents of the DOC_HDR file and substitution +# will occur: +# @@UTIL@@ becomes the utility name ${UTIL} +# @@VERS@@ becomes the utility version +# @@DATE@@ becomes the current date +DOCS="README" +DOC_HDR="HEADER" + +# These files follow the same convention as DOCS, but don't have the header +# tacked onto them. +UPDATE_VARS="configure.ac configure" + +# This script is executed immediately after copying the files +# to a temp directory to attempt to compile +BEFORE="build/pre.sh" + +# This script is executed immediately prior to creation of the +# tarball +AFTER="" + +# Files matching these (space-seperated) patterns are deleted +TMPS="*.out HEADER build work INST" ADDED build/tcc-patches/0.9.26/tcc-0.9.26-crosscompilefixes.diff Index: build/tcc-patches/0.9.26/tcc-0.9.26-crosscompilefixes.diff ================================================================== --- /dev/null +++ build/tcc-patches/0.9.26/tcc-0.9.26-crosscompilefixes.diff @@ -0,0 +1,197 @@ +diff -uNr tcc-0.9.26.orig/configure tcc-0.9.26-1crosscompilefixes/configure +--- tcc-0.9.26.orig/configure 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1crosscompilefixes/configure 2014-05-02 01:27:11.267140003 -0500 +@@ -46,16 +46,8 @@ + tcc_lddir= + confvars= + +-cpu=`uname -m` +- +-# OS specific + targetos=`uname -s` +-case $targetos in +- MINGW32*) mingw32=yes;; +- DragonFly) noldl=yes;; +- OpenBSD) noldl=yes;; +- *) ;; +-esac ++cpu=`uname -m` + + # find source path + # XXX: we assume an absolute path is given when launching configure, +@@ -68,47 +60,6 @@ + source_path_used="no" + fi + +-case "$cpu" in +- i386|i486|i586|i686|i86pc|BePC|i686-AT386) +- cpu="x86" +- ;; +- x86_64) +- cpu="x86-64" +- ;; +- arm*) +- case "$cpu" in +- arm|armv4l) +- cpuver=4 +- ;; +- armv5tel|armv5tejl) +- cpuver=5 +- ;; +- armv6j|armv6l) +- cpuver=6 +- ;; +- armv7a|armv7l) +- cpuver=7 +- ;; +- esac +- cpu="armv4l" +- ;; +- alpha) +- cpu="alpha" +- ;; +- "Power Macintosh"|ppc|ppc64) +- cpu="powerpc" +- ;; +- mips) +- cpu="mips" +- ;; +- s390) +- cpu="s390" +- ;; +- *) +- cpu="unknown" +- ;; +-esac +- + for opt do + eval opt=\"$opt\" + case "$opt" in +@@ -156,6 +107,8 @@ + ;; + --cpu=*) cpu=`echo $opt | cut -d '=' -f 2` + ;; ++ --os=*) targetos=`echo $opt | cut -d '=' -f 2-` ++ ;; + --enable-gprof) gprof="yes" + ;; + --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86 +@@ -181,6 +134,55 @@ + esac + done + ++# OS specific ++case $targetos in ++ MINGW32*|mingw32*) mingw32=yes;; ++ DragonFly) noldl=yes;; ++ OpenBSD) noldl=yes;; ++ *) ;; ++esac ++ ++case "$cpu" in ++ i386|i486|i586|i686|i86pc|BePC|i686-AT386) ++ cpu="x86" ++ ;; ++ x86_64) ++ cpu="x86-64" ++ ;; ++ arm*) ++ case "$cpu" in ++ arm|armv4l) ++ cpuver=4 ++ ;; ++ armv5tel|armv5tejl) ++ cpuver=5 ++ ;; ++ armv6j|armv6l) ++ cpuver=6 ++ ;; ++ armv7a|armv7l) ++ cpuver=7 ++ ;; ++ esac ++ cpu="armv4l" ++ ;; ++ alpha) ++ cpu="alpha" ++ ;; ++ "Power Macintosh"|ppc|ppc64) ++ cpu="powerpc" ++ ;; ++ mips) ++ cpu="mips" ++ ;; ++ s390) ++ cpu="s390" ++ ;; ++ *) ++ cpu="unknown" ++ ;; ++esac ++ + # Checking for CFLAGS + if test -z "$CFLAGS"; then + CFLAGS="-Wall -g -O2" +@@ -270,6 +272,8 @@ + --disable-static make libtcc.so instead of libtcc.a + --disable-rpath disable use of -rpath with the above + --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a ++ --cpu=... Specify CPU ++ --os=... Specify OS + --enable-mingw32 build windows version on linux with mingw32 + --enable-cygwin build windows version on windows with cygwin + --enable-cross build cross compilers +diff -uNr tcc-0.9.26.orig/lib/Makefile tcc-0.9.26-1crosscompilefixes/lib/Makefile +--- tcc-0.9.26.orig/lib/Makefile 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1crosscompilefixes/lib/Makefile 2014-05-02 01:55:55.407140003 -0500 +@@ -47,24 +47,22 @@ + ifeq "$(TARGET)" "i386-win32" + OBJ = $(addprefix $(DIR)/,$(WIN32_O)) + TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE +- XCC = $(TCC) -B$(top_srcdir)/win32 -I$(top_srcdir)/include +- XAR = $(DIR)/tiny_libmaker$(EXESUF) ++ XCC = $(CC) -I$(top_srcdir)/win32 -I$(top_srcdir)/include + else + ifeq "$(TARGET)" "x86_64-win32" + OBJ = $(addprefix $(DIR)/,$(WIN64_O)) + TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE +- XCC = $(TCC) -B$(top_srcdir)/win32 -I$(top_srcdir)/include +- XAR = $(DIR)/tiny_libmaker$(EXESUF) ++ XCC = $(CC) -I$(top_srcdir)/win32 -I$(top_srcdir)/include + else + ifeq "$(TARGET)" "i386" + OBJ = $(addprefix $(DIR)/,$(I386_O)) + TGT = -DTCC_TARGET_I386 +- XCC ?= $(TCC) -B$(TOP) ++ XCC ?= $(CC) -I$(TOP) + else + ifeq "$(TARGET)" "x86_64" + OBJ = $(addprefix $(DIR)/,$(X86_64_O)) + TGT = -DTCC_TARGET_X86_64 +- XCC ?= $(TCC) -B$(TOP) ++ XCC ?= $(CC) -I$(TOP) + else + $(error libtcc1.a not supported on target '$(TARGET)') + endif +diff -uNr tcc-0.9.26.orig/win32/lib/crt1.c tcc-0.9.26-1crosscompilefixes/win32/lib/crt1.c +--- tcc-0.9.26.orig/win32/lib/crt1.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1crosscompilefixes/win32/lib/crt1.c 2014-05-02 01:56:11.277140003 -0500 +@@ -19,7 +19,6 @@ + + int _start(void) + { +- __TRY__ + int argc; char **argv; char **env; int ret; + _startupinfo start_info = {0}; + +diff -uNr tcc-0.9.26.orig/win32/lib/wincrt1.c tcc-0.9.26-1crosscompilefixes/win32/lib/wincrt1.c +--- tcc-0.9.26.orig/win32/lib/wincrt1.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1crosscompilefixes/win32/lib/wincrt1.c 2014-05-02 01:56:15.197140003 -0500 +@@ -11,7 +11,6 @@ + + int _winstart(void) + { +- __TRY__ + char *szCmd; + STARTUPINFO startinfo; + int fShow; ADDED build/tcc-patches/0.9.26/tcc-0.9.26-elfsearchforlibtcc.diff Index: build/tcc-patches/0.9.26/tcc-0.9.26-elfsearchforlibtcc.diff ================================================================== --- /dev/null +++ build/tcc-patches/0.9.26/tcc-0.9.26-elfsearchforlibtcc.diff @@ -0,0 +1,31 @@ +diff -uNr tcc-0.9.26.orig/tccelf.c tcc-0.9.26-1elfsearchforlibtcc/tccelf.c +--- tcc-0.9.26.orig/tccelf.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1elfsearchforlibtcc/tccelf.c 2014-05-03 23:24:08.325640003 -0500 +@@ -1349,7 +1349,27 @@ + static inline int tcc_add_support(TCCState *s1, const char *filename) + { + char buf[1024]; ++ char *path; ++ void *check; ++ int i; ++ + snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, filename); ++ check = tcc_open(s1, buf); ++ if (check != NULL) { ++ tcc_close(); ++ } else { ++ for (i = 0; i < s1->nb_library_paths; i++) { ++ path = s1->library_paths[i]; ++ snprintf(buf, sizeof(buf), "%s/%s", path, filename); ++ check = tcc_open(s1, buf); ++ ++ if (check != NULL) { ++ tcc_close(); ++ break; ++ } ++ } ++ } ++ + return tcc_add_file(s1, buf); + } + ADDED build/tcc-patches/0.9.26/tcc-0.9.26-gnusourcesafety.diff Index: build/tcc-patches/0.9.26/tcc-0.9.26-gnusourcesafety.diff ================================================================== --- /dev/null +++ build/tcc-patches/0.9.26/tcc-0.9.26-gnusourcesafety.diff @@ -0,0 +1,13 @@ +diff -uNr tcc-0.9.26.orig/tcc.h tcc-0.9.26-1gnusourcesafety/tcc.h +--- tcc-0.9.26.orig/tcc.h 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1gnusourcesafety/tcc.h 2014-05-02 10:45:54.576640002 -0500 +@@ -21,7 +21,9 @@ + #ifndef _TCC_H + #define _TCC_H + ++#ifndef _GNU_SOURCE + #define _GNU_SOURCE ++#endif + #include "config.h" + + #ifdef CONFIG_TCCBOOT ADDED build/tcc-patches/0.9.26/tcc-0.9.26-setlibpathsooner.diff Index: build/tcc-patches/0.9.26/tcc-0.9.26-setlibpathsooner.diff ================================================================== --- /dev/null +++ build/tcc-patches/0.9.26/tcc-0.9.26-setlibpathsooner.diff @@ -0,0 +1,42 @@ +diff -uNr tcc-0.9.26.orig/libtcc.c tcc-0.9.26-1setlibpathsooner/libtcc.c +--- tcc-0.9.26.orig/libtcc.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1setlibpathsooner/libtcc.c 2014-05-03 23:19:00.965640003 -0500 +@@ -888,7 +888,7 @@ + macro_ptr = NULL; + } + +-LIBTCCAPI TCCState *tcc_new(void) ++LIBTCCAPI TCCState *tcc_new(const char *init_lib_path) + { + TCCState *s; + char buffer[100]; +@@ -900,11 +900,15 @@ + if (!s) + return NULL; + tcc_state = s; ++ if (init_lib_path == NULL) { + #ifdef _WIN32 +- tcc_set_lib_path_w32(s); ++ tcc_set_lib_path_w32(s); + #else +- tcc_set_lib_path(s, CONFIG_TCCDIR); ++ tcc_set_lib_path(s, CONFIG_TCCDIR); + #endif ++ } else { ++ tcc_set_lib_path(s, init_lib_path); ++ } + s->output_type = TCC_OUTPUT_MEMORY; + preprocess_new(); + s->include_stack_ptr = s->include_stack; +diff -uNr tcc-0.9.26.orig/libtcc.h tcc-0.9.26-1setlibpathsooner/libtcc.h +--- tcc-0.9.26.orig/libtcc.h 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1setlibpathsooner/libtcc.h 2014-05-03 23:20:14.785640003 -0500 +@@ -14,7 +14,7 @@ + typedef struct TCCState TCCState; + + /* create a new TCC compilation context */ +-LIBTCCAPI TCCState *tcc_new(void); ++LIBTCCAPI TCCState *tcc_new(const char *init_lib_path); + + /* free a TCC compilation context */ + LIBTCCAPI void tcc_delete(TCCState *s); ADDED build/tcc-patches/0.9.26/tcc-0.9.26-tcl.diff Index: build/tcc-patches/0.9.26/tcc-0.9.26-tcl.diff ================================================================== --- /dev/null +++ build/tcc-patches/0.9.26/tcc-0.9.26-tcl.diff @@ -0,0 +1,65 @@ +--- tcc-0.9.26.orig/configure 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1tcl/configure 2014-05-01 19:50:10.103740647 -0500 +@@ -43,6 +43,7 @@ + tcc_libpaths="" + tcc_crtprefix="" + tcc_elfinterp="" ++tcc_tcl_path="" + tcc_lddir= + confvars= + +@@ -154,6 +155,8 @@ + ;; + --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2` + ;; ++ --with-tcl=*) tcc_tcl_path=`echo $opt | cut -d '=' -f 2-` ++ ;; + --cpu=*) cpu=`echo $opt | cut -d '=' -f 2` + ;; + --enable-gprof) gprof="yes" +@@ -278,6 +281,7 @@ + --libpaths=... specify system library paths, colon separated + --crtprefix=... specify locations of crt?.o, colon separated + --elfinterp=... specify elf interpreter ++ --with-tcl=... specify path to Tcl + EOF + #echo "NOTE: The object files are build at the place where configure is launched" + exit 1 +@@ -339,6 +343,25 @@ + esac + fi + ++print_tcl_defs() { ++ ( ++ tclConfig="$1" ++ . "${tclConfig}" ++ LDFLAGS="$LDFLAGS $TCL_LIB_SPEC $TCL_LIBS" ++ CFLAGS="$CFLAGS $TCL_INCLUDE_SPEC -DHAVE_TCL_H=1" ++ set | egrep '^(CFLAGS|LDFLAGS)=' ++ ) ++} ++ ++if [ -n "${tcc_tcl_path}" ]; then ++ for tcc_tcl_path_file in ${tcc_tcl_path}/{,lib,lib64}/tclConfig.sh; do ++ if [ -f "${tcc_tcl_path_file}" ]; then ++ eval `print_tcl_defs "${tcc_tcl_path_file}"` ++ break ++ fi ++ done ++fi ++ + cat < ++#endif + + #ifdef CONFIG_TCCBOOT + #include "tccboot.h" ADDED build/tcc-patches/0.9.26/tcc-0.9.26-tclio.diff Index: build/tcc-patches/0.9.26/tcc-0.9.26-tclio.diff ================================================================== --- /dev/null +++ build/tcc-patches/0.9.26/tcc-0.9.26-tclio.diff @@ -0,0 +1,430 @@ +diff -uNr tcc-0.9.26.orig/libtcc.c tcc-0.9.26-1tclio/libtcc.c +--- tcc-0.9.26.orig/libtcc.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1tclio/libtcc.c 2014-05-02 01:30:08.967140003 -0500 +@@ -669,7 +669,7 @@ + bf->line_num = 1; + bf->ifndef_macro = 0; + bf->ifdef_stack_ptr = s1->ifdef_stack_ptr; +- bf->fd = -1; ++ bf->fd = NULL; + bf->prev = file; + file = bf; + } +@@ -677,26 +677,35 @@ + ST_FUNC void tcc_close(void) + { + BufferedFile *bf = file; +- if (bf->fd > 0) { +- close(bf->fd); ++ if (bf->fd != NULL) { ++ Tcl_Close(NULL,bf->fd); + total_lines += bf->line_num; + } + file = bf->prev; + tcc_free(bf); + } + +-ST_FUNC int tcc_open(TCCState *s1, const char *filename) ++ST_FUNC Tcl_Channel tcc_open(TCCState *s1, const char *filename) + { +- int fd; +- if (strcmp(filename, "-") == 0) +- fd = 0, filename = "stdin"; +- else +- fd = open(filename, O_RDONLY | O_BINARY); +- if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3) +- printf("%s %*s%s\n", fd < 0 ? "nf":"->", ++ Tcl_Channel fd; ++ Tcl_Obj *path; ++ ++ if (strcmp(filename, "-") == 0) { ++ fd = Tcl_GetStdChannel(TCL_STDIN); ++ filename = "stdin"; ++ } else { ++ path = Tcl_NewStringObj(filename,-1); ++ Tcl_IncrRefCount(path); ++ fd = Tcl_FSOpenFileChannel(NULL,path, "r", 0); ++ Tcl_DecrRefCount(path); ++ } ++ ++ if ((s1->verbose == 2 && fd != NULL) || s1->verbose == 3) ++ printf("%s %*s%s\n", fd == NULL ? "nf":"->", + (int)(s1->include_stack_ptr - s1->include_stack), "", filename); +- if (fd < 0) +- return -1; ++ if (fd == NULL) { ++ return NULL; ++ } + + tcc_open_bf(s1, filename, 0); + file->fd = fd; +@@ -1099,7 +1108,8 @@ + { + const char *ext; + ElfW(Ehdr) ehdr; +- int fd, ret, size; ++ int ret, size; ++ Tcl_Channel ret_chan, fd; + + /* find source file type with extension */ + ext = tcc_fileextension(filename); +@@ -1113,11 +1123,12 @@ + #endif + + /* open the file */ +- ret = tcc_open(s1, filename); +- if (ret < 0) { ++ ret = 0; ++ ret_chan = tcc_open(s1, filename); ++ if (ret_chan == NULL) { + if (flags & AFF_PRINT_ERROR) + tcc_error_noabort("file '%s' not found", filename); +- return ret; ++ return -1; + } + + /* update target deps */ +@@ -1151,8 +1162,8 @@ + + fd = file->fd; + /* assume executable format: auto guess file type */ +- size = read(fd, &ehdr, sizeof(ehdr)); +- lseek(fd, 0, SEEK_SET); ++ size = Tcl_Read(fd, (char *)&ehdr, sizeof(ehdr)); ++ Tcl_Seek(fd, 0, SEEK_SET); + if (size <= 0) { + tcc_error_noabort("could not read header"); + goto the_end; +diff -uNr tcc-0.9.26.orig/tcc.h tcc-0.9.26-1tclio/tcc.h +--- tcc-0.9.26.orig/tcc.h 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1tclio/tcc.h 2014-05-02 01:30:08.967140003 -0500 +@@ -429,7 +429,7 @@ + typedef struct BufferedFile { + uint8_t *buf_ptr; + uint8_t *buf_end; +- int fd; ++ Tcl_Channel fd; + struct BufferedFile *prev; + int line_num; /* current line number - here to simplify code */ + int ifndef_macro; /* #ifndef macro / #endif search */ +@@ -1045,7 +1045,7 @@ + ST_FUNC Sym *global_identifier_push(int v, int t, int c); + + ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen); +-ST_FUNC int tcc_open(TCCState *s1, const char *filename); ++ST_FUNC Tcl_Channel tcc_open(TCCState *s1, const char *filename); + ST_FUNC void tcc_close(void); + + ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags); +@@ -1226,8 +1226,8 @@ + ST_FUNC void relocate_section(TCCState *s1, Section *s); + + ST_FUNC void tcc_add_linker_symbols(TCCState *s1); +-ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset); +-ST_FUNC int tcc_load_archive(TCCState *s1, int fd); ++ST_FUNC int tcc_load_object_file(TCCState *s1, Tcl_Channel fd, unsigned long file_offset); ++ST_FUNC int tcc_load_archive(TCCState *s1, Tcl_Channel fd); + ST_FUNC void tcc_add_bcheck(TCCState *s1); + + ST_FUNC void build_got_entries(TCCState *s1); +@@ -1239,7 +1239,7 @@ + #endif + + #ifndef TCC_TARGET_PE +-ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level); ++ST_FUNC int tcc_load_dll(TCCState *s1, Tcl_Channel fd, const char *filename, int level); + ST_FUNC int tcc_load_ldscript(TCCState *s1); + ST_FUNC uint8_t *parse_comment(uint8_t *p); + ST_FUNC void minp(void); +@@ -1313,7 +1313,7 @@ + + #ifdef TCC_TARGET_COFF + ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f); +-ST_FUNC int tcc_load_coff(TCCState * s1, int fd); ++ST_FUNC int tcc_load_coff(TCCState * s1, Tcl_Channel fd); + #endif + + /* ------------ tccasm.c ------------ */ +@@ -1335,7 +1335,7 @@ + + /* ------------ tccpe.c -------------- */ + #ifdef TCC_TARGET_PE +-ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd); ++ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, Tcl_Channel fd); + ST_FUNC int pe_output_file(TCCState * s1, const char *filename); + ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value); + ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2); +diff -uNr tcc-0.9.26.orig/tcccoff.c tcc-0.9.26-1tclio/tcccoff.c +--- tcc-0.9.26.orig/tcccoff.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1tclio/tcccoff.c 2014-05-02 01:30:08.967140003 -0500 +@@ -858,10 +858,11 @@ + return 0; + } + +-ST_FUNC int tcc_load_coff(TCCState * s1, int fd) ++ST_FUNC int tcc_load_coff(TCCState * s1, Tcl_Channel fd) + { + // tktk TokenSym *ts; + ++ int native_fd; + FILE *f; + unsigned int str_size; + char *Coff_str_table, *name; +@@ -869,8 +870,14 @@ + struct syment csym; + char name2[9]; + FILHDR file_hdr; /* FILE HEADER STRUCTURE */ ++ int tcl_ret; + +- f = fdopen(fd, "rb"); ++ tcl_ret = Tcl_GetChannelHandle(fd, TCL_READABLE, &native_fd); ++ if (tcl_ret != TCL_OK) { ++ tcc_error("Unable to open .out file for input"); ++ } ++ ++ f = fdopen(native_fd, "rb"); + if (!f) { + tcc_error("Unable to open .out file for input"); + } +diff -uNr tcc-0.9.26.orig/tccelf.c tcc-0.9.26-1tclio/tccelf.c +--- tcc-0.9.26.orig/tccelf.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1tclio/tccelf.c 2014-05-02 01:30:08.967140003 -0500 +@@ -2334,13 +2334,13 @@ + return ret; + } + +-static void *load_data(int fd, unsigned long file_offset, unsigned long size) ++static void *load_data(Tcl_Channel fd, unsigned long file_offset, unsigned long size) + { + void *data; + + data = tcc_malloc(size); +- lseek(fd, file_offset, SEEK_SET); +- read(fd, data, size); ++ Tcl_Seek(fd, file_offset, SEEK_SET); ++ Tcl_Read(fd, data, size); + return data; + } + +@@ -2354,7 +2354,7 @@ + /* load an object file and merge it with current files */ + /* XXX: handle correctly stab (debug) info */ + ST_FUNC int tcc_load_object_file(TCCState *s1, +- int fd, unsigned long file_offset) ++ Tcl_Channel fd, unsigned long file_offset) + { + ElfW(Ehdr) ehdr; + ElfW(Shdr) *shdr, *sh; +@@ -2372,7 +2372,7 @@ + + stab_index = stabstr_index = 0; + +- if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr)) ++ if (Tcl_Read(fd, (char *) &ehdr, sizeof(ehdr)) != sizeof(ehdr)) + goto fail1; + if (ehdr.e_ident[0] != ELFMAG0 || + ehdr.e_ident[1] != ELFMAG1 || +@@ -2499,9 +2499,9 @@ + size = sh->sh_size; + if (sh->sh_type != SHT_NOBITS) { + unsigned char *ptr; +- lseek(fd, file_offset + sh->sh_offset, SEEK_SET); ++ Tcl_Seek(fd, file_offset + sh->sh_offset, SEEK_SET); + ptr = section_ptr_add(s, size); +- read(fd, ptr, size); ++ Tcl_Read(fd, ptr, size); + } else { + s->data_offset += size; + } +@@ -2657,7 +2657,7 @@ + } + + /* load only the objects which resolve undefined symbols */ +-static int tcc_load_alacarte(TCCState *s1, int fd, int size) ++static int tcc_load_alacarte(TCCState *s1, Tcl_Channel fd, int size) + { + int i, bound, nsyms, sym_index, off, ret; + uint8_t *data; +@@ -2666,7 +2666,7 @@ + ElfW(Sym) *sym; + + data = tcc_malloc(size); +- if (read(fd, data, size) != size) ++ if (Tcl_Read(fd, data, size) != size) + goto fail; + nsyms = get_be32(data); + ar_index = data + 4; +@@ -2684,7 +2684,7 @@ + printf("%5d\t%s\t%08x\n", i, p, sym->st_shndx); + #endif + ++bound; +- lseek(fd, off, SEEK_SET); ++ Tcl_Seek(fd, off, SEEK_SET); + if(tcc_load_object_file(s1, fd, off) < 0) { + fail: + ret = -1; +@@ -2701,7 +2701,7 @@ + } + + /* load a '.a' file */ +-ST_FUNC int tcc_load_archive(TCCState *s1, int fd) ++ST_FUNC int tcc_load_archive(TCCState *s1, Tcl_Channel fd) + { + ArchiveHeader hdr; + char ar_size[11]; +@@ -2711,10 +2711,10 @@ + unsigned long file_offset; + + /* skip magic which was already checked */ +- read(fd, magic, sizeof(magic)); ++ Tcl_Read(fd, magic, sizeof(magic)); + + for(;;) { +- len = read(fd, &hdr, sizeof(hdr)); ++ len = Tcl_Read(fd, (char *) &hdr, sizeof(hdr)); + if (len == 0) + break; + if (len != sizeof(hdr)) { +@@ -2731,7 +2731,7 @@ + } + ar_name[i + 1] = '\0'; + // printf("name='%s' size=%d %s\n", ar_name, size, ar_size); +- file_offset = lseek(fd, 0, SEEK_CUR); ++ file_offset = Tcl_Seek(fd, 0, SEEK_CUR); + /* align to even */ + size = (size + 1) & ~1; + if (!strcmp(ar_name, "/")) { +@@ -2747,7 +2747,7 @@ + if (tcc_load_object_file(s1, fd, file_offset) < 0) + return -1; + } +- lseek(fd, file_offset + size, SEEK_SET); ++ Tcl_Seek(fd, file_offset + size, SEEK_SET); + } + return 0; + } +@@ -2756,7 +2756,7 @@ + /* load a DLL and all referenced DLLs. 'level = 0' means that the DLL + is referenced by the user (so it should be added as DT_NEEDED in + the generated ELF file) */ +-ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) ++ST_FUNC int tcc_load_dll(TCCState *s1, Tcl_Channel fd, const char *filename, int level) + { + ElfW(Ehdr) ehdr; + ElfW(Shdr) *shdr, *sh, *sh1; +@@ -2767,7 +2767,7 @@ + const char *name, *soname; + DLLReference *dllref; + +- read(fd, &ehdr, sizeof(ehdr)); ++ Tcl_Read(fd, (char *) &ehdr, sizeof(ehdr)); + + /* test CPU specific stuff */ + if (ehdr.e_ident[5] != ELFDATA2LSB || +diff -uNr tcc-0.9.26.orig/tccpe.c tcc-0.9.26-1tclio/tccpe.c +--- tcc-0.9.26.orig/tccpe.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1tclio/tccpe.c 2014-05-02 01:30:08.967140003 -0500 +@@ -1505,10 +1505,10 @@ + + /* ------------------------------------------------------------- */ + +-static int read_mem(int fd, unsigned offset, void *buffer, unsigned len) ++static int read_mem(Tcl_Channel fd, unsigned offset, void *buffer, unsigned len) + { +- lseek(fd, offset, SEEK_SET); +- return len == read(fd, buffer, len); ++ Tcl_Seek(fd, offset, SEEK_SET); ++ return len == Tcl_Read(fd, buffer, len); + } + + /* ------------------------------------------------------------- +@@ -1516,7 +1516,7 @@ + * as generated by 'windres.exe -O coff ...'. + */ + +-static int pe_load_res(TCCState *s1, int fd) ++static int pe_load_res(TCCState *s1, Tcl_Channel fd) + { + struct pe_rsrc_header hdr; + Section *rsrc_section; +@@ -1571,11 +1571,11 @@ + return a; + } + +-static char *get_line(char *line, int size, int fd) ++static char *get_line(char *line, int size, Tcl_Channel fd) + { + int n; + for (n = 0; n < size - 1; ) +- if (read(fd, line + n, 1) < 1 || line[n++] == '\n') ++ if (Tcl_Read(fd, line + n, 1) < 1 || line[n++] == '\n') + break; + if (0 == n) + return NULL; +@@ -1584,7 +1584,7 @@ + } + + /* ------------------------------------------------------------- */ +-static int pe_load_def(TCCState *s1, int fd) ++static int pe_load_def(TCCState *s1, Tcl_Channel fd) + { + int state = 0, ret = -1, dllindex = 0; + char line[400], dllname[80], *p; +@@ -1627,7 +1627,7 @@ + #define TINY_IMPDEF_GET_EXPORT_NAMES_ONLY + #include "win32/tools/tiny_impdef.c" + +-static int pe_load_dll(TCCState *s1, const char *dllname, int fd) ++static int pe_load_dll(TCCState *s1, const char *dllname, Tcl_Channel fd) + { + char *p, *q; + int index; +@@ -1642,7 +1642,7 @@ + } + + /* ------------------------------------------------------------- */ +-ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd) ++ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, Tcl_Channel fd) + { + int ret = -1; + char buf[10]; +diff -uNr tcc-0.9.26.orig/tccpp.c tcc-0.9.26-1tclio/tccpp.c +--- tcc-0.9.26.orig/tccpp.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1tclio/tccpp.c 2014-05-02 01:30:08.967140003 -0500 +@@ -360,13 +360,13 @@ + int len; + /* only tries to read if really end of buffer */ + if (bf->buf_ptr >= bf->buf_end) { +- if (bf->fd != -1) { ++ if (bf->fd != NULL) { + #if defined(PARSE_DEBUG) + len = 8; + #else + len = IO_BUF_SIZE; + #endif +- len = read(bf->fd, bf->buffer, len); ++ len = Tcl_Read(bf->fd, bf->buffer, len); + if (len < 0) + len = 0; + } else { +@@ -1484,7 +1484,7 @@ + goto include_done; + } + +- if (tcc_open(s1, buf1) < 0) ++ if (tcc_open(s1, buf1) == NULL) + include_trynext: + continue; + +diff -uNr tcc-0.9.26.orig/win32/tools/tiny_impdef.c tcc-0.9.26-1tclio/win32/tools/tiny_impdef.c +--- tcc-0.9.26.orig/win32/tools/tiny_impdef.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1tclio/win32/tools/tiny_impdef.c 2014-05-02 01:31:28.497140003 -0500 +@@ -161,7 +161,7 @@ + /* -------------------------------------------------------------- */ + #endif + +-char *get_export_names(int fd) ++char *get_export_names(Tcl_Channel fd) + { + int l, i, n, n0; + char *p; ADDED build/tcc-patches/0.9.26/tcc-0.9.26-win32useopenlibs.diff Index: build/tcc-patches/0.9.26/tcc-0.9.26-win32useopenlibs.diff ================================================================== --- /dev/null +++ build/tcc-patches/0.9.26/tcc-0.9.26-win32useopenlibs.diff @@ -0,0 +1,79 @@ +diff -uNr tcc-0.9.26.orig/tccpe.c tcc-0.9.26-1win32useopenlibs/tccpe.c +--- tcc-0.9.26.orig/tccpe.c 2013-02-15 08:24:00.000000000 -0600 ++++ tcc-0.9.26-1win32useopenlibs/tccpe.c 2014-05-04 02:20:25.285150002 -0500 +@@ -38,6 +38,9 @@ + # define ADDR3264 DWORD + #endif + ++#ifdef TCC_IS_NATIVE ++#include ++#endif + #ifdef _WIN32 + void dbg_printf (const char *fmt, ...) + { +@@ -831,7 +834,27 @@ + if (dllref) { + if ( !dllref->handle ) + dllref->handle = LoadLibrary(dllref->name); +- v = (ADDR3264)GetProcAddress(dllref->handle, name); ++ if (dllref->handle) { ++ v = (ADDR3264)GetProcAddress(dllref->handle, name); ++ } ++ } ++ if (!v) { ++ HANDLE cur_proc = GetCurrentProcess(); ++ HMODULE *modules; ++ DWORD needed, i; ++ ++ needed = 0; ++ EnumProcessModules(cur_proc, NULL, 0, &needed); ++ modules = tcc_malloc(needed); ++ if (EnumProcessModules(cur_proc, modules, needed, &needed)) { ++ for (i = 0; i < needed / sizeof(HMODULE); i++) { ++ v = (ADDR3264)GetProcAddress(modules[i], name); ++ if (v) { ++ break; ++ } ++ } ++ } ++ tcc_free(modules); + } + if (!v) + tcc_error_noabort("undefined symbol '%s'", name); +@@ -1209,9 +1232,35 @@ + + const char *name = symtab_section->link->data + sym->st_name; + unsigned type = ELFW(ST_TYPE)(sym->st_info); +- int imp_sym = pe_find_import(pe->s1, sym); ++ int imp_sym; + struct import_symbol *is; + ++ imp_sym = pe_find_import(pe->s1, sym); ++ if (0 == imp_sym) { ++ HANDLE cur_proc = GetCurrentProcess(); ++ HMODULE *modules; ++ DWORD needed, i; ++ const char *symname; ++ void *addr; ++ ++ symname = pe_export_name(pe->s1, sym); ++ ++ needed = 0; ++ EnumProcessModules(cur_proc, NULL, 0, &needed); ++ modules = tcc_malloc(needed); ++ if (EnumProcessModules(cur_proc, modules, needed, &needed)) { ++ for (i = 0; i < needed / sizeof(HMODULE); i++) { ++ addr = GetProcAddress(modules[i], symname); ++ if (addr) { ++ put_elf_sym( pe->s1->dynsymtab_section, (ADDR3264) addr, sizeof(addr), ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT), 0, SHN_UNDEF, symname); ++ imp_sym = pe_find_import(pe->s1, sym); ++ break; ++ } ++ } ++ } ++ tcc_free(modules); ++ } ++ + if (0 == imp_sym) + goto not_found; + ADDED headers.awk Index: headers.awk ================================================================== --- /dev/null +++ headers.awk @@ -0,0 +1,29 @@ +/^# [0-9][0-9]* /{ + file = $3; + + gsub(/^"/, "", file); + gsub(/"$/, "", file); + + destfile = file; + if (!gsub(/^.*\/include\//, "", destfile)) { + if (!gsub(/^.*\/include-fixed\//, "fix/", destfile)) { + next + } + } + + if (file ~ / 0}} -proc ::tcc::cleanname {n} {regsub -all {[^a-zA-Z0-9_]+} $n _} - -proc ::tcc::ccode {code} { - variable tcc - Log "INJECTING CCODE" - append tcc(code) $code \n -} -proc ::tcc::cc {code} { - variable tcc - if {![info exists tcc(cc)]} { - set tcc(cc) tcc1 - tcc $tcc::dir $tcc(cc) - $tcc(cc) add_library tcl8.5 - $tcc(cc) add_include_path [file join $::tcc::dir include] - } - Log code:$code - $tcc(cc) compile $code -} -#----------------------------------------------------------- New DLL API -proc ::tcc::dll {{name ""}} { - variable count - if {$name eq ""} {set name dll[incr count]} - namespace eval ::tcc::dll::$name { - variable code "#include \n" ;# always needed - variable cmds {} - } - proc ::$name {cmd args} "::tcc::dll::\$cmd $name \$args" - return $name -} -namespace eval ::tcc::dll {} -proc ::tcc::dll::ccode {name argl} { - append ${name}::code \n [lindex $argl 0] - return -} -proc ::tcc::dll::cproc {name argl} { - foreach {pname pargs rtype body} $argl break - set code [::tcc::wrapCmd $pname $pargs $rtype cx_$pname $body] - lappend ${name}::cmds $pname cx_$pname - append ${name}::code \n $code - return -} -proc ::tcc::dll::write {name argl} { - set (-dir) . - set (-code) "" ;# possible extra code to go into the _Init function - set (-libs) "" - set (-name) [string tolower $name] - array set "" $argl - append ${name}::code \n \ - [::tcc::wrapExport $(-name) [set ${name}::cmds] $(-code)] - set outfile $(-dir)/$(-name)[info sharedlibextension] - ::tcc::to_dll [set ${name}::code] $outfile $(-libs) -} -#--------------------------------------------------------------------- -proc ::tcc::wrap {name adefs rtype {body "#"}} { - set cname c_$name - set wname tcl_$name - array set types {} - set names {} - set cargs {} - set cnames {} - # if first arg is "Tcl_Interp*", pass it without counting it as a cmd arg - if {[lindex $adefs 0] eq "Tcl_Interp*"} { - lappend cnames ip - lappend cargs [lrange $adefs 0 1] - set adefs [lrange $adefs 2 end] - } - foreach {t n} $adefs { - set types($n) $t - lappend names $n - lappend cnames _$n - lappend cargs "$t $n" - } - switch -- $rtype { - ok { set rtype2 "int" } - string - dstring - vstring { set rtype2 "char*" } - default { set rtype2 $rtype } - } - set code "" - append code "\n#include " "\n" - if {[info exists tcc(tk)] && $tcc(tk)} { - append code "\#include " "\n" - } - if {$body ne "#"} { - append code "static $rtype2" "\n" - append code "${cname}([join $cargs {, }]) \{\n" - append code $body - append code "\}" "\n" - } else { - append code "#define $cname $name" "\n" - } - # Supported input types - # Tcl_Interp* - # int - # long - # float - # double - # char* - # Tcl_Obj* - # void* - foreach x $names { - set t $types($x) - switch -- $t { - int - long - float - double - char* - Tcl_Obj* { - append cbody " $types($x) _$x;" "\n" - } - default {append cbody " void *_$x;" "\n"} - } - } - if {$rtype ne "void"} { append cbody " $rtype2 rv;" "\n" } - append cbody " if (objc != [expr {[llength $names] + 1}]) {" "\n" - append cbody " Tcl_WrongNumArgs(ip, 1, objv, \"[join $names { }]\");\n" - append cbody " return TCL_ERROR;" "\n" - append cbody " }" "\n" - set n 0 - foreach x $names { - incr n - switch -- $types($x) { - int { - append cbody " if (Tcl_GetIntFromObj(ip, objv\[$n], &_$x) != TCL_OK)" - append cbody " return TCL_ERROR;" "\n" - } - long { - append cbody " if (Tcl_GetLongFromObj(ip, objv\[$n], &_$x) != TCL_OK)" - append cbody " return TCL_ERROR;" "\n" - } - float { - append cbody " {" "\n" - append cbody " double t;" "\n" - append cbody " if (Tcl_GetDoubleFromObj(ip, objv\[$n], &t) != TCL_OK)" - append cbody " return TCL_ERROR;" "\n" - append cbody " _$x = (float) t;" "\n" - append cbody " }" "\n" - } - double { - append cbody " if (Tcl_GetDoubleFromObj(ip, objv\[$n], &_$x) != TCL_OK)" - append cbody " return TCL_ERROR;" "\n" - } - char* { - append cbody " _$x = Tcl_GetString(objv\[$n]);" "\n" - } - default { - append cbody " _$x = objv\[$n];" "\n" - } - } - } - append cbody "\n " - if {$rtype != "void"} {append cbody "rv = "} - append cbody "${cname}([join $cnames {, }]);" "\n" - # Return types supported by critcl - # void - # ok - # int - # long - # float - # double - # char* (TCL_STATIC char*) - # string (TCL_DYNAMIC char*) - # dstring (TCL_DYNAMIC char*) - # vstring (TCL_VOLATILE char*) - # default (Tcl_Obj*) - # Our extensions - # wide - switch -- $rtype { - void { } - ok { append cbody " return rv;" "\n" } - int { append cbody " Tcl_SetIntObj(Tcl_GetObjResult(ip), rv);" "\n" } - long { append cbody " Tcl_SetLongObj(Tcl_GetObjResult(ip), rv);" "\n" } - float - - double { append cbody " Tcl_SetDoubleObj(Tcl_GetObjResult(ip), rv);" "\n" } - char* { append cbody " Tcl_SetResult(ip, rv, TCL_STATIC);" "\n" } - string - - dstring { append cbody " Tcl_SetResult(ip, rv, TCL_DYNAMIC);" "\n" } - vstring { append cbody " Tcl_SetResult(ip, rv, TCL_VOLATILE);" "\n" } - default { append cbody " Tcl_SetObjResult(ip, rv); Tcl_DecrRefCount(rv);" "\n" } - } - if {$rtype != "ok"} {append cbody " return TCL_OK;" \n} - - #puts ----code:\n$code - #puts ----cbody:\n$cbody - list $code $cbody -} -proc ::tcc::wrapCmd {tclname argl rtype cname body} { - foreach {code cbody} [wrap $tclname $argl $rtype $body] break - append code "\nstatic int $cname" - append code {(ClientData cdata,Tcl_Interp *ip, - int objc,Tcl_Obj* CONST objv[])} " \{" - append code \n$cbody \n\}\n -} -proc ::tcc::wrapExport {name cmds {body ""}} { - set code "DLL_EXPORT int [string totitle $name]_Init(Tcl_Interp *interp)" - append code " \{\n" - foreach {tclname cname} $cmds { - append code \ - "Tcl_CreateObjCommand(interp,\"$tclname\",$cname,NULL,NULL);\n" - } - append code $body - append code "\nreturn TCL_OK;\n\}" -} -#--------------------------------------------------------------------- -proc ::tcc::cproc {name adefs rtype {body "#"}} { - foreach {code cbody} [wrap $name $adefs $rtype $body] break - ccode $code - set ns [namespace current] - uplevel 1 [list ${ns}::ccommand $name {dummy ip objc objv} $cbody] -} -#--------------------------------------------------------------------- -proc ::tcc::cdata {name data} { - # Extract bytes from data - binary scan $data c* bytes - set inittext "\n" - set line "" - set n 0 - set l 0 - foreach c $bytes { - if {$n>0} {append inittext ","} - if {$l>20} { - append inittext "\n" - set l 0 - } - if {$l==0} {append inittext " "} - append inittext [format "0x%02X" [expr {$c & 0xff}]] - incr n - incr l - } - append inittext "\n" - set count [llength $bytes] - set cbody "" - append cbody "static unsigned char script\[$count\] = \{" "\n" - append cbody $inittext - append cbody "\};" "\n" - append cbody "Tcl_SetByteArrayObj(Tcl_GetObjResult(ip), (unsigned char*) script, $count);\n" - append cbody "return TCL_OK;" "\n" - set ns [namespace current] - uplevel 1 [list ${ns}::ccommand $name {dummy ip objc objv} $cbody] - return $name -} -#------------------------------------------------------------------- -proc ::tcc::ccommand {procname anames args} { - variable tcc - # Fully qualified proc name - if {[string match "::*" $procname]} { - # procname is already absolute - } else { - set nsfrom [uplevel 1 {namespace current}] - if {$nsfrom eq "::"} {set nsfrom ""} - set procname "${nsfrom}::${procname}" - } - set v(clientdata) clientdata - set v(interp) interp - set v(objc) objc - set v(objv) objv - set id 0 - foreach defname {clientdata interp objc objv} { - if {[llength $anames]>$id} { - set vname [lindex $anames $id] - if {![checkname $vname]} { - error "invalid variable name \"$vname\"" - } - } else {set vname $defname} - set v($defname) $vname - incr id - } - set cname Cmd_N${id}_[cleanname $procname] - set code "" - if {[info exists tcc(tk)] && $tcc(tk)} { - append code "\#include " "\n" - } - if {[info exists tcc(code)] && [string length $tcc(code)]>0} { - append code $tcc(code) - append code "\n" - } - append code "int $cname (ClientData $v(clientdata),Tcl_Interp *$v(interp)," - append code "int $v(objc),Tcl_Obj *CONST $v(objv)\[\]) {" "\n" - append code [lindex $args end] "\n" - append code "}" "\n" - set ns [namespace current] - uplevel 1 [list ${ns}::cc $code] - Log "CREATING TCL COMMAND $procname / $cname" - uplevel 1 [list $tcc(cc) command $procname $cname] - unset tcc(cc) ;# can't be used for compiling anymore -} -proc ::tcc::tk {args} { - variable tcc - set tcc(tk) 1 -} -::tcc::reset -namespace eval tcc {namespace export cproc ccode cdata} - ADDED tcc4tcl.c Index: tcc4tcl.c ================================================================== --- /dev/null +++ tcc4tcl.c @@ -0,0 +1,284 @@ +/* + * TclTCC - Tcl binding to Tiny C Compiler + * + * Copyright (c) 2007 Mark Janssen + * Copyright (c) 2014 Roy Keene + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include "tcc.h" + +struct TclTCCState { + TCCState *s; + int relocated; +}; + +static void Tcc4tclErrorFunc(Tcl_Interp * interp, char * msg) { + Tcl_AppendResult(interp, msg, "\n", NULL); +} + +static void Tcc4tclCCommandDeleteProc (ClientData cdata) { + struct TclTCCState *ts; + TCCState *s ; + + ts = (struct TclTCCState *) cdata; + s = ts->s; + + /* We can delete the compiler if the output was not to memory */ + if (s->output_type != TCC_OUTPUT_MEMORY) { + tcc_delete(s); + ts->s = NULL; + } + + ckfree((void *) ts); +} + +static int Tcc4tclHandleCmd ( ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]){ + unsigned long val; + void *val_p; + int index; + int res; + struct TclTCCState *ts; + TCCState *s; + Tcl_Obj *sym_addr; + static CONST char *options[] = { + "add_include_path", "add_file", "add_library", + "add_library_path", "add_symbol", "command", "compile", + "define", "get_symbol", "output_file", "undefine", (char *) NULL + }; + enum options { + TCLTCC_ADD_INCLUDE, TCLTCC_ADD_FILE, TCLTCC_ADD_LIBRARY, + TCLTCC_ADD_LIBRARY_PATH, TCLTCC_ADD_SYMBOL, TCLTCC_COMMAND, TCLTCC_COMPILE, + TCLTCC_DEFINE, TCLTCC_GET_SYMBOL, TCLTCC_OUTPUT_FILE, TCLTCC_UNDEFINE + }; + + ts = (struct TclTCCState *) cdata; + s = ts->s; + + if (objc < 2) { + Tcl_WrongNumArgs(interp, 1, objv, "subcommand arg ?arg ...?"); + return TCL_ERROR; + } + + if (Tcl_GetIndexFromObj(interp, objv[1], options, "option", 0, + &index) != TCL_OK) { + return TCL_ERROR; + } + switch (index) { + case TCLTCC_ADD_INCLUDE: + if (objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "path"); + return TCL_ERROR; + } else { + tcc_add_include_path(s, Tcl_GetString(objv[2])); + return TCL_OK; + } + case TCLTCC_ADD_FILE: + if (objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "filename"); + return TCL_ERROR; + } else { + if(tcc_add_file(s, Tcl_GetString(objv[2]))!=0) { + return TCL_ERROR; + } else { + return TCL_OK; + } + } + case TCLTCC_ADD_LIBRARY: + if (objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "lib"); + return TCL_ERROR; + } else { + tcc_add_library(s, Tcl_GetString(objv[2])); + return TCL_OK; + } + case TCLTCC_ADD_LIBRARY_PATH: + if (objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "path"); + return TCL_ERROR; + } else { + tcc_add_library_path(s, Tcl_GetString(objv[2])); + return TCL_OK; + } +#if 0 + case TCLTCC_ADD_SYMBOL: + if (objc != 4) { + Tcl_WrongNumArgs(interp, 2, objv, "symbol value"); + return TCL_ERROR; + } + Tcl_GetLongFromObj(interp,objv[3], &val); + + tcc_add_symbol(s,Tcl_GetString(objv[2]),val); + return TCL_OK; +#endif + case TCLTCC_COMMAND: + if (objc != 4) { + Tcl_WrongNumArgs(interp, 2, objv, "tclname cname"); + return TCL_ERROR; + } + if (!ts->relocated) { + if(tcc_relocate(s, TCC_RELOCATE_AUTO)!=0) { + Tcl_AppendResult(interp, "relocating failed", NULL); + return TCL_ERROR; + } else { + ts->relocated=1; + } + } + + val_p = tcc_get_symbol(s, Tcl_GetString(objv[3])); + if (val_p == NULL) { + Tcl_AppendResult(interp, "symbol '", Tcl_GetString(objv[3]),"' not found", NULL); + return TCL_ERROR; + } + + /*printf("symbol: %x\n",val); */ + Tcl_CreateObjCommand(interp,Tcl_GetString(objv[2]),val_p,NULL,NULL); + return TCL_OK; + case TCLTCC_COMPILE: + if(ts->relocated == 1) { + Tcl_AppendResult(interp, "code already relocated, cannot compile more",NULL); + return TCL_ERROR; + } + if (objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "ccode"); + return TCL_ERROR; + } else { + + int i; + Tcl_GetString(objv[2]); + i = tcc_compile_string(s,Tcl_GetString(objv[2])); + if (i!=0) { + Tcl_AppendResult(interp,"compilation failed",NULL); + return TCL_ERROR; + } else { + return TCL_OK; + } + } + case TCLTCC_DEFINE: + if (objc != 4) { + Tcl_WrongNumArgs(interp, 2, objv, "symbol value"); + return TCL_ERROR; + } + tcc_define_symbol(s,Tcl_GetString(objv[2]),Tcl_GetString(objv[3])); + return TCL_OK; + case TCLTCC_GET_SYMBOL: + if (objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "symbol"); + return TCL_ERROR; + } + if (!ts->relocated) { + if(tcc_relocate(s, TCC_RELOCATE_AUTO)!=0) { + Tcl_AppendResult(interp, "relocating failed", NULL); + return TCL_ERROR; + } else { + ts->relocated=1; + } + } + val_p = tcc_get_symbol(s,Tcl_GetString(objv[2])); + if(val_p == NULL) { + Tcl_AppendResult(interp, "symbol '", Tcl_GetString(objv[2]),"' not found", NULL); + return TCL_ERROR; + } + sym_addr = Tcl_NewWideIntObj((Tcl_WideInt) val_p); + Tcl_SetObjResult(interp, sym_addr); + return TCL_OK; + case TCLTCC_OUTPUT_FILE: + if (objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "filename"); + return TCL_ERROR; + } + if (ts->relocated) { + Tcl_AppendResult(interp, "code already relocated, cannot output to file", NULL); + return TCL_ERROR; + } + if (s->output_type == TCC_OUTPUT_MEMORY) { + Tcl_AppendResult(interp, "output_type memory not valid for output to file", NULL); + return TCL_ERROR; + } + res = tcc_output_file(s,Tcl_GetString(objv[2])); + + if (res!=0) { + Tcl_AppendResult(interp, "output to file failed", NULL); + return TCL_ERROR; + } else { + return TCL_OK; + } + case TCLTCC_UNDEFINE: + if (objc != 3) { + Tcl_WrongNumArgs(interp, 2, objv, "symbol"); + return TCL_ERROR; + } + tcc_undefine_symbol(s,Tcl_GetString(objv[2])); + return TCL_OK; + default: + Tcl_Panic("internal error during option lookup"); + } + return TCL_OK; +} + +static int Tcc4tclCreateCmd( ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]){ + struct TclTCCState *ts; + TCCState *s; + int index; + static CONST char *types[] = { + "memory", "exe", "dll", "obj", "preprocess", (char *) NULL + }; + + if (objc < 3 || objc > 4) { + Tcl_WrongNumArgs(interp, 1, objv, "tcc_libary_path ?output_type? handle"); + return TCL_ERROR; + } + + if (objc == 3) { + index = TCC_OUTPUT_MEMORY; + } else { + if (Tcl_GetIndexFromObj(interp, objv[2], types, "type", 0, &index) != TCL_OK) { + return TCL_ERROR; + } + } + + s = tcc_new(Tcl_GetString(objv[1])); + if (s == NULL) { + return(TCL_ERROR); + } + + tcc_set_error_func(s, interp, (void *)&Tcc4tclErrorFunc); + + ts = (void *) ckalloc(sizeof(*ts)); + ts->s = s; + ts->relocated = 0; + + /*printf("type: %d\n", index); */ + tcc_set_output_type(s,index); + Tcl_CreateObjCommand(interp,Tcl_GetString(objv[objc-1]),Tcc4tclHandleCmd,ts,Tcc4tclCCommandDeleteProc); + + return TCL_OK; +} + +int Tcc4tcl_Init(Tcl_Interp *interp) { +#ifdef USE_TCL_STUBS + if (Tcl_InitStubs(interp, "8.4" , 0) == 0L) { + return TCL_ERROR; + } +#endif + + Tcl_CreateObjCommand(interp, PACKAGE_NAME, Tcc4tclCreateCmd, NULL, NULL); + Tcl_PkgProvide(interp, PACKAGE_NAME, PACKAGE_VERSION); + + return TCL_OK; +} ADDED tcc4tcl.syms.in Index: tcc4tcl.syms.in ================================================================== --- /dev/null +++ tcc4tcl.syms.in @@ -0,0 +1,1 @@ +@SYMPREFIX@Tcc4tcl_Init ADDED tcc4tcl.tcl Index: tcc4tcl.tcl ================================================================== --- /dev/null +++ tcc4tcl.tcl @@ -0,0 +1,370 @@ +# tcc.tcl - library routines for the tcc wrapper (Mark Janssen) + +namespace eval tcc4tcl { + variable dir + variable libs + variable includes + variable count + variable command_count + variable commands + + set dir [file dirname [info script]] + if {[info command ::tcc4tcl] == ""} { + catch { load {} tcc4tcl } + } + if {[info command ::tcc4tcl] == ""} { + load [file join $dir tcc4tcl[info sharedlibextension]] tcc4tcl + } + set libs $dir/lib + set includes $dir/include + set count 0 + set command_count 0 + array set commands {} + proc new {} { + variable dir + variable count + set handle tcc_[incr count] + tcc4tcl $dir $handle + return tcc_$count + } + proc tclcommand {handle name ccode} { + variable commands + variable command_count + set cname _tcc_tcl_command_[incr command_count] + set code {#include "tcl.h"} + append code "\n int $cname" + append code "(ClientData cdata,Tcl_Interp *interp,int objc,Tcl_Obj* CONST objv[]){" + append code "\n$ccode" + append code "}" + $handle compile $code + set commands($handle,$name) $cname + return + } + proc compile {handle} { + variable commands + foreach cmd [array names commands $handle*] { + puts $cmd + puts $commands($cmd) + set cname $commands($cmd) + set tclcommand [join [lrange [split $cmd ,] 1 end] {}] + set handle [lindex [split $cmd ,] 0] + $handle command $tclcommand $cname + } + return + } +} +proc tcc4tcl::to_dll {code dll {libs {}}} { + tcc4tcl $::tcc4tcl::dir dll tcc_1 + foreach lib $libs {tcc_1 add_library $lib} + if {$::tcl_platform(platform) eq "windows"} { + tcc_1 define DLL_EXPORT {__declspec(dllexport)} + set f [open $::tcc4tcl::dir/c/dllcrt1.c] + tcc_1 compile [read $f] + close $f + set f [open $::tcc4tcl::dir/c/dllmain.c] + tcc_1 compile [read $f] + close $f + } else { + tcc_1 define DLL_EXPORT "" + } + tcc_1 compile $code + tcc_1 output_file $dll + rename tcc_1 {} +} +proc ::tcc4tcl::Log {args} { + # puts $args +} +proc ::tcc4tcl::reset {} { + variable tcc + set tcc(code) "" + set tcc(cfiles) [list] + set tcc(tk) 0 +} +# Custom helpers +proc ::tcc4tcl::checkname {n} {expr {[regexp {^[a-zA-Z0-9_]+$} $n] > 0}} +proc ::tcc4tcl::cleanname {n} {regsub -all {[^a-zA-Z0-9_]+} $n _} + +proc ::tcc4tcl::ccode {code} { + variable tcc + Log "INJECTING CCODE" + append tcc(code) $code \n +} +proc ::tcc4tcl::cc {code} { + variable tcc + if {![info exists tcc(cc)]} { + set tcc(cc) tcc1 + tcc4tcl $::tcc4tcl::dir $tcc(cc) + } + Log code:$code + $tcc(cc) compile $code +} +#----------------------------------------------------------- New DLL API +proc ::tcc4tcl::dll {{name ""}} { + variable count + if {$name eq ""} {set name dll[incr count]} + namespace eval ::tcc4tcl::dll::$name { + variable code "#include \n" ;# always needed + variable cmds {} + } + proc ::$name {cmd args} "::tcc4tcl::dll::\$cmd $name \$args" + return $name +} +namespace eval ::tcc4tcl::dll {} +proc ::tcc4tcl::dll::ccode {name argl} { + append ${name}::code \n [lindex $argl 0] + return +} +proc ::tcc4tcl::dll::cproc {name argl} { + foreach {pname pargs rtype body} $argl break + set code [::tcc4tcl::wrapCmd $pname $pargs $rtype cx_$pname $body] + lappend ${name}::cmds $pname cx_$pname + append ${name}::code \n $code + return +} +proc ::tcc4tcl::dll::write {name argl} { + set (-dir) . + set (-code) "" ;# possible extra code to go into the _Init function + set (-libs) "" + set (-name) [string tolower $name] + array set "" $argl + append ${name}::code \n \ + [::tcc4tcl::wrapExport $(-name) [set ${name}::cmds] $(-code)] + set outfile $(-dir)/$(-name)[info sharedlibextension] + ::tcc4tcl::to_dll [set ${name}::code] $outfile $(-libs) +} +#--------------------------------------------------------------------- +proc ::tcc4tcl::wrap {name adefs rtype {body "#"}} { + set cname c_$name + set wname tcl_$name + array set types {} + set names {} + set cargs {} + set cnames {} + # if first arg is "Tcl_Interp*", pass it without counting it as a cmd arg + if {[lindex $adefs 0] eq "Tcl_Interp*"} { + lappend cnames ip + lappend cargs [lrange $adefs 0 1] + set adefs [lrange $adefs 2 end] + } + foreach {t n} $adefs { + set types($n) $t + lappend names $n + lappend cnames _$n + lappend cargs "$t $n" + } + switch -- $rtype { + ok { set rtype2 "int" } + string - dstring - vstring { set rtype2 "char*" } + default { set rtype2 $rtype } + } + set code "" + append code "\n#include " "\n" + if {[info exists tcc(tk)] && $tcc(tk)} { + append code "\#include " "\n" + } + if {$body ne "#"} { + append code "static $rtype2" "\n" + append code "${cname}([join $cargs {, }]) \{\n" + append code $body + append code "\}" "\n" + } else { + append code "#define $cname $name" "\n" + } + # Supported input types + # Tcl_Interp* + # int + # long + # float + # double + # char* + # Tcl_Obj* + # void* + foreach x $names { + set t $types($x) + switch -- $t { + int - long - float - double - char* - Tcl_Obj* { + append cbody " $types($x) _$x;" "\n" + } + default {append cbody " void *_$x;" "\n"} + } + } + if {$rtype ne "void"} { append cbody " $rtype2 rv;" "\n" } + append cbody " if (objc != [expr {[llength $names] + 1}]) {" "\n" + append cbody " Tcl_WrongNumArgs(ip, 1, objv, \"[join $names { }]\");\n" + append cbody " return TCL_ERROR;" "\n" + append cbody " }" "\n" + set n 0 + foreach x $names { + incr n + switch -- $types($x) { + int { + append cbody " if (Tcl_GetIntFromObj(ip, objv\[$n], &_$x) != TCL_OK)" + append cbody " return TCL_ERROR;" "\n" + } + long { + append cbody " if (Tcl_GetLongFromObj(ip, objv\[$n], &_$x) != TCL_OK)" + append cbody " return TCL_ERROR;" "\n" + } + float { + append cbody " {" "\n" + append cbody " double t;" "\n" + append cbody " if (Tcl_GetDoubleFromObj(ip, objv\[$n], &t) != TCL_OK)" + append cbody " return TCL_ERROR;" "\n" + append cbody " _$x = (float) t;" "\n" + append cbody " }" "\n" + } + double { + append cbody " if (Tcl_GetDoubleFromObj(ip, objv\[$n], &_$x) != TCL_OK)" + append cbody " return TCL_ERROR;" "\n" + } + char* { + append cbody " _$x = Tcl_GetString(objv\[$n]);" "\n" + } + default { + append cbody " _$x = objv\[$n];" "\n" + } + } + } + append cbody "\n " + if {$rtype != "void"} {append cbody "rv = "} + append cbody "${cname}([join $cnames {, }]);" "\n" + # Return types supported by critcl + # void + # ok + # int + # long + # float + # double + # char* (TCL_STATIC char*) + # string (TCL_DYNAMIC char*) + # dstring (TCL_DYNAMIC char*) + # vstring (TCL_VOLATILE char*) + # default (Tcl_Obj*) + # Our extensions + # wide + switch -- $rtype { + void { } + ok { append cbody " return rv;" "\n" } + int { append cbody " Tcl_SetIntObj(Tcl_GetObjResult(ip), rv);" "\n" } + long { append cbody " Tcl_SetLongObj(Tcl_GetObjResult(ip), rv);" "\n" } + float - + double { append cbody " Tcl_SetDoubleObj(Tcl_GetObjResult(ip), rv);" "\n" } + char* { append cbody " Tcl_SetResult(ip, rv, TCL_STATIC);" "\n" } + string - + dstring { append cbody " Tcl_SetResult(ip, rv, TCL_DYNAMIC);" "\n" } + vstring { append cbody " Tcl_SetResult(ip, rv, TCL_VOLATILE);" "\n" } + default { append cbody " Tcl_SetObjResult(ip, rv); Tcl_DecrRefCount(rv);" "\n" } + } + if {$rtype != "ok"} {append cbody " return TCL_OK;" \n} + + #puts ----code:\n$code + #puts ----cbody:\n$cbody + list $code $cbody +} +proc ::tcc4tcl::wrapCmd {tclname argl rtype cname body} { + foreach {code cbody} [wrap $tclname $argl $rtype $body] break + append code "\nstatic int $cname" + append code {(ClientData cdata,Tcl_Interp *ip, + int objc,Tcl_Obj* CONST objv[])} " \{" + append code \n$cbody \n\}\n +} +proc ::tcc4tcl::wrapExport {name cmds {body ""}} { + set code "DLL_EXPORT int [string totitle $name]_Init(Tcl_Interp *interp)" + append code " \{\n" + foreach {tclname cname} $cmds { + append code \ + "Tcl_CreateObjCommand(interp,\"$tclname\",$cname,NULL,NULL);\n" + } + append code $body + append code "\nreturn TCL_OK;\n\}" +} +#--------------------------------------------------------------------- +proc ::tcc4tcl::cproc {name adefs rtype {body "#"}} { + foreach {code cbody} [wrap $name $adefs $rtype $body] break + ccode $code + set ns [namespace current] + uplevel 1 [list ${ns}::ccommand $name {dummy ip objc objv} $cbody] +} +#--------------------------------------------------------------------- +proc ::tcc4tcl::cdata {name data} { + # Extract bytes from data + binary scan $data c* bytes + set inittext "\n" + set line "" + set n 0 + set l 0 + foreach c $bytes { + if {$n>0} {append inittext ","} + if {$l>20} { + append inittext "\n" + set l 0 + } + if {$l==0} {append inittext " "} + append inittext [format "0x%02X" [expr {$c & 0xff}]] + incr n + incr l + } + append inittext "\n" + set count [llength $bytes] + set cbody "" + append cbody "static unsigned char script\[$count\] = \{" "\n" + append cbody $inittext + append cbody "\};" "\n" + append cbody "Tcl_SetByteArrayObj(Tcl_GetObjResult(ip), (unsigned char*) script, $count);\n" + append cbody "return TCL_OK;" "\n" + set ns [namespace current] + uplevel 1 [list ${ns}::ccommand $name {dummy ip objc objv} $cbody] + return $name +} +#------------------------------------------------------------------- +proc ::tcc4tcl::ccommand {procname anames args} { + variable tcc + # Fully qualified proc name + if {[string match "::*" $procname]} { + # procname is already absolute + } else { + set nsfrom [uplevel 1 {namespace current}] + if {$nsfrom eq "::"} {set nsfrom ""} + set procname "${nsfrom}::${procname}" + } + set v(clientdata) clientdata + set v(interp) interp + set v(objc) objc + set v(objv) objv + set id 0 + foreach defname {clientdata interp objc objv} { + if {[llength $anames]>$id} { + set vname [lindex $anames $id] + if {![checkname $vname]} { + error "invalid variable name \"$vname\"" + } + } else {set vname $defname} + set v($defname) $vname + incr id + } + set cname Cmd_N${id}_[cleanname $procname] + set code "" + if {[info exists tcc(tk)] && $tcc(tk)} { + append code "\#include " "\n" + } + if {[info exists tcc(code)] && [string length $tcc(code)]>0} { + append code $tcc(code) + append code "\n" + } + append code "int $cname (ClientData $v(clientdata),Tcl_Interp *$v(interp)," + append code "int $v(objc),Tcl_Obj *CONST $v(objv)\[\]) {" "\n" + append code [lindex $args end] "\n" + append code "}" "\n" + set ns [namespace current] + uplevel 1 [list ${ns}::cc $code] + Log "CREATING TCL COMMAND $procname / $cname" + uplevel 1 [list $tcc(cc) command $procname $cname] + unset tcc(cc) ;# can't be used for compiling anymore +} +proc ::tcc4tcl::tk {args} { + variable tcc + set tcc(tk) 1 +} +::tcc4tcl::reset +namespace eval tcc4tcl {namespace export cproc ccode cdata} + DELETED tcltcc.c Index: tcltcc.c ================================================================== --- tcltcc.c +++ /dev/null @@ -1,253 +0,0 @@ -/* - * TclTCC - Tcl binding to Tiny C Compiler - * - * Copyright (c) 2007 Mark Janssen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -static void TccErrorFunc(Tcl_Interp * interp, char * msg) { - Tcl_AppendResult(interp, msg, "\n", NULL); -} - - -static void TccCCommandDeleteProc (ClientData cdata) { - TCCState * s ; - s = (TCCState *)cdata; - Tcl_DecrRefCount(s->tcc_lib_path); - /* We can delete the compiler if the output was not to memory */ - if (s->output_type != TCC_OUTPUT_MEMORY) { - tcc_delete(s); - } -} - -static int TccHandleCmd ( ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]){ - unsigned long val; - int index; - int res; - TCCState * s = (TCCState *)cdata ; - Tcl_Obj * sym_addr; - - static CONST char *options[] = { - "add_include_path", "add_file", "add_library", - "add_library_path", "add_symbol", "command", "compile", - "define", "get_symbol", "output_file", "undefine", (char *) NULL - }; - enum options { - TCLTCC_ADD_INCLUDE, TCLTCC_ADD_FILE, TCLTCC_ADD_LIBRARY, - TCLTCC_ADD_LIBRARY_PATH, TCLTCC_ADD_SYMBOL, TCLTCC_COMMAND, TCLTCC_COMPILE, - TCLTCC_DEFINE, TCLTCC_GET_SYMBOL, TCLTCC_OUTPUT_FILE, TCLTCC_UNDEFINE - }; - - - if (objc < 2) { - Tcl_WrongNumArgs(interp, 1, objv, "subcommand arg ?arg ...?"); - return TCL_ERROR; - } - - if (Tcl_GetIndexFromObj(interp, objv[1], options, "option", 0, - &index) != TCL_OK) { - return TCL_ERROR; - } - switch (index) { - case TCLTCC_ADD_INCLUDE: - if (objc != 3) { - Tcl_WrongNumArgs(interp, 2, objv, "path"); - return TCL_ERROR; - } else { - tcc_add_include_path(s, Tcl_GetString(objv[2])); - return TCL_OK; - } - case TCLTCC_ADD_FILE: - if (objc != 3) { - Tcl_WrongNumArgs(interp, 2, objv, "filename"); - return TCL_ERROR; - } else { - if(tcc_add_file(s, Tcl_GetString(objv[2]))!=0) { - return TCL_ERROR; - } else { - return TCL_OK; - } - } - case TCLTCC_ADD_LIBRARY: - if (objc != 3) { - Tcl_WrongNumArgs(interp, 2, objv, "lib"); - return TCL_ERROR; - } else { - tcc_add_library(s, Tcl_GetString(objv[2])); - return TCL_OK; - } - case TCLTCC_ADD_LIBRARY_PATH: - if (objc != 3) { - Tcl_WrongNumArgs(interp, 2, objv, "path"); - return TCL_ERROR; - } else { - tcc_add_library_path(s, Tcl_GetString(objv[2])); - return TCL_OK; - } - case TCLTCC_ADD_SYMBOL: - if (objc != 4) { - Tcl_WrongNumArgs(interp, 2, objv, "symbol value"); - return TCL_ERROR; - } - Tcl_GetLongFromObj(interp,objv[3], &val); - tcc_add_symbol(s,Tcl_GetString(objv[2]),val); - return TCL_OK; - case TCLTCC_COMMAND: - if (objc != 4) { - Tcl_WrongNumArgs(interp, 2, objv, "tclname cname"); - return TCL_ERROR; - } - if (!s->relocated) { - if(tcc_relocate(s)!=0) { - Tcl_AppendResult(interp, "relocating failed", NULL); - return TCL_ERROR; - } else { - s->relocated=1; - } - } - if (tcc_get_symbol(s,&val,Tcl_GetString(objv[3]))!=0) { - Tcl_AppendResult(interp, "symbol '", Tcl_GetString(objv[3]),"' not found", NULL); - return TCL_ERROR; - } - - /*printf("symbol: %x\n",val); */ - Tcl_CreateObjCommand(interp,Tcl_GetString(objv[2]),(void *)val,NULL,NULL); - return TCL_OK; - case TCLTCC_COMPILE: - if(s->relocated == 1) { - Tcl_AppendResult(interp, "code already relocated, cannot compile more",NULL); - return TCL_ERROR; - } - if (objc != 3) { - Tcl_WrongNumArgs(interp, 2, objv, "ccode"); - return TCL_ERROR; - } else { - - int i; - Tcl_GetString(objv[2]); - i = tcc_compile_string(s,Tcl_GetString(objv[2])); - if (i!=0) { - Tcl_AppendResult(interp,"compilation failed",NULL); - return TCL_ERROR; - } else { - return TCL_OK; - } - } - case TCLTCC_DEFINE: - if (objc != 4) { - Tcl_WrongNumArgs(interp, 2, objv, "symbol value"); - return TCL_ERROR; - } - tcc_define_symbol(s,Tcl_GetString(objv[2]),Tcl_GetString(objv[3])); - return TCL_OK; - case TCLTCC_GET_SYMBOL: - if (objc != 3) { - Tcl_WrongNumArgs(interp, 2, objv, "symbol"); - return TCL_ERROR; - } - if (!s->relocated) { - if(tcc_relocate(s)!=0) { - Tcl_AppendResult(interp, "relocating failed", NULL); - return TCL_ERROR; - } else { - s->relocated=1; - } - } - if(tcc_get_symbol(s,&val,Tcl_GetString(objv[2]))!=0) { - Tcl_AppendResult(interp, "symbol '", Tcl_GetString(objv[2]),"' not found", NULL); - return TCL_ERROR; - } - sym_addr = Tcl_NewLongObj(val); - Tcl_SetObjResult(interp, sym_addr); - return TCL_OK; - case TCLTCC_OUTPUT_FILE: - if (objc != 3) { - Tcl_WrongNumArgs(interp, 2, objv, "filename"); - return TCL_ERROR; - } - if (s->relocated) { - Tcl_AppendResult(interp, "code already relocated, cannot output to file", NULL); - return TCL_ERROR; - } - if (s->output_type == TCC_OUTPUT_MEMORY) { - Tcl_AppendResult(interp, "output_type memory not valid for output to file", NULL); - return TCL_ERROR; - } -#ifdef WIN32 - res = tcc_output_pe(s,Tcl_GetString(objv[2])); -#else - res = tcc_output_file(s,Tcl_GetString(objv[2])); -#endif - - if (res!=0) { - Tcl_AppendResult(interp, "output to file failed", NULL); - return TCL_ERROR; - } else { - return TCL_OK; - } - case TCLTCC_UNDEFINE: - if (objc != 3) { - Tcl_WrongNumArgs(interp, 2, objv, "symbol"); - return TCL_ERROR; - } - tcc_undefine_symbol(s,Tcl_GetString(objv[2])); - return TCL_OK; - default: - Tcl_Panic("internal error during option lookup"); - } - return TCL_OK; -} - -static int TccCreateCmd( ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]){ - TCCState * s; - static CONST char *types[] = { - "memory", "exe", "dll", "obj", "preprocess", (char *) NULL - }; - int index; - if (objc < 3 || objc > 4) { - Tcl_WrongNumArgs(interp, 1, objv, "tcc_libary_path ?output_type? handle"); - return TCL_ERROR; - } - if (objc == 3) { - index = TCC_OUTPUT_MEMORY; - } else { - if (Tcl_GetIndexFromObj(interp, objv[2], types, "type", 0, - &index) != TCL_OK) { - return TCL_ERROR; - } - } - s = tcc_new(objv[1]); - tcc_set_error_func(s, interp, (void *)&TccErrorFunc); - s->relocated = 0; - /*printf("type: %d\n", index); */ - tcc_set_output_type(s,index); - Tcl_CreateObjCommand(interp,Tcl_GetString(objv[objc-1]),TccHandleCmd,s,TccCCommandDeleteProc); - - return TCL_OK; -} - -DLL_EXPORT int Tcc_Init(Tcl_Interp *interp) -{ - if (Tcl_InitStubs(interp, "8.4" , 0) == 0L) { - return TCL_ERROR; - } - Tcl_CreateObjCommand(interp,PACKAGE_NAME,TccCreateCmd,NULL,NULL); - Tcl_PkgProvide(interp,PACKAGE_NAME,PACKAGE_VERSION); - return TCL_OK; -} - - - ADDED test Index: test ================================================================== --- /dev/null +++ test @@ -0,0 +1,6 @@ +#! /usr/bin/env tclsh + +source tcc4tcl.tcl +tcc4tcl::cproc test {int i} int { return(i+42); } +tcc4tcl::cproc test1 {int i} int { return(i+42); } +puts [test 1]