Move the libmtp source from jumper to external.

Change-Id: I06bce6628cf809af6f7125c8fb4115bafd7c6c87
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..4ce8132
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,40 @@
+libmtp was invented by:
+
+Richard Low <richard@wentnet.com>
+Linus Walleij <triad@df.lth.se>
+
+We both came to do libmtp after working on the libnjb
+project, which was all about Creative Technology devices
+implementing the OASiS and PDE protocols.
+
+libmtp is however largely based on libptp2, which was created by
+Mariusz Woloszyn <emsi@ipartners.pl> as part of gPhoto2 then
+derived into its own project.
+
+We later started to use libgphoto2 which is also based on the same
+code as libptp2 but with large contributions from
+Marcus Meissner <marcus@jet.franken.de>. Marcus is also a
+contributor on libmtp from time to time and we're great friends.
+
+Other contributors to libmtp include:
+
+Andy Kelk <andy@mopoke.co.uk>
+Chris A. Debenham <chris@adebenham.com>
+Daniel Williams <danielw@iinet.net.au>
+Dave Kelly <libmtp@ravelox.co.uk>
+Matthew Wilcox <matthew@wil.cx>
+Robert Reardon <rreardon@monkshatch.vispa.com>
+Orson Teodoro <orsonteodoro@yahoo.com>
+Ted Bullock <tbullock@canada.com>
+Sean Kellogg <skellogg@gmail.com>
+Tero Saarni <tero.saarni@gmail.com>
+Jeff Mitchell <kde-dev@emailgoeshere.com>
+Johannes Huber <johub1180@gmx.at>
+Alistair Boyle <alistair.js.boyle@gmail.com>
+Chris Bagwell <chris@cnpbagwell.com>
+Joseph Nahmias <joe@nahmias.net>
+Florent Mertens <flomertens@gmail.com>
+Alvin <alvinbeach@gmail.com>
+James Ravenscroft <ravenscroftj@gmail.com>
+Thomas Schweitzer <thomas_-_s@users.sourceforge.net>
+Nyall Dawson <nyall@zombiepigs.net>
\ No newline at end of file
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..213a1ab
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,504 @@
+		  GNU LESSER GENERAL PUBLIC LICENSE
+		       Version 2.1, February 1999
+
+ Copyright © 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.
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright © <year>  <name of author>
+
+    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.1 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.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..f6c3500
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,2720 @@
+2009-09-12  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump version to libmtp 1.0.1 and release!
+	* src/Makefile.am: bump soversion to libmtp.so.8.3.1
+
+2009-09-11  Linus Walleij <triad@df.lth.se>
+
+	* src/music-players.h: tag all SONY NWZ walkmen with
+	  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST.
+
+2009-08-27  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: modernize the album retrieveal functions
+	  so they work just as nicely as the track/playlist etc
+	  functions. Triggered by Nyalls excellent bug report that
+	  showed how libmtp tried to get "composer" info for an
+	  album eventhough the device didn't support it.
+
+2009-08-27  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: bugfixes again...
+
+2009-08-25  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: fix a bug where the metadata was cached
+	  twice, thx to Marcus for the patch!
+
+2009-08-23  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: sync to upstream
+	* src/ptp.h: dito.
+	* src/libmtp.c: patch from Thomas Schweitzer to not use
+	  C++ reserved words like "private" and "new", this was
+	  changed to "priv" and "newlist" making C++ happy.
+	* src/libusb-glue.h: inclusion guard, export functions to
+	  C++ (whoever wants to do that...)
+	* src/libusb-glue.c: define USB_CLASS_PTP unless defined,
+	  out-commented code to detect all PTP devices as MTP
+	  devices as well.
+
+2009-08-12  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: patch from Simon Berg to detect PTP
+	  interface descriptors.
+	* src/ptp.c: sync to upstream with correct MTP interface
+	  detection in accordance with MTP spec.
+	* src/ptp.h: dito.
+
+2009-08-02  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: tag for libmtp 1.0.0!
+	* src/Makefile.am: bump to compatible API/ABI
+	  result = libmtp.so.8.3.0
+	* src/libmtp.c: missing flag fix from Marcus.
+
+2009-07-24  Linus Walleij <triad@df.lth.se>
+
+	* src/device-flags.h: add a flag for unknown FLAC type.
+	* src/music-players.h: tag the Cowon iAudio S9 with this.
+	* src/libmtp.c: implement unknown FLAC type.
+
+2009-07-24  Linus Walleij <triad@df.lth.se>
+
+	* src/music-players.h: a number of new devices.
+	* src/ptp.c: sync to upstream.
+	* src/ptp.h: sync to upstream.
+	* src/ptp-pack.c: sync to upstream.
+
+2009-06-24  Linus Walleij <triad@df.lth.se>
+
+	* src/music-players.h: tag most all Samsung devices with
+	  the UNLOAD_DRIVER flag. Broken GET_ALL info in all
+	  Creative devices.
+
+2009-06-20  Linus Walleij <triad@df.lth.se>
+
+	* examples/pathutils.c: detect VCF files too.
+
+2009-06-15  Marcus Meissner <meissner@suse.de>
+
+	* configure.ac: use the AC_SYS_LARGEFILE macro instead
+	  of the ugly largefile hacks.
+	* src/libmtp.c: fix use of largefile back to the simple
+	  functions instead.
+	* examples/albumart.c: dito.
+	* examples/sendfile.c: dito.
+	* examples/sendtr.c: dito.
+	* examples/thumb.c: dito.
+
+2009-06-15  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: some buildsystem updates.
+	* INSTALL: some doc updates.
+
+2009-06-15  Marcus Meissner <meissner@suse.de>
+
+	* src/libmtp.c: synced to new libgphoto2 code.
+	* src/device-flags.h: dito.
+	* src/ptp.h: sync to upstream.
+	* src/ptp.c: dito.
+	* src/ptp-pack.c: dito.
+
+	The handles, the PTPObjectInfo and the MTP proplists
+	are now consolidated into "PTPObject"s.
+
+	This and abstraction and the resulting helper functions
+	allow implementation of easier dynamic operations like
+	I need for libgphoto2.
+
+	Some corner stones:
+
+	- PTPParams now contains the device flags itself.
+	  (from device-flags.h) This is needed due to
+	  ptp_object_want() needing to decide whether it can call
+	  GetObjPropList, and it makes it cleaner.
+
+	  So the ptp-bugs and device-flags handling are unified.
+
+	- PTPObjects are sorted by object handle. This allows binary
+	  search by handle.
+
+	- New generic helper functions.
+
+	  * uint16_t ptp_object_find (PTPParams *params,
+	    uint32_t handle, PTPObject **retob)
+	    binary searches the handle in the object list and returns
+	    a pointer to the object.
+
+	  * uint16_t ptp_object_find_or_insert (PTPParams *params,
+	    uint32_t handle, PTPObject **retob)
+	    binary searches the handle in the object list, inserts it
+	    if not there yet, and returns a pointer to the object.
+
+	  * uint16_t ptp_object_want (PTPParams *params, uint32_t handle,
+	    int want, PTPObject **retob)
+	    The most magic function, which does the "on demand" loading
+	    of objectinfos, mtp proplists (and more).
+	    want is a flag mask of PTPOBJECT_*_LOADED
+	    PTPOBJECT_OBJECTINFO_LOADED   clear
+	    PTPOBJECT_CANONFLAGS_LOADED   (special canon flags)
+	    PTPOBJECT_MTPPROPLIST_LOADED  mtp properties for this object
+	                                  loaded
+	    PTPOBJECT_DIRECTORY_LOADED    (only used by libgphoto2 currently)
+	    PTPOBJECT_PARENTOBJECT_LOADED this and storageid are
+	                                  interesting for directory based
+	                                  lookups
+	    PTPOBJECT_STORAGEID_LOADED    and can be filled out by directory
+	                                  loading
+
+	  * void ptp_objects_sort (PTPParams *params);
+	    Sort the objects list if you did any modification of your own
+	    on it and the order of object handles might not be linear
+	    anymore.
+
+	- Multiple object information loading strategies are possible.
+	  libmtp uses getobjecthandles() /getobjectinfo() and
+	  getobjectproplist() loading strategies for initial setup. This
+	  stays of course, it will just fill out the PTPObject array.
+
+	  libgphoto2 now uses a per-directory getobjecthandles() /
+	  getobjectinfo() loading approach, and I will readd the
+	  getobjectproplist() approach.
+
+	  It is open what you chose to use here. For libmtp the "load all
+	  handles at startup" is good, dynamic loading is better for
+	  libgphoto2.
+
+	  Only rule is: The objectlist must be in order of objecthandles!
+	  (ptp_object_sort()).
+
+2009-06-02  Linus Walleij <triad@df.lth.se>
+
+	* examples/hotplug.c: change the udev match rule from
+	  ATTR{dev}!="?*" to ENV{MAJOR}!="?*" at the suggestion of
+	  Alan Jenkins, this should be faster.
+	* src/libusb-glue.c: include config.h (Marcus Meissner found
+	  this is needed when you're not using iconv().)
+
+2009-05-09  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: include <config.h> for iconv() compatibility.
+	* src/unicode.c: dito. NOTE: this file needs fixing to work
+	  without iconv!
+	* src/ptp.h: sync to upstream and get all the embedded support
+	  for FREE!
+	* src/ptp.c: dito.
+	* src/ptp-pack.c: dito.
+
+2009-05-06  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.h: sync to upstream.
+	* src/ptp.c: dito.
+	* src/ptp-pack.c: dito.
+
+2009-05-06  Linus Walleij <triad@df.lth.se>
+
+	A host of Windows fixes from
+	Carlo Bramini <carlo_bramini@users.sourcefore.net>
+	With this patch everything works fine with cygwin and
+	Debian 5.0. Unfortunately, with MSys the "make install"
+	still fails at the very last actions. It happens that
+	everything is re-linked (strange, but not a big problem)
+	and for some unknown reason it loops forever when executing
+	"examples/hotplug > libmtp.usermap". But hopefully the
+	simple "make" completes without errors.
+
+	* configure.ac:
+	  * iconv is now detected with autotools, this makes libmtp
+	    linkable on cygwin too (previously it was not).
+	  * the presence of Microsoft LIB.EXE is checked; if it is
+	    absent then the MSVC libraries won't be generated.
+	  * Added checking for some include files not available on
+	    Windows: arpa/inet.h, byteswap.h, sys/uio.h.
+	  * Check for presence of mkstemp: a replacement has been
+	    written for Windows.
+	* examples/Makefile.am: the creation of the links failed:
+	  I added source path and $(EXEEXT) extension for executables.
+	  This is tested and working with Mingw+MSys, Cygwin, Debian 5.0.
+	* examples/albumart.c: include sys/uio.h only if it's available.
+	* examples/trexist.c: u_int32_t does not exists, into almost all
+	  other parts libmtp is using uint32_t so I fixed it in that
+	  manner. (Same for u_int64_t/uint64_t).
+	* examples/getfile.c: dito.
+	* examples/pathutils.c: dito, plus rindex() does not exist under
+	  Windows, we must user strrchr() instead.
+	* examples/pathutils.h: fixes for prototypes changes made into
+	  examples/pathutils.c
+	* examples/thumb.c: include sys/uio.h only if it's available.
+	* src/Makefile.am:
+	  * Several fixes because the check on the presence of LIB.EXE
+	    libmtp.sym is now prefixed by $(srcdir), this allows to
+	    configure libmtp outside the source tree in Windows too.
+	  * Libraries are put into LIBADD instead of LDFLAGS, this is the
+	    right place.
+	  * Previously the linker crashed because there was -ws2_32
+	    instead of -lws2_32.
+	* src/playlist-spl.c:
+	  * include sys/uio.h only if it's available.
+	  * include replacement for mkstemp() function.
+
+2009-05-03  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: add external property types just like file
+	  types so any property can be retrieved/set. Add function
+	  LIBMTP_Is_Property_Supported to determine if a property is
+	  supported for a given object type. Add function
+	  LIBMTP_Get_Allowed_Property_Values to get alowed range/enum
+	  of a property value. Make
+	  LIBMTP_Get_Representative_Sample_Format get the size parameter
+	  to allow us to determine the maximum size for a representative
+	  sample.
+	* src/libmtp.h.in: ditto
+	* src/libusb-glue.c: update to check the handler function return
+	  value so the handler can return PTP_ERROR_CANCEL to cancel the
+	  transfer.
+
+2009-05-02 Richard Low <richard@wentnet.com>
+
+	* src/ptp-pack.c: add a NULL check
+
+2009-04-18  Richard Low <richard@wentnet.com>
+
+	* src/ptp-pack.c: add terminating NULL character
+
+2009-04-11  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: Make get_playlist_extension return type
+	  const char *
+	* src/libusb-glue.h: ditto
+	* src/libusb-glue.c: In probe_device_descriptor, check to see if
+	  dev->config is NULL before going round the first loop
+	* src/libmtp.c: Add LIBMTP_Get_File_To_Handler,
+	  LIBMTP_Send_File_From_Handler, LIBMTP_Get_Track_To_Handler,
+	  LIBMTP_Send_Track_From_Handler functions to get/send files/tracks
+	  from/to handler functions. Add modificationdate to file and track
+	  structs. Add LIBMTP_FILETYPE_ALBUM and LIBMTP_FILETYPE_PLAYLIST
+	  filetypes.
+
+2009-03-17  Linus Walleij <triad@df.lth.se>
+
+	* src/device-flags.h: discovered a new device that cannot even
+	  read out battery level but still claims to be able to. Sigh.
+	* src/libusb-glue.h: flag macro.
+	* src/music-players.h: flag the Slacker.
+	* src/libmtp.c: avoid battery level getting on these devices.
+	* configure.ac: preparing for 0.3.7.
+	* src/Makefile.am: preparing for 0.3.7 (libmtp.so.8.2.2)
+	* Release libmtp 0.3.7.
+
+2009-03-08  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: refactored OGG extenstion check again, same
+	  code in three places, broke it out and made it foolproof
+	  (hopefully) in one single spot.
+
+2009-03-04  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: patch from Marcus to fix an issue
+	  with retransmit originally reported by Florent Pillet.
+
+2009-02-21  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: some additional NULL checks from
+	  Florent Pillet.
+
+2009-02-18  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: error report from RedHat BZ
+	  http://bugzilla.redhat.com/show_bug.cgi?id=485627
+	  led to strange code for detecting anonymous OGG files
+	  being rewritten to handle NULL filenames and filenames
+	  that do not exceed 4 chars.
+
+2009-01-30  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: store albums and playlists in the default
+	  music folder if no default folder for albums resp.
+	  playlists has been detected.
+
+2009-01-22  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump to 0.3.6 and release.
+	* src/Makefile.am: interface bump to libmtp.so.8.2.1
+	
+2009-01-16  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: sync to upstream.
+	* src/ptp.h: dito.
+
+2009-01-15  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: include fixes from Yuri Pankov for *BSD.
+	* src/playlist-spl.c: dito.
+	* examples/*.c: (more or less) dito.
+
+2009-01-14  Linus Walleij <triad@df.lth.se>
+
+	* src/device-flags.h: new device flag for broken
+	  SendObjectPropList, as found broken in MEU202
+	* src/music-players.h: use the new flag.
+	* src/libmtp.c: implement this device flag.
+	* src/libusb-glue.h: dito.
+
+2009-01-10  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: mingw32 fixes from James Ravenscroft.
+	* src/libmtp.c: dito. Replaced "rindex" with "strrchr"
+	* src/Makefile.am: dito.
+	* examples/albumart.c: dito.
+
+2009-01-06  Linus Walleij <triad@df.lth.se>
+
+	* src/Makefile.am: patch from Rafael Laboissiere removing a
+	  build artifact in distclean.
+
+2009-01-02  Linus Walleij <triad@df.lth.se>
+
+	* examples/connect.c: usage patch from Riley Patterson.
+	* examples/sendtr.c: dito. Plus only try to add track to an
+	  album if and only if an album name was given.
+	* examples/newfolder.c: real bad bug fixed, didn't even work
+	  due to bad args check.
+	* examples/sendfile.c: another bad bug...
+	* examples/common.h: include <config.h> not "config.h"
+	* src/unicode.h: no reason for this to include config.h!
+
+2008-12-21  Linus Walleij <triad@df.lth.se>
+
+	* Release libmtp 0.3.5.
+
+2008-12-15  Nathan Bullock <nathanbullock@gmail.com>
+
+	* src/libmtp.c: get folders to a flat list and we get O(n) searching
+	  instead of the previous O(n^2) algorithm!
+
+2008-12-13  Linus Walleij <triad@df.lth.se>
+
+	* examples/detect.c: make mtp-detect dump out default-capabilities.xml
+	  if such a file exists on the device.
+	* m4/stdint.m4: update to newer macro from libgphoto2.
+	* m4/byteorder.m4: update to newer macro from libgphoto2.
+	  We find these here:
+	  http://gphoto.svn.sourceforge.net/viewvc/gphoto/trunk/m4/
+	* configure.ac: fix the renamed _stdint.h too.
+	* Doxyfile.in: some config option got obsolete.
+	* libmtp.c: start to use PTP error redirection to the libmtp error
+	  stack. This also makes it possible to stop the annoying debug prints.
+	* libusb-glue.c: dito.
+	* ptp.c: sync to upstream.
+	* ptp.h: sync to upstream.
+
+2008-12-02  Linus Walleij <triad@df.lth.se>
+
+	* examples/util.c: another NULL check.
+
+2008-11-25  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: fix a bug on handling folder children with an illegal
+	  ID of 0. Occured in the ZEN Xi-Fi in the "Recordings" folder, when
+	  that is created on the device.
+
+2008-11-17  Alistair Boyle <alistair.js.boyle@gmail.com>
+
+	* configure.ac: change release to 0.3.5.
+	* libmtp.c: change metadata const*const to *const to allow playlist_id
+	  to be modified by LIBMTP_Update_Playlist. (Samsung playlists)
+	* libmtp.h.in: match libmtp.c
+
+2008-11-11  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: allow for playlists with zero tracks on them,
+	  also in update.
+
+2008-11-09  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.h: sync from upstream.
+	* src/ptp.c: sync from upstream.
+	* src/ptp-pack.c: sync from upstream.
+
+2008-11-07  Linus Walleij <triad@df.lth.se>
+
+	* Release libmtp 0.3.4.
+	* configure.ac: let's release 0.3.4.
+	* src/Makefile.am: compatible API and ABI.
+	
+2008-11-05  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: fix the association type problem on
+	  LIBMTP_Create_Folder(). This causes folders not to
+	  work properly on some devices!!
+
+2008-11-01  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.h: sync to upstream.
+	* src/ptp.c: sync to upstream.
+	* src/ptp-pack.c: introduce Richards bugfix on top of
+	  upstream and take advantage of the ptp_debug() function.
+	* src/libusb-glue.c: make ptp_debug() non-static since
+	  ptp-pack.c needs it.
+
+2008-10-21  Linus Walleij <triad@df.lth.se>
+
+	* src/device-flags.h: actually the SanDisks cannot handle
+	  PTP_OPC_DateModified at ALL, not even as part of the
+	  initial update so rename the flag to something sensible.
+	* src/music-players.h: consequental changes.
+	* src/libmtp.c: disable all use of PTP_OPC_DateModified if
+	  flag is set, not just updates.
+
+2008-10-16  Linus Walleij <triad@df.lth.se>
+
+	* src/device-flags.h: new flag for broken updates of
+	  PTP_OPC_DateModified.
+	* src/music-players.h: tag all SanDisk devices with this
+	  flag. Bug appeared in them.
+	* libmtp.c: avoid updating PTP_OPC_DateModified on broken
+	  devices.
+
+2008-09-28  Alvin <alvinbeach@gmail.com>
+
+	* src/libmtp.c: fix several bugs in Ogg filetype support.
+
+2008-09-26  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: check propdesc before setting props in
+	  create_new_abstract_list()
+
+2008-09-25  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump to 0.3.3.
+	* src/Makefile.am: interface to .so.8.1.0
+	* Release as 0.3.3.
+	
+2008-09-24  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: add new filename setting functions, patch
+	  from Florent Mertens <flomertens@gmail.com>.
+	* src/libmtp.c: implementation.
+	* src/playlist-spl.c: consequental changes.
+	* src/libmtp.sym: consequental changes.
+	* Fixup patch from Alvin later this day.
+	* Note to self: remember to bump soname to .so.8.1.0.
+
+2008-09-23  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: check for NULL storage
+	* src/libusb-glue.c: return PTP_RC_OK on zero read
+	* src/music-players.h: give Samsung YP-10 DEVICE_FLAG_NO_ZERO_READS
+
+2008-09-22  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: make sure we don't try to fit a new file onto
+	  a ROM storage. Add some pretty-print to FourCC codecs so
+	  you can actually understand the enumerations.
+
+2008-09-20  Joe Nahmias <joe@nahmias.net>
+
+	* examples/sendtr.c: added option to specify which 
+	  storage_id the track should be copied.
+
+2008-09-20  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump to 0.3.2.
+	* src/Makefile.am: bump to libmtp.so.8.0.2, compatible
+	  interface.
+	* Release this as 0.3.2 mainly to get the Creative fixes out.
+
+2008-09-17  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: new helper macros from
+	  Alvin <alvinbeach@gmail.com> plus some docs.
+
+2008-09-12  Linus Walleij <triad@df.lth.se>
+
+	* src/music-players.h: drop bug flags off the Creative devices.
+	  I am confident that the bugs they were masking have been
+	  fixed now.
+
+2008-09-07  Richard Low <richard@wentnet.com>
+
+	* src/music-players.h: added Panasonic P905i
+
+2008-09-05  Marcus Meissner <meissner@suse.de>
+
+	* src/libmtp.sym: update symbol export table.
+	* src/Makefile.am: fix up some magic for symbol export.
+
+2008-09-04  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: look up the filename for playlists if the name is 
+	  missing or not properly set. Not doing the same for albums -
+	  these must have proper metadata.
+	* src/music-players.h: more players as usual.
+	* examples/sendtr.c: more warnings.
+
+2008-08-31  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.h: sync to upstream.
+	* src/ptp.c: sync to upstream.
+
+2008-08-30  Chris Bagwell <chris@cnpbagwell.com>
+
+	* src/libusb-glue.c: make it possible to have per-command
+	  or otherwise altered timeout values for different PTP
+	  request/response sequences.
+	* src/libusb-glue.h: dito.
+	* src/libmtp.c: increase USB timeout to 30s when getting
+	  a complete track listing off the device.
+	* src/music-players.h: as a consequence, the Sirus Stiletto
+	  no longer needs any brokenness flag.
+
+2008-08-30  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: sync to upstream.
+
+2008-08-28  Linus Walleij <triad@df.lth.se>
+
+	* examples/sendtr.c: fix non-strdup():ed strings to be
+	  copied, patch courtesy of Juanan Pereira.
+
+2008-08-25  Linus Walleij <triad@df.lth.se>
+
+	* src/Makefile.am: bump interface a patchlevel. (Fully
+	  compatible.)
+	* configure.ac: bump version to 0.3.1.
+	* Release as libmtp 0.3.1.
+
+2008-08-18  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: some vartype and return flunkies.
+	* configure.ac: check for locale.h
+	* examples/util.c: set locale to pick up environment.
+
+2008-08-17  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: some handling of ptp_usb_getdata()
+	  when passed in data size was 0xffffffffU, data
+	  sent in first transaction was ignored, fix by
+	  Rob Woolley.
+	* src/ptp-pack.c: sync in from upstream libgphoto2.
+	* src/README: move relevant stuff to README.
+	* README: see above.
+
+2008-08-15  Alistair Boyle <alistair.js.boyle@gmail.com>
+
+	* src/playlist-spl.c: added handling of Samsung's
+	  proprietary .spl playlist format.
+	* src/playlist-spl.h: dito.
+	* src/device-flags.h: new flags for Samsung playlists.
+	* src/music-players.h: assign flags.
+	* src/libusb-glue.h: convenience macros.
+	* src/libmtp.c: integrate Samsung playlists.
+
+2008-08-15  Linus Walleij <triad@df.lth.se>
+
+	* examples/Makefile.am: break out utility functions
+	  (currently only checklang()) to a separate file.
+	* examples/util.h: dito.
+	* examples/util.c: dito.
+	* examples/detect.c: dito.
+	* examples/sendtr.c: dito.
+	* examples/connect.c: dito.
+
+2008-08-14  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: add some documentation to file and track
+	  listing functions to that it's clear that you have to
+	  inspect storage_id and parent_id in order to group files
+	  into storages and/or folders.
+
+2008-07-31  Linus Walleij <triad@df.lth.se>
+
+	* src/music-players.h: several new devices and flags.
+
+2008-06-24  Linus Walleij <triad@df.lth.se>
+
+	* TODO: updates.
+	* src/Makefile.am: bump interface to libmtp.so.8.0.0.
+	  It's NOT compatible!
+	* RELEASE libmtp 0.3.0 and let the apps developers have
+	  their apps fixed!
+	
+2008-06-22  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: removed the parenthandle argument from
+	  LIBMTP_Send_File_From_File(),
+	  LIBMTP_Send_File_From_File_Descriptor(),
+	  LIBMTP_Send_Track_From_File(),
+	  LIBMTP_Send_Track_From_File_Descriptor(),
+	  LIBMTP_Create_New_Playlist() and
+	  LIBMTP_Create_New_Album()
+	  Now you must pass in parent ID from a metadata or
+	  filedata set. Use the respective field of the
+	  file, track, playlist or album struct to pass in
+	  a parent handle when calling these functions from
+	  now on. The bonus for changing your code is that you
+	  can now also pass in a storage_id with any metadata
+	  set! Consequently LIBMTP_Create_Folder() was
+	  altered to accept THREE metadata arguments: name,
+	  parent_id and storage_id. All calls to any of these
+	  functions in any referring code need to be altered to
+	  use this scheme. It should be quite self-evident for
+	  most code and easy to perform.
+	* src/libmtp.c: changed outlined above were implemented.
+	* examples/newfolder.c: consequental changes.
+	* examples/sendfile.c: consequental changes.
+	* examples/sendtr.c: consequental changes.
+	* examples/albumart.c: consequental changes.
+	* examples/newplaylist.c: consequental changes.
+	* examples/files.c: consequental changes.
+	* examples/tracks.c: correct misleading strings.
+
+2008-06-15  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: only look for default folders in the
+	  root folder on the primary storage, even.
+
+2008-06-14  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: only look for default folders in the
+	  primary storage, and only try to put files there
+	  if they are targetting the primary storage.
+	
+2008-06-08  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: check for the langinfo.h header.
+	* examples/connect.c: check charset properly.
+	* examples/sendtr.c: dito.
+	* src/music-players.h: new devices galore.
+	
+2008-06-03  Linus Walleij <triad@df.lth.se>
+
+	* src/device-flags.h: new device flag for devices that
+	  always need to have their device descriptor probed.
+	* src/music-players.h: generously add this flag to all
+	  SanDisk devices. The e280v2 and Fuze are known to be
+	  especially problematic.
+	* src/libusb-glue.h: helper macro.
+	* src/libusb-glue.c: massage "OS Descriptor" on demand
+	  when opening the device.
+	* src/music-players.h: detailed info and flags for the
+	  SanDisk Sansa players. More to be done, probably.
+
+2008-06-02  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: refactor PTP_USB to use the raw
+	  device and its contained deviceinfo to store and
+	  retrieve the device flags. (This is starting to look
+	  object oriented...)
+	* src/libusb-glue.h: accessor functions to simplify
+	  switching on the device flags and increase the code
+	  readability.
+	* src/libmtp.c: use the new accessor functions.
+	
+2008-06-01  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: use LIBMTP_Detect_Raw_Devices() and
+	  LIBMTP_Open_Raw_Device() inside 
+	  LIBMTP_Get_First_Device() refactoring. Move
+	  params creation into this file.
+	* src/libusb-glue.c: move params creation away
+	  from here.
+
+2008-05-30  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: unused variable.
+	* examples/detect.c: switch to using raw device
+	  interface for opening devices.
+
+2008-05-28  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: internally using the raw devices to
+	  get a list of devices.
+	* src/ptp.c: sync to upstream.
+	* src/ptp.h: dito.
+	* src/ptp-pack.c: dito.
+	* src/libmtp.h.in: move raw device detection to use
+	  error codes. Add interface to open a raw device!
+	* src/libusb-glue.h: make the old device list internal,
+	  use raw device in interface for configuring USB.
+	* src/libusb-glue.c: fix up error messages. Move the
+	  raw device detection interface to use error codes.
+	* examples/detect.c: fix up error messages. Use error
+	  codes for raw devices.
+
+2008-05-23  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: after sending a file, look up the
+	  resulting file metadata from the cache to make sure
+	  that parent_id is identical to that the file actually
+	  gets on the device. If root folder (0) is selected, we
+	  hardcode thing to 0xffffffffu to be used as parent,
+	  but it will probably end up being 0 for example.
+	  Also fix an issue with ptp_mtp_getobjectproplist()
+	  sometimes returning a NULL pointer while still
+	  claiming there are props in the list.
+	* src/libusb-glue.h: add a function to get the preferred
+	  playlist extension.
+	* src/libusb-glue.c: "written" variable in
+	  ptp_usb_sendreq() may end up uninitialized if
+	  ptp_write_func() fails. Initialize it to 0.
+	  Get the prefered playlist extension.
+
+2008-05-18  Richard Low <richard@wentnet.com>
+
+	* src/device-flags.h: added
+	  DEVICE_FLAG_BROKEN_SET_SAMPLE_DIMENSIONS device flag
+	* src/music-players.h: ditto. Also set Samsung YH-999 to
+ 	  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL based on users
+	  experience.
+	* src/libmtp.c: added
+          DEVICE_FLAG_BROKEN_SET_SAMPLE_DIMENSIONS device flag
+
+2008-05-05  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: assign device name and flags to
+	  detected raw devices, slowly preparing to move to 
+	  using the raw device detection internally as well.
+
+2008-05-04  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: move useful filetype macros here so
+	  external programs can use them.
+	* src/libmtp.c: consequental changes.
+	* examples/sendtr.c: use the new macro to detect track
+	  content.
+
+2008-05-03  Johannes Huber <johub1180@gmx.at>
+
+	* src/libmtp.h.in: add interface for setting album composer,
+	  needed for classical albums, on abstract albums.
+	* src/libmtp.c: implement it.
+	* examples/albums.c: consequental changes.
+	* examples/connect.c: dito.
+	* examples/sendtr.c: dito.
+	* examples/tracks.c: dito.
+	* AUTHORS: new contributor.
+
+2008-04-27  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: recognize audio files as tracks, since this
+	  is what WMP does. (e.g. it sets playlength on movies
+	  to enable skip bar) also define macros for audio/video/both
+	  types and tidy up a bit.
+
+2008-04-24  Linus Walleij <triad@df.lth.se>
+	
+	* src/libmtp.h.in: added preliminary interface for getting
+	  raw devices.
+	* src/libusb-glue.c: the implementation is all here!
+	* src/libusb-glue.h: add some bus and device fields to the
+	  internal device list.
+	* examples/detect.c: exercise the raw device detection code.
+	
+2008-03-26  Linus Walleij <triad@df.lth.se>
+
+	* examples/pathutils.c: fix a folder identification bug,
+	  courtesy of Dr Nicholas Jacobs.
+
+2008-03-12  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bad mailing list address. (Marcus) Bump to
+	  version 0.3.0.
+	* examples/hotplug.c: switch from using "info.bus" to
+	  using "info.subsystem" to identify USB events. (Marcus).
+	* src/libmtp.c: add parent_id to albums and playlists,
+	  based on a patch by Ali Shah.
+	* src/libmtp.h.in: dito.
+	* examples/playlists.c: consequental changes.
+	* examples/albums.c: consequental changes.
+	* This will be a new major revision of the API/ABI no
+	  matter what.
+
+2008-03-08  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: left debug prints on :-(
+	* configure.ac: set to 0.2.6.1
+	* Release as 0.2.6.1
+
+2008-03-02  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: prepare 0.2.6 release.
+	* src/Makefile.am: bump to compatible interface, 
+	* src/ptp.c: sync in upstream, a Sansa fix!
+	* src/ptp.h: sync in upstream.
+	* doc/Doxyfile.in: retire obsoleted parameters.
+	* Release this as 0.2.6!
+	
+2008-02-24  Richard Low <richard@wentnet.com>
+
+	* src/music-players.h: add DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL
+	  for a broken Philips player.
+
+2008-02-18  Linus Walleij <triad@df.lth.se>
+
+	* examples/pathutils.c: fix up item ID typing to uint32_t,
+	  handle file names passed in as arguments at suggestion from
+	  anonymous mail list user.
+	* examples/pathutils.h: move a function static.
+
+2008-02-12  Nicolas Pennequin <nicolas.pennequin@free.fr>
+
+	* examples/sendtr.c: add transferred tracks to albums if possible.
+
+2008-02-10  Scott Snyder <snyder@fnal.gov>
+
+	* src/libusb-glue.c: finally fix up the short header detection
+	  to skip over zero packets when encountered.
+	* examples/pathutils.c: fix a problem where all files sent has
+	  to include a "." (period).
+
+2008-02-06  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: wait for response > 0 instead of > 2.
+
+2008-01-28  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: LIBMTP_Get_Filemetadata() return metadata for
+	  folders (associations) too. There is really no reason why it
+	  shouldn't and it's good for use internally. 
+	  LIBMTP_Get_Filelisting_With_Callback() will still not return
+	  any associations however. We want to use the folder functions
+	  for that.
+
+2008-01-28  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: withdraw LIBMTP_Set_Object_Parent() function,
+	  no known devices will support this.
+	* src/libmtp.c: dito. Fix up some problems with the 
+	  LIBMTP_Set_Object_Filename() function.
+
+2008-01-27  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: fix up some minor things and documentation on
+	  the object handling functions.
+
+2008-01-27  Florent Mertens <flomertens@gmail.com>
+
+	* src/libmtp.h.in: new functions to rename object filenames
+	  and change object parents. Good when modifying the device
+	  as a file system, LIBMTP_Set_Object_Filename(),
+	  LIBMTP_Set_Object_Parent().
+	* src/libmtp.c: implementation.
+
+2008-01-27  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: re-read response from device until
+	  it atleast exceeds two bytes. This fixes a problem with
+	  the Samsung YP-U3 when populated with many, many songs.
+
+2008-01-21  Richard Low <richard@wentnet.com>
+
+	* src/music-players.h: add Thomson Lyrca HC308A, remove
+	  incorrect ID for Creative Zen 8GB
+
+2008-01-20  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: add LIBMTP_Get_Representative_Sample()
+	* src/libmtp.h.in: ditto
+
+2008-01-14  Linus Walleij <triad@df.lth.se>
+	
+	* src/libmtp.c: add LIBMTP_Get_Manufacturername(). Remember
+	  to bump soname (compatible) in 0.2.6 (or whatever we name it).
+	  0.3.0 perhaps?
+	* src/libmtp.h.in: dito.
+	* src/libmtp.c: detect default folders named "Datacasts" and
+	  "Texts".
+
+2008-01-11  Linus Walleij <triad@df.lth.se>
+
+	* examples/pathutils.c: recognize .bin files as firmware,
+	  used by e.g. RockBox developers. Doesn't cost anything to
+	  add.
+	
+2008-01-08  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump to 0.2.5.
+	* src/Makefile.am: interface to libmtp.so.7.0.2
+	  (compatible).
+	* Release as libmtp 0.2.5. Why not?
+
+2007-12-28  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: make libmtp use PTP_OPC_AlbumArtist on albums,
+	  instead of the (seldom present) PTP_OPC_Artist tag. Use both
+	  if both are supported. We're not setting AlbumArtist on regular
+	  tracks though, what's the point, and what does it mean if this
+	  differs from Artist??
+
+2007-11-30  Linus Walleij <triad@df.lth.se>
+
+	* src/music-players.h: new flag for the YP-T10.
+	* src/device-flags.h: define the new flag, that is needed
+	  to support Ogg files on these devices.
+	* src/libmtp.c: recognize and report Ogg support, set type
+	  to unknown when transferring.
+
+2007-11-22  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump to 0.2.4.
+	* src/Makefile.am: bump age of soversion (compatible).
+	* RELEASE 0.2.4 mainly to get some new device support out there.
+
+2007-11-09  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: avoid probing deeper into interfaces
+	  that have a string describing them as "MTP" after a
+	  suggested patch from Alexander Kanavin <ak@sensi.org>.
+	* examples/albumart.c: patch from Chris Waters <xtifr@debian.org>
+	  replacing calls to atoi() with calls to strtoul(). Since
+	  object ID:s are unsigned long, atoi() would reject too
+	  high object IDs. The patch also fix a few memory leaks.
+	  THANKS DEBIAN! We love our downstream!
+	* examples/newplaylist.c: dito.
+	* examples/pathutils.c: dito.
+	* examples/thumb.c: dito.
+
+2007-11-05  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: use OPFF codes instead of DPFF codes,
+	  we're dealing with objects, not device props.
+	* src/ptp.c: silence some OPFF freeing warnings.
+
+2007-11-02  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: try to repair header here instead of
+	  ignoring error in ptp.c.
+	* src/music-players.h: flag some more Creative devices as
+	  broken getting all files.
+	* src/Makefile.am: reference the 2 new .h files.
+
+2007-10-31  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: bring cache handling into this file.
+	* src/ptp.h: dito.
+	* src/libmtp.c: consequential changes.
+
+2007-10-30  Linus Walleij <triad@df.lth.se>
+
+	* src/music-players.h: split this off as a shared file
+	  between us and libgphoto2 so we get out of the syncing
+	  nightmare.
+	* src/device-flags.h: split out this as well, Marcus
+	  might want it.
+	* src/libusb-glue.c: consequential movement.
+	* src/libmtp.c: reference new flag file.
+	* src/ptp.c: sync in upstream.
+	* src/ptp.h: dito.
+
+2007-10-25  Linus Walleij <triad@df.lth.se>
+
+	* Release 0.2.3. Nice bunch of cleaned-up code, sad we had
+	  too bump soversion but such is life.
+
+2007-10-23  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: make LIBMTP_Send_File_From_File_Descriptor()
+	  survive the case where device->storage is NULL. This happens
+	  on the Nokia 3110c.
+
+2007-10-19  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: bring the cache handling code together at the
+	  end of the file, refactor so as to avoid code duplication,
+	  do things in one place only and looking good. Get folder
+	  list recursively instead, this works better with fast dir
+	  retrieveal I think.
+
+2007-10-18  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: fix the deletion of cached properties when
+	  removing objects. This code was seriously broken.
+
+2007-10-16  Jeff Mitchell <kde-dev@emailgoeshere.com>
+
+	* src/libusb-glue.c: remove the previously-concatenated vendor
+	  and product string "name" field as it's now redundant
+	* src/Makefile.am: interface to libmtp.so.7.0.0 (incompatible,
+	  device_entry_struct members changed)
+	* examples/hotplug.c: port to use vendor and product instead of
+	  name, also some useful commenting in the fdi file
+
+2007-10-15  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: repair headers, don't just ignore them.
+	  Add support for broken set object proplist devices. Motorola
+	  RAZR2 V8 has this problem.
+	* src/libusb-glue.h: flag for broken set object proplist.
+	* libmtp.c: avoid broken set object proplist.
+	
+2007-10-09  Jeff Mitchell <kde-dev@emailgoeshere.com>
+
+	* src/libusb-glue.c: add separate vendor and product strings
+	  in device entry structs
+	* src/libmtp.h.in: update device entry structs to reflect this
+
+2007-10-04  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: rm some pointless confusing defines
+	  inherited from libgphoto2.
+	* configure.ac: bump to 0.2.2
+	* src/Makefile.am: interface to libmtp.so.6.0.2 (compatible)
+	* Release as 0.2.2. Now is as good time as ever. Release
+	  early and release often.
+	
+2007-10-03  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: tag the OLD Creative devices with
+	  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL, after clear
+	  indications that it was broken when retrieveing folders
+	  on all those devices. The newer devices (those supporting
+	  32bit object size) presumably does not have this limitation.
+
+2007-10-02  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: devices which represented file size with a
+	  32bit value (some Creative devices) would return a bananas
+	  file size. Fixed it up by...
+	* src/libmtp.h.in: recycling the uint8_t "interface" 
+	  field in the device struct as a holder of the object size 
+	  for the device. This will make the new library binary 
+	  compatible with version 0.2.1 since no-one should *ever* 
+	  dereference that value (which used to be the USB interface 
+	  number and is now the object size).
+	* examples/files.c: display 64bit file sizes in hex correctly.
+
+2007-09-29  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: avoid crash on failed connect
+
+2007-09-28  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.h: introduce a new device flag for devices that
+	  have broken PTP headers, first encountered on the Creative
+	  ZEN 8GB.
+	* src/libusb-glue.c: attempt to begin to work around the broken
+	  PTP headers.
+
+2007-09-25  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.h: add a new device flag for devices that don't
+	  like it if you release the interface (or try to clear endpoints).
+	* src/libusb-glue.c: dito, implement this flag, tag all SanDisk
+	  Sansa devices with it except for the Linux-based Sansa Connect.
+
+2007-09-23  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: updated some device flags, removed second
+	  call to ptp_getdeviceinfo
+	* src/libmtp.c: property cache fixes
+
+2007-09-23  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: wrapped updating of playlists and albums into an
+	  abstract function so we do it consistently. Added support for
+	  tagging on modification date to files, tracks, playlists and
+	  albums.
+
+2007-09-21  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: flag the Samsung YH-820 with
+	  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL after tests by Stephan
+	  Fabel.
+	
+2007-09-18  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: stop the endpoint unhalting/unstalling when
+	  closing the USB device. It was AYBABTU the Samsungs 
+	  (and others).
+
+2007-09-17  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: silenced weirdo error message.
+
+2007-09-16  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: cancellation working *as it should*
+	* src/ptp.h: dito.
+	* src/libusb-glue.c: dito.
+	* src/libusb-glue.h: dito.
+	* src/libmtp.c: dito.
+	* src/libmtp.h.in: new error code for cancellation.
+
+2007-09-16  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: only read descriptors for devices we
+	  don't know since it breaks on some devices
+	* src/libmtp.c: a couple of bugs fixed in metadata retreival
+
+2007-09-15  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: get cancellation of xfers working.
+	* src/libusb-glue.c: dito.
+	* src/libusb-glue.h: dito.
+	* src/libmtp.c: dito.
+
+2007-09-14  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.h: sync in upstream to get cancellation prototypes.
+	* src/libusb-glue.c: first try to implement cancellation.
+	* src/libmtp.c: dito. Bugfix to one of Marcus' realloc():s.
+
+2007-09-12  Marcus Meissner <meissner@suse.de>
+
+	* src/ptp-pack.c: sync to upstream, rewrote packing to use
+	  a static array to be qsort():ed when reading in proplists.
+	* src/ptp.c: reflect changes.
+	* src/ptp.h: reflect changes.
+	* src/libmtp.c: reflect changes.
+	
+2007-09-06  Linus Walleij <triad@df.lth.se>
+
+	* examples/hotplug.c: edit up into a udev ruleset that is
+	  inexorably complicated but probably compatible with most
+	  udev versions out there. Now please DON'T update udev
+	  styles again!
+
+2007-09-05  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: album fixups
+
+2007-09-05  Linus Walleij <triad@df.lth.se>
+
+	* examples/hotplug.c: use old udev style by default, use new
+	  if requested explicitly by a -U switch.
+
+2007-09-04  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: make sure we query recursively supplying each
+	  storage ID in turn, so we spin over storages. Also check
+	  what storage may be available to store a file, if the first
+	  one fails, try the next!
+
+2007-09-01  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp-pack.c: make the resulting MTP proplist sorted by
+	  object ID.
+	* hotplug.sh.in: explicitly call BASH instead of just sh. Warn
+	  if script is not run as root.
+	
+2007-08-29  Linus Walleij <triad@df.lth.se>
+
+	* examples/Makefile.am: move include define from AM_CFLAGS to
+	  AM_CPPFLAGS (as it should be) bug found by Petar Petrov 
+	  <pesho.petrov@gmail.com>.
+	* src/libusb-glue.c: strange misleading message corrected. Fix
+	  up the horrid interface passing back-and-forward and confusing.
+	* src/libusb-glue.h: dito.
+	* src/libmtp.c: rid interface references, that's a USB issue!
+	* src/libmtp.h.in: flag interface number in device struct as retired.
+
+2007-08-28  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: retire the horrid, broken, stream send facility that
+	  does not work on any device since they all want to know the file
+	  size in advance. Add in some code to fall back on the recursive
+	  metadata retrieveal if getting the whole long list fails.
+	* src/libusb-glue.c: tag all Sansas as having broken GetObjectPropList
+	  when all tags for all objects are requested. Scan each INTERFACE 
+	  of the device for device descriptors.
+
+2007-08-24  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.h: new device flag to strip all non-7bit chars from
+	  filenames on some lame devices.
+	* src/libusb-glue.c: tag the Philips Shoqbox with this flag.
+	* src/libmtp.c: strip the non-7bit chars from filenames if that
+	  flag is set.
+	* src/unicode.h: introduce a 7bit-strip helper function.
+	* src/unicode.c: dito.
+
+2007-08-22  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: deal with setting of metadata sets for u16/u32:s that
+	  are ranges or enums, rounding and twiddling if need be. This is
+	  needed because some new devices (like the TrekStor Sweez,
+	  has duration defined as a range: MIN 0, MAX 65535000, STEP 1
+	  and Sandisk Sansa c240 has duration as range: MIN 0, MAX 2147483000, 
+	  STEP 1000) whereas old devices would just accept any value.
+
+2007-08-16  Richard Low <richard@wentnet.com>
+
+	* src/ptp-pack.c: allow packing of NULL strings
+
+2007-08-15  Robert Reardon <rreardon@monkshatch.vispa.com>
+
+	* src/libmtp.c: return device max values for representative
+	  samples.
+
+2007-08-15  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: added Philips Shoqbox
+
+2007-08-13  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: sync to upstream.
+
+2007-08-07  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump to 0.2.1.
+	* src/Makefile.am: interface to libmtp.so.6.0.1.
+	* Release libmtp 0.2.1!
+
+2007-08-06  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: tag on the large file support compilation flag.
+	* src/libmtp.c: smack up the data file transfer function so it
+	  works again and *finally* should support 64bit sizes!
+	  Then wrapped the track sending function around the file
+	  sending function so there is no more pointless code duplication
+	  giving rise to ever more bugs. Enable LFS, Large File Support so
+	  we can handle 64bit files properly.
+	* examples/sendtr.c: shape up print-outs, LFS support.
+	* examples/sendfile.c: dito.
+
+2007-08-06  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: fixed a stray error print bug.
+	* src/libmtp.c: overhaul of all proplist setting to follow the same
+	  design pattern. Probably fixed a few opd memory leaks along the road.
+
+2007-08-05  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: send 64 bit filesize
+
+2007-08-04  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: fix up the 64bit filesize and tracksize support.
+	  There were some bugs...
+	* src/Makefile.am: tweak interface revision so that we produce
+	  libmtp.so.6 now.
+	* configure.ac: bump library revision to 0.2.0.
+	* examples/hotplug.c: switch to use ATTR{} instead of SYSFS{}
+	* Release libmtp 0.2.0!
+
+2007-08-04  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: add Sansa m240 (a different ID to before)
+	  Give the Toshiba Gigabeat S
+	  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL.
+
+2007-08-03  Marcus Meissner <meissner@suse.de>
+
+	* m4/byteorder.m4: byteorder fixes.
+
+2007-07-30  Richard Low <richard@wentnet.com>
+
+	* src/ptp-pack.c: fix up array packing
+
+2007-07-30  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp-pack.c: try to get a uniform 64 bit
+	  support, use some old macro code.
+
+2007-07-29  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: 64 bit filesize support for tracks
+	* src/ptp-pack.c: ditto
+	* src/ptp.h: ditto
+
+2007-07-27  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: Some better NULL checks
+
+2007-07-27  Linus Walleij <triad@df.lth.se>
+
+	* examples/hotplug.c: changed subsystem from "usb_device"
+	  to "usb". Presumably a change in the kernel some time ago.
+
+2007-07-21  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: Correctly bail out of LIBMTP_Get_Storage
+
+2007-07-17  Linus Walleij <triad@df.lth.se>
+
+	* examples/reset.c: Add a device reset program.
+	* src/libmtp.c: Add reset command.
+	* src/ptp.c: dito, and sync in upstream changes.
+	* src/ptp.h: dito, and sync in upstream changes.
+	* src/ptp-pack.c: sync in upstream changes.
+
+2007-07-17  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: Added some more (paranoid) NULL checks
+
+2007-07-14  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: Add a NULL check
+
+2007-07-13  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: add Disney MixMax
+
+2007-07-11  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: put in Tero's name in the preamble.
+	* src/libusb-glue.c: make the dump function sump out the zuper zecret
+	  devize dezcriptorz in clear text hex.
+
+2007-07-10  Linus Walleij <triad@df.lth.se>
+
+	* examples/hotplug.c: force HAL OGG support on iriver devices. 
+	  They all have it! Also force for two other devices that does 
+	  this.
+
+2007-07-07  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.h: new flag for the case when getting the object
+	  property list of all metadata for all objects is broken.
+	* src/libusb-glue.c: tentatively tag a Philips device with this flag.
+	* src/libmtp.c: fixed usage of returned pointers from realloc(),
+	  introduce new flag.
+
+2007-07-05  Tero Saarni <tero.saarni@gmail.com>
+
+	* src/libmtp.c: update cache when manipulating objects instead of
+	  always flushing the whole cache.
+
+2007-07-03  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: use the params->proplist metadata cache. Help
+	  rid all flush_handles() you can in order to add even more to
+	  the efficiency of the cache.
+
+2007-07-01  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: sync to upstream gPhoto source.
+	* src/ptp.h: dito.
+	* src/ptp-pack.c: dito.
+	* src/libmtp.c: use the params->objectinfo object info cache to
+	  speed things up considerably. This is exactly what libgphoto2
+	  does so now we move closer to upstream. I believe this also
+	  fixes quite a few memory leaks because we weren't freeing the
+	  strings inside the objectinfo previously.
+
+2007-05-29  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: use the set object prop list command to set album
+	  props if available. Follow metadata set design pattern used for
+	  tracks; check first if the object type can set name/artist/genre.
+
+2007-05-24  Jeff Mitchell <kde-dev@emailgoeshere.com>
+
+	* hotplug.sh.in: Properly install the HAL FDI rules if
+	  the user so chooses to when prompted.
+
+2007-05-24  Jeff Mitchell <kde-dev@emailgoeshere.com>
+
+	* examples/hotplug.c: Fix/update HAL output to conform
+	  to new specs. Fix whitespacing to be consistent.
+
+2007-05-17  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: added Samsung YH-920
+
+2007-05-11  Linus Walleij <triad@df.lth.se>
+
+	* examples/hotplug.c: output a usb.ids map if need be.
+	* sync-usbids.sh: script to assist in comparing our device
+	  database to the linux-usb database so we can submit new
+	  entries to it more easily. Please extend this until it
+	  creates automated diff:s if you can!
+
+2007-05-10  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: some new devices, some rewording etc.
+
+2007-05-05  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.h: removed the DUALMODE flag, it's pointless and
+	  equal to the problem solved by the UNLOAD_DRIVER flag.
+	* src/libusb-glue.c: dito, move the only DUALMODE flag into an
+	  UNLOAD_DRIVER flag. Added Archos Gmini.
+
+2007-05-05  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: added Philips PSA610
+	* src/libmtp.c: code to recursively get object handles for each
+	  assoc.
+	* src/ptp.h: ditto
+
+2007-04-28  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: new device
+
+2007-04-26  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: memory leak: dangling, unused pointer killed.
+
+2007-04-23  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: extend LIBMTP_album_t to include fields for
+	  artist and genre. This is sort of required so we must change
+	  the API to have it working properly.
+	* src/libmtp.c: dito. Reflect changes in implementation.
+
+2007-04-18  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: sync to upstream gPhoto source.
+	* src/ptp.h: dito.
+	
+2007-04-17  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: new device
+
+2007-04-13  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: new devices
+
+2007-04-12  Linus Walleij <triad@df.lth.se>
+
+	* examples/hotplug.c: fix GOTO style in udev map.
+
+2007-04-02  Linus Walleij <triad@df.lth.se>
+
+	* examples/files.c: some WIN32 64bit prefix fixup.
+	* examples/tracks.c: dito.
+	
+2007-03-28  Ted Bullock <tbullock@canada.com>
+
+	* examples/*.c: Print library version number on execution of examples.
+	* src/libmtp.h.in: New version number string to aid version echoing.
+
+2007-03-26  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump version to 0.1.5, release 0.1.5!
+	* src/Makefile.am: bump lib interface revision to libmtp.so.5.2.1,
+	  backwards compatible to libmtp.so.5.
+
+2007-03-24  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: fixed bug in zero read code
+
+2007-03-23  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: refactored MTP property list handling code to make
+	  things simple. Removed the flag for MTP enhanced: there are devices
+	  that will not work without MTP enhanced (for example the Samsung 
+	  YP-K5 will only support setting object property lists, not 
+	  individual object properties, leaving out parts of the MTP basic 
+	  subset), thus we are allowed to reverse-engineer and implement this 
+	  for interoperability. I also made the output from 
+	  LIBMTP_Dump_Device_Info() considerably more verbose, plotting out 
+	  the ranges and possible enumerated values of all object properties.
+	  For example you can see that the secret values associated with 
+	  Audible.com property 0xda01 is an enumerated value that can be 
+	  2, 3 or 4 (etc).
+
+2007-03-22  Richard Low <richard@wentnet.com>
+
+	* src/ptp.c: PTP_OC_MTP_SetObjPropList implementation
+	* src/ptp.h: ditto
+	* src/libmtp.c: Use PTP_OC_MTP_SetObjPropList when updating track
+	  metadata.
+
+2007-03-18  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: new devices. Some of the Samsung players may
+	  need DEVICE_FLAG_NO_ZERO_READS to be set - I only know the YP-K5
+	  needs it.
+
+2007-03-16  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.h: introducing yet another device flag for the
+	  irivers bugged firmwares, this is for the Alzheimer disease that
+	  cause irivers to forget that OGG files are OGG files.
+	* src/libmtp.c: dito.
+	* src/libusb-glue.c: introduce this flag for all iriver devices.
+	* examples/pathutils.c: found a (small) bug.
+
+2007-03-12  Linus Walleij <triad@df.lth.se>
+
+	* Makefile.am: cleanup patch from Rafael Laboissiere.
+	* src/libusb-glue.c: refactored device detection code to 
+	  immediately test if the device is in the known devices list if it 
+	  does not feature a MTP device descriptor. This fixes the problem 
+	  of not being able to mix devices with proper descriptors and 
+	  non-detected devices.
+
+2007-03-07  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: remove libgphoto2 functions that we
+	  don't use.
+	* src/libusb-glue.h: export the free_mtpdevice_list() function,
+	  new signature of find_usb_devices().	
+	* src/libmtp.c: shrink code, pass as list of devices instead of
+	  several huge arrays between libmtp.c and USB glue layer in
+	  libusb-glue.c using the nifty list struct defined in libusb-glue.h.
+	* Eventually release libmtp 0.1.4.
+
+2007-03-06  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: rewrote one more function to be 
+	  non-recursive, perhaps I found the remaining bug, just
+	  cannot see that right now, will test tomorrow.
+	
+2007-03-05  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: rewrite recursive function to linear.
+	* src/libusb-glue.h: create a wrapper type for the
+	  device list instead of abusing the libusb device "next"
+	  field in our code.
+	* src/libusb-glue.c: rewrite all recursive functions to
+	  linear, use wrapper objects, don't copy the libusb device
+	  struct, instead just store a pointer to it. This magically
+	  solved a bug...
+	
+2007-03-04  Linus Walleij <triad@df.lth.se>
+
+	* src/Makefile.am: bump library interface to libmtp.so.5.2.0
+	  backwards compatible with any libmtp.so.5 interface, for
+	  imminent libmtp 0.1.4 release.
+	
+2007-03-03  Ted Bullock  <tbullock@canada.com>
+
+	* src/libusb-glue.c: Don't echo warnings about reading a single
+	  extra byte on devices in which DEVICE_FLAG_NO_ZERO_READS has
+	  been set
+	* src/libmtp.c: New API function to retrieve the number of devices
+	  in a list of connected devices
+	* src/libmtp.h: New API function to retrieve the number of devices
+	  in a list of connected devices
+	* examples/detect.c: Use new API function to count number of devices
+	  that were detected
+
+2007-03-03  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.h: Tiresome ramblings to explain exactly what
+	  the (now renamed) device flag DEVICE_FLAG_NO_ZERO_READS really 
+	  means.
+	* src/libusb-glue.c: Renamed flag. Indent code :-) Reading the code
+	  and being impressed by our ability to iron out the root cause
+	  of this kinda weird thing... Fix a few compile warnings.
+
+2007-03-03  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: (hopefully) fixed iRiver read errors. Enabled
+	  get object prop lists for Clix since it appears to work.
+	* src/libusb-glue.h: ditto
+	* src/ptp.h: ditto
+
+2007-02-28  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.h: Upstream accepted our patch so synced it in.
+	
+2007-02-27  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: Synced in upstream version which removes the 
+	  offending line.
+	* src/libmtp.c: replaces strcmp() for strcasecmp() in folder
+	  detection since Windows and some devices (such as iRivers)
+	  ignore case and user capital letters for default folders.
+	
+2007-02-22  Ted Bullock  <tbullock@canada.com>
+
+	* src/ptp.c: Comment out line in ptp_exit_fd_handler that was 
+	  closing a file descriptor.  This is not the responsibility of 
+	  the PTP Layer. Defect and solution found by Rob Reardon
+
+2007-02-26  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: Implement a check for PTP_OC_MTP_SetObjectPropValue 
+	  in the LIBMTP_Update_Track_Metadata() function, there are 
+	  obviously devices that do not support this, but only 
+	  PTP_OC_MTP_SetObjPropList instead (such as the Samsung YH 925-GS), 
+	  but we haven't implemented that yet. Problems are 
+	  atleast reported correctly now.
+
+2007-02-24  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: Fix incorrect transfer sizes causing zero
+	  write issues
+
+2007-02-23  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: Undeprecate getting first device code.
+	
+2007-02-23  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: Fix crash when no devices connected
+
+2007-02-23  Ted Bullock  <tbullock@canada.com>
+
+	* examples/detect.c: Stub out probe functionality
+	* src/libusb-glue.c: Remove old uni-device cruft code
+	* src/libusb-glue.h: Remove old uni-device cruft code
+	* Replace LIBMTP_ERROR_N0_DEVICE_ATTACHED with
+		LIBMTP_ERROR_NO_DEVICE_ATTACHED across entire project
+	
+2007-02-22  Ted Bullock  <tbullock@canada.com>
+
+	* examples/albums.c: Updated to use new multi device code
+	* examples/tracks.c: Updated to use new multi device code
+	* examples/files.c: Updated to use new multi device code
+
+2007-02-18  Ted Bullock  <tbullock@canada.com>
+
+	* src/libmtp.c: Altered the function LIBMTP_Get_First_Device
+	  to wrap around the multi device API. Also added deprecation
+	  warnings to avoid using this function
+
+2007-02-17  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: Debug output fixes and read/write sizes changed
+	* src/libmtp.c: memset params to 0 to avoid freeing unalloced
+	  memory
+	* src/ptp.h: read/write sizes changed
+
+2007-02-15  Robert Reardon <rreardon@monkshatch.vispa.com>
+
+	* src/libmtp.c: Fix a segfault in new error handling code.
+
+2007-02-15  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: Adding some sanity checks to error stack code.
+	* examples/newplaylist.c: LGPL boilerplate, crediting Robert.
+	* examples/playlists.c: LGPL boilerplate.
+	* examples/sendfile.c: LGPL boilerplate, crediting me and Chris.
+	* examples/sendtr.c: LGPL boilerplate, crediting me, Chris,
+	  Shaun, Enrique.
+	* examples/thumb.c: LGPL boilerplate, crediting Robert.
+	* examples/tracks.c: LGPL boilerplate.
+	* examples/trexist.c: LGPL boilerplate, crediting noone.
+
+2007-02-15  Ted Bullock  <tbullock@canada.com>
+
+	* examples/folders.c: Updated to use new multi device code
+	* src/libmtp.c: Fixed potential memory leaks
+	* src/libusb-glue.c: Fixed potential memory leaks and fixed device 
+	  release segfault for multiple devices
+
+2007-02-14  Ted Bullock  <tbullock@canada.com>
+
+	* src/libusb-glue.c: Wrote three new recursive functions to avoid 
+	  extreme levels of multiple indirection and to clean the code up 
+	  a bit for multiple devices.
+	* examples/detect.c: Adjusted function calls to use new multiple 
+	  device code.
+	* src/libmtp.h.in: Added prototype for LIBMTP_Release_Device_List
+
+2007-02-12  Ted Bullock  <tbullock@canada.com>
+
+	* src/libmtp.c: Two new functions (create_usb_mtp_devices and 
+	  LIBMTP_Get_Connected_Devices) to add support for multiple devices
+	  to client applications
+	* src/libmtp.h: Added LIBMTP_Get_Connected_Devices as a publicly
+	  accessible function
+	*libusb-glue.c: Renamed connect_mtp_devices to find_usb_devices
+	*libusb-glue.h: Renamed connect_mtp_devices to find_usb_devices
+
+2007-02-09  Ted Bullock  <tbullock@canada.com>
+
+	* src/libusb-glue.c: Addressed a number of potential memory leaks in
+	  the new multiple device code
+
+2007-02-05  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: LGPL boilerplate.
+	* src/libusb-glue.h: LGPL boilerplate.
+	* src/unicode.h: LGPL boilerplate.
+	* src/util.h: LGPL boilerplate.
+	* examples/albumart.c: LGPL boilerplate, crediting Andy.
+	* examples/pathutils.h: LGPL boilerplate, crediting Chris.
+	* examples/pathutils.c: LGPL boilerplate, crediting me and Chris.
+	* examples/common.h: LGPL boilerplate.
+	* examples/albums.c: LGPL boilerplate, crediting Chris.
+	* examples/connect.c: LGPL boilerplate, crediting Chris.
+	* examples/delfile.c: LGPL boilerplate, crediting me and Chris.
+	* examples/detect.c: LGPL boilerplate.
+	* examples/emptyfolders.c: LGPL boilerplate, crediting Andy.
+	* examples/files.c: LGPL boilerplate.
+	* examples/folders.c: LGPL boilerplate.
+	* examples/format.c: LGPL boilerplate.
+	* examples/getfile.c: LGPL boilerplate, crediting me and Chris.
+	* examples/getplaylist.c: LGPL boilerplate.
+	* examples/hotplug.c: LGPL boilerplate, crediting me and Marcus.
+	* examples/newfolder.c: LGPL boilerplate, crediting me and Chris.
+
+2007-02-02  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: sync upstream.
+	* src/ptp.h: dito.
+	* src/ptp-pack.c: dito.
+	* src/libmtp.c: make changes necessary to handle
+	  the new iconv(3) code in ptp-pack.c. People will have to
+	  use recent stdlibc, glibc or libiconv. Also call new memory
+	  clean-up functions. Fix LGPL boilerplate text.
+	* src/unicode.c: Fix LGPL boilerplate text.
+	* src/utils.c: Fix LGPL boilerplate text.
+	* src/libusb-glue.c: Fix LGPL boilerplate text.
+
+2007-01-24  Ted Bullock <tbullock@canada.com>
+
+	* src/libusb-glue.c: new function to retrieve multiple device
+	  instances.
+	* src/libusb-glue.h: dito.
+	* src/libmtp.h.in: new error codes.
+
+2007-01-22  Linus Walleij <triad@df.lth.se>
+
+	* examples/albumart.c: use the new errostack.
+	* examples/delfile.c: dito.
+	* examples/detect.c: dito.
+	* examples/emptyfolders.c: dito.
+	* examples/format.c: dito.
+	* examples/getfile.c: dito.
+	* examples/getplaylist.c: dito.
+	* examples/newfolder.c: dito.
+	* examples/newplaylist.c: dito.
+	* examples/playlists.c: dito.
+	* examples/sendfile.c: dito.
+	* examples/sendtr.c: dito.
+	* examples/thumb.c: dito.
+	* src/libmtp.c: add some errors to the stack so we can
+	  see how it's to be used. (Just a first try...)
+	* src/libusb-glue.c: move the LIBMTP_Get_Supported_Devices()
+	  function into this file cause it only return USB devices
+	  anyway and could be renamed LIBMTP_Get_Supported_USB_Devices()
+	  (but let's not do that renaming since it would break the API).
+	  For now let's understand this is a USB-only function by
+	  simply putting it in the libusb-glue.c file.
+	
+2007-01-22  Ted Bullock <tbullock@canada.com>
+
+	* src/libusb-glue.c: first hack at creating an interface
+	  to retrieve multiple devices.
+	* src/libmtp.h.in: new error codes related to multiple devices.
+
+2007-01-21  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: more new devices
+
+2007-01-20  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: error stack handling like in libnjb.
+	  just bare bones implementation as of now but the idea
+	  should be clearly visible. TODO: add a plethora of
+	  errors and adjust examples to make use of the error
+	  stack.
+	* src/libmtp.c: dito.
+	
+2007-01-20  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: new device 'Philips PSA235'
+
+2007-01-16  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump and release 0.1.3.
+	* src/Makefile.am: bump interface REVISION. Nothing changed
+	  externally really.
+
+2007-01-11  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.sym: updated symbol table for mingw32 but does
+	  anyone use this? Also I believe one could auto-generate
+	  this some way, just haven't figured out how... Perhaps with
+	  a funky script that massage libmtp.h if nothing else.
+
+2007-01-11  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: a zero read fix
+	* src/libmtp.c: fix spelling mistake
+
+2007-01-09  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: repair callbacks, structure the code just
+	  a little bit.
+	* src/libmtp.c: don't assign values to writes or reads, use the
+	  PTP transport intrinsics instead.
+	
+2007-01-07  Orson Teodoro <orsonteodoro@yahoo.com>
+
+	* src/ptp.h: Encoding profile.
+	* src/ptp.c: Dito.
+
+2006-01-07  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: (re)introduce de-halting of endpoints
+	  as this is needed by VMWare emulation. Must check whether
+	  this causes problems for other archs! Problem was reported
+	  by Orson Teodoro under i686 Gentoo, with a suggested patch.
+
+2006-01-07  Marcus Meissner <meissner@suse.de>
+
+	* src/ptp.c: sync to upstream libgphoto2.
+	* src/ptp.h: dito.
+	* src/ptp-pack.c: dito.
+	* libusb-glue.c: fixes to move low-level functions
+	  out of ptp.c and into this libmtp-specific portion.
+	  libgphoto2 has been similarly altered to use a usb.c
+	  file for the low-level stuff. (This was a long needed
+	  split anyway.)
+
+2007-01-03  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: fix zero write bug
+	* src/ptp.c: ditto
+
+2007-01-02  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: fix up comments, remove things 
+	  refering to stuff we don't have.
+
+2007-01-02  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: another try at split headers/packet sizes
+	* src/ptp.c: ditto
+	* src/libusb-glue.c: ditto
+
+2007-01-01  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: move default setting of split headers
+	  off to ptp.c open session.
+	* src/ptp.c: dito.
+
+2007-01-01  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: split headers/packet size fix
+	* src/ptp.c: ditto
+	* src/ptp.h: ditto
+	* src/libusb-glue.c: ditto
+
+2007-01-01  Orson Teodoro <orsonteodoro@yahoo.com>
+
+	* src/ptp.h: changed some WMDRMND def codes to AAVT def codes. 
+	  addition of AAVT error codes.
+	* src/ptp.c: changes to reflect modifications done in ptp.h
+
+2006-12-31  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump to 0.1.2.
+	* src/Makefile.am: bump interface revision. (Compatible.)
+	* RELEASE 0.1.2.
+
+2006-12-30  Linus Walleij <triad@df.lth.se>
+
+	* examples/pathutils.c: reflect new filetypes.
+	* examples/sendtr.c: dito.
+
+2006-12-30  Orson Teodoro <orsonteodoro@yahoo.com>
+
+	* src/ptp.h: added WMDRMPD, WMDRMND, WMPPD, WPDWCN extension
+	  codes. added more format object codes flac, m4a, 3gp, aac,
+          xml, xls, ppt, etc.  0x9101-0x910B identfiers are infixed
+	  with WMDRMPD. Added more object properties codes (0xDCD3-0xDD72).
+	  Added more device property codes.
+	  Changed PTP_OFC_MTP_WindowsImageFormat to 0xb881 reflect spec.
+        * src/ptp.c: added changes to reflect new extensions, object
+	  codes, device property codes.
+	* src/libmtp.c: modified mp4 to reflect it is a container format
+	  not a codec.  Added more descriptions in init_filemap(). mp4
+          container format is ambiguous in
+	  LIBMTP_Send_File_From_File_Descriptor(). Audio? video? both?.
+	  mp4 searched in video by default.  Added comments about this.
+          Added support for the new format object types.
+	* src/libmtp.h.in: added constants to reflect changes to
+          init_filemap().
+
+2006-12-30  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: fixed bug in debug printing
+
+2006-12-29  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: Made abstract list creation to be more
+	  WMP like
+	* src/libusb-glue.c: added Philips GoGear SA9200
+	* src/ptp-pack.c: fixed packing bug in ptp_pack_OI
+
+2006-12-29  Marcus Meissner <meissner@suse.de>
+
+	* src/ptp.h: API changes for libgphoto2 to use the file
+	  retrieveal functions.
+	* src/ptp.c: dito.
+	* src/libusb-glue.c: changes in libmtp reflecting the new
+	  API for libgphoto2.
+
+2006-12-28  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: making older autotools happy. Bump to 0.1.1.
+	* src/Makefile.am: bump interface for release, also autotools.
+	* RELEASE libmtp 0.1.1.
+
+2006-12-19  Matthew Wilcox <matthew@wil.cx>
+
+	* src/ptp.c: fix a (serious) short file bug.
+
+2006-12-17  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: don't bail out on failures when setting
+	  metadata.
+
+2006-12-16  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: sync to upstream.
+	* src/ptp.h: dito.
+	* src/ptp-pack.c: dito.
+	
+2006-12-15  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: make the format function take a storage as
+	  parameter. Add comments to device storage.
+	* src/libmtp.c: dito, fix up some code and docs.
+	* examples/format.c: make the format command comply with
+	  the new API.
+
+2006-12-14  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: make get_first_storage_freespace() always query
+	  the first storage when the space is requested. And some other
+	  janitorial stuff.
+	
+2006-12-13  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: one more device.
+	* examples/detect.c: compilation warnings fixed.
+
+2006-12-13  Robert Reardon <rreardon@monkshatch.vispa.com>
+
+	* src/ptp.c: add 0xD901 flag as BuyNow property of objects.
+	* src/ptp.h: ditto.
+
+2006-12-12  Daniel Williams <danielw@iinet.net.au>
+
+	* src/libmtp.h.in: revamped storage API.
+	* src/libmtp.c: dito.
+	* examples/detect.c: dito.
+
+2006-12-12  Robert Reardon <rreardon@monkshatch.vispa.com>
+
+	* src/libmtp.c: Send_Representative_Sample() updated to
+	  set image height and width, or audio duration and size.
+
+2006-12-07  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: support firmware object type. (Dangerous.)
+	* src/libmtp.c: dito.
+
+2006-12-07  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: default text folder detection (used in Samsung
+	  Yepp T9) also add a few "My Foo" folder strings, remove the
+	  "remaining directories" kludge.
+	* src/libmtp.h.in: default text folder.
+
+2006-12-06  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: extend the respresentative sample API a bit.
+	* src/libmtp.c: dito.
+	* examples/albumart.c: free memory after use.
+	* examples/thumb.c: dito.
+	* RELEASE this as libmtp 0.1.0!
+
+2006-12-04  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: enable split headers on sending object lists again.
+
+2006-12-04  Robert Reardon <rreardon@monkshatch.vispa.com>
+
+	* src/libmtp.c: abstract Send_Representative_Sample() so
+	  it can send samples for any format that supports it
+	* src/libmtp.h.in: same as above
+	* examples/albumart.c: altered to use new abstract function above
+	* example/thumb.c: sample program to upload thumbnails
+	* example/Makefile.am: add sample thumbnail program
+
+2006-12-03  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: check space on disk before sending
+	  tracks or files.
+	* src/libmtp.h.in: refactor LIBMTP_Send_Album_Art()
+	  into LIBMTP_Send_Representative_Sample().
+	* src/libmtp.c: dito.
+	* examples/albumart.c: dito.
+
+2006-12-02  Marcus Meissner <meissner@suse.de>
+
+	* examples/Makefile.am: make sure symlinks really end
+	  up in the correct dir.
+
+2006-11-30  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.c: make Matthews patch thread-safe and fix it
+	  so it will handle more than one surplus packet.
+	* src/ptp.h: dito.
+
+2006-11-30  Richard Low <richard@wentent.com>
+
+	* src/libmtp.c: memset PTPObjectInfo structs to 0
+
+2006-11-30  Matthew Wilcox <matthew@wil.cx>
+
+	* src/ptp.c: on some devices, surplus packet data is 
+	  sometimes returned during read, i.e. a header of the
+	  next package is typically attacked to the incoming 
+	  data, as if someone was sending several packets at 
+	  once. If this happens we buffer the surplus packet.
+	* src/libusb-glue.c: revert my own mistakes by making
+	  them Windows-only.
+
+2006-11-30  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: this *is* gonna be libmtp 0.1.0!
+	* src/Makefile.am: age interface to 4-0-0 to indicate that
+	  intefaces have been removed.
+	* src/libmtp.h.in: removed external object interface.
+	* src/libmtp.c: dito. Made all object manipulation functions
+	  static.
+	
+2006-11-29  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: added new devices
+
+2006-11-29  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: remove some pointless #include <>
+	  clutter, call usb_set_configuration() as needed by
+	  Windows.
+	* src/libmtp.c: various fixups to enable use of Windows
+	  <io.h> include file.
+	* README.windows.txt: added a quick porting guide for 
+	  MSVC by Farooq Zaman.
+
+2006-11-28  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: removed filetype mapping API. We can handle
+	  everything inside of libmtp now so no need for this.
+	* src/libmtp.c: dito.
+
+2006-11-27  Linus Walleij <triad@df.lth.se>
+
+	* examples/files.c: unsigned int sized printout.
+	* examples/tracks.c: sort of the same.
+	* Makefile.am: HAL style map output by default.
+
+2006-11-26  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: object handles for proplists
+	* src/ptp-pack.c: ditto
+	* src/ptp.c: ditto
+	* src/ptp.h: ditto
+
+2006-11-25  Marcus Meissner <marcus@jet.franken.de>
+
+	* examples/hotplug.c: adding HAL style XML output for 
+	  the devices.
+	* examples/Makefile.am: fixing a bug in the automake 
+	  file (pathutils.h missing!)
+	* Makefile.am: fix the problem with re-making sources
+	  (you had to run ./autogen.sh before!)
+
+2006-11-23  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.h: add a new bug flag for devices that
+	  have broken PTP_OC_MTP_GetObjPropList implementations.
+	* src/libusb-glue.c: state that all iRivers have this problem.
+	* src/libmtp.c: disable the user of ptp_mtp_getobjectproplist()
+	  for these devices.
+
+2006-11-21  Robert Reardon <rreardon@monkshatch.vispa.com>
+
+	* src/libmtp.c: set handle ids for new objects to 0 when
+	  creating new albums and playlists.
+
+2006-11-21  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: enabled enhanced mode for metadata retrieval
+	  by default.
+	* src/libmtp.c: fixed the problem with sending files using
+	  enhanced commands.
+
+2006-11-20  Linus Walleij <triad@df.lth.se>
+
+	* src/ptp.h: sync to upstream libgphoto2
+	* src/ptp.c: dito.
+	* src/ptp-pack.c: dito.
+	* src/libmtp.c: check for zerolength files/tracks.
+
+2006-11-20  Andy Kelk <andy@mopoke.co.uk>
+
+	* src/libmtp.h.in: add "parent_id" property to LIBMTP_track_struct. 
+	* src/libmtp.c: get "parent_id" property when reading tracks.
+	* examples/emptyfolders.c: new example program for pruning empty
+	  folders. (does a dummy run by default).
+
+2006-11-19  Robert Reardon <rreardon@monkshatch.vispa.com>
+
+	* src/libmtp.c: use enhanced MTP commands to create playlists and
+	  send files
+	* examples/newplaylist.c: demo program for creating new playlists
+	* examples/Makefile.am: add demo newplaylists program
+
+2006-11-19  Daniel Williams <danielw@iinet.net.au>
+
+	* src/libusb-glue.c: fix error on reconnect.
+	
+2006-11-18  Richard Low <richard@wentnet.com>
+
+	* src/ptp.c: tidy up ptp_usb_getdata
+
+2006-11-17  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: fixed parent handle for uploaded tracks
+
+2006-11-17  Robert Reardon <rreardon@monkshatch.vispa.com>
+
+	* src/libmtp.c: fixed up album art using enhanced commands.
+
+2006-11-16  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: a crude implementation of ptp_mtp_getobjectproplist
+	* src/ptp.c: ditto
+	* src/ptp.h: ditto
+	* src/ptp-pack.c: ditto
+
+2006-11-16  Robert Reardon <rreardon@monkshatch.vispa.com>
+
+	* src/libmtp.c: use enhanced MTP commands to create albums and
+	  add detection of the default album folder.
+	* src/libmtp.h.in: add a holder for album default folder.
+	
+2006-11-15  Richard Low <richard@wentnet.com>
+
+	* src/ptp-pack.c: set string buffer to correct size.
+
+2006-11-14  Richard Low <richard@wentnet.com>
+	
+	* examples/tracks.c: really use undeprecated API entry.
+
+2006-11-13  Richard Low <richard@wentnet.com>, Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: add LIBMTP_Get_Tracklisting_With_Callback()
+	  and LIBMTP_Get_Filelisting_With_Callback()
+	* src/libmtp.c: dito, deprecate LIBMTP_Get_Tracklisting()
+	  and LIBMTP_Get_Filelisting()
+	* examples/tracks.c: use undeprecated API entry.
+	* examples/connect.c: ditto.
+	* examples/detect.c: ditto.
+	* examples/files.c: ditto.	
+	* src/ptp.c: working on getting object prop lists.
+	* src/ptp.h: dito.
+
+2006-11-12  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: added Zen Vision W to devices
+
+2006-11-07  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: added checks for supported properties
+
+2006-11-06  Richard Low <richard@wentnet.com>
+
+	* src/libmtp.c: added a check for NULL filenames in
+	  LIBMTP_Get_Folder_List.
+
+2006-11-01  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: set/get uint8 to/from objects
+	* src/libmtp.c: send object property list.
+	* src/ptp.c: dito.
+	* src/ptp.h: dito.
+	* src/ptp-pack.c: dito.
+
+2006-10-29  Andy Kelk <andy@mopoke.co.uk>
+
+	* examples/albumart.c: simple tool for adding album art.
+	* src/libmtp.c: graceful handling of players not supporting 
+	  abstract album objects.
+
+2006-10-27  Linus Walleij <triad@df.lth.se>
+
+	* src/Makefile.am: bump library interface to reflect the new
+	  album methods.
+	* configure.ac: bump to 0.0.22 for the next release.
+
+2006-10-27  Andy Kelk <andy@mopoke.co.uk>
+
+	* src/libmtp.c: add support form abstract audio/video albums.
+	* src/libmtp.h.in: dito.
+
+2006-10-23  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: retire opcode rendering (moved to ptp.c)
+	* src/ptp.c: sync to upstream.
+	* src/ptp.h: dito.
+	* src/ptp-pack.c: dito.
+
+2006-10-20  Linus Walleij <triad@df.lth.se>
+
+	* Release 0.0.21 to get all the new device support out.
+	
+2006-10-16  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump to 0.0.21.
+	* src/libusb-glue.c: add code to unload a kernel driver for
+	  the primary interface if it is already in use under Linux.
+	* src/libusb-glue.h: add a device flag to make this possible.
+
+2006-10-11  Linus Walleij <triad@df.lth.se>
+
+	* examples/delfile.c: patch from Chris Debenham 
+	  straingtening out the command-line interface a bit
+	  more.
+
+2006-10-10  Linus Walleij <triad@df.lth.se>
+
+	* examples/delfile.c: patch from Chris Debenham to make 
+	  this command take an optional filename as parameter 
+	  instead of file ID.
+
+2006-09-26  Linus Walleij <triad@df.lth.se>
+
+	* libmtp.pc.in: require libusb instead of just linking it.
+	* configure.ac: bump release to 0.0.20 and release.
+
+2006-09-25  Linus Walleij <triad@df.lth.se>
+
+	* examples/evolution-sync.sh: example script to illustrate
+	  to to transfer calendar, task and contact information
+	  to a device supporting this.
+
+2006-09-19  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: fixed attribute IDs to be 16bit.
+	* src/libmtp.c: dito.
+	* examples/sendfile.c: support vcard3.
+
+2006-09-16  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump to 0.0.19 and release. There are some
+	  new devices as well.
+	* src/unicode.c: retire unused code.
+
+2006-09-13  Linus Walleij <triad@df.lth.se>
+
+	* examples/format.c: formatting test program.
+	* examples.Makefile.am: added format.
+
+2006-09-13  Andy Kelk <andy@mopoke.co.uk>
+
+	* src/libmtp.h.in: added interface to format storage.
+	* src/libmtp.c: dito.
+	* src/ptp.c: dito.
+	* src/ptp.h: dito.
+
+2006-09-12  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump release. Released 0.0.18 yesterday.
+	* src/libmtp.c: do not try to read battery max level unless
+	  the device supports it. (Bug occurred on Toshiba Gigabeat 
+	  P10.)
+
+2006-09-11  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: messed around a bit with device descriptor
+	  detection so as to bring closer to libgphoto2 detection algorithm.
+	  I've seen things that might be false positives, possibly USB mass
+	  storage devices with additional MSFT descriptors to indicate they
+	  have Janus DRM. 
+	* src/libmtp.c: use UCS-2-INTERNAL if we're not on glibc. glibc
+	  knows that UCS-2 is in machine endianness but Darwin and *BSD does
+	  not. Detect C library and switch accordingly.
+	* src/unicode.c: retire old unicode code only keep things we cannot
+	  live without. Remove the own internal UCS-2 conversion engine and
+	  the internal iconv() engine and use the one already available in
+	  PTPParams.
+	* src/unicode.h: dito.
+
+2006-09-07  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.h: added device flags so we can make
+	  the code behave differently on certain devices.
+	* src/libusb-glue.c: dito, plus removed some debug prints.
+	* src/libmtp.c: docs.
+	* src/libmtp.h.in: added device_flags to device list struct.
+	* src/Makefile.am: bumped to compatible library interface.
+	* configure.ac: bump version to 0.0.18 (0.0.17 released
+	  yesterday).
+
+2006-09-06  Richard Low <richard@wentnet.com>
+
+	* src/libusb-glue.c: changed packet sizes to improve
+	  transfer speeds.
+	* src/libmtp.c: changed packet sizes to improve transfer
+	  transfer speeds. Also stopped extra ptp_getobjectinfo
+	  calls when getting directories on connect.
+
+2006-09-06  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: fixed some endpoint size detection
+	  and sending special file sizes stuff. Real hairy bug...
+	  Also messed around a bit with the callbacks.
+	* src/libmtp.c: changes for callback size detection.
+
+2006-09-04  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: bug in streaming code, use defined USB_BULK_HDR_SIZE
+	  instead of magic values.
+
+2006-09-02  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: add some code to have 
+	  LIBMTP_Send_File_From_File_Descriptor() accept a stream
+	  if size is set to (uint64_t) -1, plus documentation fixes.
+	  I don't think the streaming code will work but whoever want
+	  to experiment with it has a place to start.
+	* examples/refactortest.c: removed. Who uses this?
+
+2006-08-30  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: version bump.
+	* src/libmtp.c: more debug prints.
+	* src/libusb-glue.c: new iRiver device called Clix. By
+	  the way I released libmtp 0.0.16 yesterday.
+
+2006-08-28  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: version bump.
+	* src/ptp-pack.c: upstream has committed my patch giving full
+	  unicode support in libgphoto2 ptp2 camlib. No need for
+	  any more ugly workarounds, plus we now have full unicode
+	  filenames!
+	* src/ptp.c: dito.
+	* src/ptp.h: dito.
+	* src/libmtp.c: revamp to use the new unicode support in
+	  libgphoto2.
+	* src/unicode.c: remove unused functionality.
+	* src/unicode.h: dito.
+
+2006-08-27  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: version bump. Release all these fixes
+	  as 0.0.15.
+	* src/libusb-glue.c: fixed sucky errors. Added callback
+	  code when reading files.
+	* src/libusb-glue.h: const correctness.
+	* src/libmtp.h.in: finally fixup the type on the callbacks.
+	* src/libmtp.c: more accurate sending callbacks. Callbacks
+	  when getting files also, working correctly. Typeing of
+	  callbacks now OK.
+	* examples/getfile.c: some display bar cosmetic fixup.
+	* TODO: lots of the things todo are now done.
+
+2006-08-26  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: version bump.
+	* src/libmtp.c: fix bug and reinstate callbacks.
+	* src/libusb-glue.h: dito.
+	* src/libusb-glue.c: dito.
+
+2006-08-25  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: use the new file descriptor sender function.
+	  Going to release this as 0.0.13.
+	* src/ptp.c: upstream accepted patches synced in.
+	* src/ptp.h: dito.
+
+2006-08-22  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: found a real nasty endpoint bug,
+	  code from libgphoto2 was assuming max packet size of
+	  512 bytes while it is 64 when a USB 2.0 device is
+	  plugged into an UHCI hub.
+
+2006-08-22  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump to 0.0.13, also released 0.0.12 now.
+	
+2006-08-21  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: fixup mmap() usage and add madvise() 
+	  as result of experiments by Gavin McCullagh. Upstream
+	  accept patch to get files directly to file descriptor.
+	  Move iconv() converters into device struct for thread
+	  safety.
+	* src/ptp.c: sync to upstream which merges patch to get
+	  file directly to file descriptor.
+	* src/ptp.h: dito.
+	* src/unicode.c: move iconv() converters into the device
+	  struct for thread safety.
+	* src/unicode.h: dito.
+
+2006-08-20  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: set friendly name and sync partner,
+	  rename ownername to friendlyname.
+	* src/libmtp.c: dito.
+	* examples/detect.c: reflect changes.
+	* src/Makefile.am: interface is incompatible so age it.
+	
+2006-08-19  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: add function to get syncronization
+	  partner for the device.
+	* src/libmtp.c: dito.
+	* examples/detect.c: use that function.
+	* src/Makefile.am: backward-compatible interface bump.
+
+2006-08-17  Linus Walleij <triad@df.lth.se>
+
+	* configure.ac: bump to 0.0.12 and require iconv.h.
+
+2006-08-16  Linus Walleij <triad@df.lth.se>
+
+	* src/unicode.c: remove bigendian weirdness and switch
+	  to using iconv() instead.
+	* src/unicode.h: dito.
+	* src/libmtp.c: reflect changes.
+	
+2006-08-09  Linus Walleij <triad@df.lth.se>
+
+	* Release libmtp 0.0.11.
+
+2006-08-04  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: patch from Dan Aloni to make sendfile
+	  use mmap and avoid memory drainage.
+	* src/libusb-glue.c: patch from Andy Kelk to avoid 
+	  exit():ing when the interface cannot be claimed.
+	* configure.ac: version bump.
+
+2006-07-27  Linus Walleij <triad@df.lth.se>
+	
+	* Release libmtp 0.0.10.
+
+2006-07-26  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: new SanDisk devices.
+	* src/libmtp.c: only set metdata properties supported by
+	  the device, duh.
+	* src/ptp.c: sync to upstream.
+	* src/ptp.h: sync to upstream.
+	* configure.ac: bump to 0.0.10.
+
+2006-06-22  Linus Walleij <triad@df.lth.se>
+
+	* Release libmtp 0.0.9.
+
+2006-06-21  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: added function to retrieve supported
+	  filetypes.	
+	* src/libmtp.c: ditto.
+	* examples/detect.c: use that function.
+
+2006-06-19  Linus Walleij <triad@df.lth.se>
+
+	* src/unicode.c: support all endianness, detect 
+	  byte-order-mark
+	* src/unicode.h: ditto.
+	* src/libmtp.c: ditto.
+	* examples/detect.c: use proper tempfile function.
+	* src/libmtp.h.in: add some more track properties.
+	* src/libmtp.c: ditto.
+	* examples/tracks.c: ditto.
+	
+2006-06-16  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: new interfaces for single metadata post
+	  retrieveal.
+	* src/libmtp.c: ditto.
+	* examples/playlists.c: display track info using the new
+	  individual track metadata retrieveal method.
+	* examples/getplaylist.c: ditto.
+
+2006-06-13  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: added default folders to device struct.
+	  Add some new function prototypes.
+	* src/libmtp.c: discover and use the default folders if
+	  we can find them. Retrieve device secure time and cert
+	  out of sheer curiosity.
+	* src/ptp.c: sync to libgphoto2 with my patches.
+	* src/ptp.h: ditto.
+
+2006-06-07  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.h.in: new playlist API and refactorings.
+	* src/libmtp.c: ditto, and refactorings.
+	* src/unicode.h: const correctness.
+	* src/unicode.c: ditto.
+	* examples/playlists.c: new example program.
+	* configure.ac: bump to 0.0.9
+	* src/Makefile.am: bump library interface.
+	
+2006-06-05  Linus Walleij <triad@df.lth.se>
+
+	* examples/sendtr.c: fixed annoying bug that made this
+	  program totally useless.
+	* src/libmtp.c: cosmetics.
+	* configure.ac: bump to 0.0.8.
+
+2006-06-03  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: metadata bugs, album name and genre
+	  confused. Fixe it and released libmtp 0.0.7.
+
+2006-06-01  Linus Walleij <triad@df.lth.se>
+
+	* Released libmtp 0.0.6.
+
+2006-05-31  Linus Walleij <triad@df.lth.se>
+
+	* src/libmtp.c: fixed mapping for JPEG vs JFIF
+	* src/libmtp.h.in: added proper type for JPEG
+	* examples/sendfile.c: send proper JPEG type
+
+2006-05-30  Flavien Lebarbe <flavien+libmtp@lebarbe.net>
+
+	* src/libmtp.c: fixed a bug in update metadata due to
+	  bad use of return code.
+	* src/libusb-glue.c: fixed a loop exiting problem with
+	  good 'ol GOTO.
+	
+2006-05-29  Linus Walleij <triad@df.lth.se>
+
+	* src/libusb-glue.c: one more device.
+	* doc/examples.h: produce correct documentation.
+	* configure.ac: bump to 0.0.6.
+	* src/ptp.c: sync to libgphoto2.
+	* src/ptp.h: ditto.
+	* src/ptp-pack.c: ditto.
+	* src/libmtp.c: fixed all filetype API related functions
+	  not to use any PTP intrinsic defines at all, made all
+	  parameters to functions use the internal libmtp interface
+	  enumerations and definitions. Removed LIBMTP_Release():
+	  we can live with the memory lost during init. You're not
+	  supposed to re-initialize the device. Consequently removed
+	  the delete function that cleaned the filetype assoc list.
+	* examples/refactortest.c: reflect changes.
+
+2006-05-26  Dave Kelly <libmtp@ravelox.co.uk>
+
+	* src/libmtp.c: refactored object handling to be more generic
+	* src/libmtp.h.in: ditto
+	* examples/refactortest.c: Added simple example to use refactoring
+	* examples/getplaylist.c: Added example to extract playlist data
+	* src/ptp.c: Re-added ptp_get/set_objectreferences to allow 
+	  for playlist handling
+	* src/ptp.h: ditto
+
+2006-05-08  Linus Walleij  <triad@df.lth.se>
+
+	* src/libmtp.h.in: add simple detection function.
+	* src/libusb-glue.c: implement MTP "OS descriptor" for
+	  looking for MTP devices.
+	* examples/detect.c: make it possible to do very 
+	  rudimentary detection with "detect -p".
+	* configure.ac: bump to 0.0.5.
+
+2006-05-07  Linus Walleij  <triad@df.lth.se>
+
+	* COPYING: since we no longer use any parts of libptp2
+	  and only files from libgphoto2, we switch to the GNU
+	  Lesser General Public License (GNU LGPL). libptp2 is
+	  a derived work from libgphoto2, and so is libmtp, there
+	  are no remnants of libptp2 in libmtp anymore.
+
+2006-05-04  Linus Walleij  <triad@df.lth.se>
+
+	* examples/sendfile.c: fixes some more filetypes.
+	* src/libmtp.c: respectfully rearranged to use a filetype mapping 
+	  table.
+	* src/ptp-pack.c: real nasty unicode packing bug.
+	* Release libmtp 0.0.4.
+
+2006-05-02  Linus Walleij  <triad@df.lth.se>
+
+	* src/libmtp.c: general shaping up for release. All track
+	  and file sending functions now respects a parent ID to be
+	  sent along with files and tracks.
+	* src/libmtp.h.in: dito.
+	* src/libusb-glue.c: dito.
+	* examples/sendfile.c: interface dependency changes.
+	* examples/sendtr.c: dito.
+
+2006-04-30  Linus Walleij  <triad@df.lth.se>
+
+	* src/ptp.c: sync upstream.
+	* src/ptp.h: dito.
+
+2006-04-27  Linus Walleij  <triad@df.lth.se>
+
+	* examples/sendfile.c: first file sender program based
+	  on API implementation and changes by Chris Allegretta.
+	* examples/Makefile.am: new program, new entry.
+	* src/libmtp.c: reflect this new functionality.
+	* src/libmtp.h.in: dito.
+	
+2006-04-25  Linus Walleij  <triad@df.lth.se>
+
+	* Rebased the sources around libgphoto2 instead.
+	  This was a major revision...
+	* src/ptp.c: imported libgphoto2 version verbatim.
+	* src/ptp.h: imported libgphoto2 version, minor patch.
+	* src/ptp-pack.c: imported libgphoto2 version, minor patch.
+	* src/ptp-pack.h: dropped, libgphoto2 does not use it.
+	* src/mtp.c: dropped, since all functions are now in ptp.c
+	* src/mtp-pack.c: dropped, same reason.
+	* src/mtp.h: dropped, same reason.
+	* src/mtp-pack.h: dropped, same reason.
+
+2006-04-21  Linus Walleij  <triad@df.lth.se>
+
+	* Released libmtp 0.0.3
+	* Bumped source to 0.0.4
+
+2006-04-21  Linus Walleij  <triad@df.lth.se>
+
+	* src/ptp-pack.c: GCC 4.x compilation patch from
+	  Diego Pettenò.
+	* src/libusb-glue.c: New Samsung device and some
+	  from libgphoto2.
+	* src/ptp.h: some defines from libgphoto2 to get
+	  a bit more compatible.
+	* src/libmtp.c: Added a folder API implementation by
+	  Dave "ravelox" Kelly.
+	* src/libmtp.h.in: dito.
+	* examples/folders.c: dito.
+	* examples/newfolder.c: dito.
+	* examples/trexist.c: dito.
+	
+2006-03-28  Linus Walleij  <triad@df.lth.se>
+
+	* m4/*: updated macros to work with GCC 4.1.0.
+	* examples/hotplug.c: new program to create device
+	  ID lists.
+	* libmtp.rules: now an auto-generated file.
+	* libmtp.usermap: now an auto-generated file.
+
+2006-03-24  Linus Walleij  <triad@df.lth.se>
+
+	* Beginning a file API, fixed some example program
+	  names and such.
+
+2006-03-18  Linus Walleij  <triad@df.lth.se>
+
+	* Fixed up callback interface to a simpler version,
+	  the old one was bloated stuff from libnjb anyway.
+	  Bump to 0.0.2.
+
+2006-03-16  Linus Walleij  <triad@df.lth.se>
+
+	* Fixed the .h file and implementation so you really only
+	  need this one .h file to interface the library.
+
+2006-03-15  Linus Walleij  <triad@df.lth.se>
+
+	* Added three device information retrieval functions.
+
+2006-03-06  Linus Walleij  <triad@df.lth.se>
+
+	* Moving some things around to structure the source. More
+	  will be needed...
+
+2006-02-27  Linus Walleij  <triad@df.lth.se>
+
+	* Release libmtp 0.0.1 so people have something to play with,
+	  what the heck. Probably saves someones day.
+
+2006-02-24  Linus Walleij  <triad@df.lth.se>
+
+	* Deltr example program to delete tracks, plus corresponding
+	  interface call.
+	
+2006-02-23  Linus Walleij  <triad@df.lth.se>
+
+	* Fixed up sendtr program and metadata tagging function that is
+	  used after sending files.
+
+2006-02-22  Linus Walleij  <triad@df.lth.se>
+
+	* Untested gettr.c and sendtr.c programs to get and send tracks
+	  created.
+	
+2006-01-30  Linus Walleij  <triad@df.lth.se>
+
+	* Created the initial GNU source directory structure.
+	* Added the most basic files.
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..97180c6
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,206 @@
+INSTALLATION OVERVIEW
+=====================
+
+Once libmtp is built and installed, you will have the following files
+($PREFIX is the --prefix option given to the "configure" script and
+defaults to /usr/local/):
+
+   $PREFIX/lib/libmtp.a               Static C library
+   $PREFIX/lib/libmtp.so.x.y.z        Dynamic C library
+   $PREFIX/lib/libmtp.so.x            A link to the library
+   $PREFIX/lib/libmtp.so              A link to the library
+   $PREFIX/include/libmtp.h           C header file for libmtp API
+   $PREFIX/lib/pkgconfig/libmtp.pc    pkg-config configuration file
+
+Sample programs will be built in the "example" directory, and should
+help you get used to using the libmtp API, as well as provide some
+immediate gratification. Links to other programs using the libmtp
+API may be found at the homepage: http://libmtp.sourceforge.net/
+
+
+Install From Distribution
+-------------------------
+
+You should probably prefer to install libmtp from the distribution
+source you're using. Last time we checked, libmtp was part of Ubuntu,
+Fedora, OpenSUSE, Debian testing, Gentoo, FreeBSD ports and OpenBSD
+packages/ports.
+
+
+Dependencies
+------------
+
+To build libmtp you should only need development files for libusb.
+(Often named libusb-devel or similar.) For working with CVS versions
+you may need autoconf, automake, libtool, gettext(-devel).
+
+
+Shared Library Support
+----------------------
+
+Shared library linking is supported. You will need to 'make install'
+the library before you can execute the sample binaries, and add the
+libmtp install directory to your shared library search path.
+
+On Linux, you would add the line "/usr/local/lib" to your
+"/etc/ld.so.conf" or as a oneliner in for example a
+"/etc/ld.so.conf.d/local.conf" file and run the
+program "ldconfig" to scan in the shared libraries at
+the new path. This is a part of the Linux shared library
+loader actually.
+
+To access the library from real odd locations you can use
+the LD_LIBRARY_PATH environment variable by setting it before
+you run your program, for example:
+
+  % export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
+  % my_program
+
+This way of enabling the library to link is a workaround hack.
+Note that the LD_LIBRARY_PATH is actually supposed to be used for
+testing, not production systems or distributions. It is commonly
+used as a workaround when a user is installing libraries in her/his
+home directory however. Read more about this environment variable
+here: http://www.visi.com/~barr/ldpath.html
+
+The shared library comes with different interface version numbers,
+for example libmtp.so.4, libmtp.so.5 and so forth. This is used so
+that both old and new libmtp libraries shall be able to coexist on
+the same system. When you compile your programs they will typically
+bind to the latest version of the shared library. A link to the
+latest version is always provided as $PREFIX/lib/libmtp.so.
+
+libusb Support
+--------------
+
+This package depends on libusb.  Get libusb from sourceforge at:
+
+   http://www.sourceforge.net/projects/libusb/
+
+On Linux, please use the very latest version you can get, between
+0.1.8 and 0.1.12 a lot of things happened which pertains to
+the udev hotplugging support, see below.
+
+
+BASIC BUILD PROCEDURE
+=====================
+
+To build the package:
+
+   % ./configure
+   % make
+   % make install
+
+By default, libmtp will add the program-prefix "mtp-" to all the
+example programs prior to installation. The program-prefix option
+makes libmtp sample programs avoid collision with other programs like
+sox' "play" program. If the default prefix for some reason fail,
+try to tag on "--program-prefix=mtp-" to the "configure" command.
+
+On Linux you should then typically type (see below for details):
+
+   % ./hotplug.sh
+
+you can achieve the same with
+
+   % ./configure --enable-hotplugging
+
+you can turn off some speed enhancements (for testing) with:
+
+   % ./configure --no-turbo
+
+if you want to install the documentation type:
+
+   % make install-docs
+
+if you checked out the sources from CVS, you must first run the
+autogen.sh script that generates all the GNU autotools files.
+Notice that this requires GNU autoconf, automake and libtool and
+possibly some other packages like gettext, readline, intltool and
+other M4 macro sources. This is done with:
+
+   % ./autogen.sh
+
+
+Linux hotplugging
+-----------------
+
+After compilation and installation you may (and should) add hotplugging
+support by running the hotplug script, if your distribution supports
+hotplugging (all do). This typically means you have something
+in /etc/hotplug and that hotplugging is started when you boot your
+machine in a script named /etc/init.d/hotplug or similar.
+
+Activate hotplugging by running:
+
+   %./hotplug.sh
+
+Hotplug will (typically) use the device map file installed by hotplug.sh
+at /etc/hotplug/usb/libmtp.usermap to lift the device to userspace for the
+current user by running the script /etc/hotplug/usb/libmtp.sh. If
+you have the program "resmgr" installed (currently used only by SuSE to
+our knowledge) that program will be used for enabling desktop user
+access, otherwise the current user of the desktop will be determined
+from files in /var/run. (See the script "libmtp.sh" for details.)
+
+
+Linux udev hotplugging
+----------------------
+
+Newer Linux distributions have dropped support for the old hotplug system
+and rely solely on udev, and rules stored below /etc/udev/rules.d to
+handle permissions and actions on device connections. It's quite solid
+but the whole thing is rather shaky when it comes to such things as
+custom devices handled solely by libusb, which is what libmtp and for
+example SANE backends use.
+
+The libmtp.rules file that comes with libmtp can be used as a starter.
+
+First you need a crazy rule that creates a device node in the
+/dev/bus/usb hierarchy whenever any USB device is connected. The
+script has this at the top, you can comment it in if your
+distribution does not already create these device nodes.
+
+Then libusb may need to be patched to recognize this hierarchy. 
+The 0.1.12 version is the first which is properly fixed.
+
+The script sets the device access to "666" which is rather nasty
+(not that big security issue, unless you think someone will break
+into your jukebox) some systems prefer to let PAM do this by placing
+a configuration file in /etc/security/ somewhere. See the Fedora Extras
+SRPM source package in case you're interested in how it is handled
+there.
+
+
+If you cannot run hotplugging
+-----------------------------
+
+If you have a distro without hotplugging enabled try this as root:
+
+  % chmod -R a+w /proc/bus/usb
+
+You have to do this again every time you unplug/replug your USB cable
+or restart the jukebox, every time you quit libnjb and restart it,
+etc etc etc an alternative is to run libmtp as root which works just fine.
+The problem is to somehow assure that you (ie the current user) always
+has write access on  /proc/bus/usb/*
+
+You can find the Linux hotplug project at:
+http://linux-hotplug.sourceforge.net/
+
+
+Compilation for embedded devices
+--------------------------------
+
+Problems with Autoconf complaining about a missing malloc() function
+during cross-compilation can be solved with this hack if you're using
+glibc:
+
+  % export ac_cv_func_malloc_0_nonnull=yes
+  % ./configure
+
+If you're using uclibc you may have to smack in a custom rpl_malloc()
+function in your program, see the Autoconf texinfo documentation.
+
+See further:
+http://wiki.buici.com/wiki/Autoconf_and_RPL_MALLOC
\ No newline at end of file
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..f79235d
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,15 @@
+SUBDIRS=src examples doc
+ACLOCAL_AMFLAGS=-I m4
+
+pkgconfigdir=$(libdir)/pkgconfig
+pkgconfig_DATA=libmtp.pc
+EXTRA_DIST=libmtp.pc libmtp.sh COPYING README.windows.txt
+noinst_DATA=libmtp.usermap libmtp.rules libmtp.fdi
+libmtp.usermap: examples/hotplug
+	examples/hotplug > libmtp.usermap
+libmtp.rules: examples/hotplug
+	examples/hotplug -u > libmtp.rules
+libmtp.fdi: examples/hotplug
+	examples/hotplug -H > libmtp.fdi
+
+CLEANFILES = libmtp.usermap libmtp.rules libmtp.fdi
diff --git a/Makefile.in b/Makefile.in
new file mode 100644
index 0000000..2c20865
--- /dev/null
+++ b/Makefile.in
@@ -0,0 +1,792 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = .
+DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
+	$(srcdir)/Makefile.in $(srcdir)/config.h.in \
+	$(srcdir)/hotplug.sh.in $(srcdir)/libmtp.pc.in \
+	$(srcdir)/libmtp.sh.in $(top_srcdir)/configure AUTHORS COPYING \
+	ChangeLog INSTALL TODO config.guess config.rpath config.sub \
+	depcomp install-sh ltmain.sh missing
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/byteorder.m4 \
+	$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+	$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+	$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/stdint.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
+ configure.lineno config.status.lineno
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = config.h
+CONFIG_CLEAN_FILES = libmtp.sh hotplug.sh libmtp.pc
+CONFIG_CLEAN_VPATH_FILES =
+SOURCES =
+DIST_SOURCES =
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
+	html-recursive info-recursive install-data-recursive \
+	install-dvi-recursive install-exec-recursive \
+	install-html-recursive install-info-recursive \
+	install-pdf-recursive install-ps-recursive install-recursive \
+	installcheck-recursive installdirs-recursive pdf-recursive \
+	ps-recursive uninstall-recursive
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(pkgconfigdir)"
+DATA = $(noinst_DATA) $(pkgconfig_DATA)
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
+  distclean-recursive maintainer-clean-recursive
+AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
+	$(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
+	distdir dist dist-all distcheck
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+distdir = $(PACKAGE)-$(VERSION)
+top_distdir = $(distdir)
+am__remove_distdir = \
+  { test ! -d "$(distdir)" \
+    || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
+         && rm -fr "$(distdir)"; }; }
+am__relativize = \
+  dir0=`pwd`; \
+  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+  sed_rest='s,^[^/]*/*,,'; \
+  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+  sed_butlast='s,/*[^/]*$$,,'; \
+  while test -n "$$dir1"; do \
+    first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+    if test "$$first" != "."; then \
+      if test "$$first" = ".."; then \
+        dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+        dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+      else \
+        first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+        if test "$$first2" = "$$first"; then \
+          dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+        else \
+          dir2="../$$dir2"; \
+        fi; \
+        dir0="$$dir0"/"$$first"; \
+      fi; \
+    fi; \
+    dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+  done; \
+  reldir="$$dir2"
+DIST_ARCHIVES = $(distdir).tar.gz
+GZIP_ENV = --best
+distuninstallcheck_listfiles = find . -type f -print
+distcleancheck_listfiles = find . -type f -print
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AS = @AS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+HAVE_DOXYGEN = @HAVE_DOXYGEN@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBICONV = @LIBICONV@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBICONV = @LTLIBICONV@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OSFLAGS = @OSFLAGS@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+effective_target = @effective_target@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+ms_lib_exe = @ms_lib_exe@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+SUBDIRS = src examples doc
+ACLOCAL_AMFLAGS = -I m4
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libmtp.pc
+EXTRA_DIST = libmtp.pc libmtp.sh COPYING README.windows.txt
+noinst_DATA = libmtp.usermap libmtp.rules libmtp.fdi
+CLEANFILES = libmtp.usermap libmtp.rules libmtp.fdi
+all: config.h
+	$(MAKE) $(AM_MAKEFLAGS) all-recursive
+
+.SUFFIXES:
+am--refresh:
+	@:
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \
+	      $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \
+		&& exit 0; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    echo ' $(SHELL) ./config.status'; \
+	    $(SHELL) ./config.status;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	$(SHELL) ./config.status --recheck
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	$(am__cd) $(srcdir) && $(AUTOCONF)
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	$(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
+$(am__aclocal_m4_deps):
+
+config.h: stamp-h1
+	@if test ! -f $@; then \
+	  rm -f stamp-h1; \
+	  $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \
+	else :; fi
+
+stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
+	@rm -f stamp-h1
+	cd $(top_builddir) && $(SHELL) ./config.status config.h
+$(srcdir)/config.h.in:  $(am__configure_deps) 
+	($(am__cd) $(top_srcdir) && $(AUTOHEADER))
+	rm -f stamp-h1
+	touch $@
+
+distclean-hdr:
+	-rm -f config.h stamp-h1
+libmtp.sh: $(top_builddir)/config.status $(srcdir)/libmtp.sh.in
+	cd $(top_builddir) && $(SHELL) ./config.status $@
+hotplug.sh: $(top_builddir)/config.status $(srcdir)/hotplug.sh.in
+	cd $(top_builddir) && $(SHELL) ./config.status $@
+libmtp.pc: $(top_builddir)/config.status $(srcdir)/libmtp.pc.in
+	cd $(top_builddir) && $(SHELL) ./config.status $@
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+distclean-libtool:
+	-rm -f libtool config.lt
+install-pkgconfigDATA: $(pkgconfig_DATA)
+	@$(NORMAL_INSTALL)
+	test -z "$(pkgconfigdir)" || $(MKDIR_P) "$(DESTDIR)$(pkgconfigdir)"
+	@list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgconfigdir)'"; \
+	  $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgconfigdir)" || exit $$?; \
+	done
+
+uninstall-pkgconfigDATA:
+	@$(NORMAL_UNINSTALL)
+	@list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	test -n "$$files" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(pkgconfigdir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(pkgconfigdir)" && rm -f $$files
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+#     (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	target=`echo $@ | sed s/-recursive//`; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    dot_seen=yes; \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done; \
+	if test "$$dot_seen" = "no"; then \
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+	fi; test -z "$$fail"
+
+$(RECURSIVE_CLEAN_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	case "$@" in \
+	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+	  *) list='$(SUBDIRS)' ;; \
+	esac; \
+	rev=''; for subdir in $$list; do \
+	  if test "$$subdir" = "."; then :; else \
+	    rev="$$subdir $$rev"; \
+	  fi; \
+	done; \
+	rev="$$rev ."; \
+	target=`echo $@ | sed s/-recursive//`; \
+	for subdir in $$rev; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done && test -z "$$fail"
+tags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+	done
+ctags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
+	done
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+	  include_option=--etags-include; \
+	  empty_fix=.; \
+	else \
+	  include_option=--include; \
+	  empty_fix=; \
+	fi; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test ! -f $$subdir/TAGS || \
+	      set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
+	  fi; \
+	done; \
+	list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	$(am__remove_distdir)
+	test -d "$(distdir)" || mkdir "$(distdir)"
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test -d "$(distdir)/$$subdir" \
+	    || $(MKDIR_P) "$(distdir)/$$subdir" \
+	    || exit 1; \
+	  fi; \
+	done
+	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+	    $(am__relativize); \
+	    new_distdir=$$reldir; \
+	    dir1=$$subdir; dir2="$(top_distdir)"; \
+	    $(am__relativize); \
+	    new_top_distdir=$$reldir; \
+	    echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
+	    echo "     am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
+	    ($(am__cd) $$subdir && \
+	      $(MAKE) $(AM_MAKEFLAGS) \
+	        top_distdir="$$new_top_distdir" \
+	        distdir="$$new_distdir" \
+		am__remove_distdir=: \
+		am__skip_length_check=: \
+		am__skip_mode_fix=: \
+	        distdir) \
+	      || exit 1; \
+	  fi; \
+	done
+	-test -n "$(am__skip_mode_fix)" \
+	|| find "$(distdir)" -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
+	  ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
+	  ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
+	  ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
+	|| chmod -R a+r "$(distdir)"
+dist-gzip: distdir
+	tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+	$(am__remove_distdir)
+
+dist-bzip2: distdir
+	tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
+	$(am__remove_distdir)
+
+dist-lzma: distdir
+	tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma
+	$(am__remove_distdir)
+
+dist-xz: distdir
+	tardir=$(distdir) && $(am__tar) | xz -c >$(distdir).tar.xz
+	$(am__remove_distdir)
+
+dist-tarZ: distdir
+	tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
+	$(am__remove_distdir)
+
+dist-shar: distdir
+	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
+	$(am__remove_distdir)
+
+dist-zip: distdir
+	-rm -f $(distdir).zip
+	zip -rq $(distdir).zip $(distdir)
+	$(am__remove_distdir)
+
+dist dist-all: distdir
+	tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
+	$(am__remove_distdir)
+
+# This target untars the dist file and tries a VPATH configuration.  Then
+# it guarantees that the distribution is self-contained by making another
+# tarfile.
+distcheck: dist
+	case '$(DIST_ARCHIVES)' in \
+	*.tar.gz*) \
+	  GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(am__untar) ;;\
+	*.tar.bz2*) \
+	  bunzip2 -c $(distdir).tar.bz2 | $(am__untar) ;;\
+	*.tar.lzma*) \
+	  unlzma -c $(distdir).tar.lzma | $(am__untar) ;;\
+	*.tar.xz*) \
+	  xz -dc $(distdir).tar.xz | $(am__untar) ;;\
+	*.tar.Z*) \
+	  uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
+	*.shar.gz*) \
+	  GZIP=$(GZIP_ENV) gunzip -c $(distdir).shar.gz | unshar ;;\
+	*.zip*) \
+	  unzip $(distdir).zip ;;\
+	esac
+	chmod -R a-w $(distdir); chmod a+w $(distdir)
+	mkdir $(distdir)/_build
+	mkdir $(distdir)/_inst
+	chmod a-w $(distdir)
+	test -d $(distdir)/_build || exit 0; \
+	dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
+	  && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
+	  && am__cwd=`pwd` \
+	  && $(am__cd) $(distdir)/_build \
+	  && ../configure --srcdir=.. --prefix="$$dc_install_base" \
+	    $(DISTCHECK_CONFIGURE_FLAGS) \
+	  && $(MAKE) $(AM_MAKEFLAGS) \
+	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
+	  && $(MAKE) $(AM_MAKEFLAGS) check \
+	  && $(MAKE) $(AM_MAKEFLAGS) install \
+	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
+	  && $(MAKE) $(AM_MAKEFLAGS) uninstall \
+	  && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
+	        distuninstallcheck \
+	  && chmod -R a-w "$$dc_install_base" \
+	  && ({ \
+	       (cd ../.. && umask 077 && mkdir "$$dc_destdir") \
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
+	            distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
+	      } || { rm -rf "$$dc_destdir"; exit 1; }) \
+	  && rm -rf "$$dc_destdir" \
+	  && $(MAKE) $(AM_MAKEFLAGS) dist \
+	  && rm -rf $(DIST_ARCHIVES) \
+	  && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \
+	  && cd "$$am__cwd" \
+	  || exit 1
+	$(am__remove_distdir)
+	@(echo "$(distdir) archives ready for distribution: "; \
+	  list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
+	  sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
+distuninstallcheck:
+	@$(am__cd) '$(distuninstallcheck_dir)' \
+	&& test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
+	   || { echo "ERROR: files left after uninstall:" ; \
+	        if test -n "$(DESTDIR)"; then \
+	          echo "  (check DESTDIR support)"; \
+	        fi ; \
+	        $(distuninstallcheck_listfiles) ; \
+	        exit 1; } >&2
+distcleancheck: distclean
+	@if test '$(srcdir)' = . ; then \
+	  echo "ERROR: distcleancheck can only run from a VPATH build" ; \
+	  exit 1 ; \
+	fi
+	@test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
+	  || { echo "ERROR: files left in build directory after distclean:" ; \
+	       $(distcleancheck_listfiles) ; \
+	       exit 1; } >&2
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(DATA) config.h
+installdirs: installdirs-recursive
+installdirs-am:
+	for dir in "$(DESTDIR)$(pkgconfigdir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+	-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-recursive
+
+clean-am: clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-recursive
+	-rm -f $(am__CONFIG_DISTCLEAN_FILES)
+	-rm -f Makefile
+distclean-am: clean-am distclean-generic distclean-hdr \
+	distclean-libtool distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+html-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am: install-pkgconfigDATA
+
+install-dvi: install-dvi-recursive
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-recursive
+
+install-html-am:
+
+install-info: install-info-recursive
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-pdf-am:
+
+install-ps: install-ps-recursive
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+	-rm -f $(am__CONFIG_DISTCLEAN_FILES)
+	-rm -rf $(top_srcdir)/autom4te.cache
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am: uninstall-pkgconfigDATA
+
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) all \
+	ctags-recursive install-am install-strip tags-recursive
+
+.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
+	all all-am am--refresh check check-am clean clean-generic \
+	clean-libtool ctags ctags-recursive dist dist-all dist-bzip2 \
+	dist-gzip dist-lzma dist-shar dist-tarZ dist-xz dist-zip \
+	distcheck distclean distclean-generic distclean-hdr \
+	distclean-libtool distclean-tags distcleancheck distdir \
+	distuninstallcheck dvi dvi-am html html-am info info-am \
+	install install-am install-data install-data-am install-dvi \
+	install-dvi-am install-exec install-exec-am install-html \
+	install-html-am install-info install-info-am install-man \
+	install-pdf install-pdf-am install-pkgconfigDATA install-ps \
+	install-ps-am install-strip installcheck installcheck-am \
+	installdirs installdirs-am maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \
+	uninstall uninstall-am uninstall-pkgconfigDATA
+
+libmtp.usermap: examples/hotplug
+	examples/hotplug > libmtp.usermap
+libmtp.rules: examples/hotplug
+	examples/hotplug -u > libmtp.rules
+libmtp.fdi: examples/hotplug
+	examples/hotplug -H > libmtp.fdi
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/README b/README
new file mode 100644
index 0000000..c4f3368
--- /dev/null
+++ b/README
@@ -0,0 +1,709 @@
+Building and Installing
+-----------------------
+
+See the "INSTALL" file.
+
+
+Heritage
+--------
+
+libmtp is based on several ancestors:
+
+* libptp2 by Mariusz Woloszyn was the starting point used
+  by Richard A. Low for the initial starter port. You can
+  find it at http://libptp.sourceforge.net/
+
+* libgphoto2 by Mariusz Woloszyn and Marcus Meissner was
+  used at a later stage since it was (is) more actively
+  maintained. libmtp tracks the PTP implementation in
+  libgphoto2 and considers it an upstream project. We will
+  try to submit anything generally useful back to libgphoto2
+  and not make double efforts. In practice this means we
+  use ptp.c, ptp.h and ptp-pack.c verbatim from the libgphoto2
+  source code. If you need to change things in these files,
+  make sure it is so general that libgphoto2 will want to
+  merge it to their codebase too. You find libgphoto2 as part
+  of gPhoto: http://gphoto.sourceforge.net/
+
+* libnjb was a project that Richard and Linus were working
+  on before libmtp. When Linus took Richards initial port
+  and made an generic C API he re-used the philosophy and
+  much code from libnjb. Many of the sample programs are for
+  example taken quite literally from libnjb. You find it here:
+  http://libnjb.sourceforge.net/
+
+
+Contacting and Contributing
+---------------------------
+
+See the project page at http://libmtp.sourceforge.net/
+We always need your help. There is a mailinglist and a
+bug report system there.
+
+People who want to discuss MTP devices in fora seem to
+hang out on the forums at AnythingbutiPod:
+http://www.anythingbutipod.com/forum/
+
+
+Compiling programs for libmtp
+-----------------------------
+
+libmtp has support for the pkg-config script by adding a libmtp.pc
+entry in $(prefix)/lib/pkgconfig. To compile a libmtp program,
+"just" write:
+
+gcc -o foo `pkg-config --cflags --libs libmtp` foo.c
+
+This also simplifies compilation using autoconf and pkg-config: just
+write e.g.
+
+PKG_CHECK_MODULES(MTP, libmtp)
+AC_SUBST(MTP_CFLAGS)
+AC_SUBST(MTP_LIBS)
+
+To have libmtp LIBS and CFLAGS defined. Needless to say, this will
+only work if you have pkgconfig installed on your system, but most
+people have nowadays.
+
+If your library is installed in e.g. /usr/local you may have to tell
+this to pkgconfig by setting the PKG_CONFIG_PATH thus:
+
+export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
+
+
+Documentation
+-------------
+
+Read the API documentation that can be generated with doxygen.
+It will be output in doc/html if you have Doxygen properly
+installed. (It will not be created unless you have Doxygen!)
+
+For information about the Media Transfer Protocol, see:
+http://en.wikipedia.org/wiki/Media_Transfer_Protocol
+
+The official 1.0 specification for MTP was released by the
+USB Implementers Forum in may, 2008. Prior to this, only a
+proprietary Microsoft version was available, and quite a few
+devices out there still use some aspects of the Microsoft
+version, which deviates from the specified standard. You can
+find the official specification here:
+http://www.usb.org/developers/devclass_docs/MTP_1.0.zip
+
+
+The Examples
+------------
+
+In the subdirectory "examples" you find a number of 
+command-line tools, illustrating the use of libmtp in very
+simple terms.
+
+Please do not complain about the usability or documentation
+of these examples, they look like they do for two reasons:
+
+1. They are examples, not tools. If they were intended for
+   day-to-day usage by commandline freaks, I would have
+   called them "tools" not "examples".
+
+2. The MTP usage paradigm is that a daemon should hook
+   the device upon connection, and that it should be 
+   released by unplugging. GUI tools utilizing HAL (hald)
+   and D-Bus do this much better than any commandline
+   program ever can. (See below on bugs.) Specificationwise
+   this is a bug, however it is present in many, many
+   devices.
+
+That said, if you want to pick up and maintain the examples,
+please volunteer.
+
+
+New Devices
+-----------
+
+If you happen upon a device which libmtp claims it cannot
+autodetect, please submit the vendor ID and device ID 
+(these can be obtained from the "lsusb" and "lsusb -n"
+commands run as root) as a bug, patch or feature request 
+on the Sourceforge bug tracker at our homepage. If it 
+gives a sensible  output from "mtp-detect" then please attach 
+the result as well as it teach us some stuff about your 
+device. If you've done some additional hacking, join our 
+mailinglist and post your experiences there.
+
+If you want to be able to hack some more and you're not
+afraid of C hacking, add an entry for your device's 
+vendor/product ID and a descriptive string to the database 
+in the file src/music-players.h.
+
+If you want to poke around to see if your device has some
+special pecularities, you can test some special device
+flags (defined in src/device-flags.h) by inserting them
+together with your device entry in src/music-players.h.
+Flags can be tested in isolation or catenated with "|"
+(binary OR). If relatives to your device use a certain
+flag, chances are high that a new device will need it
+too, typically from the same manufacturer.
+
+The most common flag that needs to be set is the 
+DEVICE_FLAG_UNLOAD_DRIVER that detach any Linux kernel
+drivers that may have attached to the device making
+MTP access impossible. This is however not expected to
+really work: this is a problem being tracked as of
+now (2007-08-04). See the "last resort" solutions below
+if you really need to get your dual-mode device to work 
+with MTP.
+
+Another flag which is easy to identify is the
+DEVICE_FLAG_NO_ZERO_READS, which remedies connection
+timeouts when getting files, and some timeouts on e.g. 
+successive "mtp-connect" calls.
+
+If you are a device vendor, please consider assigning one 
+of your employees as a contact person for libmtp, have them
+sign up to the libmtp development list and answer questions
+and post new device ID:s as they are released to our
+mailing list. By the way: do you have spare devices you
+can give us? Send them to Richard (Mac support) or Linus
+(Linux support). (So far nobody did that except for Microsoft
+who sent us a Zune by proxy!)
+
+If your device is very problematic we are curious of how it
+works under Windows, so we enjoy reading USB packet sniffs
+that reveal the low-level traffic carried out between
+Windows Media Player and your device. This can be done 
+using e.g.:
+
+* USBsnoop:
+  http://benoit.papillault.free.fr/usbsnoop/
+
+* The trial version of HHD Softwares software-only
+  USB monitor. You need to get a copy of version 2.37 since
+  the newer trial versions won't let you carry out the 
+  needed packet sniffs. (As of 2007-03-10 a copy can be found
+  at: http://www.cobbleware.com/files/usb-monitor-237.exe)
+
+There are other USB monitors as well, some more expensive
+alternatives use hardware and even measure electronic
+characteristics of the traffic (which is far too much 
+detail for us).
+
+Device sniffs are an easy read since the PTP/MTP protocol
+is nicely structured. All commands will have a structure such
+as this in the log, we examplify with a object list request:
+
+PTP REQEUST:
+000120: Bulk or Interrupt Transfer (UP), 03.09.2007 12:49:25.9843750 +0.0
+Pipe Handle: 0x863ce234 (Endpoint Address: 0x2)
+Send 0x20 bytes to the device:
+ 20 00 00 00 01 00 05 98 23 00 00 00 27 03 00 10    ......?#...'...
+ Length      TYPE  CMD   Trans#      Param1
+
+ 00 00 00 00 02 DC 00 00 00 00 00 00 00 00 00 00   .....Ü..........
+ Param2      Param3      Param4      Param5
+
+[OPTIONAL] DATA PHASE:
+000121: Bulk or Interrupt Transfer (UP), 03.09.2007 12:49:26.0 +0.0156250
+Pipe Handle: 0x863ce214 (Endpoint Address: 0x81)
+Get 0x1a bytes from the device:
+ 1A 00 00 00 02 00 05 98 23 00 00 00 01 00 00 00   .......?#.......
+ Length      TYPE  CMD   Trans#      DATA
+
+ 27 03 00 10 02 DC 04 00 00 30                     '....Ü...0
+
+RESPONSE:
+000122: Bulk or Interrupt Transfer (UP), 03.09.2007 12:49:26.0 +0.0
+Pipe Handle: 0x863ce214 (Endpoint Address: 0x81)
+Get 0xc bytes from the device:
+ 0C 00 00 00 03 00 01 20 23 00 00 00               ....... #...
+ Length      TYPE  CODE  Trans#
+
+* One send (OUT to the device), two reads (IN from the device).
+
+* All three byte chunks commands are 
+  sent/recieved/recieeved by the function  ptp_transaction() 
+  in the file ptp.c.
+
+* It boils down to ptp_usb_sendreq(), optionally ptp_usb_senddata() 
+  or ptp_usb_getdata() and finally ptp_usb_getresp() in the file 
+  libusb-glue.c. Notice ptp_usb_sendreq() and ptp_usb_getresp()
+  are ALWAYS called. The TYPE field correspond to this, so the
+  TYPES in this case are "COMMAND" (0x0001), "DATA" (0x0002), 
+  and "RESPONSE" (0x0003).
+
+* Notice that the byte order is little endian, so you need to read
+  each field from right to left.
+
+* This COMMAND has:
+  CMD 0x99805, we see in ptp.h that this is PTP_OC_MTP_GetObjPropList.
+  Transaction# 0x00000023.
+  REQUEST parameters 0x10000327, 0x00000000, 0x0000DC02, 0x00000000
+    0x00000000, in this case it means "get props for object 0x10000327",
+    "any format", "property 0xDC02" (PTP_OPC_ObjectFormat), then two
+    parameters that are always zero (no idea what they mean or their
+    use).
+
+* The DATA has:
+  CMD 0x99805, we see in ptp.h that this is PTP_OC_MTP_GetObjPropList.
+  Transaction# 0x00000023.
+  Then comes data 0x00000001, 0x10000327, 0xDC02, 0x0004, 0x3000
+  Which means in this case, (and this is the tricky part) "here
+  you have 1 property", "for object 0x10000327", "it is property
+  0xDC02" (PTP_OPC_ObjectFormat), "which is of type 0x0004"
+  (PTP_DTC_UINT16), "and set to 0x3000" (PTP_OFC_Undefined, it
+  is perfectly valid to have undefined object formats, since it
+  is a legal value defining this).
+
+* This RESPONSE has:
+  CMD 0x99805, we see in ptp.h that this is PTP_OC_MTP_GetObjPropList.
+  Return Code ("RC") = 0x2001, PTP_RC_OK, all went fine.
+  Transaction# 0x00000023.  
+
+If you want to compare the Windows behaviour with a similar
+operation using libmtp you can go into the src/libusb-glue.c 
+file and uncomment the row that reads:
+
+//#define ENABLE_USB_BULK_DEBUG
+
+(I.e. remove the two //.)
+
+This will make libmtp print out a hex dump of every bulk USB
+transaction. The bulk transactions contain all the PTP/MTP layer
+data, which is usually where the problems appear.
+
+
+Dual-mode devices does not work - last resort:
+----------------------------------------------
+
+Some devices that are dual-mode are simply impossible to get
+to work under Linux because the usb-storage(.ko) kernel
+module hook them first, and refuse to release them, even
+when we specify the DEVICE_FLAG_UNLOAD_DRIVER flag. (Maybe
+it DOES release it but the device will immediately be probed
+at the USB mass storage interface AGAIN because it 
+enumerates.)
+
+Here is what some people do:
+
+ 1. Plug in the device.
+ 2. USB-mass storage folder will open automatically.
+ 3. Unmount the device.
+ 4. Run mtp-detect. It will most likely fail the first time.
+ 5. Run mtp-detect again, it might work this time, or fail. Keep running
+    till it works. 99% it works by the third try.
+ 6. Once mtp-detect gives you an "Ok", open either Rhythmbox or Gnomad2,
+    everything should work.
+
+Linux: Try this, if you have a recent 2.6.x Linux kernel,
+run (as root) something like:
+
+> rmmod usb_storage ; mtp-detect
+
+You can run most any command or a client like gnomad2 or
+Amarok immediately after the rmmod command. This works 
+sometimes. Another way:
+
+* Edit /etc/modprobe.d/blacklist
+
+* Add the line "blacklist usb-storage"
+
+* Reboot.
+
+Now none of you USB disks, flash memory sticks etc will be 
+working (you just disabled them all). However you *can* try
+your device, and it might have started working because there
+is no longer a USB mass storage driver that tries to hook onto
+the mass storage interface of your device.
+
+If not even blacklisting works (check with 
+"lsmod | grep usb-storage"), there is some problem with
+something else and you may need to remove or rename the file 
+/lib/modules/<VERSION>/kernel/drivers/usb/storage/usb-storage.ko
+manually.
+
+If you find the PerfectSolution(TM) to this dilemma, so you 
+can properly switch for individual devices whether to use it
+as USB mass storage or not, please tell us how you did it. We
+know we cannot use udev, because udev is called after-the-fact:
+the device is already configured for USB mass storage when
+udev is called.
+
+On Mac OS there is another ugly hack:
+
+1. Open up a terminal window
+2. Type:
+sudo mv /System/Library/Extensions/IOUSBMassStorageClass.kext
+/System/Library/Extensions/IOUSBMassStorageClass.kext.disabled
+
+and when prompted enter your password.
+
+3. Restart.
+
+To reverse this change, just reverse the filenames:
+
+sudo mv /System/Library/Extensions/
+IOUSBMassStorageClass.kext.disabled /System/Library/Extensions/
+IOUSBMassStorageClass.kext
+
+and restart.
+
+
+Calendar and contact support:
+-----------------------------
+
+The Creative Zen series can read VCALENDAR2 (.ics) files
+and VCard (.vcf) files from programs like for example
+Evolution with the following limitations/conditions: 
+
+- The file must be in DOS (CR/LF) format, use the unix2dos
+  program to convert if needed
+
+- Repeat events in calendar files do not seem to be supported, 
+  entries will only appear once.
+
+- Calendar (.ics) files should be stored in the folder "My Organizer" 
+  when sent to the device (this directory should be autodetected
+  for use with calendar files, otherwise use the option 
+  -f "My Organizer" to sendfile for this) Apparently this file can
+  also contain tasklists.
+
+- Contact (.vcf) files should be stored in the folder "My Contacts"
+  when sent to the device. (-f "My Contacts")
+
+- Some devices are picky about the name of the calendar and
+  contact files. For example the Zen Microphoto wants:
+
+  Calendar: My Organizer/6651416.ics
+  Contacts: My Organizer/6651416.vcf
+
+
+Syncing in with Evolution and Creative Devices
+----------------------------------------------
+
+Evolution can easily export .ics an .vcf files, but you currently
+need some command-line hacking to get you stuff copied over in
+one direction host -> device. The examples/ directory contains a script
+created for the Creative Zen Microphoto by Nicolas Tetreault.
+
+
+It's Not Our Bug!
+-----------------
+
+Some MTP devices have strange pecularities. We try to work around
+these whenever we can, sometimes we cannot work around it or we 
+cannot test your solution.
+
+* Generic MTP/PTP disconnect misbehaviour: we have noticed that 
+  Windows Media Player apparently never close the session to an MTP
+  device. There is a daemon in Windows that "hooks" the device
+  by opening a PTP session to any MTP device, whenever it is 
+  plugged in. This daemon proxies any subsequent transactions 
+  to/from the device and will never close the session, thus
+  Windows simply does not close sessions at all.
+
+  Typical sign of this illness: broken pipes on closing sessions,
+  on the main transfer pipes(s) or the interrupt pipe:
+
+    Closing session
+    usb_clear_halt() on INTERRUPT endpoint: Broken pipe
+    OK.
+
+  This means that device manufacturers doesn't notice any problems
+  with devices that do not correctly handle closing PTP/MTP
+  sessions, since Windows never do it. The proper way of closing
+  a session in Windows is to unplug the device, simply put.
+
+  Since libmtp actually tries to close sessions, some devices
+  may fail since the close session functionality has never been
+  properly tested, and "it works with Windows" is sort of the
+  testing criteria at some companies.
+
+  You can get Windows-like behaviour on Linux by running a HAL-aware
+  libmtp GUI client like Rhythmbox or Gnomad2, which will "hook"
+  the device when you plug it in, and "release" it if you unplug
+  it.
+
+  If this bug in your device annoys you, contact your device 
+  manufacturer and ask them to test their product with some libmtp 
+  program.
+
+* Generic USB misbehaviour: some devices behave badly under MTP
+  and USB mass storage alike, even down to the lowest layers
+  of USB. You can always discuss such issues at the linux-usb
+  mailing list if you're using Linux: 
+  http://www.linux-usb.org/mailing.html
+
+  If you have a problem specific to USB mass storage mode, there
+  is a list of strange behaving devices in the Linux kernel:
+  http://lxr.linux.no/linux/drivers/usb/storage/unusual_devs.h
+  You can discuss this too on the mentioned list, for understanding
+  the quirks, see:
+  http://www2.one-eyed-alien.net/~mdharm/linux-usb/target_offenses.txt
+
+* Kernel bug on Linux. Linux 2.6.16 is generally speaking required
+  to use any MTP device under USB 2.0. This is because the EHCI
+  driver previously did not support zero-length writes to endpoints.
+  It should work in most cases however, or if you connect it
+  to an UHCI/OHCI port instead (yielding lower speed). But 
+  please just use a recent kernel.
+
+* Zen models AVI file seeking problem: the Zens cannot parse the
+  files for the runlength metadata. Do not transfer file with e.g.
+  mtp-sendfile, use mtp-sendtr and set the length of the track to
+  the apropriate number of seconds and it will work. In graphical
+  clients, use a "track transfer" function to send these AVI files,
+  the Zens need the metadata associated with tracks to play back
+  movies properly. Movies are considered "tracks" in the MTP world.
+
+* Some devices that disregard the metadata sent with the MTP 
+  commands will parse the files for e.g. ID3 metadata. Some still
+  of these devices expect only ID3v2.3 metadata and will fail with
+  a modern ID3v2,4 tag writer, like many of those found in Linux
+  applications. Windows Media Player use ID3v2.3 only, so many
+  manufacturers only test this version.
+
+* The Zen Vision:M (possibly more Creative Zens) has a firmware bug
+  that makes it drop the last two characters off a playlist name.
+  It is fixed in later firmware.
+
+* For Creative Technology devices, there are hard limits on how
+  many files can be put onto the device. For a 30 GiB device (like
+  the Zen Xtra) the limit is 6000, for a 60 GiB device the limit
+  is 15000 files. For further Creative pecularities, see the
+  FAQ sections at www.nomadness.net.
+
+* Sandisk sansa c150 and probably several other Sandisk devices 
+  (and possibly devices from other manufacturers) have a dual
+  mode with MTP and USB mass storage. The device will initially
+  claim to be mass storage so udev will capture is and make the
+  use of MTP mode impossible. One way of avoiding it could be to
+  be to blacklist the "usb-storage" module in 
+  /etc/modprobe.c/blacklist with a row like this:
+  "blacklist usb-storage". Some have even removed the
+  "usb-storage.ko" (kernel module file) to avoid loading.
+
+* Sandisk Sansa Fuze has three modes: auto, MTP or mass storage
+  (MSC). Please set it to MTP to avoid problems with libmtp.
+
+* The iriver devices (possibly all of them) cannot handle the 
+  enhanced GetObjectPropList MTP command (0x9805) properly. So 
+  they have been banned from using it.
+
+* iriver devices have problems with older versions of libmtp and
+  with new devices libmtp does not know of as of yet, since it
+  has an oldstyle USB device controller that cannot handle zero
+  writes. (Register your device with us!) All their devices are
+  likely to need a special device flag in the src/libusb-glue.c
+  database.
+
+* The Samsung Yepp T9 has several strange characteristics, some
+  that we've managed to work around. (For example it will return
+  multiple PTP packages in a single transaction.)
+
+* The early firmware for Philips HDD players is known to be 
+  problematic. Please upgrade to as new firmware as you can get.
+  (Yes this requires some kind of Windows Installation I think.)
+
+* Philips HDD 1630/16 or 1630/17 etc may lock themselves up,
+  turning inresponsive due to internal corruption. This typically
+  gives an error in opening the PTP session. Apparently you can
+  do a "repair" with the firmware utility (Windows only) which
+  will often fix this problem and make the device responsive
+  again.
+
+* Some devices that implement GetObjectPropList (0x9805) will
+  not return the entire object list if you request a list for object
+  0xffffffffu. (But they should.) So they may need the special
+  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL.
+
+* Some (smaller) subset of devices cannot even get all the 
+  properties for a single object in one go, these need the
+  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST. Currently only the
+  iriver devices seem to have this bug.
+
+* The Toshiba Gigabeat S (and probably its sibling the 
+  Microsoft Zune and other Toshiba devices) will only display
+  album information tags for a song in case there is also
+  an abstract album (created with the album interface) with
+  the exact same name.
+
+* The Zen Vision:M has an older firmware which is very corrupt,
+  it is incompatible with the Linux USB stack altogether. The
+  kernel dmesg will look something like this, and you have to
+  upgrade the firmware using Windows:
+  usb 4-5: new high speed USB device using ehci_hcd and address 5
+  usb 4-5: configuration #1 chosen from 1 choice
+  usb 4-5: can't set config #1, error -110
+
+* The Sirus Stiletto does not seem to allow you to copy any files
+  off the device. This may be someone's idea of copy protection.
+
+* The Samsung P2 assigns parent folder ID 0 to all unknown file
+  types.(i.e. moves them to the root folder) 
+
+Lost symbols
+------------
+
+Shared libraries can be troublesome to users not experienced with
+them. The following is a condensed version of a generic question 
+that has appeared on the libmtp mailing list from time to time.
+
+> PTP: Opening session
+> Queried Creative Zen Vision:M
+> gnomad2: relocation error: gnomad2: undefined symbol:
+> LIBMTP_Get_Storageinfo
+> (...)
+> Are these type of errors related to libmtp or something else?
+
+The problem is of a generic nature, and related to dynamic library 
+loading. It is colloquially known as "dependency hell".
+(http://en.wikipedia.org/wiki/Dependency_hell)
+
+The gnomad2 application calls upon the dynamic linker in Linux to
+resolve the symbol "LIBMTP_Get_Storageinfo" or any other symbol
+(ELF symbol, or link point or whatever you want to call them, a
+symbol is a label on a memory address that the linker shall 
+resolve from label to actual address.)
+For generic information on this subject see the INSTALL file and
+this Wikipedia page:
+
+http://en.wikipedia.org/wiki/Library_(computing)
+
+When Linux /lib/ld-linux.so.X is called to link the symbols compiled 
+into gnomad2 (or any other executable using libmtp), it examines the 
+ELF file for the libmtp.so.X file it finds first and cannot resolve 
+the symbol "LIBMTP_Get_Storageinfo" (or whichever symbol you have a
+problem witj) from it, since it's probably not there. There are many 
+possible causes of this symbol breakage:
+
+1) You installed precompiled libmtp and gnomad2 packages (RPMs, debs
+    whatever) that do not match up. Typical cause: your gnomad2 package was
+    built against a newer version of libmtp than what's installed on your
+    machine. Another typical cause: you installed a package you found on
+    the web, somewhere, the dependency resolution system did not protest
+    properly (as it should) or you forced it to install anyway, ignoring
+    some warnings.
+
+2) You compiled libmtp and/or gnomad2 from source, installing both or
+    either in /usr/local/lib and /usr/local/bin. This means at compile-time
+    gnomad2 finds the libmtp library in /usr/local/lib but at runtime, it
+    depends on the Linux system wide library loader (/lib/ld-linux.so.X) in
+    order to resolve the symbols. This loader will look into the file
+    /etc/ld.so.conf and/or the folder /etc/ld.so.conf.d in order to find
+    paths to libraries to be used for resolving the symbols. If you have
+    some older version of libmtp in e.g. /usr/lib (typically installed by a
+    package manager) it will take precedence over the new version you just
+    installed in /usr/local/lib and the newly compiled library in
+    /usr/local/lib will *not* be used, resulting in this error message.
+
+3) You really did install the very latest versions (as of writing libmtp
+    0.1.5 and gnomad2 2.8.11) from source and there really is no
+    pre-installed package of either on your machine. In that case I'm
+    totally lost, I have no idea what's causing this.
+
+Typical remedies:
+
+1) If you don't want to mess around with your system and risk these
+    situations, only use pre-packaged software that came with the
+    distribution or its official support channels. If it still breaks,
+    blame your distribution, they're not packaging correctly. Relying on
+    properly packaged software and not installing things yourself *is* the
+    Linux solution to the "dependency hell" problem.
+
+2) Read about dynamically linked library handling until the stuff I wrote
+    about in the previous list sounds like music to your ears, inspect
+    your /lib, /usr/lib, /usr/local/lib, /etc/ld.so.conf and the
+    /etc/ld.so.conf.d, remove all pre-packed versions using RPM, APT,
+    YaST or whatever your distribution uses, compile libmtp and gnomad2
+    (or whatever) from source only and you will be enlighted.
+
+I don't know if this helps you, it's the best answer we can give.
+
+
+API is obscure - I want plain files!
+------------------------------------
+
+PTP/MTP devices does not actually contain "files", they contain
+objects. These objects have file names, but that is actually
+just a name tag on the object.
+
+Folders/directories aren't really such entities: they are just 
+objects too, albeit objects that can act as parent to other
+objects. They are called "associations" and are created in atomic
+fashion and even though there is an MTP command to get all the
+associations of a certain association, this command is optional
+so it is perfectly possible (and most common, actually) to create
+devices where the "folders" (which are actually associations) have
+no idea whatsoever of what files they are associated as parents to 
+(i.e. which files they contain). This is very easy for device
+manufacturers to implement, all the association (i.e. finding out
+which files are in a certain folder) has to be done by the MTP
+Initiator / host computer.
+
+Moving a file to a new folder is for example very simple in a
+"real" file system. In PTP/MTP devices it is often not even possible,
+some devices *may* be able to do that. But actually the only
+reliable way of doing that is to upload the file to the host,
+download it with the new parent, then delete the old file.
+We have played with the idea of implementing this time consuming
+function, perhaps we will.
+
+Then the issue that in PTP/MTP it is legal for two files to have
+exactly the same path as long as their object IDs differ. A
+folder/association can contain two files with the exact same name.
+(And on the Creative devices this even works, too, though most devices
+implicitly fail at this.) Perhaps one could add some custom hook for
+handling that, so they become  /Foo.mp3 and /Foo.mp3(1) or something
+similar, but it's really a bit kludgy.
+
+Playlists and albums aren't really files, thinking about 
+them as files like the hacks in libgphoto2 is really backwards. They are
+called associations and are more like a symbolic link that links in a
+star-shaped pattern to all the files that are part of the album/playlist.
+Some devices (Samsung) thought that was too complicated and have a
+different way of storing playlists in an UTF-16 encoded .spl-like file
+instead! This is why playlists/albums must have their own structs and 
+functions.
+
+Plain file access also assumes to be able to write files of an
+undetermined size, which is simply not possible in a transactional
+file system like PTP/MTP. (See further below.)
+
+
+I Want Streaming!
+-----------------
+
+Streaming reads is easy. Just connect the output file descriptor from
+LIBMTP_Get_File_To_File_Descriptor() (and a similar function for tracks)
+wherever you want.
+
+People have connected this to TCP sockets for streaming web servers 
+etc, works like a charm. Some devices will even survive if the callback 
+functions return non-zero and cancel the download. Some devices will
+lock up and even require a reset if you do that. Devices are poorly
+implemented so that's life. If you want to stream off a device, the
+best idea is always to stream the entire file and discard the stuff
+at the end you don't want. It will incur a delay if you e.g. want to
+skip between tracks, sadly.
+
+Then we get to the complicated things: streaming WRITES...
+
+There is a function:
+LIBMTP_Send_File_From_File_Descriptor() (and similar for tracks)
+which will write a file to a device from a file descriptor, which may
+be a socket or whatever.
+
+HOWEVER: this requires a piece of metadata with the .filesize properly
+set first.
+
+This is not because we think it is funny to require that, the protocol
+requires it. The reason is that PTP/MTP is a transactional file system
+and it wants to be able to deny file transfer if the file won't fit on
+the device, so the transaction never even starts, it's impossible to
+start a transaction without giving file length.
+
+People really want streaming so I tried a lot of hacks to see if they
+would work, such as setting file size to 0xffffffffU or something other
+unnaturally big and then aborting the file transfer when the stream ends.
+It doesn't work: either the device crashes or the file simply disappears
+since the device rolls back all failed transactions.
+
+So this is an inherent limitation of the PTP/MTP protocol.
diff --git a/README.windows.txt b/README.windows.txt
new file mode 100644
index 0000000..d360806
--- /dev/null
+++ b/README.windows.txt
@@ -0,0 +1,54 @@
+This file was created by James Ravenscroft <ravenscroftj@gmail.com> as a direct revision of Farooq Zaman's work with LibMTP on Windows.

+

+ CHANGELOG

+----------------

+14th January 2009: Created the first revision of this file taking information from the work of Farooq Zaman.

+

+ 1.0 Compilation of LibMTP on Windows 2000/XP/NT 

+-----------------------------------------------------------

+LibMTP currently compiles under Windows using MingW/MSys. The source relies upon the __WIN32__ macro which is defined by MinGW by default.

+

+Libraries:

+LibMTP currently depends on LibUSB and libiconv. There are currently projects that port both of these libraries to Windows. Binary files can be

+obtained from:

+

+LibUSB Win32 - http://libusb-win32.sourceforge.net/

+

+LibIconv - http://gnuwin32.sourceforge.net/packages/libiconv.htm

+

+With both of these libraries extracted and placed in MinGW's search path, you can compile the library by opening the Msys prompt, navigating to

+the path where the extracted LibMTP source files can be found and typing:

+

+./configure

+make all

+make install

+

+

+

+ 2.0 LibUSB and Driver Issues for Windows

+----------------------------------------------

+

+Unfortunately, Windows does not have abstract USB support and depends upon specific drivers for each and every device you use. Fortunately, 

+LibUSB-Win32 provide a solution to this problem. LibMTP takes advantage of the LibUSB-Win32 Device Driver package.

+

+1. Download the latest device driver binary package (libusb-win32-device-bin-x.x.x.x.tar.gz) from http://sourceforge.net/project/showfiles.php?group_id=78138

+2. Upon extraction, plug in your music device and run bin/inf-wizard.exe. Selecting your device and saving the inf file in the project root directory.

+3. Copy the files "bin/libusb0.dll" and "libusb0.sys" or "libusb0_x64.dll" and "libusb0_x64.sys" for 32-bit or 64-bit operating systems respectively.

+4. Goto Start -> Run, type "devmgmt.msc" and press "ok".

+5. Select your music device from the list and click Action -> Update Driver, Choose "No, not this time" if prompted to connect to microsoft.

+6. Choose "Install from a list or specific location".

+7.  Choose "Don't search, I will choose the driver to install

+8. Click the "Have Disk..." button in the bottom right corner of the prompt

+9. Browse to your .inf file and select it. Press Ok 

+10. The name of your music device should appear in the prompt, click it and click "Next>" (Ignore any prompts about Driver Signing, continuing 

+installation of the selected driver).

+11. Click finish to end the driver install process.

+

+To get your old driver back:

+

+1. Goto Start -> Run, type "devmgmt.msc" and press "ok".

+2. Select your music device, right click on it and click "Properties"

+3. Go to the "Driver" pane and select "Roll Back Driver".

+

+ 3.0 

+----------------------------------------------

diff --git a/TODO b/TODO
new file mode 100644
index 0000000..74ad560
--- /dev/null
+++ b/TODO
@@ -0,0 +1,106 @@
+TODO file:
+----------
+
+COMPATIBILITY fixes:
+
+1. COMPATIBILITY: dual-mode devices, i.e. devices exposing both an MTP
+  and a USB Mass Storage Device Class (flashdrive) interface are and
+  have always been problematic. We must find a way to get this to work,
+  eventually. The problem is that the in-kernel mass storage driver hogs
+  the device before the MTP mode gets a chance of being used, whereas
+  the Windows kernel driver apparently does it the other way around, 
+  trying the MTP mode first and then not fall back on mass storage if
+  MTP is available. (For some more explanations se src/libusb-glue.h.)
+  This may involve kernel modifications. Perhaps it is only necessary
+  to tweak the udev config not to load USB mass storage support for
+  these devices. Dunno.
+
+2. COMPATIBILITY: several devices tend to "hang" after disconnect, 
+  needing to be unplugged and replugged before they can be used again. 
+  We don't know why, it may be related to low-level USB behaviour that
+  is not exposed in the logs we read. On some devices it appear that
+  avoiding to release the USB interface after closing the PTP/MTP 
+  session solves this, and might be a hint at how the Windows MTP stack
+  works: perhaps the Windows MTP daemon grabs the interface once the
+  device is plugged in, created a session and NEVER release it.
+  Thus only unplug or shutdown ends the session. This behaviour can be
+  emulated (sort of) by DEVICE_FLAG_NO_RELEASE_INTERFACE which will
+  make the device not release the USB low-level interface, though it'll
+  still close the session. But is it really desireable to have
+  as default? Not unless we run an MTP daemon as well, probably, and
+  the behaviour is questionable from an USB interoperability point
+  of view.
+
+
+SPEEDUP fixes:
+
+  None known. libmtp is fast :-)
+
+
+FEATURE fixes:
+
+1. FEATURE: Support playback and volume setting on devices that have it.
+  (I don't have one that does - Linus.)
+
+2. FEATURE: Support relevant events. MTP devices seen in existance provide
+  events for "object added" and "object deleted". These should result in
+  atleast a call to the cache update function.
+
+3. FEATURE: Mechanism to retrieve the device icon device property, else if not
+  present, look for DevIcon.fil (Windows ICO format) and 
+  DevLogo.fil (PNG Format) images from the device (if available).
+
+4. FEATURE: Shared device access so that multiple client applications can have
+  an open connection to the device at the same time via a handle. For example,
+  it should be somehow possible to run mtp-detect at the same time as amarok or 
+  mtpfs is connected to a device. This would require some form of resource
+  sharing.
+
+5. FEATURE: Implement an OpenSync backend for devices which have
+  calendaring, contact etc support. http://opensync.org/
+
+
+THOSE ARE ALREADY DONE:
+
+1. FEATURE: Make an API that can return several devices and let the user 
+  choose which one to operate, not just connect to the first one...
+
+2. SPEED: Cache the object info for all items on the device.
+  Right now, ptp_getobjectinfo() is called repeatedly on the same
+  objects during startup, track listing, file listing, playlist listing,
+  album listing and whatever we implement tomorrow. A lot of useless
+  communication can be saved by cacheing this info. Notice that this
+  needs to be updated whenever flush_handles() is called too.
+  (This came from libgphoto2 implementing it!)
+
+3. SPEED: Cache track metadata, file metadata etc in params->proplist.
+
+4. SPEED: Whenever we add an object (file, track, playlist...) we
+  should only need to update the cache with relevant data. Atleast for
+  speedup caches.
+
+5. COMPATIBILITY: account for different step sizes and intervals on some
+  numeric properties we set, make the functions round off when possible.
+
+6. SPEED: Cache the supported object properties at first read/startup.
+  then use the cache to check for supported props instead of calling
+  out to PTP with ptp_mtp_getobjectpropssupported() every time.
+  The cache would be an array of size params->deviceinfo.ImageFormats_len
+  with a list for each format of the properties it will support. Notice 
+  that this needs to be updated whenever flush_handles() is called too.
+  THIS HAS BEEN DISCARDED, TERO IMPLEMENTED IT BUT IT DOESN'T SEEM TO 
+  YIELD MUCH.
+
+7. FEATURE: Make abstract playlists really become size -1 when created as 
+  the ones created on the device instead of the current 1 byte size.
+  (Is this possible using enhanced commands? See TODO remarks in
+  the create_abstract_entity() function)
+
+8. FEATURE: Integrate libmtp with HAL / D-Bus so applications can dynamically
+  know when a device has been plugged in or removed. Need a mechanism to 
+  connect a specific hal UDI.
+
+9. SPEEDUP: The recursive function that builds the folder tree is
+  O(n^2)! Atleast remove all non-folders (PTP associations) from the
+  list before we start sorting and building that tree. We walk the
+  entire list for each group of siblings right now!
diff --git a/aclocal.m4 b/aclocal.m4
new file mode 100644
index 0000000..225c014
--- /dev/null
+++ b/aclocal.m4
@@ -0,0 +1,2158 @@
+# generated automatically by aclocal 1.11 -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+# 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+m4_ifndef([AC_AUTOCONF_VERSION],
+  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
+m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.63],,
+[m4_warning([this file was generated for autoconf 2.63.
+You have another version of autoconf.  It may work, but is not guaranteed to.
+If you have problems, you may need to regenerate the build system entirely.
+To do so, use the procedure documented by the package, typically `autoreconf'.])])
+
+# iconv.m4 serial AM6 (gettext-0.17)
+dnl Copyright (C) 2000-2002, 2007 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
+[
+  dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
+  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+  AC_REQUIRE([AC_LIB_RPATH])
+
+  dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
+  dnl accordingly.
+  AC_LIB_LINKFLAGS_BODY([iconv])
+])
+
+AC_DEFUN([AM_ICONV_LINK],
+[
+  dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
+  dnl those with the standalone portable GNU libiconv installed).
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+
+  dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
+  dnl accordingly.
+  AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
+
+  dnl Add $INCICONV to CPPFLAGS before performing the following checks,
+  dnl because if the user has installed libiconv and not disabled its use
+  dnl via --without-libiconv-prefix, he wants to use it. The first
+  dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
+  am_save_CPPFLAGS="$CPPFLAGS"
+  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
+
+  AC_CACHE_CHECK([for iconv], am_cv_func_iconv, [
+    am_cv_func_iconv="no, consider installing GNU libiconv"
+    am_cv_lib_iconv=no
+    AC_TRY_LINK([#include <stdlib.h>
+#include <iconv.h>],
+      [iconv_t cd = iconv_open("","");
+       iconv(cd,NULL,NULL,NULL,NULL);
+       iconv_close(cd);],
+      am_cv_func_iconv=yes)
+    if test "$am_cv_func_iconv" != yes; then
+      am_save_LIBS="$LIBS"
+      LIBS="$LIBS $LIBICONV"
+      AC_TRY_LINK([#include <stdlib.h>
+#include <iconv.h>],
+        [iconv_t cd = iconv_open("","");
+         iconv(cd,NULL,NULL,NULL,NULL);
+         iconv_close(cd);],
+        am_cv_lib_iconv=yes
+        am_cv_func_iconv=yes)
+      LIBS="$am_save_LIBS"
+    fi
+  ])
+  if test "$am_cv_func_iconv" = yes; then
+    AC_CACHE_CHECK([for working iconv], am_cv_func_iconv_works, [
+      dnl This tests against bugs in AIX 5.1 and HP-UX 11.11.
+      am_save_LIBS="$LIBS"
+      if test $am_cv_lib_iconv = yes; then
+        LIBS="$LIBS $LIBICONV"
+      fi
+      AC_TRY_RUN([
+#include <iconv.h>
+#include <string.h>
+int main ()
+{
+  /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
+     returns.  */
+  {
+    iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
+    if (cd_utf8_to_88591 != (iconv_t)(-1))
+      {
+        static const char input[] = "\342\202\254"; /* EURO SIGN */
+        char buf[10];
+        const char *inptr = input;
+        size_t inbytesleft = strlen (input);
+        char *outptr = buf;
+        size_t outbytesleft = sizeof (buf);
+        size_t res = iconv (cd_utf8_to_88591,
+                            (char **) &inptr, &inbytesleft,
+                            &outptr, &outbytesleft);
+        if (res == 0)
+          return 1;
+      }
+  }
+#if 0 /* This bug could be worked around by the caller.  */
+  /* Test against HP-UX 11.11 bug: Positive return value instead of 0.  */
+  {
+    iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
+    if (cd_88591_to_utf8 != (iconv_t)(-1))
+      {
+        static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
+        char buf[50];
+        const char *inptr = input;
+        size_t inbytesleft = strlen (input);
+        char *outptr = buf;
+        size_t outbytesleft = sizeof (buf);
+        size_t res = iconv (cd_88591_to_utf8,
+                            (char **) &inptr, &inbytesleft,
+                            &outptr, &outbytesleft);
+        if ((int)res > 0)
+          return 1;
+      }
+  }
+#endif
+  /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
+     provided.  */
+  if (/* Try standardized names.  */
+      iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
+      /* Try IRIX, OSF/1 names.  */
+      && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
+      /* Try AIX names.  */
+      && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
+      /* Try HP-UX names.  */
+      && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
+    return 1;
+  return 0;
+}], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no],
+        [case "$host_os" in
+           aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
+           *)            am_cv_func_iconv_works="guessing yes" ;;
+         esac])
+      LIBS="$am_save_LIBS"
+    ])
+    case "$am_cv_func_iconv_works" in
+      *no) am_func_iconv=no am_cv_lib_iconv=no ;;
+      *)   am_func_iconv=yes ;;
+    esac
+  else
+    am_func_iconv=no am_cv_lib_iconv=no
+  fi
+  if test "$am_func_iconv" = yes; then
+    AC_DEFINE(HAVE_ICONV, 1,
+      [Define if you have the iconv() function and it works.])
+  fi
+  if test "$am_cv_lib_iconv" = yes; then
+    AC_MSG_CHECKING([how to link with libiconv])
+    AC_MSG_RESULT([$LIBICONV])
+  else
+    dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
+    dnl either.
+    CPPFLAGS="$am_save_CPPFLAGS"
+    LIBICONV=
+    LTLIBICONV=
+  fi
+  AC_SUBST(LIBICONV)
+  AC_SUBST(LTLIBICONV)
+])
+
+AC_DEFUN([AM_ICONV],
+[
+  AM_ICONV_LINK
+  if test "$am_cv_func_iconv" = yes; then
+    AC_MSG_CHECKING([for iconv declaration])
+    AC_CACHE_VAL(am_cv_proto_iconv, [
+      AC_TRY_COMPILE([
+#include <stdlib.h>
+#include <iconv.h>
+extern
+#ifdef __cplusplus
+"C"
+#endif
+#if defined(__STDC__) || defined(__cplusplus)
+size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
+#else
+size_t iconv();
+#endif
+], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
+      am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
+    am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
+    AC_MSG_RESULT([$]{ac_t:-
+         }[$]am_cv_proto_iconv)
+    AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
+      [Define as const if the declaration of iconv() needs const.])
+  fi
+])
+
+# lib-ld.m4 serial 3 (gettext-0.13)
+dnl Copyright (C) 1996-2003 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Subroutines of libtool.m4,
+dnl with replacements s/AC_/AC_LIB/ and s/lt_cv/acl_cv/ to avoid collision
+dnl with libtool.m4.
+
+dnl From libtool-1.4. Sets the variable with_gnu_ld to yes or no.
+AC_DEFUN([AC_LIB_PROG_LD_GNU],
+[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], acl_cv_prog_gnu_ld,
+[# I'd rather use --version here, but apparently some GNU ld's only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  acl_cv_prog_gnu_ld=yes ;;
+*)
+  acl_cv_prog_gnu_ld=no ;;
+esac])
+with_gnu_ld=$acl_cv_prog_gnu_ld
+])
+
+dnl From libtool-1.4. Sets the variable LD.
+AC_DEFUN([AC_LIB_PROG_LD],
+[AC_ARG_WITH(gnu-ld,
+[  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]],
+test "$withval" = no || with_gnu_ld=yes, with_gnu_ld=no)
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
+# Prepare PATH_SEPARATOR.
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  AC_MSG_CHECKING([for ld used by GCC])
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [[\\/]* | [A-Za-z]:[\\/]*)]
+      [re_direlt='/[^/][^/]*/\.\./']
+      # Canonicalize the path of ld
+      ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'`
+      while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
+	ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  AC_MSG_CHECKING([for GNU ld])
+else
+  AC_MSG_CHECKING([for non-GNU ld])
+fi
+AC_CACHE_VAL(acl_cv_path_LD,
+[if test -z "$LD"; then
+  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}"
+  for ac_dir in $PATH; do
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      acl_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some GNU ld's only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$acl_cv_path_LD" -v 2>&1 < /dev/null` in
+      *GNU* | *'with BFD'*)
+	test "$with_gnu_ld" != no && break ;;
+      *)
+	test "$with_gnu_ld" != yes && break ;;
+      esac
+    fi
+  done
+  IFS="$ac_save_ifs"
+else
+  acl_cv_path_LD="$LD" # Let the user override the test with a path.
+fi])
+LD="$acl_cv_path_LD"
+if test -n "$LD"; then
+  AC_MSG_RESULT($LD)
+else
+  AC_MSG_RESULT(no)
+fi
+test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
+AC_LIB_PROG_LD_GNU
+])
+
+# lib-link.m4 serial 13 (gettext-0.17)
+dnl Copyright (C) 2001-2007 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+AC_PREREQ(2.54)
+
+dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
+dnl the libraries corresponding to explicit and implicit dependencies.
+dnl Sets and AC_SUBSTs the LIB${NAME} and LTLIB${NAME} variables and
+dnl augments the CPPFLAGS variable.
+dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
+dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
+AC_DEFUN([AC_LIB_LINKFLAGS],
+[
+  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+  AC_REQUIRE([AC_LIB_RPATH])
+  define([Name],[translit([$1],[./-], [___])])
+  define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
+                               [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
+  AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [
+    AC_LIB_LINKFLAGS_BODY([$1], [$2])
+    ac_cv_lib[]Name[]_libs="$LIB[]NAME"
+    ac_cv_lib[]Name[]_ltlibs="$LTLIB[]NAME"
+    ac_cv_lib[]Name[]_cppflags="$INC[]NAME"
+    ac_cv_lib[]Name[]_prefix="$LIB[]NAME[]_PREFIX"
+  ])
+  LIB[]NAME="$ac_cv_lib[]Name[]_libs"
+  LTLIB[]NAME="$ac_cv_lib[]Name[]_ltlibs"
+  INC[]NAME="$ac_cv_lib[]Name[]_cppflags"
+  LIB[]NAME[]_PREFIX="$ac_cv_lib[]Name[]_prefix"
+  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
+  AC_SUBST([LIB]NAME)
+  AC_SUBST([LTLIB]NAME)
+  AC_SUBST([LIB]NAME[_PREFIX])
+  dnl Also set HAVE_LIB[]NAME so that AC_LIB_HAVE_LINKFLAGS can reuse the
+  dnl results of this search when this library appears as a dependency.
+  HAVE_LIB[]NAME=yes
+  undefine([Name])
+  undefine([NAME])
+])
+
+dnl AC_LIB_HAVE_LINKFLAGS(name, dependencies, includes, testcode)
+dnl searches for libname and the libraries corresponding to explicit and
+dnl implicit dependencies, together with the specified include files and
+dnl the ability to compile and link the specified testcode. If found, it
+dnl sets and AC_SUBSTs HAVE_LIB${NAME}=yes and the LIB${NAME} and
+dnl LTLIB${NAME} variables and augments the CPPFLAGS variable, and
+dnl #defines HAVE_LIB${NAME} to 1. Otherwise, it sets and AC_SUBSTs
+dnl HAVE_LIB${NAME}=no and LIB${NAME} and LTLIB${NAME} to empty.
+dnl Sets and AC_SUBSTs the LIB${NAME}_PREFIX variable to nonempty if libname
+dnl was found in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
+AC_DEFUN([AC_LIB_HAVE_LINKFLAGS],
+[
+  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+  AC_REQUIRE([AC_LIB_RPATH])
+  define([Name],[translit([$1],[./-], [___])])
+  define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
+                               [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
+
+  dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME
+  dnl accordingly.
+  AC_LIB_LINKFLAGS_BODY([$1], [$2])
+
+  dnl Add $INC[]NAME to CPPFLAGS before performing the following checks,
+  dnl because if the user has installed lib[]Name and not disabled its use
+  dnl via --without-lib[]Name-prefix, he wants to use it.
+  ac_save_CPPFLAGS="$CPPFLAGS"
+  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INC]NAME)
+
+  AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [
+    ac_save_LIBS="$LIBS"
+    LIBS="$LIBS $LIB[]NAME"
+    AC_TRY_LINK([$3], [$4], [ac_cv_lib[]Name=yes], [ac_cv_lib[]Name=no])
+    LIBS="$ac_save_LIBS"
+  ])
+  if test "$ac_cv_lib[]Name" = yes; then
+    HAVE_LIB[]NAME=yes
+    AC_DEFINE([HAVE_LIB]NAME, 1, [Define if you have the $1 library.])
+    AC_MSG_CHECKING([how to link with lib[]$1])
+    AC_MSG_RESULT([$LIB[]NAME])
+  else
+    HAVE_LIB[]NAME=no
+    dnl If $LIB[]NAME didn't lead to a usable library, we don't need
+    dnl $INC[]NAME either.
+    CPPFLAGS="$ac_save_CPPFLAGS"
+    LIB[]NAME=
+    LTLIB[]NAME=
+    LIB[]NAME[]_PREFIX=
+  fi
+  AC_SUBST([HAVE_LIB]NAME)
+  AC_SUBST([LIB]NAME)
+  AC_SUBST([LTLIB]NAME)
+  AC_SUBST([LIB]NAME[_PREFIX])
+  undefine([Name])
+  undefine([NAME])
+])
+
+dnl Determine the platform dependent parameters needed to use rpath:
+dnl   acl_libext,
+dnl   acl_shlibext,
+dnl   acl_hardcode_libdir_flag_spec,
+dnl   acl_hardcode_libdir_separator,
+dnl   acl_hardcode_direct,
+dnl   acl_hardcode_minus_L.
+AC_DEFUN([AC_LIB_RPATH],
+[
+  dnl Tell automake >= 1.10 to complain if config.rpath is missing.
+  m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])])
+  AC_REQUIRE([AC_PROG_CC])                dnl we use $CC, $GCC, $LDFLAGS
+  AC_REQUIRE([AC_LIB_PROG_LD])            dnl we use $LD, $with_gnu_ld
+  AC_REQUIRE([AC_CANONICAL_HOST])         dnl we use $host
+  AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) dnl we use $ac_aux_dir
+  AC_CACHE_CHECK([for shared library run path origin], acl_cv_rpath, [
+    CC="$CC" GCC="$GCC" LDFLAGS="$LDFLAGS" LD="$LD" with_gnu_ld="$with_gnu_ld" \
+    ${CONFIG_SHELL-/bin/sh} "$ac_aux_dir/config.rpath" "$host" > conftest.sh
+    . ./conftest.sh
+    rm -f ./conftest.sh
+    acl_cv_rpath=done
+  ])
+  wl="$acl_cv_wl"
+  acl_libext="$acl_cv_libext"
+  acl_shlibext="$acl_cv_shlibext"
+  acl_libname_spec="$acl_cv_libname_spec"
+  acl_library_names_spec="$acl_cv_library_names_spec"
+  acl_hardcode_libdir_flag_spec="$acl_cv_hardcode_libdir_flag_spec"
+  acl_hardcode_libdir_separator="$acl_cv_hardcode_libdir_separator"
+  acl_hardcode_direct="$acl_cv_hardcode_direct"
+  acl_hardcode_minus_L="$acl_cv_hardcode_minus_L"
+  dnl Determine whether the user wants rpath handling at all.
+  AC_ARG_ENABLE(rpath,
+    [  --disable-rpath         do not hardcode runtime library paths],
+    :, enable_rpath=yes)
+])
+
+dnl AC_LIB_LINKFLAGS_BODY(name [, dependencies]) searches for libname and
+dnl the libraries corresponding to explicit and implicit dependencies.
+dnl Sets the LIB${NAME}, LTLIB${NAME} and INC${NAME} variables.
+dnl Also, sets the LIB${NAME}_PREFIX variable to nonempty if libname was found
+dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem.
+AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
+[
+  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
+  define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
+                               [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
+  dnl Autoconf >= 2.61 supports dots in --with options.
+  define([N_A_M_E],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[translit([$1],[.],[_])],[$1])])
+  dnl By default, look in $includedir and $libdir.
+  use_additional=yes
+  AC_LIB_WITH_FINAL_PREFIX([
+    eval additional_includedir=\"$includedir\"
+    eval additional_libdir=\"$libdir\"
+  ])
+  AC_LIB_ARG_WITH([lib]N_A_M_E[-prefix],
+[  --with-lib]N_A_M_E[-prefix[=DIR]  search for lib$1 in DIR/include and DIR/lib
+  --without-lib]N_A_M_E[-prefix     don't search for lib$1 in includedir and libdir],
+[
+    if test "X$withval" = "Xno"; then
+      use_additional=no
+    else
+      if test "X$withval" = "X"; then
+        AC_LIB_WITH_FINAL_PREFIX([
+          eval additional_includedir=\"$includedir\"
+          eval additional_libdir=\"$libdir\"
+        ])
+      else
+        additional_includedir="$withval/include"
+        additional_libdir="$withval/$acl_libdirstem"
+      fi
+    fi
+])
+  dnl Search the library and its dependencies in $additional_libdir and
+  dnl $LDFLAGS. Using breadth-first-seach.
+  LIB[]NAME=
+  LTLIB[]NAME=
+  INC[]NAME=
+  LIB[]NAME[]_PREFIX=
+  rpathdirs=
+  ltrpathdirs=
+  names_already_handled=
+  names_next_round='$1 $2'
+  while test -n "$names_next_round"; do
+    names_this_round="$names_next_round"
+    names_next_round=
+    for name in $names_this_round; do
+      already_handled=
+      for n in $names_already_handled; do
+        if test "$n" = "$name"; then
+          already_handled=yes
+          break
+        fi
+      done
+      if test -z "$already_handled"; then
+        names_already_handled="$names_already_handled $name"
+        dnl See if it was already located by an earlier AC_LIB_LINKFLAGS
+        dnl or AC_LIB_HAVE_LINKFLAGS call.
+        uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
+        eval value=\"\$HAVE_LIB$uppername\"
+        if test -n "$value"; then
+          if test "$value" = yes; then
+            eval value=\"\$LIB$uppername\"
+            test -z "$value" || LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$value"
+            eval value=\"\$LTLIB$uppername\"
+            test -z "$value" || LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$value"
+          else
+            dnl An earlier call to AC_LIB_HAVE_LINKFLAGS has determined
+            dnl that this library doesn't exist. So just drop it.
+            :
+          fi
+        else
+          dnl Search the library lib$name in $additional_libdir and $LDFLAGS
+          dnl and the already constructed $LIBNAME/$LTLIBNAME.
+          found_dir=
+          found_la=
+          found_so=
+          found_a=
+          eval libname=\"$acl_libname_spec\"    # typically: libname=lib$name
+          if test -n "$acl_shlibext"; then
+            shrext=".$acl_shlibext"             # typically: shrext=.so
+          else
+            shrext=
+          fi
+          if test $use_additional = yes; then
+            dir="$additional_libdir"
+            dnl The same code as in the loop below:
+            dnl First look for a shared library.
+            if test -n "$acl_shlibext"; then
+              if test -f "$dir/$libname$shrext"; then
+                found_dir="$dir"
+                found_so="$dir/$libname$shrext"
+              else
+                if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
+                  ver=`(cd "$dir" && \
+                        for f in "$libname$shrext".*; do echo "$f"; done \
+                        | sed -e "s,^$libname$shrext\\\\.,," \
+                        | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
+                        | sed 1q ) 2>/dev/null`
+                  if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
+                    found_dir="$dir"
+                    found_so="$dir/$libname$shrext.$ver"
+                  fi
+                else
+                  eval library_names=\"$acl_library_names_spec\"
+                  for f in $library_names; do
+                    if test -f "$dir/$f"; then
+                      found_dir="$dir"
+                      found_so="$dir/$f"
+                      break
+                    fi
+                  done
+                fi
+              fi
+            fi
+            dnl Then look for a static library.
+            if test "X$found_dir" = "X"; then
+              if test -f "$dir/$libname.$acl_libext"; then
+                found_dir="$dir"
+                found_a="$dir/$libname.$acl_libext"
+              fi
+            fi
+            if test "X$found_dir" != "X"; then
+              if test -f "$dir/$libname.la"; then
+                found_la="$dir/$libname.la"
+              fi
+            fi
+          fi
+          if test "X$found_dir" = "X"; then
+            for x in $LDFLAGS $LTLIB[]NAME; do
+              AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+              case "$x" in
+                -L*)
+                  dir=`echo "X$x" | sed -e 's/^X-L//'`
+                  dnl First look for a shared library.
+                  if test -n "$acl_shlibext"; then
+                    if test -f "$dir/$libname$shrext"; then
+                      found_dir="$dir"
+                      found_so="$dir/$libname$shrext"
+                    else
+                      if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
+                        ver=`(cd "$dir" && \
+                              for f in "$libname$shrext".*; do echo "$f"; done \
+                              | sed -e "s,^$libname$shrext\\\\.,," \
+                              | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
+                              | sed 1q ) 2>/dev/null`
+                        if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
+                          found_dir="$dir"
+                          found_so="$dir/$libname$shrext.$ver"
+                        fi
+                      else
+                        eval library_names=\"$acl_library_names_spec\"
+                        for f in $library_names; do
+                          if test -f "$dir/$f"; then
+                            found_dir="$dir"
+                            found_so="$dir/$f"
+                            break
+                          fi
+                        done
+                      fi
+                    fi
+                  fi
+                  dnl Then look for a static library.
+                  if test "X$found_dir" = "X"; then
+                    if test -f "$dir/$libname.$acl_libext"; then
+                      found_dir="$dir"
+                      found_a="$dir/$libname.$acl_libext"
+                    fi
+                  fi
+                  if test "X$found_dir" != "X"; then
+                    if test -f "$dir/$libname.la"; then
+                      found_la="$dir/$libname.la"
+                    fi
+                  fi
+                  ;;
+              esac
+              if test "X$found_dir" != "X"; then
+                break
+              fi
+            done
+          fi
+          if test "X$found_dir" != "X"; then
+            dnl Found the library.
+            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$found_dir -l$name"
+            if test "X$found_so" != "X"; then
+              dnl Linking with a shared library. We attempt to hardcode its
+              dnl directory into the executable's runpath, unless it's the
+              dnl standard /usr/lib.
+              if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then
+                dnl No hardcoding is needed.
+                LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
+              else
+                dnl Use an explicit option to hardcode DIR into the resulting
+                dnl binary.
+                dnl Potentially add DIR to ltrpathdirs.
+                dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
+                haveit=
+                for x in $ltrpathdirs; do
+                  if test "X$x" = "X$found_dir"; then
+                    haveit=yes
+                    break
+                  fi
+                done
+                if test -z "$haveit"; then
+                  ltrpathdirs="$ltrpathdirs $found_dir"
+                fi
+                dnl The hardcoding into $LIBNAME is system dependent.
+                if test "$acl_hardcode_direct" = yes; then
+                  dnl Using DIR/libNAME.so during linking hardcodes DIR into the
+                  dnl resulting binary.
+                  LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
+                else
+                  if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
+                    dnl Use an explicit option to hardcode DIR into the resulting
+                    dnl binary.
+                    LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
+                    dnl Potentially add DIR to rpathdirs.
+                    dnl The rpathdirs will be appended to $LIBNAME at the end.
+                    haveit=
+                    for x in $rpathdirs; do
+                      if test "X$x" = "X$found_dir"; then
+                        haveit=yes
+                        break
+                      fi
+                    done
+                    if test -z "$haveit"; then
+                      rpathdirs="$rpathdirs $found_dir"
+                    fi
+                  else
+                    dnl Rely on "-L$found_dir".
+                    dnl But don't add it if it's already contained in the LDFLAGS
+                    dnl or the already constructed $LIBNAME
+                    haveit=
+                    for x in $LDFLAGS $LIB[]NAME; do
+                      AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+                      if test "X$x" = "X-L$found_dir"; then
+                        haveit=yes
+                        break
+                      fi
+                    done
+                    if test -z "$haveit"; then
+                      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir"
+                    fi
+                    if test "$acl_hardcode_minus_L" != no; then
+                      dnl FIXME: Not sure whether we should use
+                      dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
+                      dnl here.
+                      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
+                    else
+                      dnl We cannot use $acl_hardcode_runpath_var and LD_RUN_PATH
+                      dnl here, because this doesn't fit in flags passed to the
+                      dnl compiler. So give up. No hardcoding. This affects only
+                      dnl very old systems.
+                      dnl FIXME: Not sure whether we should use
+                      dnl "-L$found_dir -l$name" or "-L$found_dir $found_so"
+                      dnl here.
+                      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
+                    fi
+                  fi
+                fi
+              fi
+            else
+              if test "X$found_a" != "X"; then
+                dnl Linking with a static library.
+                LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_a"
+              else
+                dnl We shouldn't come here, but anyway it's good to have a
+                dnl fallback.
+                LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$found_dir -l$name"
+              fi
+            fi
+            dnl Assume the include files are nearby.
+            additional_includedir=
+            case "$found_dir" in
+              */$acl_libdirstem | */$acl_libdirstem/)
+                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
+                LIB[]NAME[]_PREFIX="$basedir"
+                additional_includedir="$basedir/include"
+                ;;
+            esac
+            if test "X$additional_includedir" != "X"; then
+              dnl Potentially add $additional_includedir to $INCNAME.
+              dnl But don't add it
+              dnl   1. if it's the standard /usr/include,
+              dnl   2. if it's /usr/local/include and we are using GCC on Linux,
+              dnl   3. if it's already present in $CPPFLAGS or the already
+              dnl      constructed $INCNAME,
+              dnl   4. if it doesn't exist as a directory.
+              if test "X$additional_includedir" != "X/usr/include"; then
+                haveit=
+                if test "X$additional_includedir" = "X/usr/local/include"; then
+                  if test -n "$GCC"; then
+                    case $host_os in
+                      linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+                    esac
+                  fi
+                fi
+                if test -z "$haveit"; then
+                  for x in $CPPFLAGS $INC[]NAME; do
+                    AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+                    if test "X$x" = "X-I$additional_includedir"; then
+                      haveit=yes
+                      break
+                    fi
+                  done
+                  if test -z "$haveit"; then
+                    if test -d "$additional_includedir"; then
+                      dnl Really add $additional_includedir to $INCNAME.
+                      INC[]NAME="${INC[]NAME}${INC[]NAME:+ }-I$additional_includedir"
+                    fi
+                  fi
+                fi
+              fi
+            fi
+            dnl Look for dependencies.
+            if test -n "$found_la"; then
+              dnl Read the .la file. It defines the variables
+              dnl dlname, library_names, old_library, dependency_libs, current,
+              dnl age, revision, installed, dlopen, dlpreopen, libdir.
+              save_libdir="$libdir"
+              case "$found_la" in
+                */* | *\\*) . "$found_la" ;;
+                *) . "./$found_la" ;;
+              esac
+              libdir="$save_libdir"
+              dnl We use only dependency_libs.
+              for dep in $dependency_libs; do
+                case "$dep" in
+                  -L*)
+                    additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
+                    dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME.
+                    dnl But don't add it
+                    dnl   1. if it's the standard /usr/lib,
+                    dnl   2. if it's /usr/local/lib and we are using GCC on Linux,
+                    dnl   3. if it's already present in $LDFLAGS or the already
+                    dnl      constructed $LIBNAME,
+                    dnl   4. if it doesn't exist as a directory.
+                    if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
+                      haveit=
+                      if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
+                        if test -n "$GCC"; then
+                          case $host_os in
+                            linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+                          esac
+                        fi
+                      fi
+                      if test -z "$haveit"; then
+                        haveit=
+                        for x in $LDFLAGS $LIB[]NAME; do
+                          AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+                          if test "X$x" = "X-L$additional_libdir"; then
+                            haveit=yes
+                            break
+                          fi
+                        done
+                        if test -z "$haveit"; then
+                          if test -d "$additional_libdir"; then
+                            dnl Really add $additional_libdir to $LIBNAME.
+                            LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir"
+                          fi
+                        fi
+                        haveit=
+                        for x in $LDFLAGS $LTLIB[]NAME; do
+                          AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+                          if test "X$x" = "X-L$additional_libdir"; then
+                            haveit=yes
+                            break
+                          fi
+                        done
+                        if test -z "$haveit"; then
+                          if test -d "$additional_libdir"; then
+                            dnl Really add $additional_libdir to $LTLIBNAME.
+                            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir"
+                          fi
+                        fi
+                      fi
+                    fi
+                    ;;
+                  -R*)
+                    dir=`echo "X$dep" | sed -e 's/^X-R//'`
+                    if test "$enable_rpath" != no; then
+                      dnl Potentially add DIR to rpathdirs.
+                      dnl The rpathdirs will be appended to $LIBNAME at the end.
+                      haveit=
+                      for x in $rpathdirs; do
+                        if test "X$x" = "X$dir"; then
+                          haveit=yes
+                          break
+                        fi
+                      done
+                      if test -z "$haveit"; then
+                        rpathdirs="$rpathdirs $dir"
+                      fi
+                      dnl Potentially add DIR to ltrpathdirs.
+                      dnl The ltrpathdirs will be appended to $LTLIBNAME at the end.
+                      haveit=
+                      for x in $ltrpathdirs; do
+                        if test "X$x" = "X$dir"; then
+                          haveit=yes
+                          break
+                        fi
+                      done
+                      if test -z "$haveit"; then
+                        ltrpathdirs="$ltrpathdirs $dir"
+                      fi
+                    fi
+                    ;;
+                  -l*)
+                    dnl Handle this in the next round.
+                    names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
+                    ;;
+                  *.la)
+                    dnl Handle this in the next round. Throw away the .la's
+                    dnl directory; it is already contained in a preceding -L
+                    dnl option.
+                    names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
+                    ;;
+                  *)
+                    dnl Most likely an immediate library name.
+                    LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$dep"
+                    LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }$dep"
+                    ;;
+                esac
+              done
+            fi
+          else
+            dnl Didn't find the library; assume it is in the system directories
+            dnl known to the linker and runtime loader. (All the system
+            dnl directories known to the linker should also be known to the
+            dnl runtime loader, otherwise the system is severely misconfigured.)
+            LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-l$name"
+            LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-l$name"
+          fi
+        fi
+      fi
+    done
+  done
+  if test "X$rpathdirs" != "X"; then
+    if test -n "$acl_hardcode_libdir_separator"; then
+      dnl Weird platform: only the last -rpath option counts, the user must
+      dnl pass all path elements in one option. We can arrange that for a
+      dnl single library, but not when more than one $LIBNAMEs are used.
+      alldirs=
+      for found_dir in $rpathdirs; do
+        alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir"
+      done
+      dnl Note: acl_hardcode_libdir_flag_spec uses $libdir and $wl.
+      acl_save_libdir="$libdir"
+      libdir="$alldirs"
+      eval flag=\"$acl_hardcode_libdir_flag_spec\"
+      libdir="$acl_save_libdir"
+      LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
+    else
+      dnl The -rpath options are cumulative.
+      for found_dir in $rpathdirs; do
+        acl_save_libdir="$libdir"
+        libdir="$found_dir"
+        eval flag=\"$acl_hardcode_libdir_flag_spec\"
+        libdir="$acl_save_libdir"
+        LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$flag"
+      done
+    fi
+  fi
+  if test "X$ltrpathdirs" != "X"; then
+    dnl When using libtool, the option that works for both libraries and
+    dnl executables is -R. The -R options are cumulative.
+    for found_dir in $ltrpathdirs; do
+      LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
+    done
+  fi
+])
+
+dnl AC_LIB_APPENDTOVAR(VAR, CONTENTS) appends the elements of CONTENTS to VAR,
+dnl unless already present in VAR.
+dnl Works only for CPPFLAGS, not for LIB* variables because that sometimes
+dnl contains two or three consecutive elements that belong together.
+AC_DEFUN([AC_LIB_APPENDTOVAR],
+[
+  for element in [$2]; do
+    haveit=
+    for x in $[$1]; do
+      AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+      if test "X$x" = "X$element"; then
+        haveit=yes
+        break
+      fi
+    done
+    if test -z "$haveit"; then
+      [$1]="${[$1]}${[$1]:+ }$element"
+    fi
+  done
+])
+
+dnl For those cases where a variable contains several -L and -l options
+dnl referring to unknown libraries and directories, this macro determines the
+dnl necessary additional linker options for the runtime path.
+dnl AC_LIB_LINKFLAGS_FROM_LIBS([LDADDVAR], [LIBSVALUE], [USE-LIBTOOL])
+dnl sets LDADDVAR to linker options needed together with LIBSVALUE.
+dnl If USE-LIBTOOL evaluates to non-empty, linking with libtool is assumed,
+dnl otherwise linking without libtool is assumed.
+AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
+[
+  AC_REQUIRE([AC_LIB_RPATH])
+  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
+  $1=
+  if test "$enable_rpath" != no; then
+    if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
+      dnl Use an explicit option to hardcode directories into the resulting
+      dnl binary.
+      rpathdirs=
+      next=
+      for opt in $2; do
+        if test -n "$next"; then
+          dir="$next"
+          dnl No need to hardcode the standard /usr/lib.
+          if test "X$dir" != "X/usr/$acl_libdirstem"; then
+            rpathdirs="$rpathdirs $dir"
+          fi
+          next=
+        else
+          case $opt in
+            -L) next=yes ;;
+            -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'`
+                 dnl No need to hardcode the standard /usr/lib.
+                 if test "X$dir" != "X/usr/$acl_libdirstem"; then
+                   rpathdirs="$rpathdirs $dir"
+                 fi
+                 next= ;;
+            *) next= ;;
+          esac
+        fi
+      done
+      if test "X$rpathdirs" != "X"; then
+        if test -n ""$3""; then
+          dnl libtool is used for linking. Use -R options.
+          for dir in $rpathdirs; do
+            $1="${$1}${$1:+ }-R$dir"
+          done
+        else
+          dnl The linker is used for linking directly.
+          if test -n "$acl_hardcode_libdir_separator"; then
+            dnl Weird platform: only the last -rpath option counts, the user
+            dnl must pass all path elements in one option.
+            alldirs=
+            for dir in $rpathdirs; do
+              alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$dir"
+            done
+            acl_save_libdir="$libdir"
+            libdir="$alldirs"
+            eval flag=\"$acl_hardcode_libdir_flag_spec\"
+            libdir="$acl_save_libdir"
+            $1="$flag"
+          else
+            dnl The -rpath options are cumulative.
+            for dir in $rpathdirs; do
+              acl_save_libdir="$libdir"
+              libdir="$dir"
+              eval flag=\"$acl_hardcode_libdir_flag_spec\"
+              libdir="$acl_save_libdir"
+              $1="${$1}${$1:+ }$flag"
+            done
+          fi
+        fi
+      fi
+    fi
+  fi
+  AC_SUBST([$1])
+])
+
+# lib-prefix.m4 serial 5 (gettext-0.15)
+dnl Copyright (C) 2001-2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and
+dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't
+dnl require excessive bracketing.
+ifdef([AC_HELP_STRING],
+[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])],
+[AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])])
+
+dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed
+dnl to access previously installed libraries. The basic assumption is that
+dnl a user will want packages to use other packages he previously installed
+dnl with the same --prefix option.
+dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate
+dnl libraries, but is otherwise very convenient.
+AC_DEFUN([AC_LIB_PREFIX],
+[
+  AC_BEFORE([$0], [AC_LIB_LINKFLAGS])
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
+  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
+  dnl By default, look in $includedir and $libdir.
+  use_additional=yes
+  AC_LIB_WITH_FINAL_PREFIX([
+    eval additional_includedir=\"$includedir\"
+    eval additional_libdir=\"$libdir\"
+  ])
+  AC_LIB_ARG_WITH([lib-prefix],
+[  --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib
+  --without-lib-prefix    don't search for libraries in includedir and libdir],
+[
+    if test "X$withval" = "Xno"; then
+      use_additional=no
+    else
+      if test "X$withval" = "X"; then
+        AC_LIB_WITH_FINAL_PREFIX([
+          eval additional_includedir=\"$includedir\"
+          eval additional_libdir=\"$libdir\"
+        ])
+      else
+        additional_includedir="$withval/include"
+        additional_libdir="$withval/$acl_libdirstem"
+      fi
+    fi
+])
+  if test $use_additional = yes; then
+    dnl Potentially add $additional_includedir to $CPPFLAGS.
+    dnl But don't add it
+    dnl   1. if it's the standard /usr/include,
+    dnl   2. if it's already present in $CPPFLAGS,
+    dnl   3. if it's /usr/local/include and we are using GCC on Linux,
+    dnl   4. if it doesn't exist as a directory.
+    if test "X$additional_includedir" != "X/usr/include"; then
+      haveit=
+      for x in $CPPFLAGS; do
+        AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+        if test "X$x" = "X-I$additional_includedir"; then
+          haveit=yes
+          break
+        fi
+      done
+      if test -z "$haveit"; then
+        if test "X$additional_includedir" = "X/usr/local/include"; then
+          if test -n "$GCC"; then
+            case $host_os in
+              linux* | gnu* | k*bsd*-gnu) haveit=yes;;
+            esac
+          fi
+        fi
+        if test -z "$haveit"; then
+          if test -d "$additional_includedir"; then
+            dnl Really add $additional_includedir to $CPPFLAGS.
+            CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir"
+          fi
+        fi
+      fi
+    fi
+    dnl Potentially add $additional_libdir to $LDFLAGS.
+    dnl But don't add it
+    dnl   1. if it's the standard /usr/lib,
+    dnl   2. if it's already present in $LDFLAGS,
+    dnl   3. if it's /usr/local/lib and we are using GCC on Linux,
+    dnl   4. if it doesn't exist as a directory.
+    if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
+      haveit=
+      for x in $LDFLAGS; do
+        AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
+        if test "X$x" = "X-L$additional_libdir"; then
+          haveit=yes
+          break
+        fi
+      done
+      if test -z "$haveit"; then
+        if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
+          if test -n "$GCC"; then
+            case $host_os in
+              linux*) haveit=yes;;
+            esac
+          fi
+        fi
+        if test -z "$haveit"; then
+          if test -d "$additional_libdir"; then
+            dnl Really add $additional_libdir to $LDFLAGS.
+            LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir"
+          fi
+        fi
+      fi
+    fi
+  fi
+])
+
+dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix,
+dnl acl_final_exec_prefix, containing the values to which $prefix and
+dnl $exec_prefix will expand at the end of the configure script.
+AC_DEFUN([AC_LIB_PREPARE_PREFIX],
+[
+  dnl Unfortunately, prefix and exec_prefix get only finally determined
+  dnl at the end of configure.
+  if test "X$prefix" = "XNONE"; then
+    acl_final_prefix="$ac_default_prefix"
+  else
+    acl_final_prefix="$prefix"
+  fi
+  if test "X$exec_prefix" = "XNONE"; then
+    acl_final_exec_prefix='${prefix}'
+  else
+    acl_final_exec_prefix="$exec_prefix"
+  fi
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  eval acl_final_exec_prefix=\"$acl_final_exec_prefix\"
+  prefix="$acl_save_prefix"
+])
+
+dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the
+dnl variables prefix and exec_prefix bound to the values they will have
+dnl at the end of the configure script.
+AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
+[
+  acl_save_prefix="$prefix"
+  prefix="$acl_final_prefix"
+  acl_save_exec_prefix="$exec_prefix"
+  exec_prefix="$acl_final_exec_prefix"
+  $1
+  exec_prefix="$acl_save_exec_prefix"
+  prefix="$acl_save_prefix"
+])
+
+dnl AC_LIB_PREPARE_MULTILIB creates a variable acl_libdirstem, containing
+dnl the basename of the libdir, either "lib" or "lib64".
+AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
+[
+  dnl There is no formal standard regarding lib and lib64. The current
+  dnl practice is that on a system supporting 32-bit and 64-bit instruction
+  dnl sets or ABIs, 64-bit libraries go under $prefix/lib64 and 32-bit
+  dnl libraries go under $prefix/lib. We determine the compiler's default
+  dnl mode by looking at the compiler's library search path. If at least
+  dnl of its elements ends in /lib64 or points to a directory whose absolute
+  dnl pathname ends in /lib64, we assume a 64-bit ABI. Otherwise we use the
+  dnl default, namely "lib".
+  acl_libdirstem=lib
+  searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
+  if test -n "$searchpath"; then
+    acl_save_IFS="${IFS= 	}"; IFS=":"
+    for searchdir in $searchpath; do
+      if test -d "$searchdir"; then
+        case "$searchdir" in
+          */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
+          *) searchdir=`cd "$searchdir" && pwd`
+             case "$searchdir" in
+               */lib64 ) acl_libdirstem=lib64 ;;
+             esac ;;
+        esac
+      fi
+    done
+    IFS="$acl_save_IFS"
+  fi
+])
+
+# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_AUTOMAKE_VERSION(VERSION)
+# ----------------------------
+# Automake X.Y traces this macro to ensure aclocal.m4 has been
+# generated from the m4 files accompanying Automake X.Y.
+# (This private macro should not be called outside this file.)
+AC_DEFUN([AM_AUTOMAKE_VERSION],
+[am__api_version='1.11'
+dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
+dnl require some minimum version.  Point them to the right macro.
+m4_if([$1], [1.11], [],
+      [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
+])
+
+# _AM_AUTOCONF_VERSION(VERSION)
+# -----------------------------
+# aclocal traces this macro to find the Autoconf version.
+# This is a private macro too.  Using m4_define simplifies
+# the logic in aclocal, which can simply ignore this definition.
+m4_define([_AM_AUTOCONF_VERSION], [])
+
+# AM_SET_CURRENT_AUTOMAKE_VERSION
+# -------------------------------
+# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
+# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
+AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
+[AM_AUTOMAKE_VERSION([1.11])dnl
+m4_ifndef([AC_AUTOCONF_VERSION],
+  [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
+_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
+
+# AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
+
+# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
+# $ac_aux_dir to `$srcdir/foo'.  In other projects, it is set to
+# `$srcdir', `$srcdir/..', or `$srcdir/../..'.
+#
+# Of course, Automake must honor this variable whenever it calls a
+# tool from the auxiliary directory.  The problem is that $srcdir (and
+# therefore $ac_aux_dir as well) can be either absolute or relative,
+# depending on how configure is run.  This is pretty annoying, since
+# it makes $ac_aux_dir quite unusable in subdirectories: in the top
+# source directory, any form will work fine, but in subdirectories a
+# relative path needs to be adjusted first.
+#
+# $ac_aux_dir/missing
+#    fails when called from a subdirectory if $ac_aux_dir is relative
+# $top_srcdir/$ac_aux_dir/missing
+#    fails if $ac_aux_dir is absolute,
+#    fails when called from a subdirectory in a VPATH build with
+#          a relative $ac_aux_dir
+#
+# The reason of the latter failure is that $top_srcdir and $ac_aux_dir
+# are both prefixed by $srcdir.  In an in-source build this is usually
+# harmless because $srcdir is `.', but things will broke when you
+# start a VPATH build or use an absolute $srcdir.
+#
+# So we could use something similar to $top_srcdir/$ac_aux_dir/missing,
+# iff we strip the leading $srcdir from $ac_aux_dir.  That would be:
+#   am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"`
+# and then we would define $MISSING as
+#   MISSING="\${SHELL} $am_aux_dir/missing"
+# This will work as long as MISSING is not called from configure, because
+# unfortunately $(top_srcdir) has no meaning in configure.
+# However there are other variables, like CC, which are often used in
+# configure, and could therefore not use this "fixed" $ac_aux_dir.
+#
+# Another solution, used here, is to always expand $ac_aux_dir to an
+# absolute PATH.  The drawback is that using absolute paths prevent a
+# configured tree to be moved without reconfiguration.
+
+AC_DEFUN([AM_AUX_DIR_EXPAND],
+[dnl Rely on autoconf to set up CDPATH properly.
+AC_PREREQ([2.50])dnl
+# expand $ac_aux_dir to an absolute path
+am_aux_dir=`cd $ac_aux_dir && pwd`
+])
+
+# AM_CONDITIONAL                                            -*- Autoconf -*-
+
+# Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 9
+
+# AM_CONDITIONAL(NAME, SHELL-CONDITION)
+# -------------------------------------
+# Define a conditional.
+AC_DEFUN([AM_CONDITIONAL],
+[AC_PREREQ(2.52)dnl
+ ifelse([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
+	[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
+AC_SUBST([$1_TRUE])dnl
+AC_SUBST([$1_FALSE])dnl
+_AM_SUBST_NOTMAKE([$1_TRUE])dnl
+_AM_SUBST_NOTMAKE([$1_FALSE])dnl
+m4_define([_AM_COND_VALUE_$1], [$2])dnl
+if $2; then
+  $1_TRUE=
+  $1_FALSE='#'
+else
+  $1_TRUE='#'
+  $1_FALSE=
+fi
+AC_CONFIG_COMMANDS_PRE(
+[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
+  AC_MSG_ERROR([[conditional "$1" was never defined.
+Usually this means the macro was only invoked conditionally.]])
+fi])])
+
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 10
+
+# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
+# written in clear, in which case automake, when reading aclocal.m4,
+# will think it sees a *use*, and therefore will trigger all it's
+# C support machinery.  Also note that it means that autoscan, seeing
+# CC etc. in the Makefile, will ask for an AC_PROG_CC use...
+
+
+# _AM_DEPENDENCIES(NAME)
+# ----------------------
+# See how the compiler implements dependency checking.
+# NAME is "CC", "CXX", "GCJ", or "OBJC".
+# We try a few techniques and use that to set a single cache variable.
+#
+# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
+# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular
+# dependency, and given that the user is not expected to run this macro,
+# just rely on AC_PROG_CC.
+AC_DEFUN([_AM_DEPENDENCIES],
+[AC_REQUIRE([AM_SET_DEPDIR])dnl
+AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
+AC_REQUIRE([AM_MAKE_INCLUDE])dnl
+AC_REQUIRE([AM_DEP_TRACK])dnl
+
+ifelse([$1], CC,   [depcc="$CC"   am_compiler_list=],
+       [$1], CXX,  [depcc="$CXX"  am_compiler_list=],
+       [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
+       [$1], UPC,  [depcc="$UPC"  am_compiler_list=],
+       [$1], GCJ,  [depcc="$GCJ"  am_compiler_list='gcc3 gcc'],
+                   [depcc="$$1"   am_compiler_list=])
+
+AC_CACHE_CHECK([dependency style of $depcc],
+               [am_cv_$1_dependencies_compiler_type],
+[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
+  # We make a subdir and do the tests there.  Otherwise we can end up
+  # making bogus files that we don't know about and never remove.  For
+  # instance it was reported that on HP-UX the gcc test will end up
+  # making a dummy file named `D' -- because `-MD' means `put the output
+  # in D'.
+  mkdir conftest.dir
+  # Copy depcomp to subdir because otherwise we won't find it if we're
+  # using a relative directory.
+  cp "$am_depcomp" conftest.dir
+  cd conftest.dir
+  # We will build objects and dependencies in a subdirectory because
+  # it helps to detect inapplicable dependency modes.  For instance
+  # both Tru64's cc and ICC support -MD to output dependencies as a
+  # side effect of compilation, but ICC will put the dependencies in
+  # the current directory while Tru64 will put them in the object
+  # directory.
+  mkdir sub
+
+  am_cv_$1_dependencies_compiler_type=none
+  if test "$am_compiler_list" = ""; then
+     am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
+  fi
+  am__universal=false
+  m4_case([$1], [CC],
+    [case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac],
+    [CXX],
+    [case " $depcc " in #(
+     *\ -arch\ *\ -arch\ *) am__universal=true ;;
+     esac])
+
+  for depmode in $am_compiler_list; do
+    # Setup a source with many dependencies, because some compilers
+    # like to wrap large dependency lists on column 80 (with \), and
+    # we should not choose a depcomp mode which is confused by this.
+    #
+    # We need to recreate these files for each test, as the compiler may
+    # overwrite some of them when testing with obscure command lines.
+    # This happens at least with the AIX C compiler.
+    : > sub/conftest.c
+    for i in 1 2 3 4 5 6; do
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
+      # Solaris 8's {/usr,}/bin/sh.
+      touch sub/conftst$i.h
+    done
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
+
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
+    # mode.  It turns out that the SunPro C++ compiler does not properly
+    # handle `-M -o', and we need to detect this.  Also, some Intel
+    # versions had trouble with output in subdirs
+    am__obj=sub/conftest.${OBJEXT-o}
+    am__minus_obj="-o $am__obj"
+    case $depmode in
+    gcc)
+      # This depmode causes a compiler race in universal mode.
+      test "$am__universal" = false || continue
+      ;;
+    nosideeffect)
+      # after this tag, mechanisms are not by side-effect, so they'll
+      # only be used when explicitly requested
+      if test "x$enable_dependency_tracking" = xyes; then
+	continue
+      else
+	break
+      fi
+      ;;
+    msvisualcpp | msvcmsys)
+      # This compiler won't grok `-c -o', but also, the minuso test has
+      # not run yet.  These depmodes are late enough in the game, and
+      # so weak that their functioning should not be impacted.
+      am__obj=conftest.${OBJEXT-o}
+      am__minus_obj=
+      ;;
+    none) break ;;
+    esac
+    if depmode=$depmode \
+       source=sub/conftest.c object=$am__obj \
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
+       $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \
+         >/dev/null 2>conftest.err &&
+       grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
+       grep $am__obj sub/conftest.Po > /dev/null 2>&1 &&
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
+      # icc doesn't choke on unknown options, it will just issue warnings
+      # or remarks (even with -Werror).  So we grep stderr for any message
+      # that says an option was ignored or not supported.
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
+      #   icc: Command line warning: ignoring option '-M'; no argument required
+      # The diagnosis changed in icc 8.0:
+      #   icc: Command line remark: option '-MP' not supported
+      if (grep 'ignoring option' conftest.err ||
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
+        am_cv_$1_dependencies_compiler_type=$depmode
+        break
+      fi
+    fi
+  done
+
+  cd ..
+  rm -rf conftest.dir
+else
+  am_cv_$1_dependencies_compiler_type=none
+fi
+])
+AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])
+AM_CONDITIONAL([am__fastdep$1], [
+  test "x$enable_dependency_tracking" != xno \
+  && test "$am_cv_$1_dependencies_compiler_type" = gcc3])
+])
+
+
+# AM_SET_DEPDIR
+# -------------
+# Choose a directory name for dependency files.
+# This macro is AC_REQUIREd in _AM_DEPENDENCIES
+AC_DEFUN([AM_SET_DEPDIR],
+[AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
+])
+
+
+# AM_DEP_TRACK
+# ------------
+AC_DEFUN([AM_DEP_TRACK],
+[AC_ARG_ENABLE(dependency-tracking,
+[  --disable-dependency-tracking  speeds up one-time build
+  --enable-dependency-tracking   do not reject slow dependency extractors])
+if test "x$enable_dependency_tracking" != xno; then
+  am_depcomp="$ac_aux_dir/depcomp"
+  AMDEPBACKSLASH='\'
+fi
+AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
+AC_SUBST([AMDEPBACKSLASH])dnl
+_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
+])
+
+# Generate code to set up dependency tracking.              -*- Autoconf -*-
+
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+#serial 5
+
+# _AM_OUTPUT_DEPENDENCY_COMMANDS
+# ------------------------------
+AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
+[{
+  # Autoconf 2.62 quotes --file arguments for eval, but not when files
+  # are listed without --file.  Let's play safe and only enable the eval
+  # if we detect the quoting.
+  case $CONFIG_FILES in
+  *\'*) eval set x "$CONFIG_FILES" ;;
+  *)   set x $CONFIG_FILES ;;
+  esac
+  shift
+  for mf
+  do
+    # Strip MF so we end up with the name of the file.
+    mf=`echo "$mf" | sed -e 's/:.*$//'`
+    # Check whether this is an Automake generated Makefile or not.
+    # We used to match only the files named `Makefile.in', but
+    # some people rename them; so instead we look at the file content.
+    # Grep'ing the first line is not enough: some people post-process
+    # each Makefile.in and add a new line on top of each file to say so.
+    # Grep'ing the whole file is not good either: AIX grep has a line
+    # limit of 2048, but all sed's we know have understand at least 4000.
+    if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
+      dirpart=`AS_DIRNAME("$mf")`
+    else
+      continue
+    fi
+    # Extract the definition of DEPDIR, am__include, and am__quote
+    # from the Makefile without running `make'.
+    DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
+    test -z "$DEPDIR" && continue
+    am__include=`sed -n 's/^am__include = //p' < "$mf"`
+    test -z "am__include" && continue
+    am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
+    # When using ansi2knr, U may be empty or an underscore; expand it
+    U=`sed -n 's/^U = //p' < "$mf"`
+    # Find all dependency output files, they are included files with
+    # $(DEPDIR) in their names.  We invoke sed twice because it is the
+    # simplest approach to changing $(DEPDIR) to its actual value in the
+    # expansion.
+    for file in `sed -n "
+      s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
+	 sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
+      # Make sure the directory exists.
+      test -f "$dirpart/$file" && continue
+      fdir=`AS_DIRNAME(["$file"])`
+      AS_MKDIR_P([$dirpart/$fdir])
+      # echo "creating $dirpart/$file"
+      echo '# dummy' > "$dirpart/$file"
+    done
+  done
+}
+])# _AM_OUTPUT_DEPENDENCY_COMMANDS
+
+
+# AM_OUTPUT_DEPENDENCY_COMMANDS
+# -----------------------------
+# This macro should only be invoked once -- use via AC_REQUIRE.
+#
+# This code is only required when automatic dependency tracking
+# is enabled.  FIXME.  This creates each `.P' file that we will
+# need in order to bootstrap the dependency handling code.
+AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
+[AC_CONFIG_COMMANDS([depfiles],
+     [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
+     [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
+])
+
+# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 8
+
+# AM_CONFIG_HEADER is obsolete.  It has been replaced by AC_CONFIG_HEADERS.
+AU_DEFUN([AM_CONFIG_HEADER], [AC_CONFIG_HEADERS($@)])
+
+# Do all the work for Automake.                             -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+# 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 16
+
+# This macro actually does too much.  Some checks are only needed if
+# your package does certain things.  But this isn't really a big deal.
+
+# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
+# AM_INIT_AUTOMAKE([OPTIONS])
+# -----------------------------------------------
+# The call with PACKAGE and VERSION arguments is the old style
+# call (pre autoconf-2.50), which is being phased out.  PACKAGE
+# and VERSION should now be passed to AC_INIT and removed from
+# the call to AM_INIT_AUTOMAKE.
+# We support both call styles for the transition.  After
+# the next Automake release, Autoconf can make the AC_INIT
+# arguments mandatory, and then we can depend on a new Autoconf
+# release and drop the old call support.
+AC_DEFUN([AM_INIT_AUTOMAKE],
+[AC_PREREQ([2.62])dnl
+dnl Autoconf wants to disallow AM_ names.  We explicitly allow
+dnl the ones we care about.
+m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
+AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
+AC_REQUIRE([AC_PROG_INSTALL])dnl
+if test "`cd $srcdir && pwd`" != "`pwd`"; then
+  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
+  # is not polluted with repeated "-I."
+  AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl
+  # test to see if srcdir already configured
+  if test -f $srcdir/config.status; then
+    AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
+  fi
+fi
+
+# test whether we have cygpath
+if test -z "$CYGPATH_W"; then
+  if (cygpath --version) >/dev/null 2>/dev/null; then
+    CYGPATH_W='cygpath -w'
+  else
+    CYGPATH_W=echo
+  fi
+fi
+AC_SUBST([CYGPATH_W])
+
+# Define the identity of the package.
+dnl Distinguish between old-style and new-style calls.
+m4_ifval([$2],
+[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
+ AC_SUBST([PACKAGE], [$1])dnl
+ AC_SUBST([VERSION], [$2])],
+[_AM_SET_OPTIONS([$1])dnl
+dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
+m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,,
+  [m4_fatal([AC_INIT should be called with package and version arguments])])dnl
+ AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
+ AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
+
+_AM_IF_OPTION([no-define],,
+[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
+ AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl
+
+# Some tools Automake needs.
+AC_REQUIRE([AM_SANITY_CHECK])dnl
+AC_REQUIRE([AC_ARG_PROGRAM])dnl
+AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version})
+AM_MISSING_PROG(AUTOCONF, autoconf)
+AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})
+AM_MISSING_PROG(AUTOHEADER, autoheader)
+AM_MISSING_PROG(MAKEINFO, makeinfo)
+AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
+AC_REQUIRE([AM_PROG_MKDIR_P])dnl
+# We need awk for the "check" target.  The system "awk" is bad on
+# some platforms.
+AC_REQUIRE([AC_PROG_AWK])dnl
+AC_REQUIRE([AC_PROG_MAKE_SET])dnl
+AC_REQUIRE([AM_SET_LEADING_DOT])dnl
+_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])],
+	      [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])],
+			     [_AM_PROG_TAR([v7])])])
+_AM_IF_OPTION([no-dependencies],,
+[AC_PROVIDE_IFELSE([AC_PROG_CC],
+		  [_AM_DEPENDENCIES(CC)],
+		  [define([AC_PROG_CC],
+			  defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_CXX],
+		  [_AM_DEPENDENCIES(CXX)],
+		  [define([AC_PROG_CXX],
+			  defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl
+AC_PROVIDE_IFELSE([AC_PROG_OBJC],
+		  [_AM_DEPENDENCIES(OBJC)],
+		  [define([AC_PROG_OBJC],
+			  defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl
+])
+_AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl
+dnl The `parallel-tests' driver may need to know about EXEEXT, so add the
+dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen.  This macro
+dnl is hooked onto _AC_COMPILER_EXEEXT early, see below.
+AC_CONFIG_COMMANDS_PRE(dnl
+[m4_provide_if([_AM_COMPILER_EXEEXT],
+  [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl
+])
+
+dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion.  Do not
+dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
+dnl mangled by Autoconf and run in a shell conditional statement.
+m4_define([_AC_COMPILER_EXEEXT],
+m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])
+
+
+# When config.status generates a header, we must update the stamp-h file.
+# This file resides in the same directory as the config header
+# that is generated.  The stamp files are numbered to have different names.
+
+# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the
+# loop where config.status creates the headers, so we can generate
+# our stamp files there.
+AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],
+[# Compute $1's index in $config_headers.
+_am_arg=$1
+_am_stamp_count=1
+for _am_header in $config_headers :; do
+  case $_am_header in
+    $_am_arg | $_am_arg:* )
+      break ;;
+    * )
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
+  esac
+done
+echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
+
+# Copyright (C) 2001, 2003, 2005, 2008  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_INSTALL_SH
+# ------------------
+# Define $install_sh.
+AC_DEFUN([AM_PROG_INSTALL_SH],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+if test x"${install_sh}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;;
+  *)
+    install_sh="\${SHELL} $am_aux_dir/install-sh"
+  esac
+fi
+AC_SUBST(install_sh)])
+
+# Copyright (C) 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 2
+
+# Check whether the underlying file-system supports filenames
+# with a leading dot.  For instance MS-DOS doesn't.
+AC_DEFUN([AM_SET_LEADING_DOT],
+[rm -rf .tst 2>/dev/null
+mkdir .tst 2>/dev/null
+if test -d .tst; then
+  am__leading_dot=.
+else
+  am__leading_dot=_
+fi
+rmdir .tst 2>/dev/null
+AC_SUBST([am__leading_dot])])
+
+# Check to see how 'make' treats includes.	            -*- Autoconf -*-
+
+# Copyright (C) 2001, 2002, 2003, 2005, 2009  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 4
+
+# AM_MAKE_INCLUDE()
+# -----------------
+# Check to see how make treats includes.
+AC_DEFUN([AM_MAKE_INCLUDE],
+[am_make=${MAKE-make}
+cat > confinc << 'END'
+am__doit:
+	@echo this is the am__doit target
+.PHONY: am__doit
+END
+# If we don't find an include directive, just comment out the code.
+AC_MSG_CHECKING([for style of include used by $am_make])
+am__include="#"
+am__quote=
+_am_result=none
+# First try GNU make style include.
+echo "include confinc" > confmf
+# Ignore all kinds of additional output from `make'.
+case `$am_make -s -f confmf 2> /dev/null` in #(
+*the\ am__doit\ target*)
+  am__include=include
+  am__quote=
+  _am_result=GNU
+  ;;
+esac
+# Now try BSD make style include.
+if test "$am__include" = "#"; then
+   echo '.include "confinc"' > confmf
+   case `$am_make -s -f confmf 2> /dev/null` in #(
+   *the\ am__doit\ target*)
+     am__include=.include
+     am__quote="\""
+     _am_result=BSD
+     ;;
+   esac
+fi
+AC_SUBST([am__include])
+AC_SUBST([am__quote])
+AC_MSG_RESULT([$_am_result])
+rm -f confinc confmf
+])
+
+# Fake the existence of programs that GNU maintainers use.  -*- Autoconf -*-
+
+# Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 6
+
+# AM_MISSING_PROG(NAME, PROGRAM)
+# ------------------------------
+AC_DEFUN([AM_MISSING_PROG],
+[AC_REQUIRE([AM_MISSING_HAS_RUN])
+$1=${$1-"${am_missing_run}$2"}
+AC_SUBST($1)])
+
+
+# AM_MISSING_HAS_RUN
+# ------------------
+# Define MISSING if not defined so far and test if it supports --run.
+# If it does, set am_missing_run to use it, otherwise, to nothing.
+AC_DEFUN([AM_MISSING_HAS_RUN],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([missing])dnl
+if test x"${MISSING+set}" != xset; then
+  case $am_aux_dir in
+  *\ * | *\	*)
+    MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
+  *)
+    MISSING="\${SHELL} $am_aux_dir/missing" ;;
+  esac
+fi
+# Use eval to expand $SHELL
+if eval "$MISSING --run true"; then
+  am_missing_run="$MISSING --run "
+else
+  am_missing_run=
+  AC_MSG_WARN([`missing' script is too old or missing])
+fi
+])
+
+# Copyright (C) 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_MKDIR_P
+# ---------------
+# Check for `mkdir -p'.
+AC_DEFUN([AM_PROG_MKDIR_P],
+[AC_PREREQ([2.60])dnl
+AC_REQUIRE([AC_PROG_MKDIR_P])dnl
+dnl Automake 1.8 to 1.9.6 used to define mkdir_p.  We now use MKDIR_P,
+dnl while keeping a definition of mkdir_p for backward compatibility.
+dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile.
+dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of
+dnl Makefile.ins that do not define MKDIR_P, so we do our own
+dnl adjustment using top_builddir (which is defined more often than
+dnl MKDIR_P).
+AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl
+case $mkdir_p in
+  [[\\/$]]* | ?:[[\\/]]*) ;;
+  */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;;
+esac
+])
+
+# Helper functions for option handling.                     -*- Autoconf -*-
+
+# Copyright (C) 2001, 2002, 2003, 2005, 2008  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 4
+
+# _AM_MANGLE_OPTION(NAME)
+# -----------------------
+AC_DEFUN([_AM_MANGLE_OPTION],
+[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
+
+# _AM_SET_OPTION(NAME)
+# ------------------------------
+# Set option NAME.  Presently that only means defining a flag for this option.
+AC_DEFUN([_AM_SET_OPTION],
+[m4_define(_AM_MANGLE_OPTION([$1]), 1)])
+
+# _AM_SET_OPTIONS(OPTIONS)
+# ----------------------------------
+# OPTIONS is a space-separated list of Automake options.
+AC_DEFUN([_AM_SET_OPTIONS],
+[m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
+
+# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
+# -------------------------------------------
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
+AC_DEFUN([_AM_IF_OPTION],
+[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
+
+# Check to make sure that the build environment is sane.    -*- Autoconf -*-
+
+# Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008
+# Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 5
+
+# AM_SANITY_CHECK
+# ---------------
+AC_DEFUN([AM_SANITY_CHECK],
+[AC_MSG_CHECKING([whether build environment is sane])
+# Just in case
+sleep 1
+echo timestamp > conftest.file
+# Reject unsafe characters in $srcdir or the absolute working directory
+# name.  Accept space and tab only in the latter.
+am_lf='
+'
+case `pwd` in
+  *[[\\\"\#\$\&\'\`$am_lf]]*)
+    AC_MSG_ERROR([unsafe absolute working directory name]);;
+esac
+case $srcdir in
+  *[[\\\"\#\$\&\'\`$am_lf\ \	]]*)
+    AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);;
+esac
+
+# Do `set' in a subshell so we don't clobber the current shell's
+# arguments.  Must try -L first in case configure is actually a
+# symlink; some systems play weird games with the mod time of symlinks
+# (eg FreeBSD returns the mod time of the symlink's containing
+# directory).
+if (
+   set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null`
+   if test "$[*]" = "X"; then
+      # -L didn't work.
+      set X `ls -t "$srcdir/configure" conftest.file`
+   fi
+   rm -f conftest.file
+   if test "$[*]" != "X $srcdir/configure conftest.file" \
+      && test "$[*]" != "X conftest.file $srcdir/configure"; then
+
+      # If neither matched, then we have a broken ls.  This can happen
+      # if, for instance, CONFIG_SHELL is bash and it inherits a
+      # broken ls alias from the environment.  This has actually
+      # happened.  Such a system could not be considered "sane".
+      AC_MSG_ERROR([ls -t appears to fail.  Make sure there is not a broken
+alias in your environment])
+   fi
+
+   test "$[2]" = conftest.file
+   )
+then
+   # Ok.
+   :
+else
+   AC_MSG_ERROR([newly created file is older than distributed files!
+Check your system clock])
+fi
+AC_MSG_RESULT(yes)])
+
+# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_PROG_INSTALL_STRIP
+# ---------------------
+# One issue with vendor `install' (even GNU) is that you can't
+# specify the program used to strip binaries.  This is especially
+# annoying in cross-compiling environments, where the build's strip
+# is unlikely to handle the host's binaries.
+# Fortunately install-sh will honor a STRIPPROG variable, so we
+# always use install-sh in `make install-strip', and initialize
+# STRIPPROG with the value of the STRIP variable (set by the user).
+AC_DEFUN([AM_PROG_INSTALL_STRIP],
+[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
+# Installed binaries are usually stripped using `strip' when the user
+# run `make install-strip'.  However `strip' might not be the right
+# tool to use in cross-compilation environments, therefore Automake
+# will honor the `STRIP' environment variable to overrule this program.
+dnl Don't test for $cross_compiling = yes, because it might be `maybe'.
+if test "$cross_compiling" != no; then
+  AC_CHECK_TOOL([STRIP], [strip], :)
+fi
+INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
+AC_SUBST([INSTALL_STRIP_PROGRAM])])
+
+# Copyright (C) 2006, 2008  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 2
+
+# _AM_SUBST_NOTMAKE(VARIABLE)
+# ---------------------------
+# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in.
+# This macro is traced by Automake.
+AC_DEFUN([_AM_SUBST_NOTMAKE])
+
+# AM_SUBST_NOTMAKE(VARIABLE)
+# ---------------------------
+# Public sister of _AM_SUBST_NOTMAKE.
+AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
+
+# Check how to create a tarball.                            -*- Autoconf -*-
+
+# Copyright (C) 2004, 2005  Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 2
+
+# _AM_PROG_TAR(FORMAT)
+# --------------------
+# Check how to create a tarball in format FORMAT.
+# FORMAT should be one of `v7', `ustar', or `pax'.
+#
+# Substitute a variable $(am__tar) that is a command
+# writing to stdout a FORMAT-tarball containing the directory
+# $tardir.
+#     tardir=directory && $(am__tar) > result.tar
+#
+# Substitute a variable $(am__untar) that extract such
+# a tarball read from stdin.
+#     $(am__untar) < result.tar
+AC_DEFUN([_AM_PROG_TAR],
+[# Always define AMTAR for backward compatibility.
+AM_MISSING_PROG([AMTAR], [tar])
+m4_if([$1], [v7],
+     [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'],
+     [m4_case([$1], [ustar],, [pax],,
+              [m4_fatal([Unknown tar format])])
+AC_MSG_CHECKING([how to create a $1 tar archive])
+# Loop over all known methods to create a tar archive until one works.
+_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none'
+_am_tools=${am_cv_prog_tar_$1-$_am_tools}
+# Do not fold the above two line into one, because Tru64 sh and
+# Solaris sh will not grok spaces in the rhs of `-'.
+for _am_tool in $_am_tools
+do
+  case $_am_tool in
+  gnutar)
+    for _am_tar in tar gnutar gtar;
+    do
+      AM_RUN_LOG([$_am_tar --version]) && break
+    done
+    am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"'
+    am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"'
+    am__untar="$_am_tar -xf -"
+    ;;
+  plaintar)
+    # Must skip GNU tar: if it does not support --format= it doesn't create
+    # ustar tarball either.
+    (tar --version) >/dev/null 2>&1 && continue
+    am__tar='tar chf - "$$tardir"'
+    am__tar_='tar chf - "$tardir"'
+    am__untar='tar xf -'
+    ;;
+  pax)
+    am__tar='pax -L -x $1 -w "$$tardir"'
+    am__tar_='pax -L -x $1 -w "$tardir"'
+    am__untar='pax -r'
+    ;;
+  cpio)
+    am__tar='find "$$tardir" -print | cpio -o -H $1 -L'
+    am__tar_='find "$tardir" -print | cpio -o -H $1 -L'
+    am__untar='cpio -i -H $1 -d'
+    ;;
+  none)
+    am__tar=false
+    am__tar_=false
+    am__untar=false
+    ;;
+  esac
+
+  # If the value was cached, stop now.  We just wanted to have am__tar
+  # and am__untar set.
+  test -n "${am_cv_prog_tar_$1}" && break
+
+  # tar/untar a dummy directory, and stop if the command works
+  rm -rf conftest.dir
+  mkdir conftest.dir
+  echo GrepMe > conftest.dir/file
+  AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar])
+  rm -rf conftest.dir
+  if test -s conftest.tar; then
+    AM_RUN_LOG([$am__untar <conftest.tar])
+    grep GrepMe conftest.dir/file >/dev/null 2>&1 && break
+  fi
+done
+rm -rf conftest.dir
+
+AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool])
+AC_MSG_RESULT([$am_cv_prog_tar_$1])])
+AC_SUBST([am__tar])
+AC_SUBST([am__untar])
+]) # _AM_PROG_TAR
+
+m4_include([m4/byteorder.m4])
+m4_include([m4/libtool.m4])
+m4_include([m4/ltoptions.m4])
+m4_include([m4/ltsugar.m4])
+m4_include([m4/ltversion.m4])
+m4_include([m4/lt~obsolete.m4])
+m4_include([m4/stdint.m4])
diff --git a/config.guess b/config.guess
new file mode 100644
index 0000000..f32079a
--- /dev/null
+++ b/config.guess
@@ -0,0 +1,1526 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+#   Free Software Foundation, Inc.
+
+timestamp='2008-01-23'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+
+# Originally written by Per Bothner <per@bothner.com>.
+# Please send patches to <config-patches@gnu.org>.  Submit a context
+# diff and a properly formatted ChangeLog entry.
+#
+# This script attempts to guess a canonical system name similar to
+# config.sub.  If it succeeds, it prints the system name on stdout, and
+# exits with 0.  Otherwise, it exits with 1.
+#
+# The plan is that this can be called by configure scripts if you
+# don't specify an explicit build system type.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION]
+
+Output the configuration name of the system \`$me' is run on.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.guess ($timestamp)
+
+Originally written by Per Bothner.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help" >&2
+       exit 1 ;;
+    * )
+       break ;;
+  esac
+done
+
+if test $# != 0; then
+  echo "$me: too many arguments$help" >&2
+  exit 1
+fi
+
+trap 'exit 1' 1 2 15
+
+# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
+# compiler to aid in system detection is discouraged as it requires
+# temporary files to be created and, as you can see below, it is a
+# headache to deal with in a portable fashion.
+
+# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
+# use `HOST_CC' if defined, but it is deprecated.
+
+# Portable tmp directory creation inspired by the Autoconf team.
+
+set_cc_for_build='
+trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
+trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
+: ${TMPDIR=/tmp} ;
+ { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
+ { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
+dummy=$tmp/dummy ;
+tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
+case $CC_FOR_BUILD,$HOST_CC,$CC in
+ ,,)    echo "int x;" > $dummy.c ;
+	for c in cc gcc c89 c99 ; do
+	  if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
+	     CC_FOR_BUILD="$c"; break ;
+	  fi ;
+	done ;
+	if test x"$CC_FOR_BUILD" = x ; then
+	  CC_FOR_BUILD=no_compiler_found ;
+	fi
+	;;
+ ,,*)   CC_FOR_BUILD=$CC ;;
+ ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
+esac ; set_cc_for_build= ;'
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi@noc.rutgers.edu 1994-08-24)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+	PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+# Note: order is significant - the case branches are not exclusive.
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+    *:NetBSD:*:*)
+	# NetBSD (nbsd) targets should (where applicable) match one or
+	# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
+	# *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
+	# switched to ELF, *-*-netbsd* would select the old
+	# object file format.  This provides both forward
+	# compatibility and a consistent mechanism for selecting the
+	# object file format.
+	#
+	# Note: NetBSD doesn't particularly care about the vendor
+	# portion of the name.  We always set it to "unknown".
+	sysctl="sysctl -n hw.machine_arch"
+	UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
+	    /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
+	case "${UNAME_MACHINE_ARCH}" in
+	    armeb) machine=armeb-unknown ;;
+	    arm*) machine=arm-unknown ;;
+	    sh3el) machine=shl-unknown ;;
+	    sh3eb) machine=sh-unknown ;;
+	    sh5el) machine=sh5le-unknown ;;
+	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
+	esac
+	# The Operating System including object format, if it has switched
+	# to ELF recently, or will in the future.
+	case "${UNAME_MACHINE_ARCH}" in
+	    arm*|i386|m68k|ns32k|sh3*|sparc|vax)
+		eval $set_cc_for_build
+		if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
+			| grep __ELF__ >/dev/null
+		then
+		    # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
+		    # Return netbsd for either.  FIX?
+		    os=netbsd
+		else
+		    os=netbsdelf
+		fi
+		;;
+	    *)
+	        os=netbsd
+		;;
+	esac
+	# The OS release
+	# Debian GNU/NetBSD machines have a different userland, and
+	# thus, need a distinct triplet. However, they do not need
+	# kernel version information, so it can be replaced with a
+	# suitable tag, in the style of linux-gnu.
+	case "${UNAME_VERSION}" in
+	    Debian*)
+		release='-gnu'
+		;;
+	    *)
+		release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+		;;
+	esac
+	# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
+	# contains redundant information, the shorter form:
+	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
+	echo "${machine}-${os}${release}"
+	exit ;;
+    *:OpenBSD:*:*)
+	UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
+	echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
+	exit ;;
+    *:ekkoBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
+	exit ;;
+    *:SolidBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
+	exit ;;
+    macppc:MirBSD:*:*)
+	echo powerpc-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
+    *:MirBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
+    alpha:OSF1:*:*)
+	case $UNAME_RELEASE in
+	*4.0)
+		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+		;;
+	*5.*)
+	        UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+		;;
+	esac
+	# According to Compaq, /usr/sbin/psrinfo has been available on
+	# OSF/1 and Tru64 systems produced since 1995.  I hope that
+	# covers most systems running today.  This code pipes the CPU
+	# types through head -n 1, so we only detect the type of CPU 0.
+	ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \(.*\) processor.*$/\1/p' | head -n 1`
+	case "$ALPHA_CPU_TYPE" in
+	    "EV4 (21064)")
+		UNAME_MACHINE="alpha" ;;
+	    "EV4.5 (21064)")
+		UNAME_MACHINE="alpha" ;;
+	    "LCA4 (21066/21068)")
+		UNAME_MACHINE="alpha" ;;
+	    "EV5 (21164)")
+		UNAME_MACHINE="alphaev5" ;;
+	    "EV5.6 (21164A)")
+		UNAME_MACHINE="alphaev56" ;;
+	    "EV5.6 (21164PC)")
+		UNAME_MACHINE="alphapca56" ;;
+	    "EV5.7 (21164PC)")
+		UNAME_MACHINE="alphapca57" ;;
+	    "EV6 (21264)")
+		UNAME_MACHINE="alphaev6" ;;
+	    "EV6.7 (21264A)")
+		UNAME_MACHINE="alphaev67" ;;
+	    "EV6.8CB (21264C)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.8AL (21264B)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.8CX (21264D)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.9A (21264/EV69A)")
+		UNAME_MACHINE="alphaev69" ;;
+	    "EV7 (21364)")
+		UNAME_MACHINE="alphaev7" ;;
+	    "EV7.9 (21364A)")
+		UNAME_MACHINE="alphaev79" ;;
+	esac
+	# A Pn.n version is a patched version.
+	# A Vn.n version is a released version.
+	# A Tn.n version is a released field test version.
+	# A Xn.n version is an unreleased experimental baselevel.
+	# 1.2 uses "1.2" for uname -r.
+	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	exit ;;
+    Alpha\ *:Windows_NT*:*)
+	# How do we know it's Interix rather than the generic POSIX subsystem?
+	# Should we change UNAME_MACHINE based on the output of uname instead
+	# of the specific Alpha model?
+	echo alpha-pc-interix
+	exit ;;
+    21064:Windows_NT:50:3)
+	echo alpha-dec-winnt3.5
+	exit ;;
+    Amiga*:UNIX_System_V:4.0:*)
+	echo m68k-unknown-sysv4
+	exit ;;
+    *:[Aa]miga[Oo][Ss]:*:*)
+	echo ${UNAME_MACHINE}-unknown-amigaos
+	exit ;;
+    *:[Mm]orph[Oo][Ss]:*:*)
+	echo ${UNAME_MACHINE}-unknown-morphos
+	exit ;;
+    *:OS/390:*:*)
+	echo i370-ibm-openedition
+	exit ;;
+    *:z/VM:*:*)
+	echo s390-ibm-zvmoe
+	exit ;;
+    *:OS400:*:*)
+        echo powerpc-ibm-os400
+	exit ;;
+    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
+	echo arm-acorn-riscix${UNAME_RELEASE}
+	exit ;;
+    arm:riscos:*:*|arm:RISCOS:*:*)
+	echo arm-unknown-riscos
+	exit ;;
+    SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
+	echo hppa1.1-hitachi-hiuxmpp
+	exit ;;
+    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
+	# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
+	if test "`(/bin/universe) 2>/dev/null`" = att ; then
+		echo pyramid-pyramid-sysv3
+	else
+		echo pyramid-pyramid-bsd
+	fi
+	exit ;;
+    NILE*:*:*:dcosx)
+	echo pyramid-pyramid-svr4
+	exit ;;
+    DRS?6000:unix:4.0:6*)
+	echo sparc-icl-nx6
+	exit ;;
+    DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
+	case `/usr/bin/uname -p` in
+	    sparc) echo sparc-icl-nx7; exit ;;
+	esac ;;
+    sun4H:SunOS:5.*:*)
+	echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
+	echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
+	echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:6*:*)
+	# According to config.sub, this is the proper way to canonicalize
+	# SunOS6.  Hard to guess exactly what SunOS6 will be like, but
+	# it's likely to be more like Solaris than SunOS4.
+	echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:*:*)
+	case "`/usr/bin/arch -k`" in
+	    Series*|S4*)
+		UNAME_RELEASE=`uname -v`
+		;;
+	esac
+	# Japanese Language versions have a version number like `4.1.3-JL'.
+	echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
+	exit ;;
+    sun3*:SunOS:*:*)
+	echo m68k-sun-sunos${UNAME_RELEASE}
+	exit ;;
+    sun*:*:4.2BSD:*)
+	UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
+	test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
+	case "`/bin/arch`" in
+	    sun3)
+		echo m68k-sun-sunos${UNAME_RELEASE}
+		;;
+	    sun4)
+		echo sparc-sun-sunos${UNAME_RELEASE}
+		;;
+	esac
+	exit ;;
+    aushp:SunOS:*:*)
+	echo sparc-auspex-sunos${UNAME_RELEASE}
+	exit ;;
+    # The situation for MiNT is a little confusing.  The machine name
+    # can be virtually everything (everything which is not
+    # "atarist" or "atariste" at least should have a processor
+    # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
+    # to the lowercase version "mint" (or "freemint").  Finally
+    # the system name "TOS" denotes a system which is actually not
+    # MiNT.  But MiNT is downward compatible to TOS, so this should
+    # be no problem.
+    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
+        echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
+	echo m68k-atari-mint${UNAME_RELEASE}
+        exit ;;
+    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
+        echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
+        echo m68k-milan-mint${UNAME_RELEASE}
+        exit ;;
+    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
+        echo m68k-hades-mint${UNAME_RELEASE}
+        exit ;;
+    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
+        echo m68k-unknown-mint${UNAME_RELEASE}
+        exit ;;
+    m68k:machten:*:*)
+	echo m68k-apple-machten${UNAME_RELEASE}
+	exit ;;
+    powerpc:machten:*:*)
+	echo powerpc-apple-machten${UNAME_RELEASE}
+	exit ;;
+    RISC*:Mach:*:*)
+	echo mips-dec-mach_bsd4.3
+	exit ;;
+    RISC*:ULTRIX:*:*)
+	echo mips-dec-ultrix${UNAME_RELEASE}
+	exit ;;
+    VAX*:ULTRIX*:*:*)
+	echo vax-dec-ultrix${UNAME_RELEASE}
+	exit ;;
+    2020:CLIX:*:* | 2430:CLIX:*:*)
+	echo clipper-intergraph-clix${UNAME_RELEASE}
+	exit ;;
+    mips:*:*:UMIPS | mips:*:*:RISCos)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+	int main (int argc, char *argv[]) {
+#else
+	int main (argc, argv) int argc; char *argv[]; {
+#endif
+	#if defined (host_mips) && defined (MIPSEB)
+	#if defined (SYSTYPE_SYSV)
+	  printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
+	#endif
+	#if defined (SYSTYPE_SVR4)
+	  printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
+	#endif
+	#if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
+	  printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
+	#endif
+	#endif
+	  exit (-1);
+	}
+EOF
+	$CC_FOR_BUILD -o $dummy $dummy.c &&
+	  dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
+	  SYSTEM_NAME=`$dummy $dummyarg` &&
+	    { echo "$SYSTEM_NAME"; exit; }
+	echo mips-mips-riscos${UNAME_RELEASE}
+	exit ;;
+    Motorola:PowerMAX_OS:*:*)
+	echo powerpc-motorola-powermax
+	exit ;;
+    Motorola:*:4.3:PL8-*)
+	echo powerpc-harris-powermax
+	exit ;;
+    Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
+	echo powerpc-harris-powermax
+	exit ;;
+    Night_Hawk:Power_UNIX:*:*)
+	echo powerpc-harris-powerunix
+	exit ;;
+    m88k:CX/UX:7*:*)
+	echo m88k-harris-cxux7
+	exit ;;
+    m88k:*:4*:R4*)
+	echo m88k-motorola-sysv4
+	exit ;;
+    m88k:*:3*:R3*)
+	echo m88k-motorola-sysv3
+	exit ;;
+    AViiON:dgux:*:*)
+        # DG/UX returns AViiON for all architectures
+        UNAME_PROCESSOR=`/usr/bin/uname -p`
+	if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
+	then
+	    if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
+	       [ ${TARGET_BINARY_INTERFACE}x = x ]
+	    then
+		echo m88k-dg-dgux${UNAME_RELEASE}
+	    else
+		echo m88k-dg-dguxbcs${UNAME_RELEASE}
+	    fi
+	else
+	    echo i586-dg-dgux${UNAME_RELEASE}
+	fi
+ 	exit ;;
+    M88*:DolphinOS:*:*)	# DolphinOS (SVR3)
+	echo m88k-dolphin-sysv3
+	exit ;;
+    M88*:*:R3*:*)
+	# Delta 88k system running SVR3
+	echo m88k-motorola-sysv3
+	exit ;;
+    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
+	echo m88k-tektronix-sysv3
+	exit ;;
+    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
+	echo m68k-tektronix-bsd
+	exit ;;
+    *:IRIX*:*:*)
+	echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
+	exit ;;
+    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
+	echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
+	exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
+    i*86:AIX:*:*)
+	echo i386-ibm-aix
+	exit ;;
+    ia64:AIX:*:*)
+	if [ -x /usr/bin/oslevel ] ; then
+		IBM_REV=`/usr/bin/oslevel`
+	else
+		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+	fi
+	echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
+	exit ;;
+    *:AIX:2:3)
+	if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
+		eval $set_cc_for_build
+		sed 's/^		//' << EOF >$dummy.c
+		#include <sys/systemcfg.h>
+
+		main()
+			{
+			if (!__power_pc())
+				exit(1);
+			puts("powerpc-ibm-aix3.2.5");
+			exit(0);
+			}
+EOF
+		if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
+		then
+			echo "$SYSTEM_NAME"
+		else
+			echo rs6000-ibm-aix3.2.5
+		fi
+	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
+		echo rs6000-ibm-aix3.2.4
+	else
+		echo rs6000-ibm-aix3.2
+	fi
+	exit ;;
+    *:AIX:*:[456])
+	IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
+	if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
+		IBM_ARCH=rs6000
+	else
+		IBM_ARCH=powerpc
+	fi
+	if [ -x /usr/bin/oslevel ] ; then
+		IBM_REV=`/usr/bin/oslevel`
+	else
+		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+	fi
+	echo ${IBM_ARCH}-ibm-aix${IBM_REV}
+	exit ;;
+    *:AIX:*:*)
+	echo rs6000-ibm-aix
+	exit ;;
+    ibmrt:4.4BSD:*|romp-ibm:BSD:*)
+	echo romp-ibm-bsd4.4
+	exit ;;
+    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
+	echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
+	exit ;;                             # report: romp-ibm BSD 4.3
+    *:BOSX:*:*)
+	echo rs6000-bull-bosx
+	exit ;;
+    DPX/2?00:B.O.S.:*:*)
+	echo m68k-bull-sysv3
+	exit ;;
+    9000/[34]??:4.3bsd:1.*:*)
+	echo m68k-hp-bsd
+	exit ;;
+    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
+	echo m68k-hp-bsd4.4
+	exit ;;
+    9000/[34678]??:HP-UX:*:*)
+	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+	case "${UNAME_MACHINE}" in
+	    9000/31? )            HP_ARCH=m68000 ;;
+	    9000/[34]?? )         HP_ARCH=m68k ;;
+	    9000/[678][0-9][0-9])
+		if [ -x /usr/bin/getconf ]; then
+		    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
+                    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
+                    case "${sc_cpu_version}" in
+                      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
+                      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
+                      532)                      # CPU_PA_RISC2_0
+                        case "${sc_kernel_bits}" in
+                          32) HP_ARCH="hppa2.0n" ;;
+                          64) HP_ARCH="hppa2.0w" ;;
+			  '') HP_ARCH="hppa2.0" ;;   # HP-UX 10.20
+                        esac ;;
+                    esac
+		fi
+		if [ "${HP_ARCH}" = "" ]; then
+		    eval $set_cc_for_build
+		    sed 's/^              //' << EOF >$dummy.c
+
+              #define _HPUX_SOURCE
+              #include <stdlib.h>
+              #include <unistd.h>
+
+              int main ()
+              {
+              #if defined(_SC_KERNEL_BITS)
+                  long bits = sysconf(_SC_KERNEL_BITS);
+              #endif
+                  long cpu  = sysconf (_SC_CPU_VERSION);
+
+                  switch (cpu)
+              	{
+              	case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+              	case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+              	case CPU_PA_RISC2_0:
+              #if defined(_SC_KERNEL_BITS)
+              	    switch (bits)
+              		{
+              		case 64: puts ("hppa2.0w"); break;
+              		case 32: puts ("hppa2.0n"); break;
+              		default: puts ("hppa2.0"); break;
+              		} break;
+              #else  /* !defined(_SC_KERNEL_BITS) */
+              	    puts ("hppa2.0"); break;
+              #endif
+              	default: puts ("hppa1.0"); break;
+              	}
+                  exit (0);
+              }
+EOF
+		    (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
+		    test -z "$HP_ARCH" && HP_ARCH=hppa
+		fi ;;
+	esac
+	if [ ${HP_ARCH} = "hppa2.0w" ]
+	then
+	    eval $set_cc_for_build
+
+	    # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
+	    # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
+	    # generating 64-bit code.  GNU and HP use different nomenclature:
+	    #
+	    # $ CC_FOR_BUILD=cc ./config.guess
+	    # => hppa2.0w-hp-hpux11.23
+	    # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
+	    # => hppa64-hp-hpux11.23
+
+	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
+		grep __LP64__ >/dev/null
+	    then
+		HP_ARCH="hppa2.0w"
+	    else
+		HP_ARCH="hppa64"
+	    fi
+	fi
+	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
+	exit ;;
+    ia64:HP-UX:*:*)
+	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+	echo ia64-hp-hpux${HPUX_REV}
+	exit ;;
+    3050*:HI-UX:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#include <unistd.h>
+	int
+	main ()
+	{
+	  long cpu = sysconf (_SC_CPU_VERSION);
+	  /* The order matters, because CPU_IS_HP_MC68K erroneously returns
+	     true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
+	     results, however.  */
+	  if (CPU_IS_PA_RISC (cpu))
+	    {
+	      switch (cpu)
+		{
+		  case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
+		  case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
+		  case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
+		  default: puts ("hppa-hitachi-hiuxwe2"); break;
+		}
+	    }
+	  else if (CPU_IS_HP_MC68K (cpu))
+	    puts ("m68k-hitachi-hiuxwe2");
+	  else puts ("unknown-hitachi-hiuxwe2");
+	  exit (0);
+	}
+EOF
+	$CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
+		{ echo "$SYSTEM_NAME"; exit; }
+	echo unknown-hitachi-hiuxwe2
+	exit ;;
+    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
+	echo hppa1.1-hp-bsd
+	exit ;;
+    9000/8??:4.3bsd:*:*)
+	echo hppa1.0-hp-bsd
+	exit ;;
+    *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
+	echo hppa1.0-hp-mpeix
+	exit ;;
+    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
+	echo hppa1.1-hp-osf
+	exit ;;
+    hp8??:OSF1:*:*)
+	echo hppa1.0-hp-osf
+	exit ;;
+    i*86:OSF1:*:*)
+	if [ -x /usr/sbin/sysversion ] ; then
+	    echo ${UNAME_MACHINE}-unknown-osf1mk
+	else
+	    echo ${UNAME_MACHINE}-unknown-osf1
+	fi
+	exit ;;
+    parisc*:Lites*:*:*)
+	echo hppa1.1-hp-lites
+	exit ;;
+    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
+	echo c1-convex-bsd
+        exit ;;
+    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
+	if getsysinfo -f scalar_acc
+	then echo c32-convex-bsd
+	else echo c2-convex-bsd
+	fi
+        exit ;;
+    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
+	echo c34-convex-bsd
+        exit ;;
+    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
+	echo c38-convex-bsd
+        exit ;;
+    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
+	echo c4-convex-bsd
+        exit ;;
+    CRAY*Y-MP:*:*:*)
+	echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*[A-Z]90:*:*:*)
+	echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
+	| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
+	      -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
+	      -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*TS:*:*:*)
+	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*T3E:*:*:*)
+	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*SV1:*:*:*)
+	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    *:UNICOS/mp:*:*)
+	echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
+	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+        FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+        echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+        exit ;;
+    5000:UNIX_System_V:4.*:*)
+        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+        FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
+        echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+	exit ;;
+    i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
+	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
+	exit ;;
+    sparc*:BSD/OS:*:*)
+	echo sparc-unknown-bsdi${UNAME_RELEASE}
+	exit ;;
+    *:BSD/OS:*:*)
+	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
+	exit ;;
+    *:FreeBSD:*:*)
+	case ${UNAME_MACHINE} in
+	    pc98)
+		echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	    amd64)
+		echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	    *)
+		echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	esac
+	exit ;;
+    i*:CYGWIN*:*)
+	echo ${UNAME_MACHINE}-pc-cygwin
+	exit ;;
+    *:MINGW*:*)
+	echo ${UNAME_MACHINE}-pc-mingw32
+	exit ;;
+    i*:windows32*:*)
+    	# uname -m includes "-pc" on this system.
+    	echo ${UNAME_MACHINE}-mingw32
+	exit ;;
+    i*:PW*:*)
+	echo ${UNAME_MACHINE}-pc-pw32
+	exit ;;
+    *:Interix*:[3456]*)
+    	case ${UNAME_MACHINE} in
+	    x86)
+		echo i586-pc-interix${UNAME_RELEASE}
+		exit ;;
+	    EM64T | authenticamd)
+		echo x86_64-unknown-interix${UNAME_RELEASE}
+		exit ;;
+	    IA64)
+		echo ia64-unknown-interix${UNAME_RELEASE}
+		exit ;;
+	esac ;;
+    [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
+	echo i${UNAME_MACHINE}-pc-mks
+	exit ;;
+    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
+	# How do we know it's Interix rather than the generic POSIX subsystem?
+	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
+	# UNAME_MACHINE based on the output of uname instead of i386?
+	echo i586-pc-interix
+	exit ;;
+    i*:UWIN*:*)
+	echo ${UNAME_MACHINE}-pc-uwin
+	exit ;;
+    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
+	echo x86_64-unknown-cygwin
+	exit ;;
+    p*:CYGWIN*:*)
+	echo powerpcle-unknown-cygwin
+	exit ;;
+    prep*:SunOS:5.*:*)
+	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    *:GNU:*:*)
+	# the GNU system
+	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+	exit ;;
+    *:GNU/*:*:*)
+	# other systems with GNU libc and userland
+	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
+	exit ;;
+    i*86:Minix:*:*)
+	echo ${UNAME_MACHINE}-pc-minix
+	exit ;;
+    arm*:Linux:*:*)
+	eval $set_cc_for_build
+	if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
+	    | grep -q __ARM_EABI__
+	then
+	    echo ${UNAME_MACHINE}-unknown-linux-gnu
+	else
+	    echo ${UNAME_MACHINE}-unknown-linux-gnueabi
+	fi
+	exit ;;
+    avr32*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    cris:Linux:*:*)
+	echo cris-axis-linux-gnu
+	exit ;;
+    crisv32:Linux:*:*)
+	echo crisv32-axis-linux-gnu
+	exit ;;
+    frv:Linux:*:*)
+    	echo frv-unknown-linux-gnu
+	exit ;;
+    ia64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    m32r*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    m68*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    mips:Linux:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#undef CPU
+	#undef mips
+	#undef mipsel
+	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+	CPU=mipsel
+	#else
+	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+	CPU=mips
+	#else
+	CPU=
+	#endif
+	#endif
+EOF
+	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+	    /^CPU/{
+		s: ::g
+		p
+	    }'`"
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
+	;;
+    mips64:Linux:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#undef CPU
+	#undef mips64
+	#undef mips64el
+	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+	CPU=mips64el
+	#else
+	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+	CPU=mips64
+	#else
+	CPU=
+	#endif
+	#endif
+EOF
+	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+	    /^CPU/{
+		s: ::g
+		p
+	    }'`"
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
+	;;
+    or32:Linux:*:*)
+	echo or32-unknown-linux-gnu
+	exit ;;
+    ppc:Linux:*:*)
+	echo powerpc-unknown-linux-gnu
+	exit ;;
+    ppc64:Linux:*:*)
+	echo powerpc64-unknown-linux-gnu
+	exit ;;
+    alpha:Linux:*:*)
+	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
+	  EV5)   UNAME_MACHINE=alphaev5 ;;
+	  EV56)  UNAME_MACHINE=alphaev56 ;;
+	  PCA56) UNAME_MACHINE=alphapca56 ;;
+	  PCA57) UNAME_MACHINE=alphapca56 ;;
+	  EV6)   UNAME_MACHINE=alphaev6 ;;
+	  EV67)  UNAME_MACHINE=alphaev67 ;;
+	  EV68*) UNAME_MACHINE=alphaev68 ;;
+        esac
+	objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
+	if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
+	echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
+	exit ;;
+    parisc:Linux:*:* | hppa:Linux:*:*)
+	# Look for CPU level
+	case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
+	  PA7*) echo hppa1.1-unknown-linux-gnu ;;
+	  PA8*) echo hppa2.0-unknown-linux-gnu ;;
+	  *)    echo hppa-unknown-linux-gnu ;;
+	esac
+	exit ;;
+    parisc64:Linux:*:* | hppa64:Linux:*:*)
+	echo hppa64-unknown-linux-gnu
+	exit ;;
+    s390:Linux:*:* | s390x:Linux:*:*)
+	echo ${UNAME_MACHINE}-ibm-linux
+	exit ;;
+    sh64*:Linux:*:*)
+    	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    sh*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    sparc:Linux:*:* | sparc64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    vax:Linux:*:*)
+	echo ${UNAME_MACHINE}-dec-linux-gnu
+	exit ;;
+    x86_64:Linux:*:*)
+	echo x86_64-unknown-linux-gnu
+	exit ;;
+    xtensa*:Linux:*:*)
+    	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
+    i*86:Linux:*:*)
+	# The BFD linker knows what the default object file format is, so
+	# first see if it will tell us. cd to the root directory to prevent
+	# problems with other programs or directories called `ld' in the path.
+	# Set LC_ALL=C to ensure ld outputs messages in English.
+	ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
+			 | sed -ne '/supported targets:/!d
+				    s/[ 	][ 	]*/ /g
+				    s/.*supported targets: *//
+				    s/ .*//
+				    p'`
+        case "$ld_supported_targets" in
+	  elf32-i386)
+		TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu"
+		;;
+	  a.out-i386-linux)
+		echo "${UNAME_MACHINE}-pc-linux-gnuaout"
+		exit ;;
+	  coff-i386)
+		echo "${UNAME_MACHINE}-pc-linux-gnucoff"
+		exit ;;
+	  "")
+		# Either a pre-BFD a.out linker (linux-gnuoldld) or
+		# one that does not give us useful --help.
+		echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
+		exit ;;
+	esac
+	# Determine whether the default compiler is a.out or elf
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#include <features.h>
+	#ifdef __ELF__
+	# ifdef __GLIBC__
+	#  if __GLIBC__ >= 2
+	LIBC=gnu
+	#  else
+	LIBC=gnulibc1
+	#  endif
+	# else
+	LIBC=gnulibc1
+	# endif
+	#else
+	#if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+	LIBC=gnu
+	#else
+	LIBC=gnuaout
+	#endif
+	#endif
+	#ifdef __dietlibc__
+	LIBC=dietlibc
+	#endif
+EOF
+	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+	    /^LIBC/{
+		s: ::g
+		p
+	    }'`"
+	test x"${LIBC}" != x && {
+		echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
+		exit
+	}
+	test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; }
+	;;
+    i*86:DYNIX/ptx:4*:*)
+	# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
+	# earlier versions are messed up and put the nodename in both
+	# sysname and nodename.
+	echo i386-sequent-sysv4
+	exit ;;
+    i*86:UNIX_SV:4.2MP:2.*)
+        # Unixware is an offshoot of SVR4, but it has its own version
+        # number series starting with 2...
+        # I am not positive that other SVR4 systems won't match this,
+	# I just have to hope.  -- rms.
+        # Use sysv4.2uw... so that sysv4* matches it.
+	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
+	exit ;;
+    i*86:OS/2:*:*)
+	# If we were able to find `uname', then EMX Unix compatibility
+	# is probably installed.
+	echo ${UNAME_MACHINE}-pc-os2-emx
+	exit ;;
+    i*86:XTS-300:*:STOP)
+	echo ${UNAME_MACHINE}-unknown-stop
+	exit ;;
+    i*86:atheos:*:*)
+	echo ${UNAME_MACHINE}-unknown-atheos
+	exit ;;
+    i*86:syllable:*:*)
+	echo ${UNAME_MACHINE}-pc-syllable
+	exit ;;
+    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
+	echo i386-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    i*86:*DOS:*:*)
+	echo ${UNAME_MACHINE}-pc-msdosdjgpp
+	exit ;;
+    i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
+	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
+	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
+		echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
+	else
+		echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
+	fi
+	exit ;;
+    i*86:*:5:[678]*)
+    	# UnixWare 7.x, OpenUNIX and OpenServer 6.
+	case `/bin/uname -X | grep "^Machine"` in
+	    *486*)	     UNAME_MACHINE=i486 ;;
+	    *Pentium)	     UNAME_MACHINE=i586 ;;
+	    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
+	esac
+	echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
+	exit ;;
+    i*86:*:3.2:*)
+	if test -f /usr/options/cb.name; then
+		UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
+		echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
+	elif /bin/uname -X 2>/dev/null >/dev/null ; then
+		UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
+		(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
+		(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
+			&& UNAME_MACHINE=i586
+		(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
+			&& UNAME_MACHINE=i686
+		(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
+			&& UNAME_MACHINE=i686
+		echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
+	else
+		echo ${UNAME_MACHINE}-pc-sysv32
+	fi
+	exit ;;
+    pc:*:*:*)
+	# Left here for compatibility:
+        # uname -m prints for DJGPP always 'pc', but it prints nothing about
+        # the processor, so we play safe by assuming i386.
+	echo i386-pc-msdosdjgpp
+        exit ;;
+    Intel:Mach:3*:*)
+	echo i386-pc-mach3
+	exit ;;
+    paragon:*:*:*)
+	echo i860-intel-osf1
+	exit ;;
+    i860:*:4.*:*) # i860-SVR4
+	if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
+	  echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
+	else # Add other i860-SVR4 vendors below as they are discovered.
+	  echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
+	fi
+	exit ;;
+    mini*:CTIX:SYS*5:*)
+	# "miniframe"
+	echo m68010-convergent-sysv
+	exit ;;
+    mc68k:UNIX:SYSTEM5:3.51m)
+	echo m68k-convergent-sysv
+	exit ;;
+    M680?0:D-NIX:5.3:*)
+	echo m68k-diab-dnix
+	exit ;;
+    M68*:*:R3V[5678]*:*)
+	test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
+    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
+	OS_REL=''
+	test -r /etc/.relid \
+	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	  && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+	  && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
+        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+          && { echo i486-ncr-sysv4; exit; } ;;
+    m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
+	echo m68k-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    mc68030:UNIX_System_V:4.*:*)
+	echo m68k-atari-sysv4
+	exit ;;
+    TSUNAMI:LynxOS:2.*:*)
+	echo sparc-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    rs6000:LynxOS:2.*:*)
+	echo rs6000-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
+	echo powerpc-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    SM[BE]S:UNIX_SV:*:*)
+	echo mips-dde-sysv${UNAME_RELEASE}
+	exit ;;
+    RM*:ReliantUNIX-*:*:*)
+	echo mips-sni-sysv4
+	exit ;;
+    RM*:SINIX-*:*:*)
+	echo mips-sni-sysv4
+	exit ;;
+    *:SINIX-*:*:*)
+	if uname -p 2>/dev/null >/dev/null ; then
+		UNAME_MACHINE=`(uname -p) 2>/dev/null`
+		echo ${UNAME_MACHINE}-sni-sysv4
+	else
+		echo ns32k-sni-sysv
+	fi
+	exit ;;
+    PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+                      # says <Richard.M.Bartel@ccMail.Census.GOV>
+        echo i586-unisys-sysv4
+        exit ;;
+    *:UNIX_System_V:4*:FTX*)
+	# From Gerald Hewes <hewes@openmarket.com>.
+	# How about differentiating between stratus architectures? -djm
+	echo hppa1.1-stratus-sysv4
+	exit ;;
+    *:*:*:FTX*)
+	# From seanf@swdc.stratus.com.
+	echo i860-stratus-sysv4
+	exit ;;
+    i*86:VOS:*:*)
+	# From Paul.Green@stratus.com.
+	echo ${UNAME_MACHINE}-stratus-vos
+	exit ;;
+    *:VOS:*:*)
+	# From Paul.Green@stratus.com.
+	echo hppa1.1-stratus-vos
+	exit ;;
+    mc68*:A/UX:*:*)
+	echo m68k-apple-aux${UNAME_RELEASE}
+	exit ;;
+    news*:NEWS-OS:6*:*)
+	echo mips-sony-newsos6
+	exit ;;
+    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
+	if [ -d /usr/nec ]; then
+	        echo mips-nec-sysv${UNAME_RELEASE}
+	else
+	        echo mips-unknown-sysv${UNAME_RELEASE}
+	fi
+        exit ;;
+    BeBox:BeOS:*:*)	# BeOS running on hardware made by Be, PPC only.
+	echo powerpc-be-beos
+	exit ;;
+    BeMac:BeOS:*:*)	# BeOS running on Mac or Mac clone, PPC only.
+	echo powerpc-apple-beos
+	exit ;;
+    BePC:BeOS:*:*)	# BeOS running on Intel PC compatible.
+	echo i586-pc-beos
+	exit ;;
+    SX-4:SUPER-UX:*:*)
+	echo sx4-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-5:SUPER-UX:*:*)
+	echo sx5-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-6:SUPER-UX:*:*)
+	echo sx6-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-7:SUPER-UX:*:*)
+	echo sx7-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-8:SUPER-UX:*:*)
+	echo sx8-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-8R:SUPER-UX:*:*)
+	echo sx8r-nec-superux${UNAME_RELEASE}
+	exit ;;
+    Power*:Rhapsody:*:*)
+	echo powerpc-apple-rhapsody${UNAME_RELEASE}
+	exit ;;
+    *:Rhapsody:*:*)
+	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
+	exit ;;
+    *:Darwin:*:*)
+	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
+	case $UNAME_PROCESSOR in
+	    unknown) UNAME_PROCESSOR=powerpc ;;
+	esac
+	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
+	exit ;;
+    *:procnto*:*:* | *:QNX:[0123456789]*:*)
+	UNAME_PROCESSOR=`uname -p`
+	if test "$UNAME_PROCESSOR" = "x86"; then
+		UNAME_PROCESSOR=i386
+		UNAME_MACHINE=pc
+	fi
+	echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
+	exit ;;
+    *:QNX:*:4*)
+	echo i386-pc-qnx
+	exit ;;
+    NSE-?:NONSTOP_KERNEL:*:*)
+	echo nse-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    NSR-?:NONSTOP_KERNEL:*:*)
+	echo nsr-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    *:NonStop-UX:*:*)
+	echo mips-compaq-nonstopux
+	exit ;;
+    BS2000:POSIX*:*:*)
+	echo bs2000-siemens-sysv
+	exit ;;
+    DS/*:UNIX_System_V:*:*)
+	echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
+	exit ;;
+    *:Plan9:*:*)
+	# "uname -m" is not consistent, so use $cputype instead. 386
+	# is converted to i386 for consistency with other x86
+	# operating systems.
+	if test "$cputype" = "386"; then
+	    UNAME_MACHINE=i386
+	else
+	    UNAME_MACHINE="$cputype"
+	fi
+	echo ${UNAME_MACHINE}-unknown-plan9
+	exit ;;
+    *:TOPS-10:*:*)
+	echo pdp10-unknown-tops10
+	exit ;;
+    *:TENEX:*:*)
+	echo pdp10-unknown-tenex
+	exit ;;
+    KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
+	echo pdp10-dec-tops20
+	exit ;;
+    XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
+	echo pdp10-xkl-tops20
+	exit ;;
+    *:TOPS-20:*:*)
+	echo pdp10-unknown-tops20
+	exit ;;
+    *:ITS:*:*)
+	echo pdp10-unknown-its
+	exit ;;
+    SEI:*:*:SEIUX)
+        echo mips-sei-seiux${UNAME_RELEASE}
+	exit ;;
+    *:DragonFly:*:*)
+	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+	exit ;;
+    *:*VMS:*:*)
+    	UNAME_MACHINE=`(uname -p) 2>/dev/null`
+	case "${UNAME_MACHINE}" in
+	    A*) echo alpha-dec-vms ; exit ;;
+	    I*) echo ia64-dec-vms ; exit ;;
+	    V*) echo vax-dec-vms ; exit ;;
+	esac ;;
+    *:XENIX:*:SysV)
+	echo i386-pc-xenix
+	exit ;;
+    i*86:skyos:*:*)
+	echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
+	exit ;;
+    i*86:rdos:*:*)
+	echo ${UNAME_MACHINE}-pc-rdos
+	exit ;;
+esac
+
+#echo '(No uname command or uname output not recognized.)' 1>&2
+#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
+
+eval $set_cc_for_build
+cat >$dummy.c <<EOF
+#ifdef _SEQUENT_
+# include <sys/types.h>
+# include <sys/utsname.h>
+#endif
+main ()
+{
+#if defined (sony)
+#if defined (MIPSEB)
+  /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
+     I don't know....  */
+  printf ("mips-sony-bsd\n"); exit (0);
+#else
+#include <sys/param.h>
+  printf ("m68k-sony-newsos%s\n",
+#ifdef NEWSOS4
+          "4"
+#else
+	  ""
+#endif
+         ); exit (0);
+#endif
+#endif
+
+#if defined (__arm) && defined (__acorn) && defined (__unix)
+  printf ("arm-acorn-riscix\n"); exit (0);
+#endif
+
+#if defined (hp300) && !defined (hpux)
+  printf ("m68k-hp-bsd\n"); exit (0);
+#endif
+
+#if defined (NeXT)
+#if !defined (__ARCHITECTURE__)
+#define __ARCHITECTURE__ "m68k"
+#endif
+  int version;
+  version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
+  if (version < 4)
+    printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
+  else
+    printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
+  exit (0);
+#endif
+
+#if defined (MULTIMAX) || defined (n16)
+#if defined (UMAXV)
+  printf ("ns32k-encore-sysv\n"); exit (0);
+#else
+#if defined (CMU)
+  printf ("ns32k-encore-mach\n"); exit (0);
+#else
+  printf ("ns32k-encore-bsd\n"); exit (0);
+#endif
+#endif
+#endif
+
+#if defined (__386BSD__)
+  printf ("i386-pc-bsd\n"); exit (0);
+#endif
+
+#if defined (sequent)
+#if defined (i386)
+  printf ("i386-sequent-dynix\n"); exit (0);
+#endif
+#if defined (ns32000)
+  printf ("ns32k-sequent-dynix\n"); exit (0);
+#endif
+#endif
+
+#if defined (_SEQUENT_)
+    struct utsname un;
+
+    uname(&un);
+
+    if (strncmp(un.version, "V2", 2) == 0) {
+	printf ("i386-sequent-ptx2\n"); exit (0);
+    }
+    if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
+	printf ("i386-sequent-ptx1\n"); exit (0);
+    }
+    printf ("i386-sequent-ptx\n"); exit (0);
+
+#endif
+
+#if defined (vax)
+# if !defined (ultrix)
+#  include <sys/param.h>
+#  if defined (BSD)
+#   if BSD == 43
+      printf ("vax-dec-bsd4.3\n"); exit (0);
+#   else
+#    if BSD == 199006
+      printf ("vax-dec-bsd4.3reno\n"); exit (0);
+#    else
+      printf ("vax-dec-bsd\n"); exit (0);
+#    endif
+#   endif
+#  else
+    printf ("vax-dec-bsd\n"); exit (0);
+#  endif
+# else
+    printf ("vax-dec-ultrix\n"); exit (0);
+# endif
+#endif
+
+#if defined (alliant) && defined (i860)
+  printf ("i860-alliant-bsd\n"); exit (0);
+#endif
+
+  exit (1);
+}
+EOF
+
+$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
+	{ echo "$SYSTEM_NAME"; exit; }
+
+# Apollos put the system type in the environment.
+
+test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
+
+# Convex versions that predate uname can use getsysinfo(1)
+
+if [ -x /usr/convex/getsysinfo ]
+then
+    case `getsysinfo -f cpu_type` in
+    c1*)
+	echo c1-convex-bsd
+	exit ;;
+    c2*)
+	if getsysinfo -f scalar_acc
+	then echo c32-convex-bsd
+	else echo c2-convex-bsd
+	fi
+	exit ;;
+    c34*)
+	echo c34-convex-bsd
+	exit ;;
+    c38*)
+	echo c38-convex-bsd
+	exit ;;
+    c4*)
+	echo c4-convex-bsd
+	exit ;;
+    esac
+fi
+
+cat >&2 <<EOF
+$0: unable to guess system type
+
+This script, last modified $timestamp, has failed to recognize
+the operating system you are using. It is advised that you
+download the most up to date version of the config scripts from
+
+  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+and
+  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+If the version you run ($0) is already up to date, please
+send the following data and any information you think might be
+pertinent to <config-patches@gnu.org> in order to provide the needed
+information to handle your system.
+
+config.guess timestamp = $timestamp
+
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null`
+
+hostinfo               = `(hostinfo) 2>/dev/null`
+/bin/universe          = `(/bin/universe) 2>/dev/null`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`
+/bin/arch              = `(/bin/arch) 2>/dev/null`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
+
+UNAME_MACHINE = ${UNAME_MACHINE}
+UNAME_RELEASE = ${UNAME_RELEASE}
+UNAME_SYSTEM  = ${UNAME_SYSTEM}
+UNAME_VERSION = ${UNAME_VERSION}
+EOF
+
+exit 1
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/config.h b/config.h
new file mode 100644
index 0000000..27edb8d
--- /dev/null
+++ b/config.h
@@ -0,0 +1,192 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Define if building universal (internal helper macro) */
+/* #undef AC_APPLE_UNIVERSAL_BUILD */
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#define HAVE_ARPA_INET_H 1
+
+/* Define to 1 if you have the `basename' function. */
+#define HAVE_BASENAME 1
+
+/* Define to 1 if you have the <byteswap.h> header file. */
+/* #undef HAVE_BYTESWAP_H */
+
+/* Define to 1 if you have the <ctype.h> header file. */
+#define HAVE_CTYPE_H 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <getopt.h> header file. */
+#define HAVE_GETOPT_H 1
+
+/* Define if you have the iconv() function and it works. */
+#define HAVE_ICONV 1
+
+/* Define to 1 if you have the <iconv.h> header file. */
+#define HAVE_ICONV_H 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <langinfo.h> header file. */
+#define HAVE_LANGINFO_H 1
+
+/* Define to 1 if you have the <libgen.h> header file. */
+#define HAVE_LIBGEN_H 1
+
+/* Define to 1 if you have the `usb' library (-lusb). */
+/* #undef HAVE_LIBUSB */
+
+/* Define to 1 if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the <locale.h> header file. */
+#define HAVE_LOCALE_H 1
+
+/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
+   to 0 otherwise. */
+#define HAVE_MALLOC 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `memset' function. */
+#define HAVE_MEMSET 1
+
+/* Define to 1 if you have the `mkstemp' function. */
+#define HAVE_MKSTEMP 1
+
+/* Define to 1 if you have the `select' function. */
+#define HAVE_SELECT 1
+
+/* Define to 1 if `stat' has the bug that it succeeds when given the
+   zero-length file name argument. */
+/* #undef HAVE_STAT_EMPTY_STRING_BUG */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strdup' function. */
+#define HAVE_STRDUP 1
+
+/* Define to 1 if you have the `strerror' function. */
+#define HAVE_STRERROR 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strrchr' function. */
+#define HAVE_STRRCHR 1
+
+/* Define to 1 if you have the `strtoul' function. */
+#define HAVE_STRTOUL 1
+
+/* Define to 1 if `st_blksize' is member of `struct stat'. */
+#define HAVE_STRUCT_STAT_ST_BLKSIZE 1
+
+/* Define to 1 if your `struct stat' has `st_blksize'. Deprecated, use
+   `HAVE_STRUCT_STAT_ST_BLKSIZE' instead. */
+#define HAVE_ST_BLKSIZE 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/uio.h> header file. */
+#define HAVE_SYS_UIO_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the `usleep' function. */
+#define HAVE_USLEEP 1
+
+/* Define as const if the declaration of iconv() needs const. */
+#define ICONV_CONST 
+
+/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
+   slash. */
+/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+   */
+#define LT_OBJDIR ".libs/"
+
+/* Name of package */
+#define PACKAGE "libmtp"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "libmtp-discuss@lists.sourceforge.net"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libmtp"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libmtp 1.0.1"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libmtp"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "1.0.1"
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#define RETSIGTYPE void
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#define TIME_WITH_SYS_TIME 1
+
+/* Version number of package */
+#define VERSION "1.0.1"
+
+/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+   significant byte first (like Motorola and SPARC, unlike Intel). */
+#ifdef __BIG_ENDIAN__
+#  define WORDS_BIGENDIAN 1
+#else
+#  undef WORDS_BIGENDIAN 
+#endif
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+/* #undef _FILE_OFFSET_BITS */
+
+/* Define for large files, on AIX-style hosts. */
+/* #undef _LARGE_FILES */
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to rpl_malloc if the replacement function should be used. */
+/* #undef malloc */
+
+/* Define to `long int' if <sys/types.h> does not define. */
+/* #undef off_t */
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */
diff --git a/config.h.in b/config.h.in
new file mode 100644
index 0000000..925807d
--- /dev/null
+++ b/config.h.in
@@ -0,0 +1,195 @@
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Define if building universal (internal helper macro) */
+#undef AC_APPLE_UNIVERSAL_BUILD
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#undef HAVE_ARPA_INET_H
+
+/* Define to 1 if you have the `basename' function. */
+#undef HAVE_BASENAME
+
+/* Define to 1 if you have the <byteswap.h> header file. */
+#undef HAVE_BYTESWAP_H
+
+/* Define to 1 if you have the <ctype.h> header file. */
+#undef HAVE_CTYPE_H
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
+
+/* Define to 1 if you have the <errno.h> header file. */
+#undef HAVE_ERRNO_H
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#undef HAVE_FCNTL_H
+
+/* Define to 1 if you have the <getopt.h> header file. */
+#undef HAVE_GETOPT_H
+
+/* Define if you have the iconv() function and it works. */
+#undef HAVE_ICONV
+
+/* Define to 1 if you have the <iconv.h> header file. */
+#undef HAVE_ICONV_H
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <langinfo.h> header file. */
+#undef HAVE_LANGINFO_H
+
+/* Define to 1 if you have the <libgen.h> header file. */
+#undef HAVE_LIBGEN_H
+
+/* Define to 1 if you have the `usb' library (-lusb). */
+#undef HAVE_LIBUSB
+
+/* Define to 1 if you have the <limits.h> header file. */
+#undef HAVE_LIMITS_H
+
+/* Define to 1 if you have the <locale.h> header file. */
+#undef HAVE_LOCALE_H
+
+/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
+   to 0 otherwise. */
+#undef HAVE_MALLOC
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the `memset' function. */
+#undef HAVE_MEMSET
+
+/* Define to 1 if you have the `mkstemp' function. */
+#undef HAVE_MKSTEMP
+
+/* Define to 1 if you have the `select' function. */
+#undef HAVE_SELECT
+
+/* Define to 1 if `stat' has the bug that it succeeds when given the
+   zero-length file name argument. */
+#undef HAVE_STAT_EMPTY_STRING_BUG
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#undef HAVE_STDIO_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the `strdup' function. */
+#undef HAVE_STRDUP
+
+/* Define to 1 if you have the `strerror' function. */
+#undef HAVE_STRERROR
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the `strrchr' function. */
+#undef HAVE_STRRCHR
+
+/* Define to 1 if you have the `strtoul' function. */
+#undef HAVE_STRTOUL
+
+/* Define to 1 if `st_blksize' is member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_BLKSIZE
+
+/* Define to 1 if your `struct stat' has `st_blksize'. Deprecated, use
+   `HAVE_STRUCT_STAT_ST_BLKSIZE' instead. */
+#undef HAVE_ST_BLKSIZE
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#undef HAVE_SYS_TIME_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <sys/uio.h> header file. */
+#undef HAVE_SYS_UIO_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to 1 if you have the `usleep' function. */
+#undef HAVE_USLEEP
+
+/* Define as const if the declaration of iconv() needs const. */
+#undef ICONV_CONST
+
+/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
+   slash. */
+#undef LSTAT_FOLLOWS_SLASHED_SYMLINK
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+   */
+#undef LT_OBJDIR
+
+/* Name of package */
+#undef PACKAGE
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#undef RETSIGTYPE
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#undef TIME_WITH_SYS_TIME
+
+/* Version number of package */
+#undef VERSION
+
+/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+   significant byte first (like Motorola and SPARC, unlike Intel). */
+#if defined AC_APPLE_UNIVERSAL_BUILD
+# if defined __BIG_ENDIAN__
+#  define WORDS_BIGENDIAN 1
+# endif
+#else
+# ifndef WORDS_BIGENDIAN
+#  undef WORDS_BIGENDIAN
+# endif
+#endif
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+#undef _FILE_OFFSET_BITS
+
+/* Define for large files, on AIX-style hosts. */
+#undef _LARGE_FILES
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#undef const
+
+/* Define to rpl_malloc if the replacement function should be used. */
+#undef malloc
+
+/* Define to `long int' if <sys/types.h> does not define. */
+#undef off_t
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+#undef size_t
diff --git a/config.rpath b/config.rpath
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/config.rpath
diff --git a/config.sub b/config.sub
new file mode 100644
index 0000000..6759825
--- /dev/null
+++ b/config.sub
@@ -0,0 +1,1658 @@
+#! /bin/sh
+# Configuration validation subroutine script.
+#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+#   Free Software Foundation, Inc.
+
+timestamp='2008-01-16'
+
+# This file is (in principle) common to ALL GNU software.
+# The presence of a machine in this file suggests that SOME GNU software
+# can handle that machine.  It does not imply ALL GNU software can.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+
+# Please send patches to <config-patches@gnu.org>.  Submit a context
+# diff and a properly formatted ChangeLog entry.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support.  The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+#	CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+#	CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION] CPU-MFR-OPSYS
+       $0 [OPTION] ALIAS
+
+Canonicalize a configuration name.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help"
+       exit 1 ;;
+
+    *local*)
+       # First pass through any local machine types.
+       echo $1
+       exit ;;
+
+    * )
+       break ;;
+  esac
+done
+
+case $# in
+ 0) echo "$me: missing argument$help" >&2
+    exit 1;;
+ 1) ;;
+ *) echo "$me: too many arguments$help" >&2
+    exit 1;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+  nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
+  uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
+  storm-chaos* | os2-emx* | rtmk-nova*)
+    os=-$maybe_os
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+    ;;
+  *)
+    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+    if [ $basic_machine != $1 ]
+    then os=`echo $1 | sed 's/.*-/-/'`
+    else os=; fi
+    ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work.  We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+	-sun*os*)
+		# Prevent following clause from handling this invalid input.
+		;;
+	-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+	-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+	-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+	-apple | -axis | -knuth | -cray)
+		os=
+		basic_machine=$1
+		;;
+	-sim | -cisco | -oki | -wec | -winbond)
+		os=
+		basic_machine=$1
+		;;
+	-scout)
+		;;
+	-wrs)
+		os=-vxworks
+		basic_machine=$1
+		;;
+	-chorusos*)
+		os=-chorusos
+		basic_machine=$1
+		;;
+ 	-chorusrdb)
+ 		os=-chorusrdb
+		basic_machine=$1
+ 		;;
+	-hiux*)
+		os=-hiuxwe2
+		;;
+	-sco6)
+		os=-sco5v6
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco5)
+		os=-sco3.2v5
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco4)
+		os=-sco3.2v4
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2.[4-9]*)
+		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2v[4-9]*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco5v6*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco*)
+		os=-sco3.2v2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-udk*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-isc)
+		os=-isc2.2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-clix*)
+		basic_machine=clipper-intergraph
+		;;
+	-isc*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-lynx*)
+		os=-lynxos
+		;;
+	-ptx*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+		;;
+	-windowsnt*)
+		os=`echo $os | sed -e 's/windowsnt/winnt/'`
+		;;
+	-psos*)
+		os=-psos
+		;;
+	-mint | -mint[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+	# Recognize the basic CPU types without company name.
+	# Some are omitted here because they have special meanings below.
+	1750a | 580 \
+	| a29k \
+	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
+	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
+	| am33_2.0 \
+	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
+	| bfin \
+	| c4x | clipper \
+	| d10v | d30v | dlx | dsp16xx \
+	| fido | fr30 | frv \
+	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+	| i370 | i860 | i960 | ia64 \
+	| ip2k | iq2000 \
+	| m32c | m32r | m32rle | m68000 | m68k | m88k \
+	| maxq | mb | microblaze | mcore | mep \
+	| mips | mipsbe | mipseb | mipsel | mipsle \
+	| mips16 \
+	| mips64 | mips64el \
+	| mips64vr | mips64vrel \
+	| mips64orion | mips64orionel \
+	| mips64vr4100 | mips64vr4100el \
+	| mips64vr4300 | mips64vr4300el \
+	| mips64vr5000 | mips64vr5000el \
+	| mips64vr5900 | mips64vr5900el \
+	| mipsisa32 | mipsisa32el \
+	| mipsisa32r2 | mipsisa32r2el \
+	| mipsisa64 | mipsisa64el \
+	| mipsisa64r2 | mipsisa64r2el \
+	| mipsisa64sb1 | mipsisa64sb1el \
+	| mipsisa64sr71k | mipsisa64sr71kel \
+	| mipstx39 | mipstx39el \
+	| mn10200 | mn10300 \
+	| mt \
+	| msp430 \
+	| nios | nios2 \
+	| ns16k | ns32k \
+	| or32 \
+	| pdp10 | pdp11 | pj | pjl \
+	| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
+	| pyramid \
+	| score \
+	| sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
+	| sh64 | sh64le \
+	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
+	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
+	| spu | strongarm \
+	| tahoe | thumb | tic4x | tic80 | tron \
+	| v850 | v850e \
+	| we32k \
+	| x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
+	| z8k)
+		basic_machine=$basic_machine-unknown
+		;;
+	m6811 | m68hc11 | m6812 | m68hc12)
+		# Motorola 68HC11/12.
+		basic_machine=$basic_machine-unknown
+		os=-none
+		;;
+	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
+		;;
+	ms1)
+		basic_machine=mt-unknown
+		;;
+
+	# We use `pc' rather than `unknown'
+	# because (1) that's what they normally are, and
+	# (2) the word "unknown" tends to confuse beginning users.
+	i*86 | x86_64)
+	  basic_machine=$basic_machine-pc
+	  ;;
+	# Object if more than one company name word.
+	*-*-*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+	# Recognize the basic CPU types with company name.
+	580-* \
+	| a29k-* \
+	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
+	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
+	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
+	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
+	| avr-* | avr32-* \
+	| bfin-* | bs2000-* \
+	| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
+	| clipper-* | craynv-* | cydra-* \
+	| d10v-* | d30v-* | dlx-* \
+	| elxsi-* \
+	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
+	| h8300-* | h8500-* \
+	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
+	| i*86-* | i860-* | i960-* | ia64-* \
+	| ip2k-* | iq2000-* \
+	| m32c-* | m32r-* | m32rle-* \
+	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
+	| m88110-* | m88k-* | maxq-* | mcore-* \
+	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
+	| mips16-* \
+	| mips64-* | mips64el-* \
+	| mips64vr-* | mips64vrel-* \
+	| mips64orion-* | mips64orionel-* \
+	| mips64vr4100-* | mips64vr4100el-* \
+	| mips64vr4300-* | mips64vr4300el-* \
+	| mips64vr5000-* | mips64vr5000el-* \
+	| mips64vr5900-* | mips64vr5900el-* \
+	| mipsisa32-* | mipsisa32el-* \
+	| mipsisa32r2-* | mipsisa32r2el-* \
+	| mipsisa64-* | mipsisa64el-* \
+	| mipsisa64r2-* | mipsisa64r2el-* \
+	| mipsisa64sb1-* | mipsisa64sb1el-* \
+	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
+	| mipstx39-* | mipstx39el-* \
+	| mmix-* \
+	| mt-* \
+	| msp430-* \
+	| nios-* | nios2-* \
+	| none-* | np1-* | ns16k-* | ns32k-* \
+	| orion-* \
+	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
+	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
+	| pyramid-* \
+	| romp-* | rs6000-* \
+	| sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
+	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
+	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
+	| sparclite-* \
+	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
+	| tahoe-* | thumb-* \
+	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
+	| tron-* \
+	| v850-* | v850e-* | vax-* \
+	| we32k-* \
+	| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
+	| xstormy16-* | xtensa*-* \
+	| ymp-* \
+	| z8k-*)
+		;;
+	# Recognize the basic CPU types without company name, with glob match.
+	xtensa*)
+		basic_machine=$basic_machine-unknown
+		;;
+	# Recognize the various machine names and aliases which stand
+	# for a CPU type and a company and sometimes even an OS.
+	386bsd)
+		basic_machine=i386-unknown
+		os=-bsd
+		;;
+	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+		basic_machine=m68000-att
+		;;
+	3b*)
+		basic_machine=we32k-att
+		;;
+	a29khif)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+    	abacus)
+		basic_machine=abacus-unknown
+		;;
+	adobe68k)
+		basic_machine=m68010-adobe
+		os=-scout
+		;;
+	alliant | fx80)
+		basic_machine=fx80-alliant
+		;;
+	altos | altos3068)
+		basic_machine=m68k-altos
+		;;
+	am29k)
+		basic_machine=a29k-none
+		os=-bsd
+		;;
+	amd64)
+		basic_machine=x86_64-pc
+		;;
+	amd64-*)
+		basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	amdahl)
+		basic_machine=580-amdahl
+		os=-sysv
+		;;
+	amiga | amiga-*)
+		basic_machine=m68k-unknown
+		;;
+	amigaos | amigados)
+		basic_machine=m68k-unknown
+		os=-amigaos
+		;;
+	amigaunix | amix)
+		basic_machine=m68k-unknown
+		os=-sysv4
+		;;
+	apollo68)
+		basic_machine=m68k-apollo
+		os=-sysv
+		;;
+	apollo68bsd)
+		basic_machine=m68k-apollo
+		os=-bsd
+		;;
+	aux)
+		basic_machine=m68k-apple
+		os=-aux
+		;;
+	balance)
+		basic_machine=ns32k-sequent
+		os=-dynix
+		;;
+	blackfin)
+		basic_machine=bfin-unknown
+		os=-linux
+		;;
+	blackfin-*)
+		basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	c90)
+		basic_machine=c90-cray
+		os=-unicos
+		;;
+	convex-c1)
+		basic_machine=c1-convex
+		os=-bsd
+		;;
+	convex-c2)
+		basic_machine=c2-convex
+		os=-bsd
+		;;
+	convex-c32)
+		basic_machine=c32-convex
+		os=-bsd
+		;;
+	convex-c34)
+		basic_machine=c34-convex
+		os=-bsd
+		;;
+	convex-c38)
+		basic_machine=c38-convex
+		os=-bsd
+		;;
+	cray | j90)
+		basic_machine=j90-cray
+		os=-unicos
+		;;
+	craynv)
+		basic_machine=craynv-cray
+		os=-unicosmp
+		;;
+	cr16)
+		basic_machine=cr16-unknown
+		os=-elf
+		;;
+	crds | unos)
+		basic_machine=m68k-crds
+		;;
+	crisv32 | crisv32-* | etraxfs*)
+		basic_machine=crisv32-axis
+		;;
+	cris | cris-* | etrax*)
+		basic_machine=cris-axis
+		;;
+	crx)
+		basic_machine=crx-unknown
+		os=-elf
+		;;
+	da30 | da30-*)
+		basic_machine=m68k-da30
+		;;
+	decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+		basic_machine=mips-dec
+		;;
+	decsystem10* | dec10*)
+		basic_machine=pdp10-dec
+		os=-tops10
+		;;
+	decsystem20* | dec20*)
+		basic_machine=pdp10-dec
+		os=-tops20
+		;;
+	delta | 3300 | motorola-3300 | motorola-delta \
+	      | 3300-motorola | delta-motorola)
+		basic_machine=m68k-motorola
+		;;
+	delta88)
+		basic_machine=m88k-motorola
+		os=-sysv3
+		;;
+	djgpp)
+		basic_machine=i586-pc
+		os=-msdosdjgpp
+		;;
+	dpx20 | dpx20-*)
+		basic_machine=rs6000-bull
+		os=-bosx
+		;;
+	dpx2* | dpx2*-bull)
+		basic_machine=m68k-bull
+		os=-sysv3
+		;;
+	ebmon29k)
+		basic_machine=a29k-amd
+		os=-ebmon
+		;;
+	elxsi)
+		basic_machine=elxsi-elxsi
+		os=-bsd
+		;;
+	encore | umax | mmax)
+		basic_machine=ns32k-encore
+		;;
+	es1800 | OSE68k | ose68k | ose | OSE)
+		basic_machine=m68k-ericsson
+		os=-ose
+		;;
+	fx2800)
+		basic_machine=i860-alliant
+		;;
+	genix)
+		basic_machine=ns32k-ns
+		;;
+	gmicro)
+		basic_machine=tron-gmicro
+		os=-sysv
+		;;
+	go32)
+		basic_machine=i386-pc
+		os=-go32
+		;;
+	h3050r* | hiux*)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	h8300hms)
+		basic_machine=h8300-hitachi
+		os=-hms
+		;;
+	h8300xray)
+		basic_machine=h8300-hitachi
+		os=-xray
+		;;
+	h8500hms)
+		basic_machine=h8500-hitachi
+		os=-hms
+		;;
+	harris)
+		basic_machine=m88k-harris
+		os=-sysv3
+		;;
+	hp300-*)
+		basic_machine=m68k-hp
+		;;
+	hp300bsd)
+		basic_machine=m68k-hp
+		os=-bsd
+		;;
+	hp300hpux)
+		basic_machine=m68k-hp
+		os=-hpux
+		;;
+	hp3k9[0-9][0-9] | hp9[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k2[0-9][0-9] | hp9k31[0-9])
+		basic_machine=m68000-hp
+		;;
+	hp9k3[2-9][0-9])
+		basic_machine=m68k-hp
+		;;
+	hp9k6[0-9][0-9] | hp6[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k7[0-79][0-9] | hp7[0-79][0-9])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k78[0-9] | hp78[0-9])
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][13679] | hp8[0-9][13679])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][0-9] | hp8[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hppa-next)
+		os=-nextstep3
+		;;
+	hppaosf)
+		basic_machine=hppa1.1-hp
+		os=-osf
+		;;
+	hppro)
+		basic_machine=hppa1.1-hp
+		os=-proelf
+		;;
+	i370-ibm* | ibm*)
+		basic_machine=i370-ibm
+		;;
+# I'm not sure what "Sysv32" means.  Should this be sysv3.2?
+	i*86v32)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv32
+		;;
+	i*86v4*)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv4
+		;;
+	i*86v)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv
+		;;
+	i*86sol2)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-solaris2
+		;;
+	i386mach)
+		basic_machine=i386-mach
+		os=-mach
+		;;
+	i386-vsta | vsta)
+		basic_machine=i386-unknown
+		os=-vsta
+		;;
+	iris | iris4d)
+		basic_machine=mips-sgi
+		case $os in
+		    -irix*)
+			;;
+		    *)
+			os=-irix4
+			;;
+		esac
+		;;
+	isi68 | isi)
+		basic_machine=m68k-isi
+		os=-sysv
+		;;
+	m68knommu)
+		basic_machine=m68k-unknown
+		os=-linux
+		;;
+	m68knommu-*)
+		basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	m88k-omron*)
+		basic_machine=m88k-omron
+		;;
+	magnum | m3230)
+		basic_machine=mips-mips
+		os=-sysv
+		;;
+	merlin)
+		basic_machine=ns32k-utek
+		os=-sysv
+		;;
+	mingw32)
+		basic_machine=i386-pc
+		os=-mingw32
+		;;
+	mingw32ce)
+		basic_machine=arm-unknown
+		os=-mingw32ce
+		;;
+	miniframe)
+		basic_machine=m68000-convergent
+		;;
+	*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+	mips3*-*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+		;;
+	mips3*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+		;;
+	monitor)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	morphos)
+		basic_machine=powerpc-unknown
+		os=-morphos
+		;;
+	msdos)
+		basic_machine=i386-pc
+		os=-msdos
+		;;
+	ms1-*)
+		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
+		;;
+	mvs)
+		basic_machine=i370-ibm
+		os=-mvs
+		;;
+	ncr3000)
+		basic_machine=i486-ncr
+		os=-sysv4
+		;;
+	netbsd386)
+		basic_machine=i386-unknown
+		os=-netbsd
+		;;
+	netwinder)
+		basic_machine=armv4l-rebel
+		os=-linux
+		;;
+	news | news700 | news800 | news900)
+		basic_machine=m68k-sony
+		os=-newsos
+		;;
+	news1000)
+		basic_machine=m68030-sony
+		os=-newsos
+		;;
+	news-3600 | risc-news)
+		basic_machine=mips-sony
+		os=-newsos
+		;;
+	necv70)
+		basic_machine=v70-nec
+		os=-sysv
+		;;
+	next | m*-next )
+		basic_machine=m68k-next
+		case $os in
+		    -nextstep* )
+			;;
+		    -ns2*)
+		      os=-nextstep2
+			;;
+		    *)
+		      os=-nextstep3
+			;;
+		esac
+		;;
+	nh3000)
+		basic_machine=m68k-harris
+		os=-cxux
+		;;
+	nh[45]000)
+		basic_machine=m88k-harris
+		os=-cxux
+		;;
+	nindy960)
+		basic_machine=i960-intel
+		os=-nindy
+		;;
+	mon960)
+		basic_machine=i960-intel
+		os=-mon960
+		;;
+	nonstopux)
+		basic_machine=mips-compaq
+		os=-nonstopux
+		;;
+	np1)
+		basic_machine=np1-gould
+		;;
+	nsr-tandem)
+		basic_machine=nsr-tandem
+		;;
+	op50n-* | op60c-*)
+		basic_machine=hppa1.1-oki
+		os=-proelf
+		;;
+	openrisc | openrisc-*)
+		basic_machine=or32-unknown
+		;;
+	os400)
+		basic_machine=powerpc-ibm
+		os=-os400
+		;;
+	OSE68000 | ose68000)
+		basic_machine=m68000-ericsson
+		os=-ose
+		;;
+	os68k)
+		basic_machine=m68k-none
+		os=-os68k
+		;;
+	pa-hitachi)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	paragon)
+		basic_machine=i860-intel
+		os=-osf
+		;;
+	parisc)
+		basic_machine=hppa-unknown
+		os=-linux
+		;;
+	parisc-*)
+		basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	pbd)
+		basic_machine=sparc-tti
+		;;
+	pbb)
+		basic_machine=m68k-tti
+		;;
+	pc532 | pc532-*)
+		basic_machine=ns32k-pc532
+		;;
+	pc98)
+		basic_machine=i386-pc
+		;;
+	pc98-*)
+		basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentium | p5 | k5 | k6 | nexgen | viac3)
+		basic_machine=i586-pc
+		;;
+	pentiumpro | p6 | 6x86 | athlon | athlon_*)
+		basic_machine=i686-pc
+		;;
+	pentiumii | pentium2 | pentiumiii | pentium3)
+		basic_machine=i686-pc
+		;;
+	pentium4)
+		basic_machine=i786-pc
+		;;
+	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
+		basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumpro-* | p6-* | 6x86-* | athlon-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentium4-*)
+		basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pn)
+		basic_machine=pn-gould
+		;;
+	power)	basic_machine=power-ibm
+		;;
+	ppc)	basic_machine=powerpc-unknown
+		;;
+	ppc-*)	basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppcle | powerpclittle | ppc-le | powerpc-little)
+		basic_machine=powerpcle-unknown
+		;;
+	ppcle-* | powerpclittle-*)
+		basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64)	basic_machine=powerpc64-unknown
+		;;
+	ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64le | powerpc64little | ppc64-le | powerpc64-little)
+		basic_machine=powerpc64le-unknown
+		;;
+	ppc64le-* | powerpc64little-*)
+		basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ps2)
+		basic_machine=i386-ibm
+		;;
+	pw32)
+		basic_machine=i586-unknown
+		os=-pw32
+		;;
+	rdos)
+		basic_machine=i386-pc
+		os=-rdos
+		;;
+	rom68k)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	rm[46]00)
+		basic_machine=mips-siemens
+		;;
+	rtpc | rtpc-*)
+		basic_machine=romp-ibm
+		;;
+	s390 | s390-*)
+		basic_machine=s390-ibm
+		;;
+	s390x | s390x-*)
+		basic_machine=s390x-ibm
+		;;
+	sa29200)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	sb1)
+		basic_machine=mipsisa64sb1-unknown
+		;;
+	sb1el)
+		basic_machine=mipsisa64sb1el-unknown
+		;;
+	sde)
+		basic_machine=mipsisa32-sde
+		os=-elf
+		;;
+	sei)
+		basic_machine=mips-sei
+		os=-seiux
+		;;
+	sequent)
+		basic_machine=i386-sequent
+		;;
+	sh)
+		basic_machine=sh-hitachi
+		os=-hms
+		;;
+	sh5el)
+		basic_machine=sh5le-unknown
+		;;
+	sh64)
+		basic_machine=sh64-unknown
+		;;
+	sparclite-wrs | simso-wrs)
+		basic_machine=sparclite-wrs
+		os=-vxworks
+		;;
+	sps7)
+		basic_machine=m68k-bull
+		os=-sysv2
+		;;
+	spur)
+		basic_machine=spur-unknown
+		;;
+	st2000)
+		basic_machine=m68k-tandem
+		;;
+	stratus)
+		basic_machine=i860-stratus
+		os=-sysv4
+		;;
+	sun2)
+		basic_machine=m68000-sun
+		;;
+	sun2os3)
+		basic_machine=m68000-sun
+		os=-sunos3
+		;;
+	sun2os4)
+		basic_machine=m68000-sun
+		os=-sunos4
+		;;
+	sun3os3)
+		basic_machine=m68k-sun
+		os=-sunos3
+		;;
+	sun3os4)
+		basic_machine=m68k-sun
+		os=-sunos4
+		;;
+	sun4os3)
+		basic_machine=sparc-sun
+		os=-sunos3
+		;;
+	sun4os4)
+		basic_machine=sparc-sun
+		os=-sunos4
+		;;
+	sun4sol2)
+		basic_machine=sparc-sun
+		os=-solaris2
+		;;
+	sun3 | sun3-*)
+		basic_machine=m68k-sun
+		;;
+	sun4)
+		basic_machine=sparc-sun
+		;;
+	sun386 | sun386i | roadrunner)
+		basic_machine=i386-sun
+		;;
+	sv1)
+		basic_machine=sv1-cray
+		os=-unicos
+		;;
+	symmetry)
+		basic_machine=i386-sequent
+		os=-dynix
+		;;
+	t3e)
+		basic_machine=alphaev5-cray
+		os=-unicos
+		;;
+	t90)
+		basic_machine=t90-cray
+		os=-unicos
+		;;
+	tic54x | c54x*)
+		basic_machine=tic54x-unknown
+		os=-coff
+		;;
+	tic55x | c55x*)
+		basic_machine=tic55x-unknown
+		os=-coff
+		;;
+	tic6x | c6x*)
+		basic_machine=tic6x-unknown
+		os=-coff
+		;;
+	tile*)
+		basic_machine=tile-unknown
+		os=-linux-gnu
+		;;
+	tx39)
+		basic_machine=mipstx39-unknown
+		;;
+	tx39el)
+		basic_machine=mipstx39el-unknown
+		;;
+	toad1)
+		basic_machine=pdp10-xkl
+		os=-tops20
+		;;
+	tower | tower-32)
+		basic_machine=m68k-ncr
+		;;
+	tpf)
+		basic_machine=s390x-ibm
+		os=-tpf
+		;;
+	udi29k)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	ultra3)
+		basic_machine=a29k-nyu
+		os=-sym1
+		;;
+	v810 | necv810)
+		basic_machine=v810-nec
+		os=-none
+		;;
+	vaxv)
+		basic_machine=vax-dec
+		os=-sysv
+		;;
+	vms)
+		basic_machine=vax-dec
+		os=-vms
+		;;
+	vpp*|vx|vx-*)
+		basic_machine=f301-fujitsu
+		;;
+	vxworks960)
+		basic_machine=i960-wrs
+		os=-vxworks
+		;;
+	vxworks68)
+		basic_machine=m68k-wrs
+		os=-vxworks
+		;;
+	vxworks29k)
+		basic_machine=a29k-wrs
+		os=-vxworks
+		;;
+	w65*)
+		basic_machine=w65-wdc
+		os=-none
+		;;
+	w89k-*)
+		basic_machine=hppa1.1-winbond
+		os=-proelf
+		;;
+	xbox)
+		basic_machine=i686-pc
+		os=-mingw32
+		;;
+	xps | xps100)
+		basic_machine=xps100-honeywell
+		;;
+	ymp)
+		basic_machine=ymp-cray
+		os=-unicos
+		;;
+	z8k-*-coff)
+		basic_machine=z8k-unknown
+		os=-sim
+		;;
+	none)
+		basic_machine=none-none
+		os=-none
+		;;
+
+# Here we handle the default manufacturer of certain CPU types.  It is in
+# some cases the only manufacturer, in others, it is the most popular.
+	w89k)
+		basic_machine=hppa1.1-winbond
+		;;
+	op50n)
+		basic_machine=hppa1.1-oki
+		;;
+	op60c)
+		basic_machine=hppa1.1-oki
+		;;
+	romp)
+		basic_machine=romp-ibm
+		;;
+	mmix)
+		basic_machine=mmix-knuth
+		;;
+	rs6000)
+		basic_machine=rs6000-ibm
+		;;
+	vax)
+		basic_machine=vax-dec
+		;;
+	pdp10)
+		# there are many clones, so DEC is not a safe bet
+		basic_machine=pdp10-unknown
+		;;
+	pdp11)
+		basic_machine=pdp11-dec
+		;;
+	we32k)
+		basic_machine=we32k-att
+		;;
+	sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele)
+		basic_machine=sh-unknown
+		;;
+	sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
+		basic_machine=sparc-sun
+		;;
+	cydra)
+		basic_machine=cydra-cydrome
+		;;
+	orion)
+		basic_machine=orion-highlevel
+		;;
+	orion105)
+		basic_machine=clipper-highlevel
+		;;
+	mac | mpw | mac-mpw)
+		basic_machine=m68k-apple
+		;;
+	pmac | pmac-mpw)
+		basic_machine=powerpc-apple
+		;;
+	*-unknown)
+		# Make sure to match an already-canonicalized machine name.
+		;;
+	*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+	*-digital*)
+		basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+		;;
+	*-commodore*)
+		basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+		;;
+	*)
+		;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+        # First match some system type aliases
+        # that might get confused with valid system types.
+	# -solaris* is a basic system type, with this one exception.
+	-solaris1 | -solaris1.*)
+		os=`echo $os | sed -e 's|solaris1|sunos4|'`
+		;;
+	-solaris)
+		os=-solaris2
+		;;
+	-svr4*)
+		os=-sysv4
+		;;
+	-unixware*)
+		os=-sysv4.2uw
+		;;
+	-gnu/linux*)
+		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+		;;
+	# First accept the basic system types.
+	# The portable systems comes first.
+	# Each alternative MUST END IN A *, to match a version number.
+	# -sysv* is not here because it comes later, after sysvr4.
+	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
+	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
+	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+	      | -aos* \
+	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
+	      | -openbsd* | -solidbsd* \
+	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
+	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+	      | -chorusos* | -chorusrdb* \
+	      | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+	      | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
+	      | -uxpv* | -beos* | -mpeix* | -udk* \
+	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
+	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
+	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
+	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
+	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
+	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
+	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops*)
+	# Remember, each alternative MUST END IN *, to match a version number.
+		;;
+	-qnx*)
+		case $basic_machine in
+		    x86-* | i*86-*)
+			;;
+		    *)
+			os=-nto$os
+			;;
+		esac
+		;;
+	-nto-qnx*)
+		;;
+	-nto*)
+		os=`echo $os | sed -e 's|nto|nto-qnx|'`
+		;;
+	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
+	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
+	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
+		;;
+	-mac*)
+		os=`echo $os | sed -e 's|mac|macos|'`
+		;;
+	-linux-dietlibc)
+		os=-linux-dietlibc
+		;;
+	-linux*)
+		os=`echo $os | sed -e 's|linux|linux-gnu|'`
+		;;
+	-sunos5*)
+		os=`echo $os | sed -e 's|sunos5|solaris2|'`
+		;;
+	-sunos6*)
+		os=`echo $os | sed -e 's|sunos6|solaris3|'`
+		;;
+	-opened*)
+		os=-openedition
+		;;
+        -os400*)
+		os=-os400
+		;;
+	-wince*)
+		os=-wince
+		;;
+	-osfrose*)
+		os=-osfrose
+		;;
+	-osf*)
+		os=-osf
+		;;
+	-utek*)
+		os=-bsd
+		;;
+	-dynix*)
+		os=-bsd
+		;;
+	-acis*)
+		os=-aos
+		;;
+	-atheos*)
+		os=-atheos
+		;;
+	-syllable*)
+		os=-syllable
+		;;
+	-386bsd)
+		os=-bsd
+		;;
+	-ctix* | -uts*)
+		os=-sysv
+		;;
+	-nova*)
+		os=-rtmk-nova
+		;;
+	-ns2 )
+		os=-nextstep2
+		;;
+	-nsk*)
+		os=-nsk
+		;;
+	# Preserve the version number of sinix5.
+	-sinix5.*)
+		os=`echo $os | sed -e 's|sinix|sysv|'`
+		;;
+	-sinix*)
+		os=-sysv4
+		;;
+        -tpf*)
+		os=-tpf
+		;;
+	-triton*)
+		os=-sysv3
+		;;
+	-oss*)
+		os=-sysv3
+		;;
+	-svr4)
+		os=-sysv4
+		;;
+	-svr3)
+		os=-sysv3
+		;;
+	-sysvr4)
+		os=-sysv4
+		;;
+	# This must come after -sysvr4.
+	-sysv*)
+		;;
+	-ose*)
+		os=-ose
+		;;
+	-es1800*)
+		os=-ose
+		;;
+	-xenix)
+		os=-xenix
+		;;
+	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+		os=-mint
+		;;
+	-aros*)
+		os=-aros
+		;;
+	-kaos*)
+		os=-kaos
+		;;
+	-zvmoe)
+		os=-zvmoe
+		;;
+	-none)
+		;;
+	*)
+		# Get rid of the `-' at the beginning of $os.
+		os=`echo $os | sed 's/[^-]*-//'`
+		echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+		exit 1
+		;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system.  Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+        score-*)
+		os=-elf
+		;;
+        spu-*)
+		os=-elf
+		;;
+	*-acorn)
+		os=-riscix1.2
+		;;
+	arm*-rebel)
+		os=-linux
+		;;
+	arm*-semi)
+		os=-aout
+		;;
+        c4x-* | tic4x-*)
+        	os=-coff
+		;;
+	# This must come before the *-dec entry.
+	pdp10-*)
+		os=-tops20
+		;;
+	pdp11-*)
+		os=-none
+		;;
+	*-dec | vax-*)
+		os=-ultrix4.2
+		;;
+	m68*-apollo)
+		os=-domain
+		;;
+	i386-sun)
+		os=-sunos4.0.2
+		;;
+	m68000-sun)
+		os=-sunos3
+		# This also exists in the configure program, but was not the
+		# default.
+		# os=-sunos4
+		;;
+	m68*-cisco)
+		os=-aout
+		;;
+        mep-*)
+		os=-elf
+		;;
+	mips*-cisco)
+		os=-elf
+		;;
+	mips*-*)
+		os=-elf
+		;;
+	or32-*)
+		os=-coff
+		;;
+	*-tti)	# must be before sparc entry or we get the wrong os.
+		os=-sysv3
+		;;
+	sparc-* | *-sun)
+		os=-sunos4.1.1
+		;;
+	*-be)
+		os=-beos
+		;;
+	*-haiku)
+		os=-haiku
+		;;
+	*-ibm)
+		os=-aix
+		;;
+    	*-knuth)
+		os=-mmixware
+		;;
+	*-wec)
+		os=-proelf
+		;;
+	*-winbond)
+		os=-proelf
+		;;
+	*-oki)
+		os=-proelf
+		;;
+	*-hp)
+		os=-hpux
+		;;
+	*-hitachi)
+		os=-hiux
+		;;
+	i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+		os=-sysv
+		;;
+	*-cbm)
+		os=-amigaos
+		;;
+	*-dg)
+		os=-dgux
+		;;
+	*-dolphin)
+		os=-sysv3
+		;;
+	m68k-ccur)
+		os=-rtu
+		;;
+	m88k-omron*)
+		os=-luna
+		;;
+	*-next )
+		os=-nextstep
+		;;
+	*-sequent)
+		os=-ptx
+		;;
+	*-crds)
+		os=-unos
+		;;
+	*-ns)
+		os=-genix
+		;;
+	i370-*)
+		os=-mvs
+		;;
+	*-next)
+		os=-nextstep3
+		;;
+	*-gould)
+		os=-sysv
+		;;
+	*-highlevel)
+		os=-bsd
+		;;
+	*-encore)
+		os=-bsd
+		;;
+	*-sgi)
+		os=-irix
+		;;
+	*-siemens)
+		os=-sysv4
+		;;
+	*-masscomp)
+		os=-rtu
+		;;
+	f30[01]-fujitsu | f700-fujitsu)
+		os=-uxpv
+		;;
+	*-rom68k)
+		os=-coff
+		;;
+	*-*bug)
+		os=-coff
+		;;
+	*-apple)
+		os=-macos
+		;;
+	*-atari*)
+		os=-mint
+		;;
+	*)
+		os=-none
+		;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer.  We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+	*-unknown)
+		case $os in
+			-riscix*)
+				vendor=acorn
+				;;
+			-sunos*)
+				vendor=sun
+				;;
+			-aix*)
+				vendor=ibm
+				;;
+			-beos*)
+				vendor=be
+				;;
+			-hpux*)
+				vendor=hp
+				;;
+			-mpeix*)
+				vendor=hp
+				;;
+			-hiux*)
+				vendor=hitachi
+				;;
+			-unos*)
+				vendor=crds
+				;;
+			-dgux*)
+				vendor=dg
+				;;
+			-luna*)
+				vendor=omron
+				;;
+			-genix*)
+				vendor=ns
+				;;
+			-mvs* | -opened*)
+				vendor=ibm
+				;;
+			-os400*)
+				vendor=ibm
+				;;
+			-ptx*)
+				vendor=sequent
+				;;
+			-tpf*)
+				vendor=ibm
+				;;
+			-vxsim* | -vxworks* | -windiss*)
+				vendor=wrs
+				;;
+			-aux*)
+				vendor=apple
+				;;
+			-hms*)
+				vendor=hitachi
+				;;
+			-mpw* | -macos*)
+				vendor=apple
+				;;
+			-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+				vendor=atari
+				;;
+			-vos*)
+				vendor=stratus
+				;;
+		esac
+		basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+		;;
+esac
+
+echo $basic_machine$os
+exit
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/configure b/configure
new file mode 100755
index 0000000..1a23167
--- /dev/null
+++ b/configure
Binary files differ
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..b6bfd07
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,115 @@
+# Process this file with autoconf to produce a configure script.
+AC_PREREQ(2.52)
+AC_INIT([libmtp], [1.0.1], [libmtp-discuss@lists.sourceforge.net])
+AC_CONFIG_MACRO_DIR([m4])
+AM_INIT_AUTOMAKE([foreign])
+AC_CONFIG_SRCDIR([src/libmtp.c])
+AM_CONFIG_HEADER(config.h)
+
+# This can be overridden by the command line switch
+if test "$program_prefix" = NONE; then
+   program_prefix=mtp-
+   program_transform_name="s,^,$program_prefix,;$program_transform_name"
+fi
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_INSTALL
+AC_PROG_LN_S
+AC_LIBTOOL_WIN32_DLL
+AC_PROG_LIBTOOL
+AM_ICONV
+
+# Check for doxygen
+AC_CHECK_PROG(HAVE_DOXYGEN, doxygen, true, false)
+AM_CONDITIONAL(HAVE_DOXYGEN,$HAVE_DOXYGEN)
+if test $HAVE_DOXYGEN = "false"; then
+             AC_MSG_WARN([*** doxygen not found, docs will not be built])
+fi
+
+# Check for Darwin
+AC_MSG_CHECKING([if the host operating system is Darwin])
+case "$host" in
+  *-darwin*)
+    AC_MSG_RESULT([yes])
+    CFLAGS="$CFLAGS -DUSE_DARWIN"
+    OSFLAGS="-framework IOKit"
+    ;;
+  *) AC_MSG_RESULT([no]) ;;
+esac
+AC_SUBST(OSFLAGS)
+
+# Check for mingw compiler platform
+AC_MSG_CHECKING([For MinGW32])
+case "$host" in
+  *-*-mingw*)
+    AC_MSG_RESULT([yes])
+    mingw_compiler=yes
+    ;;
+  *) AC_MSG_RESULT([no]) ;;
+esac
+AM_CONDITIONAL(COMPILE_MINGW32, [test "$mingw_compiler" = "yes"])
+
+# Check if Microsoft LIB.EXE is available
+if test "$mingw_compiler" = "yes"; then
+  AC_CHECK_PROG(ms_lib_exe, lib.exe, yes, no)
+fi
+AM_CONDITIONAL(MS_LIB_EXE, test x$ms_lib_exe = xyes)
+
+# Checks for libraries.
+AC_CHECK_LIB([usb], [usb_control_msg],,
+	AC_MSG_ERROR([I can't find the libusb libraries on your system. You
+	may need to set the LDFLAGS environment variable to include the
+	search path where you have libusb installed before running
+	configure (e.g. setenv LDFLAGS=-L/usr/local/lib)]), "$OSFLAGS")
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_HEADER_TIME
+# zlib.h the day we need to decompress firmware
+AC_CHECK_HEADERS([ctype.h errno.h fcntl.h getopt.h libgen.h \
+	limits.h stdio.h string.h sys/stat.h sys/time.h unistd.h \
+	iconv.h langinfo.h locale.h arpa/inet.h byteswap.h sys/uio.h])
+AC_CHECK_HEADER([usb.h],,
+	AC_MSG_ERROR([I can't find the libusb header file on your system.
+	You may need to set the CPPFLAGS environment variable to include
+	the search path where you have libusb installed before running
+	configure (e.g. setenv CPPFLAGS=-I/usr/local/include)]))
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_TYPE_OFF_T
+AC_TYPE_SIGNAL
+AC_TYPE_SIZE_T
+AC_STRUCT_ST_BLKSIZE
+
+# Checks for library functions.
+AC_FUNC_MALLOC
+AC_FUNC_MEMCMP
+AC_FUNC_STAT
+AC_CHECK_FUNCS(basename memset select strdup strerror strrchr strtoul usleep mkstemp)
+
+# Switches.
+# Enable LFS (Large File Support)
+AC_SYS_LARGEFILE
+# Stick in "-Werror" if you want to be more aggressive.
+# (No need to use AC_SUBST on this default substituted environment variable.)
+CFLAGS="$CFLAGS -Wall -Wmissing-prototypes"
+
+# Output files
+
+# Create a stdint.h-like file containing size-specific integer definitions
+# that will always be available. The <stdint.h> file is required by the
+# library, but we provide this anyway because the libptp2 stuff wants this
+# file.
+AX_NEED_STDINT_H([src/_stdint.h])
+
+# Create a header file containing NetBSD-style byte swapping macros.
+# This m4 macros has caused severe pain, I am considering creating a 
+# hard-coded byte swapper that will be eternally portable.
+AC_NEED_BYTEORDER_H(src/gphoto2-endian.h)
+
+AC_CONFIG_FILES([src/libmtp.h doc/Doxyfile Makefile doc/Makefile src/Makefile
+	examples/Makefile libmtp.sh hotplug.sh libmtp.pc])
+AC_OUTPUT
+chmod +x hotplug.sh
diff --git a/depcomp b/depcomp
new file mode 100755
index 0000000..df8eea7
--- /dev/null
+++ b/depcomp
@@ -0,0 +1,630 @@
+#! /bin/sh
+# depcomp - compile a program generating dependencies as side-effects
+
+scriptversion=2009-04-28.21; # UTC
+
+# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
+# Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program 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 General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
+
+case $1 in
+  '')
+     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: depcomp [--help] [--version] PROGRAM [ARGS]
+
+Run PROGRAMS ARGS to compile a file, generating dependencies
+as side-effects.
+
+Environment variables:
+  depmode     Dependency tracking mode.
+  source      Source file read by `PROGRAMS ARGS'.
+  object      Object file output by `PROGRAMS ARGS'.
+  DEPDIR      directory where to store dependencies.
+  depfile     Dependency file to output.
+  tmpdepfile  Temporary file to use when outputing dependencies.
+  libtool     Whether libtool is used (yes/no).
+
+Report bugs to <bug-automake@gnu.org>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "depcomp $scriptversion"
+    exit $?
+    ;;
+esac
+
+if test -z "$depmode" || test -z "$source" || test -z "$object"; then
+  echo "depcomp: Variables source, object and depmode must be set" 1>&2
+  exit 1
+fi
+
+# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
+depfile=${depfile-`echo "$object" |
+  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
+tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
+
+rm -f "$tmpdepfile"
+
+# Some modes work just like other modes, but use different flags.  We
+# parameterize here, but still list the modes in the big case below,
+# to make depend.m4 easier to write.  Note that we *cannot* use a case
+# here, because this file can only contain one case statement.
+if test "$depmode" = hp; then
+  # HP compiler uses -M and no extra arg.
+  gccflag=-M
+  depmode=gcc
+fi
+
+if test "$depmode" = dashXmstdout; then
+   # This is just like dashmstdout with a different argument.
+   dashmflag=-xM
+   depmode=dashmstdout
+fi
+
+cygpath_u="cygpath -u -f -"
+if test "$depmode" = msvcmsys; then
+   # This is just like msvisualcpp but w/o cygpath translation.
+   # Just convert the backslash-escaped backslashes to single forward
+   # slashes to satisfy depend.m4
+   cygpath_u="sed s,\\\\\\\\,/,g"
+   depmode=msvisualcpp
+fi
+
+case "$depmode" in
+gcc3)
+## gcc 3 implements dependency tracking that does exactly what
+## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
+## it if -MD -MP comes after the -MF stuff.  Hmm.
+## Unfortunately, FreeBSD c89 acceptance of flags depends upon
+## the command line argument order; so add the flags where they
+## appear in depend2.am.  Note that the slowdown incurred here
+## affects only configure: in makefiles, %FASTDEP% shortcuts this.
+  for arg
+  do
+    case $arg in
+    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
+    *)  set fnord "$@" "$arg" ;;
+    esac
+    shift # fnord
+    shift # $arg
+  done
+  "$@"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  mv "$tmpdepfile" "$depfile"
+  ;;
+
+gcc)
+## There are various ways to get dependency output from gcc.  Here's
+## why we pick this rather obscure method:
+## - Don't want to use -MD because we'd like the dependencies to end
+##   up in a subdir.  Having to rename by hand is ugly.
+##   (We might end up doing this anyway to support other compilers.)
+## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
+##   -MM, not -M (despite what the docs say).
+## - Using -M directly means running the compiler twice (even worse
+##   than renaming).
+  if test -z "$gccflag"; then
+    gccflag=-MD,
+  fi
+  "$@" -Wp,"$gccflag$tmpdepfile"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
+## The second -e expression handles DOS-style file names with drive letters.
+  sed -e 's/^[^:]*: / /' \
+      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
+## This next piece of magic avoids the `deleted header file' problem.
+## The problem is that when a header file which appears in a .P file
+## is deleted, the dependency causes make to die (because there is
+## typically no way to rebuild the header).  We avoid this by adding
+## dummy dependencies for each header file.  Too bad gcc doesn't do
+## this for us directly.
+  tr ' ' '
+' < "$tmpdepfile" |
+## Some versions of gcc put a space before the `:'.  On the theory
+## that the space means something, we add a space to the output as
+## well.
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+sgi)
+  if test "$libtool" = yes; then
+    "$@" "-Wp,-MDupdate,$tmpdepfile"
+  else
+    "$@" -MDupdate "$tmpdepfile"
+  fi
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+
+  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
+    echo "$object : \\" > "$depfile"
+
+    # Clip off the initial element (the dependent).  Don't try to be
+    # clever and replace this with sed code, as IRIX sed won't handle
+    # lines with more than a fixed number of characters (4096 in
+    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
+    # the IRIX cc adds comments like `#:fec' to the end of the
+    # dependency line.
+    tr ' ' '
+' < "$tmpdepfile" \
+    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
+    tr '
+' ' ' >> "$depfile"
+    echo >> "$depfile"
+
+    # The second pass generates a dummy entry for each header file.
+    tr ' ' '
+' < "$tmpdepfile" \
+   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
+   >> "$depfile"
+  else
+    # The sourcefile does not contain any dependencies, so just
+    # store a dummy comment line, to avoid errors with the Makefile
+    # "include basename.Plo" scheme.
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile"
+  ;;
+
+aix)
+  # The C for AIX Compiler uses -M and outputs the dependencies
+  # in a .u file.  In older versions, this file always lives in the
+  # current directory.  Also, the AIX compiler puts `$object:' at the
+  # start of each line; $object doesn't have directory information.
+  # Version 6 uses the directory in both cases.
+  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+  test "x$dir" = "x$object" && dir=
+  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$base.u
+    tmpdepfile3=$dir.libs/$base.u
+    "$@" -Wc,-M
+  else
+    tmpdepfile1=$dir$base.u
+    tmpdepfile2=$dir$base.u
+    tmpdepfile3=$dir$base.u
+    "$@" -M
+  fi
+  stat=$?
+
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+    exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    # Each line is of the form `foo.o: dependent.h'.
+    # Do two passes, one to just change these to
+    # `$object: dependent.h' and one to simply `dependent.h:'.
+    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
+    # That's a tab and a space in the [].
+    sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
+  else
+    # The sourcefile does not contain any dependencies, so just
+    # store a dummy comment line, to avoid errors with the Makefile
+    # "include basename.Plo" scheme.
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile"
+  ;;
+
+icc)
+  # Intel's C compiler understands `-MD -MF file'.  However on
+  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
+  # ICC 7.0 will fill foo.d with something like
+  #    foo.o: sub/foo.c
+  #    foo.o: sub/foo.h
+  # which is wrong.  We want:
+  #    sub/foo.o: sub/foo.c
+  #    sub/foo.o: sub/foo.h
+  #    sub/foo.c:
+  #    sub/foo.h:
+  # ICC 7.1 will output
+  #    foo.o: sub/foo.c sub/foo.h
+  # and will wrap long lines using \ :
+  #    foo.o: sub/foo.c ... \
+  #     sub/foo.h ... \
+  #     ...
+
+  "$@" -MD -MF "$tmpdepfile"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  # Each line is of the form `foo.o: dependent.h',
+  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
+  # Do two passes, one to just change these to
+  # `$object: dependent.h' and one to simply `dependent.h:'.
+  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process this invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
+    sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+hp2)
+  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
+  # compilers, which have integrated preprocessors.  The correct option
+  # to use with these is +Maked; it writes dependencies to a file named
+  # 'foo.d', which lands next to the object file, wherever that
+  # happens to be.
+  # Much of this is similar to the tru64 case; see comments there.
+  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+  test "x$dir" = "x$object" && dir=
+  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir.libs/$base.d
+    "$@" -Wc,+Maked
+  else
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir$base.d
+    "$@" +Maked
+  fi
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+     rm -f "$tmpdepfile1" "$tmpdepfile2"
+     exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
+    # Add `dependent.h:' lines.
+    sed -ne '2,${
+	       s/^ *//
+	       s/ \\*$//
+	       s/$/:/
+	       p
+	     }' "$tmpdepfile" >> "$depfile"
+  else
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile" "$tmpdepfile2"
+  ;;
+
+tru64)
+   # The Tru64 compiler uses -MD to generate dependencies as a side
+   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
+   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
+   # dependencies in `foo.d' instead, so we check for that too.
+   # Subdirectories are respected.
+   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+   test "x$dir" = "x$object" && dir=
+   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+
+   if test "$libtool" = yes; then
+      # With Tru64 cc, shared objects can also be used to make a
+      # static library.  This mechanism is used in libtool 1.4 series to
+      # handle both shared and static libraries in a single compilation.
+      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
+      #
+      # With libtool 1.5 this exception was removed, and libtool now
+      # generates 2 separate objects for the 2 libraries.  These two
+      # compilations output dependencies in $dir.libs/$base.o.d and
+      # in $dir$base.o.d.  We have to check for both files, because
+      # one of the two compilations can be disabled.  We should prefer
+      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
+      # automatically cleaned when .libs/ is deleted, while ignoring
+      # the former would cause a distcleancheck panic.
+      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
+      tmpdepfile2=$dir$base.o.d          # libtool 1.5
+      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
+      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
+      "$@" -Wc,-MD
+   else
+      tmpdepfile1=$dir$base.o.d
+      tmpdepfile2=$dir$base.d
+      tmpdepfile3=$dir$base.d
+      tmpdepfile4=$dir$base.d
+      "$@" -MD
+   fi
+
+   stat=$?
+   if test $stat -eq 0; then :
+   else
+      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
+      exit $stat
+   fi
+
+   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
+   do
+     test -f "$tmpdepfile" && break
+   done
+   if test -f "$tmpdepfile"; then
+      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
+      # That's a tab and a space in the [].
+      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
+   else
+      echo "#dummy" > "$depfile"
+   fi
+   rm -f "$tmpdepfile"
+   ;;
+
+#nosideeffect)
+  # This comment above is used by automake to tell side-effect
+  # dependency tracking mechanisms from slower ones.
+
+dashmstdout)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout, regardless of -o.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove `-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
+      ;;
+    esac
+  done
+
+  test -z "$dashmflag" && dashmflag=-M
+  # Require at least two characters before searching for `:'
+  # in the target name.  This is to cope with DOS-style filenames:
+  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
+  "$@" $dashmflag |
+    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
+  rm -f "$depfile"
+  cat < "$tmpdepfile" > "$depfile"
+  tr ' ' '
+' < "$tmpdepfile" | \
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+dashXmstdout)
+  # This case only exists to satisfy depend.m4.  It is never actually
+  # run, as this mode is specially recognized in the preamble.
+  exit 1
+  ;;
+
+makedepend)
+  "$@" || exit $?
+  # Remove any Libtool call
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+  # X makedepend
+  shift
+  cleared=no eat=no
+  for arg
+  do
+    case $cleared in
+    no)
+      set ""; shift
+      cleared=yes ;;
+    esac
+    if test $eat = yes; then
+      eat=no
+      continue
+    fi
+    case "$arg" in
+    -D*|-I*)
+      set fnord "$@" "$arg"; shift ;;
+    # Strip any option that makedepend may not understand.  Remove
+    # the object too, otherwise makedepend will parse it as a source file.
+    -arch)
+      eat=yes ;;
+    -*|$object)
+      ;;
+    *)
+      set fnord "$@" "$arg"; shift ;;
+    esac
+  done
+  obj_suffix=`echo "$object" | sed 's/^.*\././'`
+  touch "$tmpdepfile"
+  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
+  rm -f "$depfile"
+  cat < "$tmpdepfile" > "$depfile"
+  sed '1,2d' "$tmpdepfile" | tr ' ' '
+' | \
+## Some versions of the HPUX 10.20 sed can't process this invocation
+## correctly.  Breaking it into two sed invocations is a workaround.
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile" "$tmpdepfile".bak
+  ;;
+
+cpp)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  # Remove `-o $object'.
+  IFS=" "
+  for arg
+  do
+    case $arg in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    *)
+      set fnord "$@" "$arg"
+      shift # fnord
+      shift # $arg
+      ;;
+    esac
+  done
+
+  "$@" -E |
+    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
+    sed '$ s: \\$::' > "$tmpdepfile"
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  cat < "$tmpdepfile" >> "$depfile"
+  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+msvisualcpp)
+  # Important note: in order to support this mode, a compiler *must*
+  # always write the preprocessed file to stdout.
+  "$@" || exit $?
+
+  # Remove the call to Libtool.
+  if test "$libtool" = yes; then
+    while test "X$1" != 'X--mode=compile'; do
+      shift
+    done
+    shift
+  fi
+
+  IFS=" "
+  for arg
+  do
+    case "$arg" in
+    -o)
+      shift
+      ;;
+    $object)
+      shift
+      ;;
+    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
+	set fnord "$@"
+	shift
+	shift
+	;;
+    *)
+	set fnord "$@" "$arg"
+	shift
+	shift
+	;;
+    esac
+  done
+  "$@" -E 2>/dev/null |
+  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
+  rm -f "$depfile"
+  echo "$object : \\" > "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
+  echo "	" >> "$depfile"
+  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
+msvcmsys)
+  # This case exists only to let depend.m4 do its work.  It works by
+  # looking at the text of this script.  This case will never be run,
+  # since it is checked for above.
+  exit 1
+  ;;
+
+none)
+  exec "$@"
+  ;;
+
+*)
+  echo "Unknown depmode $depmode" 1>&2
+  exit 1
+  ;;
+esac
+
+exit 0
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in
new file mode 100644
index 0000000..65c2b83
--- /dev/null
+++ b/doc/Doxyfile.in
@@ -0,0 +1,1143 @@
+# Doxyfile 1.3.9.1
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project
+#
+# All text after a hash (#) is considered a comment and will be ignored
+# The format is:
+#       TAG = value [value, ...]
+# For lists items can also be appended using:
+#       TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ")
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded 
+# by quotes) that should identify the project.
+
+PROJECT_NAME           =  "libmtp"
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number. 
+# This could be handy for archiving the generated documentation or 
+# if some version control system is used.
+# Do this with autoconf eventually
+
+PROJECT_NUMBER         = @VERSION@
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) 
+# base path where the generated documentation will be put. 
+# If a relative path is entered, it will be relative to the location 
+# where doxygen was started. If left blank the current directory will be used.
+
+#OUTPUT_DIRECTORY       = .
+
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 
+# 4096 sub-directories (in 2 levels) under the output directory of each output 
+# format and will distribute the generated files over these directories. 
+# Enabling this option can be useful when feeding doxygen a huge amount of source 
+# files, where putting all generated files in the same directory would otherwise 
+# cause performance problems for the file system.
+
+CREATE_SUBDIRS         = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all 
+# documentation generated by doxygen is written. Doxygen will use this 
+# information to generate all constant output in the proper language. 
+# The default language is English, other supported languages are: 
+# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, 
+# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, 
+# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, 
+# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, 
+# Swedish, and Ukrainian.
+
+OUTPUT_LANGUAGE        = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will 
+# include brief member descriptions after the members that are listed in 
+# the file and class documentation (similar to JavaDoc). 
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC      = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend 
+# the brief description of a member or function before the detailed description. 
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the 
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF           = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator 
+# that is used to form the text in various listings. Each string 
+# in this list, if found as the leading text of the brief description, will be 
+# stripped from the text and the result after processing the whole list, is used 
+# as the annotated text. Otherwise, the brief description is used as-is. If left 
+# blank, the following values are used ("$name" is automatically replaced with the 
+# name of the entity): "The $name class" "The $name widget" "The $name file" 
+# "is" "provides" "specifies" "contains" "represents" "a" "an" "the"
+
+ABBREVIATE_BRIEF       = 
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then 
+# Doxygen will generate a detailed section even if there is only a brief 
+# description.
+
+ALWAYS_DETAILED_SEC    = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all inherited 
+# members of a class in the documentation of that class as if those members were 
+# ordinary class members. Constructors, destructors and assignment operators of 
+# the base classes will not be shown.
+
+INLINE_INHERITED_MEMB  = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full 
+# path before files name in the file list and in the header files. If set 
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES        = YES
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag 
+# can be used to strip a user-defined part of the path. Stripping is 
+# only done if one of the specified strings matches the left-hand part of 
+# the path. The tag can be used to show relative paths in the file list. 
+# If left blank the directory from which doxygen is run is used as the 
+# path to strip.
+
+STRIP_FROM_PATH        = 
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of 
+# the path mentioned in the documentation of a class, which tells 
+# the reader which header file to include in order to use a class. 
+# If left blank only the name of the header file containing the class 
+# definition is used. Otherwise one should specify the include paths that 
+# are normally passed to the compiler using the -I flag.
+
+STRIP_FROM_INC_PATH    = 
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter 
+# (but less readable) file names. This can be useful is your file systems 
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES            = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen 
+# will interpret the first line (until the first dot) of a JavaDoc-style 
+# comment as the brief description. If set to NO, the JavaDoc 
+# comments will behave just like the Qt-style comments (thus requiring an 
+# explicit @brief command for a brief description.
+
+JAVADOC_AUTOBRIEF      = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen 
+# treat a multi-line C++ special comment block (i.e. a block of //! or /// 
+# comments) as a brief description. This used to be the default behaviour. 
+# The new default is to treat a multi-line C++ comment block as a detailed 
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the DETAILS_AT_TOP tag is set to YES then Doxygen 
+# will output the detailed description near the top, like JavaDoc.
+# If set to NO, the detailed description appears after the member 
+# documentation.
+
+# DETAILS_AT_TOP         = NO
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented 
+# member inherits the documentation from any documented member that it 
+# re-implements.
+
+INHERIT_DOCS           = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC 
+# tag is set to YES, then doxygen will reuse the documentation of the first 
+# member in the group (if any) for the other members of the group. By default 
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC   = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab. 
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE               = 8
+
+# This tag can be used to specify a number of aliases that acts 
+# as commands in the documentation. An alias has the form "name=value". 
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to 
+# put the command \sideeffect (or @sideeffect) in the documentation, which 
+# will result in a user-defined paragraph with heading "Side Effects:". 
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES                = 
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources 
+# only. Doxygen will then generate output that is more tailored for C. 
+# For instance, some of the names that are used will be different. The list 
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C  = YES
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources 
+# only. Doxygen will then generate output that is more tailored for Java. 
+# For instance, namespaces will be presented as packages, qualified scopes 
+# will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA   = NO
+
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of 
+# the same type (for instance a group of public functions) to be put as a 
+# subgroup of that type (e.g. under the Public Functions section). Set it to 
+# NO to prevent subgrouping. Alternatively, this can be done per class using 
+# the \nosubgrouping command.
+
+SUBGROUPING            = YES
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in 
+# documentation are documented, even if no documentation was available. 
+# Private class members and static file members will be hidden unless 
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL            = NO
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class 
+# will be included in the documentation.
+
+EXTRACT_PRIVATE        = NO
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file 
+# will be included in the documentation.
+
+EXTRACT_STATIC         = NO
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) 
+# defined locally in source files will be included in the documentation. 
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES  = YES
+
+# This flag is only useful for Objective-C code. When set to YES local 
+# methods, which are defined in the implementation section but not in 
+# the interface are included in the documentation. 
+# If set to NO (the default) only methods in the interface are included.
+
+EXTRACT_LOCAL_METHODS  = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all 
+# undocumented members of documented classes, files or namespaces. 
+# If set to NO (the default) these members will be included in the 
+# various overviews, but no documentation section is generated. 
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS     = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all 
+# undocumented classes that are normally visible in the class hierarchy. 
+# If set to NO (the default) these classes will be included in the various 
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES     = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all 
+# friend (class|struct|union) declarations. 
+# If set to NO (the default) these declarations will be included in the 
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS  = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any 
+# documentation blocks found inside the body of a function. 
+# If set to NO (the default) these blocks will be appended to the 
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS      = NO
+
+# The INTERNAL_DOCS tag determines if documentation 
+# that is typed after a \internal command is included. If the tag is set 
+# to NO (the default) then the documentation will be excluded. 
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS          = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate 
+# file names in lower-case letters. If set to YES upper-case letters are also 
+# allowed. This is useful if you have classes or files whose names only differ 
+# in case and if your file system supports case sensitive file names. Windows 
+# and Mac users are advised to set this option to NO.
+
+CASE_SENSE_NAMES       = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen 
+# will show members with their full class and namespace scopes in the 
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES       = NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen 
+# will put a list of the files that are included by a file in the documentation 
+# of that file.
+
+SHOW_INCLUDE_FILES     = YES
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] 
+# is inserted in the documentation for inline members.
+
+INLINE_INFO            = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen 
+# will sort the (detailed) documentation of file and class members 
+# alphabetically by member name. If set to NO the members will appear in 
+# declaration order.
+
+SORT_MEMBER_DOCS       = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the 
+# brief documentation of file, namespace and class members alphabetically 
+# by member name. If set to NO (the default) the members will appear in 
+# declaration order.
+
+SORT_BRIEF_DOCS        = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be 
+# sorted by fully-qualified names, including namespaces. If set to 
+# NO (the default), the class list will be sorted only by class name, 
+# not including the namespace part. 
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the 
+# alphabetical list.
+
+SORT_BY_SCOPE_NAME     = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or 
+# disable (NO) the todo list. This list is created by putting \todo 
+# commands in the documentation.
+
+GENERATE_TODOLIST      = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or 
+# disable (NO) the test list. This list is created by putting \test 
+# commands in the documentation.
+
+GENERATE_TESTLIST      = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or 
+# disable (NO) the bug list. This list is created by putting \bug 
+# commands in the documentation.
+
+GENERATE_BUGLIST       = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or 
+# disable (NO) the deprecated list. This list is created by putting 
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional 
+# documentation sections, marked by \if sectionname ... \endif.
+
+ENABLED_SECTIONS       = 
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines 
+# the initial value of a variable or define consists of for it to appear in 
+# the documentation. If the initializer consists of more lines than specified 
+# here it will be hidden. Use a value of 0 to hide initializers completely. 
+# The appearance of the initializer of individual variables and defines in the 
+# documentation can be controlled using \showinitializer or \hideinitializer 
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES  = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated 
+# at the bottom of the documentation of classes and structs. If set to YES the 
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES        = YES
+
+# If the sources in your project are distributed over multiple directories 
+# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy 
+# in the documentation.
+
+SHOW_DIRECTORIES       = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated 
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+# Set to YES by Linus Walleij on 2005-07-30.
+
+QUIET                  = YES
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are 
+# generated by doxygen. Possible values are YES and NO. If left blank 
+# NO is used.
+# Set to NO by Linus Walleij on 2005-07-30.
+
+WARNINGS               = NO
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings 
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will 
+# automatically be disabled.
+# Set to NO by Linus Walleij on 2005-07-30.
+
+WARN_IF_UNDOCUMENTED   = NO
+
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for 
+# potential errors in the documentation, such as not documenting some 
+# parameters in a documented function, or documenting parameters that 
+# don't exist or using markup commands wrongly.
+# Set to NO by Linus Walleij on 2005-07-30.
+
+WARN_IF_DOC_ERROR      = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that 
+# doxygen can produce. The string should contain the $file, $line, and $text 
+# tags, which will be replaced by the file and line number from which the 
+# warning originated and the warning text.
+
+WARN_FORMAT            = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning 
+# and error messages should be written. If left blank the output is written 
+# to stderr.
+
+WARN_LOGFILE           = 
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain 
+# documented source files. You may enter file names like "myfile.cpp" or 
+# directories like "/usr/src/myproject". Separate the files or directories 
+# with spaces.
+
+INPUT = @top_srcdir@/src \
+	@top_srcdir@/doc/mainpage.h \
+	@top_srcdir@/doc/examples.h
+
+# If the value of the INPUT tag contains directories, you can use the 
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
+# and *.h) to filter out the source-files in the directories. If left 
+# blank the following patterns are tested: 
+# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx *.hpp 
+# *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm
+
+FILE_PATTERNS          = *.c *.h
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories 
+# should be searched for input files as well. Possible values are YES and NO. 
+# If left blank NO is used.
+
+RECURSIVE              = NO
+
+# The EXCLUDE tag can be used to specify files and/or directories that should 
+# excluded from the INPUT source files. This way you can easily exclude a 
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+EXCLUDE                = 
+
+# The EXCLUDE_SYMLINKS tag can be used select whether or not files or directories 
+# that are symbolic links (a Unix filesystem feature) are excluded from the input.
+
+EXCLUDE_SYMLINKS       = NO
+
+# If the value of the INPUT tag contains directories, you can use the 
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude 
+# certain files from those directories.
+
+EXCLUDE_PATTERNS       = 
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or 
+# directories that contain example code fragments that are included (see 
+# the \include command).
+
+EXAMPLE_PATH           = @top_srcdir@/examples
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the 
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
+# and *.h) to filter out the source-files in the directories. If left 
+# blank all files are included.
+
+EXAMPLE_PATTERNS       = *.c
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be 
+# searched for input files to be used with the \include or \dontinclude 
+# commands irrespective of the value of the RECURSIVE tag. 
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE      = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or 
+# directories that contain image that are included in the documentation (see 
+# the \image command).
+
+IMAGE_PATH             = 
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should 
+# invoke to filter for each input file. Doxygen will invoke the filter program 
+# by executing (via popen()) the command <filter> <input-file>, where <filter> 
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an 
+# input file. Doxygen will then use the output that the filter program writes 
+# to standard output.  If FILTER_PATTERNS is specified, this tag will be 
+# ignored.
+
+INPUT_FILTER           = 
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern 
+# basis.  Doxygen will compare the file name with each pattern and apply the 
+# filter if there is a match.  The filters are a list of the form: 
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further 
+# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER 
+# is applied to all files.
+
+FILTER_PATTERNS        = 
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using 
+# INPUT_FILTER) will be used to filter the input files when producing source 
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES    = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will 
+# be generated. Documented entities will be cross-referenced with these sources. 
+# Note: To get rid of all source code in the generated output, make sure also 
+# VERBATIM_HEADERS is set to NO.
+
+SOURCE_BROWSER         = NO
+
+# Setting the INLINE_SOURCES tag to YES will include the body 
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES         = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct 
+# doxygen to hide any special comment blocks from generated source code 
+# fragments. Normal C and C++ comments will always remain visible.
+
+STRIP_CODE_COMMENTS    = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES (the default) 
+# then for each documented function all documented 
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = YES
+
+# If the REFERENCES_RELATION tag is set to YES (the default) 
+# then for each documented function all documented entities 
+# called/used by that function will be listed.
+
+REFERENCES_RELATION    = YES
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen 
+# will generate a verbatim copy of the header file for each class for 
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS       = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index 
+# of all compounds will be generated. Enable this if the project 
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX     = NO
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then 
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns 
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX    = 5
+
+# In case all classes in a project start with a common prefix, all 
+# classes will be put under the same header in the alphabetical index. 
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that 
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX          = 
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will 
+# generate HTML output.
+
+GENERATE_HTML          = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT            = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for 
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank 
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION    = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for 
+# each generated HTML page. If it is left blank doxygen will generate a 
+# standard header.
+# doc/libnjb_header.html
+
+HTML_HEADER            = 
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for 
+# each generated HTML page. If it is left blank doxygen will generate a 
+# standard footer.
+
+HTML_FOOTER            = 
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading 
+# style sheet that is used by each HTML page. It can be used to 
+# fine-tune the look of the HTML output. If the tag is left blank doxygen 
+# will generate a default style sheet. Note that doxygen will try to copy 
+# the style sheet file to the HTML output directory, so don't put your own 
+# stylesheet in the HTML output directory as well, or it will be erased!
+
+HTML_STYLESHEET        = 
+
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, 
+# files or namespaces will be aligned in HTML using tables. If set to 
+# NO a bullet list will be used.
+
+HTML_ALIGN_MEMBERS     = YES
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files 
+# will be generated that can be used as input for tools like the 
+# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) 
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP      = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can 
+# be used to specify the file name of the resulting .chm file. You 
+# can add a path in front of the file if the result should not be 
+# written to the html output directory.
+
+CHM_FILE               = 
+
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can 
+# be used to specify the location (absolute path including file name) of 
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run 
+# the HTML help compiler on the generated index.hhp.
+
+HHC_LOCATION           = 
+
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag 
+# controls if a separate .chi index file is generated (YES) or that 
+# it should be included in the master .chm file (NO).
+
+GENERATE_CHI           = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag 
+# controls whether a binary table of contents is generated (YES) or a 
+# normal table of contents (NO) in the .chm file.
+
+BINARY_TOC             = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members 
+# to the contents of the HTML help documentation and to the tree view.
+
+TOC_EXPAND             = NO
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at 
+# top of each HTML page. The value NO (the default) enables the index and 
+# the value YES disables it.
+
+DISABLE_INDEX          = NO
+
+# This tag can be used to set the number of enum values (range [1..20]) 
+# that doxygen will group on one line in the generated HTML documentation.
+
+ENUM_VALUES_PER_LINE   = 4
+
+# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be
+# generated containing a tree-like index structure (just like the one that 
+# is generated for HTML Help). For this to work a browser that supports 
+# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, 
+# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are 
+# probably better off using the HTML help feature.
+
+GENERATE_TREEVIEW      = NO
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be 
+# used to set the initial width (in pixels) of the frame in which the tree 
+# is shown.
+
+TREEVIEW_WIDTH         = 250
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will 
+# generate Latex output.
+
+GENERATE_LATEX         = YES
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT           = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be 
+# invoked. If left blank `latex' will be used as the default command name.
+
+LATEX_CMD_NAME         = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to 
+# generate index for LaTeX. If left blank `makeindex' will be used as the 
+# default command name.
+
+MAKEINDEX_CMD_NAME     = makeindex
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact 
+# LaTeX documents. This may be useful for small projects and may help to 
+# save some trees in general.
+
+COMPACT_LATEX          = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used 
+# by the printer. Possible values are: a4, a4wide, letter, legal and 
+# executive. If left blank a4wide will be used.
+
+PAPER_TYPE             = a4wide
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX 
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES         = 
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for 
+# the generated latex document. The header should contain everything until 
+# the first chapter. If it is left blank doxygen will generate a 
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER           = 
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated 
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will 
+# contain links (just like the HTML output) instead of page references 
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS         = NO
+
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of 
+# plain latex in the generated Makefile. Set this option to YES to get a 
+# higher quality PDF documentation.
+
+USE_PDFLATEX           = NO
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. 
+# command to the generated LaTeX files. This will instruct LaTeX to keep 
+# running if errors occur, instead of asking the user for help. 
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE        = NO
+
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not 
+# include the index chapters (such as File Index, Compound Index, etc.) 
+# in the output.
+
+LATEX_HIDE_INDICES     = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output 
+# The RTF output is optimized for Word 97 and may not look very pretty with 
+# other RTF readers or editors.
+
+GENERATE_RTF           = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT             = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact 
+# RTF documents. This may be useful for small projects and may help to 
+# save some trees in general.
+
+COMPACT_RTF            = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated 
+# will contain hyperlink fields. The RTF file will 
+# contain links (just like the HTML output) instead of page references. 
+# This makes the output suitable for online browsing using WORD or other 
+# programs which support those fields. 
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS         = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's 
+# config file, i.e. a series of assignments. You only have to provide 
+# replacements, missing definitions are set to their default value.
+
+RTF_STYLESHEET_FILE    = 
+
+# Set optional variables used in the generation of an rtf document. 
+# Syntax is similar to doxygen's config file.
+
+RTF_EXTENSIONS_FILE    = 
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will 
+# generate man pages
+
+GENERATE_MAN           = YES
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT             = man
+
+# The MAN_EXTENSION tag determines the extension that is added to 
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION          = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output, 
+# then it will generate one additional man file for each entity 
+# documented in the real man page(s). These additional files 
+# only source the real man page, but without them the man command 
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS              = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES Doxygen will 
+# generate an XML file that captures the structure of 
+# the code including all documentation.
+
+GENERATE_XML           = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `xml' will be used as the default path.
+
+XML_OUTPUT             = xml
+
+# The XML_SCHEMA tag can be used to specify an XML schema, 
+# which can be used by a validating XML parser to check the 
+# syntax of the XML files.
+
+XML_SCHEMA             = 
+
+# The XML_DTD tag can be used to specify an XML DTD, 
+# which can be used by a validating XML parser to check the 
+# syntax of the XML files.
+
+XML_DTD                = 
+
+# If the XML_PROGRAMLISTING tag is set to YES Doxygen will 
+# dump the program listings (including syntax highlighting 
+# and cross-referencing information) to the XML output. Note that 
+# enabling this will significantly increase the size of the XML output.
+
+XML_PROGRAMLISTING     = YES
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will 
+# generate an AutoGen Definitions (see autogen.sf.net) file 
+# that captures the structure of the code including all 
+# documentation. Note that this feature is still experimental 
+# and incomplete at the moment.
+
+GENERATE_AUTOGEN_DEF   = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will 
+# generate a Perl module file that captures the structure of 
+# the code including all documentation. Note that this 
+# feature is still experimental and incomplete at the 
+# moment.
+
+GENERATE_PERLMOD       = NO
+
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate 
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able 
+# to generate PDF and DVI output from the Perl module output.
+
+PERLMOD_LATEX          = NO
+
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be 
+# nicely formatted so it can be parsed by a human reader.  This is useful 
+# if you want to understand what is going on.  On the other hand, if this 
+# tag is set to NO the size of the Perl module output will be much smaller 
+# and Perl will parse it just the same.
+
+PERLMOD_PRETTY         = YES
+
+# The names of the make variables in the generated doxyrules.make file 
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. 
+# This is useful so different doxyrules.make files included by the same 
+# Makefile don't overwrite each other's variables.
+
+PERLMOD_MAKEVAR_PREFIX = 
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor   
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will 
+# evaluate all C-preprocessor directives found in the sources and include 
+# files.
+
+ENABLE_PREPROCESSING   = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro 
+# names in the source code. If set to NO (the default) only conditional 
+# compilation will be performed. Macro expansion can be done in a controlled 
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION        = NO
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES 
+# then the macro expansion is limited to the macros specified with the 
+# PREDEFINED and EXPAND_AS_PREDEFINED tags.
+
+EXPAND_ONLY_PREDEF     = NO
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files 
+# in the INCLUDE_PATH (see below) will be search if a #include is found.
+
+SEARCH_INCLUDES        = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that 
+# contain include files that are not input files but should be processed by 
+# the preprocessor.
+
+INCLUDE_PATH           = 
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard 
+# patterns (like *.h and *.hpp) to filter out the header-files in the 
+# directories. If left blank, the patterns specified with FILE_PATTERNS will 
+# be used.
+
+INCLUDE_FILE_PATTERNS  = 
+
+# The PREDEFINED tag can be used to specify one or more macro names that 
+# are defined before the preprocessor is started (similar to the -D option of 
+# gcc). The argument of the tag is a list of macros of the form: name 
+# or name=definition (no spaces). If the definition and the = are 
+# omitted =1 is assumed. To prevent a macro definition from being 
+# undefined via #undef or recursively expanded use the := operator 
+# instead of the = operator.
+
+PREDEFINED             = 
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then 
+# this tag can be used to specify a list of macro names that should be expanded. 
+# The macro definition that is found in the sources will be used. 
+# Use the PREDEFINED tag if you want to use a different macro definition.
+
+EXPAND_AS_DEFINED      = 
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then 
+# doxygen's preprocessor will remove all function-like macros that are alone 
+# on a line, have an all uppercase name, and do not end with a semicolon. Such 
+# function macros are typically used for boiler-plate code, and will confuse the 
+# parser if not removed.
+
+SKIP_FUNCTION_MACROS   = NO
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references   
+#---------------------------------------------------------------------------
+
+# The TAGFILES option can be used to specify one or more tagfiles. 
+# Optionally an initial location of the external documentation 
+# can be added for each tagfile. The format of a tag file without 
+# this location is as follows: 
+#   TAGFILES = file1 file2 ... 
+# Adding location for the tag files is done as follows: 
+#   TAGFILES = file1=loc1 "file2 = loc2" ... 
+# where "loc1" and "loc2" can be relative or absolute paths or 
+# URLs. If a location is present for each tag, the installdox tool 
+# does not have to be run to correct the links.
+# Note that each tag file must have a unique name
+# (where the name does NOT include the path)
+# If a tag file is not located in the directory in which doxygen 
+# is run, you must also specify the path to the tagfile here.
+
+TAGFILES               = 
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create 
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE       = 
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed 
+# in the class index. If set to NO only the inherited external classes 
+# will be listed.
+
+ALLEXTERNALS           = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed 
+# in the modules index. If set to NO, only the current project's groups will 
+# be listed.
+
+EXTERNAL_GROUPS        = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script 
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH              = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool   
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will 
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base or 
+# super classes. Setting the tag to NO turns the diagrams off. Note that this 
+# option is superseded by the HAVE_DOT option below. This is only a fallback. It is 
+# recommended to install and use dot, since it yields more powerful graphs.
+
+CLASS_DIAGRAMS         = YES
+
+# If set to YES, the inheritance and collaboration graphs will hide 
+# inheritance and usage relations if the target is undocumented 
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS   = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is 
+# available from the path. This tool is part of Graphviz, a graph visualization 
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section 
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT               = NO
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen 
+# will generate a graph for each documented class showing the direct and 
+# indirect inheritance relations. Setting this tag to YES will force the 
+# the CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH            = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen 
+# will generate a graph for each documented class showing the direct and 
+# indirect implementation dependencies (inheritance, containment, and 
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH    = YES
+
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and 
+# collaboration diagrams in a style similar to the OMG's Unified Modeling 
+# Language.
+
+UML_LOOK               = NO
+
+# If set to YES, the inheritance and collaboration graphs will show the 
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS     = NO
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT 
+# tags are set to YES then doxygen will generate a graph for each documented 
+# file showing the direct and indirect include dependencies of the file with 
+# other documented files.
+
+INCLUDE_GRAPH          = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and 
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each 
+# documented header file showing the documented files that directly or 
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH      = YES
+
+# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will 
+# generate a call dependency graph for every global function or class method. 
+# Note that enabling this option will significantly increase the time of a run. 
+# So in most cases it will be better to enable call graphs for selected 
+# functions only using the \callgraph command.
+
+CALL_GRAPH             = NO
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen 
+# will graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY    = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images 
+# generated by dot. Possible values are png, jpg, or gif
+# If left blank png will be used.
+
+DOT_IMAGE_FORMAT       = png
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be 
+# found. If left blank, it is assumed the dot tool can be found on the path.
+
+DOT_PATH               = 
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that 
+# contain dot files that are included in the documentation (see the 
+# \dotfile command).
+
+DOTFILE_DIRS           = 
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the 
+# graphs generated by dot. A depth value of 3 means that only nodes reachable 
+# from the root by following a path via at most 3 edges will be shown. Nodes that 
+# lay further from the root node will be omitted. Note that setting this option to 
+# 1 or 2 may greatly reduce the computation time needed for large code bases. Also 
+# note that a graph may be further truncated if the graph's image dimensions are 
+# not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH and MAX_DOT_GRAPH_HEIGHT). 
+# If 0 is used for the depth value (the default), the graph is not depth-constrained.
+
+MAX_DOT_GRAPH_DEPTH    = 0
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will 
+# generate a legend page explaining the meaning of the various boxes and 
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND        = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will 
+# remove the intermediate dot files that are used to generate 
+# the various graphs.
+
+DOT_CLEANUP            = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to the search engine   
+#---------------------------------------------------------------------------
+
+# The SEARCHENGINE tag specifies whether or not a search engine should be 
+# used. If set to NO the values of all tags below this one will be ignored.
+
+SEARCHENGINE           = NO
diff --git a/doc/Makefile.am b/doc/Makefile.am
new file mode 100644
index 0000000..2a0250b
--- /dev/null
+++ b/doc/Makefile.am
@@ -0,0 +1,20 @@
+EXTRA_DIST=Doxyfile.in examples.h mainpage.h
+
+if HAVE_DOXYGEN
+pkgdocdir=$(datadir)/doc/$(PACKAGE)-$(VERSION)
+htmldocdir=$(pkgdocdir)/html
+
+all-local:
+	doxygen
+
+install-data-local:
+	$(INSTALL) -d $(DESTDIR)$(htmldocdir)
+	$(INSTALL_DATA) html/* $(DESTDIR)$(htmldocdir)
+
+uninstall-local:
+	$(RM) -r $(DESTDIR)$(htmldocdir)
+	$(RM) -r $(DESTDIR)$(pkgdocdir)
+
+clean-local:
+	$(RM) -r html latex man
+endif
diff --git a/doc/Makefile.in b/doc/Makefile.in
new file mode 100644
index 0000000..0833998
--- /dev/null
+++ b/doc/Makefile.in
@@ -0,0 +1,384 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = doc
+DIST_COMMON = $(srcdir)/Doxyfile.in $(srcdir)/Makefile.am \
+	$(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/byteorder.m4 \
+	$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+	$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+	$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/stdint.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES = Doxyfile
+CONFIG_CLEAN_VPATH_FILES =
+SOURCES =
+DIST_SOURCES =
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AS = @AS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+HAVE_DOXYGEN = @HAVE_DOXYGEN@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBICONV = @LIBICONV@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBICONV = @LTLIBICONV@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OSFLAGS = @OSFLAGS@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+effective_target = @effective_target@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+ms_lib_exe = @ms_lib_exe@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+EXTRA_DIST = Doxyfile.in examples.h mainpage.h
+@HAVE_DOXYGEN_TRUE@pkgdocdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)
+@HAVE_DOXYGEN_TRUE@htmldocdir = $(pkgdocdir)/html
+all: all-am
+
+.SUFFIXES:
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign doc/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign doc/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+Doxyfile: $(top_builddir)/config.status $(srcdir)/Doxyfile.in
+	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+tags: TAGS
+TAGS:
+
+ctags: CTAGS
+CTAGS:
+
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+@HAVE_DOXYGEN_FALSE@all-local:
+all-am: Makefile all-local
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+@HAVE_DOXYGEN_FALSE@uninstall-local:
+@HAVE_DOXYGEN_FALSE@install-data-local:
+@HAVE_DOXYGEN_FALSE@clean-local:
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-local mostlyclean-am
+
+distclean: distclean-am
+	-rm -f Makefile
+distclean-am: clean-am distclean-generic
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-data-local
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-local
+
+.MAKE: install-am install-strip
+
+.PHONY: all all-am all-local check check-am clean clean-generic \
+	clean-libtool clean-local distclean distclean-generic \
+	distclean-libtool distdir dvi dvi-am html html-am info info-am \
+	install install-am install-data install-data-am \
+	install-data-local install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am install-info \
+	install-info-am install-man install-pdf install-pdf-am \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am \
+	uninstall-local
+
+
+@HAVE_DOXYGEN_TRUE@all-local:
+@HAVE_DOXYGEN_TRUE@	doxygen
+
+@HAVE_DOXYGEN_TRUE@install-data-local:
+@HAVE_DOXYGEN_TRUE@	$(INSTALL) -d $(DESTDIR)$(htmldocdir)
+@HAVE_DOXYGEN_TRUE@	$(INSTALL_DATA) html/* $(DESTDIR)$(htmldocdir)
+
+@HAVE_DOXYGEN_TRUE@uninstall-local:
+@HAVE_DOXYGEN_TRUE@	$(RM) -r $(DESTDIR)$(htmldocdir)
+@HAVE_DOXYGEN_TRUE@	$(RM) -r $(DESTDIR)$(pkgdocdir)
+
+@HAVE_DOXYGEN_TRUE@clean-local:
+@HAVE_DOXYGEN_TRUE@	$(RM) -r html latex man
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/doc/examples.h b/doc/examples.h
new file mode 100644
index 0000000..3e88ca4
--- /dev/null
+++ b/doc/examples.h
@@ -0,0 +1,17 @@
+/*
+ * List examples here...
+ */
+/** \example delfile.c */
+/** \example detect.c */
+/** \example files.c */
+/** \example folders.c */
+/** \example getfile.c */
+/** \example hotplug.c */
+/** \example newfolder.c */
+/** \example sendfile.c */
+/** \example sendtr.c */
+/** \example tracks.c */
+/** \example trexist.c */
+/** \example playlists.c */
+/** \example getplaylist.c */
+/** \example refactortest.c */
diff --git a/doc/mainpage.h b/doc/mainpage.h
new file mode 100644
index 0000000..19ef339
--- /dev/null
+++ b/doc/mainpage.h
@@ -0,0 +1,17 @@
+/**
+ * \mainpage The official libmtp documentation
+ *
+ * \section Introduction
+ *
+ * libmtp is a library for the Media Transfer Protocol (MTP)
+ * under various POSIX operating systems.
+ *
+ * \section License
+ *
+ * libmtp is available under the GNU Lesser General Public License,
+ * version 2. You can use libmtp in Free or proprietary software alike as
+ * long as you publish your modifications to this library in accordance
+ * with the LGPL license. If you do not follow the LGPL you will be in 
+ * deep, deep trouble.
+ * 
+ */
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644
index 0000000..101141c
--- /dev/null
+++ b/examples/Makefile.am
@@ -0,0 +1,34 @@
+bin_PROGRAMS=connect detect tracks files hotplug \
+	folders trexist playlists getplaylist \
+	format albumart albums newplaylist emptyfolders \
+	thumb reset
+
+connect_SOURCES=connect.c delfile.c getfile.c newfolder.c \
+	sendfile.c sendtr.c pathutils.c pathutils.h \
+	util.c util.h common.h
+detect_SOURCES=detect.c util.c util.h common.h
+tracks_SOURCES=tracks.c util.c util.h common.h
+files_SOURCES=files.c util.c util.h common.h
+hotplug_SOURCES=hotplug.c util.c util.h common.h
+folders_SOURCES=folders.c util.c util.h common.h
+trexist_SOURCES=trexist.c util.c util.h common.h
+playlists_SOURCES=playlists.c util.c util.h common.h
+getplaylist_SOURCES=getplaylist.c util.c util.h common.h
+newplaylist_SOURCES=newplaylist.c util.c util.h common.h
+format_SOURCES=format.c util.c util.h common.h
+albumart_SOURCES=albumart.c util.c util.h common.h
+albums_SOURCES=albums.c util.c util.h common.h
+emptyfolders_SOURCES=emptyfolders.c util.c util.h common.h
+thumb_SOURCES=thumb.c util.c util.h common.h
+reset_SOURCES=reset.c util.c util.h common.h
+
+AM_CPPFLAGS=-I$(top_builddir)/src
+LDADD=../src/libmtp.la
+EXTRA_DIST=evolution-sync.sh
+
+install-exec-hook:
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-delfile$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-getfile$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-newfolder$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-sendfile$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-sendtr$(EXEEXT)
diff --git a/examples/Makefile.in b/examples/Makefile.in
new file mode 100644
index 0000000..875656e
--- /dev/null
+++ b/examples/Makefile.in
@@ -0,0 +1,687 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+bin_PROGRAMS = connect$(EXEEXT) detect$(EXEEXT) tracks$(EXEEXT) \
+	files$(EXEEXT) hotplug$(EXEEXT) folders$(EXEEXT) \
+	trexist$(EXEEXT) playlists$(EXEEXT) getplaylist$(EXEEXT) \
+	format$(EXEEXT) albumart$(EXEEXT) albums$(EXEEXT) \
+	newplaylist$(EXEEXT) emptyfolders$(EXEEXT) thumb$(EXEEXT) \
+	reset$(EXEEXT)
+subdir = examples
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/byteorder.m4 \
+	$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+	$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+	$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/stdint.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__installdirs = "$(DESTDIR)$(bindir)"
+PROGRAMS = $(bin_PROGRAMS)
+am_albumart_OBJECTS = albumart.$(OBJEXT) util.$(OBJEXT)
+albumart_OBJECTS = $(am_albumart_OBJECTS)
+albumart_LDADD = $(LDADD)
+albumart_DEPENDENCIES = ../src/libmtp.la
+am_albums_OBJECTS = albums.$(OBJEXT) util.$(OBJEXT)
+albums_OBJECTS = $(am_albums_OBJECTS)
+albums_LDADD = $(LDADD)
+albums_DEPENDENCIES = ../src/libmtp.la
+am_connect_OBJECTS = connect.$(OBJEXT) delfile.$(OBJEXT) \
+	getfile.$(OBJEXT) newfolder.$(OBJEXT) sendfile.$(OBJEXT) \
+	sendtr.$(OBJEXT) pathutils.$(OBJEXT) util.$(OBJEXT)
+connect_OBJECTS = $(am_connect_OBJECTS)
+connect_LDADD = $(LDADD)
+connect_DEPENDENCIES = ../src/libmtp.la
+am_detect_OBJECTS = detect.$(OBJEXT) util.$(OBJEXT)
+detect_OBJECTS = $(am_detect_OBJECTS)
+detect_LDADD = $(LDADD)
+detect_DEPENDENCIES = ../src/libmtp.la
+am_emptyfolders_OBJECTS = emptyfolders.$(OBJEXT) util.$(OBJEXT)
+emptyfolders_OBJECTS = $(am_emptyfolders_OBJECTS)
+emptyfolders_LDADD = $(LDADD)
+emptyfolders_DEPENDENCIES = ../src/libmtp.la
+am_files_OBJECTS = files.$(OBJEXT) util.$(OBJEXT)
+files_OBJECTS = $(am_files_OBJECTS)
+files_LDADD = $(LDADD)
+files_DEPENDENCIES = ../src/libmtp.la
+am_folders_OBJECTS = folders.$(OBJEXT) util.$(OBJEXT)
+folders_OBJECTS = $(am_folders_OBJECTS)
+folders_LDADD = $(LDADD)
+folders_DEPENDENCIES = ../src/libmtp.la
+am_format_OBJECTS = format.$(OBJEXT) util.$(OBJEXT)
+format_OBJECTS = $(am_format_OBJECTS)
+format_LDADD = $(LDADD)
+format_DEPENDENCIES = ../src/libmtp.la
+am_getplaylist_OBJECTS = getplaylist.$(OBJEXT) util.$(OBJEXT)
+getplaylist_OBJECTS = $(am_getplaylist_OBJECTS)
+getplaylist_LDADD = $(LDADD)
+getplaylist_DEPENDENCIES = ../src/libmtp.la
+am_hotplug_OBJECTS = hotplug.$(OBJEXT) util.$(OBJEXT)
+hotplug_OBJECTS = $(am_hotplug_OBJECTS)
+hotplug_LDADD = $(LDADD)
+hotplug_DEPENDENCIES = ../src/libmtp.la
+am_newplaylist_OBJECTS = newplaylist.$(OBJEXT) util.$(OBJEXT)
+newplaylist_OBJECTS = $(am_newplaylist_OBJECTS)
+newplaylist_LDADD = $(LDADD)
+newplaylist_DEPENDENCIES = ../src/libmtp.la
+am_playlists_OBJECTS = playlists.$(OBJEXT) util.$(OBJEXT)
+playlists_OBJECTS = $(am_playlists_OBJECTS)
+playlists_LDADD = $(LDADD)
+playlists_DEPENDENCIES = ../src/libmtp.la
+am_reset_OBJECTS = reset.$(OBJEXT) util.$(OBJEXT)
+reset_OBJECTS = $(am_reset_OBJECTS)
+reset_LDADD = $(LDADD)
+reset_DEPENDENCIES = ../src/libmtp.la
+am_thumb_OBJECTS = thumb.$(OBJEXT) util.$(OBJEXT)
+thumb_OBJECTS = $(am_thumb_OBJECTS)
+thumb_LDADD = $(LDADD)
+thumb_DEPENDENCIES = ../src/libmtp.la
+am_tracks_OBJECTS = tracks.$(OBJEXT) util.$(OBJEXT)
+tracks_OBJECTS = $(am_tracks_OBJECTS)
+tracks_LDADD = $(LDADD)
+tracks_DEPENDENCIES = ../src/libmtp.la
+am_trexist_OBJECTS = trexist.$(OBJEXT) util.$(OBJEXT)
+trexist_OBJECTS = $(am_trexist_OBJECTS)
+trexist_LDADD = $(LDADD)
+trexist_DEPENDENCIES = ../src/libmtp.la
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(albumart_SOURCES) $(albums_SOURCES) $(connect_SOURCES) \
+	$(detect_SOURCES) $(emptyfolders_SOURCES) $(files_SOURCES) \
+	$(folders_SOURCES) $(format_SOURCES) $(getplaylist_SOURCES) \
+	$(hotplug_SOURCES) $(newplaylist_SOURCES) $(playlists_SOURCES) \
+	$(reset_SOURCES) $(thumb_SOURCES) $(tracks_SOURCES) \
+	$(trexist_SOURCES)
+DIST_SOURCES = $(albumart_SOURCES) $(albums_SOURCES) \
+	$(connect_SOURCES) $(detect_SOURCES) $(emptyfolders_SOURCES) \
+	$(files_SOURCES) $(folders_SOURCES) $(format_SOURCES) \
+	$(getplaylist_SOURCES) $(hotplug_SOURCES) \
+	$(newplaylist_SOURCES) $(playlists_SOURCES) $(reset_SOURCES) \
+	$(thumb_SOURCES) $(tracks_SOURCES) $(trexist_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AS = @AS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+HAVE_DOXYGEN = @HAVE_DOXYGEN@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBICONV = @LIBICONV@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBICONV = @LTLIBICONV@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OSFLAGS = @OSFLAGS@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+effective_target = @effective_target@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+ms_lib_exe = @ms_lib_exe@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+connect_SOURCES = connect.c delfile.c getfile.c newfolder.c \
+	sendfile.c sendtr.c pathutils.c pathutils.h \
+	util.c util.h common.h
+
+detect_SOURCES = detect.c util.c util.h common.h
+tracks_SOURCES = tracks.c util.c util.h common.h
+files_SOURCES = files.c util.c util.h common.h
+hotplug_SOURCES = hotplug.c util.c util.h common.h
+folders_SOURCES = folders.c util.c util.h common.h
+trexist_SOURCES = trexist.c util.c util.h common.h
+playlists_SOURCES = playlists.c util.c util.h common.h
+getplaylist_SOURCES = getplaylist.c util.c util.h common.h
+newplaylist_SOURCES = newplaylist.c util.c util.h common.h
+format_SOURCES = format.c util.c util.h common.h
+albumart_SOURCES = albumart.c util.c util.h common.h
+albums_SOURCES = albums.c util.c util.h common.h
+emptyfolders_SOURCES = emptyfolders.c util.c util.h common.h
+thumb_SOURCES = thumb.c util.c util.h common.h
+reset_SOURCES = reset.c util.c util.h common.h
+AM_CPPFLAGS = -I$(top_builddir)/src
+LDADD = ../src/libmtp.la
+EXTRA_DIST = evolution-sync.sh
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign examples/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign examples/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-binPROGRAMS: $(bin_PROGRAMS)
+	@$(NORMAL_INSTALL)
+	test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
+	@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+	for p in $$list; do echo "$$p $$p"; done | \
+	sed 's/$(EXEEXT)$$//' | \
+	while read p p1; do if test -f $$p || test -f $$p1; \
+	  then echo "$$p"; echo "$$p"; else :; fi; \
+	done | \
+	sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \
+	    -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+	sed 'N;N;N;s,\n, ,g' | \
+	$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+	  { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+	    if ($$2 == $$4) files[d] = files[d] " " $$1; \
+	    else { print "f", $$3 "/" $$4, $$1; } } \
+	  END { for (d in files) print "f", d, files[d] }' | \
+	while read type dir files; do \
+	    if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+	    test -z "$$files" || { \
+	    echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
+	    $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
+	    } \
+	; done
+
+uninstall-binPROGRAMS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+	files=`for p in $$list; do echo "$$p"; done | \
+	  sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+	      -e 's/$$/$(EXEEXT)/' `; \
+	test -n "$$list" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(bindir)" && rm -f $$files
+
+clean-binPROGRAMS:
+	@list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
+albumart$(EXEEXT): $(albumart_OBJECTS) $(albumart_DEPENDENCIES) 
+	@rm -f albumart$(EXEEXT)
+	$(LINK) $(albumart_OBJECTS) $(albumart_LDADD) $(LIBS)
+albums$(EXEEXT): $(albums_OBJECTS) $(albums_DEPENDENCIES) 
+	@rm -f albums$(EXEEXT)
+	$(LINK) $(albums_OBJECTS) $(albums_LDADD) $(LIBS)
+connect$(EXEEXT): $(connect_OBJECTS) $(connect_DEPENDENCIES) 
+	@rm -f connect$(EXEEXT)
+	$(LINK) $(connect_OBJECTS) $(connect_LDADD) $(LIBS)
+detect$(EXEEXT): $(detect_OBJECTS) $(detect_DEPENDENCIES) 
+	@rm -f detect$(EXEEXT)
+	$(LINK) $(detect_OBJECTS) $(detect_LDADD) $(LIBS)
+emptyfolders$(EXEEXT): $(emptyfolders_OBJECTS) $(emptyfolders_DEPENDENCIES) 
+	@rm -f emptyfolders$(EXEEXT)
+	$(LINK) $(emptyfolders_OBJECTS) $(emptyfolders_LDADD) $(LIBS)
+files$(EXEEXT): $(files_OBJECTS) $(files_DEPENDENCIES) 
+	@rm -f files$(EXEEXT)
+	$(LINK) $(files_OBJECTS) $(files_LDADD) $(LIBS)
+folders$(EXEEXT): $(folders_OBJECTS) $(folders_DEPENDENCIES) 
+	@rm -f folders$(EXEEXT)
+	$(LINK) $(folders_OBJECTS) $(folders_LDADD) $(LIBS)
+format$(EXEEXT): $(format_OBJECTS) $(format_DEPENDENCIES) 
+	@rm -f format$(EXEEXT)
+	$(LINK) $(format_OBJECTS) $(format_LDADD) $(LIBS)
+getplaylist$(EXEEXT): $(getplaylist_OBJECTS) $(getplaylist_DEPENDENCIES) 
+	@rm -f getplaylist$(EXEEXT)
+	$(LINK) $(getplaylist_OBJECTS) $(getplaylist_LDADD) $(LIBS)
+hotplug$(EXEEXT): $(hotplug_OBJECTS) $(hotplug_DEPENDENCIES) 
+	@rm -f hotplug$(EXEEXT)
+	$(LINK) $(hotplug_OBJECTS) $(hotplug_LDADD) $(LIBS)
+newplaylist$(EXEEXT): $(newplaylist_OBJECTS) $(newplaylist_DEPENDENCIES) 
+	@rm -f newplaylist$(EXEEXT)
+	$(LINK) $(newplaylist_OBJECTS) $(newplaylist_LDADD) $(LIBS)
+playlists$(EXEEXT): $(playlists_OBJECTS) $(playlists_DEPENDENCIES) 
+	@rm -f playlists$(EXEEXT)
+	$(LINK) $(playlists_OBJECTS) $(playlists_LDADD) $(LIBS)
+reset$(EXEEXT): $(reset_OBJECTS) $(reset_DEPENDENCIES) 
+	@rm -f reset$(EXEEXT)
+	$(LINK) $(reset_OBJECTS) $(reset_LDADD) $(LIBS)
+thumb$(EXEEXT): $(thumb_OBJECTS) $(thumb_DEPENDENCIES) 
+	@rm -f thumb$(EXEEXT)
+	$(LINK) $(thumb_OBJECTS) $(thumb_LDADD) $(LIBS)
+tracks$(EXEEXT): $(tracks_OBJECTS) $(tracks_DEPENDENCIES) 
+	@rm -f tracks$(EXEEXT)
+	$(LINK) $(tracks_OBJECTS) $(tracks_LDADD) $(LIBS)
+trexist$(EXEEXT): $(trexist_OBJECTS) $(trexist_DEPENDENCIES) 
+	@rm -f trexist$(EXEEXT)
+	$(LINK) $(trexist_OBJECTS) $(trexist_LDADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/albumart.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/albums.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/connect.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/delfile.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/detect.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/emptyfolders.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/files.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/folders.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/format.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getfile.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getplaylist.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hotplug.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/newfolder.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/newplaylist.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pathutils.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/playlists.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reset.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sendfile.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sendtr.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/thumb.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tracks.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/trexist.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+	for dir in "$(DESTDIR)$(bindir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-binPROGRAMS
+	@$(NORMAL_INSTALL)
+	$(MAKE) $(AM_MAKEFLAGS) install-exec-hook
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-binPROGRAMS
+
+.MAKE: install-am install-exec-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
+	clean-generic clean-libtool ctags distclean distclean-compile \
+	distclean-generic distclean-libtool distclean-tags distdir dvi \
+	dvi-am html html-am info info-am install install-am \
+	install-binPROGRAMS install-data install-data-am install-dvi \
+	install-dvi-am install-exec install-exec-am install-exec-hook \
+	install-html install-html-am install-info install-info-am \
+	install-man install-pdf install-pdf-am install-ps \
+	install-ps-am install-strip installcheck installcheck-am \
+	installdirs maintainer-clean maintainer-clean-generic \
+	mostlyclean mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \
+	uninstall-am uninstall-binPROGRAMS
+
+
+install-exec-hook:
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-delfile$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-getfile$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-newfolder$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-sendfile$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-sendtr$(EXEEXT)
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/examples/albumart.c b/examples/albumart.c
new file mode 100644
index 0000000..61b056e
--- /dev/null
+++ b/examples/albumart.c
@@ -0,0 +1,160 @@
+/** 
+ * \file albumart.c
+ * Example program to send album art.
+ *
+ * Copyright (C) 2006 Andy Kelk <andy@mopoke.co.uk>
+ *
+ * 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 "config.h"
+#include "common.h"
+#include "string.h"
+#include <stdlib.h>
+#include <limits.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_UIO_H
+#include <sys/uio.h>
+#endif
+
+static void usage(void) {
+  printf("Usage: albumart -i <fileid/trackid> -n <albumname> <imagefile>\n");
+  exit(0);
+}
+
+int main (int argc, char **argv) {
+  int opt;
+  extern int optind;
+  extern char *optarg;
+  LIBMTP_mtpdevice_t *device = NULL;
+  int idcount = 0;
+  int fd;
+  uint32_t *ids = NULL;
+  uint32_t *tmp = NULL;
+  uint64_t filesize;
+  char *imagedata = NULL;
+  char *albumname = NULL;
+  char *path = NULL;
+  char *rest;
+  struct stat statbuff;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  while ( (opt = getopt(argc, argv, "hn:i:")) != -1 ) {
+    switch (opt) {
+    case 'h':
+      usage();
+    case 'i':
+      idcount++;
+      if ((tmp = realloc(ids, sizeof(uint32_t) * (idcount))) == NULL) {
+        printf("realloc failed\n");
+        return 1;
+      }
+      ids = tmp;
+      ids[(idcount-1)] = strtoul(optarg, &rest, 0);
+      break;
+    case 'n':
+      albumname = strdup(optarg);
+      break;
+    default:
+      usage();
+    }
+  }
+  argc -= optind;
+  argv += optind;
+
+  if ( argc != 1 ) {
+    printf("You need to pass a filename.\n");
+    usage();
+  }
+
+  if ( albumname == NULL) {
+    printf("You need to supply an album name.\n");
+    usage();
+  }
+
+  if (idcount == 0) {
+    printf("You need to supply one or more track IDs\n");
+    usage();
+  }
+
+  path = argv[0];
+
+  if ( stat(path, &statbuff) == -1 ) {
+    fprintf(stderr, "%s: ", path);
+    perror("stat");
+    exit(1);
+  }
+  filesize = (uint64_t) statbuff.st_size;
+  imagedata = malloc(filesize * sizeof(uint8_t));
+
+#ifdef __WIN32__
+  if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
+#else
+  if ( (fd = open(path, O_RDONLY)) == -1) {
+#endif
+    printf("Couldn't open image file %s (%s)\n",path,strerror(errno));
+    return 1;
+  }
+  else {
+    read(fd, imagedata, filesize);
+    close(fd);
+  }
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    return 0;
+  }
+
+  LIBMTP_filesampledata_t *albumart = LIBMTP_new_filesampledata_t();
+  albumart->data = imagedata;
+  albumart->size = filesize;
+  albumart->filetype = LIBMTP_FILETYPE_JPEG;
+
+  LIBMTP_album_t *album = LIBMTP_new_album_t();
+  album->name = albumname;
+  album->no_tracks = idcount;
+  album->tracks = ids;
+  album->parent_id = 0;
+  album->storage_id = 0;
+  int ret = LIBMTP_Create_New_Album(device,album);
+  if (ret == 0) {
+    ret = LIBMTP_Send_Representative_Sample(device,album->album_id, albumart);
+    if (ret != 0) {
+      printf("Couldn't send album art\n");
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+    }
+  }
+  else {
+    printf("Couldn't create album object\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+  }
+
+  LIBMTP_destroy_filesampledata_t(albumart);
+  LIBMTP_destroy_album_t(album);
+
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  return 0;
+}
+
diff --git a/examples/albums.c b/examples/albums.c
new file mode 100644
index 0000000..a653126
--- /dev/null
+++ b/examples/albums.c
@@ -0,0 +1,99 @@
+/** 
+ * \file albums.c
+ * Example program that lists the albums on the device.
+ *
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ *
+ * 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 "common.h"
+#include <stdlib.h>
+
+static void dump_albuminfo(LIBMTP_album_t *album)
+{
+  printf("Album ID: %d\n",album->album_id);
+  printf("    Parent ID:   %d\n",album->parent_id);
+  printf("    Name:   %s\n",album->name);
+  printf("    Artist: %s\n", album->artist);
+  printf("    Composer:  %s\n", album->composer);
+  printf("    Genre:  %s\n", album->genre);
+  printf("    Tracks: %d\n\n",album->no_tracks);
+}
+
+int main () {
+  LIBMTP_mtpdevice_t *device_list, *iter;
+
+  LIBMTP_Init();
+    
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  switch(LIBMTP_Get_Connected_Devices(&device_list))
+  {
+  case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
+    fprintf(stdout, "mtp-albums: No Devices have been found\n");
+    return 0;
+  case LIBMTP_ERROR_CONNECTING:
+    fprintf(stderr, "mtp-albums: There has been an error connecting. Exit\n");
+    return 1;
+  case LIBMTP_ERROR_MEMORY_ALLOCATION:
+    fprintf(stderr, "mtp-albums: Memory Allocation Error. Exit\n");
+    return 1;
+ 
+  /* Unknown general errors - This should never execute */
+  case LIBMTP_ERROR_GENERAL:
+  default:
+    fprintf(stderr, "mtp-albums: Unknown error, please report "
+                    "this to the libmtp developers\n");
+  return 1;
+
+  /* Successfully connected at least one device, so continue */
+  case LIBMTP_ERROR_NONE:
+    fprintf(stdout, "mtp-albums: Successfully connected\n");
+    fflush(stdout);
+  }
+  
+  /* iterate through connected MTP devices */
+  for(iter = device_list; iter != NULL; iter = iter->next)
+  {
+    char *friendlyname;
+    LIBMTP_album_t *album_list, *album, *tmp;
+    
+    /* Echo the friendly name so we know which device we are working with */
+    friendlyname = LIBMTP_Get_Friendlyname(iter);
+    if (friendlyname == NULL) {
+      printf("Retrieving Albums on Device with name: (NULL)\n");
+    } else {
+      printf("Retrieving Albums on Device with name: %s\n", friendlyname);
+      free(friendlyname);
+    }
+    
+    album_list = LIBMTP_Get_Album_List(iter);
+    album = album_list;
+    while(album != NULL)
+    {
+      dump_albuminfo(album);
+      tmp = album;
+      album = album->next;
+      LIBMTP_destroy_album_t(tmp);
+    }
+  }
+  
+  LIBMTP_Release_Device_List(device_list);
+  printf("OK.\n");
+  return 0;
+}
+
diff --git a/examples/common.h b/examples/common.h
new file mode 100644
index 0000000..ec41bb8
--- /dev/null
+++ b/examples/common.h
@@ -0,0 +1,34 @@
+/** 
+ * \file common.h
+ * These headers are used by absolutely all sample programs.
+ * Special quirks that apply to all samples go here.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ *
+ * 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 <libmtp.h>
+#ifndef _MSC_VER
+#include <config.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+#include <unistd.h>
+#endif
+#else
+// Only if using MSVC...
+#include "..\windows\getopt.h"
+#endif
diff --git a/examples/connect.c b/examples/connect.c
new file mode 100644
index 0000000..99945eb
--- /dev/null
+++ b/examples/connect.c
@@ -0,0 +1,169 @@
+/** 
+ * \file connect.c
+ * Main programs implementing several utilities in one.
+ *
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ * Copyright (C) 2008-2009 Linus Walleij <triad@df.lth.se>
+ *
+ * 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 <stdlib.h>
+#include <libgen.h>
+#include <getopt.h>
+#include <string.h>
+#include "common.h"
+#include "util.h"
+#include "pathutils.h"
+
+LIBMTP_folder_t *folders;
+LIBMTP_file_t *files;
+LIBMTP_mtpdevice_t *device;
+
+void usage(void);
+void split_arg(char *,char **, char **);
+void delfile_function(char *);
+void delfile_command(int, char **);
+void delfile_usage(void);
+int sendtrack_function(char *, char *, char *, char *, char *, char *, char *, char *, uint16_t, uint16_t, uint16_t);
+void sendtrack_command (int, char **);
+void sendtrack_usage(void);
+void sendfile_function(char *,char *);
+void sendfile_command(int, char **);
+void sendfile_usage(void);
+void getfile_function(char *,char *);
+void getfile_command(int, char **);
+void getfile_usage(void);
+void newfolder_function(char *);
+void newfolder_command(int,char **);
+void newfolder_usage(void);
+
+void
+split_arg(char * argument, char ** part1, char ** part2)
+{
+  char *sepp;
+  *part1 = NULL;
+  *part2 = NULL;
+
+  sepp = argument + strcspn(argument, ",");
+  sepp[0] = '\0';
+  *part1 = argument;
+  *part2 = sepp+1;
+}
+
+void
+usage(void)
+{
+  printf("Usage: connect <command1> <command2>\n");
+  printf("Commands: --delete [filename]\n");
+  printf("          --sendfile [source] [destination]\n");
+  printf("          --sendtrack [source] [destination]\n");
+  printf("          --getfile [source] [destination]\n");
+  printf("          --newfolder [foldername]\n");
+}
+
+
+int main (int argc, char **argv)
+{
+  checklang();
+
+  LIBMTP_Init();
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    return 0;
+  }
+  files = LIBMTP_Get_Filelisting_With_Callback (device, NULL, NULL);
+  folders = LIBMTP_Get_Folder_List (device);
+
+  if ((strncmp(basename(argv[0]),"mtp-delfile",11) == 0) || (strncmp(basename(argv[0]),"delfile",7) == 0)) {
+    delfile_command(argc,argv);
+  } else if ((strncmp(basename(argv[0]),"mtp-getfile",13) == 0) || (strncmp(basename(argv[0]),"getfile",9) == 0)) {
+    getfile_command(argc,argv);
+  } else if ((strncmp(basename(argv[0]),"mtp-newfolder",13) == 0) || (strncmp(basename(argv[0]),"newfolder",9) == 0)) {
+    newfolder_command(argc,argv);
+  } else if ((strncmp(basename(argv[0]),"mtp-sendfile",11) == 0) || (strncmp(basename(argv[0]),"sendfile",7) == 0)) {
+    sendfile_command(argc, argv);
+  } else if ((strncmp(basename(argv[0]),"mtp-sendtr",10) == 0) || (strncmp(basename(argv[0]),"sendtr",6) == 0)) {
+    sendtrack_command(argc, argv);
+  } else {  
+    if ( argc < 2 ) {
+      usage ();
+      return 1;
+    }
+
+    while (1) {
+      int option_index = 0;
+      static struct option long_options[] = {
+        {"delete", 1, 0, 'd'},
+        {"sendfile", 1, 0, 'f'},
+        {"getfile", 1, 0, 'g'},
+        {"newfolder", 1, 0, 'n'},
+        {"sendtrack", 1, 0, 't'},
+        {0, 0, 0, 0}
+      };
+  
+      int c = getopt_long (argc, argv, "d:f:g:n:t:", long_options, &option_index);
+      if (c == -1)
+        break;
+  
+      char *arg1, *arg2;
+      switch (c) {
+      case 'd':
+        printf("Delete %s\n",optarg);
+        delfile_function(optarg);
+        break;
+  
+      case 'f':
+        printf("Send file %s\n",optarg);
+        split_arg(optarg,&arg1,&arg2);
+        sendfile_function(arg1,arg2);
+        break;
+  
+      case 'g':
+        printf("Get file %s\n",optarg);
+        split_arg(optarg,&arg1,&arg2);
+        getfile_function(arg1,arg2);
+        break;
+  
+      case 'n':
+        printf("New folder %s\n",optarg);
+        newfolder_function(optarg);
+        break;
+  
+      case 't':
+        printf("Send track %s\n",optarg);
+        split_arg(optarg,&arg1,&arg2);
+        sendtrack_function(arg1,arg2,NULL,NULL,NULL,NULL,NULL,NULL,0,0,0);
+        break;
+      }
+    }
+  
+    if (optind < argc) {
+      printf("Unknown options: ");
+      while (optind < argc)
+        printf("%s ", argv[optind++]);
+      printf("\n");
+    }
+  }
+  
+  LIBMTP_Release_Device(device);
+
+  exit (0);
+}
+
diff --git a/examples/delfile.c b/examples/delfile.c
new file mode 100644
index 0000000..670c703
--- /dev/null
+++ b/examples/delfile.c
@@ -0,0 +1,113 @@
+/** 
+ * \file delfile.c
+ * Example program to delete a file off the device.
+ *
+ * Copyright (C) 2005-2008 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ *
+ * 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 "common.h"
+#include "string.h"
+#include "pathutils.h"
+#include <stdlib.h>
+#include <limits.h>
+
+void delfile_usage(void);
+void delfile_function(char *);
+void delfile_command(int, char **);
+
+extern LIBMTP_mtpdevice_t *device;
+extern LIBMTP_folder_t *folders;
+extern LIBMTP_file_t *files;
+
+void delfile_usage(void)
+{
+  printf("Usage: delfile [-n] <fileid/trackid> | -f <filename>\n");
+}
+
+void
+delfile_function(char * path)
+{
+  uint32_t id = parse_path (path,files,folders);
+
+  if (id > 0) {
+    printf("Deleting %s which has item_id:%d\n",path,id);
+    int ret = 1;
+    ret = LIBMTP_Delete_Object(device, id);
+    if (ret != 0) {
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+      printf("Failed to remove file\n");
+    }
+  }
+}
+
+void delfile_command(int argc, char **argv)
+{
+  int FILENAME = 1;
+  int ITEMID = 2;
+  int field_type = 0;
+  int i;
+
+  if ( argc > 2 ) {
+    if (strncmp(argv[1],"-f",2) == 0) {
+      field_type = FILENAME;
+      strcpy(argv[1],"");
+    } else if (strncmp(argv[1],"-n",2) == 0) {
+      field_type = ITEMID;
+      strcpy(argv[1],"0");
+    } else {
+      delfile_usage();
+      return;
+    }
+  } else {
+    delfile_usage();
+    return;
+  }
+
+  for (i=1;i<argc;i++) {
+    uint32_t id;
+    char *endptr;
+    int ret = 0;
+
+    if (field_type == ITEMID) {
+      // Sanity check song ID
+      id = strtoul(argv[i], &endptr, 10);
+      if ( *endptr != 0 ) {
+        fprintf(stderr, "illegal value %s .. skipping\n", argv[i]);
+        id = 0;
+      }
+    } else {
+      if (strlen(argv[i]) > 0) {
+        id = parse_path (argv[i],files,folders);
+      } else {
+        id = 0;
+      }
+    }
+    if (id > 0 ) {
+      printf("Deleting %s\n",argv[i]);
+      ret = LIBMTP_Delete_Object(device, id);
+    }
+    if ( ret != 0 ) {
+      printf("Failed to delete file:%s\n",argv[i]);
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+      ret = 1;
+    }
+  }
+}
+
diff --git a/examples/detect.c b/examples/detect.c
new file mode 100644
index 0000000..393fd2c
--- /dev/null
+++ b/examples/detect.c
@@ -0,0 +1,268 @@
+/** 
+ * \file detect.c
+ * Example program to detect a device and list capabilities.
+ *
+ * Copyright (C) 2005-2008 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ *
+ * 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 "common.h"
+#include "util.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#define XML_BUFSIZE 0x10000
+
+static void dump_xml_fragment(uint8_t *buf, uint32_t len)
+{
+  static int endianness = 0; // 0 = LE, 1 = BE
+  uint32_t bp = 0;
+  
+  while (bp < len) {
+    if (buf[bp+0] == 0xFF && buf[bp+1] == 0xFE) {
+      endianness = 0;
+    } else if (buf[bp+0] == 0xFE && buf[bp+1] == 0xff) {
+      endianness = 1;
+    } else {
+      uint16_t tmp;
+      
+      if (endianness == 0) {
+	tmp = buf[bp+1] << 8 | buf[bp+0];
+      } else {
+	tmp = buf[bp+0] << 8 | buf[bp+1];
+      }
+      // Fix this some day, we only print ISO 8859-1 correctly here,
+      // should atleast support UTF-8.
+      printf("%c", (uint8_t) tmp);
+    }
+    bp += 2;
+  }
+  printf("\n");
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_raw_device_t * rawdevices;
+  int numrawdevices;
+  LIBMTP_error_number_t err;
+  int i;
+
+  LIBMTP_Init();
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  fprintf(stdout, "Listing raw device(s)\n");
+  err = LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices);
+  switch(err) {
+  case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
+    fprintf(stdout, "   No raw devices found.\n");
+    return 0;
+  case LIBMTP_ERROR_CONNECTING:
+    fprintf(stderr, "Detect: There has been an error connecting. Exiting\n");
+    return 1;
+  case LIBMTP_ERROR_MEMORY_ALLOCATION:
+    fprintf(stderr, "Detect: Encountered a Memory Allocation Error. Exiting\n");
+    return 1;
+  case LIBMTP_ERROR_NONE:
+    {
+      int i;
+      
+      fprintf(stdout, "   Found %d device(s):\n", numrawdevices);
+      for (i = 0; i < numrawdevices; i++) {
+	if (rawdevices[i].device_entry.vendor != NULL ||
+	    rawdevices[i].device_entry.product != NULL) {
+	  fprintf(stdout, "   %s: %s (%04x:%04x) @ bus %d, dev %d\n", 
+		  rawdevices[i].device_entry.vendor,
+		  rawdevices[i].device_entry.product,
+		  rawdevices[i].device_entry.vendor_id,
+		  rawdevices[i].device_entry.product_id,
+		  rawdevices[i].bus_location,
+		  rawdevices[i].devnum);
+	} else {
+	  fprintf(stdout, "   %04x:%04x @ bus %d, dev %d\n", 
+		  rawdevices[i].device_entry.vendor_id,
+		  rawdevices[i].device_entry.product_id,
+		  rawdevices[i].bus_location,
+		  rawdevices[i].devnum);
+	}
+      }
+    }
+    break;
+  case LIBMTP_ERROR_GENERAL:
+  default:
+    fprintf(stderr, "Unknown connection error.\n");
+    return 1;
+  }
+
+  /* Iterate over connected MTP devices */
+  fprintf(stdout, "Attempting to connect device(s)\n");
+  for (i = 0; i < numrawdevices; i++) {
+    LIBMTP_mtpdevice_t *device;
+    LIBMTP_file_t *files;
+    char *friendlyname;
+    char *syncpartner;
+    char *sectime;
+    char *devcert;
+    uint16_t *filetypes;
+    uint16_t filetypes_len;
+    uint8_t maxbattlevel;
+    uint8_t currbattlevel;
+    int ret;
+
+    device = LIBMTP_Open_Raw_Device(&rawdevices[i]);
+    if (device == NULL) {
+      fprintf(stderr, "Unable to open raw device %d\n", i);
+      continue;
+    }
+
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+    LIBMTP_Dump_Device_Info(device);
+    
+    printf("MTP-specific device properties:\n");
+    // The friendly name
+    friendlyname = LIBMTP_Get_Friendlyname(device);
+    if (friendlyname == NULL) {
+      fprintf(stdout, "   Friendly name: (NULL)\n");
+    } else {
+      fprintf(stdout, "   Friendly name: %s\n", friendlyname);
+      free(friendlyname);
+    }
+    syncpartner = LIBMTP_Get_Syncpartner(device);
+    if (syncpartner == NULL) {
+      fprintf(stdout, "   Synchronization partner: (NULL)\n");
+    } else {
+      fprintf(stdout, "   Synchronization partner: %s\n", syncpartner);
+      free(syncpartner);
+    }
+    
+    // Some battery info
+    ret = LIBMTP_Get_Batterylevel(device, &maxbattlevel, &currbattlevel);
+    if (ret == 0) {
+      fprintf(stdout, "   Battery level %d of %d (%d%%)\n",currbattlevel, maxbattlevel, 
+	      (int) ((float) currbattlevel/ (float) maxbattlevel * 100.0));
+    } else {
+      // Silently ignore. Some devices does not support getting the 
+      // battery level.
+      LIBMTP_Clear_Errorstack(device);
+    }
+    
+    ret = LIBMTP_Get_Supported_Filetypes(device, &filetypes, &filetypes_len);
+    if (ret == 0) {
+      uint16_t i;
+      
+      printf("libmtp supported (playable) filetypes:\n");
+      for (i = 0; i < filetypes_len; i++) {
+	fprintf(stdout, "   %s\n", LIBMTP_Get_Filetype_Description(filetypes[i]));
+      }
+    } else {
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+    }
+    
+    // Secure time XML fragment
+    ret = LIBMTP_Get_Secure_Time(device, &sectime);
+    if (ret == 0 && sectime != NULL) {
+      fprintf(stdout, "\nSecure Time:\n%s\n", sectime);
+      free(sectime);
+    } else {
+      // Silently ignore - there may be devices not supporting secure time.
+      LIBMTP_Clear_Errorstack(device);
+    }
+    
+    // Device certificate XML fragment
+    ret = LIBMTP_Get_Device_Certificate(device, &devcert);
+    if (ret == 0 && devcert != NULL) {
+      fprintf(stdout, "\nDevice Certificate:\n%s\n", devcert);
+      free(devcert);
+    } else {
+      fprintf(stdout, "Unable to acquire device certificate, perhaps this device "
+	      "does not support this\n");
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+    }
+
+    // Try to get Media player device info XML file...
+    files = LIBMTP_Get_Filelisting_With_Callback(device, NULL, NULL);
+    if (files != NULL) {
+      LIBMTP_file_t *file, *tmp;
+      file = files;
+      while (file != NULL) {
+	if (!strcmp(file->filename, "WMPInfo.xml") ||
+	    !strcmp(file->filename, "WMPinfo.xml") ||
+	    !strcmp(file->filename, "default-capabilities.xml")) {
+	    if (file->item_id != 0) {
+	      /* Dump this file */
+	      FILE *xmltmp = tmpfile();
+	      int tmpfiledescriptor = fileno(xmltmp);
+	      
+	      if (tmpfiledescriptor != -1) {
+		int ret = LIBMTP_Get_Track_To_File_Descriptor(device,
+							      file->item_id,
+							      tmpfiledescriptor,
+							      NULL,
+							      NULL);
+		if (ret == 0) {
+		  uint8_t *buf = NULL;
+		  uint32_t readbytes;
+		  
+		  buf = malloc(XML_BUFSIZE);
+		  if (buf == NULL) {
+		    printf("Could not allocate %08x bytes...\n", XML_BUFSIZE);
+		    LIBMTP_Dump_Errorstack(device);
+		    LIBMTP_Clear_Errorstack(device);
+		    free(rawdevices);
+		    return 1;
+		  }
+		  
+		  lseek(tmpfiledescriptor, 0, SEEK_SET);
+		  readbytes = read(tmpfiledescriptor, (void*) buf, XML_BUFSIZE);
+		  
+		  if (readbytes >= 2 && readbytes < XML_BUFSIZE) {
+		    fprintf(stdout, "\n%s file contents:\n", file->filename);
+		    dump_xml_fragment(buf, readbytes);
+		  } else {
+		    perror("Unable to read file");
+		    LIBMTP_Dump_Errorstack(device);
+		    LIBMTP_Clear_Errorstack(device);
+		  }
+		  free(buf);
+		} else {
+		  LIBMTP_Dump_Errorstack(device);
+		  LIBMTP_Clear_Errorstack(device);
+		}
+		fclose(xmltmp);
+	      }
+	    }
+	}
+	tmp = file;
+	file = file->next;
+	LIBMTP_destroy_file_t(tmp);
+      }
+    }
+    LIBMTP_Release_Device(device);
+  } /* End For Loop */
+
+  free(rawdevices);
+
+  printf("OK.\n");
+  
+  return 0; 
+}
diff --git a/examples/emptyfolders.c b/examples/emptyfolders.c
new file mode 100644
index 0000000..9cd7b49
--- /dev/null
+++ b/examples/emptyfolders.c
@@ -0,0 +1,112 @@
+/** 
+ * \file emptyfolders.c
+ * Example program that prunes empty folders.
+ *
+ * Copyright (C) 2006 Andy Kelk <andy@mopoke.co.uk>
+ *
+ * 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 "common.h"
+#include <stdlib.h>
+
+static void prune_empty_folders(LIBMTP_mtpdevice_t *device, LIBMTP_file_t *files, LIBMTP_folder_t *folderlist, int do_delete)
+{
+  if(folderlist==NULL)
+    return;
+
+  if(folderlist->child == NULL) { // this *might* be empty
+    // therefore, check every file for this parent_id
+    int found = 0;
+    LIBMTP_file_t *file;
+    file = files;
+    while (file != NULL) {
+      if(file->parent_id == folderlist->folder_id) { // folder has a child
+        found = 1;
+        break;
+      }
+      file = file->next;
+    }
+
+    if(found == 0) { // no files claim this as a parent
+      printf("empty folder %u (%s)\n",folderlist->folder_id,folderlist->name);
+      if(do_delete) {
+        if (LIBMTP_Delete_Object(device,folderlist->folder_id) != 0) {
+          printf("Couldn't delete folder %u\n",folderlist->folder_id);
+	  LIBMTP_Dump_Errorstack(device);
+	  LIBMTP_Clear_Errorstack(device);
+        }
+      }
+    }
+  }
+
+  prune_empty_folders(device,files,folderlist->child,do_delete); // recurse down
+  prune_empty_folders(device,files,folderlist->sibling,do_delete); // recurse along
+}
+
+int main (int argc, char **argv)
+{
+  // check if we're doing a dummy run
+  int do_delete = 0;
+  int opt;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  while ( (opt = getopt(argc, argv, "d")) != -1 ) {
+    switch (opt) {
+    case 'd':
+      do_delete = 1;
+      break;
+    default:
+      break;
+    }
+  }
+
+  if(do_delete == 0) {
+    printf("This is a dummy run. No folders will be deleted.\n");
+    printf("To delete folders, use the '-d' option.\n");
+  }
+
+  LIBMTP_mtpdevice_t *device;
+  LIBMTP_folder_t *folders;
+  LIBMTP_file_t *files;
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    exit (0);
+  }
+
+  // Get file listing.
+  files = LIBMTP_Get_Filelisting_With_Callback(device,NULL,NULL);
+
+  // Get folder listing.
+  folders = LIBMTP_Get_Folder_List(device);
+
+  if(folders == NULL) {
+    printf("No folders found\n");
+  } else {
+    prune_empty_folders(device,files,folders,do_delete);
+  }
+
+  LIBMTP_destroy_folder_t(folders);
+  LIBMTP_destroy_file_t(files);
+
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  exit (0);
+}
+
diff --git a/examples/evolution-sync.sh b/examples/evolution-sync.sh
new file mode 100755
index 0000000..53ca0b9
--- /dev/null
+++ b/examples/evolution-sync.sh
@@ -0,0 +1,93 @@
+#!/bin/bash
+
+# Example evolution synchronization script by Nicolas Tetreault,
+# modified by Linus Walleij.
+
+# Define target files
+SYNC_HOME=$HOME/MTP_device_sync
+
+# Define tool locations
+SENDFILE=`which mtp-sendfile`
+# SENDFILE="$HOME/comp-apps/bin/sendfile"
+#EADDEXP=`which evolution-addressbook-export`
+# This is the location in Fedora Core 5:
+EADDEXP="/usr/libexec/evolution/2.6/evolution-addressbook-export"
+
+# You need to change the name of the files
+# that contains the calendar and contacts on your device. 
+# You can find out by  starting Gnomad2, choose the data transfer 
+# tab, sort by size (it should be small files, extension .ics and .vcf)
+# On my Zen Microphoto, the calendar and contacts files are called
+# 6651416 with the ics and vcf extensions, respectively.
+CALENDAR_FILE="6651416.ics"
+CONTACTS_FILE="6651416.vcf"
+
+# The evolution address book. To list your addressbooks, type:
+# evolution-addressbook-export -l
+# the output for me:
+# "file:///home/nt271/.evolution/addressbook/local/system
+# ","Personal",26
+# "file:///home/nt271/.evolution/addressbook/local/1158600180.5386.0@sierra"
+# ,"MicroPhoto",24
+# I only want the Microphoto addressbook and the output will be
+# $SYNC_HOME/contacts/Evolution_contacts.vcf
+EVOLUTION_CONTACTS="file:///home/linus/.evolution/addressbook/local/system"
+
+# Check for sync dir, create it if needed
+
+if test -d $SYNC_HOME ; then
+    echo "$SYNC_HOME exists, OK."
+else
+    echo "$SYNC_HOME must first be created..."
+    mkdir $SYNC_HOME
+    # This is a working dir for contact merging, you can put
+    # in some extra .vcf files here as well if you like.
+    mkdir $SYNC_HOME/contacts
+    # Here you can place some extra calendars to be sync:ed, you
+    # can put in some extra .ics files of any kind here.
+    mkdir $SYNC_HOME/calendars
+fi
+
+# Check for prerequisites
+
+if test -f $EADDEXP ; then
+    echo "evolution-addressbook-export present in $EADDEXP, OK."
+else
+    echo "Cannot locate evolution-addressbook-export!!"
+    exit 0
+fi
+
+
+# Next line merges all of your tasklist, your personal calendar, 
+# and then any saved to disk calendar you have placed in
+# $SYNC_HOME/calendars
+
+cat $HOME/.evolution/tasks/local/system/tasks.ics \
+    $HOME/.evolution/calendar/local/system/calendar.ics \
+    $SYNC_HOME/calendars/*.ics > $SYNC_HOME/$CALENDAR_FILE
+
+# Use evolution-addressbook-export (installed with Evolution) to
+# export your contacts to vcard.
+
+$EADDEXP --format=vcard \
+    --output=$SYNC_HOME/contacts/Evolution_contacts.vcf \
+    $EVOLUTION_CONTACTS
+
+# Repeat for each addressbook you want to upload.
+
+# The next command will then merge all the contact lists
+
+cat $SYNC_HOME/contacts/*.vcf > $SYNC_HOME/$CONTACTS_FILE
+
+# The calendar and contacts files now need to be converted from unix
+# to DOS linefeeds (CR+LF instead of just LF)
+
+unix2dos $SYNC_HOME/$CALENDAR_FILE $SYNC_HOME/$CONTACTS_FILE
+
+# You can now upload the ics and vcf files to you My Organizer folder
+# on your device. Change the path to your sendfile command.
+# Sending the vcf file is only supported in CVS version at this time
+
+$SENDFILE -f "My Organizer" -t ics $SYNC_HOME/$CALENDAR_FILE
+$SENDFILE -f "My Organizer" -t vcf $SYNC_HOME/$CONTACTS_FILE
+
diff --git a/examples/files.c b/examples/files.c
new file mode 100644
index 0000000..9ccf3d7
--- /dev/null
+++ b/examples/files.c
@@ -0,0 +1,120 @@
+/** 
+ * \file files.c
+ * Example program that lists all files on a device.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ *
+ * 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 "common.h"
+#include <stdlib.h>
+
+static void dump_fileinfo(LIBMTP_file_t *file)
+{
+  printf("File ID: %u\n", file->item_id);
+  if (file->filename != NULL)
+    printf("   Filename: %s\n", file->filename);
+
+  // This is sort of special...
+  if (file->filesize == (uint32_t) -1) {
+    printf("   None. (abstract file, size = -1)\n");
+  } else {
+#ifdef __WIN32__
+    printf("   File size %llu (0x%016I64X) bytes\n", file->filesize, file->filesize);
+#else
+    printf("   File size %llu (0x%016llX) bytes\n",
+	   (long long unsigned int) file->filesize, 
+	   (long long unsigned int) file->filesize);
+#endif
+  }
+  printf("   Parent ID: %u\n", file->parent_id);
+  printf("   Storage ID: 0x%08X\n", file->storage_id);
+  printf("   Filetype: %s\n", LIBMTP_Get_Filetype_Description(file->filetype));
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device_list, *iter;
+  LIBMTP_file_t *files;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  LIBMTP_Init();
+
+  switch(LIBMTP_Get_Connected_Devices(&device_list))
+  {
+  case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
+    fprintf(stdout, "mtp-files: No Devices have been found\n");
+    return 0;
+  case LIBMTP_ERROR_CONNECTING:
+    fprintf(stderr, "mtp-files: There has been an error connecting. Exit\n");
+    return 1;
+  case LIBMTP_ERROR_MEMORY_ALLOCATION:
+    fprintf(stderr, "mtp-files: Memory Allocation Error. Exit\n");
+    return 1;
+ 
+  /* Unknown general errors - This should never execute */
+  case LIBMTP_ERROR_GENERAL:
+  default:
+    fprintf(stderr, "mtp-files: Unknown error, please report "
+                    "this to the libmtp developers\n");
+  return 1;
+
+  /* Successfully connected at least one device, so continue */
+  case LIBMTP_ERROR_NONE:
+    fprintf(stdout, "mtp-files: Successfully connected\n");
+    fflush(stdout);
+  }
+  
+  /* iterate through connected MTP devices */
+  for(iter = device_list; iter != NULL; iter = iter->next)
+  {
+  	
+    char *friendlyname;
+    
+    /* Echo the friendly name so we know which device we are working with */
+    friendlyname = LIBMTP_Get_Friendlyname(iter);
+    if (friendlyname == NULL) {
+      printf("Listing File Information on Device with name: (NULL)\n");
+    } else {
+      printf("Listing File Information on Device with name: %s\n", friendlyname);
+      free(friendlyname);
+    }
+  
+	  /* Get track listing. */
+	  files = LIBMTP_Get_Filelisting_With_Callback(iter, NULL, NULL);
+	  if (files == NULL) {
+	    printf("No files.\n");
+	    LIBMTP_Dump_Errorstack(iter);
+	    LIBMTP_Clear_Errorstack(iter);
+	  } else {
+	    LIBMTP_file_t *file, *tmp;
+	    file = files;
+	    while (file != NULL) {
+	      dump_fileinfo(file);
+	      tmp = file;
+	      file = file->next;
+	      LIBMTP_destroy_file_t(tmp);
+      }
+	  }
+  }
+    
+  LIBMTP_Release_Device_List(device_list);
+  printf("OK.\n");
+  exit (0);
+}
+
diff --git a/examples/folders.c b/examples/folders.c
new file mode 100644
index 0000000..ee63709
--- /dev/null
+++ b/examples/folders.c
@@ -0,0 +1,109 @@
+/** 
+ * \file folders.c
+ * Example program that lists all folders on a device.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ *
+ * 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 "common.h"
+#include <stdlib.h>
+
+static void dump_folder_list(LIBMTP_folder_t *folderlist, int level)
+{
+  int i;
+  if(folderlist==NULL) {
+    return;
+  }
+
+  printf("%u\t", folderlist->folder_id);
+  for(i=0;i<level;i++) printf("  ");
+
+  printf("%s\n", folderlist->name);
+
+  dump_folder_list(folderlist->child, level+1);
+  dump_folder_list(folderlist->sibling, level);
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device, *iter;
+  LIBMTP_folder_t *folders;
+
+  LIBMTP_Init();
+  fprintf(stdout, "Attempting to connect device(s)\n");
+
+  switch(LIBMTP_Get_Connected_Devices(&device))
+  {
+  case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
+    fprintf(stdout, "mtp-folders: No Devices have been found\n");
+    return 0;
+  case LIBMTP_ERROR_CONNECTING:
+    fprintf(stderr, "mtp-folders: There has been an error connecting. Exit\n");
+    return 1;
+  case LIBMTP_ERROR_MEMORY_ALLOCATION:
+    fprintf(stderr, "mtp-folders: Memory Allocation Error. Exit\n");
+    return 1;
+ 
+  /* Unknown general errors - This should never execute */
+  case LIBMTP_ERROR_GENERAL:
+  default:
+    fprintf(stderr, "mtp-folders: Unknown error, please report "
+                    "this to the libmtp developers\n");
+  return 1;
+
+  /* Successfully connected at least one device, so continue */
+  case LIBMTP_ERROR_NONE:
+    fprintf(stdout, "mtp-folders: Successfully connected\n");
+    fflush(stdout);
+  }
+  
+  /* iterate through connected MTP devices */
+  for(iter = device; iter != NULL; iter = iter->next)
+  {
+  	char *friendlyname;
+    /* Echo the friendly name so we know which device we are working with */
+    friendlyname = LIBMTP_Get_Friendlyname(iter);
+    if (friendlyname == NULL) {
+      printf("Friendly name: (NULL)\n");
+    } else {
+      printf("Friendly name: %s\n", friendlyname);
+      free(friendlyname);
+    }
+    
+    LIBMTP_Dump_Errorstack(iter);
+    LIBMTP_Clear_Errorstack(iter);    /* Get folder listing */
+
+    folders = LIBMTP_Get_Folder_List(iter);
+    
+    if (folders == NULL) {
+      fprintf(stdout, "No folders found\n");
+      LIBMTP_Dump_Errorstack(iter);
+      LIBMTP_Clear_Errorstack(iter);
+    } else {
+      dump_folder_list(folders,0);
+    }
+
+    LIBMTP_destroy_folder_t(folders);
+  }
+
+  
+  LIBMTP_Release_Device_List(device);
+  printf("OK.\n");
+
+  return 0;
+}
diff --git a/examples/format.c b/examples/format.c
new file mode 100644
index 0000000..52608a9
--- /dev/null
+++ b/examples/format.c
@@ -0,0 +1,86 @@
+/** 
+ * \file format.c
+ * Example program that formats the device storage.
+ *
+ * Copyright (C) 2006-2007 Linus Walleij <triad@df.lth.se>
+ *
+ * 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 "common.h"
+
+/**
+ * Returns 0 if OK (yes), 1 if not OK (no)
+ */
+static int prompt()
+{
+  char buff[2];
+  
+  while (1) {
+    fprintf(stdout, "> ");
+    if ( fgets(buff, sizeof(buff), stdin) == NULL ) {
+      if (ferror(stdin)) {
+        fprintf(stderr, "File error on stdin\n");
+      } else {
+        fprintf(stderr, "EOF on stdin\n");
+      }
+      return 1;
+    }
+    if (buff[0] == 'y') {
+      return 0;
+    } else if (buff[0] == 'n') {
+      return 1;
+    }
+  }
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device;
+  int ret;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    return 0;
+  }
+
+  printf("I will now format your device. This means that\n");
+  printf("all content (and licenses) will be lost forever.\n");
+  printf("you will not be able to undo this operation.\n");
+  printf("Continue? (y/n)\n");
+  if (prompt() == 0) {
+    // This will just format the first storage.
+    ret = LIBMTP_Format_Storage(device, device->storage);
+  } else {
+    printf("Aborted.\n");
+    ret = 0;
+  }
+
+  if ( ret != 0 ) {
+    printf("Failed to format device.\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+    LIBMTP_Release_Device(device);
+    return 1;
+  }
+
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  return 0;
+}
diff --git a/examples/getfile.c b/examples/getfile.c
new file mode 100644
index 0000000..7df2453
--- /dev/null
+++ b/examples/getfile.c
@@ -0,0 +1,91 @@
+/** 
+ * \file getfile.c
+ * Example program to retrieve a file off the device.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ *
+ * 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 "common.h"
+#include "pathutils.h"
+#include <stdlib.h>
+#include <limits.h>
+
+void getfile_function(char *,char *);
+void getfile_command(int, char **);
+void getfile_usage(void);
+
+extern LIBMTP_folder_t *folders;
+extern LIBMTP_file_t *files;
+extern LIBMTP_mtpdevice_t *device;
+
+void getfile_usage (void)
+{
+  fprintf(stderr, "getfile <fileid/trackid> <filename>\n");
+}
+
+void
+getfile_function(char * from_path,char * to_path)
+{
+  int id = parse_path (from_path,files,folders);
+  if (id > 0) {
+    printf("Getting %s to %s\n",from_path,to_path);
+    if (LIBMTP_Get_File_To_File(device, id, to_path, progress, NULL) != 0 ) {
+      printf("\nError getting file from MTP device.\n");
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+    }
+  }
+}
+
+
+void getfile_command(int argc, char **argv)
+{
+  uint32_t id;
+  char *endptr;
+  char *file;
+
+  // We need file ID and filename
+  if ( argc != 3 ) {
+    getfile_usage();
+    return;
+  }
+
+  // Sanity check song ID
+  id = strtoul(argv[1], &endptr, 10);
+  if ( *endptr != 0 ) {
+    fprintf(stderr, "illegal value %s\n", argv[1]);
+    return;
+  } else if ( ! id ) {
+    fprintf(stderr, "bad file/track id %u\n", id);
+    return;
+ }
+
+  // Filename, e.g. "foo.mp3"
+  file = argv[2];
+  printf("Getting file/track %d to local file %s\n", id, file);
+
+  // This function will also work just as well for tracks.
+  if (LIBMTP_Get_File_To_File(device, id, file, progress, NULL) != 0 ) {
+    printf("\nError getting file from MTP device.\n");
+  }
+  // Terminate progress bar.
+  printf("\n");
+  
+  return;
+}
+
diff --git a/examples/getplaylist.c b/examples/getplaylist.c
new file mode 100644
index 0000000..cc9c4ca
--- /dev/null
+++ b/examples/getplaylist.c
@@ -0,0 +1,93 @@
+/** 
+ * \file getplaylist.c
+ * Example program that lists the abstract playlists on the device.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ *
+ * 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 "common.h"
+#include <stdlib.h>
+#include <limits.h>
+
+static uint32_t dump_playlist(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl)
+{
+  uint32_t i;
+
+  printf("Number of items: %u\n", pl->no_tracks);
+  if(pl->no_tracks > 0) {
+    for(i=0;i<pl->no_tracks;i++) {
+      LIBMTP_track_t *track;
+      
+      track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]);
+      if (track != NULL) {
+	printf("   %u: %s - %s\n", pl->tracks[i], track->artist, track->title);
+	LIBMTP_destroy_track_t(track);
+      } else {
+	printf("   %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]);
+	LIBMTP_Dump_Errorstack(device);
+	LIBMTP_Clear_Errorstack(device);
+      }
+    }
+  }
+  return 0;
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device;
+  LIBMTP_playlist_t *playlist;
+  uint32_t id;
+  char *endptr;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  // We need file ID
+  if ( argc != 2 ) {
+    fprintf(stderr, "Just a playlist ID is required\n");
+    return 1;
+  }
+
+  // Sanity check playlist ID
+  id = strtoul(argv[1], &endptr, 10);
+  if ( *endptr != 0 ) {
+    fprintf(stderr, "illegal value %s\n", argv[1]);
+    return 1;
+  } else if ( ! id ) {
+    fprintf(stderr, "bad playlist id %u\n", id);
+    return 1;
+ }
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices. Connect/replug device and try again.\n");
+    exit (0);
+  }
+
+  playlist = LIBMTP_Get_Playlist(device,id);  
+
+  if (playlist != NULL) {
+    dump_playlist(device,playlist);
+  }
+
+  LIBMTP_destroy_playlist_t(playlist);
+  
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  exit (0);
+}
+
diff --git a/examples/hotplug.c b/examples/hotplug.c
new file mode 100644
index 0000000..c2f36c4
--- /dev/null
+++ b/examples/hotplug.c
@@ -0,0 +1,213 @@
+/** 
+ * \file hotplug.c
+ * Example program to create hotplug scripts.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006-2008 Marcus Meissner <marcus@jet.franken.de>
+ *
+ * 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 "common.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+static void usage(void)
+{
+  fprintf(stderr, "usage: hotplug [-u -H -i -a\"ACTION\"]\n");
+  fprintf(stderr, "       -u:  use udev syntax\n");
+  fprintf(stderr, "       -H:  use hal syntax\n");
+  fprintf(stderr, "       -i:  use usb.ids simple list syntax\n");
+  fprintf(stderr, "       -a\"ACTION\": perform udev action ACTION on attachment\n");
+  exit(1);
+}
+
+enum style {
+  style_usbmap,
+  style_udev,
+  style_hal,
+  style_usbids
+};
+
+int main (int argc, char **argv)
+{
+  LIBMTP_device_entry_t *entries;
+  int numentries;
+  int i;
+  int ret;
+  enum style style = style_usbmap;
+  int opt;
+  extern int optind;
+  extern char *optarg;
+  char *udev_action = NULL;
+  char default_udev_action[] = "SYMLINK+=\"libmtp-%k\", MODE=\"666\"";
+  char *action; // To hold the action actually used.
+  uint16_t last_vendor = 0x0000U;  
+
+  while ( (opt = getopt(argc, argv, "uUiHa:")) != -1 ) {
+    switch (opt) {
+    case 'a':
+      udev_action = strdup(optarg);
+    case 'u':
+      style = style_udev;
+      break;
+    case 'H':
+      style = style_hal;
+      break;
+    case 'i':
+      style = style_usbids;
+      break;
+    default:
+      usage();
+    }
+  }
+
+  if (udev_action != NULL) {
+    action = udev_action;
+  } else {
+    action = default_udev_action;
+  }
+
+  LIBMTP_Init();
+  ret = LIBMTP_Get_Supported_Devices_List(&entries, &numentries);
+  if (ret == 0) {
+    switch (style) {
+    case style_udev:
+      printf("# UDEV-style hotplug map for libmtp\n");
+      printf("# Put this file in /etc/udev/rules.d\n\n");
+      printf("ACTION!=\"add\", GOTO=\"libmtp_rules_end\"\n");
+      printf("ENV{MAJOR}!=\"?*\", GOTO=\"libmtp_rules_end\"\n");
+      printf("SUBSYSTEM==\"usb\", GOTO=\"libmtp_usb_rules\"\n"
+	     "# The following thing will be deprecated when older kernels are phased out.\n"
+             "SUBSYSTEM==\"usb_device\", GOTO=\"libmtp_usb_device_rules\"\n"
+	     "GOTO=\"libmtp_rules_end\"\n\n"
+	     "LABEL=\"libmtp_usb_rules\"\n\n");
+      break;
+    case style_usbmap:
+      printf("# This usermap will call the script \"libmtp.sh\" whenever a known MTP device is attached.\n\n");
+      break;
+    case style_hal:
+      printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <!-- -*- SGML -*- -->\n");
+      printf("<!-- This file was generated by %s - - fdi -->\n", argv[0]);
+      printf("<deviceinfo version=\"0.2\">\n");
+      printf("  <device>\n");
+      printf("    <match key=\"info.subsystem\" string=\"usb\">\n");
+      break;
+    case style_usbids:
+      printf("# usb.ids style device list from libmtp\n");
+      printf("# Compare: http://www.linux-usb.org/usb.ids\n");
+      break;
+    }
+
+    for (i = 0; i < numentries; i++) {
+      LIBMTP_device_entry_t * entry = &entries[i];
+
+      switch (style) {
+      case style_udev: 
+	{
+          printf("# %s %s\n", entry->vendor, entry->product);
+	  // Old style directly SYSFS named.
+	  // printf("SYSFS{idVendor}==\"%04x\", SYSFS{idProduct}==\"%04x\", %s\n", entry->vendor_id, entry->product_id, action);
+	  // Newer style
+	  printf("ATTR{idVendor}==\"%04x\", ATTR{idProduct}==\"%04x\", %s\n", entry->vendor_id, entry->product_id, action);
+	  break;
+        }
+      case style_usbmap:
+          printf("# %s %s\n", entry->vendor, entry->product);
+          printf("libmtp.sh    0x0003  0x%04x  0x%04x  0x0000  0x0000  0x00    0x00    0x00    0x00    0x00    0x00    0x00000000\n", entry->vendor_id, entry->product_id);
+          break;
+        case style_hal:
+          printf("      <!-- %s %s -->\n", entry->vendor, entry->product);
+          printf("      <match key=\"usb.vendor_id\" int=\"0x%04x\">\n", entry->vendor_id);
+          printf("        <match key=\"usb.product_id\" int=\"0x%04x\">\n", entry->product_id);
+          /* FIXME: If hal >=0.5.10 can be depended upon, the matches below with contains_not can instead use addset */
+          printf("          <match key=\"info.capabilities\" contains_not=\"portable_audio_player\">\n");
+          printf("            <append key=\"info.capabilities\" type=\"strlist\">portable_audio_player</append>\n");
+          printf("          </match>\n");
+          printf("          <merge key=\"info.vendor\" type=\"string\">%s</merge>\n", entry->vendor);
+          printf("          <merge key=\"info.product\" type=\"string\">%s</merge>\n", entry->product);
+          printf("          <merge key=\"info.category\" type=\"string\">portable_audio_player</merge>\n");
+          printf("          <merge key=\"portable_audio_player.access_method\" type=\"string\">user</merge>\n");
+          printf("          <match key=\"portable_audio_player.access_method.protocols\" contains_not=\"mtp\">\n");
+          printf("            <append key=\"portable_audio_player.access_method.protocols\" type=\"strlist\">mtp</append>\n");
+          printf("          </match>\n");
+          printf("          <append key=\"portable_audio_player.access_method.drivers\" type=\"strlist\">libmtp</append>\n");
+          /* FIXME: needs true list of formats ... But all of them can do MP3 and WMA */
+          printf("          <match key=\"portable_audio_player.output_formats\" contains_not=\"audio/mpeg\">\n");
+          printf("            <append key=\"portable_audio_player.output_formats\" type=\"strlist\">audio/mpeg</append>\n");
+          printf("          </match>\n");
+          printf("          <match key=\"portable_audio_player.output_formats\" contains_not=\"audio/x-ms-wma\">\n");
+          printf("            <append key=\"portable_audio_player.output_formats\" type=\"strlist\">audio/x-ms-wma</append>\n");
+          printf("          </match>\n");
+	  /* Special hack to support the OGG format - irivers, TrekStor and NormSoft (Palm) can always play these files! */
+	  if (entry->vendor_id == 0x4102 || // iriver
+	      entry->vendor_id == 0x066f || // TrekStor
+	      entry->vendor_id == 0x1703) { // NormSoft, Inc.
+	    printf("          <match key=\"portable_audio_player.output_formats\" contains_not=\"application/ogg\">\n");
+	    printf("            <append key=\"portable_audio_player.output_formats\" type=\"strlist\">application/ogg</append>\n");
+	    printf("          </match>\n");
+	  }
+          printf("          <merge key=\"portable_audio_player.libmtp.protocol\" type=\"string\">mtp</merge>\n");
+          printf("        </match>\n");
+          printf("      </match>\n");
+        break;
+        case style_usbids:
+          if (last_vendor != entry->vendor_id) {
+            printf("%04x\n", entry->vendor_id);
+          }
+          printf("\t%04x  %s %s\n", entry->product_id, entry->vendor, entry->product);
+        break;
+      }
+      last_vendor = entry->vendor_id;
+    }
+  } else {
+    printf("Error.\n");
+    exit(1);
+  }
+
+  // For backward comparibility with the #$!+@! ever changing
+  // udev rule style...
+  if (style == style_udev) {
+    printf("GOTO=\"libmtp_rules_end\"\n\n");
+    printf("LABEL=\"libmtp_usb_device_rules\"\n");
+    for (i = 0; i < numentries; i++) {
+      LIBMTP_device_entry_t * entry = &entries[i];
+
+      printf("# %s %s\n", entry->vendor, entry->product);
+      printf("ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\", %s\n", entry->vendor_id, entry->product_id, action); 
+    }
+    printf("GOTO=\"libmtp_rules_end\"\n\n");
+  }
+
+  // Then the footer.
+  switch (style) {
+  case style_usbmap:
+    break;
+  case style_udev:
+    printf("LABEL=\"libmtp_rules_end\"\n");
+    break;
+  case style_hal:
+    printf("    </match>\n");
+    printf("  </device>\n");
+    printf("</deviceinfo>\n");
+    break;
+  case style_usbids:
+    printf("\n");
+  }
+
+  exit (0);
+}
diff --git a/examples/newfolder.c b/examples/newfolder.c
new file mode 100644
index 0000000..884c2bc
--- /dev/null
+++ b/examples/newfolder.c
@@ -0,0 +1,70 @@
+/** 
+ * \file newfolder.c
+ * Example program to create a folder on the device.
+ *
+ * Copyright (C) 2006-2009 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ *
+ * 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 "common.h"
+#include "pathutils.h"
+#include <stdlib.h>
+#include <libgen.h>
+
+void newfolder_function(char *);
+void newfolder_command(int,char **);
+
+extern LIBMTP_folder_t *folders;
+extern LIBMTP_file_t *files;
+extern LIBMTP_mtpdevice_t *device;
+
+void newfolder_command (int argc, char **argv)
+{
+  uint32_t newid;
+  
+  if(argc != 4) {
+    printf("Usage: newfolder name <parent> <storage>\n");
+    printf("  parent = parent folder or 0 to create the new folder in the root dir\n");
+    printf("  storage = storage id or 0 to create the new folder on the primary storage\n");
+    return;
+  }
+  
+  newid = LIBMTP_Create_Folder(device, argv[1], atol(argv[2]), atol(argv[3]));
+  if (newid == 0) {
+    printf("Folder creation failed.\n");
+  } else {
+    printf("New folder created with ID: %d\n", newid);
+  }
+}
+
+void
+newfolder_function(char * path)
+{
+  printf("Creating new folder %s\n",path);
+  char * parent = dirname(path);
+  char * folder = basename(path);
+  int id = parse_path (parent,files,folders);
+  int newid = LIBMTP_Create_Folder(device, folder, id, 0);
+  if (newid == 0) {
+    printf("Folder creation failed.\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+  } else {
+    printf("New folder created with ID: %d\n", newid);
+  }
+}
+
diff --git a/examples/newplaylist.c b/examples/newplaylist.c
new file mode 100644
index 0000000..a5caf86
--- /dev/null
+++ b/examples/newplaylist.c
@@ -0,0 +1,109 @@
+/** 
+ * \file newplaylist.c
+ * Example program to create a playlist on a device.
+ *
+ * Copyright (C) 2006 Robert Reardon <rreardon@monkshatch.vispa.com>
+ *
+ * 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 "common.h"
+#include "string.h"
+#include <stdlib.h>
+#include <limits.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+static void usage(void) {
+  printf("Usage: newplaylist -i <fileid/trackid> -n <playlistname>\n");
+  exit(0);
+}
+
+int main (int argc, char **argv) {
+  int opt;
+  extern int optind;
+  extern char *optarg;
+  LIBMTP_mtpdevice_t *device = NULL;
+  int idcount = 0;
+  uint32_t *ids = NULL;
+  uint32_t *tmp = NULL;
+  char *playlistname = NULL;
+  char *rest;
+ 
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  while ( (opt = getopt(argc, argv, "hn:i:")) != -1 ) {
+    switch (opt) {
+    case 'h':
+      usage();
+    case 'i':
+      idcount++;
+      if ((tmp = realloc(ids, sizeof(uint32_t) * (idcount))) == NULL) {
+        printf("realloc failed\n");
+        return 1;
+      }
+      ids = tmp;
+      ids[(idcount-1)] = strtoul(optarg, &rest, 0);
+      break;
+    case 'n':
+      playlistname = strdup(optarg);
+      break;
+    default:
+      usage();
+    }
+  }
+  argc -= optind;
+  argv += optind;
+
+  if ( playlistname == NULL) {
+    printf("You need to supply a playlist name.\n");
+    usage();
+  }
+
+  if (idcount == 0) {
+    printf("You need to supply one or more track IDs\n");
+    usage();
+  }
+
+    
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    return 0;
+  }
+
+  LIBMTP_playlist_t *playlist = LIBMTP_new_playlist_t();
+  playlist->name = playlistname;
+  playlist->no_tracks = idcount;
+  playlist->tracks = ids;
+  playlist->parent_id = 0;
+  playlist->storage_id = 0;
+  int ret = LIBMTP_Create_New_Playlist(device,playlist);
+  if (ret != 0) {
+    printf("Couldn't create playlist object\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+  }
+  else {
+    printf("Created new playlist: %u\n", playlist->playlist_id);
+  }
+
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  return 0;
+}
+
diff --git a/examples/pathutils.c b/examples/pathutils.c
new file mode 100644
index 0000000..419a543
--- /dev/null
+++ b/examples/pathutils.c
@@ -0,0 +1,238 @@
+/** 
+ * \file pathutils.c
+ *
+ * Copyright (C) 2005-2008 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ *
+ * 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 "common.h"
+#include "pathutils.h"
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+#include <libgen.h>
+
+/* Find the folder_id of a given path
+ * Runs by walking through folders structure */
+static uint32_t
+lookup_folder_id (LIBMTP_folder_t * folder, char * path, char * parent)
+{
+  char * current;
+  uint32_t ret = (uint32_t) -1;
+
+  if (strcmp(path,"/")==0)
+    return 0;
+
+  if (folder == NULL) {
+    return ret;
+  }
+
+  current = malloc (strlen(parent) + strlen(folder->name) + 2);
+  sprintf(current,"%s/%s",parent,folder->name);
+  if (strcasecmp (path, current) == 0) {
+    free (current);
+    return folder->folder_id;
+  }
+  if (strncasecmp (path, current, strlen (current)) == 0) {
+    ret = lookup_folder_id (folder->child, path, current);
+  }
+  free (current);
+  if (ret != (uint32_t) (-1)) {
+    return ret;
+  }
+  ret = lookup_folder_id (folder->sibling, path, parent);
+  return ret;
+}
+
+/* Parses a string to find item_id */
+int
+parse_path (char * path, LIBMTP_file_t * files, LIBMTP_folder_t * folders)
+{
+  char *rest;
+  uint32_t item_id;
+
+  // Check if path is an item_id
+  if (*path != '/') {
+    item_id = strtoul(path, &rest, 0);
+    // really should check contents of "rest" here...
+    /* if not number, assume a file name */
+    if (item_id == 0) {
+      LIBMTP_file_t * file = files;
+
+      /* search for matching name */
+      while (file != NULL) {
+	if (strcasecmp (file->filename, path) == 0) {
+	  return file->item_id;
+	}
+	file = file->next;
+      }
+    }
+    return item_id;
+  }
+  // Check if path is a folder
+  item_id = lookup_folder_id(folders,path,"");
+  if (item_id == (uint32_t) -1) {
+    char * dirc = strdup(path);
+    char * basec = strdup(path);
+    char * parent = dirname(dirc);
+    char * filename = basename(basec);
+    uint32_t parent_id = lookup_folder_id(folders,parent,"");
+    LIBMTP_file_t * file;
+
+    file = files;
+    while (file != NULL) {
+      if (file->parent_id == parent_id) {
+        if (strcasecmp (file->filename, filename) == 0) {
+	  free(dirc);
+	  free(basec);
+          return file->item_id;
+        }
+      }
+      file = file->next;
+    }
+    free(dirc);
+    free(basec);
+  } else {
+    return item_id;
+  }
+
+  return -1;
+}
+
+int progress (const uint64_t sent, const uint64_t total, void const * const data)
+{
+  int percent = (sent*100)/total;
+#ifdef __WIN32__
+  printf("Progress: %I64u of %I64u (%d%%)\r", sent, total, percent);
+#else
+  printf("Progress: %llu of %llu (%d%%)\r", sent, total, percent);
+#endif
+  fflush(stdout);
+  return 0;
+}
+
+/* Find the file type based on extension */
+LIBMTP_filetype_t
+find_filetype (const char * filename)
+{
+  char *ptype;
+  LIBMTP_filetype_t filetype;
+
+#ifdef __WIN32__
+  ptype = strrchr(filename, '.');
+#else
+  ptype = rindex(filename,'.');
+#endif
+  // This accounts for the case with a filename without any "." (period).
+  if (!ptype) {
+    ptype = "";
+  } else {
+    ++ptype;
+  }
+
+  /* This need to be kept constantly updated as new file types arrive. */
+  if (!strcasecmp (ptype, "wav")) {
+    filetype = LIBMTP_FILETYPE_WAV;
+  } else if (!strcasecmp (ptype, "mp3")) {
+    filetype = LIBMTP_FILETYPE_MP3;
+  } else if (!strcasecmp (ptype, "wma")) {
+    filetype = LIBMTP_FILETYPE_WMA;
+  } else if (!strcasecmp (ptype, "ogg")) {
+    filetype = LIBMTP_FILETYPE_OGG;
+  } else if (!strcasecmp (ptype, "mp4")) {
+    filetype = LIBMTP_FILETYPE_MP4;
+  } else if (!strcasecmp (ptype, "wmv")) {
+    filetype = LIBMTP_FILETYPE_WMV;
+  } else if (!strcasecmp (ptype, "avi")) {
+    filetype = LIBMTP_FILETYPE_AVI;
+  } else if (!strcasecmp (ptype, "mpeg") || !strcasecmp (ptype, "mpg")) {
+    filetype = LIBMTP_FILETYPE_MPEG;
+  } else if (!strcasecmp (ptype, "asf")) {
+    filetype = LIBMTP_FILETYPE_ASF;
+  } else if (!strcasecmp (ptype, "qt") || !strcasecmp (ptype, "mov")) {
+    filetype = LIBMTP_FILETYPE_QT;
+  } else if (!strcasecmp (ptype, "wma")) {
+    filetype = LIBMTP_FILETYPE_WMA;
+  } else if (!strcasecmp (ptype, "jpg") || !strcasecmp (ptype, "jpeg")) {
+    filetype = LIBMTP_FILETYPE_JPEG;
+  } else if (!strcasecmp (ptype, "jfif")) {
+    filetype = LIBMTP_FILETYPE_JFIF;
+  } else if (!strcasecmp (ptype, "tif") || !strcasecmp (ptype, "tiff")) {
+    filetype = LIBMTP_FILETYPE_TIFF;
+  } else if (!strcasecmp (ptype, "bmp")) {
+    filetype = LIBMTP_FILETYPE_BMP;
+  } else if (!strcasecmp (ptype, "gif")) {
+    filetype = LIBMTP_FILETYPE_GIF;
+  } else if (!strcasecmp (ptype, "pic") || !strcasecmp (ptype, "pict")) {
+    filetype = LIBMTP_FILETYPE_PICT;
+  } else if (!strcasecmp (ptype, "png")) {
+    filetype = LIBMTP_FILETYPE_PNG;
+  } else if (!strcasecmp (ptype, "wmf")) {
+    filetype = LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT;
+  } else if (!strcasecmp (ptype, "ics")) {
+    filetype = LIBMTP_FILETYPE_VCALENDAR2;
+  } else if (!strcasecmp (ptype, "exe") || !strcasecmp (ptype, "com") ||
+	     !strcasecmp (ptype, "bat") || !strcasecmp (ptype, "dll") ||
+	     !strcasecmp (ptype, "sys")) {
+    filetype = LIBMTP_FILETYPE_WINEXEC;
+  } else if (!strcasecmp (ptype, "aac")) {
+    filetype = LIBMTP_FILETYPE_AAC;
+  } else if (!strcasecmp (ptype, "mp2")) {
+    filetype = LIBMTP_FILETYPE_MP2;
+  } else if (!strcasecmp (ptype, "flac")) {
+    filetype = LIBMTP_FILETYPE_FLAC;
+  } else if (!strcasecmp (ptype, "m4a")) {
+    filetype = LIBMTP_FILETYPE_M4A;
+  } else if (!strcasecmp (ptype, "doc")) {
+    filetype = LIBMTP_FILETYPE_DOC;
+  } else if (!strcasecmp (ptype, "xml")) {
+    filetype = LIBMTP_FILETYPE_XML;
+  } else if (!strcasecmp (ptype, "xls")) {
+    filetype = LIBMTP_FILETYPE_XLS;
+  } else if (!strcasecmp (ptype, "ppt")) {
+    filetype = LIBMTP_FILETYPE_PPT;
+  } else if (!strcasecmp (ptype, "mht")) {
+    filetype = LIBMTP_FILETYPE_MHT;
+  } else if (!strcasecmp (ptype, "jp2")) {
+    filetype = LIBMTP_FILETYPE_JP2;
+  } else if (!strcasecmp (ptype, "jpx")) {
+    filetype = LIBMTP_FILETYPE_JPX;
+  } else if (!strcasecmp (ptype, "bin")) {
+    filetype = LIBMTP_FILETYPE_FIRMWARE;
+  } else if (!strcasecmp (ptype, "vcf")) {
+    filetype = LIBMTP_FILETYPE_VCARD3;
+  } else {
+    /* Tagging as unknown file type */
+    filetype = LIBMTP_FILETYPE_UNKNOWN;
+  }
+  printf("type: %s, %d\n", ptype, filetype);
+  return filetype;
+}
+
+/* Function that compensate for missing libgen.h on Windows */
+#ifndef HAVE_LIBGEN_H
+static char *basename(char *in) {
+  char *p;
+
+  if (in == NULL)
+    return NULL;
+  p = in + strlen(in) - 1;
+  while (*p != '\\' && *p != '/' && *p != ':')
+    { p--; }
+  return ++p;
+}
+#endif
diff --git a/examples/pathutils.h b/examples/pathutils.h
new file mode 100644
index 0000000..f40b6d6
--- /dev/null
+++ b/examples/pathutils.h
@@ -0,0 +1,29 @@
+/** 
+ * \file pathutils.h
+ *
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ *
+ * 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.
+ */
+#ifndef PATHUTILS_H_INCLUSION_GUARD
+#define PATHUTILS_H_INCLUSION_GUARD
+int parse_path (char *, LIBMTP_file_t *, LIBMTP_folder_t *);
+LIBMTP_filetype_t find_filetype (const char *);
+int progress (const uint64_t, const uint64_t, void const * const); 
+#ifndef HAVE_LIBGEN_H
+char *basename(char *in);
+#endif
+#endif
diff --git a/examples/playlists.c b/examples/playlists.c
new file mode 100644
index 0000000..1416c61
--- /dev/null
+++ b/examples/playlists.c
@@ -0,0 +1,82 @@
+/** 
+ * \file playlists.c
+ * Example program to list the playlists on a device.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ *
+ * 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 "common.h"
+#include <stdlib.h>
+
+static void dump_plinfo(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl)
+{
+  uint32_t i;
+
+  printf("Playlist ID: %d\n", pl->playlist_id);
+  if (pl->name != NULL)
+    printf("   Name: %s\n", pl->name);
+  printf("   Parent ID: %d\n", pl->parent_id);
+  printf("   Tracks:\n");
+
+  for (i = 0; i < pl->no_tracks; i++) {
+    LIBMTP_track_t *track;
+    
+    track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]);
+    if (track != NULL) {
+      printf("      %u: %s - %s\n", pl->tracks[i], track->artist, track->title);
+      LIBMTP_destroy_track_t(track);
+    } else {
+      printf("      %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]);
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+    }
+  }
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device;
+  LIBMTP_playlist_t *playlists;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    exit (0);
+  }
+  
+  // Get playlist listing.
+  playlists = LIBMTP_Get_Playlist_List(device);
+  if (playlists == NULL) {
+    printf("No playlists.\n");
+  } else {
+    LIBMTP_playlist_t *pl, *tmp;
+    pl = playlists;
+    while (pl != NULL) {
+      dump_plinfo(device, pl);
+      tmp = pl;
+      pl = pl->next;
+      LIBMTP_destroy_playlist_t(tmp);
+    }
+  }
+    
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  exit (0);
+}
diff --git a/examples/reset.c b/examples/reset.c
new file mode 100644
index 0000000..f8ef376
--- /dev/null
+++ b/examples/reset.c
@@ -0,0 +1,85 @@
+/** 
+ * \file reset.c
+ * Example program that resets the device.
+ *
+ * Copyright (C) 2007 Linus Walleij <triad@df.lth.se>
+ *
+ * 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 "common.h"
+
+/**
+ * Returns 0 if OK (yes), 1 if not OK (no)
+ */
+static int prompt()
+{
+  char buff[2];
+  
+  while (1) {
+    fprintf(stdout, "> ");
+    if ( fgets(buff, sizeof(buff), stdin) == NULL ) {
+      if (ferror(stdin)) {
+        fprintf(stderr, "File error on stdin\n");
+      } else {
+        fprintf(stderr, "EOF on stdin\n");
+      }
+      return 1;
+    }
+    if (buff[0] == 'y') {
+      return 0;
+    } else if (buff[0] == 'n') {
+      return 1;
+    }
+  }
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device;
+  int ret;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    return 0;
+  }
+
+  printf("I will now reset your device. This means that\n");
+  printf("the device may go inactive immediately and may report errors.\n");
+  printf("Continue? (y/n)\n");
+  if (prompt() == 0) {
+    ret = LIBMTP_Reset_Device(device);
+  } else {
+    printf("Aborted.\n");
+    ret = 0;
+  }
+
+  if ( ret != 0 ) {
+    printf("Failed to reset device.\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+    LIBMTP_Release_Device(device);
+    return 1;
+  }
+
+  // It is not possible to release the device after successful reset!
+  // LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  return 0;
+}
diff --git a/examples/sendfile.c b/examples/sendfile.c
new file mode 100644
index 0000000..3155622
--- /dev/null
+++ b/examples/sendfile.c
@@ -0,0 +1,102 @@
+/** 
+ * \file sendfile.c
+ * Example program to send an arbitrary file to a device.
+ *
+ * Copyright (C) 2005-2009 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ *
+ * 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 "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <libgen.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include "common.h"
+#include "libmtp.h"
+#include "pathutils.h"
+
+extern LIBMTP_folder_t *folders;
+extern LIBMTP_file_t *files;
+extern LIBMTP_mtpdevice_t *device;
+
+int sendfile_function(char *, char *);
+void sendfile_command(int, char **);
+void sendfile_usage(void);
+
+void sendfile_usage(void)
+{
+  fprintf(stderr, "usage: sendfile <local filename> <remote filename>\n");
+}
+
+int sendfile_function(char * from_path, char *to_path)
+{
+  printf("Sending %s to %s\n",from_path,to_path);
+  char *filename;
+  uint64_t filesize;
+  struct stat sb;
+  LIBMTP_file_t *genfile;
+  int ret;
+  uint32_t parent_id = 0;
+
+  if ( stat(from_path, &sb) == -1 ) {
+    fprintf(stderr, "%s: ", from_path);
+    perror("stat");
+    exit(1);
+  }
+
+  filesize = sb.st_size;
+  filename = basename(from_path);
+  parent_id = parse_path (to_path,files,folders);
+  if (parent_id == -1) {
+    printf("Parent folder could not be found, skipping\n");
+    return 0;
+  }
+  
+  genfile = LIBMTP_new_file_t();
+  genfile->filesize = filesize;
+  genfile->filename = strdup(filename);
+  genfile->filetype = find_filetype (filename);
+  genfile->parent_id = parent_id;
+  genfile->storage_id = 0;
+
+  printf("Sending file...\n");
+  ret = LIBMTP_Send_File_From_File(device, from_path, genfile, progress, NULL);
+  printf("\n");
+  if (ret != 0) {
+    printf("Error sending file.\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+  } else {
+    printf("New file ID: %d\n", genfile->item_id);
+  }
+
+  LIBMTP_destroy_file_t(genfile);
+
+  return 0;
+}
+
+void sendfile_command (int argc, char **argv) {
+  if (argc < 3) {
+    sendfile_usage();
+    return;
+  }
+  sendfile_function(argv[1],argv[2]);
+}
diff --git a/examples/sendtr.c b/examples/sendtr.c
new file mode 100644
index 0000000..212c088
--- /dev/null
+++ b/examples/sendtr.c
@@ -0,0 +1,443 @@
+/** 
+ * \file sendtr.c
+ * Example program to send a music track to a device.
+ * This program is derived from the exact equivalent in libnjb.
+ * based on Enrique Jorreto Ledesma's work on the original program by 
+ * Shaun Jackman and Linus Walleij.
+ *
+ * Copyright (C) 2003-2009 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2003-2005 Shaun Jackman
+ * Copyright (C) 2003-2005 Enrique Jorrete Ledesma
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ * Copyright (C) 2008 Nicolas Pennequin <nicolas.pennequin@free.fr>
+ * Copyright (C) 2008 Joseph Nahmias <joe@nahmias.net>
+ *
+ * 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 "config.h"
+#include "common.h"
+#include "util.h"
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+#include <libgen.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+#include "libmtp.h"
+#include "pathutils.h"
+
+extern LIBMTP_folder_t *folders;
+extern LIBMTP_file_t *files;
+extern LIBMTP_mtpdevice_t *device;
+
+int sendtrack_function (char *, char *, char *, char *, char *, char *, char *, char *, uint16_t, uint16_t, uint16_t, uint32_t);
+void sendtrack_command (int, char **);
+void sendtrack_usage (void);
+
+void sendtrack_usage (void)
+{
+  fprintf(stderr, "usage: sendtr [ -D debuglvl ] [ -q ]\n");
+  fprintf(stderr, "-t <title> -a <artist> -A <Album artist> -w <writer or composer>\n");
+  fprintf(stderr, "    -l <album> -c <codec> -g <genre> -n <track number> -y <year>\n");
+  fprintf(stderr, "       -d <duration in seconds> -s <storage_id> <local path> <remote path>\n");
+  fprintf(stderr, "(-q means the program will not ask for missing information.)\n");
+}
+
+static char *prompt (const char *prompt, char *buffer, size_t bufsz, int required)
+{
+  char *cp, *bp;
+  
+  while (1) {
+    fprintf(stdout, "%s> ", prompt);
+    if ( fgets(buffer, bufsz, stdin) == NULL ) {
+      if (ferror(stdin)) {
+	perror("fgets");
+      } else {
+	fprintf(stderr, "EOF on stdin\n");
+      }
+      return NULL;
+    }
+    
+    cp = strrchr(buffer, '\n');
+    if ( cp != NULL ) *cp = '\0';
+    
+    bp = buffer;
+    while ( bp != cp ) {
+      if ( *bp != ' ' && *bp != '\t' ) return bp;
+      bp++;
+    }
+    
+    if (! required) return bp;
+  }
+}
+
+static int add_track_to_album(LIBMTP_album_t *albuminfo, LIBMTP_track_t *trackmeta)
+{
+  LIBMTP_album_t *album;
+  LIBMTP_album_t *found_album = NULL;
+  int ret;
+
+  /* Look for the album */
+  album = LIBMTP_Get_Album_List(device);
+  while(album != NULL) {
+    if ((album->name != NULL &&
+	album->artist != NULL &&
+	!strcmp(album->name, albuminfo->name) &&
+	!strcmp(album->artist, albuminfo->artist)) ||
+	  (album->name != NULL &&
+	album->composer != NULL &&
+	!strcmp(album->name, albuminfo->name) &&
+	!strcmp(album->composer, albuminfo->composer))) {
+      /* Disconnect this album for later use */
+      found_album = album;
+      album = album->next;
+      found_album->next = NULL;
+    } else {
+      LIBMTP_album_t *tmp;
+
+      tmp = album;
+      album = album->next;
+      LIBMTP_destroy_album_t(tmp);
+    }
+  }
+  
+  if (found_album != NULL) {
+    uint32_t *tracks;
+
+    tracks = (uint32_t *)malloc((found_album->no_tracks+1) * sizeof(uint32_t));
+    printf("Album \"%s\" found: updating...\n", found_album->name);
+    if (!tracks) {
+      printf("failed malloc in add_track_to_album()\n");
+      return 1;
+    }
+    found_album->no_tracks++;
+    if (found_album->tracks != NULL) {
+      memcpy(tracks, found_album->tracks, found_album->no_tracks * sizeof(uint32_t));
+      free(found_album->tracks);
+    }
+    tracks[found_album->no_tracks-1] = trackmeta->item_id;
+    found_album->tracks = tracks;
+    ret = LIBMTP_Update_Album(device, found_album);
+    LIBMTP_destroy_album_t(found_album);
+  } else {
+    uint32_t *trackid;
+    
+    trackid = (uint32_t *)malloc(sizeof(uint32_t));
+    *trackid = trackmeta->item_id;
+    albuminfo->tracks = trackid;
+    albuminfo->no_tracks = 1;
+    albuminfo->storage_id = trackmeta->storage_id;
+    printf("Album doesn't exist: creating...\n");
+    ret = LIBMTP_Create_New_Album(device, albuminfo);
+    /* albuminfo will be destroyed later by caller */
+  }
+  
+  if (ret != 0) {
+    printf("Error creating or updating album.\n");
+    printf("(This could be due to that your device does not support albums.)\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+  } else {
+    printf("success!\n");
+  }
+  return ret;
+}
+
+int sendtrack_function(char * from_path, char * to_path, char *partist, char *palbumartist, char *ptitle, char *pgenre, char *palbum, char *pcomposer, uint16_t tracknum, uint16_t length, uint16_t year, uint32_t storageid)
+{
+  char *filename, *parent;
+  char artist[80], albumartist[80], title[80], genre[80], album[80], composer[80];
+  char num[80];
+  uint64_t filesize;
+  uint32_t parent_id = 0;
+  struct stat sb;
+  LIBMTP_track_t *trackmeta;
+  LIBMTP_album_t *albuminfo;
+  int ret;
+
+  printf("Sending track %s to %s\n",from_path,to_path);
+
+  trackmeta = LIBMTP_new_track_t();
+  albuminfo = LIBMTP_new_album_t();
+
+  parent = dirname(strdup(to_path));
+  filename = basename(strdup(to_path));
+  parent_id = parse_path (parent,files,folders);
+  if (parent_id == -1) {
+    printf("Parent folder could not be found, skipping\n");
+    return 1;
+  }
+
+  if ( stat(from_path, &sb) == -1 ) {
+    fprintf(stderr, "%s: ", from_path);
+    perror("stat");
+    return 1;
+  } else if (S_ISREG (sb.st_mode)) {
+    filesize = sb.st_size;
+    trackmeta->filetype = find_filetype (from_path);
+    if (!LIBMTP_FILETYPE_IS_TRACK(trackmeta->filetype)) {
+      printf("Not a valid track codec: \"%s\"\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
+      return 1;
+    }
+
+    if (ptitle == NULL) {
+      ptitle = prompt("Title", title, 80, 0);
+    }
+    if (!strlen(ptitle))
+      ptitle = NULL;
+
+    if (palbum == NULL) {
+      palbum = prompt("Album", album, 80, 0);
+    }
+    if (!strlen(palbum))
+      palbum = NULL;
+
+    if (palbumartist == NULL) {
+      palbumartist = prompt("Album artist", albumartist, 80, 0);
+    }
+    if (partist == NULL) {
+      partist = prompt("Artist", artist, 80, 0);
+    }
+    if (!strlen(partist))
+      partist = NULL;
+
+    if (pcomposer == NULL) {
+      pcomposer = prompt("Writer or Composer", composer, 80, 0);
+    }
+    if (!strlen(pcomposer))
+      pcomposer = NULL;
+
+    if (pgenre == NULL) {
+      pgenre = prompt("Genre", genre, 80, 0);
+    }
+    if (!strlen(pgenre))
+      pgenre = NULL;
+
+    if (tracknum == 0) {
+      char *pnum;
+      if ( (pnum = prompt("Track number", num, 80, 0)) == NULL )
+      tracknum = 0;
+      if ( strlen(pnum) ) {
+        tracknum = strtoul(pnum, 0, 10);
+      } else {
+        tracknum = 0;
+      }
+    }
+
+    if (year == 0) {
+      char *pnum;
+      if ( (pnum = prompt("Year", num, 80, 0)) == NULL )
+        year = 0;
+      if ( strlen(pnum) ) {
+        year = strtoul(pnum, 0, 10);
+      } else {
+        year = 0;
+      }
+    }
+
+    if (length == 0) {
+      char *pnum;
+      if ( (pnum = prompt("Length", num, 80, 0)) == NULL )
+        length = 0;
+      if ( strlen(pnum) ) {
+        length = strtoul(pnum, 0, 10);
+      } else {
+        length = 0;
+      }
+    }
+    
+    printf("Sending track:\n");
+    printf("Codec:     %s\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
+    if (ptitle) {
+      printf("Title:     %s\n", ptitle);
+      trackmeta->title = strdup(ptitle);
+    }
+    if (palbum) {
+      printf("Album:     %s\n", palbum);
+      trackmeta->album = strdup(palbum);
+      albuminfo->name = strdup(palbum);
+    }
+    if (palbumartist) {
+      printf("Album artist:    %s\n", palbumartist);
+      albuminfo->artist = strdup(palbumartist);
+    }
+    if (partist) {
+      printf("Artist:    %s\n", partist);
+      trackmeta->artist = strdup(partist);
+      if (palbumartist == NULL)
+      albuminfo->artist = strdup(partist);
+    }
+
+    if (pcomposer) {
+      printf("Writer or Composer:    %s\n", pcomposer);
+      trackmeta->composer = strdup(pcomposer);
+      albuminfo->composer = strdup(pcomposer);
+    }
+    if (pgenre) {
+      printf("Genre:     %s\n", pgenre);
+      trackmeta->genre = strdup(pgenre);
+      albuminfo->genre = strdup(pgenre);
+    }
+    if (year > 0) {
+      char tmp[80];
+      printf("Year:      %d\n", year);
+      snprintf(tmp, sizeof(tmp)-1, "%4d0101T0000.0", year);
+      tmp[sizeof(tmp)-1] = '\0';
+      trackmeta->date = strdup(tmp);
+    }
+    if (tracknum > 0) {
+      printf("Track no:  %d\n", tracknum);
+      trackmeta->tracknumber = tracknum;
+    }
+    if (length > 0) {
+      printf("Length:    %d\n", length);
+      // Multiply by 1000 since this is in milliseconds
+      trackmeta->duration = length * 1000;
+    }
+    // We should always have this
+    if (filename != NULL) {
+      trackmeta->filename = strdup(filename);
+    }
+    trackmeta->filesize = filesize;
+    trackmeta->parent_id = parent_id;
+    {
+        int rc;
+        char *desc = NULL;
+        LIBMTP_devicestorage_t *pds = NULL;
+
+        if ( 0 != (rc=LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED)) )
+        {
+            perror("LIBMTP_Get_Storage()");
+            exit(-1);
+        }
+        for (pds = device->storage; pds != NULL; pds = pds->next)
+        {
+            if (pds->id == storageid)
+            {
+                desc = strdup(pds->StorageDescription);
+                break;
+            }
+        }
+        if (NULL != desc)
+        {
+            printf("Storage ID: %s (%u)\n", desc, storageid);
+            free(desc);
+        }
+        else
+            printf("Storage ID: %u\n", storageid);
+        trackmeta->storage_id = storageid;
+    }
+      
+    printf("Sending track...\n");
+    ret = LIBMTP_Send_Track_From_File(device, from_path, trackmeta, progress, NULL);
+    printf("\n");
+    if (ret != 0) {
+      printf("Error sending track.\n");
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+    } else {
+      printf("New track ID: %d\n", trackmeta->item_id);
+    }
+
+    /* Add here add to album call */
+    if (palbum)
+      ret = add_track_to_album(albuminfo, trackmeta);
+
+    LIBMTP_destroy_album_t(albuminfo);
+    LIBMTP_destroy_track_t(trackmeta);
+
+    return 0;
+  }
+  return 0;
+}
+
+void sendtrack_command (int argc, char **argv) {
+  int opt;
+  extern int optind;
+  extern char *optarg;
+  char *partist = NULL;
+  char *palbumartist = NULL;
+  char *pcomposer = NULL;
+  char *ptitle = NULL;
+  char *pgenre = NULL;
+  char *pcodec = NULL;
+  char *palbum = NULL;
+  uint16_t tracknum = 0;
+  uint16_t length = 0;
+  uint16_t year = 0;
+  uint16_t quiet = 0;
+  uint32_t storageid = 0;
+  while ( (opt = getopt(argc, argv, "qD:t:a:A:w:l:c:g:n:d:y:s:")) != -1 ) {
+    switch (opt) {
+    case 't':
+      ptitle = strdup(optarg);
+      break;
+    case 'a':
+      partist = strdup(optarg);
+      break;
+    case 'A':
+      palbumartist = strdup(optarg);
+      break;
+    case 'w':
+      pcomposer = strdup(optarg);
+      break;
+    case 'l':
+      palbum = strdup(optarg);
+      break;
+    case 'c':
+      pcodec = strdup(optarg); // FIXME: DSM check for MP3, WAV or WMA
+      break;
+    case 'g':
+      pgenre = strdup(optarg);
+      break;
+    case 'n':
+      tracknum = atoi(optarg);
+      break;
+    case 's':
+      storageid = (uint32_t) strtoul(optarg, NULL, 0);
+      break;
+    case 'd':
+      length = atoi(optarg);
+      break;
+    case 'y':
+      year = atoi(optarg);
+      break;
+    case 'q':
+      quiet = 1;
+      break;
+    default:
+      sendtrack_usage();
+    }
+  }
+  argc -= optind;
+  argv += optind;
+  
+  if ( argc != 2 ) {
+    printf("You need to pass a filename and destination.\n");
+    sendtrack_usage();
+    return;
+  }
+
+  checklang();
+  
+  printf("%s,%s,%s,%s,%s,%s,%s,%s,%d%d,%d,%u\n",argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer,tracknum, length, year, storageid);
+  sendtrack_function(argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer, tracknum, length, year, storageid);
+}
diff --git a/examples/thumb.c b/examples/thumb.c
new file mode 100644
index 0000000..2718a0c
--- /dev/null
+++ b/examples/thumb.c
@@ -0,0 +1,131 @@
+/** 
+ * \file thumb.c
+ * Example program to send and associate album art to an entity 
+ * on a device.
+ *
+ * Copyright (C) 2006 Robert Reardon <rreardon@monkshatch.vispa.com>
+ *
+ * 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 "config.h"
+#include "common.h"
+#include "string.h"
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <limits.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_UIO_H
+#include <sys/uio.h>
+#endif
+#include <sys/stat.h>
+
+static void usage(void) {
+  printf("Usage: thumb -i <fileid/trackid> <imagefile>\n");
+  exit(0);
+}
+
+int main (int argc, char **argv) {
+  int opt;
+  extern int optind;
+  extern char *optarg;
+  LIBMTP_mtpdevice_t *device = NULL;
+  int fd;
+  uint32_t id = 0;
+  uint64_t filesize;
+  uint8_t *imagedata = NULL;
+  char *path = NULL;
+  char *rest;
+  struct stat statbuff;
+  int ret;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  while ( (opt = getopt(argc, argv, "hi:")) != -1 ) {
+    switch (opt) {
+    case 'h':
+      usage();
+    case 'i':
+      id = strtoul(optarg, &rest, 0);
+      break;
+    default:
+      usage();
+    }
+  }
+  argc -= optind;
+  argv += optind;
+
+  if ( argc != 1 ) {
+    printf("You need to pass a filename.\n");
+    usage();
+  }
+
+  path = argv[0];
+
+  if ( stat(path, &statbuff) == -1 ) {
+    fprintf(stderr, "%s: ", path);
+    perror("stat");
+    exit(1);
+  }
+  filesize = (uint64_t) statbuff.st_size;
+  imagedata = malloc(filesize * sizeof(uint16_t));
+
+#ifdef __WIN32__
+  if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
+#else
+  if ( (fd = open(path, O_RDONLY)) == -1) {
+#endif
+    printf("Couldn't open image file %s (%s)\n",path,strerror(errno));
+    return 1;
+  }
+  else {
+    read(fd, imagedata, filesize);
+    close(fd);
+  }
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    return 0;
+  }
+  
+  LIBMTP_filesampledata_t *thumb = LIBMTP_new_filesampledata_t();
+
+  int i;
+  thumb->data = malloc(sizeof(uint16_t) * filesize);
+  for (i = 0; i < filesize; i++) {
+    thumb->data[i] = imagedata[i];
+  }
+
+  thumb->size = filesize;
+  thumb->filetype = LIBMTP_FILETYPE_JPEG;
+  
+  ret = LIBMTP_Send_Representative_Sample(device,id,thumb);
+  if (ret != 0) {
+    printf("Couldn't send thumbnail\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+  }
+
+  free(imagedata);
+  LIBMTP_destroy_filesampledata_t(thumb);
+
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  return 0;
+}
diff --git a/examples/tracks.c b/examples/tracks.c
new file mode 100644
index 0000000..262a8c8
--- /dev/null
+++ b/examples/tracks.c
@@ -0,0 +1,148 @@
+/** 
+ * \file tracks.c
+ * Example program to list the tracks on a device.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ *
+ * 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 "common.h"
+#include <stdlib.h>
+
+static void dump_trackinfo(LIBMTP_track_t *track)
+{
+  printf("Track ID: %u\n", track->item_id);
+  if (track->title != NULL)
+    printf("   Title: %s\n", track->title);
+  if (track->artist != NULL)
+    printf("   Artist: %s\n", track->artist);
+  if (track->genre != NULL)
+    printf("   Genre: %s\n", track->genre);
+  if (track->composer != NULL)
+    printf("   Composer: %s\n", track->composer);
+  if (track->album != NULL)
+    printf("   Album: %s\n", track->album);
+  if (track->date != NULL)
+    printf("   Date: %s\n", track->date);
+  if (track->filename != NULL)
+    printf("   Origfilename: %s\n", track->filename);
+  printf("   Track number: %d\n", track->tracknumber);
+  printf("   Duration: %d milliseconds\n", track->duration);
+#ifdef __WIN32__
+  printf("   File size %I64u bytes\n", track->filesize);
+#else
+  printf("   File size %llu bytes\n", (long long unsigned int) track->filesize);
+#endif
+  printf("   Filetype: %s\n", LIBMTP_Get_Filetype_Description(track->filetype));
+  if (track->samplerate != 0) {
+    printf("   Sample rate: %u Hz\n", track->samplerate);
+  }
+  if (track->nochannels != 0) {
+    printf("   Number of channels: %u\n", track->nochannels);
+  }
+  if (track->wavecodec != 0) {
+    printf("   WAVE fourCC code: 0x%08X\n", track->wavecodec);
+  }
+  if (track->bitrate != 0) {
+    printf("   Bitrate: %u bits/s\n", track->bitrate);
+  }
+  if (track->bitratetype != 0) {
+    if (track->bitratetype == 1) {
+      printf("   Bitrate type: Constant\n");
+    } else if (track->bitratetype == 2) {
+      printf("   Bitrate type: Variable (VBR)\n");
+    } else if (track->bitratetype == 3) {
+      printf("   Bitrate type: Free\n");
+    } else {
+      printf("   Bitrate type: Unknown/Erroneous value\n");
+    }
+  }
+  if (track->rating != 0) {
+    printf("   User rating: %u (out of 100)\n", track->rating);
+  }
+  if (track->usecount != 0) {
+    printf("   Use count: %u times\n", track->usecount);
+  }
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device_list, *iter;
+  LIBMTP_track_t *tracks;
+
+  LIBMTP_Init();
+  fprintf(stdout, "Attempting to connect device(s)\n");
+
+  switch(LIBMTP_Get_Connected_Devices(&device_list))
+  {
+  case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
+    fprintf(stdout, "mtp-tracks: No Devices have been found\n");
+    return 0;
+  case LIBMTP_ERROR_CONNECTING:
+    fprintf(stderr, "mtp-tracks: There has been an error connecting. Exit\n");
+    return 1;
+  case LIBMTP_ERROR_MEMORY_ALLOCATION:
+    fprintf(stderr, "mtp-tracks: Memory Allocation Error. Exit\n");
+    return 1;
+ 
+  /* Unknown general errors - This should never execute */
+  case LIBMTP_ERROR_GENERAL:
+  default:
+    fprintf(stderr, "mtp-tracks: Unknown error, please report "
+                    "this to the libmtp developers\n");
+  return 1;
+
+  /* Successfully connected at least one device, so continue */
+  case LIBMTP_ERROR_NONE:
+    fprintf(stdout, "mtp-tracks: Successfully connected\n");
+    fflush(stdout);
+  }
+  
+  /* iterate through connected MTP devices */
+  for(iter = device_list; iter != NULL; iter = iter->next)
+  {
+  	char *friendlyname;
+    /* Echo the friendly name so we know which device we are working with */
+    friendlyname = LIBMTP_Get_Friendlyname(iter);
+    if (friendlyname == NULL) {
+      printf("Friendly name: (NULL)\n");
+    } else {
+      printf("Friendly name: %s\n", friendlyname);
+      free(friendlyname);
+    }
+  
+	  // Get track listing.
+	  tracks = LIBMTP_Get_Tracklisting_With_Callback(iter, NULL, NULL);
+	  if (tracks == NULL) {
+	    printf("No tracks.\n");
+	  } else {
+	    LIBMTP_track_t *track, *tmp;
+	    track = tracks;
+	    while (track != NULL) {
+	      dump_trackinfo(track);
+	      tmp = track;
+	      track = track->next;
+	      LIBMTP_destroy_track_t(tmp);
+	    }
+	  }
+  }
+    
+  LIBMTP_Release_Device_List(device_list);
+  printf("OK.\n");
+  exit (0);
+}
+
diff --git a/examples/trexist.c b/examples/trexist.c
new file mode 100644
index 0000000..d6159d7
--- /dev/null
+++ b/examples/trexist.c
@@ -0,0 +1,68 @@
+/** 
+ * \file trexist.c
+ * Example program to check if a certain track exists on the device.
+ *
+ * Copyright (C) 2006 The libmtp development team. 
+ *
+ * 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 "common.h"
+#include <stdlib.h>
+#include <limits.h>
+
+static void usage (void)
+{
+  fprintf(stderr, "trexist <trackid>\n");
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device;
+  uint32_t id;
+  char *endptr;
+  
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  // We need track ID 
+  if ( argc != 2 ) {
+    usage();
+    return 1;
+  }
+
+  // Sanity check song ID
+  id = strtoul(argv[1], &endptr, 10);
+  if ( *endptr != 0 ) {
+    fprintf(stderr, "illegal value %s\n", argv[1]);
+    return 1;
+  } else if ( ! id ) {
+    fprintf(stderr, "bad song id %u\n", id);
+    return 1;
+  }
+  
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices. Connect/replug device and try again.\n");
+    exit (0);
+  }
+  
+  printf("%s\n", LIBMTP_Track_Exists(device, id) ? "Yes" : "No");
+  
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  exit (0);
+}
+
diff --git a/examples/util.c b/examples/util.c
new file mode 100644
index 0000000..f71f722
--- /dev/null
+++ b/examples/util.c
@@ -0,0 +1,63 @@
+/** 
+ * \file util.c
+ * A set of common utility functions found
+ * in all samples.
+ *
+ * Copyright (C) 2008 Linus Walleij <triad@df.lth.se>
+ *
+ * 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 "util.h"
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+void checklang(void)
+{
+  char *langsuff = NULL;
+  char *lang = getenv("LANG");
+
+#ifdef HAVE_LOCALE_H
+  // Set the locale in accordance with environment
+  setlocale(LC_ALL, "");
+#endif
+#ifdef HAVE_LANGINFO_H
+  langsuff = nl_langinfo(CODESET);
+#else
+  /*
+   * Check environment variables $LANG and $LC_CTYPE
+   * to see if we want to support UTF-8 unicode
+   */
+  if (lang != NULL) {
+    if (strlen(lang) > 5) {
+      langsuff = &lang[strlen(lang)-5];
+    }
+  }
+#endif
+  if (langsuff == NULL) {
+    printf("Could not determine language suffix for your system. Please check your setup!\n");
+  } else if (strcmp(langsuff, "UTF-8")) {
+    printf("Your system does not appear to have UTF-8 enabled ($LANG=\"%s\")\n", lang);
+    printf("If you want to have support for diacritics and Unicode characters,\n");
+    printf("please switch your locale to an UTF-8 locale, e.g. \"en_US.UTF-8\".\n");
+  }
+}
diff --git a/examples/util.h b/examples/util.h
new file mode 100644
index 0000000..ca7b658
--- /dev/null
+++ b/examples/util.h
@@ -0,0 +1,26 @@
+/** 
+ * \file util.h
+ * Header for a set of common utility functions found
+ * in all samples.
+ *
+ * Copyright (C) 2008 Linus Walleij <triad@df.lth.se>
+ *
+ * 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.
+ */
+#ifndef LIBMTP_EXAMPLES_UTIL_H
+#define LIBMTP_EXAMPLES_UTIL_H
+void checklang(void);
+#endif
diff --git a/hotplug.sh.in b/hotplug.sh.in
new file mode 100755
index 0000000..6a27552
--- /dev/null
+++ b/hotplug.sh.in
@@ -0,0 +1,185 @@
+#!/bin/bash
+
+INSTALL="@INSTALL@"
+HOTPLUGPATH=/etc/hotplug
+SCRIPTNAME=libmtp.sh
+USERMAP=libmtp.usermap
+UDEVPATH=/etc/udev/rules.d
+UDEVRULES=libmtp.rules
+HALBASEPATH=/usr/share/hal/fdi/information
+HALPATH=/usr/share/hal/fdi/information/20thirdparty
+HALRULES=libmtp.fdi
+
+# See if the parameter script ($2), device ($3) and productid ($4)
+# are already defined in the usermap ($1)
+function inmap {
+    while read LINE; do
+	if [ "x${LINE}" != "x" ]; then
+	    firstword=`echo ${LINE} | awk '{ print $1 }'`
+	    if [ ${firstword} != "#" ]; then
+	        # This is a device line entry
+		script=${firstword}
+		manid=`echo ${LINE} | awk '{ print $3 }'`
+		productid=`echo ${LINE} | awk '{ print $4 }'`
+		# Skip blank products...
+		if [ "x${script}" = "x$2" ]; then 
+		    if [ "x${manid}" = "x$3" ]; then 
+			if [ "x${productid}" = "x$4" ]; then
+			    echo "yes"
+			    return 0
+			fi
+		    fi
+		fi
+	    fi
+	fi
+    done < $1
+    echo "no"
+    return 0
+}
+
+# Scan the usermap $2 for all devices in $1 to see if they are already
+# there, else patch the usermap.
+function patchusermap {
+    # Nullify comment
+    comment=""
+    while read LINE; do
+	if [ "x$LINE" != "x" ]; then
+	    firstword=`echo ${LINE} | awk '{ print $1 }'`
+	    if [ ${firstword} = "#" ]; then
+	    # This is a comment line, save it.
+		comment=${LINE}
+	    else
+	        # This is a device line entry
+		script=${firstword}
+		manid=`echo ${LINE} | awk '{ print $3 }'`
+		productid=`echo ${LINE} | awk '{ print $4 }'`
+		# Skip blank products...
+		if [ "x${manid}" != "x" ]; then
+	            # See if this product is already in the usermap
+		    echo "Checking for product ${productid} in $2..."
+		    if [ `inmap $2 ${script} ${manid} ${productid}` = "no" ]; then
+			echo "Not present, adding to hotplug map."
+			echo ${comment} >> $2
+			echo ${LINE} >> $2
+			comment=""
+		    else
+			echo "Already installed."
+		    fi
+		fi
+	    fi
+	fi
+    done < $1
+}
+
+# Check for udev first
+if test -d ${UDEVPATH} ; then
+    echo "You seem to have udev on your system. Installing udev rules..."
+    ${INSTALL} ${UDEVRULES} ${UDEVPATH}
+    echo "You may need additional setup to get correct permissions on your device."
+    echo "See the INSTALL file for information."
+    echo "Do you also want to install HAL support or the old hotplug support (y/n)?"
+    read IN
+    if [ "$IN" = "y" ] || [ "$IN" = "Y" ]; then
+	echo "Continuing..."
+    else
+	exit 0
+    fi
+fi
+
+# Check for HAL next
+if test -d ${HALBASEPATH} ; then
+    echo "You seem to have HAL on your system. Installing HAL rules..."
+    mkdir -p ${HALPATH}
+    ${INSTALL} ${HALRULES} ${HALPATH}
+    echo "Do you also want to install the old hotplug support (y/n)?"
+    read IN
+    if [ "$IN" = "y" ] || [ "$IN" = "Y" ]; then
+	echo "Continuing..."
+    else
+	exit 0
+    fi
+fi
+
+
+# Check prerequisites
+COMMAND=`which grep 2> /dev/null`
+if [ "x${COMMAND}" = "x" ];
+then
+    echo "Missing grep program. Fatal error."
+    exit 1
+fi
+COMMAND=`which awk 2> /dev/null`
+if [ "x${COMMAND}" = "x" ];
+then
+    echo "Missing awk program. Fatal error."
+    exit 1
+fi
+if [ "x${USER}" != "xroot" ];
+    echo "WARNING: this program should be run as root!"
+fi
+
+
+# This script locates the hotplug distribution on a certain host
+# and sets up userland hotplugging scripts according to rules. 
+# The in-parameters are the hotplug directory and the name of a
+# file of hotplug device entries and a script to be executed for 
+# these deviced.
+
+if test -d ${HOTPLUGPATH}
+then
+    echo "Hotplug in ${HOTPLUGPATH}"
+else
+    echo "Hotplug missing on this system. Cannot install."
+    exit 1
+fi
+
+if test -d ${HOTPLUGPATH}/usb 
+then
+    echo "Has usb subdirectory."
+else
+    mkdir ${HOTPLUGPATH}/usb
+fi
+
+echo "Installing script."
+${INSTALL} libmtp.sh ${HOTPLUGPATH}/usb
+echo "Installing usermap."
+${INSTALL} -m 644 ${USERMAP} ${HOTPLUGPATH}/usb
+# If we find a usb.usermap file, and we see that this distribution
+# of hotplug does not support private usermaps, then we need to
+# patch the usb.usermap file.
+#
+# Create a merged file, diff the files to each other, and if there
+# were mismatches, then patch the installed file.
+echo "Checking hotplugging CVS version..."
+echo "/etc/hotplug/usb/*.usermap support was added in august 2002"
+EDITMAP="yes"
+CVSTAG=`grep '\$Id:' /etc/hotplug/usb.agent`
+if [ "x${CVSTAG}" != "x" ]; then
+    DATE=`echo ${CVSTAG} | awk '{ print $5 }'`
+    echo "Hotplug version seems to be from ${DATE}"
+    YEAR=`echo ${DATE} | awk 'BEGIN { FS="/"} {print $1; }'`
+    MONTH=`echo ${DATE} | awk 'BEGIN { FS="/"} {print $2; }'`
+    DAY=`echo ${DATE} | awk 'BEGIN { FS="/"} {print $3; }'`
+    if [ "${YEAR}" -gt "2002" ]; then
+	EDITMAP="no"
+    else
+	if [ "${YEAR}" -eq "2002" ]; then
+	    if [ "${MONTH}" -ge "08" ]; then
+		EDITMAP="no"
+	    fi
+	fi
+    fi
+fi
+if [ "x${EDITMAP}" == "xyes" ]; then
+    echo "We need to edit the ${HOTPLUGPATH}/usb.usermap if it exists..."
+    if test -f ${HOTPLUGPATH}/usb.usermap
+    then
+	echo "We have a usb.usermap..."
+	patchusermap ${USERMAP} /etc/hotplug/usb.usermap
+    fi
+fi
+
+echo "Hotplugging successfully installed."
+
+exit 0
+
diff --git a/install-sh b/install-sh
new file mode 100755
index 0000000..6781b98
--- /dev/null
+++ b/install-sh
@@ -0,0 +1,520 @@
+#!/bin/sh
+# install - install a program, script, or datafile
+
+scriptversion=2009-04-28.21; # UTC
+
+# This originates from X11R5 (mit/util/scripts/install.sh), which was
+# later released in X11R6 (xc/config/util/install.sh) with the
+# following copyright and license.
+#
+# Copyright (C) 1994 X Consortium
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
+# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# Except as contained in this notice, the name of the X Consortium shall not
+# be used in advertising or otherwise to promote the sale, use or other deal-
+# ings in this Software without prior written authorization from the X Consor-
+# tium.
+#
+#
+# FSF changes to this file are in the public domain.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+
+nl='
+'
+IFS=" ""	$nl"
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit=${DOITPROG-}
+if test -z "$doit"; then
+  doit_exec=exec
+else
+  doit_exec=$doit
+fi
+
+# Put in absolute file names if you don't have them in your path;
+# or use environment vars.
+
+chgrpprog=${CHGRPPROG-chgrp}
+chmodprog=${CHMODPROG-chmod}
+chownprog=${CHOWNPROG-chown}
+cmpprog=${CMPPROG-cmp}
+cpprog=${CPPROG-cp}
+mkdirprog=${MKDIRPROG-mkdir}
+mvprog=${MVPROG-mv}
+rmprog=${RMPROG-rm}
+stripprog=${STRIPPROG-strip}
+
+posix_glob='?'
+initialize_posix_glob='
+  test "$posix_glob" != "?" || {
+    if (set -f) 2>/dev/null; then
+      posix_glob=
+    else
+      posix_glob=:
+    fi
+  }
+'
+
+posix_mkdir=
+
+# Desired mode of installed file.
+mode=0755
+
+chgrpcmd=
+chmodcmd=$chmodprog
+chowncmd=
+mvcmd=$mvprog
+rmcmd="$rmprog -f"
+stripcmd=
+
+src=
+dst=
+dir_arg=
+dst_arg=
+
+copy_on_change=false
+no_target_directory=
+
+usage="\
+Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
+   or: $0 [OPTION]... SRCFILES... DIRECTORY
+   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
+   or: $0 [OPTION]... -d DIRECTORIES...
+
+In the 1st form, copy SRCFILE to DSTFILE.
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
+In the 4th, create DIRECTORIES.
+
+Options:
+     --help     display this help and exit.
+     --version  display version info and exit.
+
+  -c            (ignored)
+  -C            install only if different (preserve the last data modification time)
+  -d            create directories instead of installing files.
+  -g GROUP      $chgrpprog installed files to GROUP.
+  -m MODE       $chmodprog installed files to MODE.
+  -o USER       $chownprog installed files to USER.
+  -s            $stripprog installed files.
+  -t DIRECTORY  install into DIRECTORY.
+  -T            report an error if DSTFILE is a directory.
+
+Environment variables override the default commands:
+  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
+  RMPROG STRIPPROG
+"
+
+while test $# -ne 0; do
+  case $1 in
+    -c) ;;
+
+    -C) copy_on_change=true;;
+
+    -d) dir_arg=true;;
+
+    -g) chgrpcmd="$chgrpprog $2"
+	shift;;
+
+    --help) echo "$usage"; exit $?;;
+
+    -m) mode=$2
+	case $mode in
+	  *' '* | *'	'* | *'
+'*	  | *'*'* | *'?'* | *'['*)
+	    echo "$0: invalid mode: $mode" >&2
+	    exit 1;;
+	esac
+	shift;;
+
+    -o) chowncmd="$chownprog $2"
+	shift;;
+
+    -s) stripcmd=$stripprog;;
+
+    -t) dst_arg=$2
+	shift;;
+
+    -T) no_target_directory=true;;
+
+    --version) echo "$0 $scriptversion"; exit $?;;
+
+    --)	shift
+	break;;
+
+    -*)	echo "$0: invalid option: $1" >&2
+	exit 1;;
+
+    *)  break;;
+  esac
+  shift
+done
+
+if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
+  # When -d is used, all remaining arguments are directories to create.
+  # When -t is used, the destination is already specified.
+  # Otherwise, the last argument is the destination.  Remove it from $@.
+  for arg
+  do
+    if test -n "$dst_arg"; then
+      # $@ is not empty: it contains at least $arg.
+      set fnord "$@" "$dst_arg"
+      shift # fnord
+    fi
+    shift # arg
+    dst_arg=$arg
+  done
+fi
+
+if test $# -eq 0; then
+  if test -z "$dir_arg"; then
+    echo "$0: no input file specified." >&2
+    exit 1
+  fi
+  # It's OK to call `install-sh -d' without argument.
+  # This can happen when creating conditional directories.
+  exit 0
+fi
+
+if test -z "$dir_arg"; then
+  trap '(exit $?); exit' 1 2 13 15
+
+  # Set umask so as not to create temps with too-generous modes.
+  # However, 'strip' requires both read and write access to temps.
+  case $mode in
+    # Optimize common cases.
+    *644) cp_umask=133;;
+    *755) cp_umask=22;;
+
+    *[0-7])
+      if test -z "$stripcmd"; then
+	u_plus_rw=
+      else
+	u_plus_rw='% 200'
+      fi
+      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
+    *)
+      if test -z "$stripcmd"; then
+	u_plus_rw=
+      else
+	u_plus_rw=,u+rw
+      fi
+      cp_umask=$mode$u_plus_rw;;
+  esac
+fi
+
+for src
+do
+  # Protect names starting with `-'.
+  case $src in
+    -*) src=./$src;;
+  esac
+
+  if test -n "$dir_arg"; then
+    dst=$src
+    dstdir=$dst
+    test -d "$dstdir"
+    dstdir_status=$?
+  else
+
+    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
+    # might cause directories to be created, which would be especially bad
+    # if $src (and thus $dsttmp) contains '*'.
+    if test ! -f "$src" && test ! -d "$src"; then
+      echo "$0: $src does not exist." >&2
+      exit 1
+    fi
+
+    if test -z "$dst_arg"; then
+      echo "$0: no destination specified." >&2
+      exit 1
+    fi
+
+    dst=$dst_arg
+    # Protect names starting with `-'.
+    case $dst in
+      -*) dst=./$dst;;
+    esac
+
+    # If destination is a directory, append the input filename; won't work
+    # if double slashes aren't ignored.
+    if test -d "$dst"; then
+      if test -n "$no_target_directory"; then
+	echo "$0: $dst_arg: Is a directory" >&2
+	exit 1
+      fi
+      dstdir=$dst
+      dst=$dstdir/`basename "$src"`
+      dstdir_status=0
+    else
+      # Prefer dirname, but fall back on a substitute if dirname fails.
+      dstdir=`
+	(dirname "$dst") 2>/dev/null ||
+	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	     X"$dst" : 'X\(//\)[^/]' \| \
+	     X"$dst" : 'X\(//\)$' \| \
+	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
+	echo X"$dst" |
+	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\/\)[^/].*/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\/\)$/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\).*/{
+		   s//\1/
+		   q
+		 }
+		 s/.*/./; q'
+      `
+
+      test -d "$dstdir"
+      dstdir_status=$?
+    fi
+  fi
+
+  obsolete_mkdir_used=false
+
+  if test $dstdir_status != 0; then
+    case $posix_mkdir in
+      '')
+	# Create intermediate dirs using mode 755 as modified by the umask.
+	# This is like FreeBSD 'install' as of 1997-10-28.
+	umask=`umask`
+	case $stripcmd.$umask in
+	  # Optimize common cases.
+	  *[2367][2367]) mkdir_umask=$umask;;
+	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
+
+	  *[0-7])
+	    mkdir_umask=`expr $umask + 22 \
+	      - $umask % 100 % 40 + $umask % 20 \
+	      - $umask % 10 % 4 + $umask % 2
+	    `;;
+	  *) mkdir_umask=$umask,go-w;;
+	esac
+
+	# With -d, create the new directory with the user-specified mode.
+	# Otherwise, rely on $mkdir_umask.
+	if test -n "$dir_arg"; then
+	  mkdir_mode=-m$mode
+	else
+	  mkdir_mode=
+	fi
+
+	posix_mkdir=false
+	case $umask in
+	  *[123567][0-7][0-7])
+	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
+	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
+	    ;;
+	  *)
+	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
+	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
+
+	    if (umask $mkdir_umask &&
+		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
+	    then
+	      if test -z "$dir_arg" || {
+		   # Check for POSIX incompatibilities with -m.
+		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
+		   # other-writeable bit of parent directory when it shouldn't.
+		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
+		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
+		   case $ls_ld_tmpdir in
+		     d????-?r-*) different_mode=700;;
+		     d????-?--*) different_mode=755;;
+		     *) false;;
+		   esac &&
+		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
+		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
+		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
+		   }
+		 }
+	      then posix_mkdir=:
+	      fi
+	      rmdir "$tmpdir/d" "$tmpdir"
+	    else
+	      # Remove any dirs left behind by ancient mkdir implementations.
+	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
+	    fi
+	    trap '' 0;;
+	esac;;
+    esac
+
+    if
+      $posix_mkdir && (
+	umask $mkdir_umask &&
+	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
+      )
+    then :
+    else
+
+      # The umask is ridiculous, or mkdir does not conform to POSIX,
+      # or it failed possibly due to a race condition.  Create the
+      # directory the slow way, step by step, checking for races as we go.
+
+      case $dstdir in
+	/*) prefix='/';;
+	-*) prefix='./';;
+	*)  prefix='';;
+      esac
+
+      eval "$initialize_posix_glob"
+
+      oIFS=$IFS
+      IFS=/
+      $posix_glob set -f
+      set fnord $dstdir
+      shift
+      $posix_glob set +f
+      IFS=$oIFS
+
+      prefixes=
+
+      for d
+      do
+	test -z "$d" && continue
+
+	prefix=$prefix$d
+	if test -d "$prefix"; then
+	  prefixes=
+	else
+	  if $posix_mkdir; then
+	    (umask=$mkdir_umask &&
+	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
+	    # Don't fail if two instances are running concurrently.
+	    test -d "$prefix" || exit 1
+	  else
+	    case $prefix in
+	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
+	      *) qprefix=$prefix;;
+	    esac
+	    prefixes="$prefixes '$qprefix'"
+	  fi
+	fi
+	prefix=$prefix/
+      done
+
+      if test -n "$prefixes"; then
+	# Don't fail if two instances are running concurrently.
+	(umask $mkdir_umask &&
+	 eval "\$doit_exec \$mkdirprog $prefixes") ||
+	  test -d "$dstdir" || exit 1
+	obsolete_mkdir_used=true
+      fi
+    fi
+  fi
+
+  if test -n "$dir_arg"; then
+    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
+    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
+      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
+  else
+
+    # Make a couple of temp file names in the proper directory.
+    dsttmp=$dstdir/_inst.$$_
+    rmtmp=$dstdir/_rm.$$_
+
+    # Trap to clean up those temp files at exit.
+    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
+
+    # Copy the file name to the temp name.
+    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
+
+    # and set any options; do chmod last to preserve setuid bits.
+    #
+    # If any of these fail, we abort the whole thing.  If we want to
+    # ignore errors from any of these, just make sure not to ignore
+    # errors from the above "$doit $cpprog $src $dsttmp" command.
+    #
+    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
+    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
+    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
+
+    # If -C, don't bother to copy if it wouldn't change the file.
+    if $copy_on_change &&
+       old=`LC_ALL=C ls -dlL "$dst"	2>/dev/null` &&
+       new=`LC_ALL=C ls -dlL "$dsttmp"	2>/dev/null` &&
+
+       eval "$initialize_posix_glob" &&
+       $posix_glob set -f &&
+       set X $old && old=:$2:$4:$5:$6 &&
+       set X $new && new=:$2:$4:$5:$6 &&
+       $posix_glob set +f &&
+
+       test "$old" = "$new" &&
+       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
+    then
+      rm -f "$dsttmp"
+    else
+      # Rename the file to the real destination.
+      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
+
+      # The rename failed, perhaps because mv can't rename something else
+      # to itself, or perhaps because mv is so ancient that it does not
+      # support -f.
+      {
+	# Now remove or move aside any old file at destination location.
+	# We try this two ways since rm can't unlink itself on some
+	# systems and the destination file might be busy for other
+	# reasons.  In this case, the final cleanup might fail but the new
+	# file should still install successfully.
+	{
+	  test ! -f "$dst" ||
+	  $doit $rmcmd -f "$dst" 2>/dev/null ||
+	  { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
+	    { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
+	  } ||
+	  { echo "$0: cannot unlink or rename $dst" >&2
+	    (exit 1); exit 1
+	  }
+	} &&
+
+	# Now rename the file to the real destination.
+	$doit $mvcmd "$dsttmp" "$dst"
+      }
+    fi || exit 1
+
+    trap '' 0
+  fi
+done
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/libmtp.pc b/libmtp.pc
new file mode 100644
index 0000000..9a2a6ba
--- /dev/null
+++ b/libmtp.pc
@@ -0,0 +1,15 @@
+# libmtp pkg-config source file
+
+prefix=/usr/local
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: libmtp
+Description: libmtp is a library for accessing Media Transfer Protocol devices
+Version: 1.0.1
+Requires: libusb
+Conflicts:
+Libs: -L${libdir} -lmtp
+Libs.private -lusb 
+Cflags: -I${includedir} 
diff --git a/libmtp.pc.in b/libmtp.pc.in
new file mode 100644
index 0000000..cb7ad87
--- /dev/null
+++ b/libmtp.pc.in
@@ -0,0 +1,15 @@
+# libmtp pkg-config source file
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libmtp
+Description: libmtp is a library for accessing Media Transfer Protocol devices
+Version: @VERSION@
+Requires: libusb
+Conflicts:
+Libs: -L${libdir} -lmtp
+Libs.private @LIBS@
+Cflags: -I${includedir} @OSFLAGS@
diff --git a/libmtp.sh b/libmtp.sh
new file mode 100644
index 0000000..b149413
--- /dev/null
+++ b/libmtp.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+# Lifts a plugged in MTP device to user space and
+# optionally runs a client program.
+# Written by Linus Walleij 2006, based on the "usbcam"
+# script by Nalin Dahyabhai.
+DEVICEOWNER=root
+DEVICEPERMS=666
+
+# Special quirk for SuSE systems using "resmgr"
+# (see http://rechner.lst.de/~okir/resmgr/)
+if [ -f /sbin/resmgr ]
+then
+    /sbin/resmgr "${ACTION}" "${DEVICE}" desktop usb
+    exit 0
+fi
+
+# This is for most other distributions
+if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
+then
+    # New code, using lock files instead of copying /dev/console permissions
+    # This also works with non-gdm logins (e.g. on a virtual terminal)
+    # Idea and code from Nalin Dahyabhai <nalin@redhat.com>
+    if [ "x$DEVICEOWNER" = "xCONSOLE" ]
+    then
+	if [ -f /var/run/console/console.lock ]
+	then
+	    DEVICEOWNER=`cat /var/run/console/console.lock`
+	elif [ -f /var/run/console.lock ]
+	then
+	    DEVICEOWNER=`cat /var/run/console.lock`
+	elif [ -f /var/lock/console.lock ]
+	then
+	    DEVICEOWNER=`cat /var/lock/console.lock`
+	else
+	    DEVICEOWNER="nobody"
+	    DEVICEPERMS="666"
+	fi
+    fi
+    if [ -n "$DEVICEOWNER" ]
+    then
+        chmod 0000 "${DEVICE}"
+        chown "${DEVICEOWNER}" "${DEVICE}"
+        chmod "${DEVICEPERMS}" "${DEVICE}"
+    fi
+fi
diff --git a/libmtp.sh.in b/libmtp.sh.in
new file mode 100644
index 0000000..b149413
--- /dev/null
+++ b/libmtp.sh.in
@@ -0,0 +1,45 @@
+#!/bin/sh
+# Lifts a plugged in MTP device to user space and
+# optionally runs a client program.
+# Written by Linus Walleij 2006, based on the "usbcam"
+# script by Nalin Dahyabhai.
+DEVICEOWNER=root
+DEVICEPERMS=666
+
+# Special quirk for SuSE systems using "resmgr"
+# (see http://rechner.lst.de/~okir/resmgr/)
+if [ -f /sbin/resmgr ]
+then
+    /sbin/resmgr "${ACTION}" "${DEVICE}" desktop usb
+    exit 0
+fi
+
+# This is for most other distributions
+if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
+then
+    # New code, using lock files instead of copying /dev/console permissions
+    # This also works with non-gdm logins (e.g. on a virtual terminal)
+    # Idea and code from Nalin Dahyabhai <nalin@redhat.com>
+    if [ "x$DEVICEOWNER" = "xCONSOLE" ]
+    then
+	if [ -f /var/run/console/console.lock ]
+	then
+	    DEVICEOWNER=`cat /var/run/console/console.lock`
+	elif [ -f /var/run/console.lock ]
+	then
+	    DEVICEOWNER=`cat /var/run/console.lock`
+	elif [ -f /var/lock/console.lock ]
+	then
+	    DEVICEOWNER=`cat /var/lock/console.lock`
+	else
+	    DEVICEOWNER="nobody"
+	    DEVICEPERMS="666"
+	fi
+    fi
+    if [ -n "$DEVICEOWNER" ]
+    then
+        chmod 0000 "${DEVICE}"
+        chown "${DEVICEOWNER}" "${DEVICE}"
+        chmod "${DEVICEPERMS}" "${DEVICE}"
+    fi
+fi
diff --git a/libmtp.xcodeproj/project.pbxproj b/libmtp.xcodeproj/project.pbxproj
new file mode 100644
index 0000000..f652d53
--- /dev/null
+++ b/libmtp.xcodeproj/project.pbxproj
@@ -0,0 +1,377 @@
+// !$*UTF8*$!
+{
+	archiveVersion = 1;
+	classes = {
+	};
+	objectVersion = 45;
+	objects = {
+
+/* Begin PBXBuildFile section */
+		B00305CF1277B07D009FA3E1 /* device-flags.h in Headers */ = {isa = PBXBuildFile; fileRef = B00305BF1277B07D009FA3E1 /* device-flags.h */; };
+		B00305D01277B07D009FA3E1 /* gphoto2-endian.h in Headers */ = {isa = PBXBuildFile; fileRef = B00305C01277B07D009FA3E1 /* gphoto2-endian.h */; };
+		B00305D11277B07D009FA3E1 /* libmtp.c in Sources */ = {isa = PBXBuildFile; fileRef = B00305C11277B07D009FA3E1 /* libmtp.c */; };
+		B00305D21277B07D009FA3E1 /* libmtp.h in Headers */ = {isa = PBXBuildFile; fileRef = B00305C21277B07D009FA3E1 /* libmtp.h */; };
+		B00305D31277B07D009FA3E1 /* libptp-stdint.h in Headers */ = {isa = PBXBuildFile; fileRef = B00305C31277B07D009FA3E1 /* libptp-stdint.h */; };
+		B00305D41277B07D009FA3E1 /* libusb-glue.c in Sources */ = {isa = PBXBuildFile; fileRef = B00305C41277B07D009FA3E1 /* libusb-glue.c */; };
+		B00305D51277B07D009FA3E1 /* libusb-glue.h in Headers */ = {isa = PBXBuildFile; fileRef = B00305C51277B07D009FA3E1 /* libusb-glue.h */; };
+		B00305D61277B07D009FA3E1 /* music-players.h in Headers */ = {isa = PBXBuildFile; fileRef = B00305C61277B07D009FA3E1 /* music-players.h */; };
+		B00305D71277B07D009FA3E1 /* playlist-spl.c in Sources */ = {isa = PBXBuildFile; fileRef = B00305C71277B07D009FA3E1 /* playlist-spl.c */; };
+		B00305D81277B07D009FA3E1 /* playlist-spl.h in Headers */ = {isa = PBXBuildFile; fileRef = B00305C81277B07D009FA3E1 /* playlist-spl.h */; };
+		B00305D91277B07D009FA3E1 /* ptp.c in Sources */ = {isa = PBXBuildFile; fileRef = B00305C91277B07D009FA3E1 /* ptp.c */; };
+		B00305DA1277B07D009FA3E1 /* ptp.h in Headers */ = {isa = PBXBuildFile; fileRef = B00305CA1277B07D009FA3E1 /* ptp.h */; };
+		B00305DB1277B07D009FA3E1 /* unicode.c in Sources */ = {isa = PBXBuildFile; fileRef = B00305CB1277B07D009FA3E1 /* unicode.c */; };
+		B00305DC1277B07D009FA3E1 /* unicode.h in Headers */ = {isa = PBXBuildFile; fileRef = B00305CC1277B07D009FA3E1 /* unicode.h */; };
+		B00305DD1277B07D009FA3E1 /* util.c in Sources */ = {isa = PBXBuildFile; fileRef = B00305CD1277B07D009FA3E1 /* util.c */; };
+		B00305DE1277B07D009FA3E1 /* util.h in Headers */ = {isa = PBXBuildFile; fileRef = B00305CE1277B07D009FA3E1 /* util.h */; };
+		B00305FF1277B39A009FA3E1 /* libusb-compat.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B00304DA1277AFB4009FA3E1 /* libusb-compat.dylib */; };
+		B00306001277B39D009FA3E1 /* libusb.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B00304D01277AFA9009FA3E1 /* libusb.dylib */; };
+		B00306061277B3CD009FA3E1 /* libiconv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B00306051277B3CD009FA3E1 /* libiconv.dylib */; };
+		D7D0FF8B1124E29800E01FE7 /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = D7D0FF621124E29800E01FE7 /* config.h */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXContainerItemProxy section */
+		B00304CF1277AFA9009FA3E1 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = B00304C81277AFA9009FA3E1 /* libusb.xcodeproj */;
+			proxyType = 2;
+			remoteGlobalIDString = D2AAC0630554660B00DB518D;
+			remoteInfo = libusb;
+		};
+		B00304D91277AFB4009FA3E1 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = B00304D11277AFB4009FA3E1 /* libusb-compat.xcodeproj */;
+			proxyType = 2;
+			remoteGlobalIDString = D2AAC0630554660B00DB518D;
+			remoteInfo = "libusb-compat";
+		};
+		B00305B31277AFC6009FA3E1 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = B00304C81277AFA9009FA3E1 /* libusb.xcodeproj */;
+			proxyType = 1;
+			remoteGlobalIDString = D2AAC0620554660B00DB518D;
+			remoteInfo = libusb;
+		};
+		B00305B51277AFC6009FA3E1 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = B00304D11277AFB4009FA3E1 /* libusb-compat.xcodeproj */;
+			proxyType = 1;
+			remoteGlobalIDString = D2AAC0620554660B00DB518D;
+			remoteInfo = "libusb-compat";
+		};
+/* End PBXContainerItemProxy section */
+
+/* Begin PBXFileReference section */
+		B00304C81277AFA9009FA3E1 /* libusb.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = libusb.xcodeproj; path = "../libusb-1.0.8/libusb.xcodeproj"; sourceTree = SOURCE_ROOT; };
+		B00304D11277AFB4009FA3E1 /* libusb-compat.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "libusb-compat.xcodeproj"; path = "../libusb-compat-0.1.3/libusb-compat.xcodeproj"; sourceTree = SOURCE_ROOT; };
+		B00305BF1277B07D009FA3E1 /* device-flags.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "device-flags.h"; path = "src/device-flags.h"; sourceTree = SOURCE_ROOT; };
+		B00305C01277B07D009FA3E1 /* gphoto2-endian.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gphoto2-endian.h"; path = "src/gphoto2-endian.h"; sourceTree = SOURCE_ROOT; };
+		B00305C11277B07D009FA3E1 /* libmtp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = libmtp.c; path = src/libmtp.c; sourceTree = SOURCE_ROOT; };
+		B00305C21277B07D009FA3E1 /* libmtp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = libmtp.h; path = src/libmtp.h; sourceTree = SOURCE_ROOT; };
+		B00305C31277B07D009FA3E1 /* libptp-stdint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "libptp-stdint.h"; path = "src/libptp-stdint.h"; sourceTree = SOURCE_ROOT; };
+		B00305C41277B07D009FA3E1 /* libusb-glue.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "libusb-glue.c"; path = "src/libusb-glue.c"; sourceTree = SOURCE_ROOT; };
+		B00305C51277B07D009FA3E1 /* libusb-glue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "libusb-glue.h"; path = "src/libusb-glue.h"; sourceTree = SOURCE_ROOT; };
+		B00305C61277B07D009FA3E1 /* music-players.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "music-players.h"; path = "src/music-players.h"; sourceTree = SOURCE_ROOT; };
+		B00305C71277B07D009FA3E1 /* playlist-spl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "playlist-spl.c"; path = "src/playlist-spl.c"; sourceTree = SOURCE_ROOT; };
+		B00305C81277B07D009FA3E1 /* playlist-spl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "playlist-spl.h"; path = "src/playlist-spl.h"; sourceTree = SOURCE_ROOT; };
+		B00305C91277B07D009FA3E1 /* ptp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ptp.c; path = src/ptp.c; sourceTree = SOURCE_ROOT; };
+		B00305CA1277B07D009FA3E1 /* ptp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ptp.h; path = src/ptp.h; sourceTree = SOURCE_ROOT; };
+		B00305CB1277B07D009FA3E1 /* unicode.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = unicode.c; path = src/unicode.c; sourceTree = SOURCE_ROOT; };
+		B00305CC1277B07D009FA3E1 /* unicode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = unicode.h; path = src/unicode.h; sourceTree = SOURCE_ROOT; };
+		B00305CD1277B07D009FA3E1 /* util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = util.c; path = src/util.c; sourceTree = SOURCE_ROOT; };
+		B00305CE1277B07D009FA3E1 /* util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = util.h; path = src/util.h; sourceTree = SOURCE_ROOT; };
+		B00306051277B3CD009FA3E1 /* libiconv.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libiconv.dylib; path = usr/lib/libiconv.dylib; sourceTree = SDKROOT; };
+		D2AAC0630554660B00DB518D /* libmtp.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libmtp.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
+		D71350461124D56600E2C1DA /* MacConfigExternalDebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = MacConfigExternalDebug.xcconfig; path = ../MacConfigExternalDebug.xcconfig; sourceTree = SOURCE_ROOT; };
+		D71350471124D56600E2C1DA /* MacConfigExternalRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = MacConfigExternalRelease.xcconfig; path = ../MacConfigExternalRelease.xcconfig; sourceTree = SOURCE_ROOT; };
+		D7D0FF621124E29800E01FE7 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+		D289988505E68E00004EDB86 /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				B00305FF1277B39A009FA3E1 /* libusb-compat.dylib in Frameworks */,
+				B00306001277B39D009FA3E1 /* libusb.dylib in Frameworks */,
+				B00306061277B3CD009FA3E1 /* libiconv.dylib in Frameworks */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+		08FB7794FE84155DC02AAC07 /* libmtp */ = {
+			isa = PBXGroup;
+			children = (
+				D71350461124D56600E2C1DA /* MacConfigExternalDebug.xcconfig */,
+				D71350471124D56600E2C1DA /* MacConfigExternalRelease.xcconfig */,
+				B00304D11277AFB4009FA3E1 /* libusb-compat.xcodeproj */,
+				B00304C81277AFA9009FA3E1 /* libusb.xcodeproj */,
+				08FB7795FE84155DC02AAC07 /* Source */,
+				1AB674ADFE9D54B511CA2CBB /* Products */,
+				B00306051277B3CD009FA3E1 /* libiconv.dylib */,
+			);
+			name = libmtp;
+			sourceTree = "<group>";
+		};
+		08FB7795FE84155DC02AAC07 /* Source */ = {
+			isa = PBXGroup;
+			children = (
+				D7D0FF621124E29800E01FE7 /* config.h */,
+				B00305BF1277B07D009FA3E1 /* device-flags.h */,
+				B00305C01277B07D009FA3E1 /* gphoto2-endian.h */,
+				B00305C11277B07D009FA3E1 /* libmtp.c */,
+				B00305C21277B07D009FA3E1 /* libmtp.h */,
+				B00305C31277B07D009FA3E1 /* libptp-stdint.h */,
+				B00305C41277B07D009FA3E1 /* libusb-glue.c */,
+				B00305C51277B07D009FA3E1 /* libusb-glue.h */,
+				B00305C61277B07D009FA3E1 /* music-players.h */,
+				B00305C71277B07D009FA3E1 /* playlist-spl.c */,
+				B00305C81277B07D009FA3E1 /* playlist-spl.h */,
+				B00305C91277B07D009FA3E1 /* ptp.c */,
+				B00305CA1277B07D009FA3E1 /* ptp.h */,
+				B00305CB1277B07D009FA3E1 /* unicode.c */,
+				B00305CC1277B07D009FA3E1 /* unicode.h */,
+				B00305CD1277B07D009FA3E1 /* util.c */,
+				B00305CE1277B07D009FA3E1 /* util.h */,
+			);
+			name = Source;
+			sourceTree = "<group>";
+		};
+		1AB674ADFE9D54B511CA2CBB /* Products */ = {
+			isa = PBXGroup;
+			children = (
+				D2AAC0630554660B00DB518D /* libmtp.dylib */,
+			);
+			name = Products;
+			sourceTree = "<group>";
+		};
+		B00304C91277AFA9009FA3E1 /* Products */ = {
+			isa = PBXGroup;
+			children = (
+				B00304D01277AFA9009FA3E1 /* libusb.dylib */,
+			);
+			name = Products;
+			sourceTree = "<group>";
+		};
+		B00304D21277AFB4009FA3E1 /* Products */ = {
+			isa = PBXGroup;
+			children = (
+				B00304DA1277AFB4009FA3E1 /* libusb-compat.dylib */,
+			);
+			name = Products;
+			sourceTree = "<group>";
+		};
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+		D2AAC0600554660B00DB518D /* Headers */ = {
+			isa = PBXHeadersBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				D7D0FF8B1124E29800E01FE7 /* config.h in Headers */,
+				B00305CF1277B07D009FA3E1 /* device-flags.h in Headers */,
+				B00305D01277B07D009FA3E1 /* gphoto2-endian.h in Headers */,
+				B00305D21277B07D009FA3E1 /* libmtp.h in Headers */,
+				B00305D31277B07D009FA3E1 /* libptp-stdint.h in Headers */,
+				B00305D51277B07D009FA3E1 /* libusb-glue.h in Headers */,
+				B00305D61277B07D009FA3E1 /* music-players.h in Headers */,
+				B00305D81277B07D009FA3E1 /* playlist-spl.h in Headers */,
+				B00305DA1277B07D009FA3E1 /* ptp.h in Headers */,
+				B00305DC1277B07D009FA3E1 /* unicode.h in Headers */,
+				B00305DE1277B07D009FA3E1 /* util.h in Headers */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXNativeTarget section */
+		D2AAC0620554660B00DB518D /* libmtp */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 1DEB914A08733D8E0010E9CD /* Build configuration list for PBXNativeTarget "libmtp" */;
+			buildPhases = (
+				D2AAC0600554660B00DB518D /* Headers */,
+				D2AAC0610554660B00DB518D /* Sources */,
+				D289988505E68E00004EDB86 /* Frameworks */,
+				FA62191812D7CF58001B5A20 /* Generate Breakpad symbols */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+				B00305B41277AFC6009FA3E1 /* PBXTargetDependency */,
+				B00305B61277AFC6009FA3E1 /* PBXTargetDependency */,
+			);
+			name = libmtp;
+			productName = libmtp;
+			productReference = D2AAC0630554660B00DB518D /* libmtp.dylib */;
+			productType = "com.apple.product-type.library.dynamic";
+		};
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+		08FB7793FE84155DC02AAC07 /* Project object */ = {
+			isa = PBXProject;
+			buildConfigurationList = 1DEB914E08733D8E0010E9CD /* Build configuration list for PBXProject "libmtp" */;
+			compatibilityVersion = "Xcode 3.1";
+			developmentRegion = English;
+			hasScannedForEncodings = 1;
+			knownRegions = (
+				English,
+				Japanese,
+				French,
+				German,
+			);
+			mainGroup = 08FB7794FE84155DC02AAC07 /* libmtp */;
+			projectDirPath = "";
+			projectReferences = (
+				{
+					ProductGroup = B00304D21277AFB4009FA3E1 /* Products */;
+					ProjectRef = B00304D11277AFB4009FA3E1 /* libusb-compat.xcodeproj */;
+				},
+				{
+					ProductGroup = B00304C91277AFA9009FA3E1 /* Products */;
+					ProjectRef = B00304C81277AFA9009FA3E1 /* libusb.xcodeproj */;
+				},
+			);
+			projectRoot = "";
+			targets = (
+				D2AAC0620554660B00DB518D /* libmtp */,
+			);
+		};
+/* End PBXProject section */
+
+/* Begin PBXReferenceProxy section */
+		B00304D01277AFA9009FA3E1 /* libusb.dylib */ = {
+			isa = PBXReferenceProxy;
+			fileType = "compiled.mach-o.dylib";
+			path = libusb.dylib;
+			remoteRef = B00304CF1277AFA9009FA3E1 /* PBXContainerItemProxy */;
+			sourceTree = BUILT_PRODUCTS_DIR;
+		};
+		B00304DA1277AFB4009FA3E1 /* libusb-compat.dylib */ = {
+			isa = PBXReferenceProxy;
+			fileType = "compiled.mach-o.dylib";
+			path = "libusb-compat.dylib";
+			remoteRef = B00304D91277AFB4009FA3E1 /* PBXContainerItemProxy */;
+			sourceTree = BUILT_PRODUCTS_DIR;
+		};
+/* End PBXReferenceProxy section */
+
+/* Begin PBXShellScriptBuildPhase section */
+		FA62191812D7CF58001B5A20 /* Generate Breakpad symbols */ = {
+			isa = PBXShellScriptBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			inputPaths = (
+			);
+			name = "Generate Breakpad symbols";
+			outputPaths = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+			shellPath = /bin/sh;
+			shellScript = $SRCROOT/../../source/Shared/generatesymbols.sh;
+		};
+/* End PBXShellScriptBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+		D2AAC0610554660B00DB518D /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				B00305D11277B07D009FA3E1 /* libmtp.c in Sources */,
+				B00305D41277B07D009FA3E1 /* libusb-glue.c in Sources */,
+				B00305D71277B07D009FA3E1 /* playlist-spl.c in Sources */,
+				B00305D91277B07D009FA3E1 /* ptp.c in Sources */,
+				B00305DB1277B07D009FA3E1 /* unicode.c in Sources */,
+				B00305DD1277B07D009FA3E1 /* util.c in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXTargetDependency section */
+		B00305B41277AFC6009FA3E1 /* PBXTargetDependency */ = {
+			isa = PBXTargetDependency;
+			name = libusb;
+			targetProxy = B00305B31277AFC6009FA3E1 /* PBXContainerItemProxy */;
+		};
+		B00305B61277AFC6009FA3E1 /* PBXTargetDependency */ = {
+			isa = PBXTargetDependency;
+			name = "libusb-compat";
+			targetProxy = B00305B51277AFC6009FA3E1 /* PBXContainerItemProxy */;
+		};
+/* End PBXTargetDependency section */
+
+/* Begin XCBuildConfiguration section */
+		1DEB914B08733D8E0010E9CD /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				EXECUTABLE_PREFIX = lib;
+				GCC_C_LANGUAGE_STANDARD = gnu99;
+				HEADER_SEARCH_PATHS = "../libusb-compat-0.1.3/libusb";
+				OTHER_CFLAGS = (
+					"$(inherited)",
+					"-DHAVE_CONFIG_H",
+					"-DUSE_DARWIN",
+				);
+				PRODUCT_NAME = mtp;
+			};
+			name = Debug;
+		};
+		1DEB914C08733D8E0010E9CD /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				EXECUTABLE_PREFIX = lib;
+				GCC_C_LANGUAGE_STANDARD = gnu99;
+				HEADER_SEARCH_PATHS = "../libusb-compat-0.1.3/libusb";
+				OTHER_CFLAGS = (
+					"$(inherited)",
+					"-DHAVE_CONFIG_H",
+					"-DUSE_DARWIN",
+				);
+				PRODUCT_NAME = mtp;
+			};
+			name = Release;
+		};
+		1DEB914F08733D8E0010E9CD /* Debug */ = {
+			isa = XCBuildConfiguration;
+			baseConfigurationReference = D71350461124D56600E2C1DA /* MacConfigExternalDebug.xcconfig */;
+			buildSettings = {
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+			};
+			name = Debug;
+		};
+		1DEB915008733D8E0010E9CD /* Release */ = {
+			isa = XCBuildConfiguration;
+			baseConfigurationReference = D71350471124D56600E2C1DA /* MacConfigExternalRelease.xcconfig */;
+			buildSettings = {
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+			};
+			name = Release;
+		};
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+		1DEB914A08733D8E0010E9CD /* Build configuration list for PBXNativeTarget "libmtp" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				1DEB914B08733D8E0010E9CD /* Debug */,
+				1DEB914C08733D8E0010E9CD /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+		1DEB914E08733D8E0010E9CD /* Build configuration list for PBXProject "libmtp" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				1DEB914F08733D8E0010E9CD /* Debug */,
+				1DEB915008733D8E0010E9CD /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+/* End XCConfigurationList section */
+	};
+	rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
+}
diff --git a/ltmain.sh b/ltmain.sh
new file mode 100755
index 0000000..6939dcc
--- /dev/null
+++ b/ltmain.sh
@@ -0,0 +1,8406 @@
+# Generated from ltmain.m4sh.
+
+# ltmain.sh (GNU libtool) 2.2.6
+# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
+
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007 2008 Free Software Foundation, Inc.
+# This is free software; see the source for copying conditions.  There is NO
+# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+# GNU Libtool is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from http://www.gnu.org/licenses/gpl.html,
+# or obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# Usage: $progname [OPTION]... [MODE-ARG]...
+#
+# Provide generalized library-building support services.
+#
+#     --config             show all configuration variables
+#     --debug              enable verbose shell tracing
+# -n, --dry-run            display commands without modifying any files
+#     --features           display basic configuration information and exit
+#     --mode=MODE          use operation mode MODE
+#     --preserve-dup-deps  don't remove duplicate dependency libraries
+#     --quiet, --silent    don't print informational messages
+#     --tag=TAG            use configuration variables from tag TAG
+# -v, --verbose            print informational messages (default)
+#     --version            print version information
+# -h, --help               print short or long help message
+#
+# MODE must be one of the following:
+#
+#       clean              remove files from the build directory
+#       compile            compile a source file into a libtool object
+#       execute            automatically set library path, then run a program
+#       finish             complete the installation of libtool libraries
+#       install            install libraries or executables
+#       link               create a library or an executable
+#       uninstall          remove libraries from an installed directory
+#
+# MODE-ARGS vary depending on the MODE.
+# Try `$progname --help --mode=MODE' for a more detailed description of MODE.
+#
+# When reporting a bug, please describe a test case to reproduce it and
+# include the following information:
+#
+#       host-triplet:	$host
+#       shell:		$SHELL
+#       compiler:		$LTCC
+#       compiler flags:		$LTCFLAGS
+#       linker:		$LD (gnu? $with_gnu_ld)
+#       $progname:		(GNU libtool) 2.2.6
+#       automake:		$automake_version
+#       autoconf:		$autoconf_version
+#
+# Report bugs to <bug-libtool@gnu.org>.
+
+PROGRAM=ltmain.sh
+PACKAGE=libtool
+VERSION=2.2.6
+TIMESTAMP=""
+package_revision=1.3012
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# NLS nuisances: We save the old values to restore during execute mode.
+# Only set LANG and LC_ALL to C if already set.
+# These must not be set unconditionally because not all systems understand
+# e.g. LANG=C (notably SCO).
+lt_user_locale=
+lt_safe_locale=
+for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
+do
+  eval "if test \"\${$lt_var+set}\" = set; then
+          save_$lt_var=\$$lt_var
+          $lt_var=C
+	  export $lt_var
+	  lt_user_locale=\"$lt_var=\\\$save_\$lt_var; \$lt_user_locale\"
+	  lt_safe_locale=\"$lt_var=C; \$lt_safe_locale\"
+	fi"
+done
+
+$lt_unset CDPATH
+
+
+
+
+
+: ${CP="cp -f"}
+: ${ECHO="echo"}
+: ${EGREP="/bin/grep -E"}
+: ${FGREP="/bin/grep -F"}
+: ${GREP="/bin/grep"}
+: ${LN_S="ln -s"}
+: ${MAKE="make"}
+: ${MKDIR="mkdir"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+: ${SED="/bin/sed"}
+: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
+: ${Xsed="$SED -e 1s/^X//"}
+
+# Global variables:
+EXIT_SUCCESS=0
+EXIT_FAILURE=1
+EXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
+EXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
+
+exit_status=$EXIT_SUCCESS
+
+# Make sure IFS has a sensible default
+lt_nl='
+'
+IFS=" 	$lt_nl"
+
+dirname="s,/[^/]*$,,"
+basename="s,^.*/,,"
+
+# func_dirname_and_basename file append nondir_replacement
+# perform func_basename and func_dirname in a single function
+# call:
+#   dirname:  Compute the dirname of FILE.  If nonempty,
+#             add APPEND to the result, otherwise set result
+#             to NONDIR_REPLACEMENT.
+#             value returned in "$func_dirname_result"
+#   basename: Compute filename of FILE.
+#             value retuned in "$func_basename_result"
+# Implementation must be kept synchronized with func_dirname
+# and func_basename. For efficiency, we do not delegate to
+# those functions but instead duplicate the functionality here.
+func_dirname_and_basename ()
+{
+  # Extract subdirectory from the argument.
+  func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"`
+  if test "X$func_dirname_result" = "X${1}"; then
+    func_dirname_result="${3}"
+  else
+    func_dirname_result="$func_dirname_result${2}"
+  fi
+  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
+}
+
+# Generated shell functions inserted here.
+
+# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
+# is ksh but when the shell is invoked as "sh" and the current value of
+# the _XPG environment variable is not equal to 1 (one), the special
+# positional parameter $0, within a function call, is the name of the
+# function.
+progpath="$0"
+
+# The name of this program:
+# In the unlikely event $progname began with a '-', it would play havoc with
+# func_echo (imagine progname=-n), so we prepend ./ in that case:
+func_dirname_and_basename "$progpath"
+progname=$func_basename_result
+case $progname in
+  -*) progname=./$progname ;;
+esac
+
+# Make sure we have an absolute path for reexecution:
+case $progpath in
+  [\\/]*|[A-Za-z]:\\*) ;;
+  *[\\/]*)
+     progdir=$func_dirname_result
+     progdir=`cd "$progdir" && pwd`
+     progpath="$progdir/$progname"
+     ;;
+  *)
+     save_IFS="$IFS"
+     IFS=:
+     for progdir in $PATH; do
+       IFS="$save_IFS"
+       test -x "$progdir/$progname" && break
+     done
+     IFS="$save_IFS"
+     test -n "$progdir" || progdir=`pwd`
+     progpath="$progdir/$progname"
+     ;;
+esac
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+Xsed="${SED}"' -e 1s/^X//'
+sed_quote_subst='s/\([`"$\\]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\(["`\\]\)/\\\1/g'
+
+# Re-`\' parameter expansions in output of double_quote_subst that were
+# `\'-ed in input to the same.  If an odd number of `\' preceded a '$'
+# in input to double_quote_subst, that '$' was protected from expansion.
+# Since each input `\' is now two `\'s, look for any number of runs of
+# four `\'s followed by two `\'s and then a '$'.  `\' that '$'.
+bs='\\'
+bs2='\\\\'
+bs4='\\\\\\\\'
+dollar='\$'
+sed_double_backslash="\
+  s/$bs4/&\\
+/g
+  s/^$bs2$dollar/$bs&/
+  s/\\([^$bs]\\)$bs2$dollar/\\1$bs2$bs$dollar/g
+  s/\n//g"
+
+# Standard options:
+opt_dry_run=false
+opt_help=false
+opt_quiet=false
+opt_verbose=false
+opt_warning=:
+
+# func_echo arg...
+# Echo program name prefixed message, along with the current mode
+# name if it has been set yet.
+func_echo ()
+{
+    $ECHO "$progname${mode+: }$mode: $*"
+}
+
+# func_verbose arg...
+# Echo program name prefixed message in verbose mode only.
+func_verbose ()
+{
+    $opt_verbose && func_echo ${1+"$@"}
+
+    # A bug in bash halts the script if the last line of a function
+    # fails when set -e is in force, so we need another command to
+    # work around that:
+    :
+}
+
+# func_error arg...
+# Echo program name prefixed message to standard error.
+func_error ()
+{
+    $ECHO "$progname${mode+: }$mode: "${1+"$@"} 1>&2
+}
+
+# func_warning arg...
+# Echo program name prefixed warning message to standard error.
+func_warning ()
+{
+    $opt_warning && $ECHO "$progname${mode+: }$mode: warning: "${1+"$@"} 1>&2
+
+    # bash bug again:
+    :
+}
+
+# func_fatal_error arg...
+# Echo program name prefixed message to standard error, and exit.
+func_fatal_error ()
+{
+    func_error ${1+"$@"}
+    exit $EXIT_FAILURE
+}
+
+# func_fatal_help arg...
+# Echo program name prefixed message to standard error, followed by
+# a help hint, and exit.
+func_fatal_help ()
+{
+    func_error ${1+"$@"}
+    func_fatal_error "$help"
+}
+help="Try \`$progname --help' for more information."  ## default
+
+
+# func_grep expression filename
+# Check whether EXPRESSION matches any line of FILENAME, without output.
+func_grep ()
+{
+    $GREP "$1" "$2" >/dev/null 2>&1
+}
+
+
+# func_mkdir_p directory-path
+# Make sure the entire path to DIRECTORY-PATH is available.
+func_mkdir_p ()
+{
+    my_directory_path="$1"
+    my_dir_list=
+
+    if test -n "$my_directory_path" && test "$opt_dry_run" != ":"; then
+
+      # Protect directory names starting with `-'
+      case $my_directory_path in
+        -*) my_directory_path="./$my_directory_path" ;;
+      esac
+
+      # While some portion of DIR does not yet exist...
+      while test ! -d "$my_directory_path"; do
+        # ...make a list in topmost first order.  Use a colon delimited
+	# list incase some portion of path contains whitespace.
+        my_dir_list="$my_directory_path:$my_dir_list"
+
+        # If the last portion added has no slash in it, the list is done
+        case $my_directory_path in */*) ;; *) break ;; esac
+
+        # ...otherwise throw away the child directory and loop
+        my_directory_path=`$ECHO "X$my_directory_path" | $Xsed -e "$dirname"`
+      done
+      my_dir_list=`$ECHO "X$my_dir_list" | $Xsed -e 's,:*$,,'`
+
+      save_mkdir_p_IFS="$IFS"; IFS=':'
+      for my_dir in $my_dir_list; do
+	IFS="$save_mkdir_p_IFS"
+        # mkdir can fail with a `File exist' error if two processes
+        # try to create one of the directories concurrently.  Don't
+        # stop in that case!
+        $MKDIR "$my_dir" 2>/dev/null || :
+      done
+      IFS="$save_mkdir_p_IFS"
+
+      # Bail out if we (or some other process) failed to create a directory.
+      test -d "$my_directory_path" || \
+        func_fatal_error "Failed to create \`$1'"
+    fi
+}
+
+
+# func_mktempdir [string]
+# Make a temporary directory that won't clash with other running
+# libtool processes, and avoids race conditions if possible.  If
+# given, STRING is the basename for that directory.
+func_mktempdir ()
+{
+    my_template="${TMPDIR-/tmp}/${1-$progname}"
+
+    if test "$opt_dry_run" = ":"; then
+      # Return a directory name, but don't create it in dry-run mode
+      my_tmpdir="${my_template}-$$"
+    else
+
+      # If mktemp works, use that first and foremost
+      my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null`
+
+      if test ! -d "$my_tmpdir"; then
+        # Failing that, at least try and use $RANDOM to avoid a race
+        my_tmpdir="${my_template}-${RANDOM-0}$$"
+
+        save_mktempdir_umask=`umask`
+        umask 0077
+        $MKDIR "$my_tmpdir"
+        umask $save_mktempdir_umask
+      fi
+
+      # If we're not in dry-run mode, bomb out on failure
+      test -d "$my_tmpdir" || \
+        func_fatal_error "cannot create temporary directory \`$my_tmpdir'"
+    fi
+
+    $ECHO "X$my_tmpdir" | $Xsed
+}
+
+
+# func_quote_for_eval arg
+# Aesthetically quote ARG to be evaled later.
+# This function returns two values: FUNC_QUOTE_FOR_EVAL_RESULT
+# is double-quoted, suitable for a subsequent eval, whereas
+# FUNC_QUOTE_FOR_EVAL_UNQUOTED_RESULT has merely all characters
+# which are still active within double quotes backslashified.
+func_quote_for_eval ()
+{
+    case $1 in
+      *[\\\`\"\$]*)
+	func_quote_for_eval_unquoted_result=`$ECHO "X$1" | $Xsed -e "$sed_quote_subst"` ;;
+      *)
+        func_quote_for_eval_unquoted_result="$1" ;;
+    esac
+
+    case $func_quote_for_eval_unquoted_result in
+      # Double-quote args containing shell metacharacters to delay
+      # word splitting, command substitution and and variable
+      # expansion for a subsequent eval.
+      # Many Bourne shells cannot handle close brackets correctly
+      # in scan sets, so we specify it separately.
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+        func_quote_for_eval_result="\"$func_quote_for_eval_unquoted_result\""
+        ;;
+      *)
+        func_quote_for_eval_result="$func_quote_for_eval_unquoted_result"
+    esac
+}
+
+
+# func_quote_for_expand arg
+# Aesthetically quote ARG to be evaled later; same as above,
+# but do not quote variable references.
+func_quote_for_expand ()
+{
+    case $1 in
+      *[\\\`\"]*)
+	my_arg=`$ECHO "X$1" | $Xsed \
+	    -e "$double_quote_subst" -e "$sed_double_backslash"` ;;
+      *)
+        my_arg="$1" ;;
+    esac
+
+    case $my_arg in
+      # Double-quote args containing shell metacharacters to delay
+      # word splitting and command substitution for a subsequent eval.
+      # Many Bourne shells cannot handle close brackets correctly
+      # in scan sets, so we specify it separately.
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+        my_arg="\"$my_arg\""
+        ;;
+    esac
+
+    func_quote_for_expand_result="$my_arg"
+}
+
+
+# func_show_eval cmd [fail_exp]
+# Unless opt_silent is true, then output CMD.  Then, if opt_dryrun is
+# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
+# is given, then evaluate it.
+func_show_eval ()
+{
+    my_cmd="$1"
+    my_fail_exp="${2-:}"
+
+    ${opt_silent-false} || {
+      func_quote_for_expand "$my_cmd"
+      eval "func_echo $func_quote_for_expand_result"
+    }
+
+    if ${opt_dry_run-false}; then :; else
+      eval "$my_cmd"
+      my_status=$?
+      if test "$my_status" -eq 0; then :; else
+	eval "(exit $my_status); $my_fail_exp"
+      fi
+    fi
+}
+
+
+# func_show_eval_locale cmd [fail_exp]
+# Unless opt_silent is true, then output CMD.  Then, if opt_dryrun is
+# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
+# is given, then evaluate it.  Use the saved locale for evaluation.
+func_show_eval_locale ()
+{
+    my_cmd="$1"
+    my_fail_exp="${2-:}"
+
+    ${opt_silent-false} || {
+      func_quote_for_expand "$my_cmd"
+      eval "func_echo $func_quote_for_expand_result"
+    }
+
+    if ${opt_dry_run-false}; then :; else
+      eval "$lt_user_locale
+	    $my_cmd"
+      my_status=$?
+      eval "$lt_safe_locale"
+      if test "$my_status" -eq 0; then :; else
+	eval "(exit $my_status); $my_fail_exp"
+      fi
+    fi
+}
+
+
+
+
+
+# func_version
+# Echo version message to standard output and exit.
+func_version ()
+{
+    $SED -n '/^# '$PROGRAM' (GNU /,/# warranty; / {
+        s/^# //
+	s/^# *$//
+        s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/
+        p
+     }' < "$progpath"
+     exit $?
+}
+
+# func_usage
+# Echo short help message to standard output and exit.
+func_usage ()
+{
+    $SED -n '/^# Usage:/,/# -h/ {
+        s/^# //
+	s/^# *$//
+	s/\$progname/'$progname'/
+	p
+    }' < "$progpath"
+    $ECHO
+    $ECHO "run \`$progname --help | more' for full usage"
+    exit $?
+}
+
+# func_help
+# Echo long help message to standard output and exit.
+func_help ()
+{
+    $SED -n '/^# Usage:/,/# Report bugs to/ {
+        s/^# //
+	s/^# *$//
+	s*\$progname*'$progname'*
+	s*\$host*'"$host"'*
+	s*\$SHELL*'"$SHELL"'*
+	s*\$LTCC*'"$LTCC"'*
+	s*\$LTCFLAGS*'"$LTCFLAGS"'*
+	s*\$LD*'"$LD"'*
+	s/\$with_gnu_ld/'"$with_gnu_ld"'/
+	s/\$automake_version/'"`(automake --version) 2>/dev/null |$SED 1q`"'/
+	s/\$autoconf_version/'"`(autoconf --version) 2>/dev/null |$SED 1q`"'/
+	p
+     }' < "$progpath"
+    exit $?
+}
+
+# func_missing_arg argname
+# Echo program name prefixed message to standard error and set global
+# exit_cmd.
+func_missing_arg ()
+{
+    func_error "missing argument for $1"
+    exit_cmd=exit
+}
+
+exit_cmd=:
+
+
+
+
+
+# Check that we have a working $ECHO.
+if test "X$1" = X--no-reexec; then
+  # Discard the --no-reexec flag, and continue.
+  shift
+elif test "X$1" = X--fallback-echo; then
+  # Avoid inline document here, it may be left over
+  :
+elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then
+  # Yippee, $ECHO works!
+  :
+else
+  # Restart under the correct shell, and then maybe $ECHO will work.
+  exec $SHELL "$progpath" --no-reexec ${1+"$@"}
+fi
+
+if test "X$1" = X--fallback-echo; then
+  # used as fallback echo
+  shift
+  cat <<EOF
+$*
+EOF
+  exit $EXIT_SUCCESS
+fi
+
+magic="%%%MAGIC variable%%%"
+magic_exe="%%%MAGIC EXE variable%%%"
+
+# Global variables.
+# $mode is unset
+nonopt=
+execute_dlfiles=
+preserve_args=
+lo2o="s/\\.lo\$/.${objext}/"
+o2lo="s/\\.${objext}\$/.lo/"
+extracted_archives=
+extracted_serial=0
+
+opt_dry_run=false
+opt_duplicate_deps=false
+opt_silent=false
+opt_debug=:
+
+# If this variable is set in any of the actions, the command in it
+# will be execed at the end.  This prevents here-documents from being
+# left over by shells.
+exec_cmd=
+
+# func_fatal_configuration arg...
+# Echo program name prefixed message to standard error, followed by
+# a configuration failure hint, and exit.
+func_fatal_configuration ()
+{
+    func_error ${1+"$@"}
+    func_error "See the $PACKAGE documentation for more information."
+    func_fatal_error "Fatal configuration error."
+}
+
+
+# func_config
+# Display the configuration for all the tags in this script.
+func_config ()
+{
+    re_begincf='^# ### BEGIN LIBTOOL'
+    re_endcf='^# ### END LIBTOOL'
+
+    # Default configuration.
+    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
+
+    # Now print the configurations for the tags.
+    for tagname in $taglist; do
+      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
+    done
+
+    exit $?
+}
+
+# func_features
+# Display the features supported by this script.
+func_features ()
+{
+    $ECHO "host: $host"
+    if test "$build_libtool_libs" = yes; then
+      $ECHO "enable shared libraries"
+    else
+      $ECHO "disable shared libraries"
+    fi
+    if test "$build_old_libs" = yes; then
+      $ECHO "enable static libraries"
+    else
+      $ECHO "disable static libraries"
+    fi
+
+    exit $?
+}
+
+# func_enable_tag tagname
+# Verify that TAGNAME is valid, and either flag an error and exit, or
+# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
+# variable here.
+func_enable_tag ()
+{
+  # Global variable:
+  tagname="$1"
+
+  re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
+  re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
+  sed_extractcf="/$re_begincf/,/$re_endcf/p"
+
+  # Validate tagname.
+  case $tagname in
+    *[!-_A-Za-z0-9,/]*)
+      func_fatal_error "invalid tag name: $tagname"
+      ;;
+  esac
+
+  # Don't test for the "default" C tag, as we know it's
+  # there but not specially marked.
+  case $tagname in
+    CC) ;;
+    *)
+      if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
+	taglist="$taglist $tagname"
+
+	# Evaluate the configuration.  Be careful to quote the path
+	# and the sed script, to avoid splitting on whitespace, but
+	# also don't use non-portable quotes within backquotes within
+	# quotes we have to do it in 2 steps:
+	extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
+	eval "$extractedcf"
+      else
+	func_error "ignoring unknown tag $tagname"
+      fi
+      ;;
+  esac
+}
+
+# Parse options once, thoroughly.  This comes as soon as possible in
+# the script to make things like `libtool --version' happen quickly.
+{
+
+  # Shorthand for --mode=foo, only valid as the first argument
+  case $1 in
+  clean|clea|cle|cl)
+    shift; set dummy --mode clean ${1+"$@"}; shift
+    ;;
+  compile|compil|compi|comp|com|co|c)
+    shift; set dummy --mode compile ${1+"$@"}; shift
+    ;;
+  execute|execut|execu|exec|exe|ex|e)
+    shift; set dummy --mode execute ${1+"$@"}; shift
+    ;;
+  finish|finis|fini|fin|fi|f)
+    shift; set dummy --mode finish ${1+"$@"}; shift
+    ;;
+  install|instal|insta|inst|ins|in|i)
+    shift; set dummy --mode install ${1+"$@"}; shift
+    ;;
+  link|lin|li|l)
+    shift; set dummy --mode link ${1+"$@"}; shift
+    ;;
+  uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
+    shift; set dummy --mode uninstall ${1+"$@"}; shift
+    ;;
+  esac
+
+  # Parse non-mode specific arguments:
+  while test "$#" -gt 0; do
+    opt="$1"
+    shift
+
+    case $opt in
+      --config)		func_config					;;
+
+      --debug)		preserve_args="$preserve_args $opt"
+			func_echo "enabling shell trace mode"
+			opt_debug='set -x'
+			$opt_debug
+			;;
+
+      -dlopen)		test "$#" -eq 0 && func_missing_arg "$opt" && break
+			execute_dlfiles="$execute_dlfiles $1"
+			shift
+			;;
+
+      --dry-run | -n)	opt_dry_run=:					;;
+      --features)       func_features					;;
+      --finish)		mode="finish"					;;
+
+      --mode)		test "$#" -eq 0 && func_missing_arg "$opt" && break
+			case $1 in
+			  # Valid mode arguments:
+			  clean)	;;
+			  compile)	;;
+			  execute)	;;
+			  finish)	;;
+			  install)	;;
+			  link)		;;
+			  relink)	;;
+			  uninstall)	;;
+
+			  # Catch anything else as an error
+			  *) func_error "invalid argument for $opt"
+			     exit_cmd=exit
+			     break
+			     ;;
+		        esac
+
+			mode="$1"
+			shift
+			;;
+
+      --preserve-dup-deps)
+			opt_duplicate_deps=:				;;
+
+      --quiet|--silent)	preserve_args="$preserve_args $opt"
+			opt_silent=:
+			;;
+
+      --verbose| -v)	preserve_args="$preserve_args $opt"
+			opt_silent=false
+			;;
+
+      --tag)		test "$#" -eq 0 && func_missing_arg "$opt" && break
+			preserve_args="$preserve_args $opt $1"
+			func_enable_tag "$1"	# tagname is set here
+			shift
+			;;
+
+      # Separate optargs to long options:
+      -dlopen=*|--mode=*|--tag=*)
+			func_opt_split "$opt"
+			set dummy "$func_opt_split_opt" "$func_opt_split_arg" ${1+"$@"}
+			shift
+			;;
+
+      -\?|-h)		func_usage					;;
+      --help)		opt_help=:					;;
+      --version)	func_version					;;
+
+      -*)		func_fatal_help "unrecognized option \`$opt'"	;;
+
+      *)		nonopt="$opt"
+			break
+			;;
+    esac
+  done
+
+
+  case $host in
+    *cygwin* | *mingw* | *pw32* | *cegcc*)
+      # don't eliminate duplications in $postdeps and $predeps
+      opt_duplicate_compiler_generated_deps=:
+      ;;
+    *)
+      opt_duplicate_compiler_generated_deps=$opt_duplicate_deps
+      ;;
+  esac
+
+  # Having warned about all mis-specified options, bail out if
+  # anything was wrong.
+  $exit_cmd $EXIT_FAILURE
+}
+
+# func_check_version_match
+# Ensure that we are using m4 macros, and libtool script from the same
+# release of libtool.
+func_check_version_match ()
+{
+  if test "$package_revision" != "$macro_revision"; then
+    if test "$VERSION" != "$macro_version"; then
+      if test -z "$macro_version"; then
+        cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
+$progname: definition of this LT_INIT comes from an older release.
+$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
+$progname: and run autoconf again.
+_LT_EOF
+      else
+        cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
+$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
+$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
+$progname: and run autoconf again.
+_LT_EOF
+      fi
+    else
+      cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
+$progname: but the definition of this LT_INIT comes from revision $macro_revision.
+$progname: You should recreate aclocal.m4 with macros from revision $package_revision
+$progname: of $PACKAGE $VERSION and run autoconf again.
+_LT_EOF
+    fi
+
+    exit $EXIT_MISMATCH
+  fi
+}
+
+
+## ----------- ##
+##    Main.    ##
+## ----------- ##
+
+$opt_help || {
+  # Sanity checks first:
+  func_check_version_match
+
+  if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
+    func_fatal_configuration "not configured to build any kind of library"
+  fi
+
+  test -z "$mode" && func_fatal_error "error: you must specify a MODE."
+
+
+  # Darwin sucks
+  eval std_shrext=\"$shrext_cmds\"
+
+
+  # Only execute mode is allowed to have -dlopen flags.
+  if test -n "$execute_dlfiles" && test "$mode" != execute; then
+    func_error "unrecognized option \`-dlopen'"
+    $ECHO "$help" 1>&2
+    exit $EXIT_FAILURE
+  fi
+
+  # Change the help message to a mode-specific one.
+  generic_help="$help"
+  help="Try \`$progname --help --mode=$mode' for more information."
+}
+
+
+# func_lalib_p file
+# True iff FILE is a libtool `.la' library or `.lo' object file.
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_lalib_p ()
+{
+    test -f "$1" &&
+      $SED -e 4q "$1" 2>/dev/null \
+        | $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
+}
+
+# func_lalib_unsafe_p file
+# True iff FILE is a libtool `.la' library or `.lo' object file.
+# This function implements the same check as func_lalib_p without
+# resorting to external programs.  To this end, it redirects stdin and
+# closes it afterwards, without saving the original file descriptor.
+# As a safety measure, use it only where a negative result would be
+# fatal anyway.  Works if `file' does not exist.
+func_lalib_unsafe_p ()
+{
+    lalib_p=no
+    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
+	for lalib_p_l in 1 2 3 4
+	do
+	    read lalib_p_line
+	    case "$lalib_p_line" in
+		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
+	    esac
+	done
+	exec 0<&5 5<&-
+    fi
+    test "$lalib_p" = yes
+}
+
+# func_ltwrapper_script_p file
+# True iff FILE is a libtool wrapper script
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_script_p ()
+{
+    func_lalib_p "$1"
+}
+
+# func_ltwrapper_executable_p file
+# True iff FILE is a libtool wrapper executable
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_executable_p ()
+{
+    func_ltwrapper_exec_suffix=
+    case $1 in
+    *.exe) ;;
+    *) func_ltwrapper_exec_suffix=.exe ;;
+    esac
+    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
+}
+
+# func_ltwrapper_scriptname file
+# Assumes file is an ltwrapper_executable
+# uses $file to determine the appropriate filename for a
+# temporary ltwrapper_script.
+func_ltwrapper_scriptname ()
+{
+    func_ltwrapper_scriptname_result=""
+    if func_ltwrapper_executable_p "$1"; then
+	func_dirname_and_basename "$1" "" "."
+	func_stripname '' '.exe' "$func_basename_result"
+	func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper"
+    fi
+}
+
+# func_ltwrapper_p file
+# True iff FILE is a libtool wrapper script or wrapper executable
+# This function is only a basic sanity check; it will hardly flush out
+# determined imposters.
+func_ltwrapper_p ()
+{
+    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
+}
+
+
+# func_execute_cmds commands fail_cmd
+# Execute tilde-delimited COMMANDS.
+# If FAIL_CMD is given, eval that upon failure.
+# FAIL_CMD may read-access the current command in variable CMD!
+func_execute_cmds ()
+{
+    $opt_debug
+    save_ifs=$IFS; IFS='~'
+    for cmd in $1; do
+      IFS=$save_ifs
+      eval cmd=\"$cmd\"
+      func_show_eval "$cmd" "${2-:}"
+    done
+    IFS=$save_ifs
+}
+
+
+# func_source file
+# Source FILE, adding directory component if necessary.
+# Note that it is not necessary on cygwin/mingw to append a dot to
+# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
+# behavior happens only for exec(3), not for open(2)!  Also, sourcing
+# `FILE.' does not work on cygwin managed mounts.
+func_source ()
+{
+    $opt_debug
+    case $1 in
+    */* | *\\*)	. "$1" ;;
+    *)		. "./$1" ;;
+    esac
+}
+
+
+# func_infer_tag arg
+# Infer tagged configuration to use if any are available and
+# if one wasn't chosen via the "--tag" command line option.
+# Only attempt this if the compiler in the base compile
+# command doesn't match the default compiler.
+# arg is usually of the form 'gcc ...'
+func_infer_tag ()
+{
+    $opt_debug
+    if test -n "$available_tags" && test -z "$tagname"; then
+      CC_quoted=
+      for arg in $CC; do
+        func_quote_for_eval "$arg"
+	CC_quoted="$CC_quoted $func_quote_for_eval_result"
+      done
+      case $@ in
+      # Blanks in the command may have been stripped by the calling shell,
+      # but not from the CC environment variable when configure was run.
+      " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*) ;;
+      # Blanks at the start of $base_compile will cause this to fail
+      # if we don't check for them as well.
+      *)
+	for z in $available_tags; do
+	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
+	    # Evaluate the configuration.
+	    eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
+	    CC_quoted=
+	    for arg in $CC; do
+	      # Double-quote args containing other shell metacharacters.
+	      func_quote_for_eval "$arg"
+	      CC_quoted="$CC_quoted $func_quote_for_eval_result"
+	    done
+	    case "$@ " in
+	      " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*)
+	      # The compiler in the base compile command matches
+	      # the one in the tagged configuration.
+	      # Assume this is the tagged configuration we want.
+	      tagname=$z
+	      break
+	      ;;
+	    esac
+	  fi
+	done
+	# If $tagname still isn't set, then no tagged configuration
+	# was found and let the user know that the "--tag" command
+	# line option must be used.
+	if test -z "$tagname"; then
+	  func_echo "unable to infer tagged configuration"
+	  func_fatal_error "specify a tag with \`--tag'"
+#	else
+#	  func_verbose "using $tagname tagged configuration"
+	fi
+	;;
+      esac
+    fi
+}
+
+
+
+# func_write_libtool_object output_name pic_name nonpic_name
+# Create a libtool object file (analogous to a ".la" file),
+# but don't create it if we're doing a dry run.
+func_write_libtool_object ()
+{
+    write_libobj=${1}
+    if test "$build_libtool_libs" = yes; then
+      write_lobj=\'${2}\'
+    else
+      write_lobj=none
+    fi
+
+    if test "$build_old_libs" = yes; then
+      write_oldobj=\'${3}\'
+    else
+      write_oldobj=none
+    fi
+
+    $opt_dry_run || {
+      cat >${write_libobj}T <<EOF
+# $write_libobj - a libtool object file
+# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.
+pic_object=$write_lobj
+
+# Name of the non-PIC object
+non_pic_object=$write_oldobj
+
+EOF
+      $MV "${write_libobj}T" "${write_libobj}"
+    }
+}
+
+# func_mode_compile arg...
+func_mode_compile ()
+{
+    $opt_debug
+    # Get the compilation command and the source file.
+    base_compile=
+    srcfile="$nonopt"  #  always keep a non-empty value in "srcfile"
+    suppress_opt=yes
+    suppress_output=
+    arg_mode=normal
+    libobj=
+    later=
+    pie_flag=
+
+    for arg
+    do
+      case $arg_mode in
+      arg  )
+	# do not "continue".  Instead, add this to base_compile
+	lastarg="$arg"
+	arg_mode=normal
+	;;
+
+      target )
+	libobj="$arg"
+	arg_mode=normal
+	continue
+	;;
+
+      normal )
+	# Accept any command-line options.
+	case $arg in
+	-o)
+	  test -n "$libobj" && \
+	    func_fatal_error "you cannot specify \`-o' more than once"
+	  arg_mode=target
+	  continue
+	  ;;
+
+	-pie | -fpie | -fPIE)
+          pie_flag="$pie_flag $arg"
+	  continue
+	  ;;
+
+	-shared | -static | -prefer-pic | -prefer-non-pic)
+	  later="$later $arg"
+	  continue
+	  ;;
+
+	-no-suppress)
+	  suppress_opt=no
+	  continue
+	  ;;
+
+	-Xcompiler)
+	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
+	  continue      #  The current "srcfile" will either be retained or
+	  ;;            #  replaced later.  I would guess that would be a bug.
+
+	-Wc,*)
+	  func_stripname '-Wc,' '' "$arg"
+	  args=$func_stripname_result
+	  lastarg=
+	  save_ifs="$IFS"; IFS=','
+	  for arg in $args; do
+	    IFS="$save_ifs"
+	    func_quote_for_eval "$arg"
+	    lastarg="$lastarg $func_quote_for_eval_result"
+	  done
+	  IFS="$save_ifs"
+	  func_stripname ' ' '' "$lastarg"
+	  lastarg=$func_stripname_result
+
+	  # Add the arguments to base_compile.
+	  base_compile="$base_compile $lastarg"
+	  continue
+	  ;;
+
+	*)
+	  # Accept the current argument as the source file.
+	  # The previous "srcfile" becomes the current argument.
+	  #
+	  lastarg="$srcfile"
+	  srcfile="$arg"
+	  ;;
+	esac  #  case $arg
+	;;
+      esac    #  case $arg_mode
+
+      # Aesthetically quote the previous argument.
+      func_quote_for_eval "$lastarg"
+      base_compile="$base_compile $func_quote_for_eval_result"
+    done # for arg
+
+    case $arg_mode in
+    arg)
+      func_fatal_error "you must specify an argument for -Xcompile"
+      ;;
+    target)
+      func_fatal_error "you must specify a target with \`-o'"
+      ;;
+    *)
+      # Get the name of the library object.
+      test -z "$libobj" && {
+	func_basename "$srcfile"
+	libobj="$func_basename_result"
+      }
+      ;;
+    esac
+
+    # Recognize several different file suffixes.
+    # If the user specifies -o file.o, it is replaced with file.lo
+    case $libobj in
+    *.[cCFSifmso] | \
+    *.ada | *.adb | *.ads | *.asm | \
+    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
+    *.[fF][09]? | *.for | *.java | *.obj | *.sx)
+      func_xform "$libobj"
+      libobj=$func_xform_result
+      ;;
+    esac
+
+    case $libobj in
+    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
+    *)
+      func_fatal_error "cannot determine name of library object from \`$libobj'"
+      ;;
+    esac
+
+    func_infer_tag $base_compile
+
+    for arg in $later; do
+      case $arg in
+      -shared)
+	test "$build_libtool_libs" != yes && \
+	  func_fatal_configuration "can not build a shared library"
+	build_old_libs=no
+	continue
+	;;
+
+      -static)
+	build_libtool_libs=no
+	build_old_libs=yes
+	continue
+	;;
+
+      -prefer-pic)
+	pic_mode=yes
+	continue
+	;;
+
+      -prefer-non-pic)
+	pic_mode=no
+	continue
+	;;
+      esac
+    done
+
+    func_quote_for_eval "$libobj"
+    test "X$libobj" != "X$func_quote_for_eval_result" \
+      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
+      && func_warning "libobj name \`$libobj' may not contain shell special characters."
+    func_dirname_and_basename "$obj" "/" ""
+    objname="$func_basename_result"
+    xdir="$func_dirname_result"
+    lobj=${xdir}$objdir/$objname
+
+    test -z "$base_compile" && \
+      func_fatal_help "you must specify a compilation command"
+
+    # Delete any leftover library objects.
+    if test "$build_old_libs" = yes; then
+      removelist="$obj $lobj $libobj ${libobj}T"
+    else
+      removelist="$lobj $libobj ${libobj}T"
+    fi
+
+    # On Cygwin there's no "real" PIC flag so we must build both object types
+    case $host_os in
+    cygwin* | mingw* | pw32* | os2* | cegcc*)
+      pic_mode=default
+      ;;
+    esac
+    if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then
+      # non-PIC code in shared libraries is not supported
+      pic_mode=default
+    fi
+
+    # Calculate the filename of the output object if compiler does
+    # not support -o with -c
+    if test "$compiler_c_o" = no; then
+      output_obj=`$ECHO "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext}
+      lockfile="$output_obj.lock"
+    else
+      output_obj=
+      need_locks=no
+      lockfile=
+    fi
+
+    # Lock this critical section if it is needed
+    # We use this script file to make the link, it avoids creating a new file
+    if test "$need_locks" = yes; then
+      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
+	func_echo "Waiting for $lockfile to be removed"
+	sleep 2
+      done
+    elif test "$need_locks" = warn; then
+      if test -f "$lockfile"; then
+	$ECHO "\
+*** ERROR, $lockfile exists and contains:
+`cat $lockfile 2>/dev/null`
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support \`-c' and \`-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+	$opt_dry_run || $RM $removelist
+	exit $EXIT_FAILURE
+      fi
+      removelist="$removelist $output_obj"
+      $ECHO "$srcfile" > "$lockfile"
+    fi
+
+    $opt_dry_run || $RM $removelist
+    removelist="$removelist $lockfile"
+    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
+
+    if test -n "$fix_srcfile_path"; then
+      eval srcfile=\"$fix_srcfile_path\"
+    fi
+    func_quote_for_eval "$srcfile"
+    qsrcfile=$func_quote_for_eval_result
+
+    # Only build a PIC object if we are building libtool libraries.
+    if test "$build_libtool_libs" = yes; then
+      # Without this assignment, base_compile gets emptied.
+      fbsd_hideous_sh_bug=$base_compile
+
+      if test "$pic_mode" != no; then
+	command="$base_compile $qsrcfile $pic_flag"
+      else
+	# Don't build PIC code
+	command="$base_compile $qsrcfile"
+      fi
+
+      func_mkdir_p "$xdir$objdir"
+
+      if test -z "$output_obj"; then
+	# Place PIC objects in $objdir
+	command="$command -o $lobj"
+      fi
+
+      func_show_eval_locale "$command"	\
+          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
+
+      if test "$need_locks" = warn &&
+	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
+	$ECHO "\
+*** ERROR, $lockfile contains:
+`cat $lockfile 2>/dev/null`
+
+but it should contain:
+$srcfile
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support \`-c' and \`-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+	$opt_dry_run || $RM $removelist
+	exit $EXIT_FAILURE
+      fi
+
+      # Just move the object if needed, then go on to compile the next one
+      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
+	func_show_eval '$MV "$output_obj" "$lobj"' \
+	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
+      fi
+
+      # Allow error messages only from the first compilation.
+      if test "$suppress_opt" = yes; then
+	suppress_output=' >/dev/null 2>&1'
+      fi
+    fi
+
+    # Only build a position-dependent object if we build old libraries.
+    if test "$build_old_libs" = yes; then
+      if test "$pic_mode" != yes; then
+	# Don't build PIC code
+	command="$base_compile $qsrcfile$pie_flag"
+      else
+	command="$base_compile $qsrcfile $pic_flag"
+      fi
+      if test "$compiler_c_o" = yes; then
+	command="$command -o $obj"
+      fi
+
+      # Suppress compiler output if we already did a PIC compilation.
+      command="$command$suppress_output"
+      func_show_eval_locale "$command" \
+        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
+
+      if test "$need_locks" = warn &&
+	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
+	$ECHO "\
+*** ERROR, $lockfile contains:
+`cat $lockfile 2>/dev/null`
+
+but it should contain:
+$srcfile
+
+This indicates that another process is trying to use the same
+temporary object file, and libtool could not work around it because
+your compiler does not support \`-c' and \`-o' together.  If you
+repeat this compilation, it may succeed, by chance, but you had better
+avoid parallel builds (make -j) in this platform, or get a better
+compiler."
+
+	$opt_dry_run || $RM $removelist
+	exit $EXIT_FAILURE
+      fi
+
+      # Just move the object if needed
+      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
+	func_show_eval '$MV "$output_obj" "$obj"' \
+	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
+      fi
+    fi
+
+    $opt_dry_run || {
+      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
+
+      # Unlock the critical section if it was locked
+      if test "$need_locks" != no; then
+	removelist=$lockfile
+        $RM "$lockfile"
+      fi
+    }
+
+    exit $EXIT_SUCCESS
+}
+
+$opt_help || {
+test "$mode" = compile && func_mode_compile ${1+"$@"}
+}
+
+func_mode_help ()
+{
+    # We need to display help for each of the modes.
+    case $mode in
+      "")
+        # Generic help is extracted from the usage comments
+        # at the start of this file.
+        func_help
+        ;;
+
+      clean)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
+
+Remove files from the build directory.
+
+RM is the name of the program to use to delete files associated with each FILE
+(typically \`/bin/rm').  RM-OPTIONS are options (such as \`-f') to be passed
+to RM.
+
+If FILE is a libtool library, object or program, all the files associated
+with it are deleted. Otherwise, only FILE itself is deleted using RM."
+        ;;
+
+      compile)
+      $ECHO \
+"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
+
+Compile a source file into a libtool library object.
+
+This mode accepts the following additional options:
+
+  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
+  -no-suppress      do not suppress compiler output for multiple passes
+  -prefer-pic       try to building PIC objects only
+  -prefer-non-pic   try to building non-PIC objects only
+  -shared           do not build a \`.o' file suitable for static linking
+  -static           only build a \`.o' file suitable for static linking
+
+COMPILE-COMMAND is a command to be used in creating a \`standard' object file
+from the given SOURCEFILE.
+
+The output file name is determined by removing the directory component from
+SOURCEFILE, then substituting the C source code suffix \`.c' with the
+library object suffix, \`.lo'."
+        ;;
+
+      execute)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
+
+Automatically set library path, then run a program.
+
+This mode accepts the following additional options:
+
+  -dlopen FILE      add the directory containing FILE to the library path
+
+This mode sets the library path environment variable according to \`-dlopen'
+flags.
+
+If any of the ARGS are libtool executable wrappers, then they are translated
+into their corresponding uninstalled binary, and any of their required library
+directories are added to the library path.
+
+Then, COMMAND is executed, with ARGS as arguments."
+        ;;
+
+      finish)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
+
+Complete the installation of libtool libraries.
+
+Each LIBDIR is a directory that contains libtool libraries.
+
+The commands that this mode executes may require superuser privileges.  Use
+the \`--dry-run' option if you just want to see what would be executed."
+        ;;
+
+      install)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
+
+Install executables or libraries.
+
+INSTALL-COMMAND is the installation command.  The first component should be
+either the \`install' or \`cp' program.
+
+The following components of INSTALL-COMMAND are treated specially:
+
+  -inst-prefix PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
+
+The rest of the components are interpreted as arguments to that command (only
+BSD-compatible install options are recognized)."
+        ;;
+
+      link)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
+
+Link object files or libraries together to form another library, or to
+create an executable program.
+
+LINK-COMMAND is a command using the C compiler that you would use to create
+a program from several object files.
+
+The following components of LINK-COMMAND are treated specially:
+
+  -all-static       do not do any dynamic linking at all
+  -avoid-version    do not add a version suffix if possible
+  -dlopen FILE      \`-dlpreopen' FILE if it cannot be dlopened at runtime
+  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
+  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
+  -export-symbols SYMFILE
+                    try to export only the symbols listed in SYMFILE
+  -export-symbols-regex REGEX
+                    try to export only the symbols matching REGEX
+  -LLIBDIR          search LIBDIR for required installed libraries
+  -lNAME            OUTPUT-FILE requires the installed library libNAME
+  -module           build a library that can dlopened
+  -no-fast-install  disable the fast-install mode
+  -no-install       link a not-installable executable
+  -no-undefined     declare that a library does not refer to external symbols
+  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
+  -objectlist FILE  Use a list of object files found in FILE to specify objects
+  -precious-files-regex REGEX
+                    don't remove output files matching REGEX
+  -release RELEASE  specify package release information
+  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
+  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
+  -shared           only do dynamic linking of libtool libraries
+  -shrext SUFFIX    override the standard shared library file extension
+  -static           do not do any dynamic linking of uninstalled libtool libraries
+  -static-libtool-libs
+                    do not do any dynamic linking of libtool libraries
+  -version-info CURRENT[:REVISION[:AGE]]
+                    specify library version info [each variable defaults to 0]
+  -weak LIBNAME     declare that the target provides the LIBNAME interface
+
+All other options (arguments beginning with \`-') are ignored.
+
+Every other argument is treated as a filename.  Files ending in \`.la' are
+treated as uninstalled libtool libraries, other files are standard or library
+object files.
+
+If the OUTPUT-FILE ends in \`.la', then a libtool library is created,
+only library objects (\`.lo' files) may be specified, and \`-rpath' is
+required, except when creating a convenience library.
+
+If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created
+using \`ar' and \`ranlib', or on Windows using \`lib'.
+
+If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file
+is created, otherwise an executable program is created."
+        ;;
+
+      uninstall)
+        $ECHO \
+"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
+
+Remove libraries from an installation directory.
+
+RM is the name of the program to use to delete files associated with each FILE
+(typically \`/bin/rm').  RM-OPTIONS are options (such as \`-f') to be passed
+to RM.
+
+If FILE is a libtool library, all the files associated with it are deleted.
+Otherwise, only FILE itself is deleted using RM."
+        ;;
+
+      *)
+        func_fatal_help "invalid operation mode \`$mode'"
+        ;;
+    esac
+
+    $ECHO
+    $ECHO "Try \`$progname --help' for more information about other modes."
+
+    exit $?
+}
+
+  # Now that we've collected a possible --mode arg, show help if necessary
+  $opt_help && func_mode_help
+
+
+# func_mode_execute arg...
+func_mode_execute ()
+{
+    $opt_debug
+    # The first argument is the command name.
+    cmd="$nonopt"
+    test -z "$cmd" && \
+      func_fatal_help "you must specify a COMMAND"
+
+    # Handle -dlopen flags immediately.
+    for file in $execute_dlfiles; do
+      test -f "$file" \
+	|| func_fatal_help "\`$file' is not a file"
+
+      dir=
+      case $file in
+      *.la)
+	# Check to see that this really is a libtool archive.
+	func_lalib_unsafe_p "$file" \
+	  || func_fatal_help "\`$lib' is not a valid libtool archive"
+
+	# Read the libtool library.
+	dlname=
+	library_names=
+	func_source "$file"
+
+	# Skip this library if it cannot be dlopened.
+	if test -z "$dlname"; then
+	  # Warn if it was a shared library.
+	  test -n "$library_names" && \
+	    func_warning "\`$file' was not linked with \`-export-dynamic'"
+	  continue
+	fi
+
+	func_dirname "$file" "" "."
+	dir="$func_dirname_result"
+
+	if test -f "$dir/$objdir/$dlname"; then
+	  dir="$dir/$objdir"
+	else
+	  if test ! -f "$dir/$dlname"; then
+	    func_fatal_error "cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'"
+	  fi
+	fi
+	;;
+
+      *.lo)
+	# Just add the directory containing the .lo file.
+	func_dirname "$file" "" "."
+	dir="$func_dirname_result"
+	;;
+
+      *)
+	func_warning "\`-dlopen' is ignored for non-libtool libraries and objects"
+	continue
+	;;
+      esac
+
+      # Get the absolute pathname.
+      absdir=`cd "$dir" && pwd`
+      test -n "$absdir" && dir="$absdir"
+
+      # Now add the directory to shlibpath_var.
+      if eval "test -z \"\$$shlibpath_var\""; then
+	eval "$shlibpath_var=\"\$dir\""
+      else
+	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
+      fi
+    done
+
+    # This variable tells wrapper scripts just to set shlibpath_var
+    # rather than running their programs.
+    libtool_execute_magic="$magic"
+
+    # Check if any of the arguments is a wrapper script.
+    args=
+    for file
+    do
+      case $file in
+      -*) ;;
+      *)
+	# Do a test to see if this is really a libtool program.
+	if func_ltwrapper_script_p "$file"; then
+	  func_source "$file"
+	  # Transform arg to wrapped name.
+	  file="$progdir/$program"
+	elif func_ltwrapper_executable_p "$file"; then
+	  func_ltwrapper_scriptname "$file"
+	  func_source "$func_ltwrapper_scriptname_result"
+	  # Transform arg to wrapped name.
+	  file="$progdir/$program"
+	fi
+	;;
+      esac
+      # Quote arguments (to preserve shell metacharacters).
+      func_quote_for_eval "$file"
+      args="$args $func_quote_for_eval_result"
+    done
+
+    if test "X$opt_dry_run" = Xfalse; then
+      if test -n "$shlibpath_var"; then
+	# Export the shlibpath_var.
+	eval "export $shlibpath_var"
+      fi
+
+      # Restore saved environment variables
+      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
+      do
+	eval "if test \"\${save_$lt_var+set}\" = set; then
+                $lt_var=\$save_$lt_var; export $lt_var
+	      else
+		$lt_unset $lt_var
+	      fi"
+      done
+
+      # Now prepare to actually exec the command.
+      exec_cmd="\$cmd$args"
+    else
+      # Display what would be done.
+      if test -n "$shlibpath_var"; then
+	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
+	$ECHO "export $shlibpath_var"
+      fi
+      $ECHO "$cmd$args"
+      exit $EXIT_SUCCESS
+    fi
+}
+
+test "$mode" = execute && func_mode_execute ${1+"$@"}
+
+
+# func_mode_finish arg...
+func_mode_finish ()
+{
+    $opt_debug
+    libdirs="$nonopt"
+    admincmds=
+
+    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
+      for dir
+      do
+	libdirs="$libdirs $dir"
+      done
+
+      for libdir in $libdirs; do
+	if test -n "$finish_cmds"; then
+	  # Do each command in the finish commands.
+	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
+'"$cmd"'"'
+	fi
+	if test -n "$finish_eval"; then
+	  # Do the single finish_eval.
+	  eval cmds=\"$finish_eval\"
+	  $opt_dry_run || eval "$cmds" || admincmds="$admincmds
+       $cmds"
+	fi
+      done
+    fi
+
+    # Exit here if they wanted silent mode.
+    $opt_silent && exit $EXIT_SUCCESS
+
+    $ECHO "X----------------------------------------------------------------------" | $Xsed
+    $ECHO "Libraries have been installed in:"
+    for libdir in $libdirs; do
+      $ECHO "   $libdir"
+    done
+    $ECHO
+    $ECHO "If you ever happen to want to link against installed libraries"
+    $ECHO "in a given directory, LIBDIR, you must either use libtool, and"
+    $ECHO "specify the full pathname of the library, or use the \`-LLIBDIR'"
+    $ECHO "flag during linking and do at least one of the following:"
+    if test -n "$shlibpath_var"; then
+      $ECHO "   - add LIBDIR to the \`$shlibpath_var' environment variable"
+      $ECHO "     during execution"
+    fi
+    if test -n "$runpath_var"; then
+      $ECHO "   - add LIBDIR to the \`$runpath_var' environment variable"
+      $ECHO "     during linking"
+    fi
+    if test -n "$hardcode_libdir_flag_spec"; then
+      libdir=LIBDIR
+      eval flag=\"$hardcode_libdir_flag_spec\"
+
+      $ECHO "   - use the \`$flag' linker flag"
+    fi
+    if test -n "$admincmds"; then
+      $ECHO "   - have your system administrator run these commands:$admincmds"
+    fi
+    if test -f /etc/ld.so.conf; then
+      $ECHO "   - have your system administrator add LIBDIR to \`/etc/ld.so.conf'"
+    fi
+    $ECHO
+
+    $ECHO "See any operating system documentation about shared libraries for"
+    case $host in
+      solaris2.[6789]|solaris2.1[0-9])
+        $ECHO "more information, such as the ld(1), crle(1) and ld.so(8) manual"
+	$ECHO "pages."
+	;;
+      *)
+        $ECHO "more information, such as the ld(1) and ld.so(8) manual pages."
+        ;;
+    esac
+    $ECHO "X----------------------------------------------------------------------" | $Xsed
+    exit $EXIT_SUCCESS
+}
+
+test "$mode" = finish && func_mode_finish ${1+"$@"}
+
+
+# func_mode_install arg...
+func_mode_install ()
+{
+    $opt_debug
+    # There may be an optional sh(1) argument at the beginning of
+    # install_prog (especially on Windows NT).
+    if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh ||
+       # Allow the use of GNU shtool's install command.
+       $ECHO "X$nonopt" | $GREP shtool >/dev/null; then
+      # Aesthetically quote it.
+      func_quote_for_eval "$nonopt"
+      install_prog="$func_quote_for_eval_result "
+      arg=$1
+      shift
+    else
+      install_prog=
+      arg=$nonopt
+    fi
+
+    # The real first argument should be the name of the installation program.
+    # Aesthetically quote it.
+    func_quote_for_eval "$arg"
+    install_prog="$install_prog$func_quote_for_eval_result"
+
+    # We need to accept at least all the BSD install flags.
+    dest=
+    files=
+    opts=
+    prev=
+    install_type=
+    isdir=no
+    stripme=
+    for arg
+    do
+      if test -n "$dest"; then
+	files="$files $dest"
+	dest=$arg
+	continue
+      fi
+
+      case $arg in
+      -d) isdir=yes ;;
+      -f)
+	case " $install_prog " in
+	*[\\\ /]cp\ *) ;;
+	*) prev=$arg ;;
+	esac
+	;;
+      -g | -m | -o)
+	prev=$arg
+	;;
+      -s)
+	stripme=" -s"
+	continue
+	;;
+      -*)
+	;;
+      *)
+	# If the previous option needed an argument, then skip it.
+	if test -n "$prev"; then
+	  prev=
+	else
+	  dest=$arg
+	  continue
+	fi
+	;;
+      esac
+
+      # Aesthetically quote the argument.
+      func_quote_for_eval "$arg"
+      install_prog="$install_prog $func_quote_for_eval_result"
+    done
+
+    test -z "$install_prog" && \
+      func_fatal_help "you must specify an install program"
+
+    test -n "$prev" && \
+      func_fatal_help "the \`$prev' option requires an argument"
+
+    if test -z "$files"; then
+      if test -z "$dest"; then
+	func_fatal_help "no file or destination specified"
+      else
+	func_fatal_help "you must specify a destination"
+      fi
+    fi
+
+    # Strip any trailing slash from the destination.
+    func_stripname '' '/' "$dest"
+    dest=$func_stripname_result
+
+    # Check to see that the destination is a directory.
+    test -d "$dest" && isdir=yes
+    if test "$isdir" = yes; then
+      destdir="$dest"
+      destname=
+    else
+      func_dirname_and_basename "$dest" "" "."
+      destdir="$func_dirname_result"
+      destname="$func_basename_result"
+
+      # Not a directory, so check to see that there is only one file specified.
+      set dummy $files; shift
+      test "$#" -gt 1 && \
+	func_fatal_help "\`$dest' is not a directory"
+    fi
+    case $destdir in
+    [\\/]* | [A-Za-z]:[\\/]*) ;;
+    *)
+      for file in $files; do
+	case $file in
+	*.lo) ;;
+	*)
+	  func_fatal_help "\`$destdir' must be an absolute directory name"
+	  ;;
+	esac
+      done
+      ;;
+    esac
+
+    # This variable tells wrapper scripts just to set variables rather
+    # than running their programs.
+    libtool_install_magic="$magic"
+
+    staticlibs=
+    future_libdirs=
+    current_libdirs=
+    for file in $files; do
+
+      # Do each installation.
+      case $file in
+      *.$libext)
+	# Do the static libraries later.
+	staticlibs="$staticlibs $file"
+	;;
+
+      *.la)
+	# Check to see that this really is a libtool archive.
+	func_lalib_unsafe_p "$file" \
+	  || func_fatal_help "\`$file' is not a valid libtool archive"
+
+	library_names=
+	old_library=
+	relink_command=
+	func_source "$file"
+
+	# Add the libdir to current_libdirs if it is the destination.
+	if test "X$destdir" = "X$libdir"; then
+	  case "$current_libdirs " in
+	  *" $libdir "*) ;;
+	  *) current_libdirs="$current_libdirs $libdir" ;;
+	  esac
+	else
+	  # Note the libdir as a future libdir.
+	  case "$future_libdirs " in
+	  *" $libdir "*) ;;
+	  *) future_libdirs="$future_libdirs $libdir" ;;
+	  esac
+	fi
+
+	func_dirname "$file" "/" ""
+	dir="$func_dirname_result"
+	dir="$dir$objdir"
+
+	if test -n "$relink_command"; then
+	  # Determine the prefix the user has applied to our future dir.
+	  inst_prefix_dir=`$ECHO "X$destdir" | $Xsed -e "s%$libdir\$%%"`
+
+	  # Don't allow the user to place us outside of our expected
+	  # location b/c this prevents finding dependent libraries that
+	  # are installed to the same prefix.
+	  # At present, this check doesn't affect windows .dll's that
+	  # are installed into $libdir/../bin (currently, that works fine)
+	  # but it's something to keep an eye on.
+	  test "$inst_prefix_dir" = "$destdir" && \
+	    func_fatal_error "error: cannot install \`$file' to a directory not ending in $libdir"
+
+	  if test -n "$inst_prefix_dir"; then
+	    # Stick the inst_prefix_dir data into the link command.
+	    relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
+	  else
+	    relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%%"`
+	  fi
+
+	  func_warning "relinking \`$file'"
+	  func_show_eval "$relink_command" \
+	    'func_fatal_error "error: relink \`$file'\'' with the above command before installing it"'
+	fi
+
+	# See the names of the shared library.
+	set dummy $library_names; shift
+	if test -n "$1"; then
+	  realname="$1"
+	  shift
+
+	  srcname="$realname"
+	  test -n "$relink_command" && srcname="$realname"T
+
+	  # Install the shared library and build the symlinks.
+	  func_show_eval "$install_prog $dir/$srcname $destdir/$realname" \
+	      'exit $?'
+	  tstripme="$stripme"
+	  case $host_os in
+	  cygwin* | mingw* | pw32* | cegcc*)
+	    case $realname in
+	    *.dll.a)
+	      tstripme=""
+	      ;;
+	    esac
+	    ;;
+	  esac
+	  if test -n "$tstripme" && test -n "$striplib"; then
+	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
+	  fi
+
+	  if test "$#" -gt 0; then
+	    # Delete the old symlinks, and create new ones.
+	    # Try `ln -sf' first, because the `ln' binary might depend on
+	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
+	    # so we also need to try rm && ln -s.
+	    for linkname
+	    do
+	      test "$linkname" != "$realname" \
+		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
+	    done
+	  fi
+
+	  # Do each command in the postinstall commands.
+	  lib="$destdir/$realname"
+	  func_execute_cmds "$postinstall_cmds" 'exit $?'
+	fi
+
+	# Install the pseudo-library for information purposes.
+	func_basename "$file"
+	name="$func_basename_result"
+	instname="$dir/$name"i
+	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
+
+	# Maybe install the static library, too.
+	test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library"
+	;;
+
+      *.lo)
+	# Install (i.e. copy) a libtool object.
+
+	# Figure out destination file name, if it wasn't already specified.
+	if test -n "$destname"; then
+	  destfile="$destdir/$destname"
+	else
+	  func_basename "$file"
+	  destfile="$func_basename_result"
+	  destfile="$destdir/$destfile"
+	fi
+
+	# Deduce the name of the destination old-style object file.
+	case $destfile in
+	*.lo)
+	  func_lo2o "$destfile"
+	  staticdest=$func_lo2o_result
+	  ;;
+	*.$objext)
+	  staticdest="$destfile"
+	  destfile=
+	  ;;
+	*)
+	  func_fatal_help "cannot copy a libtool object to \`$destfile'"
+	  ;;
+	esac
+
+	# Install the libtool object if requested.
+	test -n "$destfile" && \
+	  func_show_eval "$install_prog $file $destfile" 'exit $?'
+
+	# Install the old object if enabled.
+	if test "$build_old_libs" = yes; then
+	  # Deduce the name of the old-style object file.
+	  func_lo2o "$file"
+	  staticobj=$func_lo2o_result
+	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
+	fi
+	exit $EXIT_SUCCESS
+	;;
+
+      *)
+	# Figure out destination file name, if it wasn't already specified.
+	if test -n "$destname"; then
+	  destfile="$destdir/$destname"
+	else
+	  func_basename "$file"
+	  destfile="$func_basename_result"
+	  destfile="$destdir/$destfile"
+	fi
+
+	# If the file is missing, and there is a .exe on the end, strip it
+	# because it is most likely a libtool script we actually want to
+	# install
+	stripped_ext=""
+	case $file in
+	  *.exe)
+	    if test ! -f "$file"; then
+	      func_stripname '' '.exe' "$file"
+	      file=$func_stripname_result
+	      stripped_ext=".exe"
+	    fi
+	    ;;
+	esac
+
+	# Do a test to see if this is really a libtool program.
+	case $host in
+	*cygwin* | *mingw*)
+	    if func_ltwrapper_executable_p "$file"; then
+	      func_ltwrapper_scriptname "$file"
+	      wrapper=$func_ltwrapper_scriptname_result
+	    else
+	      func_stripname '' '.exe' "$file"
+	      wrapper=$func_stripname_result
+	    fi
+	    ;;
+	*)
+	    wrapper=$file
+	    ;;
+	esac
+	if func_ltwrapper_script_p "$wrapper"; then
+	  notinst_deplibs=
+	  relink_command=
+
+	  func_source "$wrapper"
+
+	  # Check the variables that should have been set.
+	  test -z "$generated_by_libtool_version" && \
+	    func_fatal_error "invalid libtool wrapper script \`$wrapper'"
+
+	  finalize=yes
+	  for lib in $notinst_deplibs; do
+	    # Check to see that each library is installed.
+	    libdir=
+	    if test -f "$lib"; then
+	      func_source "$lib"
+	    fi
+	    libfile="$libdir/"`$ECHO "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test
+	    if test -n "$libdir" && test ! -f "$libfile"; then
+	      func_warning "\`$lib' has not been installed in \`$libdir'"
+	      finalize=no
+	    fi
+	  done
+
+	  relink_command=
+	  func_source "$wrapper"
+
+	  outputname=
+	  if test "$fast_install" = no && test -n "$relink_command"; then
+	    $opt_dry_run || {
+	      if test "$finalize" = yes; then
+	        tmpdir=`func_mktempdir`
+		func_basename "$file$stripped_ext"
+		file="$func_basename_result"
+	        outputname="$tmpdir/$file"
+	        # Replace the output file specification.
+	        relink_command=`$ECHO "X$relink_command" | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g'`
+
+	        $opt_silent || {
+	          func_quote_for_expand "$relink_command"
+		  eval "func_echo $func_quote_for_expand_result"
+	        }
+	        if eval "$relink_command"; then :
+	          else
+		  func_error "error: relink \`$file' with the above command before installing it"
+		  $opt_dry_run || ${RM}r "$tmpdir"
+		  continue
+	        fi
+	        file="$outputname"
+	      else
+	        func_warning "cannot relink \`$file'"
+	      fi
+	    }
+	  else
+	    # Install the binary that we compiled earlier.
+	    file=`$ECHO "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"`
+	  fi
+	fi
+
+	# remove .exe since cygwin /usr/bin/install will append another
+	# one anyway
+	case $install_prog,$host in
+	*/usr/bin/install*,*cygwin*)
+	  case $file:$destfile in
+	  *.exe:*.exe)
+	    # this is ok
+	    ;;
+	  *.exe:*)
+	    destfile=$destfile.exe
+	    ;;
+	  *:*.exe)
+	    func_stripname '' '.exe' "$destfile"
+	    destfile=$func_stripname_result
+	    ;;
+	  esac
+	  ;;
+	esac
+	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
+	$opt_dry_run || if test -n "$outputname"; then
+	  ${RM}r "$tmpdir"
+	fi
+	;;
+      esac
+    done
+
+    for file in $staticlibs; do
+      func_basename "$file"
+      name="$func_basename_result"
+
+      # Set up the ranlib parameters.
+      oldlib="$destdir/$name"
+
+      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
+
+      if test -n "$stripme" && test -n "$old_striplib"; then
+	func_show_eval "$old_striplib $oldlib" 'exit $?'
+      fi
+
+      # Do each command in the postinstall commands.
+      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
+    done
+
+    test -n "$future_libdirs" && \
+      func_warning "remember to run \`$progname --finish$future_libdirs'"
+
+    if test -n "$current_libdirs"; then
+      # Maybe just do a dry run.
+      $opt_dry_run && current_libdirs=" -n$current_libdirs"
+      exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs'
+    else
+      exit $EXIT_SUCCESS
+    fi
+}
+
+test "$mode" = install && func_mode_install ${1+"$@"}
+
+
+# func_generate_dlsyms outputname originator pic_p
+# Extract symbols from dlprefiles and create ${outputname}S.o with
+# a dlpreopen symbol table.
+func_generate_dlsyms ()
+{
+    $opt_debug
+    my_outputname="$1"
+    my_originator="$2"
+    my_pic_p="${3-no}"
+    my_prefix=`$ECHO "$my_originator" | sed 's%[^a-zA-Z0-9]%_%g'`
+    my_dlsyms=
+
+    if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
+      if test -n "$NM" && test -n "$global_symbol_pipe"; then
+	my_dlsyms="${my_outputname}S.c"
+      else
+	func_error "not configured to extract global symbols from dlpreopened files"
+      fi
+    fi
+
+    if test -n "$my_dlsyms"; then
+      case $my_dlsyms in
+      "") ;;
+      *.c)
+	# Discover the nlist of each of the dlfiles.
+	nlist="$output_objdir/${my_outputname}.nm"
+
+	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
+
+	# Parse the name list into a source file.
+	func_verbose "creating $output_objdir/$my_dlsyms"
+
+	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
+/* $my_dlsyms - symbol resolution table for \`$my_outputname' dlsym emulation. */
+/* Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION */
+
+#ifdef __cplusplus
+extern \"C\" {
+#endif
+
+/* External symbol declarations for the compiler. */\
+"
+
+	if test "$dlself" = yes; then
+	  func_verbose "generating symbol list for \`$output'"
+
+	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
+
+	  # Add our own program objects to the symbol list.
+	  progfiles=`$ECHO "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+	  for progfile in $progfiles; do
+	    func_verbose "extracting global C symbols from \`$progfile'"
+	    $opt_dry_run || eval "$NM $progfile | $global_symbol_pipe >> '$nlist'"
+	  done
+
+	  if test -n "$exclude_expsyms"; then
+	    $opt_dry_run || {
+	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
+	      eval '$MV "$nlist"T "$nlist"'
+	    }
+	  fi
+
+	  if test -n "$export_symbols_regex"; then
+	    $opt_dry_run || {
+	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
+	      eval '$MV "$nlist"T "$nlist"'
+	    }
+	  fi
+
+	  # Prepare the list of exported symbols
+	  if test -z "$export_symbols"; then
+	    export_symbols="$output_objdir/$outputname.exp"
+	    $opt_dry_run || {
+	      $RM $export_symbols
+	      eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
+	      case $host in
+	      *cygwin* | *mingw* | *cegcc* )
+                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
+                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
+	        ;;
+	      esac
+	    }
+	  else
+	    $opt_dry_run || {
+	      eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
+	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
+	      eval '$MV "$nlist"T "$nlist"'
+	      case $host in
+	        *cygwin | *mingw* | *cegcc* )
+	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
+	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
+	          ;;
+	      esac
+	    }
+	  fi
+	fi
+
+	for dlprefile in $dlprefiles; do
+	  func_verbose "extracting global C symbols from \`$dlprefile'"
+	  func_basename "$dlprefile"
+	  name="$func_basename_result"
+	  $opt_dry_run || {
+	    eval '$ECHO ": $name " >> "$nlist"'
+	    eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe >> '$nlist'"
+	  }
+	done
+
+	$opt_dry_run || {
+	  # Make sure we have at least an empty file.
+	  test -f "$nlist" || : > "$nlist"
+
+	  if test -n "$exclude_expsyms"; then
+	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
+	    $MV "$nlist"T "$nlist"
+	  fi
+
+	  # Try sorting and uniquifying the output.
+	  if $GREP -v "^: " < "$nlist" |
+	      if sort -k 3 </dev/null >/dev/null 2>&1; then
+		sort -k 3
+	      else
+		sort +2
+	      fi |
+	      uniq > "$nlist"S; then
+	    :
+	  else
+	    $GREP -v "^: " < "$nlist" > "$nlist"S
+	  fi
+
+	  if test -f "$nlist"S; then
+	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
+	  else
+	    $ECHO '/* NONE */' >> "$output_objdir/$my_dlsyms"
+	  fi
+
+	  $ECHO >> "$output_objdir/$my_dlsyms" "\
+
+/* The mapping between symbol names and symbols.  */
+typedef struct {
+  const char *name;
+  void *address;
+} lt_dlsymlist;
+"
+	  case $host in
+	  *cygwin* | *mingw* | *cegcc* )
+	    $ECHO >> "$output_objdir/$my_dlsyms" "\
+/* DATA imports from DLLs on WIN32 con't be const, because
+   runtime relocations are performed -- see ld's documentation
+   on pseudo-relocs.  */"
+	    lt_dlsym_const= ;;
+	  *osf5*)
+	    echo >> "$output_objdir/$my_dlsyms" "\
+/* This system does not cope well with relocations in const data */"
+	    lt_dlsym_const= ;;
+	  *)
+	    lt_dlsym_const=const ;;
+	  esac
+
+	  $ECHO >> "$output_objdir/$my_dlsyms" "\
+extern $lt_dlsym_const lt_dlsymlist
+lt_${my_prefix}_LTX_preloaded_symbols[];
+$lt_dlsym_const lt_dlsymlist
+lt_${my_prefix}_LTX_preloaded_symbols[] =
+{\
+  { \"$my_originator\", (void *) 0 },"
+
+	  case $need_lib_prefix in
+	  no)
+	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
+	    ;;
+	  *)
+	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
+	    ;;
+	  esac
+	  $ECHO >> "$output_objdir/$my_dlsyms" "\
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt_${my_prefix}_LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif\
+"
+	} # !$opt_dry_run
+
+	pic_flag_for_symtable=
+	case "$compile_command " in
+	*" -static "*) ;;
+	*)
+	  case $host in
+	  # compiling the symbol table file with pic_flag works around
+	  # a FreeBSD bug that causes programs to crash when -lm is
+	  # linked before any other PIC object.  But we must not use
+	  # pic_flag when linking with -static.  The problem exists in
+	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
+	  *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
+	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
+	  *-*-hpux*)
+	    pic_flag_for_symtable=" $pic_flag"  ;;
+	  *)
+	    if test "X$my_pic_p" != Xno; then
+	      pic_flag_for_symtable=" $pic_flag"
+	    fi
+	    ;;
+	  esac
+	  ;;
+	esac
+	symtab_cflags=
+	for arg in $LTCFLAGS; do
+	  case $arg in
+	  -pie | -fpie | -fPIE) ;;
+	  *) symtab_cflags="$symtab_cflags $arg" ;;
+	  esac
+	done
+
+	# Now compile the dynamic symbol file.
+	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
+
+	# Clean up the generated files.
+	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T"'
+
+	# Transform the symbol file into the correct name.
+	symfileobj="$output_objdir/${my_outputname}S.$objext"
+	case $host in
+	*cygwin* | *mingw* | *cegcc* )
+	  if test -f "$output_objdir/$my_outputname.def"; then
+	    compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
+	    finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
+	  else
+	    compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+	    finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+	  fi
+	  ;;
+	*)
+	  compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+	  finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+	  ;;
+	esac
+	;;
+      *)
+	func_fatal_error "unknown suffix for \`$my_dlsyms'"
+	;;
+      esac
+    else
+      # We keep going just in case the user didn't refer to
+      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
+      # really was required.
+
+      # Nullify the symbol file.
+      compile_command=`$ECHO "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"`
+      finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"`
+    fi
+}
+
+# func_win32_libid arg
+# return the library type of file 'arg'
+#
+# Need a lot of goo to handle *both* DLLs and import libs
+# Has to be a shell function in order to 'eat' the argument
+# that is supplied when $file_magic_command is called.
+func_win32_libid ()
+{
+  $opt_debug
+  win32_libid_type="unknown"
+  win32_fileres=`file -L $1 2>/dev/null`
+  case $win32_fileres in
+  *ar\ archive\ import\ library*) # definitely import
+    win32_libid_type="x86 archive import"
+    ;;
+  *ar\ archive*) # could be an import, or static
+    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
+       $EGREP 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then
+      win32_nmres=`eval $NM -f posix -A $1 |
+	$SED -n -e '
+	    1,100{
+		/ I /{
+		    s,.*,import,
+		    p
+		    q
+		}
+	    }'`
+      case $win32_nmres in
+      import*)  win32_libid_type="x86 archive import";;
+      *)        win32_libid_type="x86 archive static";;
+      esac
+    fi
+    ;;
+  *DLL*)
+    win32_libid_type="x86 DLL"
+    ;;
+  *executable*) # but shell scripts are "executable" too...
+    case $win32_fileres in
+    *MS\ Windows\ PE\ Intel*)
+      win32_libid_type="x86 DLL"
+      ;;
+    esac
+    ;;
+  esac
+  $ECHO "$win32_libid_type"
+}
+
+
+
+# func_extract_an_archive dir oldlib
+func_extract_an_archive ()
+{
+    $opt_debug
+    f_ex_an_ar_dir="$1"; shift
+    f_ex_an_ar_oldlib="$1"
+    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" 'exit $?'
+    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
+     :
+    else
+      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
+    fi
+}
+
+
+# func_extract_archives gentop oldlib ...
+func_extract_archives ()
+{
+    $opt_debug
+    my_gentop="$1"; shift
+    my_oldlibs=${1+"$@"}
+    my_oldobjs=""
+    my_xlib=""
+    my_xabs=""
+    my_xdir=""
+
+    for my_xlib in $my_oldlibs; do
+      # Extract the objects.
+      case $my_xlib in
+	[\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;;
+	*) my_xabs=`pwd`"/$my_xlib" ;;
+      esac
+      func_basename "$my_xlib"
+      my_xlib="$func_basename_result"
+      my_xlib_u=$my_xlib
+      while :; do
+        case " $extracted_archives " in
+	*" $my_xlib_u "*)
+	  func_arith $extracted_serial + 1
+	  extracted_serial=$func_arith_result
+	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
+	*) break ;;
+	esac
+      done
+      extracted_archives="$extracted_archives $my_xlib_u"
+      my_xdir="$my_gentop/$my_xlib_u"
+
+      func_mkdir_p "$my_xdir"
+
+      case $host in
+      *-darwin*)
+	func_verbose "Extracting $my_xabs"
+	# Do not bother doing anything if just a dry run
+	$opt_dry_run || {
+	  darwin_orig_dir=`pwd`
+	  cd $my_xdir || exit $?
+	  darwin_archive=$my_xabs
+	  darwin_curdir=`pwd`
+	  darwin_base_archive=`basename "$darwin_archive"`
+	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
+	  if test -n "$darwin_arches"; then
+	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
+	    darwin_arch=
+	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
+	    for darwin_arch in  $darwin_arches ; do
+	      func_mkdir_p "unfat-$$/${darwin_base_archive}-${darwin_arch}"
+	      $LIPO -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}"
+	      cd "unfat-$$/${darwin_base_archive}-${darwin_arch}"
+	      func_extract_an_archive "`pwd`" "${darwin_base_archive}"
+	      cd "$darwin_curdir"
+	      $RM "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}"
+	    done # $darwin_arches
+            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
+	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$basename" | sort -u`
+	    darwin_file=
+	    darwin_files=
+	    for darwin_file in $darwin_filelist; do
+	      darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP`
+	      $LIPO -create -output "$darwin_file" $darwin_files
+	    done # $darwin_filelist
+	    $RM -rf unfat-$$
+	    cd "$darwin_orig_dir"
+	  else
+	    cd $darwin_orig_dir
+	    func_extract_an_archive "$my_xdir" "$my_xabs"
+	  fi # $darwin_arches
+	} # !$opt_dry_run
+	;;
+      *)
+        func_extract_an_archive "$my_xdir" "$my_xabs"
+	;;
+      esac
+      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP`
+    done
+
+    func_extract_archives_result="$my_oldobjs"
+}
+
+
+
+# func_emit_wrapper_part1 [arg=no]
+#
+# Emit the first part of a libtool wrapper script on stdout.
+# For more information, see the description associated with
+# func_emit_wrapper(), below.
+func_emit_wrapper_part1 ()
+{
+	func_emit_wrapper_part1_arg1=no
+	if test -n "$1" ; then
+	  func_emit_wrapper_part1_arg1=$1
+	fi
+
+	$ECHO "\
+#! $SHELL
+
+# $output - temporary wrapper script for $objdir/$outputname
+# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+#
+# The $output program cannot be directly executed until all the libtool
+# libraries that it depends on are installed.
+#
+# This wrapper script should never be moved out of the build directory.
+# If it is, it will not operate correctly.
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+Xsed='${SED} -e 1s/^X//'
+sed_quote_subst='$sed_quote_subst'
+
+# Be Bourne compatible
+if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else
+  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+relink_command=\"$relink_command\"
+
+# This environment variable determines our operation mode.
+if test \"\$libtool_install_magic\" = \"$magic\"; then
+  # install mode needs the following variables:
+  generated_by_libtool_version='$macro_version'
+  notinst_deplibs='$notinst_deplibs'
+else
+  # When we are sourced in execute mode, \$file and \$ECHO are already set.
+  if test \"\$libtool_execute_magic\" != \"$magic\"; then
+    ECHO=\"$qecho\"
+    file=\"\$0\"
+    # Make sure echo works.
+    if test \"X\$1\" = X--no-reexec; then
+      # Discard the --no-reexec flag, and continue.
+      shift
+    elif test \"X\`{ \$ECHO '\t'; } 2>/dev/null\`\" = 'X\t'; then
+      # Yippee, \$ECHO works!
+      :
+    else
+      # Restart under the correct shell, and then maybe \$ECHO will work.
+      exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"}
+    fi
+  fi\
+"
+	$ECHO "\
+
+  # Find the directory that this script lives in.
+  thisdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\`
+  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
+
+  # Follow symbolic links until we get to the real thisdir.
+  file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\`
+  while test -n \"\$file\"; do
+    destdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\`
+
+    # If there was a directory component, then change thisdir.
+    if test \"x\$destdir\" != \"x\$file\"; then
+      case \"\$destdir\" in
+      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
+      *) thisdir=\"\$thisdir/\$destdir\" ;;
+      esac
+    fi
+
+    file=\`\$ECHO \"X\$file\" | \$Xsed -e 's%^.*/%%'\`
+    file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\`
+  done
+"
+}
+# end: func_emit_wrapper_part1
+
+# func_emit_wrapper_part2 [arg=no]
+#
+# Emit the second part of a libtool wrapper script on stdout.
+# For more information, see the description associated with
+# func_emit_wrapper(), below.
+func_emit_wrapper_part2 ()
+{
+	func_emit_wrapper_part2_arg1=no
+	if test -n "$1" ; then
+	  func_emit_wrapper_part2_arg1=$1
+	fi
+
+	$ECHO "\
+
+  # Usually 'no', except on cygwin/mingw when embedded into
+  # the cwrapper.
+  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_part2_arg1
+  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
+    # special case for '.'
+    if test \"\$thisdir\" = \".\"; then
+      thisdir=\`pwd\`
+    fi
+    # remove .libs from thisdir
+    case \"\$thisdir\" in
+    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"X\$thisdir\" | \$Xsed -e 's%[\\\\/][^\\\\/]*$%%'\` ;;
+    $objdir )   thisdir=. ;;
+    esac
+  fi
+
+  # Try to get the absolute directory name.
+  absdir=\`cd \"\$thisdir\" && pwd\`
+  test -n \"\$absdir\" && thisdir=\"\$absdir\"
+"
+
+	if test "$fast_install" = yes; then
+	  $ECHO "\
+  program=lt-'$outputname'$exeext
+  progdir=\"\$thisdir/$objdir\"
+
+  if test ! -f \"\$progdir/\$program\" ||
+     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\
+       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
+
+    file=\"\$\$-\$program\"
+
+    if test ! -d \"\$progdir\"; then
+      $MKDIR \"\$progdir\"
+    else
+      $RM \"\$progdir/\$file\"
+    fi"
+
+	  $ECHO "\
+
+    # relink executable if necessary
+    if test -n \"\$relink_command\"; then
+      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
+      else
+	$ECHO \"\$relink_command_output\" >&2
+	$RM \"\$progdir/\$file\"
+	exit 1
+      fi
+    fi
+
+    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
+    { $RM \"\$progdir/\$program\";
+      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
+    $RM \"\$progdir/\$file\"
+  fi"
+	else
+	  $ECHO "\
+  program='$outputname'
+  progdir=\"\$thisdir/$objdir\"
+"
+	fi
+
+	$ECHO "\
+
+  if test -f \"\$progdir/\$program\"; then"
+
+	# Export our shlibpath_var if we have one.
+	if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
+	  $ECHO "\
+    # Add our own library path to $shlibpath_var
+    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
+
+    # Some systems cannot cope with colon-terminated $shlibpath_var
+    # The second colon is a workaround for a bug in BeOS R4 sed
+    $shlibpath_var=\`\$ECHO \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\`
+
+    export $shlibpath_var
+"
+	fi
+
+	# fixup the dll searchpath if we need to.
+	if test -n "$dllsearchpath"; then
+	  $ECHO "\
+    # Add the dll search path components to the executable PATH
+    PATH=$dllsearchpath:\$PATH
+"
+	fi
+
+	$ECHO "\
+    if test \"\$libtool_execute_magic\" != \"$magic\"; then
+      # Run the actual program with our arguments.
+"
+	case $host in
+	# Backslashes separate directories on plain windows
+	*-*-mingw | *-*-os2* | *-cegcc*)
+	  $ECHO "\
+      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
+"
+	  ;;
+
+	*)
+	  $ECHO "\
+      exec \"\$progdir/\$program\" \${1+\"\$@\"}
+"
+	  ;;
+	esac
+	$ECHO "\
+      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
+      exit 1
+    fi
+  else
+    # The program doesn't exist.
+    \$ECHO \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2
+    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
+    $ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
+    exit 1
+  fi
+fi\
+"
+}
+# end: func_emit_wrapper_part2
+
+
+# func_emit_wrapper [arg=no]
+#
+# Emit a libtool wrapper script on stdout.
+# Don't directly open a file because we may want to
+# incorporate the script contents within a cygwin/mingw
+# wrapper executable.  Must ONLY be called from within
+# func_mode_link because it depends on a number of variables
+# set therein.
+#
+# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
+# variable will take.  If 'yes', then the emitted script
+# will assume that the directory in which it is stored is
+# the $objdir directory.  This is a cygwin/mingw-specific
+# behavior.
+func_emit_wrapper ()
+{
+	func_emit_wrapper_arg1=no
+	if test -n "$1" ; then
+	  func_emit_wrapper_arg1=$1
+	fi
+
+	# split this up so that func_emit_cwrapperexe_src
+	# can call each part independently.
+	func_emit_wrapper_part1 "${func_emit_wrapper_arg1}"
+	func_emit_wrapper_part2 "${func_emit_wrapper_arg1}"
+}
+
+
+# func_to_host_path arg
+#
+# Convert paths to host format when used with build tools.
+# Intended for use with "native" mingw (where libtool itself
+# is running under the msys shell), or in the following cross-
+# build environments:
+#    $build          $host
+#    mingw (msys)    mingw  [e.g. native]
+#    cygwin          mingw
+#    *nix + wine     mingw
+# where wine is equipped with the `winepath' executable.
+# In the native mingw case, the (msys) shell automatically
+# converts paths for any non-msys applications it launches,
+# but that facility isn't available from inside the cwrapper.
+# Similar accommodations are necessary for $host mingw and
+# $build cygwin.  Calling this function does no harm for other
+# $host/$build combinations not listed above.
+#
+# ARG is the path (on $build) that should be converted to
+# the proper representation for $host. The result is stored
+# in $func_to_host_path_result.
+func_to_host_path ()
+{
+  func_to_host_path_result="$1"
+  if test -n "$1" ; then
+    case $host in
+      *mingw* )
+        lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
+        case $build in
+          *mingw* ) # actually, msys
+            # awkward: cmd appends spaces to result
+            lt_sed_strip_trailing_spaces="s/[ ]*\$//"
+            func_to_host_path_tmp1=`( cmd //c echo "$1" |\
+              $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""`
+            func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
+              $SED -e "$lt_sed_naive_backslashify"`
+            ;;
+          *cygwin* )
+            func_to_host_path_tmp1=`cygpath -w "$1"`
+            func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
+              $SED -e "$lt_sed_naive_backslashify"`
+            ;;
+          * )
+            # Unfortunately, winepath does not exit with a non-zero
+            # error code, so we are forced to check the contents of
+            # stdout. On the other hand, if the command is not
+            # found, the shell will set an exit code of 127 and print
+            # *an error message* to stdout. So we must check for both
+            # error code of zero AND non-empty stdout, which explains
+            # the odd construction:
+            func_to_host_path_tmp1=`winepath -w "$1" 2>/dev/null`
+            if test "$?" -eq 0 && test -n "${func_to_host_path_tmp1}"; then
+              func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
+                $SED -e "$lt_sed_naive_backslashify"`
+            else
+              # Allow warning below.
+              func_to_host_path_result=""
+            fi
+            ;;
+        esac
+        if test -z "$func_to_host_path_result" ; then
+          func_error "Could not determine host path corresponding to"
+          func_error "  '$1'"
+          func_error "Continuing, but uninstalled executables may not work."
+          # Fallback:
+          func_to_host_path_result="$1"
+        fi
+        ;;
+    esac
+  fi
+}
+# end: func_to_host_path
+
+# func_to_host_pathlist arg
+#
+# Convert pathlists to host format when used with build tools.
+# See func_to_host_path(), above. This function supports the
+# following $build/$host combinations (but does no harm for
+# combinations not listed here):
+#    $build          $host
+#    mingw (msys)    mingw  [e.g. native]
+#    cygwin          mingw
+#    *nix + wine     mingw
+#
+# Path separators are also converted from $build format to
+# $host format. If ARG begins or ends with a path separator
+# character, it is preserved (but converted to $host format)
+# on output.
+#
+# ARG is a pathlist (on $build) that should be converted to
+# the proper representation on $host. The result is stored
+# in $func_to_host_pathlist_result.
+func_to_host_pathlist ()
+{
+  func_to_host_pathlist_result="$1"
+  if test -n "$1" ; then
+    case $host in
+      *mingw* )
+        lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
+        # Remove leading and trailing path separator characters from
+        # ARG. msys behavior is inconsistent here, cygpath turns them
+        # into '.;' and ';.', and winepath ignores them completely.
+        func_to_host_pathlist_tmp2="$1"
+        # Once set for this call, this variable should not be
+        # reassigned. It is used in tha fallback case.
+        func_to_host_pathlist_tmp1=`echo "$func_to_host_pathlist_tmp2" |\
+          $SED -e 's|^:*||' -e 's|:*$||'`
+        case $build in
+          *mingw* ) # Actually, msys.
+            # Awkward: cmd appends spaces to result.
+            lt_sed_strip_trailing_spaces="s/[ ]*\$//"
+            func_to_host_pathlist_tmp2=`( cmd //c echo "$func_to_host_pathlist_tmp1" |\
+              $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""`
+            func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\
+              $SED -e "$lt_sed_naive_backslashify"`
+            ;;
+          *cygwin* )
+            func_to_host_pathlist_tmp2=`cygpath -w -p "$func_to_host_pathlist_tmp1"`
+            func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\
+              $SED -e "$lt_sed_naive_backslashify"`
+            ;;
+          * )
+            # unfortunately, winepath doesn't convert pathlists
+            func_to_host_pathlist_result=""
+            func_to_host_pathlist_oldIFS=$IFS
+            IFS=:
+            for func_to_host_pathlist_f in $func_to_host_pathlist_tmp1 ; do
+              IFS=$func_to_host_pathlist_oldIFS
+              if test -n "$func_to_host_pathlist_f" ; then
+                func_to_host_path "$func_to_host_pathlist_f"
+                if test -n "$func_to_host_path_result" ; then
+                  if test -z "$func_to_host_pathlist_result" ; then
+                    func_to_host_pathlist_result="$func_to_host_path_result"
+                  else
+                    func_to_host_pathlist_result="$func_to_host_pathlist_result;$func_to_host_path_result"
+                  fi
+                fi
+              fi
+              IFS=:
+            done
+            IFS=$func_to_host_pathlist_oldIFS
+            ;;
+        esac
+        if test -z "$func_to_host_pathlist_result" ; then
+          func_error "Could not determine the host path(s) corresponding to"
+          func_error "  '$1'"
+          func_error "Continuing, but uninstalled executables may not work."
+          # Fallback. This may break if $1 contains DOS-style drive
+          # specifications. The fix is not to complicate the expression
+          # below, but for the user to provide a working wine installation
+          # with winepath so that path translation in the cross-to-mingw
+          # case works properly.
+          lt_replace_pathsep_nix_to_dos="s|:|;|g"
+          func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp1" |\
+            $SED -e "$lt_replace_pathsep_nix_to_dos"`
+        fi
+        # Now, add the leading and trailing path separators back
+        case "$1" in
+          :* ) func_to_host_pathlist_result=";$func_to_host_pathlist_result"
+            ;;
+        esac
+        case "$1" in
+          *: ) func_to_host_pathlist_result="$func_to_host_pathlist_result;"
+            ;;
+        esac
+        ;;
+    esac
+  fi
+}
+# end: func_to_host_pathlist
+
+# func_emit_cwrapperexe_src
+# emit the source code for a wrapper executable on stdout
+# Must ONLY be called from within func_mode_link because
+# it depends on a number of variable set therein.
+func_emit_cwrapperexe_src ()
+{
+	cat <<EOF
+
+/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
+   Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+
+   The $output program cannot be directly executed until all the libtool
+   libraries that it depends on are installed.
+
+   This wrapper executable should never be moved out of the build directory.
+   If it is, it will not operate correctly.
+
+   Currently, it simply execs the wrapper *script* "$SHELL $output",
+   but could eventually absorb all of the scripts functionality and
+   exec $objdir/$outputname directly.
+*/
+EOF
+	    cat <<"EOF"
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef _MSC_VER
+# include <direct.h>
+# include <process.h>
+# include <io.h>
+# define setmode _setmode
+#else
+# include <unistd.h>
+# include <stdint.h>
+# ifdef __CYGWIN__
+#  include <io.h>
+#  define HAVE_SETENV
+#  ifdef __STRICT_ANSI__
+char *realpath (const char *, char *);
+int putenv (char *);
+int setenv (const char *, const char *, int);
+#  endif
+# endif
+#endif
+#include <malloc.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#if defined(PATH_MAX)
+# define LT_PATHMAX PATH_MAX
+#elif defined(MAXPATHLEN)
+# define LT_PATHMAX MAXPATHLEN
+#else
+# define LT_PATHMAX 1024
+#endif
+
+#ifndef S_IXOTH
+# define S_IXOTH 0
+#endif
+#ifndef S_IXGRP
+# define S_IXGRP 0
+#endif
+
+#ifdef _MSC_VER
+# define S_IXUSR _S_IEXEC
+# define stat _stat
+# ifndef _INTPTR_T_DEFINED
+#  define intptr_t int
+# endif
+#endif
+
+#ifndef DIR_SEPARATOR
+# define DIR_SEPARATOR '/'
+# define PATH_SEPARATOR ':'
+#endif
+
+#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
+  defined (__OS2__)
+# define HAVE_DOS_BASED_FILE_SYSTEM
+# define FOPEN_WB "wb"
+# ifndef DIR_SEPARATOR_2
+#  define DIR_SEPARATOR_2 '\\'
+# endif
+# ifndef PATH_SEPARATOR_2
+#  define PATH_SEPARATOR_2 ';'
+# endif
+#endif
+
+#ifndef DIR_SEPARATOR_2
+# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+#else /* DIR_SEPARATOR_2 */
+# define IS_DIR_SEPARATOR(ch) \
+	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+#endif /* DIR_SEPARATOR_2 */
+
+#ifndef PATH_SEPARATOR_2
+# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
+#else /* PATH_SEPARATOR_2 */
+# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
+#endif /* PATH_SEPARATOR_2 */
+
+#ifdef __CYGWIN__
+# define FOPEN_WB "wb"
+#endif
+
+#ifndef FOPEN_WB
+# define FOPEN_WB "w"
+#endif
+#ifndef _O_BINARY
+# define _O_BINARY 0
+#endif
+
+#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
+#define XFREE(stale) do { \
+  if (stale) { free ((void *) stale); stale = 0; } \
+} while (0)
+
+#undef LTWRAPPER_DEBUGPRINTF
+#if defined DEBUGWRAPPER
+# define LTWRAPPER_DEBUGPRINTF(args) ltwrapper_debugprintf args
+static void
+ltwrapper_debugprintf (const char *fmt, ...)
+{
+    va_list args;
+    va_start (args, fmt);
+    (void) vfprintf (stderr, fmt, args);
+    va_end (args);
+}
+#else
+# define LTWRAPPER_DEBUGPRINTF(args)
+#endif
+
+const char *program_name = NULL;
+
+void *xmalloc (size_t num);
+char *xstrdup (const char *string);
+const char *base_name (const char *name);
+char *find_executable (const char *wrapper);
+char *chase_symlinks (const char *pathspec);
+int make_executable (const char *path);
+int check_executable (const char *path);
+char *strendzap (char *str, const char *pat);
+void lt_fatal (const char *message, ...);
+void lt_setenv (const char *name, const char *value);
+char *lt_extend_str (const char *orig_value, const char *add, int to_end);
+void lt_opt_process_env_set (const char *arg);
+void lt_opt_process_env_prepend (const char *arg);
+void lt_opt_process_env_append (const char *arg);
+int lt_split_name_value (const char *arg, char** name, char** value);
+void lt_update_exe_path (const char *name, const char *value);
+void lt_update_lib_path (const char *name, const char *value);
+
+static const char *script_text_part1 =
+EOF
+
+	    func_emit_wrapper_part1 yes |
+	        $SED -e 's/\([\\"]\)/\\\1/g' \
+	             -e 's/^/  "/' -e 's/$/\\n"/'
+	    echo ";"
+	    cat <<EOF
+
+static const char *script_text_part2 =
+EOF
+	    func_emit_wrapper_part2 yes |
+	        $SED -e 's/\([\\"]\)/\\\1/g' \
+	             -e 's/^/  "/' -e 's/$/\\n"/'
+	    echo ";"
+
+	    cat <<EOF
+const char * MAGIC_EXE = "$magic_exe";
+const char * LIB_PATH_VARNAME = "$shlibpath_var";
+EOF
+
+	    if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
+              func_to_host_pathlist "$temp_rpath"
+	      cat <<EOF
+const char * LIB_PATH_VALUE   = "$func_to_host_pathlist_result";
+EOF
+	    else
+	      cat <<"EOF"
+const char * LIB_PATH_VALUE   = "";
+EOF
+	    fi
+
+	    if test -n "$dllsearchpath"; then
+              func_to_host_pathlist "$dllsearchpath:"
+	      cat <<EOF
+const char * EXE_PATH_VARNAME = "PATH";
+const char * EXE_PATH_VALUE   = "$func_to_host_pathlist_result";
+EOF
+	    else
+	      cat <<"EOF"
+const char * EXE_PATH_VARNAME = "";
+const char * EXE_PATH_VALUE   = "";
+EOF
+	    fi
+
+	    if test "$fast_install" = yes; then
+	      cat <<EOF
+const char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
+EOF
+	    else
+	      cat <<EOF
+const char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
+EOF
+	    fi
+
+
+	    cat <<"EOF"
+
+#define LTWRAPPER_OPTION_PREFIX         "--lt-"
+#define LTWRAPPER_OPTION_PREFIX_LENGTH  5
+
+static const size_t opt_prefix_len         = LTWRAPPER_OPTION_PREFIX_LENGTH;
+static const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
+
+static const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
+
+static const size_t env_set_opt_len     = LTWRAPPER_OPTION_PREFIX_LENGTH + 7;
+static const char *env_set_opt          = LTWRAPPER_OPTION_PREFIX "env-set";
+  /* argument is putenv-style "foo=bar", value of foo is set to bar */
+
+static const size_t env_prepend_opt_len = LTWRAPPER_OPTION_PREFIX_LENGTH + 11;
+static const char *env_prepend_opt      = LTWRAPPER_OPTION_PREFIX "env-prepend";
+  /* argument is putenv-style "foo=bar", new value of foo is bar${foo} */
+
+static const size_t env_append_opt_len  = LTWRAPPER_OPTION_PREFIX_LENGTH + 10;
+static const char *env_append_opt       = LTWRAPPER_OPTION_PREFIX "env-append";
+  /* argument is putenv-style "foo=bar", new value of foo is ${foo}bar */
+
+int
+main (int argc, char *argv[])
+{
+  char **newargz;
+  int  newargc;
+  char *tmp_pathspec;
+  char *actual_cwrapper_path;
+  char *actual_cwrapper_name;
+  char *target_name;
+  char *lt_argv_zero;
+  intptr_t rval = 127;
+
+  int i;
+
+  program_name = (char *) xstrdup (base_name (argv[0]));
+  LTWRAPPER_DEBUGPRINTF (("(main) argv[0]      : %s\n", argv[0]));
+  LTWRAPPER_DEBUGPRINTF (("(main) program_name : %s\n", program_name));
+
+  /* very simple arg parsing; don't want to rely on getopt */
+  for (i = 1; i < argc; i++)
+    {
+      if (strcmp (argv[i], dumpscript_opt) == 0)
+	{
+EOF
+	    case "$host" in
+	      *mingw* | *cygwin* )
+		# make stdout use "unix" line endings
+		echo "          setmode(1,_O_BINARY);"
+		;;
+	      esac
+
+	    cat <<"EOF"
+	  printf ("%s", script_text_part1);
+	  printf ("%s", script_text_part2);
+	  return 0;
+	}
+    }
+
+  newargz = XMALLOC (char *, argc + 1);
+  tmp_pathspec = find_executable (argv[0]);
+  if (tmp_pathspec == NULL)
+    lt_fatal ("Couldn't find %s", argv[0]);
+  LTWRAPPER_DEBUGPRINTF (("(main) found exe (before symlink chase) at : %s\n",
+			  tmp_pathspec));
+
+  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
+  LTWRAPPER_DEBUGPRINTF (("(main) found exe (after symlink chase) at : %s\n",
+			  actual_cwrapper_path));
+  XFREE (tmp_pathspec);
+
+  actual_cwrapper_name = xstrdup( base_name (actual_cwrapper_path));
+  strendzap (actual_cwrapper_path, actual_cwrapper_name);
+
+  /* wrapper name transforms */
+  strendzap (actual_cwrapper_name, ".exe");
+  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
+  XFREE (actual_cwrapper_name);
+  actual_cwrapper_name = tmp_pathspec;
+  tmp_pathspec = 0;
+
+  /* target_name transforms -- use actual target program name; might have lt- prefix */
+  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
+  strendzap (target_name, ".exe");
+  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
+  XFREE (target_name);
+  target_name = tmp_pathspec;
+  tmp_pathspec = 0;
+
+  LTWRAPPER_DEBUGPRINTF (("(main) libtool target name: %s\n",
+			  target_name));
+EOF
+
+	    cat <<EOF
+  newargz[0] =
+    XMALLOC (char, (strlen (actual_cwrapper_path) +
+		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
+  strcpy (newargz[0], actual_cwrapper_path);
+  strcat (newargz[0], "$objdir");
+  strcat (newargz[0], "/");
+EOF
+
+	    cat <<"EOF"
+  /* stop here, and copy so we don't have to do this twice */
+  tmp_pathspec = xstrdup (newargz[0]);
+
+  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
+  strcat (newargz[0], actual_cwrapper_name);
+
+  /* DO want the lt- prefix here if it exists, so use target_name */
+  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
+  XFREE (tmp_pathspec);
+  tmp_pathspec = NULL;
+EOF
+
+	    case $host_os in
+	      mingw*)
+	    cat <<"EOF"
+  {
+    char* p;
+    while ((p = strchr (newargz[0], '\\')) != NULL)
+      {
+	*p = '/';
+      }
+    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
+      {
+	*p = '/';
+      }
+  }
+EOF
+	    ;;
+	    esac
+
+	    cat <<"EOF"
+  XFREE (target_name);
+  XFREE (actual_cwrapper_path);
+  XFREE (actual_cwrapper_name);
+
+  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
+  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
+  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
+  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
+
+  newargc=0;
+  for (i = 1; i < argc; i++)
+    {
+      if (strncmp (argv[i], env_set_opt, env_set_opt_len) == 0)
+        {
+          if (argv[i][env_set_opt_len] == '=')
+            {
+              const char *p = argv[i] + env_set_opt_len + 1;
+              lt_opt_process_env_set (p);
+            }
+          else if (argv[i][env_set_opt_len] == '\0' && i + 1 < argc)
+            {
+              lt_opt_process_env_set (argv[++i]); /* don't copy */
+            }
+          else
+            lt_fatal ("%s missing required argument", env_set_opt);
+          continue;
+        }
+      if (strncmp (argv[i], env_prepend_opt, env_prepend_opt_len) == 0)
+        {
+          if (argv[i][env_prepend_opt_len] == '=')
+            {
+              const char *p = argv[i] + env_prepend_opt_len + 1;
+              lt_opt_process_env_prepend (p);
+            }
+          else if (argv[i][env_prepend_opt_len] == '\0' && i + 1 < argc)
+            {
+              lt_opt_process_env_prepend (argv[++i]); /* don't copy */
+            }
+          else
+            lt_fatal ("%s missing required argument", env_prepend_opt);
+          continue;
+        }
+      if (strncmp (argv[i], env_append_opt, env_append_opt_len) == 0)
+        {
+          if (argv[i][env_append_opt_len] == '=')
+            {
+              const char *p = argv[i] + env_append_opt_len + 1;
+              lt_opt_process_env_append (p);
+            }
+          else if (argv[i][env_append_opt_len] == '\0' && i + 1 < argc)
+            {
+              lt_opt_process_env_append (argv[++i]); /* don't copy */
+            }
+          else
+            lt_fatal ("%s missing required argument", env_append_opt);
+          continue;
+        }
+      if (strncmp (argv[i], ltwrapper_option_prefix, opt_prefix_len) == 0)
+        {
+          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
+             namespace, but it is not one of the ones we know about and
+             have already dealt with, above (inluding dump-script), then
+             report an error. Otherwise, targets might begin to believe
+             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
+             namespace. The first time any user complains about this, we'll
+             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
+             or a configure.ac-settable value.
+           */
+          lt_fatal ("Unrecognized option in %s namespace: '%s'",
+                    ltwrapper_option_prefix, argv[i]);
+        }
+      /* otherwise ... */
+      newargz[++newargc] = xstrdup (argv[i]);
+    }
+  newargz[++newargc] = NULL;
+
+  LTWRAPPER_DEBUGPRINTF     (("(main) lt_argv_zero : %s\n", (lt_argv_zero ? lt_argv_zero : "<NULL>")));
+  for (i = 0; i < newargc; i++)
+    {
+      LTWRAPPER_DEBUGPRINTF (("(main) newargz[%d]   : %s\n", i, (newargz[i] ? newargz[i] : "<NULL>")));
+    }
+
+EOF
+
+	    case $host_os in
+	      mingw*)
+		cat <<"EOF"
+  /* execv doesn't actually work on mingw as expected on unix */
+  rval = _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
+  if (rval == -1)
+    {
+      /* failed to start process */
+      LTWRAPPER_DEBUGPRINTF (("(main) failed to launch target \"%s\": errno = %d\n", lt_argv_zero, errno));
+      return 127;
+    }
+  return rval;
+EOF
+		;;
+	      *)
+		cat <<"EOF"
+  execv (lt_argv_zero, newargz);
+  return rval; /* =127, but avoids unused variable warning */
+EOF
+		;;
+	    esac
+
+	    cat <<"EOF"
+}
+
+void *
+xmalloc (size_t num)
+{
+  void *p = (void *) malloc (num);
+  if (!p)
+    lt_fatal ("Memory exhausted");
+
+  return p;
+}
+
+char *
+xstrdup (const char *string)
+{
+  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
+			  string) : NULL;
+}
+
+const char *
+base_name (const char *name)
+{
+  const char *base;
+
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+  /* Skip over the disk name in MSDOS pathnames. */
+  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
+    name += 2;
+#endif
+
+  for (base = name; *name; name++)
+    if (IS_DIR_SEPARATOR (*name))
+      base = name + 1;
+  return base;
+}
+
+int
+check_executable (const char *path)
+{
+  struct stat st;
+
+  LTWRAPPER_DEBUGPRINTF (("(check_executable)  : %s\n",
+			  path ? (*path ? path : "EMPTY!") : "NULL!"));
+  if ((!path) || (!*path))
+    return 0;
+
+  if ((stat (path, &st) >= 0)
+      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
+    return 1;
+  else
+    return 0;
+}
+
+int
+make_executable (const char *path)
+{
+  int rval = 0;
+  struct stat st;
+
+  LTWRAPPER_DEBUGPRINTF (("(make_executable)   : %s\n",
+			  path ? (*path ? path : "EMPTY!") : "NULL!"));
+  if ((!path) || (!*path))
+    return 0;
+
+  if (stat (path, &st) >= 0)
+    {
+      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
+    }
+  return rval;
+}
+
+/* Searches for the full path of the wrapper.  Returns
+   newly allocated full path name if found, NULL otherwise
+   Does not chase symlinks, even on platforms that support them.
+*/
+char *
+find_executable (const char *wrapper)
+{
+  int has_slash = 0;
+  const char *p;
+  const char *p_next;
+  /* static buffer for getcwd */
+  char tmp[LT_PATHMAX + 1];
+  int tmp_len;
+  char *concat_name;
+
+  LTWRAPPER_DEBUGPRINTF (("(find_executable)   : %s\n",
+			  wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!"));
+
+  if ((wrapper == NULL) || (*wrapper == '\0'))
+    return NULL;
+
+  /* Absolute path? */
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
+    {
+      concat_name = xstrdup (wrapper);
+      if (check_executable (concat_name))
+	return concat_name;
+      XFREE (concat_name);
+    }
+  else
+    {
+#endif
+      if (IS_DIR_SEPARATOR (wrapper[0]))
+	{
+	  concat_name = xstrdup (wrapper);
+	  if (check_executable (concat_name))
+	    return concat_name;
+	  XFREE (concat_name);
+	}
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+    }
+#endif
+
+  for (p = wrapper; *p; p++)
+    if (*p == '/')
+      {
+	has_slash = 1;
+	break;
+      }
+  if (!has_slash)
+    {
+      /* no slashes; search PATH */
+      const char *path = getenv ("PATH");
+      if (path != NULL)
+	{
+	  for (p = path; *p; p = p_next)
+	    {
+	      const char *q;
+	      size_t p_len;
+	      for (q = p; *q; q++)
+		if (IS_PATH_SEPARATOR (*q))
+		  break;
+	      p_len = q - p;
+	      p_next = (*q == '\0' ? q : q + 1);
+	      if (p_len == 0)
+		{
+		  /* empty path: current directory */
+		  if (getcwd (tmp, LT_PATHMAX) == NULL)
+		    lt_fatal ("getcwd failed");
+		  tmp_len = strlen (tmp);
+		  concat_name =
+		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
+		  memcpy (concat_name, tmp, tmp_len);
+		  concat_name[tmp_len] = '/';
+		  strcpy (concat_name + tmp_len + 1, wrapper);
+		}
+	      else
+		{
+		  concat_name =
+		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
+		  memcpy (concat_name, p, p_len);
+		  concat_name[p_len] = '/';
+		  strcpy (concat_name + p_len + 1, wrapper);
+		}
+	      if (check_executable (concat_name))
+		return concat_name;
+	      XFREE (concat_name);
+	    }
+	}
+      /* not found in PATH; assume curdir */
+    }
+  /* Relative path | not found in path: prepend cwd */
+  if (getcwd (tmp, LT_PATHMAX) == NULL)
+    lt_fatal ("getcwd failed");
+  tmp_len = strlen (tmp);
+  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
+  memcpy (concat_name, tmp, tmp_len);
+  concat_name[tmp_len] = '/';
+  strcpy (concat_name + tmp_len + 1, wrapper);
+
+  if (check_executable (concat_name))
+    return concat_name;
+  XFREE (concat_name);
+  return NULL;
+}
+
+char *
+chase_symlinks (const char *pathspec)
+{
+#ifndef S_ISLNK
+  return xstrdup (pathspec);
+#else
+  char buf[LT_PATHMAX];
+  struct stat s;
+  char *tmp_pathspec = xstrdup (pathspec);
+  char *p;
+  int has_symlinks = 0;
+  while (strlen (tmp_pathspec) && !has_symlinks)
+    {
+      LTWRAPPER_DEBUGPRINTF (("checking path component for symlinks: %s\n",
+			      tmp_pathspec));
+      if (lstat (tmp_pathspec, &s) == 0)
+	{
+	  if (S_ISLNK (s.st_mode) != 0)
+	    {
+	      has_symlinks = 1;
+	      break;
+	    }
+
+	  /* search backwards for last DIR_SEPARATOR */
+	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
+	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
+	    p--;
+	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
+	    {
+	      /* no more DIR_SEPARATORS left */
+	      break;
+	    }
+	  *p = '\0';
+	}
+      else
+	{
+	  char *errstr = strerror (errno);
+	  lt_fatal ("Error accessing file %s (%s)", tmp_pathspec, errstr);
+	}
+    }
+  XFREE (tmp_pathspec);
+
+  if (!has_symlinks)
+    {
+      return xstrdup (pathspec);
+    }
+
+  tmp_pathspec = realpath (pathspec, buf);
+  if (tmp_pathspec == 0)
+    {
+      lt_fatal ("Could not follow symlinks for %s", pathspec);
+    }
+  return xstrdup (tmp_pathspec);
+#endif
+}
+
+char *
+strendzap (char *str, const char *pat)
+{
+  size_t len, patlen;
+
+  assert (str != NULL);
+  assert (pat != NULL);
+
+  len = strlen (str);
+  patlen = strlen (pat);
+
+  if (patlen <= len)
+    {
+      str += len - patlen;
+      if (strcmp (str, pat) == 0)
+	*str = '\0';
+    }
+  return str;
+}
+
+static void
+lt_error_core (int exit_status, const char *mode,
+	       const char *message, va_list ap)
+{
+  fprintf (stderr, "%s: %s: ", program_name, mode);
+  vfprintf (stderr, message, ap);
+  fprintf (stderr, ".\n");
+
+  if (exit_status >= 0)
+    exit (exit_status);
+}
+
+void
+lt_fatal (const char *message, ...)
+{
+  va_list ap;
+  va_start (ap, message);
+  lt_error_core (EXIT_FAILURE, "FATAL", message, ap);
+  va_end (ap);
+}
+
+void
+lt_setenv (const char *name, const char *value)
+{
+  LTWRAPPER_DEBUGPRINTF (("(lt_setenv) setting '%s' to '%s'\n",
+                          (name ? name : "<NULL>"),
+                          (value ? value : "<NULL>")));
+  {
+#ifdef HAVE_SETENV
+    /* always make a copy, for consistency with !HAVE_SETENV */
+    char *str = xstrdup (value);
+    setenv (name, str, 1);
+#else
+    int len = strlen (name) + 1 + strlen (value) + 1;
+    char *str = XMALLOC (char, len);
+    sprintf (str, "%s=%s", name, value);
+    if (putenv (str) != EXIT_SUCCESS)
+      {
+        XFREE (str);
+      }
+#endif
+  }
+}
+
+char *
+lt_extend_str (const char *orig_value, const char *add, int to_end)
+{
+  char *new_value;
+  if (orig_value && *orig_value)
+    {
+      int orig_value_len = strlen (orig_value);
+      int add_len = strlen (add);
+      new_value = XMALLOC (char, add_len + orig_value_len + 1);
+      if (to_end)
+        {
+          strcpy (new_value, orig_value);
+          strcpy (new_value + orig_value_len, add);
+        }
+      else
+        {
+          strcpy (new_value, add);
+          strcpy (new_value + add_len, orig_value);
+        }
+    }
+  else
+    {
+      new_value = xstrdup (add);
+    }
+  return new_value;
+}
+
+int
+lt_split_name_value (const char *arg, char** name, char** value)
+{
+  const char *p;
+  int len;
+  if (!arg || !*arg)
+    return 1;
+
+  p = strchr (arg, (int)'=');
+
+  if (!p)
+    return 1;
+
+  *value = xstrdup (++p);
+
+  len = strlen (arg) - strlen (*value);
+  *name = XMALLOC (char, len);
+  strncpy (*name, arg, len-1);
+  (*name)[len - 1] = '\0';
+
+  return 0;
+}
+
+void
+lt_opt_process_env_set (const char *arg)
+{
+  char *name = NULL;
+  char *value = NULL;
+
+  if (lt_split_name_value (arg, &name, &value) != 0)
+    {
+      XFREE (name);
+      XFREE (value);
+      lt_fatal ("bad argument for %s: '%s'", env_set_opt, arg);
+    }
+
+  lt_setenv (name, value);
+  XFREE (name);
+  XFREE (value);
+}
+
+void
+lt_opt_process_env_prepend (const char *arg)
+{
+  char *name = NULL;
+  char *value = NULL;
+  char *new_value = NULL;
+
+  if (lt_split_name_value (arg, &name, &value) != 0)
+    {
+      XFREE (name);
+      XFREE (value);
+      lt_fatal ("bad argument for %s: '%s'", env_prepend_opt, arg);
+    }
+
+  new_value = lt_extend_str (getenv (name), value, 0);
+  lt_setenv (name, new_value);
+  XFREE (new_value);
+  XFREE (name);
+  XFREE (value);
+}
+
+void
+lt_opt_process_env_append (const char *arg)
+{
+  char *name = NULL;
+  char *value = NULL;
+  char *new_value = NULL;
+
+  if (lt_split_name_value (arg, &name, &value) != 0)
+    {
+      XFREE (name);
+      XFREE (value);
+      lt_fatal ("bad argument for %s: '%s'", env_append_opt, arg);
+    }
+
+  new_value = lt_extend_str (getenv (name), value, 1);
+  lt_setenv (name, new_value);
+  XFREE (new_value);
+  XFREE (name);
+  XFREE (value);
+}
+
+void
+lt_update_exe_path (const char *name, const char *value)
+{
+  LTWRAPPER_DEBUGPRINTF (("(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
+                          (name ? name : "<NULL>"),
+                          (value ? value : "<NULL>")));
+
+  if (name && *name && value && *value)
+    {
+      char *new_value = lt_extend_str (getenv (name), value, 0);
+      /* some systems can't cope with a ':'-terminated path #' */
+      int len = strlen (new_value);
+      while (((len = strlen (new_value)) > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
+        {
+          new_value[len-1] = '\0';
+        }
+      lt_setenv (name, new_value);
+      XFREE (new_value);
+    }
+}
+
+void
+lt_update_lib_path (const char *name, const char *value)
+{
+  LTWRAPPER_DEBUGPRINTF (("(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
+                          (name ? name : "<NULL>"),
+                          (value ? value : "<NULL>")));
+
+  if (name && *name && value && *value)
+    {
+      char *new_value = lt_extend_str (getenv (name), value, 0);
+      lt_setenv (name, new_value);
+      XFREE (new_value);
+    }
+}
+
+
+EOF
+}
+# end: func_emit_cwrapperexe_src
+
+# func_mode_link arg...
+func_mode_link ()
+{
+    $opt_debug
+    case $host in
+    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+      # It is impossible to link a dll without this setting, and
+      # we shouldn't force the makefile maintainer to figure out
+      # which system we are compiling for in order to pass an extra
+      # flag for every libtool invocation.
+      # allow_undefined=no
+
+      # FIXME: Unfortunately, there are problems with the above when trying
+      # to make a dll which has undefined symbols, in which case not
+      # even a static library is built.  For now, we need to specify
+      # -no-undefined on the libtool link line when we can be certain
+      # that all symbols are satisfied, otherwise we get a static library.
+      allow_undefined=yes
+      ;;
+    *)
+      allow_undefined=yes
+      ;;
+    esac
+    libtool_args=$nonopt
+    base_compile="$nonopt $@"
+    compile_command=$nonopt
+    finalize_command=$nonopt
+
+    compile_rpath=
+    finalize_rpath=
+    compile_shlibpath=
+    finalize_shlibpath=
+    convenience=
+    old_convenience=
+    deplibs=
+    old_deplibs=
+    compiler_flags=
+    linker_flags=
+    dllsearchpath=
+    lib_search_path=`pwd`
+    inst_prefix_dir=
+    new_inherited_linker_flags=
+
+    avoid_version=no
+    dlfiles=
+    dlprefiles=
+    dlself=no
+    export_dynamic=no
+    export_symbols=
+    export_symbols_regex=
+    generated=
+    libobjs=
+    ltlibs=
+    module=no
+    no_install=no
+    objs=
+    non_pic_objects=
+    precious_files_regex=
+    prefer_static_libs=no
+    preload=no
+    prev=
+    prevarg=
+    release=
+    rpath=
+    xrpath=
+    perm_rpath=
+    temp_rpath=
+    thread_safe=no
+    vinfo=
+    vinfo_number=no
+    weak_libs=
+    single_module="${wl}-single_module"
+    func_infer_tag $base_compile
+
+    # We need to know -static, to get the right output filenames.
+    for arg
+    do
+      case $arg in
+      -shared)
+	test "$build_libtool_libs" != yes && \
+	  func_fatal_configuration "can not build a shared library"
+	build_old_libs=no
+	break
+	;;
+      -all-static | -static | -static-libtool-libs)
+	case $arg in
+	-all-static)
+	  if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then
+	    func_warning "complete static linking is impossible in this configuration"
+	  fi
+	  if test -n "$link_static_flag"; then
+	    dlopen_self=$dlopen_self_static
+	  fi
+	  prefer_static_libs=yes
+	  ;;
+	-static)
+	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
+	    dlopen_self=$dlopen_self_static
+	  fi
+	  prefer_static_libs=built
+	  ;;
+	-static-libtool-libs)
+	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
+	    dlopen_self=$dlopen_self_static
+	  fi
+	  prefer_static_libs=yes
+	  ;;
+	esac
+	build_libtool_libs=no
+	build_old_libs=yes
+	break
+	;;
+      esac
+    done
+
+    # See if our shared archives depend on static archives.
+    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
+
+    # Go through the arguments, transforming them on the way.
+    while test "$#" -gt 0; do
+      arg="$1"
+      shift
+      func_quote_for_eval "$arg"
+      qarg=$func_quote_for_eval_unquoted_result
+      func_append libtool_args " $func_quote_for_eval_result"
+
+      # If the previous option needs an argument, assign it.
+      if test -n "$prev"; then
+	case $prev in
+	output)
+	  func_append compile_command " @OUTPUT@"
+	  func_append finalize_command " @OUTPUT@"
+	  ;;
+	esac
+
+	case $prev in
+	dlfiles|dlprefiles)
+	  if test "$preload" = no; then
+	    # Add the symbol object into the linking commands.
+	    func_append compile_command " @SYMFILE@"
+	    func_append finalize_command " @SYMFILE@"
+	    preload=yes
+	  fi
+	  case $arg in
+	  *.la | *.lo) ;;  # We handle these cases below.
+	  force)
+	    if test "$dlself" = no; then
+	      dlself=needless
+	      export_dynamic=yes
+	    fi
+	    prev=
+	    continue
+	    ;;
+	  self)
+	    if test "$prev" = dlprefiles; then
+	      dlself=yes
+	    elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then
+	      dlself=yes
+	    else
+	      dlself=needless
+	      export_dynamic=yes
+	    fi
+	    prev=
+	    continue
+	    ;;
+	  *)
+	    if test "$prev" = dlfiles; then
+	      dlfiles="$dlfiles $arg"
+	    else
+	      dlprefiles="$dlprefiles $arg"
+	    fi
+	    prev=
+	    continue
+	    ;;
+	  esac
+	  ;;
+	expsyms)
+	  export_symbols="$arg"
+	  test -f "$arg" \
+	    || func_fatal_error "symbol file \`$arg' does not exist"
+	  prev=
+	  continue
+	  ;;
+	expsyms_regex)
+	  export_symbols_regex="$arg"
+	  prev=
+	  continue
+	  ;;
+	framework)
+	  case $host in
+	    *-*-darwin*)
+	      case "$deplibs " in
+		*" $qarg.ltframework "*) ;;
+		*) deplibs="$deplibs $qarg.ltframework" # this is fixed later
+		   ;;
+	      esac
+	      ;;
+	  esac
+	  prev=
+	  continue
+	  ;;
+	inst_prefix)
+	  inst_prefix_dir="$arg"
+	  prev=
+	  continue
+	  ;;
+	objectlist)
+	  if test -f "$arg"; then
+	    save_arg=$arg
+	    moreargs=
+	    for fil in `cat "$save_arg"`
+	    do
+#	      moreargs="$moreargs $fil"
+	      arg=$fil
+	      # A libtool-controlled object.
+
+	      # Check to see that this really is a libtool object.
+	      if func_lalib_unsafe_p "$arg"; then
+		pic_object=
+		non_pic_object=
+
+		# Read the .lo file
+		func_source "$arg"
+
+		if test -z "$pic_object" ||
+		   test -z "$non_pic_object" ||
+		   test "$pic_object" = none &&
+		   test "$non_pic_object" = none; then
+		  func_fatal_error "cannot find name of object for \`$arg'"
+		fi
+
+		# Extract subdirectory from the argument.
+		func_dirname "$arg" "/" ""
+		xdir="$func_dirname_result"
+
+		if test "$pic_object" != none; then
+		  # Prepend the subdirectory the object is found in.
+		  pic_object="$xdir$pic_object"
+
+		  if test "$prev" = dlfiles; then
+		    if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
+		      dlfiles="$dlfiles $pic_object"
+		      prev=
+		      continue
+		    else
+		      # If libtool objects are unsupported, then we need to preload.
+		      prev=dlprefiles
+		    fi
+		  fi
+
+		  # CHECK ME:  I think I busted this.  -Ossama
+		  if test "$prev" = dlprefiles; then
+		    # Preload the old-style object.
+		    dlprefiles="$dlprefiles $pic_object"
+		    prev=
+		  fi
+
+		  # A PIC object.
+		  func_append libobjs " $pic_object"
+		  arg="$pic_object"
+		fi
+
+		# Non-PIC object.
+		if test "$non_pic_object" != none; then
+		  # Prepend the subdirectory the object is found in.
+		  non_pic_object="$xdir$non_pic_object"
+
+		  # A standard non-PIC object
+		  func_append non_pic_objects " $non_pic_object"
+		  if test -z "$pic_object" || test "$pic_object" = none ; then
+		    arg="$non_pic_object"
+		  fi
+		else
+		  # If the PIC object exists, use it instead.
+		  # $xdir was prepended to $pic_object above.
+		  non_pic_object="$pic_object"
+		  func_append non_pic_objects " $non_pic_object"
+		fi
+	      else
+		# Only an error if not doing a dry-run.
+		if $opt_dry_run; then
+		  # Extract subdirectory from the argument.
+		  func_dirname "$arg" "/" ""
+		  xdir="$func_dirname_result"
+
+		  func_lo2o "$arg"
+		  pic_object=$xdir$objdir/$func_lo2o_result
+		  non_pic_object=$xdir$func_lo2o_result
+		  func_append libobjs " $pic_object"
+		  func_append non_pic_objects " $non_pic_object"
+	        else
+		  func_fatal_error "\`$arg' is not a valid libtool object"
+		fi
+	      fi
+	    done
+	  else
+	    func_fatal_error "link input file \`$arg' does not exist"
+	  fi
+	  arg=$save_arg
+	  prev=
+	  continue
+	  ;;
+	precious_regex)
+	  precious_files_regex="$arg"
+	  prev=
+	  continue
+	  ;;
+	release)
+	  release="-$arg"
+	  prev=
+	  continue
+	  ;;
+	rpath | xrpath)
+	  # We need an absolute path.
+	  case $arg in
+	  [\\/]* | [A-Za-z]:[\\/]*) ;;
+	  *)
+	    func_fatal_error "only absolute run-paths are allowed"
+	    ;;
+	  esac
+	  if test "$prev" = rpath; then
+	    case "$rpath " in
+	    *" $arg "*) ;;
+	    *) rpath="$rpath $arg" ;;
+	    esac
+	  else
+	    case "$xrpath " in
+	    *" $arg "*) ;;
+	    *) xrpath="$xrpath $arg" ;;
+	    esac
+	  fi
+	  prev=
+	  continue
+	  ;;
+	shrext)
+	  shrext_cmds="$arg"
+	  prev=
+	  continue
+	  ;;
+	weak)
+	  weak_libs="$weak_libs $arg"
+	  prev=
+	  continue
+	  ;;
+	xcclinker)
+	  linker_flags="$linker_flags $qarg"
+	  compiler_flags="$compiler_flags $qarg"
+	  prev=
+	  func_append compile_command " $qarg"
+	  func_append finalize_command " $qarg"
+	  continue
+	  ;;
+	xcompiler)
+	  compiler_flags="$compiler_flags $qarg"
+	  prev=
+	  func_append compile_command " $qarg"
+	  func_append finalize_command " $qarg"
+	  continue
+	  ;;
+	xlinker)
+	  linker_flags="$linker_flags $qarg"
+	  compiler_flags="$compiler_flags $wl$qarg"
+	  prev=
+	  func_append compile_command " $wl$qarg"
+	  func_append finalize_command " $wl$qarg"
+	  continue
+	  ;;
+	*)
+	  eval "$prev=\"\$arg\""
+	  prev=
+	  continue
+	  ;;
+	esac
+      fi # test -n "$prev"
+
+      prevarg="$arg"
+
+      case $arg in
+      -all-static)
+	if test -n "$link_static_flag"; then
+	  # See comment for -static flag below, for more details.
+	  func_append compile_command " $link_static_flag"
+	  func_append finalize_command " $link_static_flag"
+	fi
+	continue
+	;;
+
+      -allow-undefined)
+	# FIXME: remove this flag sometime in the future.
+	func_fatal_error "\`-allow-undefined' must not be used because it is the default"
+	;;
+
+      -avoid-version)
+	avoid_version=yes
+	continue
+	;;
+
+      -dlopen)
+	prev=dlfiles
+	continue
+	;;
+
+      -dlpreopen)
+	prev=dlprefiles
+	continue
+	;;
+
+      -export-dynamic)
+	export_dynamic=yes
+	continue
+	;;
+
+      -export-symbols | -export-symbols-regex)
+	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
+	  func_fatal_error "more than one -exported-symbols argument is not allowed"
+	fi
+	if test "X$arg" = "X-export-symbols"; then
+	  prev=expsyms
+	else
+	  prev=expsyms_regex
+	fi
+	continue
+	;;
+
+      -framework)
+	prev=framework
+	continue
+	;;
+
+      -inst-prefix-dir)
+	prev=inst_prefix
+	continue
+	;;
+
+      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
+      # so, if we see these flags be careful not to treat them like -L
+      -L[A-Z][A-Z]*:*)
+	case $with_gcc/$host in
+	no/*-*-irix* | /*-*-irix*)
+	  func_append compile_command " $arg"
+	  func_append finalize_command " $arg"
+	  ;;
+	esac
+	continue
+	;;
+
+      -L*)
+	func_stripname '-L' '' "$arg"
+	dir=$func_stripname_result
+	if test -z "$dir"; then
+	  if test "$#" -gt 0; then
+	    func_fatal_error "require no space between \`-L' and \`$1'"
+	  else
+	    func_fatal_error "need path for \`-L' option"
+	  fi
+	fi
+	# We need an absolute path.
+	case $dir in
+	[\\/]* | [A-Za-z]:[\\/]*) ;;
+	*)
+	  absdir=`cd "$dir" && pwd`
+	  test -z "$absdir" && \
+	    func_fatal_error "cannot determine absolute directory name of \`$dir'"
+	  dir="$absdir"
+	  ;;
+	esac
+	case "$deplibs " in
+	*" -L$dir "*) ;;
+	*)
+	  deplibs="$deplibs -L$dir"
+	  lib_search_path="$lib_search_path $dir"
+	  ;;
+	esac
+	case $host in
+	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+	  testbindir=`$ECHO "X$dir" | $Xsed -e 's*/lib$*/bin*'`
+	  case :$dllsearchpath: in
+	  *":$dir:"*) ;;
+	  ::) dllsearchpath=$dir;;
+	  *) dllsearchpath="$dllsearchpath:$dir";;
+	  esac
+	  case :$dllsearchpath: in
+	  *":$testbindir:"*) ;;
+	  ::) dllsearchpath=$testbindir;;
+	  *) dllsearchpath="$dllsearchpath:$testbindir";;
+	  esac
+	  ;;
+	esac
+	continue
+	;;
+
+      -l*)
+	if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then
+	  case $host in
+	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc*)
+	    # These systems don't actually have a C or math library (as such)
+	    continue
+	    ;;
+	  *-*-os2*)
+	    # These systems don't actually have a C library (as such)
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	    # Do not include libc due to us having libc/libc_r.
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  *-*-rhapsody* | *-*-darwin1.[012])
+	    # Rhapsody C and math libraries are in the System framework
+	    deplibs="$deplibs System.ltframework"
+	    continue
+	    ;;
+	  *-*-sco3.2v5* | *-*-sco5v6*)
+	    # Causes problems with __ctype
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
+	    # Compiler inserts libc in the correct place for threads to work
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  esac
+	elif test "X$arg" = "X-lc_r"; then
+	 case $host in
+	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	   # Do not include libc_r directly, use -pthread flag.
+	   continue
+	   ;;
+	 esac
+	fi
+	deplibs="$deplibs $arg"
+	continue
+	;;
+
+      -module)
+	module=yes
+	continue
+	;;
+
+      # Tru64 UNIX uses -model [arg] to determine the layout of C++
+      # classes, name mangling, and exception handling.
+      # Darwin uses the -arch flag to determine output architecture.
+      -model|-arch|-isysroot)
+	compiler_flags="$compiler_flags $arg"
+	func_append compile_command " $arg"
+	func_append finalize_command " $arg"
+	prev=xcompiler
+	continue
+	;;
+
+      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads)
+	compiler_flags="$compiler_flags $arg"
+	func_append compile_command " $arg"
+	func_append finalize_command " $arg"
+	case "$new_inherited_linker_flags " in
+	    *" $arg "*) ;;
+	    * ) new_inherited_linker_flags="$new_inherited_linker_flags $arg" ;;
+	esac
+	continue
+	;;
+
+      -multi_module)
+	single_module="${wl}-multi_module"
+	continue
+	;;
+
+      -no-fast-install)
+	fast_install=no
+	continue
+	;;
+
+      -no-install)
+	case $host in
+	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
+	  # The PATH hackery in wrapper scripts is required on Windows
+	  # and Darwin in order for the loader to find any dlls it needs.
+	  func_warning "\`-no-install' is ignored for $host"
+	  func_warning "assuming \`-no-fast-install' instead"
+	  fast_install=no
+	  ;;
+	*) no_install=yes ;;
+	esac
+	continue
+	;;
+
+      -no-undefined)
+	allow_undefined=no
+	continue
+	;;
+
+      -objectlist)
+	prev=objectlist
+	continue
+	;;
+
+      -o) prev=output ;;
+
+      -precious-files-regex)
+	prev=precious_regex
+	continue
+	;;
+
+      -release)
+	prev=release
+	continue
+	;;
+
+      -rpath)
+	prev=rpath
+	continue
+	;;
+
+      -R)
+	prev=xrpath
+	continue
+	;;
+
+      -R*)
+	func_stripname '-R' '' "$arg"
+	dir=$func_stripname_result
+	# We need an absolute path.
+	case $dir in
+	[\\/]* | [A-Za-z]:[\\/]*) ;;
+	*)
+	  func_fatal_error "only absolute run-paths are allowed"
+	  ;;
+	esac
+	case "$xrpath " in
+	*" $dir "*) ;;
+	*) xrpath="$xrpath $dir" ;;
+	esac
+	continue
+	;;
+
+      -shared)
+	# The effects of -shared are defined in a previous loop.
+	continue
+	;;
+
+      -shrext)
+	prev=shrext
+	continue
+	;;
+
+      -static | -static-libtool-libs)
+	# The effects of -static are defined in a previous loop.
+	# We used to do the same as -all-static on platforms that
+	# didn't have a PIC flag, but the assumption that the effects
+	# would be equivalent was wrong.  It would break on at least
+	# Digital Unix and AIX.
+	continue
+	;;
+
+      -thread-safe)
+	thread_safe=yes
+	continue
+	;;
+
+      -version-info)
+	prev=vinfo
+	continue
+	;;
+
+      -version-number)
+	prev=vinfo
+	vinfo_number=yes
+	continue
+	;;
+
+      -weak)
+        prev=weak
+	continue
+	;;
+
+      -Wc,*)
+	func_stripname '-Wc,' '' "$arg"
+	args=$func_stripname_result
+	arg=
+	save_ifs="$IFS"; IFS=','
+	for flag in $args; do
+	  IFS="$save_ifs"
+          func_quote_for_eval "$flag"
+	  arg="$arg $wl$func_quote_for_eval_result"
+	  compiler_flags="$compiler_flags $func_quote_for_eval_result"
+	done
+	IFS="$save_ifs"
+	func_stripname ' ' '' "$arg"
+	arg=$func_stripname_result
+	;;
+
+      -Wl,*)
+	func_stripname '-Wl,' '' "$arg"
+	args=$func_stripname_result
+	arg=
+	save_ifs="$IFS"; IFS=','
+	for flag in $args; do
+	  IFS="$save_ifs"
+          func_quote_for_eval "$flag"
+	  arg="$arg $wl$func_quote_for_eval_result"
+	  compiler_flags="$compiler_flags $wl$func_quote_for_eval_result"
+	  linker_flags="$linker_flags $func_quote_for_eval_result"
+	done
+	IFS="$save_ifs"
+	func_stripname ' ' '' "$arg"
+	arg=$func_stripname_result
+	;;
+
+      -Xcompiler)
+	prev=xcompiler
+	continue
+	;;
+
+      -Xlinker)
+	prev=xlinker
+	continue
+	;;
+
+      -XCClinker)
+	prev=xcclinker
+	continue
+	;;
+
+      # -msg_* for osf cc
+      -msg_*)
+	func_quote_for_eval "$arg"
+	arg="$func_quote_for_eval_result"
+	;;
+
+      # -64, -mips[0-9] enable 64-bit mode on the SGI compiler
+      # -r[0-9][0-9]* specifies the processor on the SGI compiler
+      # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler
+      # +DA*, +DD* enable 64-bit mode on the HP compiler
+      # -q* pass through compiler args for the IBM compiler
+      # -m*, -t[45]*, -txscale* pass through architecture-specific
+      # compiler args for GCC
+      # -F/path gives path to uninstalled frameworks, gcc on darwin
+      # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC
+      # @file GCC response files
+      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
+      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*)
+        func_quote_for_eval "$arg"
+	arg="$func_quote_for_eval_result"
+        func_append compile_command " $arg"
+        func_append finalize_command " $arg"
+        compiler_flags="$compiler_flags $arg"
+        continue
+        ;;
+
+      # Some other compiler flag.
+      -* | +*)
+        func_quote_for_eval "$arg"
+	arg="$func_quote_for_eval_result"
+	;;
+
+      *.$objext)
+	# A standard object.
+	objs="$objs $arg"
+	;;
+
+      *.lo)
+	# A libtool-controlled object.
+
+	# Check to see that this really is a libtool object.
+	if func_lalib_unsafe_p "$arg"; then
+	  pic_object=
+	  non_pic_object=
+
+	  # Read the .lo file
+	  func_source "$arg"
+
+	  if test -z "$pic_object" ||
+	     test -z "$non_pic_object" ||
+	     test "$pic_object" = none &&
+	     test "$non_pic_object" = none; then
+	    func_fatal_error "cannot find name of object for \`$arg'"
+	  fi
+
+	  # Extract subdirectory from the argument.
+	  func_dirname "$arg" "/" ""
+	  xdir="$func_dirname_result"
+
+	  if test "$pic_object" != none; then
+	    # Prepend the subdirectory the object is found in.
+	    pic_object="$xdir$pic_object"
+
+	    if test "$prev" = dlfiles; then
+	      if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
+		dlfiles="$dlfiles $pic_object"
+		prev=
+		continue
+	      else
+		# If libtool objects are unsupported, then we need to preload.
+		prev=dlprefiles
+	      fi
+	    fi
+
+	    # CHECK ME:  I think I busted this.  -Ossama
+	    if test "$prev" = dlprefiles; then
+	      # Preload the old-style object.
+	      dlprefiles="$dlprefiles $pic_object"
+	      prev=
+	    fi
+
+	    # A PIC object.
+	    func_append libobjs " $pic_object"
+	    arg="$pic_object"
+	  fi
+
+	  # Non-PIC object.
+	  if test "$non_pic_object" != none; then
+	    # Prepend the subdirectory the object is found in.
+	    non_pic_object="$xdir$non_pic_object"
+
+	    # A standard non-PIC object
+	    func_append non_pic_objects " $non_pic_object"
+	    if test -z "$pic_object" || test "$pic_object" = none ; then
+	      arg="$non_pic_object"
+	    fi
+	  else
+	    # If the PIC object exists, use it instead.
+	    # $xdir was prepended to $pic_object above.
+	    non_pic_object="$pic_object"
+	    func_append non_pic_objects " $non_pic_object"
+	  fi
+	else
+	  # Only an error if not doing a dry-run.
+	  if $opt_dry_run; then
+	    # Extract subdirectory from the argument.
+	    func_dirname "$arg" "/" ""
+	    xdir="$func_dirname_result"
+
+	    func_lo2o "$arg"
+	    pic_object=$xdir$objdir/$func_lo2o_result
+	    non_pic_object=$xdir$func_lo2o_result
+	    func_append libobjs " $pic_object"
+	    func_append non_pic_objects " $non_pic_object"
+	  else
+	    func_fatal_error "\`$arg' is not a valid libtool object"
+	  fi
+	fi
+	;;
+
+      *.$libext)
+	# An archive.
+	deplibs="$deplibs $arg"
+	old_deplibs="$old_deplibs $arg"
+	continue
+	;;
+
+      *.la)
+	# A libtool-controlled library.
+
+	if test "$prev" = dlfiles; then
+	  # This library was specified with -dlopen.
+	  dlfiles="$dlfiles $arg"
+	  prev=
+	elif test "$prev" = dlprefiles; then
+	  # The library was specified with -dlpreopen.
+	  dlprefiles="$dlprefiles $arg"
+	  prev=
+	else
+	  deplibs="$deplibs $arg"
+	fi
+	continue
+	;;
+
+      # Some other compiler argument.
+      *)
+	# Unknown arguments in both finalize_command and compile_command need
+	# to be aesthetically quoted because they are evaled later.
+	func_quote_for_eval "$arg"
+	arg="$func_quote_for_eval_result"
+	;;
+      esac # arg
+
+      # Now actually substitute the argument into the commands.
+      if test -n "$arg"; then
+	func_append compile_command " $arg"
+	func_append finalize_command " $arg"
+      fi
+    done # argument parsing loop
+
+    test -n "$prev" && \
+      func_fatal_help "the \`$prevarg' option requires an argument"
+
+    if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then
+      eval arg=\"$export_dynamic_flag_spec\"
+      func_append compile_command " $arg"
+      func_append finalize_command " $arg"
+    fi
+
+    oldlibs=
+    # calculate the name of the file, without its directory
+    func_basename "$output"
+    outputname="$func_basename_result"
+    libobjs_save="$libobjs"
+
+    if test -n "$shlibpath_var"; then
+      # get the directories listed in $shlibpath_var
+      eval shlib_search_path=\`\$ECHO \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\`
+    else
+      shlib_search_path=
+    fi
+    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
+    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
+
+    func_dirname "$output" "/" ""
+    output_objdir="$func_dirname_result$objdir"
+    # Create the object directory.
+    func_mkdir_p "$output_objdir"
+
+    # Determine the type of output
+    case $output in
+    "")
+      func_fatal_help "you must specify an output file"
+      ;;
+    *.$libext) linkmode=oldlib ;;
+    *.lo | *.$objext) linkmode=obj ;;
+    *.la) linkmode=lib ;;
+    *) linkmode=prog ;; # Anything else should be a program.
+    esac
+
+    specialdeplibs=
+
+    libs=
+    # Find all interdependent deplibs by searching for libraries
+    # that are linked more than once (e.g. -la -lb -la)
+    for deplib in $deplibs; do
+      if $opt_duplicate_deps ; then
+	case "$libs " in
+	*" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+	esac
+      fi
+      libs="$libs $deplib"
+    done
+
+    if test "$linkmode" = lib; then
+      libs="$predeps $libs $compiler_lib_search_path $postdeps"
+
+      # Compute libraries that are listed more than once in $predeps
+      # $postdeps and mark them as special (i.e., whose duplicates are
+      # not to be eliminated).
+      pre_post_deps=
+      if $opt_duplicate_compiler_generated_deps; then
+	for pre_post_dep in $predeps $postdeps; do
+	  case "$pre_post_deps " in
+	  *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;;
+	  esac
+	  pre_post_deps="$pre_post_deps $pre_post_dep"
+	done
+      fi
+      pre_post_deps=
+    fi
+
+    deplibs=
+    newdependency_libs=
+    newlib_search_path=
+    need_relink=no # whether we're linking any uninstalled libtool libraries
+    notinst_deplibs= # not-installed libtool libraries
+    notinst_path= # paths that contain not-installed libtool libraries
+
+    case $linkmode in
+    lib)
+	passes="conv dlpreopen link"
+	for file in $dlfiles $dlprefiles; do
+	  case $file in
+	  *.la) ;;
+	  *)
+	    func_fatal_help "libraries can \`-dlopen' only libtool libraries: $file"
+	    ;;
+	  esac
+	done
+	;;
+    prog)
+	compile_deplibs=
+	finalize_deplibs=
+	alldeplibs=no
+	newdlfiles=
+	newdlprefiles=
+	passes="conv scan dlopen dlpreopen link"
+	;;
+    *)  passes="conv"
+	;;
+    esac
+
+    for pass in $passes; do
+      # The preopen pass in lib mode reverses $deplibs; put it back here
+      # so that -L comes before libs that need it for instance...
+      if test "$linkmode,$pass" = "lib,link"; then
+	## FIXME: Find the place where the list is rebuilt in the wrong
+	##        order, and fix it there properly
+        tmp_deplibs=
+	for deplib in $deplibs; do
+	  tmp_deplibs="$deplib $tmp_deplibs"
+	done
+	deplibs="$tmp_deplibs"
+      fi
+
+      if test "$linkmode,$pass" = "lib,link" ||
+	 test "$linkmode,$pass" = "prog,scan"; then
+	libs="$deplibs"
+	deplibs=
+      fi
+      if test "$linkmode" = prog; then
+	case $pass in
+	dlopen) libs="$dlfiles" ;;
+	dlpreopen) libs="$dlprefiles" ;;
+	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
+	esac
+      fi
+      if test "$linkmode,$pass" = "lib,dlpreopen"; then
+	# Collect and forward deplibs of preopened libtool libs
+	for lib in $dlprefiles; do
+	  # Ignore non-libtool-libs
+	  dependency_libs=
+	  case $lib in
+	  *.la)	func_source "$lib" ;;
+	  esac
+
+	  # Collect preopened libtool deplibs, except any this library
+	  # has declared as weak libs
+	  for deplib in $dependency_libs; do
+            deplib_base=`$ECHO "X$deplib" | $Xsed -e "$basename"`
+	    case " $weak_libs " in
+	    *" $deplib_base "*) ;;
+	    *) deplibs="$deplibs $deplib" ;;
+	    esac
+	  done
+	done
+	libs="$dlprefiles"
+      fi
+      if test "$pass" = dlopen; then
+	# Collect dlpreopened libraries
+	save_deplibs="$deplibs"
+	deplibs=
+      fi
+
+      for deplib in $libs; do
+	lib=
+	found=no
+	case $deplib in
+	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads)
+	  if test "$linkmode,$pass" = "prog,link"; then
+	    compile_deplibs="$deplib $compile_deplibs"
+	    finalize_deplibs="$deplib $finalize_deplibs"
+	  else
+	    compiler_flags="$compiler_flags $deplib"
+	    if test "$linkmode" = lib ; then
+		case "$new_inherited_linker_flags " in
+		    *" $deplib "*) ;;
+		    * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;;
+		esac
+	    fi
+	  fi
+	  continue
+	  ;;
+	-l*)
+	  if test "$linkmode" != lib && test "$linkmode" != prog; then
+	    func_warning "\`-l' is ignored for archives/objects"
+	    continue
+	  fi
+	  func_stripname '-l' '' "$deplib"
+	  name=$func_stripname_result
+	  if test "$linkmode" = lib; then
+	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
+	  else
+	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
+	  fi
+	  for searchdir in $searchdirs; do
+	    for search_ext in .la $std_shrext .so .a; do
+	      # Search the libtool library
+	      lib="$searchdir/lib${name}${search_ext}"
+	      if test -f "$lib"; then
+		if test "$search_ext" = ".la"; then
+		  found=yes
+		else
+		  found=no
+		fi
+		break 2
+	      fi
+	    done
+	  done
+	  if test "$found" != yes; then
+	    # deplib doesn't seem to be a libtool library
+	    if test "$linkmode,$pass" = "prog,link"; then
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    else
+	      deplibs="$deplib $deplibs"
+	      test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
+	    fi
+	    continue
+	  else # deplib is a libtool library
+	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
+	    # We need to do some special things here, and not later.
+	    if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+	      case " $predeps $postdeps " in
+	      *" $deplib "*)
+		if func_lalib_p "$lib"; then
+		  library_names=
+		  old_library=
+		  func_source "$lib"
+		  for l in $old_library $library_names; do
+		    ll="$l"
+		  done
+		  if test "X$ll" = "X$old_library" ; then # only static version available
+		    found=no
+		    func_dirname "$lib" "" "."
+		    ladir="$func_dirname_result"
+		    lib=$ladir/$old_library
+		    if test "$linkmode,$pass" = "prog,link"; then
+		      compile_deplibs="$deplib $compile_deplibs"
+		      finalize_deplibs="$deplib $finalize_deplibs"
+		    else
+		      deplibs="$deplib $deplibs"
+		      test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
+		    fi
+		    continue
+		  fi
+		fi
+		;;
+	      *) ;;
+	      esac
+	    fi
+	  fi
+	  ;; # -l
+	*.ltframework)
+	  if test "$linkmode,$pass" = "prog,link"; then
+	    compile_deplibs="$deplib $compile_deplibs"
+	    finalize_deplibs="$deplib $finalize_deplibs"
+	  else
+	    deplibs="$deplib $deplibs"
+	    if test "$linkmode" = lib ; then
+		case "$new_inherited_linker_flags " in
+		    *" $deplib "*) ;;
+		    * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;;
+		esac
+	    fi
+	  fi
+	  continue
+	  ;;
+	-L*)
+	  case $linkmode in
+	  lib)
+	    deplibs="$deplib $deplibs"
+	    test "$pass" = conv && continue
+	    newdependency_libs="$deplib $newdependency_libs"
+	    func_stripname '-L' '' "$deplib"
+	    newlib_search_path="$newlib_search_path $func_stripname_result"
+	    ;;
+	  prog)
+	    if test "$pass" = conv; then
+	      deplibs="$deplib $deplibs"
+	      continue
+	    fi
+	    if test "$pass" = scan; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    fi
+	    func_stripname '-L' '' "$deplib"
+	    newlib_search_path="$newlib_search_path $func_stripname_result"
+	    ;;
+	  *)
+	    func_warning "\`-L' is ignored for archives/objects"
+	    ;;
+	  esac # linkmode
+	  continue
+	  ;; # -L
+	-R*)
+	  if test "$pass" = link; then
+	    func_stripname '-R' '' "$deplib"
+	    dir=$func_stripname_result
+	    # Make sure the xrpath contains only unique directories.
+	    case "$xrpath " in
+	    *" $dir "*) ;;
+	    *) xrpath="$xrpath $dir" ;;
+	    esac
+	  fi
+	  deplibs="$deplib $deplibs"
+	  continue
+	  ;;
+	*.la) lib="$deplib" ;;
+	*.$libext)
+	  if test "$pass" = conv; then
+	    deplibs="$deplib $deplibs"
+	    continue
+	  fi
+	  case $linkmode in
+	  lib)
+	    # Linking convenience modules into shared libraries is allowed,
+	    # but linking other static libraries is non-portable.
+	    case " $dlpreconveniencelibs " in
+	    *" $deplib "*) ;;
+	    *)
+	      valid_a_lib=no
+	      case $deplibs_check_method in
+		match_pattern*)
+		  set dummy $deplibs_check_method; shift
+		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+		  if eval "\$ECHO \"X$deplib\"" 2>/dev/null | $Xsed -e 10q \
+		    | $EGREP "$match_pattern_regex" > /dev/null; then
+		    valid_a_lib=yes
+		  fi
+		;;
+		pass_all)
+		  valid_a_lib=yes
+		;;
+	      esac
+	      if test "$valid_a_lib" != yes; then
+		$ECHO
+		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
+		$ECHO "*** I have the capability to make that library automatically link in when"
+		$ECHO "*** you link to this library.  But I can only do this if you have a"
+		$ECHO "*** shared version of the library, which you do not appear to have"
+		$ECHO "*** because the file extensions .$libext of this argument makes me believe"
+		$ECHO "*** that it is just a static archive that I should not use here."
+	      else
+		$ECHO
+		$ECHO "*** Warning: Linking the shared library $output against the"
+		$ECHO "*** static library $deplib is not portable!"
+		deplibs="$deplib $deplibs"
+	      fi
+	      ;;
+	    esac
+	    continue
+	    ;;
+	  prog)
+	    if test "$pass" != link; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    fi
+	    continue
+	    ;;
+	  esac # linkmode
+	  ;; # *.$libext
+	*.lo | *.$objext)
+	  if test "$pass" = conv; then
+	    deplibs="$deplib $deplibs"
+	  elif test "$linkmode" = prog; then
+	    if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then
+	      # If there is no dlopen support or we're linking statically,
+	      # we need to preload.
+	      newdlprefiles="$newdlprefiles $deplib"
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    else
+	      newdlfiles="$newdlfiles $deplib"
+	    fi
+	  fi
+	  continue
+	  ;;
+	%DEPLIBS%)
+	  alldeplibs=yes
+	  continue
+	  ;;
+	esac # case $deplib
+
+	if test "$found" = yes || test -f "$lib"; then :
+	else
+	  func_fatal_error "cannot find the library \`$lib' or unhandled argument \`$deplib'"
+	fi
+
+	# Check to see that this really is a libtool archive.
+	func_lalib_unsafe_p "$lib" \
+	  || func_fatal_error "\`$lib' is not a valid libtool archive"
+
+	func_dirname "$lib" "" "."
+	ladir="$func_dirname_result"
+
+	dlname=
+	dlopen=
+	dlpreopen=
+	libdir=
+	library_names=
+	old_library=
+	inherited_linker_flags=
+	# If the library was installed with an old release of libtool,
+	# it will not redefine variables installed, or shouldnotlink
+	installed=yes
+	shouldnotlink=no
+	avoidtemprpath=
+
+
+	# Read the .la file
+	func_source "$lib"
+
+	# Convert "-framework foo" to "foo.ltframework"
+	if test -n "$inherited_linker_flags"; then
+	  tmp_inherited_linker_flags=`$ECHO "X$inherited_linker_flags" | $Xsed -e 's/-framework \([^ $]*\)/\1.ltframework/g'`
+	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
+	    case " $new_inherited_linker_flags " in
+	      *" $tmp_inherited_linker_flag "*) ;;
+	      *) new_inherited_linker_flags="$new_inherited_linker_flags $tmp_inherited_linker_flag";;
+	    esac
+	  done
+	fi
+	dependency_libs=`$ECHO "X $dependency_libs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	if test "$linkmode,$pass" = "lib,link" ||
+	   test "$linkmode,$pass" = "prog,scan" ||
+	   { test "$linkmode" != prog && test "$linkmode" != lib; }; then
+	  test -n "$dlopen" && dlfiles="$dlfiles $dlopen"
+	  test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen"
+	fi
+
+	if test "$pass" = conv; then
+	  # Only check for convenience libraries
+	  deplibs="$lib $deplibs"
+	  if test -z "$libdir"; then
+	    if test -z "$old_library"; then
+	      func_fatal_error "cannot find name of link library for \`$lib'"
+	    fi
+	    # It is a libtool convenience library, so add in its objects.
+	    convenience="$convenience $ladir/$objdir/$old_library"
+	    old_convenience="$old_convenience $ladir/$objdir/$old_library"
+	  elif test "$linkmode" != prog && test "$linkmode" != lib; then
+	    func_fatal_error "\`$lib' is not a convenience library"
+	  fi
+	  tmp_libs=
+	  for deplib in $dependency_libs; do
+	    deplibs="$deplib $deplibs"
+	    if $opt_duplicate_deps ; then
+	      case "$tmp_libs " in
+	      *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+	      esac
+	    fi
+	    tmp_libs="$tmp_libs $deplib"
+	  done
+	  continue
+	fi # $pass = conv
+
+
+	# Get the name of the library we link against.
+	linklib=
+	for l in $old_library $library_names; do
+	  linklib="$l"
+	done
+	if test -z "$linklib"; then
+	  func_fatal_error "cannot find name of link library for \`$lib'"
+	fi
+
+	# This library was specified with -dlopen.
+	if test "$pass" = dlopen; then
+	  if test -z "$libdir"; then
+	    func_fatal_error "cannot -dlopen a convenience library: \`$lib'"
+	  fi
+	  if test -z "$dlname" ||
+	     test "$dlopen_support" != yes ||
+	     test "$build_libtool_libs" = no; then
+	    # If there is no dlname, no dlopen support or we're linking
+	    # statically, we need to preload.  We also need to preload any
+	    # dependent libraries so libltdl's deplib preloader doesn't
+	    # bomb out in the load deplibs phase.
+	    dlprefiles="$dlprefiles $lib $dependency_libs"
+	  else
+	    newdlfiles="$newdlfiles $lib"
+	  fi
+	  continue
+	fi # $pass = dlopen
+
+	# We need an absolute path.
+	case $ladir in
+	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;;
+	*)
+	  abs_ladir=`cd "$ladir" && pwd`
+	  if test -z "$abs_ladir"; then
+	    func_warning "cannot determine absolute directory name of \`$ladir'"
+	    func_warning "passing it literally to the linker, although it might fail"
+	    abs_ladir="$ladir"
+	  fi
+	  ;;
+	esac
+	func_basename "$lib"
+	laname="$func_basename_result"
+
+	# Find the relevant object directory and library name.
+	if test "X$installed" = Xyes; then
+	  if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
+	    func_warning "library \`$lib' was moved."
+	    dir="$ladir"
+	    absdir="$abs_ladir"
+	    libdir="$abs_ladir"
+	  else
+	    dir="$libdir"
+	    absdir="$libdir"
+	  fi
+	  test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes
+	else
+	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
+	    dir="$ladir"
+	    absdir="$abs_ladir"
+	    # Remove this search path later
+	    notinst_path="$notinst_path $abs_ladir"
+	  else
+	    dir="$ladir/$objdir"
+	    absdir="$abs_ladir/$objdir"
+	    # Remove this search path later
+	    notinst_path="$notinst_path $abs_ladir"
+	  fi
+	fi # $installed = yes
+	func_stripname 'lib' '.la' "$laname"
+	name=$func_stripname_result
+
+	# This library was specified with -dlpreopen.
+	if test "$pass" = dlpreopen; then
+	  if test -z "$libdir" && test "$linkmode" = prog; then
+	    func_fatal_error "only libraries may -dlpreopen a convenience library: \`$lib'"
+	  fi
+	  # Prefer using a static library (so that no silly _DYNAMIC symbols
+	  # are required to link).
+	  if test -n "$old_library"; then
+	    newdlprefiles="$newdlprefiles $dir/$old_library"
+	    # Keep a list of preopened convenience libraries to check
+	    # that they are being used correctly in the link pass.
+	    test -z "$libdir" && \
+		dlpreconveniencelibs="$dlpreconveniencelibs $dir/$old_library"
+	  # Otherwise, use the dlname, so that lt_dlopen finds it.
+	  elif test -n "$dlname"; then
+	    newdlprefiles="$newdlprefiles $dir/$dlname"
+	  else
+	    newdlprefiles="$newdlprefiles $dir/$linklib"
+	  fi
+	fi # $pass = dlpreopen
+
+	if test -z "$libdir"; then
+	  # Link the convenience library
+	  if test "$linkmode" = lib; then
+	    deplibs="$dir/$old_library $deplibs"
+	  elif test "$linkmode,$pass" = "prog,link"; then
+	    compile_deplibs="$dir/$old_library $compile_deplibs"
+	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
+	  else
+	    deplibs="$lib $deplibs" # used for prog,scan pass
+	  fi
+	  continue
+	fi
+
+
+	if test "$linkmode" = prog && test "$pass" != link; then
+	  newlib_search_path="$newlib_search_path $ladir"
+	  deplibs="$lib $deplibs"
+
+	  linkalldeplibs=no
+	  if test "$link_all_deplibs" != no || test -z "$library_names" ||
+	     test "$build_libtool_libs" = no; then
+	    linkalldeplibs=yes
+	  fi
+
+	  tmp_libs=
+	  for deplib in $dependency_libs; do
+	    case $deplib in
+	    -L*) func_stripname '-L' '' "$deplib"
+	         newlib_search_path="$newlib_search_path $func_stripname_result"
+		 ;;
+	    esac
+	    # Need to link against all dependency_libs?
+	    if test "$linkalldeplibs" = yes; then
+	      deplibs="$deplib $deplibs"
+	    else
+	      # Need to hardcode shared library paths
+	      # or/and link against static libraries
+	      newdependency_libs="$deplib $newdependency_libs"
+	    fi
+	    if $opt_duplicate_deps ; then
+	      case "$tmp_libs " in
+	      *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+	      esac
+	    fi
+	    tmp_libs="$tmp_libs $deplib"
+	  done # for deplib
+	  continue
+	fi # $linkmode = prog...
+
+	if test "$linkmode,$pass" = "prog,link"; then
+	  if test -n "$library_names" &&
+	     { { test "$prefer_static_libs" = no ||
+	         test "$prefer_static_libs,$installed" = "built,yes"; } ||
+	       test -z "$old_library"; }; then
+	    # We need to hardcode the library path
+	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then
+	      # Make sure the rpath contains only unique directories.
+	      case "$temp_rpath:" in
+	      *"$absdir:"*) ;;
+	      *) temp_rpath="$temp_rpath$absdir:" ;;
+	      esac
+	    fi
+
+	    # Hardcode the library path.
+	    # Skip directories that are in the system default run-time
+	    # search path.
+	    case " $sys_lib_dlsearch_path " in
+	    *" $absdir "*) ;;
+	    *)
+	      case "$compile_rpath " in
+	      *" $absdir "*) ;;
+	      *) compile_rpath="$compile_rpath $absdir"
+	      esac
+	      ;;
+	    esac
+	    case " $sys_lib_dlsearch_path " in
+	    *" $libdir "*) ;;
+	    *)
+	      case "$finalize_rpath " in
+	      *" $libdir "*) ;;
+	      *) finalize_rpath="$finalize_rpath $libdir"
+	      esac
+	      ;;
+	    esac
+	  fi # $linkmode,$pass = prog,link...
+
+	  if test "$alldeplibs" = yes &&
+	     { test "$deplibs_check_method" = pass_all ||
+	       { test "$build_libtool_libs" = yes &&
+		 test -n "$library_names"; }; }; then
+	    # We only need to search for static libraries
+	    continue
+	  fi
+	fi
+
+	link_static=no # Whether the deplib will be linked statically
+	use_static_libs=$prefer_static_libs
+	if test "$use_static_libs" = built && test "$installed" = yes; then
+	  use_static_libs=no
+	fi
+	if test -n "$library_names" &&
+	   { test "$use_static_libs" = no || test -z "$old_library"; }; then
+	  case $host in
+	  *cygwin* | *mingw* | *cegcc*)
+	      # No point in relinking DLLs because paths are not encoded
+	      notinst_deplibs="$notinst_deplibs $lib"
+	      need_relink=no
+	    ;;
+	  *)
+	    if test "$installed" = no; then
+	      notinst_deplibs="$notinst_deplibs $lib"
+	      need_relink=yes
+	    fi
+	    ;;
+	  esac
+	  # This is a shared library
+
+	  # Warn about portability, can't link against -module's on some
+	  # systems (darwin).  Don't bleat about dlopened modules though!
+	  dlopenmodule=""
+	  for dlpremoduletest in $dlprefiles; do
+	    if test "X$dlpremoduletest" = "X$lib"; then
+	      dlopenmodule="$dlpremoduletest"
+	      break
+	    fi
+	  done
+	  if test -z "$dlopenmodule" && test "$shouldnotlink" = yes && test "$pass" = link; then
+	    $ECHO
+	    if test "$linkmode" = prog; then
+	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
+	    else
+	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
+	    fi
+	    $ECHO "*** $linklib is not portable!"
+	  fi
+	  if test "$linkmode" = lib &&
+	     test "$hardcode_into_libs" = yes; then
+	    # Hardcode the library path.
+	    # Skip directories that are in the system default run-time
+	    # search path.
+	    case " $sys_lib_dlsearch_path " in
+	    *" $absdir "*) ;;
+	    *)
+	      case "$compile_rpath " in
+	      *" $absdir "*) ;;
+	      *) compile_rpath="$compile_rpath $absdir"
+	      esac
+	      ;;
+	    esac
+	    case " $sys_lib_dlsearch_path " in
+	    *" $libdir "*) ;;
+	    *)
+	      case "$finalize_rpath " in
+	      *" $libdir "*) ;;
+	      *) finalize_rpath="$finalize_rpath $libdir"
+	      esac
+	      ;;
+	    esac
+	  fi
+
+	  if test -n "$old_archive_from_expsyms_cmds"; then
+	    # figure out the soname
+	    set dummy $library_names
+	    shift
+	    realname="$1"
+	    shift
+	    libname=`eval "\\$ECHO \"$libname_spec\""`
+	    # use dlname if we got it. it's perfectly good, no?
+	    if test -n "$dlname"; then
+	      soname="$dlname"
+	    elif test -n "$soname_spec"; then
+	      # bleh windows
+	      case $host in
+	      *cygwin* | mingw* | *cegcc*)
+	        func_arith $current - $age
+		major=$func_arith_result
+		versuffix="-$major"
+		;;
+	      esac
+	      eval soname=\"$soname_spec\"
+	    else
+	      soname="$realname"
+	    fi
+
+	    # Make a new name for the extract_expsyms_cmds to use
+	    soroot="$soname"
+	    func_basename "$soroot"
+	    soname="$func_basename_result"
+	    func_stripname 'lib' '.dll' "$soname"
+	    newlib=libimp-$func_stripname_result.a
+
+	    # If the library has no export list, then create one now
+	    if test -f "$output_objdir/$soname-def"; then :
+	    else
+	      func_verbose "extracting exported symbol list from \`$soname'"
+	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
+	    fi
+
+	    # Create $newlib
+	    if test -f "$output_objdir/$newlib"; then :; else
+	      func_verbose "generating import library for \`$soname'"
+	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
+	    fi
+	    # make sure the library variables are pointing to the new library
+	    dir=$output_objdir
+	    linklib=$newlib
+	  fi # test -n "$old_archive_from_expsyms_cmds"
+
+	  if test "$linkmode" = prog || test "$mode" != relink; then
+	    add_shlibpath=
+	    add_dir=
+	    add=
+	    lib_linked=yes
+	    case $hardcode_action in
+	    immediate | unsupported)
+	      if test "$hardcode_direct" = no; then
+		add="$dir/$linklib"
+		case $host in
+		  *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;;
+		  *-*-sysv4*uw2*) add_dir="-L$dir" ;;
+		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
+		    *-*-unixware7*) add_dir="-L$dir" ;;
+		  *-*-darwin* )
+		    # if the lib is a (non-dlopened) module then we can not
+		    # link against it, someone is ignoring the earlier warnings
+		    if /usr/bin/file -L $add 2> /dev/null |
+			 $GREP ": [^:]* bundle" >/dev/null ; then
+		      if test "X$dlopenmodule" != "X$lib"; then
+			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
+			if test -z "$old_library" ; then
+			  $ECHO
+			  $ECHO "*** And there doesn't seem to be a static archive available"
+			  $ECHO "*** The link will probably fail, sorry"
+			else
+			  add="$dir/$old_library"
+			fi
+		      elif test -n "$old_library"; then
+			add="$dir/$old_library"
+		      fi
+		    fi
+		esac
+	      elif test "$hardcode_minus_L" = no; then
+		case $host in
+		*-*-sunos*) add_shlibpath="$dir" ;;
+		esac
+		add_dir="-L$dir"
+		add="-l$name"
+	      elif test "$hardcode_shlibpath_var" = no; then
+		add_shlibpath="$dir"
+		add="-l$name"
+	      else
+		lib_linked=no
+	      fi
+	      ;;
+	    relink)
+	      if test "$hardcode_direct" = yes &&
+	         test "$hardcode_direct_absolute" = no; then
+		add="$dir/$linklib"
+	      elif test "$hardcode_minus_L" = yes; then
+		add_dir="-L$dir"
+		# Try looking first in the location we're being installed to.
+		if test -n "$inst_prefix_dir"; then
+		  case $libdir in
+		    [\\/]*)
+		      add_dir="$add_dir -L$inst_prefix_dir$libdir"
+		      ;;
+		  esac
+		fi
+		add="-l$name"
+	      elif test "$hardcode_shlibpath_var" = yes; then
+		add_shlibpath="$dir"
+		add="-l$name"
+	      else
+		lib_linked=no
+	      fi
+	      ;;
+	    *) lib_linked=no ;;
+	    esac
+
+	    if test "$lib_linked" != yes; then
+	      func_fatal_configuration "unsupported hardcode properties"
+	    fi
+
+	    if test -n "$add_shlibpath"; then
+	      case :$compile_shlibpath: in
+	      *":$add_shlibpath:"*) ;;
+	      *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;;
+	      esac
+	    fi
+	    if test "$linkmode" = prog; then
+	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
+	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
+	    else
+	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
+	      test -n "$add" && deplibs="$add $deplibs"
+	      if test "$hardcode_direct" != yes &&
+		 test "$hardcode_minus_L" != yes &&
+		 test "$hardcode_shlibpath_var" = yes; then
+		case :$finalize_shlibpath: in
+		*":$libdir:"*) ;;
+		*) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
+		esac
+	      fi
+	    fi
+	  fi
+
+	  if test "$linkmode" = prog || test "$mode" = relink; then
+	    add_shlibpath=
+	    add_dir=
+	    add=
+	    # Finalize command for both is simple: just hardcode it.
+	    if test "$hardcode_direct" = yes &&
+	       test "$hardcode_direct_absolute" = no; then
+	      add="$libdir/$linklib"
+	    elif test "$hardcode_minus_L" = yes; then
+	      add_dir="-L$libdir"
+	      add="-l$name"
+	    elif test "$hardcode_shlibpath_var" = yes; then
+	      case :$finalize_shlibpath: in
+	      *":$libdir:"*) ;;
+	      *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
+	      esac
+	      add="-l$name"
+	    elif test "$hardcode_automatic" = yes; then
+	      if test -n "$inst_prefix_dir" &&
+		 test -f "$inst_prefix_dir$libdir/$linklib" ; then
+		add="$inst_prefix_dir$libdir/$linklib"
+	      else
+		add="$libdir/$linklib"
+	      fi
+	    else
+	      # We cannot seem to hardcode it, guess we'll fake it.
+	      add_dir="-L$libdir"
+	      # Try looking first in the location we're being installed to.
+	      if test -n "$inst_prefix_dir"; then
+		case $libdir in
+		  [\\/]*)
+		    add_dir="$add_dir -L$inst_prefix_dir$libdir"
+		    ;;
+		esac
+	      fi
+	      add="-l$name"
+	    fi
+
+	    if test "$linkmode" = prog; then
+	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
+	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
+	    else
+	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
+	      test -n "$add" && deplibs="$add $deplibs"
+	    fi
+	  fi
+	elif test "$linkmode" = prog; then
+	  # Here we assume that one of hardcode_direct or hardcode_minus_L
+	  # is not unsupported.  This is valid on all known static and
+	  # shared platforms.
+	  if test "$hardcode_direct" != unsupported; then
+	    test -n "$old_library" && linklib="$old_library"
+	    compile_deplibs="$dir/$linklib $compile_deplibs"
+	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
+	  else
+	    compile_deplibs="-l$name -L$dir $compile_deplibs"
+	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
+	  fi
+	elif test "$build_libtool_libs" = yes; then
+	  # Not a shared library
+	  if test "$deplibs_check_method" != pass_all; then
+	    # We're trying link a shared library against a static one
+	    # but the system doesn't support it.
+
+	    # Just print a warning and add the library to dependency_libs so
+	    # that the program can be linked against the static library.
+	    $ECHO
+	    $ECHO "*** Warning: This system can not link to static lib archive $lib."
+	    $ECHO "*** I have the capability to make that library automatically link in when"
+	    $ECHO "*** you link to this library.  But I can only do this if you have a"
+	    $ECHO "*** shared version of the library, which you do not appear to have."
+	    if test "$module" = yes; then
+	      $ECHO "*** But as you try to build a module library, libtool will still create "
+	      $ECHO "*** a static module, that should work as long as the dlopening application"
+	      $ECHO "*** is linked with the -dlopen flag to resolve symbols at runtime."
+	      if test -z "$global_symbol_pipe"; then
+		$ECHO
+		$ECHO "*** However, this would only work if libtool was able to extract symbol"
+		$ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could"
+		$ECHO "*** not find such a program.  So, this module is probably useless."
+		$ECHO "*** \`nm' from GNU binutils and a full rebuild may help."
+	      fi
+	      if test "$build_old_libs" = no; then
+		build_libtool_libs=module
+		build_old_libs=yes
+	      else
+		build_libtool_libs=no
+	      fi
+	    fi
+	  else
+	    deplibs="$dir/$old_library $deplibs"
+	    link_static=yes
+	  fi
+	fi # link shared/static library?
+
+	if test "$linkmode" = lib; then
+	  if test -n "$dependency_libs" &&
+	     { test "$hardcode_into_libs" != yes ||
+	       test "$build_old_libs" = yes ||
+	       test "$link_static" = yes; }; then
+	    # Extract -R from dependency_libs
+	    temp_deplibs=
+	    for libdir in $dependency_libs; do
+	      case $libdir in
+	      -R*) func_stripname '-R' '' "$libdir"
+	           temp_xrpath=$func_stripname_result
+		   case " $xrpath " in
+		   *" $temp_xrpath "*) ;;
+		   *) xrpath="$xrpath $temp_xrpath";;
+		   esac;;
+	      *) temp_deplibs="$temp_deplibs $libdir";;
+	      esac
+	    done
+	    dependency_libs="$temp_deplibs"
+	  fi
+
+	  newlib_search_path="$newlib_search_path $absdir"
+	  # Link against this library
+	  test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
+	  # ... and its dependency_libs
+	  tmp_libs=
+	  for deplib in $dependency_libs; do
+	    newdependency_libs="$deplib $newdependency_libs"
+	    if $opt_duplicate_deps ; then
+	      case "$tmp_libs " in
+	      *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+	      esac
+	    fi
+	    tmp_libs="$tmp_libs $deplib"
+	  done
+
+	  if test "$link_all_deplibs" != no; then
+	    # Add the search paths of all dependency libraries
+	    for deplib in $dependency_libs; do
+	      case $deplib in
+	      -L*) path="$deplib" ;;
+	      *.la)
+	        func_dirname "$deplib" "" "."
+		dir="$func_dirname_result"
+		# We need an absolute path.
+		case $dir in
+		[\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;;
+		*)
+		  absdir=`cd "$dir" && pwd`
+		  if test -z "$absdir"; then
+		    func_warning "cannot determine absolute directory name of \`$dir'"
+		    absdir="$dir"
+		  fi
+		  ;;
+		esac
+		if $GREP "^installed=no" $deplib > /dev/null; then
+		case $host in
+		*-*-darwin*)
+		  depdepl=
+		  eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
+		  if test -n "$deplibrary_names" ; then
+		    for tmp in $deplibrary_names ; do
+		      depdepl=$tmp
+		    done
+		    if test -f "$absdir/$objdir/$depdepl" ; then
+		      depdepl="$absdir/$objdir/$depdepl"
+		      darwin_install_name=`${OTOOL} -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
+                      if test -z "$darwin_install_name"; then
+                          darwin_install_name=`${OTOOL64} -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
+                      fi
+		      compiler_flags="$compiler_flags ${wl}-dylib_file ${wl}${darwin_install_name}:${depdepl}"
+		      linker_flags="$linker_flags -dylib_file ${darwin_install_name}:${depdepl}"
+		      path=
+		    fi
+		  fi
+		  ;;
+		*)
+		  path="-L$absdir/$objdir"
+		  ;;
+		esac
+		else
+		  eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
+		  test -z "$libdir" && \
+		    func_fatal_error "\`$deplib' is not a valid libtool archive"
+		  test "$absdir" != "$libdir" && \
+		    func_warning "\`$deplib' seems to be moved"
+
+		  path="-L$absdir"
+		fi
+		;;
+	      esac
+	      case " $deplibs " in
+	      *" $path "*) ;;
+	      *) deplibs="$path $deplibs" ;;
+	      esac
+	    done
+	  fi # link_all_deplibs != no
+	fi # linkmode = lib
+      done # for deplib in $libs
+      if test "$pass" = link; then
+	if test "$linkmode" = "prog"; then
+	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
+	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
+	else
+	  compiler_flags="$compiler_flags "`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	fi
+      fi
+      dependency_libs="$newdependency_libs"
+      if test "$pass" = dlpreopen; then
+	# Link the dlpreopened libraries before other libraries
+	for deplib in $save_deplibs; do
+	  deplibs="$deplib $deplibs"
+	done
+      fi
+      if test "$pass" != dlopen; then
+	if test "$pass" != conv; then
+	  # Make sure lib_search_path contains only unique directories.
+	  lib_search_path=
+	  for dir in $newlib_search_path; do
+	    case "$lib_search_path " in
+	    *" $dir "*) ;;
+	    *) lib_search_path="$lib_search_path $dir" ;;
+	    esac
+	  done
+	  newlib_search_path=
+	fi
+
+	if test "$linkmode,$pass" != "prog,link"; then
+	  vars="deplibs"
+	else
+	  vars="compile_deplibs finalize_deplibs"
+	fi
+	for var in $vars dependency_libs; do
+	  # Add libraries to $var in reverse order
+	  eval tmp_libs=\"\$$var\"
+	  new_libs=
+	  for deplib in $tmp_libs; do
+	    # FIXME: Pedantically, this is the right thing to do, so
+	    #        that some nasty dependency loop isn't accidentally
+	    #        broken:
+	    #new_libs="$deplib $new_libs"
+	    # Pragmatically, this seems to cause very few problems in
+	    # practice:
+	    case $deplib in
+	    -L*) new_libs="$deplib $new_libs" ;;
+	    -R*) ;;
+	    *)
+	      # And here is the reason: when a library appears more
+	      # than once as an explicit dependence of a library, or
+	      # is implicitly linked in more than once by the
+	      # compiler, it is considered special, and multiple
+	      # occurrences thereof are not removed.  Compare this
+	      # with having the same library being listed as a
+	      # dependency of multiple other libraries: in this case,
+	      # we know (pedantically, we assume) the library does not
+	      # need to be listed more than once, so we keep only the
+	      # last copy.  This is not always right, but it is rare
+	      # enough that we require users that really mean to play
+	      # such unportable linking tricks to link the library
+	      # using -Wl,-lname, so that libtool does not consider it
+	      # for duplicate removal.
+	      case " $specialdeplibs " in
+	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
+	      *)
+		case " $new_libs " in
+		*" $deplib "*) ;;
+		*) new_libs="$deplib $new_libs" ;;
+		esac
+		;;
+	      esac
+	      ;;
+	    esac
+	  done
+	  tmp_libs=
+	  for deplib in $new_libs; do
+	    case $deplib in
+	    -L*)
+	      case " $tmp_libs " in
+	      *" $deplib "*) ;;
+	      *) tmp_libs="$tmp_libs $deplib" ;;
+	      esac
+	      ;;
+	    *) tmp_libs="$tmp_libs $deplib" ;;
+	    esac
+	  done
+	  eval $var=\"$tmp_libs\"
+	done # for var
+      fi
+      # Last step: remove runtime libs from dependency_libs
+      # (they stay in deplibs)
+      tmp_libs=
+      for i in $dependency_libs ; do
+	case " $predeps $postdeps $compiler_lib_search_path " in
+	*" $i "*)
+	  i=""
+	  ;;
+	esac
+	if test -n "$i" ; then
+	  tmp_libs="$tmp_libs $i"
+	fi
+      done
+      dependency_libs=$tmp_libs
+    done # for pass
+    if test "$linkmode" = prog; then
+      dlfiles="$newdlfiles"
+    fi
+    if test "$linkmode" = prog || test "$linkmode" = lib; then
+      dlprefiles="$newdlprefiles"
+    fi
+
+    case $linkmode in
+    oldlib)
+      if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
+	func_warning "\`-dlopen' is ignored for archives"
+      fi
+
+      case " $deplibs" in
+      *\ -l* | *\ -L*)
+	func_warning "\`-l' and \`-L' are ignored for archives" ;;
+      esac
+
+      test -n "$rpath" && \
+	func_warning "\`-rpath' is ignored for archives"
+
+      test -n "$xrpath" && \
+	func_warning "\`-R' is ignored for archives"
+
+      test -n "$vinfo" && \
+	func_warning "\`-version-info/-version-number' is ignored for archives"
+
+      test -n "$release" && \
+	func_warning "\`-release' is ignored for archives"
+
+      test -n "$export_symbols$export_symbols_regex" && \
+	func_warning "\`-export-symbols' is ignored for archives"
+
+      # Now set the variables for building old libraries.
+      build_libtool_libs=no
+      oldlibs="$output"
+      objs="$objs$old_deplibs"
+      ;;
+
+    lib)
+      # Make sure we only generate libraries of the form `libNAME.la'.
+      case $outputname in
+      lib*)
+	func_stripname 'lib' '.la' "$outputname"
+	name=$func_stripname_result
+	eval shared_ext=\"$shrext_cmds\"
+	eval libname=\"$libname_spec\"
+	;;
+      *)
+	test "$module" = no && \
+	  func_fatal_help "libtool library \`$output' must begin with \`lib'"
+
+	if test "$need_lib_prefix" != no; then
+	  # Add the "lib" prefix for modules if required
+	  func_stripname '' '.la' "$outputname"
+	  name=$func_stripname_result
+	  eval shared_ext=\"$shrext_cmds\"
+	  eval libname=\"$libname_spec\"
+	else
+	  func_stripname '' '.la' "$outputname"
+	  libname=$func_stripname_result
+	fi
+	;;
+      esac
+
+      if test -n "$objs"; then
+	if test "$deplibs_check_method" != pass_all; then
+	  func_fatal_error "cannot build libtool library \`$output' from non-libtool objects on this host:$objs"
+	else
+	  $ECHO
+	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
+	  $ECHO "*** objects $objs is not portable!"
+	  libobjs="$libobjs $objs"
+	fi
+      fi
+
+      test "$dlself" != no && \
+	func_warning "\`-dlopen self' is ignored for libtool libraries"
+
+      set dummy $rpath
+      shift
+      test "$#" -gt 1 && \
+	func_warning "ignoring multiple \`-rpath's for a libtool library"
+
+      install_libdir="$1"
+
+      oldlibs=
+      if test -z "$rpath"; then
+	if test "$build_libtool_libs" = yes; then
+	  # Building a libtool convenience library.
+	  # Some compilers have problems with a `.al' extension so
+	  # convenience libraries should have the same extension an
+	  # archive normally would.
+	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
+	  build_libtool_libs=convenience
+	  build_old_libs=yes
+	fi
+
+	test -n "$vinfo" && \
+	  func_warning "\`-version-info/-version-number' is ignored for convenience libraries"
+
+	test -n "$release" && \
+	  func_warning "\`-release' is ignored for convenience libraries"
+      else
+
+	# Parse the version information argument.
+	save_ifs="$IFS"; IFS=':'
+	set dummy $vinfo 0 0 0
+	shift
+	IFS="$save_ifs"
+
+	test -n "$7" && \
+	  func_fatal_help "too many parameters to \`-version-info'"
+
+	# convert absolute version numbers to libtool ages
+	# this retains compatibility with .la files and attempts
+	# to make the code below a bit more comprehensible
+
+	case $vinfo_number in
+	yes)
+	  number_major="$1"
+	  number_minor="$2"
+	  number_revision="$3"
+	  #
+	  # There are really only two kinds -- those that
+	  # use the current revision as the major version
+	  # and those that subtract age and use age as
+	  # a minor version.  But, then there is irix
+	  # which has an extra 1 added just for fun
+	  #
+	  case $version_type in
+	  darwin|linux|osf|windows|none)
+	    func_arith $number_major + $number_minor
+	    current=$func_arith_result
+	    age="$number_minor"
+	    revision="$number_revision"
+	    ;;
+	  freebsd-aout|freebsd-elf|sunos)
+	    current="$number_major"
+	    revision="$number_minor"
+	    age="0"
+	    ;;
+	  irix|nonstopux)
+	    func_arith $number_major + $number_minor
+	    current=$func_arith_result
+	    age="$number_minor"
+	    revision="$number_minor"
+	    lt_irix_increment=no
+	    ;;
+	  esac
+	  ;;
+	no)
+	  current="$1"
+	  revision="$2"
+	  age="$3"
+	  ;;
+	esac
+
+	# Check that each of the things are valid numbers.
+	case $current in
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+	*)
+	  func_error "CURRENT \`$current' must be a nonnegative integer"
+	  func_fatal_error "\`$vinfo' is not valid version information"
+	  ;;
+	esac
+
+	case $revision in
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+	*)
+	  func_error "REVISION \`$revision' must be a nonnegative integer"
+	  func_fatal_error "\`$vinfo' is not valid version information"
+	  ;;
+	esac
+
+	case $age in
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
+	*)
+	  func_error "AGE \`$age' must be a nonnegative integer"
+	  func_fatal_error "\`$vinfo' is not valid version information"
+	  ;;
+	esac
+
+	if test "$age" -gt "$current"; then
+	  func_error "AGE \`$age' is greater than the current interface number \`$current'"
+	  func_fatal_error "\`$vinfo' is not valid version information"
+	fi
+
+	# Calculate the version variables.
+	major=
+	versuffix=
+	verstring=
+	case $version_type in
+	none) ;;
+
+	darwin)
+	  # Like Linux, but with the current version available in
+	  # verstring for coding it into the library header
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix="$major.$age.$revision"
+	  # Darwin ld doesn't like 0 for these options...
+	  func_arith $current + 1
+	  minor_current=$func_arith_result
+	  xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision"
+	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
+	  ;;
+
+	freebsd-aout)
+	  major=".$current"
+	  versuffix=".$current.$revision";
+	  ;;
+
+	freebsd-elf)
+	  major=".$current"
+	  versuffix=".$current"
+	  ;;
+
+	irix | nonstopux)
+	  if test "X$lt_irix_increment" = "Xno"; then
+	    func_arith $current - $age
+	  else
+	    func_arith $current - $age + 1
+	  fi
+	  major=$func_arith_result
+
+	  case $version_type in
+	    nonstopux) verstring_prefix=nonstopux ;;
+	    *)         verstring_prefix=sgi ;;
+	  esac
+	  verstring="$verstring_prefix$major.$revision"
+
+	  # Add in all the interfaces that we are compatible with.
+	  loop=$revision
+	  while test "$loop" -ne 0; do
+	    func_arith $revision - $loop
+	    iface=$func_arith_result
+	    func_arith $loop - 1
+	    loop=$func_arith_result
+	    verstring="$verstring_prefix$major.$iface:$verstring"
+	  done
+
+	  # Before this point, $major must not contain `.'.
+	  major=.$major
+	  versuffix="$major.$revision"
+	  ;;
+
+	linux)
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix="$major.$age.$revision"
+	  ;;
+
+	osf)
+	  func_arith $current - $age
+	  major=.$func_arith_result
+	  versuffix=".$current.$age.$revision"
+	  verstring="$current.$age.$revision"
+
+	  # Add in all the interfaces that we are compatible with.
+	  loop=$age
+	  while test "$loop" -ne 0; do
+	    func_arith $current - $loop
+	    iface=$func_arith_result
+	    func_arith $loop - 1
+	    loop=$func_arith_result
+	    verstring="$verstring:${iface}.0"
+	  done
+
+	  # Make executables depend on our current version.
+	  verstring="$verstring:${current}.0"
+	  ;;
+
+	qnx)
+	  major=".$current"
+	  versuffix=".$current"
+	  ;;
+
+	sunos)
+	  major=".$current"
+	  versuffix=".$current.$revision"
+	  ;;
+
+	windows)
+	  # Use '-' rather than '.', since we only want one
+	  # extension on DOS 8.3 filesystems.
+	  func_arith $current - $age
+	  major=$func_arith_result
+	  versuffix="-$major"
+	  ;;
+
+	*)
+	  func_fatal_configuration "unknown library version type \`$version_type'"
+	  ;;
+	esac
+
+	# Clear the version info if we defaulted, and they specified a release.
+	if test -z "$vinfo" && test -n "$release"; then
+	  major=
+	  case $version_type in
+	  darwin)
+	    # we can't check for "0.0" in archive_cmds due to quoting
+	    # problems, so we reset it completely
+	    verstring=
+	    ;;
+	  *)
+	    verstring="0.0"
+	    ;;
+	  esac
+	  if test "$need_version" = no; then
+	    versuffix=
+	  else
+	    versuffix=".0.0"
+	  fi
+	fi
+
+	# Remove version info from name if versioning should be avoided
+	if test "$avoid_version" = yes && test "$need_version" = no; then
+	  major=
+	  versuffix=
+	  verstring=""
+	fi
+
+	# Check to see if the archive will have undefined symbols.
+	if test "$allow_undefined" = yes; then
+	  if test "$allow_undefined_flag" = unsupported; then
+	    func_warning "undefined symbols not allowed in $host shared libraries"
+	    build_libtool_libs=no
+	    build_old_libs=yes
+	  fi
+	else
+	  # Don't allow undefined symbols.
+	  allow_undefined_flag="$no_undefined_flag"
+	fi
+
+      fi
+
+      func_generate_dlsyms "$libname" "$libname" "yes"
+      libobjs="$libobjs $symfileobj"
+      test "X$libobjs" = "X " && libobjs=
+
+      if test "$mode" != relink; then
+	# Remove our outputs, but don't remove object files since they
+	# may have been created when compiling PIC objects.
+	removelist=
+	tempremovelist=`$ECHO "$output_objdir/*"`
+	for p in $tempremovelist; do
+	  case $p in
+	    *.$objext | *.gcno)
+	       ;;
+	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*)
+	       if test "X$precious_files_regex" != "X"; then
+		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
+		 then
+		   continue
+		 fi
+	       fi
+	       removelist="$removelist $p"
+	       ;;
+	    *) ;;
+	  esac
+	done
+	test -n "$removelist" && \
+	  func_show_eval "${RM}r \$removelist"
+      fi
+
+      # Now set the variables for building old libraries.
+      if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then
+	oldlibs="$oldlibs $output_objdir/$libname.$libext"
+
+	# Transform .lo files to .o files.
+	oldobjs="$objs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP`
+      fi
+
+      # Eliminate all temporary directories.
+      #for path in $notinst_path; do
+      #	lib_search_path=`$ECHO "X$lib_search_path " | $Xsed -e "s% $path % %g"`
+      #	deplibs=`$ECHO "X$deplibs " | $Xsed -e "s% -L$path % %g"`
+      #	dependency_libs=`$ECHO "X$dependency_libs " | $Xsed -e "s% -L$path % %g"`
+      #done
+
+      if test -n "$xrpath"; then
+	# If the user specified any rpath flags, then add them.
+	temp_xrpath=
+	for libdir in $xrpath; do
+	  temp_xrpath="$temp_xrpath -R$libdir"
+	  case "$finalize_rpath " in
+	  *" $libdir "*) ;;
+	  *) finalize_rpath="$finalize_rpath $libdir" ;;
+	  esac
+	done
+	if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then
+	  dependency_libs="$temp_xrpath $dependency_libs"
+	fi
+      fi
+
+      # Make sure dlfiles contains only unique files that won't be dlpreopened
+      old_dlfiles="$dlfiles"
+      dlfiles=
+      for lib in $old_dlfiles; do
+	case " $dlprefiles $dlfiles " in
+	*" $lib "*) ;;
+	*) dlfiles="$dlfiles $lib" ;;
+	esac
+      done
+
+      # Make sure dlprefiles contains only unique files
+      old_dlprefiles="$dlprefiles"
+      dlprefiles=
+      for lib in $old_dlprefiles; do
+	case "$dlprefiles " in
+	*" $lib "*) ;;
+	*) dlprefiles="$dlprefiles $lib" ;;
+	esac
+      done
+
+      if test "$build_libtool_libs" = yes; then
+	if test -n "$rpath"; then
+	  case $host in
+	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc*)
+	    # these systems don't actually have a c library (as such)!
+	    ;;
+	  *-*-rhapsody* | *-*-darwin1.[012])
+	    # Rhapsody C library is in the System framework
+	    deplibs="$deplibs System.ltframework"
+	    ;;
+	  *-*-netbsd*)
+	    # Don't link with libc until the a.out ld.so is fixed.
+	    ;;
+	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	    # Do not include libc due to us having libc/libc_r.
+	    ;;
+	  *-*-sco3.2v5* | *-*-sco5v6*)
+	    # Causes problems with __ctype
+	    ;;
+	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
+	    # Compiler inserts libc in the correct place for threads to work
+	    ;;
+	  *)
+	    # Add libc to deplibs on all other systems if necessary.
+	    if test "$build_libtool_need_lc" = "yes"; then
+	      deplibs="$deplibs -lc"
+	    fi
+	    ;;
+	  esac
+	fi
+
+	# Transform deplibs into only deplibs that can be linked in shared.
+	name_save=$name
+	libname_save=$libname
+	release_save=$release
+	versuffix_save=$versuffix
+	major_save=$major
+	# I'm not sure if I'm treating the release correctly.  I think
+	# release should show up in the -l (ie -lgmp5) so we don't want to
+	# add it in twice.  Is that correct?
+	release=""
+	versuffix=""
+	major=""
+	newdeplibs=
+	droppeddeps=no
+	case $deplibs_check_method in
+	pass_all)
+	  # Don't check for shared/static.  Everything works.
+	  # This might be a little naive.  We might want to check
+	  # whether the library exists or not.  But this is on
+	  # osf3 & osf4 and I'm not really sure... Just
+	  # implementing what was already the behavior.
+	  newdeplibs=$deplibs
+	  ;;
+	test_compile)
+	  # This code stresses the "libraries are programs" paradigm to its
+	  # limits. Maybe even breaks it.  We compile a program, linking it
+	  # against the deplibs as a proxy for the library.  Then we can check
+	  # whether they linked in statically or dynamically with ldd.
+	  $opt_dry_run || $RM conftest.c
+	  cat > conftest.c <<EOF
+	  int main() { return 0; }
+EOF
+	  $opt_dry_run || $RM conftest
+	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
+	    ldd_output=`ldd conftest`
+	    for i in $deplibs; do
+	      case $i in
+	      -l*)
+		func_stripname -l '' "$i"
+		name=$func_stripname_result
+		if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		  case " $predeps $postdeps " in
+		  *" $i "*)
+		    newdeplibs="$newdeplibs $i"
+		    i=""
+		    ;;
+		  esac
+		fi
+		if test -n "$i" ; then
+		  libname=`eval "\\$ECHO \"$libname_spec\""`
+		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
+		  set dummy $deplib_matches; shift
+		  deplib_match=$1
+		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
+		    newdeplibs="$newdeplibs $i"
+		  else
+		    droppeddeps=yes
+		    $ECHO
+		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
+		    $ECHO "*** I have the capability to make that library automatically link in when"
+		    $ECHO "*** you link to this library.  But I can only do this if you have a"
+		    $ECHO "*** shared version of the library, which I believe you do not have"
+		    $ECHO "*** because a test_compile did reveal that the linker did not use it for"
+		    $ECHO "*** its dynamic dependency list that programs get resolved with at runtime."
+		  fi
+		fi
+		;;
+	      *)
+		newdeplibs="$newdeplibs $i"
+		;;
+	      esac
+	    done
+	  else
+	    # Error occurred in the first compile.  Let's try to salvage
+	    # the situation: Compile a separate program for each library.
+	    for i in $deplibs; do
+	      case $i in
+	      -l*)
+		func_stripname -l '' "$i"
+		name=$func_stripname_result
+		$opt_dry_run || $RM conftest
+		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
+		  ldd_output=`ldd conftest`
+		  if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		    case " $predeps $postdeps " in
+		    *" $i "*)
+		      newdeplibs="$newdeplibs $i"
+		      i=""
+		      ;;
+		    esac
+		  fi
+		  if test -n "$i" ; then
+		    libname=`eval "\\$ECHO \"$libname_spec\""`
+		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
+		    set dummy $deplib_matches; shift
+		    deplib_match=$1
+		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
+		      newdeplibs="$newdeplibs $i"
+		    else
+		      droppeddeps=yes
+		      $ECHO
+		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
+		      $ECHO "*** I have the capability to make that library automatically link in when"
+		      $ECHO "*** you link to this library.  But I can only do this if you have a"
+		      $ECHO "*** shared version of the library, which you do not appear to have"
+		      $ECHO "*** because a test_compile did reveal that the linker did not use this one"
+		      $ECHO "*** as a dynamic dependency that programs can get resolved with at runtime."
+		    fi
+		  fi
+		else
+		  droppeddeps=yes
+		  $ECHO
+		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
+		  $ECHO "*** make it link in!  You will probably need to install it or some"
+		  $ECHO "*** library that it depends on before this library will be fully"
+		  $ECHO "*** functional.  Installing it before continuing would be even better."
+		fi
+		;;
+	      *)
+		newdeplibs="$newdeplibs $i"
+		;;
+	      esac
+	    done
+	  fi
+	  ;;
+	file_magic*)
+	  set dummy $deplibs_check_method; shift
+	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+	  for a_deplib in $deplibs; do
+	    case $a_deplib in
+	    -l*)
+	      func_stripname -l '' "$a_deplib"
+	      name=$func_stripname_result
+	      if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		case " $predeps $postdeps " in
+		*" $a_deplib "*)
+		  newdeplibs="$newdeplibs $a_deplib"
+		  a_deplib=""
+		  ;;
+		esac
+	      fi
+	      if test -n "$a_deplib" ; then
+		libname=`eval "\\$ECHO \"$libname_spec\""`
+		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
+		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
+		  for potent_lib in $potential_libs; do
+		      # Follow soft links.
+		      if ls -lLd "$potent_lib" 2>/dev/null |
+			 $GREP " -> " >/dev/null; then
+			continue
+		      fi
+		      # The statement above tries to avoid entering an
+		      # endless loop below, in case of cyclic links.
+		      # We might still enter an endless loop, since a link
+		      # loop can be closed while we follow links,
+		      # but so what?
+		      potlib="$potent_lib"
+		      while test -h "$potlib" 2>/dev/null; do
+			potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'`
+			case $potliblink in
+			[\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";;
+			*) potlib=`$ECHO "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";;
+			esac
+		      done
+		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
+			 $SED -e 10q |
+			 $EGREP "$file_magic_regex" > /dev/null; then
+			newdeplibs="$newdeplibs $a_deplib"
+			a_deplib=""
+			break 2
+		      fi
+		  done
+		done
+	      fi
+	      if test -n "$a_deplib" ; then
+		droppeddeps=yes
+		$ECHO
+		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
+		$ECHO "*** I have the capability to make that library automatically link in when"
+		$ECHO "*** you link to this library.  But I can only do this if you have a"
+		$ECHO "*** shared version of the library, which you do not appear to have"
+		$ECHO "*** because I did check the linker path looking for a file starting"
+		if test -z "$potlib" ; then
+		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
+		else
+		  $ECHO "*** with $libname and none of the candidates passed a file format test"
+		  $ECHO "*** using a file magic. Last file checked: $potlib"
+		fi
+	      fi
+	      ;;
+	    *)
+	      # Add a -L argument.
+	      newdeplibs="$newdeplibs $a_deplib"
+	      ;;
+	    esac
+	  done # Gone through all deplibs.
+	  ;;
+	match_pattern*)
+	  set dummy $deplibs_check_method; shift
+	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
+	  for a_deplib in $deplibs; do
+	    case $a_deplib in
+	    -l*)
+	      func_stripname -l '' "$a_deplib"
+	      name=$func_stripname_result
+	      if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		case " $predeps $postdeps " in
+		*" $a_deplib "*)
+		  newdeplibs="$newdeplibs $a_deplib"
+		  a_deplib=""
+		  ;;
+		esac
+	      fi
+	      if test -n "$a_deplib" ; then
+		libname=`eval "\\$ECHO \"$libname_spec\""`
+		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
+		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
+		  for potent_lib in $potential_libs; do
+		    potlib="$potent_lib" # see symlink-check above in file_magic test
+		    if eval "\$ECHO \"X$potent_lib\"" 2>/dev/null | $Xsed -e 10q | \
+		       $EGREP "$match_pattern_regex" > /dev/null; then
+		      newdeplibs="$newdeplibs $a_deplib"
+		      a_deplib=""
+		      break 2
+		    fi
+		  done
+		done
+	      fi
+	      if test -n "$a_deplib" ; then
+		droppeddeps=yes
+		$ECHO
+		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
+		$ECHO "*** I have the capability to make that library automatically link in when"
+		$ECHO "*** you link to this library.  But I can only do this if you have a"
+		$ECHO "*** shared version of the library, which you do not appear to have"
+		$ECHO "*** because I did check the linker path looking for a file starting"
+		if test -z "$potlib" ; then
+		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
+		else
+		  $ECHO "*** with $libname and none of the candidates passed a file format test"
+		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
+		fi
+	      fi
+	      ;;
+	    *)
+	      # Add a -L argument.
+	      newdeplibs="$newdeplibs $a_deplib"
+	      ;;
+	    esac
+	  done # Gone through all deplibs.
+	  ;;
+	none | unknown | *)
+	  newdeplibs=""
+	  tmp_deplibs=`$ECHO "X $deplibs" | $Xsed \
+	      -e 's/ -lc$//' -e 's/ -[LR][^ ]*//g'`
+	  if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+	    for i in $predeps $postdeps ; do
+	      # can't use Xsed below, because $i might contain '/'
+	      tmp_deplibs=`$ECHO "X $tmp_deplibs" | $Xsed -e "s,$i,,"`
+	    done
+	  fi
+	  if $ECHO "X $tmp_deplibs" | $Xsed -e 's/[	 ]//g' |
+	     $GREP . >/dev/null; then
+	    $ECHO
+	    if test "X$deplibs_check_method" = "Xnone"; then
+	      $ECHO "*** Warning: inter-library dependencies are not supported in this platform."
+	    else
+	      $ECHO "*** Warning: inter-library dependencies are not known to be supported."
+	    fi
+	    $ECHO "*** All declared inter-library dependencies are being dropped."
+	    droppeddeps=yes
+	  fi
+	  ;;
+	esac
+	versuffix=$versuffix_save
+	major=$major_save
+	release=$release_save
+	libname=$libname_save
+	name=$name_save
+
+	case $host in
+	*-*-rhapsody* | *-*-darwin1.[012])
+	  # On Rhapsody replace the C library with the System framework
+	  newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
+	  ;;
+	esac
+
+	if test "$droppeddeps" = yes; then
+	  if test "$module" = yes; then
+	    $ECHO
+	    $ECHO "*** Warning: libtool could not satisfy all declared inter-library"
+	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
+	    $ECHO "*** a static module, that should work as long as the dlopening"
+	    $ECHO "*** application is linked with the -dlopen flag."
+	    if test -z "$global_symbol_pipe"; then
+	      $ECHO
+	      $ECHO "*** However, this would only work if libtool was able to extract symbol"
+	      $ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could"
+	      $ECHO "*** not find such a program.  So, this module is probably useless."
+	      $ECHO "*** \`nm' from GNU binutils and a full rebuild may help."
+	    fi
+	    if test "$build_old_libs" = no; then
+	      oldlibs="$output_objdir/$libname.$libext"
+	      build_libtool_libs=module
+	      build_old_libs=yes
+	    else
+	      build_libtool_libs=no
+	    fi
+	  else
+	    $ECHO "*** The inter-library dependencies that have been dropped here will be"
+	    $ECHO "*** automatically added whenever a program is linked with this library"
+	    $ECHO "*** or is declared to -dlopen it."
+
+	    if test "$allow_undefined" = no; then
+	      $ECHO
+	      $ECHO "*** Since this library must not contain undefined symbols,"
+	      $ECHO "*** because either the platform does not support them or"
+	      $ECHO "*** it was explicitly requested with -no-undefined,"
+	      $ECHO "*** libtool will only create a static version of it."
+	      if test "$build_old_libs" = no; then
+		oldlibs="$output_objdir/$libname.$libext"
+		build_libtool_libs=module
+		build_old_libs=yes
+	      else
+		build_libtool_libs=no
+	      fi
+	    fi
+	  fi
+	fi
+	# Done checking deplibs!
+	deplibs=$newdeplibs
+      fi
+      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
+      case $host in
+	*-*-darwin*)
+	  newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	  new_inherited_linker_flags=`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	  deplibs=`$ECHO "X $deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	  ;;
+      esac
+
+      # move library search paths that coincide with paths to not yet
+      # installed libraries to the beginning of the library search list
+      new_libs=
+      for path in $notinst_path; do
+	case " $new_libs " in
+	*" -L$path/$objdir "*) ;;
+	*)
+	  case " $deplibs " in
+	  *" -L$path/$objdir "*)
+	    new_libs="$new_libs -L$path/$objdir" ;;
+	  esac
+	  ;;
+	esac
+      done
+      for deplib in $deplibs; do
+	case $deplib in
+	-L*)
+	  case " $new_libs " in
+	  *" $deplib "*) ;;
+	  *) new_libs="$new_libs $deplib" ;;
+	  esac
+	  ;;
+	*) new_libs="$new_libs $deplib" ;;
+	esac
+      done
+      deplibs="$new_libs"
+
+      # All the library-specific variables (install_libdir is set above).
+      library_names=
+      old_library=
+      dlname=
+
+      # Test again, we may have decided not to build it any more
+      if test "$build_libtool_libs" = yes; then
+	if test "$hardcode_into_libs" = yes; then
+	  # Hardcode the library paths
+	  hardcode_libdirs=
+	  dep_rpath=
+	  rpath="$finalize_rpath"
+	  test "$mode" != relink && rpath="$compile_rpath$rpath"
+	  for libdir in $rpath; do
+	    if test -n "$hardcode_libdir_flag_spec"; then
+	      if test -n "$hardcode_libdir_separator"; then
+		if test -z "$hardcode_libdirs"; then
+		  hardcode_libdirs="$libdir"
+		else
+		  # Just accumulate the unique libdirs.
+		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+		    ;;
+		  *)
+		    hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+		    ;;
+		  esac
+		fi
+	      else
+		eval flag=\"$hardcode_libdir_flag_spec\"
+		dep_rpath="$dep_rpath $flag"
+	      fi
+	    elif test -n "$runpath_var"; then
+	      case "$perm_rpath " in
+	      *" $libdir "*) ;;
+	      *) perm_rpath="$perm_rpath $libdir" ;;
+	      esac
+	    fi
+	  done
+	  # Substitute the hardcoded libdirs into the rpath.
+	  if test -n "$hardcode_libdir_separator" &&
+	     test -n "$hardcode_libdirs"; then
+	    libdir="$hardcode_libdirs"
+	    if test -n "$hardcode_libdir_flag_spec_ld"; then
+	      eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\"
+	    else
+	      eval dep_rpath=\"$hardcode_libdir_flag_spec\"
+	    fi
+	  fi
+	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
+	    # We should set the runpath_var.
+	    rpath=
+	    for dir in $perm_rpath; do
+	      rpath="$rpath$dir:"
+	    done
+	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
+	  fi
+	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
+	fi
+
+	shlibpath="$finalize_shlibpath"
+	test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath"
+	if test -n "$shlibpath"; then
+	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
+	fi
+
+	# Get the real and link names of the library.
+	eval shared_ext=\"$shrext_cmds\"
+	eval library_names=\"$library_names_spec\"
+	set dummy $library_names
+	shift
+	realname="$1"
+	shift
+
+	if test -n "$soname_spec"; then
+	  eval soname=\"$soname_spec\"
+	else
+	  soname="$realname"
+	fi
+	if test -z "$dlname"; then
+	  dlname=$soname
+	fi
+
+	lib="$output_objdir/$realname"
+	linknames=
+	for link
+	do
+	  linknames="$linknames $link"
+	done
+
+	# Use standard objects if they are pic
+	test -z "$pic_flag" && libobjs=`$ECHO "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+	test "X$libobjs" = "X " && libobjs=
+
+	delfiles=
+	if test -n "$export_symbols" && test -n "$include_expsyms"; then
+	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
+	  export_symbols="$output_objdir/$libname.uexp"
+	  delfiles="$delfiles $export_symbols"
+	fi
+
+	orig_export_symbols=
+	case $host_os in
+	cygwin* | mingw* | cegcc*)
+	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
+	    # exporting using user supplied symfile
+	    if test "x`$SED 1q $export_symbols`" != xEXPORTS; then
+	      # and it's NOT already a .def file. Must figure out
+	      # which of the given symbols are data symbols and tag
+	      # them as such. So, trigger use of export_symbols_cmds.
+	      # export_symbols gets reassigned inside the "prepare
+	      # the list of exported symbols" if statement, so the
+	      # include_expsyms logic still works.
+	      orig_export_symbols="$export_symbols"
+	      export_symbols=
+	      always_export_symbols=yes
+	    fi
+	  fi
+	  ;;
+	esac
+
+	# Prepare the list of exported symbols
+	if test -z "$export_symbols"; then
+	  if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then
+	    func_verbose "generating symbol list for \`$libname.la'"
+	    export_symbols="$output_objdir/$libname.exp"
+	    $opt_dry_run || $RM $export_symbols
+	    cmds=$export_symbols_cmds
+	    save_ifs="$IFS"; IFS='~'
+	    for cmd in $cmds; do
+	      IFS="$save_ifs"
+	      eval cmd=\"$cmd\"
+	      func_len " $cmd"
+	      len=$func_len_result
+	      if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+		func_show_eval "$cmd" 'exit $?'
+		skipped_export=false
+	      else
+		# The command line is too long to execute in one step.
+		func_verbose "using reloadable object file for export list..."
+		skipped_export=:
+		# Break out early, otherwise skipped_export may be
+		# set to false by a later but shorter cmd.
+		break
+	      fi
+	    done
+	    IFS="$save_ifs"
+	    if test -n "$export_symbols_regex" && test "X$skipped_export" != "X:"; then
+	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
+	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
+	    fi
+	  fi
+	fi
+
+	if test -n "$export_symbols" && test -n "$include_expsyms"; then
+	  tmp_export_symbols="$export_symbols"
+	  test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols"
+	  $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"'
+	fi
+
+	if test "X$skipped_export" != "X:" && test -n "$orig_export_symbols"; then
+	  # The given exports_symbols file has to be filtered, so filter it.
+	  func_verbose "filter symbol list for \`$libname.la' to tag DATA exports"
+	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
+	  # 's' commands which not all seds can handle. GNU sed should be fine
+	  # though. Also, the filter scales superlinearly with the number of
+	  # global variables. join(1) would be nice here, but unfortunately
+	  # isn't a blessed tool.
+	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
+	  delfiles="$delfiles $export_symbols $output_objdir/$libname.filter"
+	  export_symbols=$output_objdir/$libname.def
+	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
+	fi
+
+	tmp_deplibs=
+	for test_deplib in $deplibs; do
+	  case " $convenience " in
+	  *" $test_deplib "*) ;;
+	  *)
+	    tmp_deplibs="$tmp_deplibs $test_deplib"
+	    ;;
+	  esac
+	done
+	deplibs="$tmp_deplibs"
+
+	if test -n "$convenience"; then
+	  if test -n "$whole_archive_flag_spec" &&
+	    test "$compiler_needs_object" = yes &&
+	    test -z "$libobjs"; then
+	    # extract the archives, so we have objects to list.
+	    # TODO: could optimize this to just extract one archive.
+	    whole_archive_flag_spec=
+	  fi
+	  if test -n "$whole_archive_flag_spec"; then
+	    save_libobjs=$libobjs
+	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
+	    test "X$libobjs" = "X " && libobjs=
+	  else
+	    gentop="$output_objdir/${outputname}x"
+	    generated="$generated $gentop"
+
+	    func_extract_archives $gentop $convenience
+	    libobjs="$libobjs $func_extract_archives_result"
+	    test "X$libobjs" = "X " && libobjs=
+	  fi
+	fi
+
+	if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then
+	  eval flag=\"$thread_safe_flag_spec\"
+	  linker_flags="$linker_flags $flag"
+	fi
+
+	# Make a backup of the uninstalled library when relinking
+	if test "$mode" = relink; then
+	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
+	fi
+
+	# Do each of the archive commands.
+	if test "$module" = yes && test -n "$module_cmds" ; then
+	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
+	    eval test_cmds=\"$module_expsym_cmds\"
+	    cmds=$module_expsym_cmds
+	  else
+	    eval test_cmds=\"$module_cmds\"
+	    cmds=$module_cmds
+	  fi
+	else
+	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
+	    eval test_cmds=\"$archive_expsym_cmds\"
+	    cmds=$archive_expsym_cmds
+	  else
+	    eval test_cmds=\"$archive_cmds\"
+	    cmds=$archive_cmds
+	  fi
+	fi
+
+	if test "X$skipped_export" != "X:" &&
+	   func_len " $test_cmds" &&
+	   len=$func_len_result &&
+	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+	  :
+	else
+	  # The command line is too long to link in one step, link piecewise
+	  # or, if using GNU ld and skipped_export is not :, use a linker
+	  # script.
+
+	  # Save the value of $output and $libobjs because we want to
+	  # use them later.  If we have whole_archive_flag_spec, we
+	  # want to use save_libobjs as it was before
+	  # whole_archive_flag_spec was expanded, because we can't
+	  # assume the linker understands whole_archive_flag_spec.
+	  # This may have to be revisited, in case too many
+	  # convenience libraries get linked in and end up exceeding
+	  # the spec.
+	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
+	    save_libobjs=$libobjs
+	  fi
+	  save_output=$output
+	  output_la=`$ECHO "X$output" | $Xsed -e "$basename"`
+
+	  # Clear the reloadable object creation command queue and
+	  # initialize k to one.
+	  test_cmds=
+	  concat_cmds=
+	  objlist=
+	  last_robj=
+	  k=1
+
+	  if test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "$with_gnu_ld" = yes; then
+	    output=${output_objdir}/${output_la}.lnkscript
+	    func_verbose "creating GNU ld script: $output"
+	    $ECHO 'INPUT (' > $output
+	    for obj in $save_libobjs
+	    do
+	      $ECHO "$obj" >> $output
+	    done
+	    $ECHO ')' >> $output
+	    delfiles="$delfiles $output"
+	  elif test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "X$file_list_spec" != X; then
+	    output=${output_objdir}/${output_la}.lnk
+	    func_verbose "creating linker input file list: $output"
+	    : > $output
+	    set x $save_libobjs
+	    shift
+	    firstobj=
+	    if test "$compiler_needs_object" = yes; then
+	      firstobj="$1 "
+	      shift
+	    fi
+	    for obj
+	    do
+	      $ECHO "$obj" >> $output
+	    done
+	    delfiles="$delfiles $output"
+	    output=$firstobj\"$file_list_spec$output\"
+	  else
+	    if test -n "$save_libobjs"; then
+	      func_verbose "creating reloadable object files..."
+	      output=$output_objdir/$output_la-${k}.$objext
+	      eval test_cmds=\"$reload_cmds\"
+	      func_len " $test_cmds"
+	      len0=$func_len_result
+	      len=$len0
+
+	      # Loop over the list of objects to be linked.
+	      for obj in $save_libobjs
+	      do
+		func_len " $obj"
+		func_arith $len + $func_len_result
+		len=$func_arith_result
+		if test "X$objlist" = X ||
+		   test "$len" -lt "$max_cmd_len"; then
+		  func_append objlist " $obj"
+		else
+		  # The command $test_cmds is almost too long, add a
+		  # command to the queue.
+		  if test "$k" -eq 1 ; then
+		    # The first file doesn't have a previous command to add.
+		    eval concat_cmds=\"$reload_cmds $objlist $last_robj\"
+		  else
+		    # All subsequent reloadable object files will link in
+		    # the last one created.
+		    eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj~\$RM $last_robj\"
+		  fi
+		  last_robj=$output_objdir/$output_la-${k}.$objext
+		  func_arith $k + 1
+		  k=$func_arith_result
+		  output=$output_objdir/$output_la-${k}.$objext
+		  objlist=$obj
+		  func_len " $last_robj"
+		  func_arith $len0 + $func_len_result
+		  len=$func_arith_result
+		fi
+	      done
+	      # Handle the remaining objects by creating one last
+	      # reloadable object file.  All subsequent reloadable object
+	      # files will link in the last one created.
+	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+	      eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\"
+	      if test -n "$last_robj"; then
+	        eval concat_cmds=\"\${concat_cmds}~\$RM $last_robj\"
+	      fi
+	      delfiles="$delfiles $output"
+
+	    else
+	      output=
+	    fi
+
+	    if ${skipped_export-false}; then
+	      func_verbose "generating symbol list for \`$libname.la'"
+	      export_symbols="$output_objdir/$libname.exp"
+	      $opt_dry_run || $RM $export_symbols
+	      libobjs=$output
+	      # Append the command to create the export file.
+	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
+	      if test -n "$last_robj"; then
+		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
+	      fi
+	    fi
+
+	    test -n "$save_libobjs" &&
+	      func_verbose "creating a temporary reloadable object file: $output"
+
+	    # Loop through the commands generated above and execute them.
+	    save_ifs="$IFS"; IFS='~'
+	    for cmd in $concat_cmds; do
+	      IFS="$save_ifs"
+	      $opt_silent || {
+		  func_quote_for_expand "$cmd"
+		  eval "func_echo $func_quote_for_expand_result"
+	      }
+	      $opt_dry_run || eval "$cmd" || {
+		lt_exit=$?
+
+		# Restore the uninstalled library and exit
+		if test "$mode" = relink; then
+		  ( cd "$output_objdir" && \
+		    $RM "${realname}T" && \
+		    $MV "${realname}U" "$realname" )
+		fi
+
+		exit $lt_exit
+	      }
+	    done
+	    IFS="$save_ifs"
+
+	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
+	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
+	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
+	    fi
+	  fi
+
+          if ${skipped_export-false}; then
+	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
+	      tmp_export_symbols="$export_symbols"
+	      test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols"
+	      $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"'
+	    fi
+
+	    if test -n "$orig_export_symbols"; then
+	      # The given exports_symbols file has to be filtered, so filter it.
+	      func_verbose "filter symbol list for \`$libname.la' to tag DATA exports"
+	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
+	      # 's' commands which not all seds can handle. GNU sed should be fine
+	      # though. Also, the filter scales superlinearly with the number of
+	      # global variables. join(1) would be nice here, but unfortunately
+	      # isn't a blessed tool.
+	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
+	      delfiles="$delfiles $export_symbols $output_objdir/$libname.filter"
+	      export_symbols=$output_objdir/$libname.def
+	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
+	    fi
+	  fi
+
+	  libobjs=$output
+	  # Restore the value of output.
+	  output=$save_output
+
+	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
+	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
+	    test "X$libobjs" = "X " && libobjs=
+	  fi
+	  # Expand the library linking commands again to reset the
+	  # value of $libobjs for piecewise linking.
+
+	  # Do each of the archive commands.
+	  if test "$module" = yes && test -n "$module_cmds" ; then
+	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
+	      cmds=$module_expsym_cmds
+	    else
+	      cmds=$module_cmds
+	    fi
+	  else
+	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
+	      cmds=$archive_expsym_cmds
+	    else
+	      cmds=$archive_cmds
+	    fi
+	  fi
+	fi
+
+	if test -n "$delfiles"; then
+	  # Append the command to remove temporary files to $cmds.
+	  eval cmds=\"\$cmds~\$RM $delfiles\"
+	fi
+
+	# Add any objects from preloaded convenience libraries
+	if test -n "$dlprefiles"; then
+	  gentop="$output_objdir/${outputname}x"
+	  generated="$generated $gentop"
+
+	  func_extract_archives $gentop $dlprefiles
+	  libobjs="$libobjs $func_extract_archives_result"
+	  test "X$libobjs" = "X " && libobjs=
+	fi
+
+	save_ifs="$IFS"; IFS='~'
+	for cmd in $cmds; do
+	  IFS="$save_ifs"
+	  eval cmd=\"$cmd\"
+	  $opt_silent || {
+	    func_quote_for_expand "$cmd"
+	    eval "func_echo $func_quote_for_expand_result"
+	  }
+	  $opt_dry_run || eval "$cmd" || {
+	    lt_exit=$?
+
+	    # Restore the uninstalled library and exit
+	    if test "$mode" = relink; then
+	      ( cd "$output_objdir" && \
+	        $RM "${realname}T" && \
+		$MV "${realname}U" "$realname" )
+	    fi
+
+	    exit $lt_exit
+	  }
+	done
+	IFS="$save_ifs"
+
+	# Restore the uninstalled library and exit
+	if test "$mode" = relink; then
+	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
+
+	  if test -n "$convenience"; then
+	    if test -z "$whole_archive_flag_spec"; then
+	      func_show_eval '${RM}r "$gentop"'
+	    fi
+	  fi
+
+	  exit $EXIT_SUCCESS
+	fi
+
+	# Create links to the real library.
+	for linkname in $linknames; do
+	  if test "$realname" != "$linkname"; then
+	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
+	  fi
+	done
+
+	# If -module or -export-dynamic was specified, set the dlname.
+	if test "$module" = yes || test "$export_dynamic" = yes; then
+	  # On all known operating systems, these are identical.
+	  dlname="$soname"
+	fi
+      fi
+      ;;
+
+    obj)
+      if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
+	func_warning "\`-dlopen' is ignored for objects"
+      fi
+
+      case " $deplibs" in
+      *\ -l* | *\ -L*)
+	func_warning "\`-l' and \`-L' are ignored for objects" ;;
+      esac
+
+      test -n "$rpath" && \
+	func_warning "\`-rpath' is ignored for objects"
+
+      test -n "$xrpath" && \
+	func_warning "\`-R' is ignored for objects"
+
+      test -n "$vinfo" && \
+	func_warning "\`-version-info' is ignored for objects"
+
+      test -n "$release" && \
+	func_warning "\`-release' is ignored for objects"
+
+      case $output in
+      *.lo)
+	test -n "$objs$old_deplibs" && \
+	  func_fatal_error "cannot build library object \`$output' from non-libtool objects"
+
+	libobj=$output
+	func_lo2o "$libobj"
+	obj=$func_lo2o_result
+	;;
+      *)
+	libobj=
+	obj="$output"
+	;;
+      esac
+
+      # Delete the old objects.
+      $opt_dry_run || $RM $obj $libobj
+
+      # Objects from convenience libraries.  This assumes
+      # single-version convenience libraries.  Whenever we create
+      # different ones for PIC/non-PIC, this we'll have to duplicate
+      # the extraction.
+      reload_conv_objs=
+      gentop=
+      # reload_cmds runs $LD directly, so let us get rid of
+      # -Wl from whole_archive_flag_spec and hope we can get by with
+      # turning comma into space..
+      wl=
+
+      if test -n "$convenience"; then
+	if test -n "$whole_archive_flag_spec"; then
+	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
+	  reload_conv_objs=$reload_objs\ `$ECHO "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'`
+	else
+	  gentop="$output_objdir/${obj}x"
+	  generated="$generated $gentop"
+
+	  func_extract_archives $gentop $convenience
+	  reload_conv_objs="$reload_objs $func_extract_archives_result"
+	fi
+      fi
+
+      # Create the old-style object.
+      reload_objs="$objs$old_deplibs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test
+
+      output="$obj"
+      func_execute_cmds "$reload_cmds" 'exit $?'
+
+      # Exit if we aren't doing a library object file.
+      if test -z "$libobj"; then
+	if test -n "$gentop"; then
+	  func_show_eval '${RM}r "$gentop"'
+	fi
+
+	exit $EXIT_SUCCESS
+      fi
+
+      if test "$build_libtool_libs" != yes; then
+	if test -n "$gentop"; then
+	  func_show_eval '${RM}r "$gentop"'
+	fi
+
+	# Create an invalid libtool object if no PIC, so that we don't
+	# accidentally link it into a program.
+	# $show "echo timestamp > $libobj"
+	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
+	exit $EXIT_SUCCESS
+      fi
+
+      if test -n "$pic_flag" || test "$pic_mode" != default; then
+	# Only do commands if we really have different PIC objects.
+	reload_objs="$libobjs $reload_conv_objs"
+	output="$libobj"
+	func_execute_cmds "$reload_cmds" 'exit $?'
+      fi
+
+      if test -n "$gentop"; then
+	func_show_eval '${RM}r "$gentop"'
+      fi
+
+      exit $EXIT_SUCCESS
+      ;;
+
+    prog)
+      case $host in
+	*cygwin*) func_stripname '' '.exe' "$output"
+	          output=$func_stripname_result.exe;;
+      esac
+      test -n "$vinfo" && \
+	func_warning "\`-version-info' is ignored for programs"
+
+      test -n "$release" && \
+	func_warning "\`-release' is ignored for programs"
+
+      test "$preload" = yes \
+        && test "$dlopen_support" = unknown \
+	&& test "$dlopen_self" = unknown \
+	&& test "$dlopen_self_static" = unknown && \
+	  func_warning "\`LT_INIT([dlopen])' not used. Assuming no dlopen support."
+
+      case $host in
+      *-*-rhapsody* | *-*-darwin1.[012])
+	# On Rhapsody replace the C library is the System framework
+	compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
+	finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
+	;;
+      esac
+
+      case $host in
+      *-*-darwin*)
+	# Don't allow lazy linking, it breaks C++ global constructors
+	# But is supposedly fixed on 10.4 or later (yay!).
+	if test "$tagname" = CXX ; then
+	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
+	    10.[0123])
+	      compile_command="$compile_command ${wl}-bind_at_load"
+	      finalize_command="$finalize_command ${wl}-bind_at_load"
+	    ;;
+	  esac
+	fi
+	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
+	compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+	;;
+      esac
+
+
+      # move library search paths that coincide with paths to not yet
+      # installed libraries to the beginning of the library search list
+      new_libs=
+      for path in $notinst_path; do
+	case " $new_libs " in
+	*" -L$path/$objdir "*) ;;
+	*)
+	  case " $compile_deplibs " in
+	  *" -L$path/$objdir "*)
+	    new_libs="$new_libs -L$path/$objdir" ;;
+	  esac
+	  ;;
+	esac
+      done
+      for deplib in $compile_deplibs; do
+	case $deplib in
+	-L*)
+	  case " $new_libs " in
+	  *" $deplib "*) ;;
+	  *) new_libs="$new_libs $deplib" ;;
+	  esac
+	  ;;
+	*) new_libs="$new_libs $deplib" ;;
+	esac
+      done
+      compile_deplibs="$new_libs"
+
+
+      compile_command="$compile_command $compile_deplibs"
+      finalize_command="$finalize_command $finalize_deplibs"
+
+      if test -n "$rpath$xrpath"; then
+	# If the user specified any rpath flags, then add them.
+	for libdir in $rpath $xrpath; do
+	  # This is the magic to use -rpath.
+	  case "$finalize_rpath " in
+	  *" $libdir "*) ;;
+	  *) finalize_rpath="$finalize_rpath $libdir" ;;
+	  esac
+	done
+      fi
+
+      # Now hardcode the library paths
+      rpath=
+      hardcode_libdirs=
+      for libdir in $compile_rpath $finalize_rpath; do
+	if test -n "$hardcode_libdir_flag_spec"; then
+	  if test -n "$hardcode_libdir_separator"; then
+	    if test -z "$hardcode_libdirs"; then
+	      hardcode_libdirs="$libdir"
+	    else
+	      # Just accumulate the unique libdirs.
+	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+		;;
+	      *)
+		hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+		;;
+	      esac
+	    fi
+	  else
+	    eval flag=\"$hardcode_libdir_flag_spec\"
+	    rpath="$rpath $flag"
+	  fi
+	elif test -n "$runpath_var"; then
+	  case "$perm_rpath " in
+	  *" $libdir "*) ;;
+	  *) perm_rpath="$perm_rpath $libdir" ;;
+	  esac
+	fi
+	case $host in
+	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
+	  testbindir=`${ECHO} "$libdir" | ${SED} -e 's*/lib$*/bin*'`
+	  case :$dllsearchpath: in
+	  *":$libdir:"*) ;;
+	  ::) dllsearchpath=$libdir;;
+	  *) dllsearchpath="$dllsearchpath:$libdir";;
+	  esac
+	  case :$dllsearchpath: in
+	  *":$testbindir:"*) ;;
+	  ::) dllsearchpath=$testbindir;;
+	  *) dllsearchpath="$dllsearchpath:$testbindir";;
+	  esac
+	  ;;
+	esac
+      done
+      # Substitute the hardcoded libdirs into the rpath.
+      if test -n "$hardcode_libdir_separator" &&
+	 test -n "$hardcode_libdirs"; then
+	libdir="$hardcode_libdirs"
+	eval rpath=\" $hardcode_libdir_flag_spec\"
+      fi
+      compile_rpath="$rpath"
+
+      rpath=
+      hardcode_libdirs=
+      for libdir in $finalize_rpath; do
+	if test -n "$hardcode_libdir_flag_spec"; then
+	  if test -n "$hardcode_libdir_separator"; then
+	    if test -z "$hardcode_libdirs"; then
+	      hardcode_libdirs="$libdir"
+	    else
+	      # Just accumulate the unique libdirs.
+	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
+	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
+		;;
+	      *)
+		hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+		;;
+	      esac
+	    fi
+	  else
+	    eval flag=\"$hardcode_libdir_flag_spec\"
+	    rpath="$rpath $flag"
+	  fi
+	elif test -n "$runpath_var"; then
+	  case "$finalize_perm_rpath " in
+	  *" $libdir "*) ;;
+	  *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;;
+	  esac
+	fi
+      done
+      # Substitute the hardcoded libdirs into the rpath.
+      if test -n "$hardcode_libdir_separator" &&
+	 test -n "$hardcode_libdirs"; then
+	libdir="$hardcode_libdirs"
+	eval rpath=\" $hardcode_libdir_flag_spec\"
+      fi
+      finalize_rpath="$rpath"
+
+      if test -n "$libobjs" && test "$build_old_libs" = yes; then
+	# Transform all the library objects into standard objects.
+	compile_command=`$ECHO "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+	finalize_command=`$ECHO "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+      fi
+
+      func_generate_dlsyms "$outputname" "@PROGRAM@" "no"
+
+      # template prelinking step
+      if test -n "$prelink_cmds"; then
+	func_execute_cmds "$prelink_cmds" 'exit $?'
+      fi
+
+      wrappers_required=yes
+      case $host in
+      *cygwin* | *mingw* )
+        if test "$build_libtool_libs" != yes; then
+          wrappers_required=no
+        fi
+        ;;
+      *cegcc)
+        # Disable wrappers for cegcc, we are cross compiling anyway.
+        wrappers_required=no
+        ;;
+      *)
+        if test "$need_relink" = no || test "$build_libtool_libs" != yes; then
+          wrappers_required=no
+        fi
+        ;;
+      esac
+      if test "$wrappers_required" = no; then
+	# Replace the output file specification.
+	compile_command=`$ECHO "X$compile_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
+	link_command="$compile_command$compile_rpath"
+
+	# We have no uninstalled library dependencies, so finalize right now.
+	exit_status=0
+	func_show_eval "$link_command" 'exit_status=$?'
+
+	# Delete the generated files.
+	if test -f "$output_objdir/${outputname}S.${objext}"; then
+	  func_show_eval '$RM "$output_objdir/${outputname}S.${objext}"'
+	fi
+
+	exit $exit_status
+      fi
+
+      if test -n "$compile_shlibpath$finalize_shlibpath"; then
+	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
+      fi
+      if test -n "$finalize_shlibpath"; then
+	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
+      fi
+
+      compile_var=
+      finalize_var=
+      if test -n "$runpath_var"; then
+	if test -n "$perm_rpath"; then
+	  # We should set the runpath_var.
+	  rpath=
+	  for dir in $perm_rpath; do
+	    rpath="$rpath$dir:"
+	  done
+	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
+	fi
+	if test -n "$finalize_perm_rpath"; then
+	  # We should set the runpath_var.
+	  rpath=
+	  for dir in $finalize_perm_rpath; do
+	    rpath="$rpath$dir:"
+	  done
+	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
+	fi
+      fi
+
+      if test "$no_install" = yes; then
+	# We don't need to create a wrapper script.
+	link_command="$compile_var$compile_command$compile_rpath"
+	# Replace the output file specification.
+	link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
+	# Delete the old output file.
+	$opt_dry_run || $RM $output
+	# Link the executable and exit
+	func_show_eval "$link_command" 'exit $?'
+	exit $EXIT_SUCCESS
+      fi
+
+      if test "$hardcode_action" = relink; then
+	# Fast installation is not supported
+	link_command="$compile_var$compile_command$compile_rpath"
+	relink_command="$finalize_var$finalize_command$finalize_rpath"
+
+	func_warning "this platform does not like uninstalled shared libraries"
+	func_warning "\`$output' will be relinked during installation"
+      else
+	if test "$fast_install" != no; then
+	  link_command="$finalize_var$compile_command$finalize_rpath"
+	  if test "$fast_install" = yes; then
+	    relink_command=`$ECHO "X$compile_var$compile_command$compile_rpath" | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g'`
+	  else
+	    # fast_install is set to needless
+	    relink_command=
+	  fi
+	else
+	  link_command="$compile_var$compile_command$compile_rpath"
+	  relink_command="$finalize_var$finalize_command$finalize_rpath"
+	fi
+      fi
+
+      # Replace the output file specification.
+      link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
+
+      # Delete the old output files.
+      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
+
+      func_show_eval "$link_command" 'exit $?'
+
+      # Now create the wrapper script.
+      func_verbose "creating $output"
+
+      # Quote the relink command for shipping.
+      if test -n "$relink_command"; then
+	# Preserve any variables that may affect compiler behavior
+	for var in $variables_saved_for_relink; do
+	  if eval test -z \"\${$var+set}\"; then
+	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
+	  elif eval var_value=\$$var; test -z "$var_value"; then
+	    relink_command="$var=; export $var; $relink_command"
+	  else
+	    func_quote_for_eval "$var_value"
+	    relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
+	  fi
+	done
+	relink_command="(cd `pwd`; $relink_command)"
+	relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"`
+      fi
+
+      # Quote $ECHO for shipping.
+      if test "X$ECHO" = "X$SHELL $progpath --fallback-echo"; then
+	case $progpath in
+	[\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";;
+	*) qecho="$SHELL `pwd`/$progpath --fallback-echo";;
+	esac
+	qecho=`$ECHO "X$qecho" | $Xsed -e "$sed_quote_subst"`
+      else
+	qecho=`$ECHO "X$ECHO" | $Xsed -e "$sed_quote_subst"`
+      fi
+
+      # Only actually do things if not in dry run mode.
+      $opt_dry_run || {
+	# win32 will think the script is a binary if it has
+	# a .exe suffix, so we strip it off here.
+	case $output in
+	  *.exe) func_stripname '' '.exe' "$output"
+	         output=$func_stripname_result ;;
+	esac
+	# test for cygwin because mv fails w/o .exe extensions
+	case $host in
+	  *cygwin*)
+	    exeext=.exe
+	    func_stripname '' '.exe' "$outputname"
+	    outputname=$func_stripname_result ;;
+	  *) exeext= ;;
+	esac
+	case $host in
+	  *cygwin* | *mingw* )
+	    func_dirname_and_basename "$output" "" "."
+	    output_name=$func_basename_result
+	    output_path=$func_dirname_result
+	    cwrappersource="$output_path/$objdir/lt-$output_name.c"
+	    cwrapper="$output_path/$output_name.exe"
+	    $RM $cwrappersource $cwrapper
+	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
+
+	    func_emit_cwrapperexe_src > $cwrappersource
+
+	    # The wrapper executable is built using the $host compiler,
+	    # because it contains $host paths and files. If cross-
+	    # compiling, it, like the target executable, must be
+	    # executed on the $host or under an emulation environment.
+	    $opt_dry_run || {
+	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
+	      $STRIP $cwrapper
+	    }
+
+	    # Now, create the wrapper script for func_source use:
+	    func_ltwrapper_scriptname $cwrapper
+	    $RM $func_ltwrapper_scriptname_result
+	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
+	    $opt_dry_run || {
+	      # note: this script will not be executed, so do not chmod.
+	      if test "x$build" = "x$host" ; then
+		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
+	      else
+		func_emit_wrapper no > $func_ltwrapper_scriptname_result
+	      fi
+	    }
+	  ;;
+	  * )
+	    $RM $output
+	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
+
+	    func_emit_wrapper no > $output
+	    chmod +x $output
+	  ;;
+	esac
+      }
+      exit $EXIT_SUCCESS
+      ;;
+    esac
+
+    # See if we need to build an old-fashioned archive.
+    for oldlib in $oldlibs; do
+
+      if test "$build_libtool_libs" = convenience; then
+	oldobjs="$libobjs_save $symfileobj"
+	addlibs="$convenience"
+	build_libtool_libs=no
+      else
+	if test "$build_libtool_libs" = module; then
+	  oldobjs="$libobjs_save"
+	  build_libtool_libs=no
+	else
+	  oldobjs="$old_deplibs $non_pic_objects"
+	  if test "$preload" = yes && test -f "$symfileobj"; then
+	    oldobjs="$oldobjs $symfileobj"
+	  fi
+	fi
+	addlibs="$old_convenience"
+      fi
+
+      if test -n "$addlibs"; then
+	gentop="$output_objdir/${outputname}x"
+	generated="$generated $gentop"
+
+	func_extract_archives $gentop $addlibs
+	oldobjs="$oldobjs $func_extract_archives_result"
+      fi
+
+      # Do each command in the archive commands.
+      if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then
+	cmds=$old_archive_from_new_cmds
+      else
+
+	# Add any objects from preloaded convenience libraries
+	if test -n "$dlprefiles"; then
+	  gentop="$output_objdir/${outputname}x"
+	  generated="$generated $gentop"
+
+	  func_extract_archives $gentop $dlprefiles
+	  oldobjs="$oldobjs $func_extract_archives_result"
+	fi
+
+	# POSIX demands no paths to be encoded in archives.  We have
+	# to avoid creating archives with duplicate basenames if we
+	# might have to extract them afterwards, e.g., when creating a
+	# static archive out of a convenience library, or when linking
+	# the entirety of a libtool archive into another (currently
+	# not supported by libtool).
+	if (for obj in $oldobjs
+	    do
+	      func_basename "$obj"
+	      $ECHO "$func_basename_result"
+	    done | sort | sort -uc >/dev/null 2>&1); then
+	  :
+	else
+	  $ECHO "copying selected object files to avoid basename conflicts..."
+	  gentop="$output_objdir/${outputname}x"
+	  generated="$generated $gentop"
+	  func_mkdir_p "$gentop"
+	  save_oldobjs=$oldobjs
+	  oldobjs=
+	  counter=1
+	  for obj in $save_oldobjs
+	  do
+	    func_basename "$obj"
+	    objbase="$func_basename_result"
+	    case " $oldobjs " in
+	    " ") oldobjs=$obj ;;
+	    *[\ /]"$objbase "*)
+	      while :; do
+		# Make sure we don't pick an alternate name that also
+		# overlaps.
+		newobj=lt$counter-$objbase
+		func_arith $counter + 1
+		counter=$func_arith_result
+		case " $oldobjs " in
+		*[\ /]"$newobj "*) ;;
+		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
+		esac
+	      done
+	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
+	      oldobjs="$oldobjs $gentop/$newobj"
+	      ;;
+	    *) oldobjs="$oldobjs $obj" ;;
+	    esac
+	  done
+	fi
+	eval cmds=\"$old_archive_cmds\"
+
+	func_len " $cmds"
+	len=$func_len_result
+	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+	  cmds=$old_archive_cmds
+	else
+	  # the command line is too long to link in one step, link in parts
+	  func_verbose "using piecewise archive linking..."
+	  save_RANLIB=$RANLIB
+	  RANLIB=:
+	  objlist=
+	  concat_cmds=
+	  save_oldobjs=$oldobjs
+	  oldobjs=
+	  # Is there a better way of finding the last object in the list?
+	  for obj in $save_oldobjs
+	  do
+	    last_oldobj=$obj
+	  done
+	  eval test_cmds=\"$old_archive_cmds\"
+	  func_len " $test_cmds"
+	  len0=$func_len_result
+	  len=$len0
+	  for obj in $save_oldobjs
+	  do
+	    func_len " $obj"
+	    func_arith $len + $func_len_result
+	    len=$func_arith_result
+	    func_append objlist " $obj"
+	    if test "$len" -lt "$max_cmd_len"; then
+	      :
+	    else
+	      # the above command should be used before it gets too long
+	      oldobjs=$objlist
+	      if test "$obj" = "$last_oldobj" ; then
+		RANLIB=$save_RANLIB
+	      fi
+	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
+	      eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\"
+	      objlist=
+	      len=$len0
+	    fi
+	  done
+	  RANLIB=$save_RANLIB
+	  oldobjs=$objlist
+	  if test "X$oldobjs" = "X" ; then
+	    eval cmds=\"\$concat_cmds\"
+	  else
+	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
+	  fi
+	fi
+      fi
+      func_execute_cmds "$cmds" 'exit $?'
+    done
+
+    test -n "$generated" && \
+      func_show_eval "${RM}r$generated"
+
+    # Now create the libtool archive.
+    case $output in
+    *.la)
+      old_library=
+      test "$build_old_libs" = yes && old_library="$libname.$libext"
+      func_verbose "creating $output"
+
+      # Preserve any variables that may affect compiler behavior
+      for var in $variables_saved_for_relink; do
+	if eval test -z \"\${$var+set}\"; then
+	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
+	elif eval var_value=\$$var; test -z "$var_value"; then
+	  relink_command="$var=; export $var; $relink_command"
+	else
+	  func_quote_for_eval "$var_value"
+	  relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
+	fi
+      done
+      # Quote the link command for shipping.
+      relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
+      relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"`
+      if test "$hardcode_automatic" = yes ; then
+	relink_command=
+      fi
+
+      # Only create the output if not a dry run.
+      $opt_dry_run || {
+	for installed in no yes; do
+	  if test "$installed" = yes; then
+	    if test -z "$install_libdir"; then
+	      break
+	    fi
+	    output="$output_objdir/$outputname"i
+	    # Replace all uninstalled libtool libraries with the installed ones
+	    newdependency_libs=
+	    for deplib in $dependency_libs; do
+	      case $deplib in
+	      *.la)
+		func_basename "$deplib"
+		name="$func_basename_result"
+		eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
+		test -z "$libdir" && \
+		  func_fatal_error "\`$deplib' is not a valid libtool archive"
+		newdependency_libs="$newdependency_libs $libdir/$name"
+		;;
+	      *) newdependency_libs="$newdependency_libs $deplib" ;;
+	      esac
+	    done
+	    dependency_libs="$newdependency_libs"
+	    newdlfiles=
+
+	    for lib in $dlfiles; do
+	      case $lib in
+	      *.la)
+	        func_basename "$lib"
+		name="$func_basename_result"
+		eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
+		test -z "$libdir" && \
+		  func_fatal_error "\`$lib' is not a valid libtool archive"
+		newdlfiles="$newdlfiles $libdir/$name"
+		;;
+	      *) newdlfiles="$newdlfiles $lib" ;;
+	      esac
+	    done
+	    dlfiles="$newdlfiles"
+	    newdlprefiles=
+	    for lib in $dlprefiles; do
+	      case $lib in
+	      *.la)
+		# Only pass preopened files to the pseudo-archive (for
+		# eventual linking with the app. that links it) if we
+		# didn't already link the preopened objects directly into
+		# the library:
+		func_basename "$lib"
+		name="$func_basename_result"
+		eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
+		test -z "$libdir" && \
+		  func_fatal_error "\`$lib' is not a valid libtool archive"
+		newdlprefiles="$newdlprefiles $libdir/$name"
+		;;
+	      esac
+	    done
+	    dlprefiles="$newdlprefiles"
+	  else
+	    newdlfiles=
+	    for lib in $dlfiles; do
+	      case $lib in
+		[\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
+		*) abs=`pwd`"/$lib" ;;
+	      esac
+	      newdlfiles="$newdlfiles $abs"
+	    done
+	    dlfiles="$newdlfiles"
+	    newdlprefiles=
+	    for lib in $dlprefiles; do
+	      case $lib in
+		[\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
+		*) abs=`pwd`"/$lib" ;;
+	      esac
+	      newdlprefiles="$newdlprefiles $abs"
+	    done
+	    dlprefiles="$newdlprefiles"
+	  fi
+	  $RM $output
+	  # place dlname in correct position for cygwin
+	  tdlname=$dlname
+	  case $host,$output,$installed,$module,$dlname in
+	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;;
+	  esac
+	  $ECHO > $output "\
+# $outputname - a libtool library file
+# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# The name that we can dlopen(3).
+dlname='$tdlname'
+
+# Names of this library.
+library_names='$library_names'
+
+# The name of the static archive.
+old_library='$old_library'
+
+# Linker flags that can not go in dependency_libs.
+inherited_linker_flags='$new_inherited_linker_flags'
+
+# Libraries that this one depends upon.
+dependency_libs='$dependency_libs'
+
+# Names of additional weak libraries provided by this library
+weak_library_names='$weak_libs'
+
+# Version information for $libname.
+current=$current
+age=$age
+revision=$revision
+
+# Is this an already installed library?
+installed=$installed
+
+# Should we warn about portability when linking against -modules?
+shouldnotlink=$module
+
+# Files to dlopen/dlpreopen
+dlopen='$dlfiles'
+dlpreopen='$dlprefiles'
+
+# Directory that this library needs to be installed in:
+libdir='$install_libdir'"
+	  if test "$installed" = no && test "$need_relink" = yes; then
+	    $ECHO >> $output "\
+relink_command=\"$relink_command\""
+	  fi
+	done
+      }
+
+      # Do a symbolic link so that the libtool archive can be found in
+      # LD_LIBRARY_PATH before the program is installed.
+      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
+      ;;
+    esac
+    exit $EXIT_SUCCESS
+}
+
+{ test "$mode" = link || test "$mode" = relink; } &&
+    func_mode_link ${1+"$@"}
+
+
+# func_mode_uninstall arg...
+func_mode_uninstall ()
+{
+    $opt_debug
+    RM="$nonopt"
+    files=
+    rmforce=
+    exit_status=0
+
+    # This variable tells wrapper scripts just to set variables rather
+    # than running their programs.
+    libtool_install_magic="$magic"
+
+    for arg
+    do
+      case $arg in
+      -f) RM="$RM $arg"; rmforce=yes ;;
+      -*) RM="$RM $arg" ;;
+      *) files="$files $arg" ;;
+      esac
+    done
+
+    test -z "$RM" && \
+      func_fatal_help "you must specify an RM program"
+
+    rmdirs=
+
+    origobjdir="$objdir"
+    for file in $files; do
+      func_dirname "$file" "" "."
+      dir="$func_dirname_result"
+      if test "X$dir" = X.; then
+	objdir="$origobjdir"
+      else
+	objdir="$dir/$origobjdir"
+      fi
+      func_basename "$file"
+      name="$func_basename_result"
+      test "$mode" = uninstall && objdir="$dir"
+
+      # Remember objdir for removal later, being careful to avoid duplicates
+      if test "$mode" = clean; then
+	case " $rmdirs " in
+	  *" $objdir "*) ;;
+	  *) rmdirs="$rmdirs $objdir" ;;
+	esac
+      fi
+
+      # Don't error if the file doesn't exist and rm -f was used.
+      if { test -L "$file"; } >/dev/null 2>&1 ||
+	 { test -h "$file"; } >/dev/null 2>&1 ||
+	 test -f "$file"; then
+	:
+      elif test -d "$file"; then
+	exit_status=1
+	continue
+      elif test "$rmforce" = yes; then
+	continue
+      fi
+
+      rmfiles="$file"
+
+      case $name in
+      *.la)
+	# Possibly a libtool archive, so verify it.
+	if func_lalib_p "$file"; then
+	  func_source $dir/$name
+
+	  # Delete the libtool libraries and symlinks.
+	  for n in $library_names; do
+	    rmfiles="$rmfiles $objdir/$n"
+	  done
+	  test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library"
+
+	  case "$mode" in
+	  clean)
+	    case "  $library_names " in
+	    # "  " in the beginning catches empty $dlname
+	    *" $dlname "*) ;;
+	    *) rmfiles="$rmfiles $objdir/$dlname" ;;
+	    esac
+	    test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i"
+	    ;;
+	  uninstall)
+	    if test -n "$library_names"; then
+	      # Do each command in the postuninstall commands.
+	      func_execute_cmds "$postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1'
+	    fi
+
+	    if test -n "$old_library"; then
+	      # Do each command in the old_postuninstall commands.
+	      func_execute_cmds "$old_postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1'
+	    fi
+	    # FIXME: should reinstall the best remaining shared library.
+	    ;;
+	  esac
+	fi
+	;;
+
+      *.lo)
+	# Possibly a libtool object, so verify it.
+	if func_lalib_p "$file"; then
+
+	  # Read the .lo file
+	  func_source $dir/$name
+
+	  # Add PIC object to the list of files to remove.
+	  if test -n "$pic_object" &&
+	     test "$pic_object" != none; then
+	    rmfiles="$rmfiles $dir/$pic_object"
+	  fi
+
+	  # Add non-PIC object to the list of files to remove.
+	  if test -n "$non_pic_object" &&
+	     test "$non_pic_object" != none; then
+	    rmfiles="$rmfiles $dir/$non_pic_object"
+	  fi
+	fi
+	;;
+
+      *)
+	if test "$mode" = clean ; then
+	  noexename=$name
+	  case $file in
+	  *.exe)
+	    func_stripname '' '.exe' "$file"
+	    file=$func_stripname_result
+	    func_stripname '' '.exe' "$name"
+	    noexename=$func_stripname_result
+	    # $file with .exe has already been added to rmfiles,
+	    # add $file without .exe
+	    rmfiles="$rmfiles $file"
+	    ;;
+	  esac
+	  # Do a test to see if this is a libtool program.
+	  if func_ltwrapper_p "$file"; then
+	    if func_ltwrapper_executable_p "$file"; then
+	      func_ltwrapper_scriptname "$file"
+	      relink_command=
+	      func_source $func_ltwrapper_scriptname_result
+	      rmfiles="$rmfiles $func_ltwrapper_scriptname_result"
+	    else
+	      relink_command=
+	      func_source $dir/$noexename
+	    fi
+
+	    # note $name still contains .exe if it was in $file originally
+	    # as does the version of $file that was added into $rmfiles
+	    rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}"
+	    if test "$fast_install" = yes && test -n "$relink_command"; then
+	      rmfiles="$rmfiles $objdir/lt-$name"
+	    fi
+	    if test "X$noexename" != "X$name" ; then
+	      rmfiles="$rmfiles $objdir/lt-${noexename}.c"
+	    fi
+	  fi
+	fi
+	;;
+      esac
+      func_show_eval "$RM $rmfiles" 'exit_status=1'
+    done
+    objdir="$origobjdir"
+
+    # Try to remove the ${objdir}s in the directories where we deleted files
+    for dir in $rmdirs; do
+      if test -d "$dir"; then
+	func_show_eval "rmdir $dir >/dev/null 2>&1"
+      fi
+    done
+
+    exit $exit_status
+}
+
+{ test "$mode" = uninstall || test "$mode" = clean; } &&
+    func_mode_uninstall ${1+"$@"}
+
+test -z "$mode" && {
+  help="$generic_help"
+  func_fatal_help "you must specify a MODE"
+}
+
+test -z "$exec_cmd" && \
+  func_fatal_help "invalid operation mode \`$mode'"
+
+if test -n "$exec_cmd"; then
+  eval exec "$exec_cmd"
+  exit $EXIT_FAILURE
+fi
+
+exit $exit_status
+
+
+# The TAGs below are defined such that we never get into a situation
+# in which we disable both kinds of libraries.  Given conflicting
+# choices, we go for a static library, that is the most portable,
+# since we can't tell whether shared libraries were disabled because
+# the user asked for that or because the platform doesn't support
+# them.  This is particularly important on AIX, because we don't
+# support having both static and shared libraries enabled at the same
+# time on that platform, so we default to a shared-only configuration.
+# If a disable-shared tag is given, we'll fallback to a static-only
+# configuration.  But we'll never go from static-only to shared-only.
+
+# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
+build_libtool_libs=no
+build_old_libs=yes
+# ### END LIBTOOL TAG CONFIG: disable-shared
+
+# ### BEGIN LIBTOOL TAG CONFIG: disable-static
+build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
+# ### END LIBTOOL TAG CONFIG: disable-static
+
+# Local Variables:
+# mode:shell-script
+# sh-indentation:2
+# End:
+# vi:sw=2
+
diff --git a/m4/byteorder.m4 b/m4/byteorder.m4
new file mode 100644
index 0000000..0ec97ea
--- /dev/null
+++ b/m4/byteorder.m4
@@ -0,0 +1,418 @@
+dnl AC_NEED_BYTEORDER_H ( HEADER-TO-GENERATE )
+dnl Copyright 2001-2002 by Dan Fandrich <dan@coneharvesters.com>
+dnl This file may be copied and used freely without restrictions.  No warranty
+dnl is expressed or implied.
+dnl
+dnl Create a header file that guarantees that byte swapping macros of the
+dnl ntohl variety as well as the extended types included in OpenBSD and
+dnl NetBSD such as le32toh are defined.  If possible, the standard ntohl
+dnl are overloaded as they are optimized for the given platform, but when
+dnl this is not possible (e.g. on a big-endian machine) they are defined
+dnl in this file.
+
+dnl Look for a symbol in a header file
+dnl AC_HAVE_SYMBOL ( IDENTIFIER, HEADER-FILE, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND )
+AC_DEFUN([AC_HAVE_SYMBOL],
+[
+AC_MSG_CHECKING(for $1 in $2)
+AC_EGREP_CPP([symbol is present|\<$1\>],[
+#include <$2>
+#ifdef $1
+ 	symbol is present
+#endif
+	], 
+[AC_MSG_RESULT(yes)
+$3
+],
+[AC_MSG_RESULT(no)
+$4
+])])
+
+
+dnl Create a header file that defines extended byte swapping macros
+AC_DEFUN([AC_NEED_BYTEORDER_H],
+[
+ac_dir=`AS_DIRNAME(["$1"])`
+if test "$ac_dir" != "$1" && test "$ac_dir" != .; then
+  # The file is in a subdirectory.
+  test ! -d "$ac_dir" && AS_MKDIR_P(["$ac_dir"])
+fi
+
+# We're only interested in the target CPU, but it's not always set
+effective_target="$target"
+if test "x$effective_target" = xNONE -o "x$effective_target" = x ; then
+	effective_target="$host"
+fi
+AC_SUBST(effective_target)
+
+cat > "$1" << EOF
+/* This file is generated automatically by configure */
+/* It is valid only for the system type ${effective_target} */
+
+#ifndef __BYTEORDER_H
+#define __BYTEORDER_H
+
+EOF
+
+dnl First, do an endian check
+AC_C_BIGENDIAN
+
+dnl Look for NetBSD-style extended byte swapping macros
+AC_HAVE_SYMBOL(le32toh,machine/endian.h,
+ [HAVE_LE32TOH=1
+ cat >> "$1" << EOF
+/* extended byte swapping macros are already available */
+#include <machine/endian.h>
+
+EOF],
+
+[
+
+dnl Look for standard byte swapping macros
+AC_HAVE_SYMBOL(ntohl,arpa/inet.h,
+ [cat >> "$1" << EOF
+/* ntohl and relatives live here */
+#include <arpa/inet.h>
+
+EOF],
+
+ [AC_HAVE_SYMBOL(ntohl,netinet/in.h,
+  [cat >> "$1" << EOF
+/* ntohl and relatives live here */
+#include <netinet/in.h>
+
+EOF],true)])
+])
+
+dnl Look for generic byte swapping macros
+
+dnl OpenBSD
+AC_HAVE_SYMBOL(swap32,machine/endian.h,
+ [cat >> "$1" << EOF
+/* swap32 and swap16 are defined in machine/endian.h */
+
+EOF],
+
+ [
+dnl Linux GLIBC
+  AC_HAVE_SYMBOL(bswap_32,byteswap.h,
+   [cat >> "$1" << EOF
+/* Define generic byte swapping functions */
+#include <byteswap.h>
+#define swap16(x) bswap_16(x)
+#define swap32(x) bswap_32(x)
+#define swap64(x) bswap_64(x)
+
+EOF],
+
+   [
+dnl NetBSD
+  	AC_HAVE_SYMBOL(bswap32,machine/endian.h,
+    dnl We're already including machine/endian.h if this test succeeds
+  	 [cat >> "$1" << EOF
+/* Define generic byte swapping functions */
+EOF
+	if test "$HAVE_LE32TOH" != "1"; then
+		echo '#include <machine/endian.h>'>> "$1"
+	fi
+cat >> "$1" << EOF
+#define swap16(x) bswap16(x)
+#define swap32(x) bswap32(x)
+#define swap64(x) bswap64(x)
+
+EOF],
+
+   [
+dnl FreeBSD
+  	AC_HAVE_SYMBOL(__byte_swap_long,sys/types.h,
+  	 [cat >> "$1" << EOF
+/* Define generic byte swapping functions */
+#include <sys/types.h>
+#define swap16(x) __byte_swap_word(x)
+#define swap32(x) __byte_swap_long(x)
+/* No optimized 64 bit byte swapping macro is available */
+#define swap64(x) ((uint64_t)(((uint64_t)(x) << 56) & 0xff00000000000000ULL | \\
+			      ((uint64_t)(x) << 40) & 0x00ff000000000000ULL | \\
+			      ((uint64_t)(x) << 24) & 0x0000ff0000000000ULL | \\
+			      ((uint64_t)(x) << 8)  & 0x000000ff00000000ULL | \\
+			      ((x) >> 8)  & 0x00000000ff000000ULL | \\
+			      ((x) >> 24) & 0x0000000000ff0000ULL | \\
+			      ((x) >> 40) & 0x000000000000ff00ULL | \\
+			      ((x) >> 56) & 0x00000000000000ffULL))
+
+EOF],
+
+  	 [
+dnl OS X
+  	AC_HAVE_SYMBOL(NXSwapLong,machine/byte_order.h,
+  	 [cat >> "$1" << EOF
+/* Define generic byte swapping functions */
+#include <machine/byte_order.h>
+#define swap16(x) NXSwapShort(x)
+#define swap32(x) NXSwapLong(x)
+#define swap64(x) NXSwapLongLong(x)
+
+EOF],
+         [
+	if test $ac_cv_c_bigendian = yes; then
+		cat >> "$1" << EOF
+/* No other byte swapping functions are available on this big-endian system */
+#define swap16(x)	((uint16_t)(((x) << 8) | ((uint16_t)(x) >> 8)))
+#define swap32(x)	((uint32_t)(((uint32_t)(x) << 24) & 0xff000000UL | \\
+				    ((uint32_t)(x) << 8)  & 0x00ff0000UL | \\
+				    ((x) >> 8)  & 0x0000ff00UL | \\
+				    ((x) >> 24) & 0x000000ffUL))
+#define swap64(x) ((uint64_t)(((uint64_t)(x) << 56) & 0xff00000000000000ULL | \\
+			      ((uint64_t)(x) << 40) & 0x00ff000000000000ULL | \\
+			      ((uint64_t)(x) << 24) & 0x0000ff0000000000ULL | \\
+			      ((uint64_t)(x) << 8)  & 0x000000ff00000000ULL | \\
+			      ((x) >> 8)  & 0x00000000ff000000ULL | \\
+			      ((x) >> 24) & 0x0000000000ff0000ULL | \\
+			      ((x) >> 40) & 0x000000000000ff00ULL | \\
+			      ((x) >> 56) & 0x00000000000000ffULL))
+
+EOF
+	else
+ cat >> "$1" << EOF
+/* Use these as generic byteswapping macros on this little endian system */
+#define swap16(x)		ntohs(x)
+#define swap32(x)		ntohl(x)
+/* No optimized 64 bit byte swapping macro is available */
+#define swap64(x) ((uint64_t)(((uint64_t)(x) << 56) & 0xff00000000000000ULL | \\
+			      ((uint64_t)(x) << 40) & 0x00ff000000000000ULL | \\
+			      ((uint64_t)(x) << 24) & 0x0000ff0000000000ULL | \\
+			      ((uint64_t)(x) << 8)  & 0x000000ff00000000ULL | \\
+			      ((x) >> 8)  & 0x00000000ff000000ULL | \\
+			      ((x) >> 24) & 0x0000000000ff0000ULL | \\
+			      ((x) >> 40) & 0x000000000000ff00ULL | \\
+			      ((x) >> 56) & 0x00000000000000ffULL))
+
+EOF
+	fi
+])
+  	  ])
+    ])
+  ])
+])
+
+
+[
+if test "$HAVE_LE32TOH" != "1"; then
+ cat >> "$1" << EOF
+/* The byte swapping macros have the form: */
+/*   EENN[a]toh or htoEENN[a] where EE is be (big endian) or */
+/* le (little-endian), NN is 16 or 32 (number of bits) and a, */
+/* if present, indicates that the endian side is a pointer to an */
+/* array of uint8_t bytes instead of an integer of the specified length. */
+/* h refers to the host's ordering method. */
+
+/* So, to convert a 32-bit integer stored in a buffer in little-endian */
+/* format into a uint32_t usable on this machine, you could use: */
+/*   uint32_t value = le32atoh(&buf[3]); */
+/* To put that value back into the buffer, you could use: */
+/*   htole32a(&buf[3], value); */
+
+/* Define aliases for the standard byte swapping macros */
+/* Arguments to these macros must be properly aligned on natural word */
+/* boundaries in order to work properly on all architectures */
+#ifndef htobe16
+# define htobe16(x) htons(x)
+#endif
+#ifndef htobe32
+# define htobe32(x) htonl(x)
+#endif
+#ifndef be16toh
+# define be16toh(x) ntohs(x)
+#endif
+#ifndef be32toh
+# define be32toh(x) ntohl(x)
+#endif
+
+#define HTOBE16(x) (x) = htobe16(x)
+#define HTOBE32(x) (x) = htobe32(x)
+#define BE32TOH(x) (x) = be32toh(x)
+#define BE16TOH(x) (x) = be16toh(x)
+
+EOF
+
+ if test $ac_cv_c_bigendian = yes; then
+  cat >> "$1" << EOF
+/* Define our own extended byte swapping macros for big-endian machines */
+#ifndef htole16
+# define htole16(x)      swap16(x)
+#endif
+#ifndef htole32
+# define htole32(x)      swap32(x)
+#endif
+#ifndef le16toh
+# define le16toh(x)      swap16(x)
+#endif
+#ifndef le32toh
+# define le32toh(x)      swap32(x)
+#endif
+#ifndef le64toh
+# define le64toh(x)      swap64(x)
+#endif
+
+#ifndef htobe64
+# define htobe64(x)      (x)
+#endif
+#ifndef be64toh
+# define be64toh(x)      (x)
+#endif
+
+#define HTOLE16(x)      (x) = htole16(x)
+#define HTOLE32(x)      (x) = htole32(x)
+#define LE16TOH(x)      (x) = le16toh(x)
+#define LE32TOH(x)      (x) = le32toh(x)
+#define LE64TOH(x)      (x) = le64toh(x)
+
+#define HTOBE64(x)      (void) (x)
+#define BE64TOH(x)      (void) (x)
+
+EOF
+ else
+  cat >> "$1" << EOF
+/* On little endian machines, these macros are null */
+#ifndef htole16
+# define htole16(x)      (x)
+#endif
+#ifndef htole32
+# define htole32(x)      (x)
+#endif
+#ifndef htole64
+# define htole64(x)      (x)
+#endif
+#ifndef le16toh
+# define le16toh(x)      (x)
+#endif
+#ifndef le32toh
+# define le32toh(x)      (x)
+#endif
+#ifndef le64toh
+# define le64toh(x)      (x)
+#endif
+
+#define HTOLE16(x)      (void) (x)
+#define HTOLE32(x)      (void) (x)
+#define HTOLE64(x)      (void) (x)
+#define LE16TOH(x)      (void) (x)
+#define LE32TOH(x)      (void) (x)
+#define LE64TOH(x)      (void) (x)
+
+/* These don't have standard aliases */
+#ifndef htobe64
+# define htobe64(x)      swap64(x)
+#endif
+#ifndef be64toh
+# define be64toh(x)      swap64(x)
+#endif
+
+#define HTOBE64(x)      (x) = htobe64(x)
+#define BE64TOH(x)      (x) = be64toh(x)
+
+EOF
+ fi
+fi
+
+cat >> "$1" << EOF
+/* Define the C99 standard length-specific integer types */
+#include <_stdint.h>
+
+EOF
+
+case "${effective_target}" in
+ i[3456]86-*)
+  cat >> "$1" << EOF
+/* Here are some macros to create integers from a byte array */
+/* These are used to get and put integers from/into a uint8_t array */
+/* with a specific endianness.  This is the most portable way to generate */
+/* and read messages to a network or serial device.  Each member of a */
+/* packet structure must be handled separately. */
+
+/* The i386 and compatibles can handle unaligned memory access, */
+/* so use the optimized macros above to do this job */
+#ifndef be16atoh
+# define be16atoh(x)     be16toh(*(uint16_t*)(x))
+#endif
+#ifndef be32atoh
+# define be32atoh(x)     be32toh(*(uint32_t*)(x))
+#endif
+#ifndef be64atoh
+# define be64atoh(x)     be64toh(*(uint64_t*)(x))
+#endif
+#ifndef le16atoh
+# define le16atoh(x)     le16toh(*(uint16_t*)(x))
+#endif
+#ifndef le32atoh
+# define le32atoh(x)     le32toh(*(uint32_t*)(x))
+#endif
+#ifndef le64atoh
+# define le64atoh(x)     le64toh(*(uint64_t*)(x))
+#endif
+
+#ifndef htob16a
+# define htobe16a(a,x)   *(uint16_t*)(a) = htobe16(x)
+#endif
+#ifndef htobe32a
+# define htobe32a(a,x)   *(uint32_t*)(a) = htobe32(x)
+#endif
+#ifndef htobe64a
+# define htobe64a(a,x)   *(uint64_t*)(a) = htobe64(x)
+#endif
+#ifndef htole16a
+# define htole16a(a,x)   *(uint16_t*)(a) = htole16(x)
+#endif
+#ifndef htole32a
+# define htole32a(a,x)   *(uint32_t*)(a) = htole32(x)
+#endif
+#ifndef htole64a
+# define htole64a(a,x)   *(uint64_t*)(a) = htole64(x)
+#endif
+
+EOF
+  ;;
+
+ *)
+  cat >> "$1" << EOF
+/* Here are some macros to create integers from a byte array */
+/* These are used to get and put integers from/into a uint8_t array */
+/* with a specific endianness.  This is the most portable way to generate */
+/* and read messages to a network or serial device.  Each member of a */
+/* packet structure must be handled separately. */
+
+/* Non-optimized but portable macros */
+#define be16atoh(x)     ((uint16_t)(((x)[0]<<8)|(x)[1]))
+#define be32atoh(x)     ((uint32_t)(((x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]))
+#define be64atoh_x(x,off,shift) 	(((uint64_t)((x)[off]))<<shift)
+#define be64atoh(x)     ((uint64_t)(be64atoh_x(x,0,56)|be64atoh_x(x,1,48)|be64atoh_x(x,2,40)| \\
+        be64atoh_x(x,3,32)|be64atoh_x(x,4,24)|be64atoh_x(x,5,16)|be64atoh_x(x,6,8)|((x)[7])))
+#define le16atoh(x)     ((uint16_t)(((x)[1]<<8)|(x)[0]))
+#define le32atoh(x)     ((uint32_t)(((x)[3]<<24)|((x)[2]<<16)|((x)[1]<<8)|(x)[0]))
+#define le64atoh_x(x,off,shift) (((uint64_t)(x)[off])<<shift)
+#define le64atoh(x)     ((uint64_t)(le64atoh_x(x,7,56)|le64atoh_x(x,6,48)|le64atoh_x(x,5,40)| \\
+        le64atoh_x(x,4,32)|le64atoh_x(x,3,24)|le64atoh_x(x,2,16)|le64atoh_x(x,1,8)|((x)[0])))
+
+#define htobe16a(a,x)   (a)[0]=(uint8_t)((x)>>8), (a)[1]=(uint8_t)(x)
+#define htobe32a(a,x)   (a)[0]=(uint8_t)((x)>>24), (a)[1]=(uint8_t)((x)>>16), \\
+        (a)[2]=(uint8_t)((x)>>8), (a)[3]=(uint8_t)(x)
+#define htobe64a(a,x)   (a)[0]=(uint8_t)((x)>>56), (a)[1]=(uint8_t)((x)>>48), \\
+        (a)[2]=(uint8_t)((x)>>40), (a)[3]=(uint8_t)((x)>>32), \\
+        (a)[4]=(uint8_t)((x)>>24), (a)[5]=(uint8_t)((x)>>16), \\
+        (a)[6]=(uint8_t)((x)>>8), (a)[7]=(uint8_t)(x)
+#define htole16a(a,x)   (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
+#define htole32a(a,x)   (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \\
+        (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
+#define htole64a(a,x)   (a)[7]=(uint8_t)((x)>>56), (a)[6]=(uint8_t)((x)>>48), \\
+        (a)[5]=(uint8_t)((x)>>40), (a)[4]=(uint8_t)((x)>>32), \\
+        (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \\
+        (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
+
+EOF
+  ;;
+esac
+]
+
+cat >> "$1" << EOF
+#endif /*__BYTEORDER_H*/
+EOF])
diff --git a/m4/libtool.m4 b/m4/libtool.m4
new file mode 100644
index 0000000..671cde1
--- /dev/null
+++ b/m4/libtool.m4
@@ -0,0 +1,7360 @@
+# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
+#
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008 Free Software Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+m4_define([_LT_COPYING], [dnl
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008 Free Software Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+#   This file is part of GNU Libtool.
+#
+# GNU Libtool is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from http://www.gnu.org/licenses/gpl.html, or
+# obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+])
+
+# serial 56 LT_INIT
+
+
+# LT_PREREQ(VERSION)
+# ------------------
+# Complain and exit if this libtool version is less that VERSION.
+m4_defun([LT_PREREQ],
+[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1,
+       [m4_default([$3],
+		   [m4_fatal([Libtool version $1 or higher is required],
+		             63)])],
+       [$2])])
+
+
+# _LT_CHECK_BUILDDIR
+# ------------------
+# Complain if the absolute build directory name contains unusual characters
+m4_defun([_LT_CHECK_BUILDDIR],
+[case `pwd` in
+  *\ * | *\	*)
+    AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;;
+esac
+])
+
+
+# LT_INIT([OPTIONS])
+# ------------------
+AC_DEFUN([LT_INIT],
+[AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT
+AC_BEFORE([$0], [LT_LANG])dnl
+AC_BEFORE([$0], [LT_OUTPUT])dnl
+AC_BEFORE([$0], [LTDL_INIT])dnl
+m4_require([_LT_CHECK_BUILDDIR])dnl
+
+dnl Autoconf doesn't catch unexpanded LT_ macros by default:
+m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl
+m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl
+dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4
+dnl unless we require an AC_DEFUNed macro:
+AC_REQUIRE([LTOPTIONS_VERSION])dnl
+AC_REQUIRE([LTSUGAR_VERSION])dnl
+AC_REQUIRE([LTVERSION_VERSION])dnl
+AC_REQUIRE([LTOBSOLETE_VERSION])dnl
+m4_require([_LT_PROG_LTMAIN])dnl
+
+dnl Parse OPTIONS
+_LT_SET_OPTIONS([$0], [$1])
+
+# This can be used to rebuild libtool when needed
+LIBTOOL_DEPS="$ltmain"
+
+# Always use our own libtool.
+LIBTOOL='$(SHELL) $(top_builddir)/libtool'
+AC_SUBST(LIBTOOL)dnl
+
+_LT_SETUP
+
+# Only expand once:
+m4_define([LT_INIT])
+])# LT_INIT
+
+# Old names:
+AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT])
+AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_PROG_LIBTOOL], [])
+dnl AC_DEFUN([AM_PROG_LIBTOOL], [])
+
+
+# _LT_CC_BASENAME(CC)
+# -------------------
+# Calculate cc_basename.  Skip known compiler wrappers and cross-prefix.
+m4_defun([_LT_CC_BASENAME],
+[for cc_temp in $1""; do
+  case $cc_temp in
+    compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;;
+    distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
+])
+
+
+# _LT_FILEUTILS_DEFAULTS
+# ----------------------
+# It is okay to use these file commands and assume they have been set
+# sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'.
+m4_defun([_LT_FILEUTILS_DEFAULTS],
+[: ${CP="cp -f"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+])# _LT_FILEUTILS_DEFAULTS
+
+
+# _LT_SETUP
+# ---------
+m4_defun([_LT_SETUP],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+_LT_DECL([], [host_alias], [0], [The host system])dnl
+_LT_DECL([], [host], [0])dnl
+_LT_DECL([], [host_os], [0])dnl
+dnl
+_LT_DECL([], [build_alias], [0], [The build system])dnl
+_LT_DECL([], [build], [0])dnl
+_LT_DECL([], [build_os], [0])dnl
+dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([LT_PATH_LD])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+dnl
+AC_REQUIRE([AC_PROG_LN_S])dnl
+test -z "$LN_S" && LN_S="ln -s"
+_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl
+dnl
+AC_REQUIRE([LT_CMD_MAX_LEN])dnl
+_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl
+_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl
+dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_CHECK_SHELL_FEATURES])dnl
+m4_require([_LT_CMD_RELOAD])dnl
+m4_require([_LT_CHECK_MAGIC_METHOD])dnl
+m4_require([_LT_CMD_OLD_ARCHIVE])dnl
+m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
+
+_LT_CONFIG_LIBTOOL_INIT([
+# See if we are running on zsh, and set the options which allow our
+# commands through without removal of \ escapes INIT.
+if test -n "\${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+])
+if test -n "${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+
+_LT_CHECK_OBJDIR
+
+m4_require([_LT_TAG_COMPILER])dnl
+_LT_PROG_ECHO_BACKSLASH
+
+case $host_os in
+aix3*)
+  # AIX sometimes has problems with the GCC collect2 program.  For some
+  # reason, if we set the COLLECT_NAMES environment variable, the problems
+  # vanish in a puff of smoke.
+  if test "X${COLLECT_NAMES+set}" != Xset; then
+    COLLECT_NAMES=
+    export COLLECT_NAMES
+  fi
+  ;;
+esac
+
+# Sed substitution that helps us do robust quoting.  It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='s/\([["`$\\]]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\([["`\\]]\)/\\\1/g'
+
+# Sed substitution to delay expansion of an escaped shell variable in a
+# double_quote_subst'ed string.
+delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
+
+# Sed substitution to delay expansion of an escaped single quote.
+delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g'
+
+# Sed substitution to avoid accidental globbing in evaled expressions
+no_glob_subst='s/\*/\\\*/g'
+
+# Global variables:
+ofile=libtool
+can_build_shared=yes
+
+# All known linkers require a `.a' archive for static linking (except MSVC,
+# which needs '.lib').
+libext=a
+
+with_gnu_ld="$lt_cv_prog_gnu_ld"
+
+old_CC="$CC"
+old_CFLAGS="$CFLAGS"
+
+# Set sane defaults for various variables
+test -z "$CC" && CC=cc
+test -z "$LTCC" && LTCC=$CC
+test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
+test -z "$LD" && LD=ld
+test -z "$ac_objext" && ac_objext=o
+
+_LT_CC_BASENAME([$compiler])
+
+# Only perform the check for file, if the check method requires it
+test -z "$MAGIC_CMD" && MAGIC_CMD=file
+case $deplibs_check_method in
+file_magic*)
+  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
+    _LT_PATH_MAGIC
+  fi
+  ;;
+esac
+
+# Use C for the default configuration in the libtool script
+LT_SUPPORTED_TAG([CC])
+_LT_LANG_C_CONFIG
+_LT_LANG_DEFAULT_CONFIG
+_LT_CONFIG_COMMANDS
+])# _LT_SETUP
+
+
+# _LT_PROG_LTMAIN
+# ---------------
+# Note that this code is called both from `configure', and `config.status'
+# now that we use AC_CONFIG_COMMANDS to generate libtool.  Notably,
+# `config.status' has no value for ac_aux_dir unless we are using Automake,
+# so we pass a copy along to make sure it has a sensible value anyway.
+m4_defun([_LT_PROG_LTMAIN],
+[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl
+_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir'])
+ltmain="$ac_aux_dir/ltmain.sh"
+])# _LT_PROG_LTMAIN
+
+
+## ------------------------------------- ##
+## Accumulate code for creating libtool. ##
+## ------------------------------------- ##
+
+# So that we can recreate a full libtool script including additional
+# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS
+# in macros and then make a single call at the end using the `libtool'
+# label.
+
+
+# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS])
+# ----------------------------------------
+# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later.
+m4_define([_LT_CONFIG_LIBTOOL_INIT],
+[m4_ifval([$1],
+          [m4_append([_LT_OUTPUT_LIBTOOL_INIT],
+                     [$1
+])])])
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_INIT])
+
+
+# _LT_CONFIG_LIBTOOL([COMMANDS])
+# ------------------------------
+# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later.
+m4_define([_LT_CONFIG_LIBTOOL],
+[m4_ifval([$1],
+          [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS],
+                     [$1
+])])])
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS])
+
+
+# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS])
+# -----------------------------------------------------
+m4_defun([_LT_CONFIG_SAVE_COMMANDS],
+[_LT_CONFIG_LIBTOOL([$1])
+_LT_CONFIG_LIBTOOL_INIT([$2])
+])
+
+
+# _LT_FORMAT_COMMENT([COMMENT])
+# -----------------------------
+# Add leading comment marks to the start of each line, and a trailing
+# full-stop to the whole comment if one is not present already.
+m4_define([_LT_FORMAT_COMMENT],
+[m4_ifval([$1], [
+m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])],
+              [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.])
+)])
+
+
+
+## ------------------------ ##
+## FIXME: Eliminate VARNAME ##
+## ------------------------ ##
+
+
+# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?])
+# -------------------------------------------------------------------
+# CONFIGNAME is the name given to the value in the libtool script.
+# VARNAME is the (base) name used in the configure script.
+# VALUE may be 0, 1 or 2 for a computed quote escaped value based on
+# VARNAME.  Any other value will be used directly.
+m4_define([_LT_DECL],
+[lt_if_append_uniq([lt_decl_varnames], [$2], [, ],
+    [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name],
+	[m4_ifval([$1], [$1], [$2])])
+    lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3])
+    m4_ifval([$4],
+	[lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])])
+    lt_dict_add_subkey([lt_decl_dict], [$2],
+	[tagged?], [m4_ifval([$5], [yes], [no])])])
+])
+
+
+# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION])
+# --------------------------------------------------------
+m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])])
+
+
+# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...])
+# ------------------------------------------------
+m4_define([lt_decl_tag_varnames],
+[_lt_decl_filter([tagged?], [yes], $@)])
+
+
+# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..])
+# ---------------------------------------------------------
+m4_define([_lt_decl_filter],
+[m4_case([$#],
+  [0], [m4_fatal([$0: too few arguments: $#])],
+  [1], [m4_fatal([$0: too few arguments: $#: $1])],
+  [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)],
+  [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)],
+  [lt_dict_filter([lt_decl_dict], $@)])[]dnl
+])
+
+
+# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...])
+# --------------------------------------------------
+m4_define([lt_decl_quote_varnames],
+[_lt_decl_filter([value], [1], $@)])
+
+
+# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...])
+# ---------------------------------------------------
+m4_define([lt_decl_dquote_varnames],
+[_lt_decl_filter([value], [2], $@)])
+
+
+# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...])
+# ---------------------------------------------------
+m4_define([lt_decl_varnames_tagged],
+[m4_assert([$# <= 2])dnl
+_$0(m4_quote(m4_default([$1], [[, ]])),
+    m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]),
+    m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))])
+m4_define([_lt_decl_varnames_tagged],
+[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])])
+
+
+# lt_decl_all_varnames([SEPARATOR], [VARNAME1...])
+# ------------------------------------------------
+m4_define([lt_decl_all_varnames],
+[_$0(m4_quote(m4_default([$1], [[, ]])),
+     m4_if([$2], [],
+	   m4_quote(lt_decl_varnames),
+	m4_quote(m4_shift($@))))[]dnl
+])
+m4_define([_lt_decl_all_varnames],
+[lt_join($@, lt_decl_varnames_tagged([$1],
+			lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl
+])
+
+
+# _LT_CONFIG_STATUS_DECLARE([VARNAME])
+# ------------------------------------
+# Quote a variable value, and forward it to `config.status' so that its
+# declaration there will have the same value as in `configure'.  VARNAME
+# must have a single quote delimited value for this to work.
+m4_define([_LT_CONFIG_STATUS_DECLARE],
+[$1='`$ECHO "X$][$1" | $Xsed -e "$delay_single_quote_subst"`'])
+
+
+# _LT_CONFIG_STATUS_DECLARATIONS
+# ------------------------------
+# We delimit libtool config variables with single quotes, so when
+# we write them to config.status, we have to be sure to quote all
+# embedded single quotes properly.  In configure, this macro expands
+# each variable declared with _LT_DECL (and _LT_TAGDECL) into:
+#
+#    <var>='`$ECHO "X$<var>" | $Xsed -e "$delay_single_quote_subst"`'
+m4_defun([_LT_CONFIG_STATUS_DECLARATIONS],
+[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames),
+    [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])])
+
+
+# _LT_LIBTOOL_TAGS
+# ----------------
+# Output comment and list of tags supported by the script
+m4_defun([_LT_LIBTOOL_TAGS],
+[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl
+available_tags="_LT_TAGS"dnl
+])
+
+
+# _LT_LIBTOOL_DECLARE(VARNAME, [TAG])
+# -----------------------------------
+# Extract the dictionary values for VARNAME (optionally with TAG) and
+# expand to a commented shell variable setting:
+#
+#    # Some comment about what VAR is for.
+#    visible_name=$lt_internal_name
+m4_define([_LT_LIBTOOL_DECLARE],
+[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1],
+					   [description])))[]dnl
+m4_pushdef([_libtool_name],
+    m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl
+m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])),
+    [0], [_libtool_name=[$]$1],
+    [1], [_libtool_name=$lt_[]$1],
+    [2], [_libtool_name=$lt_[]$1],
+    [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl
+m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl
+])
+
+
+# _LT_LIBTOOL_CONFIG_VARS
+# -----------------------
+# Produce commented declarations of non-tagged libtool config variables
+# suitable for insertion in the LIBTOOL CONFIG section of the `libtool'
+# script.  Tagged libtool config variables (even for the LIBTOOL CONFIG
+# section) are produced by _LT_LIBTOOL_TAG_VARS.
+m4_defun([_LT_LIBTOOL_CONFIG_VARS],
+[m4_foreach([_lt_var],
+    m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)),
+    [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])])
+
+
+# _LT_LIBTOOL_TAG_VARS(TAG)
+# -------------------------
+m4_define([_LT_LIBTOOL_TAG_VARS],
+[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames),
+    [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])])
+
+
+# _LT_TAGVAR(VARNAME, [TAGNAME])
+# ------------------------------
+m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])])
+
+
+# _LT_CONFIG_COMMANDS
+# -------------------
+# Send accumulated output to $CONFIG_STATUS.  Thanks to the lists of
+# variables for single and double quote escaping we saved from calls
+# to _LT_DECL, we can put quote escaped variables declarations
+# into `config.status', and then the shell code to quote escape them in
+# for loops in `config.status'.  Finally, any additional code accumulated
+# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded.
+m4_defun([_LT_CONFIG_COMMANDS],
+[AC_PROVIDE_IFELSE([LT_OUTPUT],
+	dnl If the libtool generation code has been placed in $CONFIG_LT,
+	dnl instead of duplicating it all over again into config.status,
+	dnl then we will have config.status run $CONFIG_LT later, so it
+	dnl needs to know what name is stored there:
+        [AC_CONFIG_COMMANDS([libtool],
+            [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])],
+    dnl If the libtool generation code is destined for config.status,
+    dnl expand the accumulated commands and init code now:
+    [AC_CONFIG_COMMANDS([libtool],
+        [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])])
+])#_LT_CONFIG_COMMANDS
+
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT],
+[
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+sed_quote_subst='$sed_quote_subst'
+double_quote_subst='$double_quote_subst'
+delay_variable_subst='$delay_variable_subst'
+_LT_CONFIG_STATUS_DECLARATIONS
+LTCC='$LTCC'
+LTCFLAGS='$LTCFLAGS'
+compiler='$compiler_DEFAULT'
+
+# Quote evaled strings.
+for var in lt_decl_all_varnames([[ \
+]], lt_decl_quote_varnames); do
+    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
+    *[[\\\\\\\`\\"\\\$]]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Double-quote double-evaled strings.
+for var in lt_decl_all_varnames([[ \
+]], lt_decl_dquote_varnames); do
+    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
+    *[[\\\\\\\`\\"\\\$]]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Fix-up fallback echo if it was mangled by the above quoting rules.
+case \$lt_ECHO in
+*'\\\[$]0 --fallback-echo"')dnl "
+  lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\[$]0 --fallback-echo"\[$]/\[$]0 --fallback-echo"/'\`
+  ;;
+esac
+
+_LT_OUTPUT_LIBTOOL_INIT
+])
+
+
+# LT_OUTPUT
+# ---------
+# This macro allows early generation of the libtool script (before
+# AC_OUTPUT is called), incase it is used in configure for compilation
+# tests.
+AC_DEFUN([LT_OUTPUT],
+[: ${CONFIG_LT=./config.lt}
+AC_MSG_NOTICE([creating $CONFIG_LT])
+cat >"$CONFIG_LT" <<_LTEOF
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate a libtool stub with the current configuration.
+
+lt_cl_silent=false
+SHELL=\${CONFIG_SHELL-$SHELL}
+_LTEOF
+
+cat >>"$CONFIG_LT" <<\_LTEOF
+AS_SHELL_SANITIZE
+_AS_PREPARE
+
+exec AS_MESSAGE_FD>&1
+exec AS_MESSAGE_LOG_FD>>config.log
+{
+  echo
+  AS_BOX([Running $as_me.])
+} >&AS_MESSAGE_LOG_FD
+
+lt_cl_help="\
+\`$as_me' creates a local libtool stub from the current configuration,
+for use in further configure time tests before the real libtool is
+generated.
+
+Usage: $[0] [[OPTIONS]]
+
+  -h, --help      print this help, then exit
+  -V, --version   print version number, then exit
+  -q, --quiet     do not print progress messages
+  -d, --debug     don't remove temporary files
+
+Report bugs to <bug-libtool@gnu.org>."
+
+lt_cl_version="\
+m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl
+m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION])
+configured by $[0], generated by m4_PACKAGE_STRING.
+
+Copyright (C) 2008 Free Software Foundation, Inc.
+This config.lt script is free software; the Free Software Foundation
+gives unlimited permision to copy, distribute and modify it."
+
+while test $[#] != 0
+do
+  case $[1] in
+    --version | --v* | -V )
+      echo "$lt_cl_version"; exit 0 ;;
+    --help | --h* | -h )
+      echo "$lt_cl_help"; exit 0 ;;
+    --debug | --d* | -d )
+      debug=: ;;
+    --quiet | --q* | --silent | --s* | -q )
+      lt_cl_silent=: ;;
+
+    -*) AC_MSG_ERROR([unrecognized option: $[1]
+Try \`$[0] --help' for more information.]) ;;
+
+    *) AC_MSG_ERROR([unrecognized argument: $[1]
+Try \`$[0] --help' for more information.]) ;;
+  esac
+  shift
+done
+
+if $lt_cl_silent; then
+  exec AS_MESSAGE_FD>/dev/null
+fi
+_LTEOF
+
+cat >>"$CONFIG_LT" <<_LTEOF
+_LT_OUTPUT_LIBTOOL_COMMANDS_INIT
+_LTEOF
+
+cat >>"$CONFIG_LT" <<\_LTEOF
+AC_MSG_NOTICE([creating $ofile])
+_LT_OUTPUT_LIBTOOL_COMMANDS
+AS_EXIT(0)
+_LTEOF
+chmod +x "$CONFIG_LT"
+
+# configure is writing to config.log, but config.lt does its own redirection,
+# appending to config.log, which fails on DOS, as config.log is still kept
+# open by configure.  Here we exec the FD to /dev/null, effectively closing
+# config.log, so it can be properly (re)opened and appended to by config.lt.
+if test "$no_create" != yes; then
+  lt_cl_success=:
+  test "$silent" = yes &&
+    lt_config_lt_args="$lt_config_lt_args --quiet"
+  exec AS_MESSAGE_LOG_FD>/dev/null
+  $SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false
+  exec AS_MESSAGE_LOG_FD>>config.log
+  $lt_cl_success || AS_EXIT(1)
+fi
+])# LT_OUTPUT
+
+
+# _LT_CONFIG(TAG)
+# ---------------
+# If TAG is the built-in tag, create an initial libtool script with a
+# default configuration from the untagged config vars.  Otherwise add code
+# to config.status for appending the configuration named by TAG from the
+# matching tagged config vars.
+m4_defun([_LT_CONFIG],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+_LT_CONFIG_SAVE_COMMANDS([
+  m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl
+  m4_if(_LT_TAG, [C], [
+    # See if we are running on zsh, and set the options which allow our
+    # commands through without removal of \ escapes.
+    if test -n "${ZSH_VERSION+set}" ; then
+      setopt NO_GLOB_SUBST
+    fi
+
+    cfgfile="${ofile}T"
+    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
+    $RM "$cfgfile"
+
+    cat <<_LT_EOF >> "$cfgfile"
+#! $SHELL
+
+# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
+# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+# NOTE: Changes made to this file will be lost: look at ltmain.sh.
+#
+_LT_COPYING
+_LT_LIBTOOL_TAGS
+
+# ### BEGIN LIBTOOL CONFIG
+_LT_LIBTOOL_CONFIG_VARS
+_LT_LIBTOOL_TAG_VARS
+# ### END LIBTOOL CONFIG
+
+_LT_EOF
+
+  case $host_os in
+  aix3*)
+    cat <<\_LT_EOF >> "$cfgfile"
+# AIX sometimes has problems with the GCC collect2 program.  For some
+# reason, if we set the COLLECT_NAMES environment variable, the problems
+# vanish in a puff of smoke.
+if test "X${COLLECT_NAMES+set}" != Xset; then
+  COLLECT_NAMES=
+  export COLLECT_NAMES
+fi
+_LT_EOF
+    ;;
+  esac
+
+  _LT_PROG_LTMAIN
+
+  # We use sed instead of cat because bash on DJGPP gets confused if
+  # if finds mixed CR/LF and LF-only lines.  Since sed operates in
+  # text mode, it properly converts lines to CR/LF.  This bash problem
+  # is reportedly fixed, but why not run on old versions too?
+  sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \
+    || (rm -f "$cfgfile"; exit 1)
+
+  _LT_PROG_XSI_SHELLFNS
+
+  sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \
+    || (rm -f "$cfgfile"; exit 1)
+
+  mv -f "$cfgfile" "$ofile" ||
+    (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
+  chmod +x "$ofile"
+],
+[cat <<_LT_EOF >> "$ofile"
+
+dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded
+dnl in a comment (ie after a #).
+# ### BEGIN LIBTOOL TAG CONFIG: $1
+_LT_LIBTOOL_TAG_VARS(_LT_TAG)
+# ### END LIBTOOL TAG CONFIG: $1
+_LT_EOF
+])dnl /m4_if
+],
+[m4_if([$1], [], [
+    PACKAGE='$PACKAGE'
+    VERSION='$VERSION'
+    TIMESTAMP='$TIMESTAMP'
+    RM='$RM'
+    ofile='$ofile'], [])
+])dnl /_LT_CONFIG_SAVE_COMMANDS
+])# _LT_CONFIG
+
+
+# LT_SUPPORTED_TAG(TAG)
+# ---------------------
+# Trace this macro to discover what tags are supported by the libtool
+# --tag option, using:
+#    autoconf --trace 'LT_SUPPORTED_TAG:$1'
+AC_DEFUN([LT_SUPPORTED_TAG], [])
+
+
+# C support is built-in for now
+m4_define([_LT_LANG_C_enabled], [])
+m4_define([_LT_TAGS], [])
+
+
+# LT_LANG(LANG)
+# -------------
+# Enable libtool support for the given language if not already enabled.
+AC_DEFUN([LT_LANG],
+[AC_BEFORE([$0], [LT_OUTPUT])dnl
+m4_case([$1],
+  [C],			[_LT_LANG(C)],
+  [C++],		[_LT_LANG(CXX)],
+  [Java],		[_LT_LANG(GCJ)],
+  [Fortran 77],		[_LT_LANG(F77)],
+  [Fortran],		[_LT_LANG(FC)],
+  [Windows Resource],	[_LT_LANG(RC)],
+  [m4_ifdef([_LT_LANG_]$1[_CONFIG],
+    [_LT_LANG($1)],
+    [m4_fatal([$0: unsupported language: "$1"])])])dnl
+])# LT_LANG
+
+
+# _LT_LANG(LANGNAME)
+# ------------------
+m4_defun([_LT_LANG],
+[m4_ifdef([_LT_LANG_]$1[_enabled], [],
+  [LT_SUPPORTED_TAG([$1])dnl
+  m4_append([_LT_TAGS], [$1 ])dnl
+  m4_define([_LT_LANG_]$1[_enabled], [])dnl
+  _LT_LANG_$1_CONFIG($1)])dnl
+])# _LT_LANG
+
+
+# _LT_LANG_DEFAULT_CONFIG
+# -----------------------
+m4_defun([_LT_LANG_DEFAULT_CONFIG],
+[AC_PROVIDE_IFELSE([AC_PROG_CXX],
+  [LT_LANG(CXX)],
+  [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])])
+
+AC_PROVIDE_IFELSE([AC_PROG_F77],
+  [LT_LANG(F77)],
+  [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])])
+
+AC_PROVIDE_IFELSE([AC_PROG_FC],
+  [LT_LANG(FC)],
+  [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])])
+
+dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal
+dnl pulling things in needlessly.
+AC_PROVIDE_IFELSE([AC_PROG_GCJ],
+  [LT_LANG(GCJ)],
+  [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],
+    [LT_LANG(GCJ)],
+    [AC_PROVIDE_IFELSE([LT_PROG_GCJ],
+      [LT_LANG(GCJ)],
+      [m4_ifdef([AC_PROG_GCJ],
+	[m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])])
+       m4_ifdef([A][M_PROG_GCJ],
+	[m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])])
+       m4_ifdef([LT_PROG_GCJ],
+	[m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])])
+
+AC_PROVIDE_IFELSE([LT_PROG_RC],
+  [LT_LANG(RC)],
+  [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])])
+])# _LT_LANG_DEFAULT_CONFIG
+
+# Obsolete macros:
+AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)])
+AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)])
+AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)])
+AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_CXX], [])
+dnl AC_DEFUN([AC_LIBTOOL_F77], [])
+dnl AC_DEFUN([AC_LIBTOOL_FC], [])
+dnl AC_DEFUN([AC_LIBTOOL_GCJ], [])
+
+
+# _LT_TAG_COMPILER
+# ----------------
+m4_defun([_LT_TAG_COMPILER],
+[AC_REQUIRE([AC_PROG_CC])dnl
+
+_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl
+_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl
+_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl
+_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+])# _LT_TAG_COMPILER
+
+
+# _LT_COMPILER_BOILERPLATE
+# ------------------------
+# Check for compiler boilerplate output or warnings with
+# the simple compiler test code.
+m4_defun([_LT_COMPILER_BOILERPLATE],
+[m4_require([_LT_DECL_SED])dnl
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$RM conftest*
+])# _LT_COMPILER_BOILERPLATE
+
+
+# _LT_LINKER_BOILERPLATE
+# ----------------------
+# Check for linker boilerplate output or warnings with
+# the simple link test code.
+m4_defun([_LT_LINKER_BOILERPLATE],
+[m4_require([_LT_DECL_SED])dnl
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$RM -r conftest*
+])# _LT_LINKER_BOILERPLATE
+
+# _LT_REQUIRED_DARWIN_CHECKS
+# -------------------------
+m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[
+  case $host_os in
+    rhapsody* | darwin*)
+    AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:])
+    AC_CHECK_TOOL([NMEDIT], [nmedit], [:])
+    AC_CHECK_TOOL([LIPO], [lipo], [:])
+    AC_CHECK_TOOL([OTOOL], [otool], [:])
+    AC_CHECK_TOOL([OTOOL64], [otool64], [:])
+    _LT_DECL([], [DSYMUTIL], [1],
+      [Tool to manipulate archived DWARF debug symbol files on Mac OS X])
+    _LT_DECL([], [NMEDIT], [1],
+      [Tool to change global to local symbols on Mac OS X])
+    _LT_DECL([], [LIPO], [1],
+      [Tool to manipulate fat objects and archives on Mac OS X])
+    _LT_DECL([], [OTOOL], [1],
+      [ldd/readelf like tool for Mach-O binaries on Mac OS X])
+    _LT_DECL([], [OTOOL64], [1],
+      [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4])
+
+    AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod],
+      [lt_cv_apple_cc_single_mod=no
+      if test -z "${LT_MULTI_MODULE}"; then
+	# By default we will add the -single_module flag. You can override
+	# by either setting the environment variable LT_MULTI_MODULE
+	# non-empty at configure time, or by adding -multi_module to the
+	# link flags.
+	rm -rf libconftest.dylib*
+	echo "int foo(void){return 1;}" > conftest.c
+	echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+-dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD
+	$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+	  -dynamiclib -Wl,-single_module conftest.c 2>conftest.err
+        _lt_result=$?
+	if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then
+	  lt_cv_apple_cc_single_mod=yes
+	else
+	  cat conftest.err >&AS_MESSAGE_LOG_FD
+	fi
+	rm -rf libconftest.dylib*
+	rm -f conftest.*
+      fi])
+    AC_CACHE_CHECK([for -exported_symbols_list linker flag],
+      [lt_cv_ld_exported_symbols_list],
+      [lt_cv_ld_exported_symbols_list=no
+      save_LDFLAGS=$LDFLAGS
+      echo "_main" > conftest.sym
+      LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
+	[lt_cv_ld_exported_symbols_list=yes],
+	[lt_cv_ld_exported_symbols_list=no])
+	LDFLAGS="$save_LDFLAGS"
+    ])
+    case $host_os in
+    rhapsody* | darwin1.[[012]])
+      _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
+    darwin1.*)
+      _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+    darwin*) # darwin 5.x on
+      # if running on 10.5 or later, the deployment target defaults
+      # to the OS version, if on x86, and 10.4, the deployment
+      # target defaults to 10.4. Don't you love it?
+      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
+	10.0,*86*-darwin8*|10.0,*-darwin[[91]]*)
+	  _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+	10.[[012]]*)
+	  _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+	10.*)
+	  _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+      esac
+    ;;
+  esac
+    if test "$lt_cv_apple_cc_single_mod" = "yes"; then
+      _lt_dar_single_mod='$single_module'
+    fi
+    if test "$lt_cv_ld_exported_symbols_list" = "yes"; then
+      _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym'
+    else
+      _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    fi
+    if test "$DSYMUTIL" != ":"; then
+      _lt_dsymutil='~$DSYMUTIL $lib || :'
+    else
+      _lt_dsymutil=
+    fi
+    ;;
+  esac
+])
+
+
+# _LT_DARWIN_LINKER_FEATURES
+# --------------------------
+# Checks for linker and compiler features on darwin
+m4_defun([_LT_DARWIN_LINKER_FEATURES],
+[
+  m4_require([_LT_REQUIRED_DARWIN_CHECKS])
+  _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+  _LT_TAGVAR(hardcode_direct, $1)=no
+  _LT_TAGVAR(hardcode_automatic, $1)=yes
+  _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+  _LT_TAGVAR(whole_archive_flag_spec, $1)=''
+  _LT_TAGVAR(link_all_deplibs, $1)=yes
+  _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined"
+  case $cc_basename in
+     ifort*) _lt_dar_can_shared=yes ;;
+     *) _lt_dar_can_shared=$GCC ;;
+  esac
+  if test "$_lt_dar_can_shared" = "yes"; then
+    output_verbose_link_cmd=echo
+    _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
+    _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
+    _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
+    _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
+    m4_if([$1], [CXX],
+[   if test "$lt_cv_apple_cc_single_mod" != "yes"; then
+      _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}"
+      _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}"
+    fi
+],[])
+  else
+  _LT_TAGVAR(ld_shlibs, $1)=no
+  fi
+])
+
+# _LT_SYS_MODULE_PATH_AIX
+# -----------------------
+# Links a minimal program and checks the executable
+# for the system default hardcoded library path. In most cases,
+# this is /usr/lib:/lib, but when the MPI compilers are used
+# the location of the communication and MPI libs are included too.
+# If we don't find anything, use the default library path according
+# to the aix ld manual.
+m4_defun([_LT_SYS_MODULE_PATH_AIX],
+[m4_require([_LT_DECL_SED])dnl
+AC_LINK_IFELSE(AC_LANG_PROGRAM,[
+lt_aix_libpath_sed='
+    /Import File Strings/,/^$/ {
+	/^0/ {
+	    s/^0  *\(.*\)$/\1/
+	    p
+	}
+    }'
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+# Check for a 64-bit object if we didn't find anything.
+if test -z "$aix_libpath"; then
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+fi],[])
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+])# _LT_SYS_MODULE_PATH_AIX
+
+
+# _LT_SHELL_INIT(ARG)
+# -------------------
+m4_define([_LT_SHELL_INIT],
+[ifdef([AC_DIVERSION_NOTICE],
+	     [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)],
+	 [AC_DIVERT_PUSH(NOTICE)])
+$1
+AC_DIVERT_POP
+])# _LT_SHELL_INIT
+
+
+# _LT_PROG_ECHO_BACKSLASH
+# -----------------------
+# Add some code to the start of the generated configure script which
+# will find an echo command which doesn't interpret backslashes.
+m4_defun([_LT_PROG_ECHO_BACKSLASH],
+[_LT_SHELL_INIT([
+# Check that we are running under the correct shell.
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+case X$lt_ECHO in
+X*--fallback-echo)
+  # Remove one level of quotation (which was required for Make).
+  ECHO=`echo "$lt_ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','`
+  ;;
+esac
+
+ECHO=${lt_ECHO-echo}
+if test "X[$]1" = X--no-reexec; then
+  # Discard the --no-reexec flag, and continue.
+  shift
+elif test "X[$]1" = X--fallback-echo; then
+  # Avoid inline document here, it may be left over
+  :
+elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then
+  # Yippee, $ECHO works!
+  :
+else
+  # Restart under the correct shell.
+  exec $SHELL "[$]0" --no-reexec ${1+"[$]@"}
+fi
+
+if test "X[$]1" = X--fallback-echo; then
+  # used as fallback echo
+  shift
+  cat <<_LT_EOF
+[$]*
+_LT_EOF
+  exit 0
+fi
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+if test -z "$lt_ECHO"; then
+  if test "X${echo_test_string+set}" != Xset; then
+    # find a string as large as possible, as long as the shell can cope with it
+    for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do
+      # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
+      if { echo_test_string=`eval $cmd`; } 2>/dev/null &&
+	 { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null
+      then
+        break
+      fi
+    done
+  fi
+
+  if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
+     echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
+     test "X$echo_testing_string" = "X$echo_test_string"; then
+    :
+  else
+    # The Solaris, AIX, and Digital Unix default echo programs unquote
+    # backslashes.  This makes it impossible to quote backslashes using
+    #   echo "$something" | sed 's/\\/\\\\/g'
+    #
+    # So, first we look for a working echo in the user's PATH.
+
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for dir in $PATH /usr/ucb; do
+      IFS="$lt_save_ifs"
+      if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
+         test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
+         echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
+         test "X$echo_testing_string" = "X$echo_test_string"; then
+        ECHO="$dir/echo"
+        break
+      fi
+    done
+    IFS="$lt_save_ifs"
+
+    if test "X$ECHO" = Xecho; then
+      # We didn't find a better echo, so look for alternatives.
+      if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' &&
+         echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` &&
+         test "X$echo_testing_string" = "X$echo_test_string"; then
+        # This shell has a builtin print -r that does the trick.
+        ECHO='print -r'
+      elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } &&
+	   test "X$CONFIG_SHELL" != X/bin/ksh; then
+        # If we have ksh, try running configure again with it.
+        ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
+        export ORIGINAL_CONFIG_SHELL
+        CONFIG_SHELL=/bin/ksh
+        export CONFIG_SHELL
+        exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"}
+      else
+        # Try using printf.
+        ECHO='printf %s\n'
+        if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
+	   echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
+	   test "X$echo_testing_string" = "X$echo_test_string"; then
+	  # Cool, printf works
+	  :
+        elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
+	     test "X$echo_testing_string" = 'X\t' &&
+	     echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+	     test "X$echo_testing_string" = "X$echo_test_string"; then
+	  CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
+	  export CONFIG_SHELL
+	  SHELL="$CONFIG_SHELL"
+	  export SHELL
+	  ECHO="$CONFIG_SHELL [$]0 --fallback-echo"
+        elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
+	     test "X$echo_testing_string" = 'X\t' &&
+	     echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
+	     test "X$echo_testing_string" = "X$echo_test_string"; then
+	  ECHO="$CONFIG_SHELL [$]0 --fallback-echo"
+        else
+	  # maybe with a smaller string...
+	  prev=:
+
+	  for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do
+	    if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null
+	    then
+	      break
+	    fi
+	    prev="$cmd"
+	  done
+
+	  if test "$prev" != 'sed 50q "[$]0"'; then
+	    echo_test_string=`eval $prev`
+	    export echo_test_string
+	    exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"}
+	  else
+	    # Oops.  We lost completely, so just stick with echo.
+	    ECHO=echo
+	  fi
+        fi
+      fi
+    fi
+  fi
+fi
+
+# Copy echo and quote the copy suitably for passing to libtool from
+# the Makefile, instead of quoting the original, which is used later.
+lt_ECHO=$ECHO
+if test "X$lt_ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then
+   lt_ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo"
+fi
+
+AC_SUBST(lt_ECHO)
+])
+_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts])
+_LT_DECL([], [ECHO], [1],
+    [An echo program that does not interpret backslashes])
+])# _LT_PROG_ECHO_BACKSLASH
+
+
+# _LT_ENABLE_LOCK
+# ---------------
+m4_defun([_LT_ENABLE_LOCK],
+[AC_ARG_ENABLE([libtool-lock],
+  [AS_HELP_STRING([--disable-libtool-lock],
+    [avoid locking (might break parallel builds)])])
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+
+# Some flags need to be propagated to the compiler or linker for good
+# libtool support.
+case $host in
+ia64-*-hpux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.$ac_objext` in
+      *ELF-32*)
+	HPUX_IA64_MODE="32"
+	;;
+      *ELF-64*)
+	HPUX_IA64_MODE="64"
+	;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+*-*-irix6*)
+  # Find out which ABI we are using.
+  echo '[#]line __oline__ "configure"' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    if test "$lt_cv_prog_gnu_ld" = yes; then
+      case `/usr/bin/file conftest.$ac_objext` in
+	*32-bit*)
+	  LD="${LD-ld} -melf32bsmip"
+	  ;;
+	*N32*)
+	  LD="${LD-ld} -melf32bmipn32"
+	  ;;
+	*64-bit*)
+	  LD="${LD-ld} -melf64bmip"
+	;;
+      esac
+    else
+      case `/usr/bin/file conftest.$ac_objext` in
+	*32-bit*)
+	  LD="${LD-ld} -32"
+	  ;;
+	*N32*)
+	  LD="${LD-ld} -n32"
+	  ;;
+	*64-bit*)
+	  LD="${LD-ld} -64"
+	  ;;
+      esac
+    fi
+  fi
+  rm -rf conftest*
+  ;;
+
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.o` in
+      *32-bit*)
+	case $host in
+	  x86_64-*kfreebsd*-gnu)
+	    LD="${LD-ld} -m elf_i386_fbsd"
+	    ;;
+	  x86_64-*linux*)
+	    LD="${LD-ld} -m elf_i386"
+	    ;;
+	  ppc64-*linux*|powerpc64-*linux*)
+	    LD="${LD-ld} -m elf32ppclinux"
+	    ;;
+	  s390x-*linux*)
+	    LD="${LD-ld} -m elf_s390"
+	    ;;
+	  sparc64-*linux*)
+	    LD="${LD-ld} -m elf32_sparc"
+	    ;;
+	esac
+	;;
+      *64-bit*)
+	case $host in
+	  x86_64-*kfreebsd*-gnu)
+	    LD="${LD-ld} -m elf_x86_64_fbsd"
+	    ;;
+	  x86_64-*linux*)
+	    LD="${LD-ld} -m elf_x86_64"
+	    ;;
+	  ppc*-*linux*|powerpc*-*linux*)
+	    LD="${LD-ld} -m elf64ppc"
+	    ;;
+	  s390*-*linux*|s390*-*tpf*)
+	    LD="${LD-ld} -m elf64_s390"
+	    ;;
+	  sparc*-*linux*)
+	    LD="${LD-ld} -m elf64_sparc"
+	    ;;
+	esac
+	;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+
+*-*-sco3.2v5*)
+  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -belf"
+  AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf,
+    [AC_LANG_PUSH(C)
+     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no])
+     AC_LANG_POP])
+  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
+    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
+    CFLAGS="$SAVE_CFLAGS"
+  fi
+  ;;
+sparc*-*solaris*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.o` in
+    *64-bit*)
+      case $lt_cv_prog_gnu_ld in
+      yes*) LD="${LD-ld} -m elf64_sparc" ;;
+      *)
+	if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
+	  LD="${LD-ld} -64"
+	fi
+	;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+esac
+
+need_locks="$enable_libtool_lock"
+])# _LT_ENABLE_LOCK
+
+
+# _LT_CMD_OLD_ARCHIVE
+# -------------------
+m4_defun([_LT_CMD_OLD_ARCHIVE],
+[AC_CHECK_TOOL(AR, ar, false)
+test -z "$AR" && AR=ar
+test -z "$AR_FLAGS" && AR_FLAGS=cru
+_LT_DECL([], [AR], [1], [The archiver])
+_LT_DECL([], [AR_FLAGS], [1])
+
+AC_CHECK_TOOL(STRIP, strip, :)
+test -z "$STRIP" && STRIP=:
+_LT_DECL([], [STRIP], [1], [A symbol stripping program])
+
+AC_CHECK_TOOL(RANLIB, ranlib, :)
+test -z "$RANLIB" && RANLIB=:
+_LT_DECL([], [RANLIB], [1],
+    [Commands used to install an old-style archive])
+
+# Determine commands to create old-style static archives.
+old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
+old_postinstall_cmds='chmod 644 $oldlib'
+old_postuninstall_cmds=
+
+if test -n "$RANLIB"; then
+  case $host_os in
+  openbsd*)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib"
+    ;;
+  *)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib"
+    ;;
+  esac
+  old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
+fi
+_LT_DECL([], [old_postinstall_cmds], [2])
+_LT_DECL([], [old_postuninstall_cmds], [2])
+_LT_TAGDECL([], [old_archive_cmds], [2],
+    [Commands used to build an old-style archive])
+])# _LT_CMD_OLD_ARCHIVE
+
+
+# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
+#		[OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE])
+# ----------------------------------------------------------------
+# Check whether the given compiler option works
+AC_DEFUN([_LT_COMPILER_OPTION],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_CACHE_CHECK([$1], [$2],
+  [$2=no
+   m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4])
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$3"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&AS_MESSAGE_LOG_FD
+   echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       $2=yes
+     fi
+   fi
+   $RM conftest*
+])
+
+if test x"[$]$2" = xyes; then
+    m4_if([$5], , :, [$5])
+else
+    m4_if([$6], , :, [$6])
+fi
+])# _LT_COMPILER_OPTION
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], [])
+
+
+# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
+#                  [ACTION-SUCCESS], [ACTION-FAILURE])
+# ----------------------------------------------------
+# Check whether the given linker option works
+AC_DEFUN([_LT_LINKER_OPTION],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_CACHE_CHECK([$1], [$2],
+  [$2=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $3"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&AS_MESSAGE_LOG_FD
+       $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         $2=yes
+       fi
+     else
+       $2=yes
+     fi
+   fi
+   $RM -r conftest*
+   LDFLAGS="$save_LDFLAGS"
+])
+
+if test x"[$]$2" = xyes; then
+    m4_if([$4], , :, [$4])
+else
+    m4_if([$5], , :, [$5])
+fi
+])# _LT_LINKER_OPTION
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], [])
+
+
+# LT_CMD_MAX_LEN
+#---------------
+AC_DEFUN([LT_CMD_MAX_LEN],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+# find the maximum length of command line arguments
+AC_MSG_CHECKING([the maximum length of command line arguments])
+AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl
+  i=0
+  teststring="ABCD"
+
+  case $build_os in
+  msdosdjgpp*)
+    # On DJGPP, this test can blow up pretty badly due to problems in libc
+    # (any single argument exceeding 2000 bytes causes a buffer overrun
+    # during glob expansion).  Even if it were fixed, the result of this
+    # check would be larger than it should be.
+    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
+    ;;
+
+  gnu*)
+    # Under GNU Hurd, this test is not required because there is
+    # no limit to the length of command line arguments.
+    # Libtool will interpret -1 as no limit whatsoever
+    lt_cv_sys_max_cmd_len=-1;
+    ;;
+
+  cygwin* | mingw* | cegcc*)
+    # On Win9x/ME, this test blows up -- it succeeds, but takes
+    # about 5 minutes as the teststring grows exponentially.
+    # Worse, since 9x/ME are not pre-emptively multitasking,
+    # you end up with a "frozen" computer, even though with patience
+    # the test eventually succeeds (with a max line length of 256k).
+    # Instead, let's just punt: use the minimum linelength reported by
+    # all of the supported platforms: 8192 (on NT/2K/XP).
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  amigaos*)
+    # On AmigaOS with pdksh, this test takes hours, literally.
+    # So we just punt and use a minimum line length of 8192.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
+    # This has been around since 386BSD, at least.  Likely further.
+    if test -x /sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
+    elif test -x /usr/sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
+    else
+      lt_cv_sys_max_cmd_len=65536	# usable default for all BSDs
+    fi
+    # And add a safety zone
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    ;;
+
+  interix*)
+    # We know the value 262144 and hardcode it with a safety zone (like BSD)
+    lt_cv_sys_max_cmd_len=196608
+    ;;
+
+  osf*)
+    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
+    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
+    # nice to cause kernel panics so lets avoid the loop below.
+    # First set a reasonable default.
+    lt_cv_sys_max_cmd_len=16384
+    #
+    if test -x /sbin/sysconfig; then
+      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
+        *1*) lt_cv_sys_max_cmd_len=-1 ;;
+      esac
+    fi
+    ;;
+  sco3.2v5*)
+    lt_cv_sys_max_cmd_len=102400
+    ;;
+  sysv5* | sco5v6* | sysv4.2uw2*)
+    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
+    if test -n "$kargmax"; then
+      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[	 ]]//'`
+    else
+      lt_cv_sys_max_cmd_len=32768
+    fi
+    ;;
+  *)
+    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
+    if test -n "$lt_cv_sys_max_cmd_len"; then
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    else
+      # Make teststring a little bigger before we do anything with it.
+      # a 1K string should be a reasonable start.
+      for i in 1 2 3 4 5 6 7 8 ; do
+        teststring=$teststring$teststring
+      done
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
+      # If test is not a shell built-in, we'll probably end up computing a
+      # maximum length that is only half of the actual maximum length, but
+      # we can't tell.
+      while { test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \
+	         = "XX$teststring$teststring"; } >/dev/null 2>&1 &&
+	      test $i != 17 # 1/2 MB should be enough
+      do
+        i=`expr $i + 1`
+        teststring=$teststring$teststring
+      done
+      # Only check the string length outside the loop.
+      lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
+      teststring=
+      # Add a significant safety factor because C++ compilers can tack on
+      # massive amounts of additional arguments before passing them to the
+      # linker.  It appears as though 1/2 is a usable value.
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    fi
+    ;;
+  esac
+])
+if test -n $lt_cv_sys_max_cmd_len ; then
+  AC_MSG_RESULT($lt_cv_sys_max_cmd_len)
+else
+  AC_MSG_RESULT(none)
+fi
+max_cmd_len=$lt_cv_sys_max_cmd_len
+_LT_DECL([], [max_cmd_len], [0],
+    [What is the maximum length of a command?])
+])# LT_CMD_MAX_LEN
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], [])
+
+
+# _LT_HEADER_DLFCN
+# ----------------
+m4_defun([_LT_HEADER_DLFCN],
+[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl
+])# _LT_HEADER_DLFCN
+
+
+# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE,
+#                      ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING)
+# ----------------------------------------------------------------
+m4_defun([_LT_TRY_DLOPEN_SELF],
+[m4_require([_LT_HEADER_DLFCN])dnl
+if test "$cross_compiling" = yes; then :
+  [$4]
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+[#line __oline__ "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL		RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL		DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL		0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW		RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW		DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW	RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW	DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW	0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+void fnord() { int i=42;}
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+  return status;
+}]
+_LT_EOF
+  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) $1 ;;
+      x$lt_dlneed_uscore) $2 ;;
+      x$lt_dlunknown|x*) $3 ;;
+    esac
+  else :
+    # compilation failed
+    $3
+  fi
+fi
+rm -fr conftest*
+])# _LT_TRY_DLOPEN_SELF
+
+
+# LT_SYS_DLOPEN_SELF
+# ------------------
+AC_DEFUN([LT_SYS_DLOPEN_SELF],
+[m4_require([_LT_HEADER_DLFCN])dnl
+if test "x$enable_dlopen" != xyes; then
+  enable_dlopen=unknown
+  enable_dlopen_self=unknown
+  enable_dlopen_self_static=unknown
+else
+  lt_cv_dlopen=no
+  lt_cv_dlopen_libs=
+
+  case $host_os in
+  beos*)
+    lt_cv_dlopen="load_add_on"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ;;
+
+  mingw* | pw32* | cegcc*)
+    lt_cv_dlopen="LoadLibrary"
+    lt_cv_dlopen_libs=
+    ;;
+
+  cygwin*)
+    lt_cv_dlopen="dlopen"
+    lt_cv_dlopen_libs=
+    ;;
+
+  darwin*)
+  # if libdl is installed we need to link against it
+    AC_CHECK_LIB([dl], [dlopen],
+		[lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[
+    lt_cv_dlopen="dyld"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ])
+    ;;
+
+  *)
+    AC_CHECK_FUNC([shl_load],
+	  [lt_cv_dlopen="shl_load"],
+      [AC_CHECK_LIB([dld], [shl_load],
+	    [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"],
+	[AC_CHECK_FUNC([dlopen],
+	      [lt_cv_dlopen="dlopen"],
+	  [AC_CHECK_LIB([dl], [dlopen],
+		[lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],
+	    [AC_CHECK_LIB([svld], [dlopen],
+		  [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"],
+	      [AC_CHECK_LIB([dld], [dld_link],
+		    [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"])
+	      ])
+	    ])
+	  ])
+	])
+      ])
+    ;;
+  esac
+
+  if test "x$lt_cv_dlopen" != xno; then
+    enable_dlopen=yes
+  else
+    enable_dlopen=no
+  fi
+
+  case $lt_cv_dlopen in
+  dlopen)
+    save_CPPFLAGS="$CPPFLAGS"
+    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
+
+    save_LDFLAGS="$LDFLAGS"
+    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
+
+    save_LIBS="$LIBS"
+    LIBS="$lt_cv_dlopen_libs $LIBS"
+
+    AC_CACHE_CHECK([whether a program can dlopen itself],
+	  lt_cv_dlopen_self, [dnl
+	  _LT_TRY_DLOPEN_SELF(
+	    lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes,
+	    lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross)
+    ])
+
+    if test "x$lt_cv_dlopen_self" = xyes; then
+      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
+      AC_CACHE_CHECK([whether a statically linked program can dlopen itself],
+	  lt_cv_dlopen_self_static, [dnl
+	  _LT_TRY_DLOPEN_SELF(
+	    lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes,
+	    lt_cv_dlopen_self_static=no,  lt_cv_dlopen_self_static=cross)
+      ])
+    fi
+
+    CPPFLAGS="$save_CPPFLAGS"
+    LDFLAGS="$save_LDFLAGS"
+    LIBS="$save_LIBS"
+    ;;
+  esac
+
+  case $lt_cv_dlopen_self in
+  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
+  *) enable_dlopen_self=unknown ;;
+  esac
+
+  case $lt_cv_dlopen_self_static in
+  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
+  *) enable_dlopen_self_static=unknown ;;
+  esac
+fi
+_LT_DECL([dlopen_support], [enable_dlopen], [0],
+	 [Whether dlopen is supported])
+_LT_DECL([dlopen_self], [enable_dlopen_self], [0],
+	 [Whether dlopen of programs is supported])
+_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0],
+	 [Whether dlopen of statically linked programs is supported])
+])# LT_SYS_DLOPEN_SELF
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], [])
+
+
+# _LT_COMPILER_C_O([TAGNAME])
+# ---------------------------
+# Check to see if options -c and -o are simultaneously supported by compiler.
+# This macro does not hard code the compiler like AC_PROG_CC_C_O.
+m4_defun([_LT_COMPILER_C_O],
+[m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext],
+  [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)],
+  [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&AS_MESSAGE_LOG_FD
+   echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
+     fi
+   fi
+   chmod u+w . 2>&AS_MESSAGE_LOG_FD
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+])
+_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1],
+	[Does compiler simultaneously support -c and -o options?])
+])# _LT_COMPILER_C_O
+
+
+# _LT_COMPILER_FILE_LOCKS([TAGNAME])
+# ----------------------------------
+# Check to see if we can do hard links to lock some files if needed
+m4_defun([_LT_COMPILER_FILE_LOCKS],
+[m4_require([_LT_ENABLE_LOCK])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+_LT_COMPILER_C_O([$1])
+
+hard_links="nottested"
+if test "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  AC_MSG_CHECKING([if we can lock with hard links])
+  hard_links=yes
+  $RM conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  AC_MSG_RESULT([$hard_links])
+  if test "$hard_links" = no; then
+    AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe])
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?])
+])# _LT_COMPILER_FILE_LOCKS
+
+
+# _LT_CHECK_OBJDIR
+# ----------------
+m4_defun([_LT_CHECK_OBJDIR],
+[AC_CACHE_CHECK([for objdir], [lt_cv_objdir],
+[rm -f .libs 2>/dev/null
+mkdir .libs 2>/dev/null
+if test -d .libs; then
+  lt_cv_objdir=.libs
+else
+  # MS-DOS does not allow filenames that begin with a dot.
+  lt_cv_objdir=_libs
+fi
+rmdir .libs 2>/dev/null])
+objdir=$lt_cv_objdir
+_LT_DECL([], [objdir], [0],
+         [The name of the directory that contains temporary libtool files])dnl
+m4_pattern_allow([LT_OBJDIR])dnl
+AC_DEFINE_UNQUOTED(LT_OBJDIR, "$lt_cv_objdir/",
+  [Define to the sub-directory in which libtool stores uninstalled libraries.])
+])# _LT_CHECK_OBJDIR
+
+
+# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME])
+# --------------------------------------
+# Check hardcoding attributes.
+m4_defun([_LT_LINKER_HARDCODE_LIBPATH],
+[AC_MSG_CHECKING([how to hardcode library paths into programs])
+_LT_TAGVAR(hardcode_action, $1)=
+if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" ||
+   test -n "$_LT_TAGVAR(runpath_var, $1)" ||
+   test "X$_LT_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then
+
+  # We can hardcode non-existent directories.
+  if test "$_LT_TAGVAR(hardcode_direct, $1)" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no &&
+     test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then
+    # Linking always hardcodes the temporary library directory.
+    _LT_TAGVAR(hardcode_action, $1)=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    _LT_TAGVAR(hardcode_action, $1)=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  _LT_TAGVAR(hardcode_action, $1)=unsupported
+fi
+AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)])
+
+if test "$_LT_TAGVAR(hardcode_action, $1)" = relink ||
+   test "$_LT_TAGVAR(inherit_rpath, $1)" = yes; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+_LT_TAGDECL([], [hardcode_action], [0],
+    [How to hardcode a shared library path into an executable])
+])# _LT_LINKER_HARDCODE_LIBPATH
+
+
+# _LT_CMD_STRIPLIB
+# ----------------
+m4_defun([_LT_CMD_STRIPLIB],
+[m4_require([_LT_DECL_EGREP])
+striplib=
+old_striplib=
+AC_MSG_CHECKING([whether stripping libraries is possible])
+if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then
+  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
+  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
+  AC_MSG_RESULT([yes])
+else
+# FIXME - insert some real tests, host_os isn't really good enough
+  case $host_os in
+  darwin*)
+    if test -n "$STRIP" ; then
+      striplib="$STRIP -x"
+      old_striplib="$STRIP -S"
+      AC_MSG_RESULT([yes])
+    else
+      AC_MSG_RESULT([no])
+    fi
+    ;;
+  *)
+    AC_MSG_RESULT([no])
+    ;;
+  esac
+fi
+_LT_DECL([], [old_striplib], [1], [Commands to strip libraries])
+_LT_DECL([], [striplib], [1])
+])# _LT_CMD_STRIPLIB
+
+
+# _LT_SYS_DYNAMIC_LINKER([TAG])
+# -----------------------------
+# PORTME Fill in your ld.so characteristics
+m4_defun([_LT_SYS_DYNAMIC_LINKER],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_OBJDUMP])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_MSG_CHECKING([dynamic linker characteristics])
+m4_if([$1],
+	[], [
+if test "$GCC" = yes; then
+  case $host_os in
+    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
+    *) lt_awk_arg="/^libraries:/" ;;
+  esac
+  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+  if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then
+    # if the path contains ";" then we assume it to be the separator
+    # otherwise default to the standard path separator (i.e. ":") - it is
+    # assumed that no part of a normal pathname contains ";" but that should
+    # okay in the real world where ";" in dirpaths is itself problematic.
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'`
+  else
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+  fi
+  # Ok, now we have the path, separated by spaces, we can step through it
+  # and add multilib dir if necessary.
+  lt_tmp_lt_search_path_spec=
+  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
+  for lt_sys_path in $lt_search_path_spec; do
+    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
+      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
+    else
+      test -d "$lt_sys_path" && \
+	lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
+    fi
+  done
+  lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk '
+BEGIN {RS=" "; FS="/|\n";} {
+  lt_foo="";
+  lt_count=0;
+  for (lt_i = NF; lt_i > 0; lt_i--) {
+    if ($lt_i != "" && $lt_i != ".") {
+      if ($lt_i == "..") {
+        lt_count++;
+      } else {
+        if (lt_count == 0) {
+          lt_foo="/" $lt_i lt_foo;
+        } else {
+          lt_count--;
+        }
+      }
+    }
+  }
+  if (lt_foo != "") { lt_freq[[lt_foo]]++; }
+  if (lt_freq[[lt_foo]] == 1) { print lt_foo; }
+}'`
+  sys_lib_search_path_spec=`$ECHO $lt_search_path_spec`
+else
+  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
+fi])
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix[[4-9]]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[[01]] | aix4.[[01]].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+	   echo ' yes '
+	   echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then
+	:
+      else
+	can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  case $host_cpu in
+  powerpc)
+    # Since July 2007 AmigaOS4 officially supports .so libraries.
+    # When compiling the executable, add -use-dynld -Lsobjs: to the compileline.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    ;;
+  m68k)
+    library_names_spec='$libname.ixlibrary $libname.a'
+    # Create ${libname}_ixlibrary.a entries in /sys/libs.
+    finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+    ;;
+  esac
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[[45]]*)
+  version_type=linux
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32* | cegcc*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$host_os in
+  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
+      fi'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
+      ;;
+    mingw* | cegcc*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
+      if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then
+        # It is most probably a Windows format PATH printed by
+        # mingw gcc, but we are running on Cygwin. Gcc prints its search
+        # path with ; separators, and with drive letters. We can handle the
+        # drive letters (cygwin fileutils understands them), so leave them,
+        # especially as we might pass files found there to a mingw objdump,
+        # which wouldn't understand a cygwinified path. Ahh.
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    ;;
+
+  *)
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    ;;
+  esac
+  dynamic_linker='Win32 ld.exe'
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+m4_if([$1], [],[
+  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"])
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd1*)
+  dynamic_linker=no
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[[123]]*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[[01]]* | freebsdelf3.[[01]]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \
+  freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+gnu*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  hppa*64*)
+    shrext_cmds='.sl'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555.
+  postinstall_cmds='chmod 555 $lib'
+  ;;
+
+interix[[3-9]]*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+	if test "$lt_cv_prog_gnu_ld" = yes; then
+		version_type=linux
+	else
+		version_type=irix
+	fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  # Some binutils ld are patched to set DT_RUNPATH
+  save_LDFLAGS=$LDFLAGS
+  save_libdir=$libdir
+  eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \
+       LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\""
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
+    [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null],
+       [shlibpath_overrides_runpath=yes])])
+  LDFLAGS=$save_LDFLAGS
+  libdir=$save_libdir
+
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+
+  # Add ABI-specific directories to the system library path.
+  sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib"
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[	 ]*hwcap[	 ]/d;s/[:,	]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+*nto* | *qnx*)
+  version_type=qnx
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='ldqnx.so'
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*)	need_version=yes ;;
+    *)				need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[[89]] | openbsd2.[[89]].*)
+	shlibpath_overrides_runpath=no
+	;;
+      *)
+	shlibpath_overrides_runpath=yes
+	;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+	;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+tpf*)
+  # TPF is a cross-target only.  Preferred cross-host = GNU/Linux.
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+uts4*)
+  version_type=linux
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+AC_MSG_RESULT([$dynamic_linker])
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then
+  sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec"
+fi
+if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then
+  sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec"
+fi
+
+_LT_DECL([], [variables_saved_for_relink], [1],
+    [Variables whose values should be saved in libtool wrapper scripts and
+    restored at link time])
+_LT_DECL([], [need_lib_prefix], [0],
+    [Do we need the "lib" prefix for modules?])
+_LT_DECL([], [need_version], [0], [Do we need a version for libraries?])
+_LT_DECL([], [version_type], [0], [Library versioning type])
+_LT_DECL([], [runpath_var], [0],  [Shared library runtime path variable])
+_LT_DECL([], [shlibpath_var], [0],[Shared library path variable])
+_LT_DECL([], [shlibpath_overrides_runpath], [0],
+    [Is shlibpath searched before the hard-coded library search path?])
+_LT_DECL([], [libname_spec], [1], [Format of library name prefix])
+_LT_DECL([], [library_names_spec], [1],
+    [[List of archive names.  First name is the real one, the rest are links.
+    The last name is the one that the linker finds with -lNAME]])
+_LT_DECL([], [soname_spec], [1],
+    [[The coded name of the library, if different from the real name]])
+_LT_DECL([], [postinstall_cmds], [2],
+    [Command to use after installation of a shared archive])
+_LT_DECL([], [postuninstall_cmds], [2],
+    [Command to use after uninstallation of a shared archive])
+_LT_DECL([], [finish_cmds], [2],
+    [Commands used to finish a libtool library installation in a directory])
+_LT_DECL([], [finish_eval], [1],
+    [[As "finish_cmds", except a single script fragment to be evaled but
+    not shown]])
+_LT_DECL([], [hardcode_into_libs], [0],
+    [Whether we should hardcode library paths into libraries])
+_LT_DECL([], [sys_lib_search_path_spec], [2],
+    [Compile-time system search path for libraries])
+_LT_DECL([], [sys_lib_dlsearch_path_spec], [2],
+    [Run-time system search path for libraries])
+])# _LT_SYS_DYNAMIC_LINKER
+
+
+# _LT_PATH_TOOL_PREFIX(TOOL)
+# --------------------------
+# find a file program which can recognize shared library
+AC_DEFUN([_LT_PATH_TOOL_PREFIX],
+[m4_require([_LT_DECL_EGREP])dnl
+AC_MSG_CHECKING([for $1])
+AC_CACHE_VAL(lt_cv_path_MAGIC_CMD,
+[case $MAGIC_CMD in
+[[\\/*] |  ?:[\\/]*])
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+dnl $ac_dummy forces splitting on constant user-supplied paths.
+dnl POSIX.2 word splitting is done only on the output of word expansions,
+dnl not every word.  This closes a longstanding sh security hole.
+  ac_dummy="m4_if([$2], , $PATH, [$2])"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/$1; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/$1"
+      if test -n "$file_magic_test_file"; then
+	case $deplibs_check_method in
+	"file_magic "*)
+	  file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+	  MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+	  if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+	    $EGREP "$file_magic_regex" > /dev/null; then
+	    :
+	  else
+	    cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool@gnu.org
+
+_LT_EOF
+	  fi ;;
+	esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac])
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  AC_MSG_RESULT($MAGIC_CMD)
+else
+  AC_MSG_RESULT(no)
+fi
+_LT_DECL([], [MAGIC_CMD], [0],
+	 [Used to examine libraries when file_magic_cmd begins with "file"])dnl
+])# _LT_PATH_TOOL_PREFIX
+
+# Old name:
+AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], [])
+
+
+# _LT_PATH_MAGIC
+# --------------
+# find a file program which can recognize a shared library
+m4_defun([_LT_PATH_MAGIC],
+[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH)
+if test -z "$lt_cv_path_MAGIC_CMD"; then
+  if test -n "$ac_tool_prefix"; then
+    _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH)
+  else
+    MAGIC_CMD=:
+  fi
+fi
+])# _LT_PATH_MAGIC
+
+
+# LT_PATH_LD
+# ----------
+# find the pathname to the GNU or non-GNU linker
+AC_DEFUN([LT_PATH_LD],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_DECL_EGREP])dnl
+
+AC_ARG_WITH([gnu-ld],
+    [AS_HELP_STRING([--with-gnu-ld],
+	[assume the C compiler uses GNU ld @<:@default=no@:>@])],
+    [test "$withval" = no || with_gnu_ld=yes],
+    [with_gnu_ld=no])dnl
+
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  AC_MSG_CHECKING([for ld used by $CC])
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [[\\/]]* | ?:[[\\/]]*)
+      re_direlt='/[[^/]][[^/]]*/\.\./'
+      # Canonicalize the pathname of ld
+      ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'`
+      while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do
+	ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  AC_MSG_CHECKING([for GNU ld])
+else
+  AC_MSG_CHECKING([for non-GNU ld])
+fi
+AC_CACHE_VAL(lt_cv_path_LD,
+[if test -z "$LD"; then
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for ac_dir in $PATH; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      lt_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some variants of GNU ld only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
+      *GNU* | *'with BFD'*)
+	test "$with_gnu_ld" != no && break
+	;;
+      *)
+	test "$with_gnu_ld" != yes && break
+	;;
+      esac
+    fi
+  done
+  IFS="$lt_save_ifs"
+else
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+fi])
+LD="$lt_cv_path_LD"
+if test -n "$LD"; then
+  AC_MSG_RESULT($LD)
+else
+  AC_MSG_RESULT(no)
+fi
+test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
+_LT_PATH_LD_GNU
+AC_SUBST([LD])
+
+_LT_TAGDECL([], [LD], [1], [The linker used to build libraries])
+])# LT_PATH_LD
+
+# Old names:
+AU_ALIAS([AM_PROG_LD], [LT_PATH_LD])
+AU_ALIAS([AC_PROG_LD], [LT_PATH_LD])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_PROG_LD], [])
+dnl AC_DEFUN([AC_PROG_LD], [])
+
+
+# _LT_PATH_LD_GNU
+#- --------------
+m4_defun([_LT_PATH_LD_GNU],
+[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
+[# I'd rather use --version here, but apparently some GNU lds only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  lt_cv_prog_gnu_ld=yes
+  ;;
+*)
+  lt_cv_prog_gnu_ld=no
+  ;;
+esac])
+with_gnu_ld=$lt_cv_prog_gnu_ld
+])# _LT_PATH_LD_GNU
+
+
+# _LT_CMD_RELOAD
+# --------------
+# find reload flag for linker
+#   -- PORTME Some linkers may need a different reload flag.
+m4_defun([_LT_CMD_RELOAD],
+[AC_CACHE_CHECK([for $LD option to reload object files],
+  lt_cv_ld_reload_flag,
+  [lt_cv_ld_reload_flag='-r'])
+reload_flag=$lt_cv_ld_reload_flag
+case $reload_flag in
+"" | " "*) ;;
+*) reload_flag=" $reload_flag" ;;
+esac
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
+case $host_os in
+  darwin*)
+    if test "$GCC" = yes; then
+      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
+    else
+      reload_cmds='$LD$reload_flag -o $output$reload_objs'
+    fi
+    ;;
+esac
+_LT_DECL([], [reload_flag], [1], [How to create reloadable object files])dnl
+_LT_DECL([], [reload_cmds], [2])dnl
+])# _LT_CMD_RELOAD
+
+
+# _LT_CHECK_MAGIC_METHOD
+# ----------------------
+# how to check for library dependencies
+#  -- PORTME fill in with the dynamic library characteristics
+m4_defun([_LT_CHECK_MAGIC_METHOD],
+[m4_require([_LT_DECL_EGREP])
+m4_require([_LT_DECL_OBJDUMP])
+AC_CACHE_CHECK([how to recognize dependent libraries],
+lt_cv_deplibs_check_method,
+[lt_cv_file_magic_cmd='$MAGIC_CMD'
+lt_cv_file_magic_test_file=
+lt_cv_deplibs_check_method='unknown'
+# Need to set the preceding variable on all platforms that support
+# interlibrary dependencies.
+# 'none' -- dependencies not supported.
+# `unknown' -- same as none, but documents that we really don't know.
+# 'pass_all' -- all dependencies passed with no checks.
+# 'test_compile' -- check by making test program.
+# 'file_magic [[regex]]' -- check by looking for files in library path
+# which responds to the $file_magic_cmd with a given extended regex.
+# If you have `file' or equivalent on your system and you're not sure
+# whether `pass_all' will *always* work, you probably want this one.
+
+case $host_os in
+aix[[4-9]]*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+beos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+bsdi[[45]]*)
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)'
+  lt_cv_file_magic_cmd='/usr/bin/file -L'
+  lt_cv_file_magic_test_file=/shlib/libc.so
+  ;;
+
+cygwin*)
+  # func_win32_libid is a shell function defined in ltmain.sh
+  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+  lt_cv_file_magic_cmd='func_win32_libid'
+  ;;
+
+mingw* | pw32*)
+  # Base MSYS/MinGW do not provide the 'file' command needed by
+  # func_win32_libid shell function, so use a weaker test based on 'objdump',
+  # unless we find 'file', for example because we are cross-compiling.
+  if ( file / ) >/dev/null 2>&1; then
+    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+    lt_cv_file_magic_cmd='func_win32_libid'
+  else
+    lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?'
+    lt_cv_file_magic_cmd='$OBJDUMP -f'
+  fi
+  ;;
+
+cegcc)
+  # use the weaker test based on 'objdump'. See mingw*.
+  lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?'
+  lt_cv_file_magic_cmd='$OBJDUMP -f'
+  ;;
+
+darwin* | rhapsody*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+freebsd* | dragonfly*)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    case $host_cpu in
+    i*86 )
+      # Not sure whether the presence of OpenBSD here was a mistake.
+      # Let's accept both of them until this is cleared up.
+      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library'
+      lt_cv_file_magic_cmd=/usr/bin/file
+      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
+      ;;
+    esac
+  else
+    lt_cv_deplibs_check_method=pass_all
+  fi
+  ;;
+
+gnu*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+hpux10.20* | hpux11*)
+  lt_cv_file_magic_cmd=/usr/bin/file
+  case $host_cpu in
+  ia64*)
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64'
+    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
+    ;;
+  hppa*64*)
+    [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]']
+    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
+    ;;
+  *)
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library'
+    lt_cv_file_magic_test_file=/usr/lib/libc.sl
+    ;;
+  esac
+  ;;
+
+interix[[3-9]]*)
+  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
+  lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$'
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $LD in
+  *-32|*"-32 ") libmagic=32-bit;;
+  *-n32|*"-n32 ") libmagic=N32;;
+  *-64|*"-64 ") libmagic=64-bit;;
+  *) libmagic=never-match;;
+  esac
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+# This must be Linux ELF.
+linux* | k*bsd*-gnu)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+netbsd*)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$'
+  fi
+  ;;
+
+newos6*)
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)'
+  lt_cv_file_magic_cmd=/usr/bin/file
+  lt_cv_file_magic_test_file=/usr/lib/libnls.so
+  ;;
+
+*nto* | *qnx*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+openbsd*)
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
+  fi
+  ;;
+
+osf3* | osf4* | osf5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+rdos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+solaris*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv4 | sysv4.3*)
+  case $host_vendor in
+  motorola)
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]'
+    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
+    ;;
+  ncr)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  sequent)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )'
+    ;;
+  sni)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib"
+    lt_cv_file_magic_test_file=/lib/libc.so
+    ;;
+  siemens)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  pc)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  esac
+  ;;
+
+tpf*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+esac
+])
+file_magic_cmd=$lt_cv_file_magic_cmd
+deplibs_check_method=$lt_cv_deplibs_check_method
+test -z "$deplibs_check_method" && deplibs_check_method=unknown
+
+_LT_DECL([], [deplibs_check_method], [1],
+    [Method to check whether dependent libraries are shared objects])
+_LT_DECL([], [file_magic_cmd], [1],
+    [Command to use when deplibs_check_method == "file_magic"])
+])# _LT_CHECK_MAGIC_METHOD
+
+
+# LT_PATH_NM
+# ----------
+# find the pathname to a BSD- or MS-compatible name lister
+AC_DEFUN([LT_PATH_NM],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM,
+[if test -n "$NM"; then
+  # Let the user override the test.
+  lt_cv_path_NM="$NM"
+else
+  lt_nm_to_check="${ac_tool_prefix}nm"
+  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
+    lt_nm_to_check="$lt_nm_to_check nm"
+  fi
+  for lt_tmp_nm in $lt_nm_to_check; do
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
+      IFS="$lt_save_ifs"
+      test -z "$ac_dir" && ac_dir=.
+      tmp_nm="$ac_dir/$lt_tmp_nm"
+      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
+	# Check to see if the nm accepts a BSD-compat flag.
+	# Adding the `sed 1q' prevents false positives on HP-UX, which says:
+	#   nm: unknown option "B" ignored
+	# Tru64's nm complains that /dev/null is an invalid object file
+	case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
+	*/dev/null* | *'Invalid file or object type'*)
+	  lt_cv_path_NM="$tmp_nm -B"
+	  break
+	  ;;
+	*)
+	  case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
+	  */dev/null*)
+	    lt_cv_path_NM="$tmp_nm -p"
+	    break
+	    ;;
+	  *)
+	    lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
+	    continue # so that we can try to find one that supports BSD flags
+	    ;;
+	  esac
+	  ;;
+	esac
+      fi
+    done
+    IFS="$lt_save_ifs"
+  done
+  : ${lt_cv_path_NM=no}
+fi])
+if test "$lt_cv_path_NM" != "no"; then
+  NM="$lt_cv_path_NM"
+else
+  # Didn't find any BSD compatible name lister, look for dumpbin.
+  AC_CHECK_TOOLS(DUMPBIN, ["dumpbin -symbols" "link -dump -symbols"], :)
+  AC_SUBST([DUMPBIN])
+  if test "$DUMPBIN" != ":"; then
+    NM="$DUMPBIN"
+  fi
+fi
+test -z "$NM" && NM=nm
+AC_SUBST([NM])
+_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl
+
+AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface],
+  [lt_cv_nm_interface="BSD nm"
+  echo "int some_variable = 0;" > conftest.$ac_ext
+  (eval echo "\"\$as_me:__oline__: $ac_compile\"" >&AS_MESSAGE_LOG_FD)
+  (eval "$ac_compile" 2>conftest.err)
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  (eval echo "\"\$as_me:__oline__: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD)
+  (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  (eval echo "\"\$as_me:__oline__: output\"" >&AS_MESSAGE_LOG_FD)
+  cat conftest.out >&AS_MESSAGE_LOG_FD
+  if $GREP 'External.*some_variable' conftest.out > /dev/null; then
+    lt_cv_nm_interface="MS dumpbin"
+  fi
+  rm -f conftest*])
+])# LT_PATH_NM
+
+# Old names:
+AU_ALIAS([AM_PROG_NM], [LT_PATH_NM])
+AU_ALIAS([AC_PROG_NM], [LT_PATH_NM])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_PROG_NM], [])
+dnl AC_DEFUN([AC_PROG_NM], [])
+
+
+# LT_LIB_M
+# --------
+# check for math library
+AC_DEFUN([LT_LIB_M],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+LIBM=
+case $host in
+*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*)
+  # These system don't have libm, or don't need it
+  ;;
+*-ncr-sysv4.3*)
+  AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
+  AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm")
+  ;;
+*)
+  AC_CHECK_LIB(m, cos, LIBM="-lm")
+  ;;
+esac
+AC_SUBST([LIBM])
+])# LT_LIB_M
+
+# Old name:
+AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_CHECK_LIBM], [])
+
+
+# _LT_COMPILER_NO_RTTI([TAGNAME])
+# -------------------------------
+m4_defun([_LT_COMPILER_NO_RTTI],
+[m4_require([_LT_TAG_COMPILER])dnl
+
+_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
+
+if test "$GCC" = yes; then
+  _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
+
+  _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions],
+    lt_cv_prog_compiler_rtti_exceptions,
+    [-fno-rtti -fno-exceptions], [],
+    [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"])
+fi
+_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1],
+	[Compiler flag to turn off builtin functions])
+])# _LT_COMPILER_NO_RTTI
+
+
+# _LT_CMD_GLOBAL_SYMBOLS
+# ----------------------
+m4_defun([_LT_CMD_GLOBAL_SYMBOLS],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+AC_REQUIRE([LT_PATH_LD])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+
+# Check for command to grab the raw symbol name followed by C symbol from nm.
+AC_MSG_CHECKING([command to parse $NM output from $compiler object])
+AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe],
+[
+# These are sane defaults that work on at least a few old systems.
+# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
+
+# Character class describing NM global symbol codes.
+symcode='[[BCDEGRST]]'
+
+# Regexp to match symbols that can be accessed directly from C.
+sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)'
+
+# Define system-specific variables.
+case $host_os in
+aix*)
+  symcode='[[BCDT]]'
+  ;;
+cygwin* | mingw* | pw32* | cegcc*)
+  symcode='[[ABCDGISTW]]'
+  ;;
+hpux*)
+  if test "$host_cpu" = ia64; then
+    symcode='[[ABCDEGRST]]'
+  fi
+  ;;
+irix* | nonstopux*)
+  symcode='[[BCDEGRST]]'
+  ;;
+osf*)
+  symcode='[[BCDEGQRST]]'
+  ;;
+solaris*)
+  symcode='[[BDRT]]'
+  ;;
+sco3.2v5*)
+  symcode='[[DT]]'
+  ;;
+sysv4.2uw2*)
+  symcode='[[DT]]'
+  ;;
+sysv5* | sco5v6* | unixware* | OpenUNIX*)
+  symcode='[[ABDT]]'
+  ;;
+sysv4)
+  symcode='[[DFNSTU]]'
+  ;;
+esac
+
+# If we're using GNU nm, then use its standard symbol codes.
+case `$NM -V 2>&1` in
+*GNU* | *'with BFD'*)
+  symcode='[[ABCDGIRSTW]]' ;;
+esac
+
+# Transform an extracted symbol line into a proper C declaration.
+# Some systems (esp. on ia64) link data and code symbols differently,
+# so use this general approach.
+lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+
+# Transform an extracted symbol line into symbol name and symbol address
+lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"\2\", (void *) \&\2},/p'"
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \(lib[[^ ]]*\)$/  {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"lib\2\", (void *) \&\2},/p'"
+
+# Handle CRLF in mingw tool chain
+opt_cr=
+case $build_os in
+mingw*)
+  opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
+  ;;
+esac
+
+# Try without a prefix underscore, then with it.
+for ac_symprfx in "" "_"; do
+
+  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
+  symxfrm="\\1 $ac_symprfx\\2 \\2"
+
+  # Write the raw and C identifiers.
+  if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+    # Fake it for dumpbin and say T for any non-static function
+    # and D for any global variable.
+    # Also find C++ and __fastcall symbols from MSVC++,
+    # which start with @ or ?.
+    lt_cv_sys_global_symbol_pipe="$AWK ['"\
+"     {last_section=section; section=\$ 3};"\
+"     /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\
+"     \$ 0!~/External *\|/{next};"\
+"     / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\
+"     {if(hide[section]) next};"\
+"     {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\
+"     {split(\$ 0, a, /\||\r/); split(a[2], s)};"\
+"     s[1]~/^[@?]/{print s[1], s[1]; next};"\
+"     s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\
+"     ' prfx=^$ac_symprfx]"
+  else
+    lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[	 ]]\($symcode$symcode*\)[[	 ]][[	 ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
+  fi
+
+  # Check to see that the pipe works correctly.
+  pipe_works=no
+
+  rm -f conftest*
+  cat > conftest.$ac_ext <<_LT_EOF
+#ifdef __cplusplus
+extern "C" {
+#endif
+char nm_test_var;
+void nm_test_func(void);
+void nm_test_func(void){}
+#ifdef __cplusplus
+}
+#endif
+int main(){nm_test_var='a';nm_test_func();return(0);}
+_LT_EOF
+
+  if AC_TRY_EVAL(ac_compile); then
+    # Now try to grab the symbols.
+    nlist=conftest.nm
+    if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) && test -s "$nlist"; then
+      # Try sorting and uniquifying the output.
+      if sort "$nlist" | uniq > "$nlist"T; then
+	mv -f "$nlist"T "$nlist"
+      else
+	rm -f "$nlist"T
+      fi
+
+      # Make sure that we snagged all the symbols we need.
+      if $GREP ' nm_test_var$' "$nlist" >/dev/null; then
+	if $GREP ' nm_test_func$' "$nlist" >/dev/null; then
+	  cat <<_LT_EOF > conftest.$ac_ext
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+_LT_EOF
+	  # Now generate the symbol file.
+	  eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext'
+
+	  cat <<_LT_EOF >> conftest.$ac_ext
+
+/* The mapping between symbol names and symbols.  */
+const struct {
+  const char *name;
+  void       *address;
+}
+lt__PROGRAM__LTX_preloaded_symbols[[]] =
+{
+  { "@PROGRAM@", (void *) 0 },
+_LT_EOF
+	  $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext
+	  cat <<\_LT_EOF >> conftest.$ac_ext
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt__PROGRAM__LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+_LT_EOF
+	  # Now try linking the two files.
+	  mv conftest.$ac_objext conftstm.$ac_objext
+	  lt_save_LIBS="$LIBS"
+	  lt_save_CFLAGS="$CFLAGS"
+	  LIBS="conftstm.$ac_objext"
+	  CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)"
+	  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then
+	    pipe_works=yes
+	  fi
+	  LIBS="$lt_save_LIBS"
+	  CFLAGS="$lt_save_CFLAGS"
+	else
+	  echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD
+	fi
+      else
+	echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD
+      fi
+    else
+      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD
+    fi
+  else
+    echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD
+    cat conftest.$ac_ext >&5
+  fi
+  rm -rf conftest* conftst*
+
+  # Do not use the global_symbol_pipe unless it works.
+  if test "$pipe_works" = yes; then
+    break
+  else
+    lt_cv_sys_global_symbol_pipe=
+  fi
+done
+])
+if test -z "$lt_cv_sys_global_symbol_pipe"; then
+  lt_cv_sys_global_symbol_to_cdecl=
+fi
+if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
+  AC_MSG_RESULT(failed)
+else
+  AC_MSG_RESULT(ok)
+fi
+
+_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1],
+    [Take the output of nm and produce a listing of raw symbols and C names])
+_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1],
+    [Transform the output of nm in a proper C declaration])
+_LT_DECL([global_symbol_to_c_name_address],
+    [lt_cv_sys_global_symbol_to_c_name_address], [1],
+    [Transform the output of nm in a C name address pair])
+_LT_DECL([global_symbol_to_c_name_address_lib_prefix],
+    [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1],
+    [Transform the output of nm in a C name address pair when lib prefix is needed])
+]) # _LT_CMD_GLOBAL_SYMBOLS
+
+
+# _LT_COMPILER_PIC([TAGNAME])
+# ---------------------------
+m4_defun([_LT_COMPILER_PIC],
+[m4_require([_LT_TAG_COMPILER])dnl
+_LT_TAGVAR(lt_prog_compiler_wl, $1)=
+_LT_TAGVAR(lt_prog_compiler_pic, $1)=
+_LT_TAGVAR(lt_prog_compiler_static, $1)=
+
+AC_MSG_CHECKING([for $compiler option to produce PIC])
+m4_if([$1], [CXX], [
+  # C++ specific cases for pic, static, wl, etc.
+  if test "$GXX" = yes; then
+    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+
+    case $host_os in
+    aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+    mingw* | cygwin* | os2* | pw32* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      m4_if([$1], [GCJ], [],
+	[_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
+      ;;
+    *djgpp*)
+      # DJGPP does not support shared libraries at all
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+      ;;
+    interix[[3-9]]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
+      fi
+      ;;
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+	;;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	;;
+      esac
+      ;;
+    *qnx* | *nto*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+    *)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+      ;;
+    esac
+  else
+    case $host_os in
+      aix[[4-9]]*)
+	# All AIX code is PIC.
+	if test "$host_cpu" = ia64; then
+	  # AIX 5 now supports IA64 processor
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	else
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+	fi
+	;;
+      chorus*)
+	case $cc_basename in
+	cxch68*)
+	  # Green Hills C++ Compiler
+	  # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a"
+	  ;;
+	esac
+	;;
+      dgux*)
+	case $cc_basename in
+	  ec++*)
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    ;;
+	  ghcx*)
+	    # Green Hills C++ Compiler
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      freebsd* | dragonfly*)
+	# FreeBSD uses GNU C++
+	;;
+      hpux9* | hpux10* | hpux11*)
+	case $cc_basename in
+	  CC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+	    if test "$host_cpu" != ia64; then
+	      _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+	    fi
+	    ;;
+	  aCC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+	    case $host_cpu in
+	    hppa*64*|ia64*)
+	      # +Z the default
+	      ;;
+	    *)
+	      _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+	      ;;
+	    esac
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      interix*)
+	# This is c89, which is MS Visual C++ (no shared libs)
+	# Anyone wants to do a port?
+	;;
+      irix5* | irix6* | nonstopux*)
+	case $cc_basename in
+	  CC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+	    # CC pic flag -KPIC is the default.
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      linux* | k*bsd*-gnu)
+	case $cc_basename in
+	  KCC*)
+	    # KAI C++ Compiler
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	    ;;
+	  ecpc* )
+	    # old Intel C++ for x86_64 which still supported -KPIC.
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+	    ;;
+	  icpc* )
+	    # Intel C++, used to be incompatible with GCC.
+	    # ICC 10 doesn't accept -KPIC any more.
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+	    ;;
+	  pgCC* | pgcpp*)
+	    # Portland Group C++ compiler
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    ;;
+	  cxx*)
+	    # Compaq C++
+	    # Make sure the PIC flag is empty.  It appears that all Alpha
+	    # Linux and Compaq Tru64 Unix objects are PIC.
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+	    ;;
+	  xlc* | xlC*)
+	    # IBM XL 8.0 on PPC
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink'
+	    ;;
+	  *)
+	    case `$CC -V 2>&1 | sed 5q` in
+	    *Sun\ C*)
+	      # Sun C++ 5.9
+	      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+	      ;;
+	    esac
+	    ;;
+	esac
+	;;
+      lynxos*)
+	;;
+      m88k*)
+	;;
+      mvs*)
+	case $cc_basename in
+	  cxx*)
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      netbsd*)
+	;;
+      *qnx* | *nto*)
+        # QNX uses GNU C++, but need to define -shared option too, otherwise
+        # it will coredump.
+        _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+        ;;
+      osf3* | osf4* | osf5*)
+	case $cc_basename in
+	  KCC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
+	    ;;
+	  RCC*)
+	    # Rational C++ 2.4.1
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    ;;
+	  cxx*)
+	    # Digital/Compaq C++
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    # Make sure the PIC flag is empty.  It appears that all Alpha
+	    # Linux and Compaq Tru64 Unix objects are PIC.
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      psos*)
+	;;
+      solaris*)
+	case $cc_basename in
+	  CC*)
+	    # Sun C++ 4.2, 5.x and Centerline C++
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+	    ;;
+	  gcx*)
+	    # Green Hills C++ Compiler
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      sunos4*)
+	case $cc_basename in
+	  CC*)
+	    # Sun C++ 4.x
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    ;;
+	  lcc*)
+	    # Lucid
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+	case $cc_basename in
+	  CC*)
+	    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	    ;;
+	esac
+	;;
+      tandem*)
+	case $cc_basename in
+	  NCC*)
+	    # NonStop-UX NCC 3.20
+	    _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	    ;;
+	  *)
+	    ;;
+	esac
+	;;
+      vxworks*)
+	;;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+	;;
+    esac
+  fi
+],
+[
+  if test "$GCC" = yes; then
+    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      m4_if([$1], [GCJ], [],
+	[_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
+      ;;
+
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+	# +Z the default
+	;;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	;;
+      esac
+      ;;
+
+    interix[[3-9]]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      enable_shared=no
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
+      fi
+      ;;
+
+    *)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      if test "$host_cpu" = ia64; then
+	# AIX 5 now supports IA64 processor
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      else
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      m4_if([$1], [GCJ], [],
+	[_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+	# +Z the default
+	;;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+	;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # PIC (with -KPIC) is the default.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    linux* | k*bsd*-gnu)
+      case $cc_basename in
+      # old Intel for x86_64 which still supported -KPIC.
+      ecc*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+        ;;
+      # icc used to be incompatible with GCC.
+      # ICC 10 doesn't accept -KPIC any more.
+      icc* | ifort*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+        ;;
+      # Lahey Fortran 8.1.
+      lf95*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='--static'
+	;;
+      pgcc* | pgf77* | pgf90* | pgf95*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+	# which looks to be a dead project)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+        ;;
+      ccc*)
+        _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+        # All Alpha code is PIC.
+        _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+        ;;
+      xl*)
+	# IBM XL C 8.0/Fortran 10.1 on PPC
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink'
+	;;
+      *)
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)
+	  # Sun C 5.9
+	  _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	  _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+	  ;;
+	*Sun\ F*)
+	  # Sun Fortran 8.3 passes all unrecognized flags to the linker
+	  _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+	  _LT_TAGVAR(lt_prog_compiler_wl, $1)=''
+	  ;;
+	esac
+	;;
+      esac
+      ;;
+
+    newsos6)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+
+    osf3* | osf4* | osf5*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # All OSF/1 code is PIC.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    rdos*)
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    solaris*)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95*)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';;
+      *)
+	_LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+	_LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic'
+	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    unicos*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      ;;
+
+    uts4*)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    *)
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      ;;
+    esac
+  fi
+])
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+    ;;
+  *)
+    _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])"
+    ;;
+esac
+AC_MSG_RESULT([$_LT_TAGVAR(lt_prog_compiler_pic, $1)])
+_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1],
+	[How to pass a linker flag through the compiler])
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then
+  _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works],
+    [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)],
+    [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [],
+    [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in
+     "" | " "*) ;;
+     *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;;
+     esac],
+    [_LT_TAGVAR(lt_prog_compiler_pic, $1)=
+     _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no])
+fi
+_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1],
+	[Additional compiler flags for building library objects])
+
+#
+# Check to make sure the static flag actually works.
+#
+wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\"
+_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works],
+  _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1),
+  $lt_tmp_static_flag,
+  [],
+  [_LT_TAGVAR(lt_prog_compiler_static, $1)=])
+_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1],
+	[Compiler flag to prevent dynamic linking])
+])# _LT_COMPILER_PIC
+
+
+# _LT_LINKER_SHLIBS([TAGNAME])
+# ----------------------------
+# See if the linker supports building shared libraries.
+m4_defun([_LT_LINKER_SHLIBS],
+[AC_REQUIRE([LT_PATH_LD])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
+m4_if([$1], [CXX], [
+  _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  case $host_os in
+  aix[[4-9]]*)
+    # If we're using GNU nm, then we don't want the "-C" option.
+    # -C means demangle to AIX nm, but means don't demangle with GNU nm
+    if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+    else
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+    fi
+    ;;
+  pw32*)
+    _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds"
+  ;;
+  cygwin* | mingw* | cegcc*)
+    _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols'
+  ;;
+  *)
+    _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  ;;
+  esac
+  _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
+], [
+  runpath_var=
+  _LT_TAGVAR(allow_undefined_flag, $1)=
+  _LT_TAGVAR(always_export_symbols, $1)=no
+  _LT_TAGVAR(archive_cmds, $1)=
+  _LT_TAGVAR(archive_expsym_cmds, $1)=
+  _LT_TAGVAR(compiler_needs_object, $1)=no
+  _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+  _LT_TAGVAR(export_dynamic_flag_spec, $1)=
+  _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  _LT_TAGVAR(hardcode_automatic, $1)=no
+  _LT_TAGVAR(hardcode_direct, $1)=no
+  _LT_TAGVAR(hardcode_direct_absolute, $1)=no
+  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+  _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+  _LT_TAGVAR(hardcode_libdir_separator, $1)=
+  _LT_TAGVAR(hardcode_minus_L, $1)=no
+  _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+  _LT_TAGVAR(inherit_rpath, $1)=no
+  _LT_TAGVAR(link_all_deplibs, $1)=unknown
+  _LT_TAGVAR(module_cmds, $1)=
+  _LT_TAGVAR(module_expsym_cmds, $1)=
+  _LT_TAGVAR(old_archive_from_new_cmds, $1)=
+  _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)=
+  _LT_TAGVAR(thread_safe_flag_spec, $1)=
+  _LT_TAGVAR(whole_archive_flag_spec, $1)=
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  _LT_TAGVAR(include_expsyms, $1)=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  # Exclude shared library initialization/finalization symbols.
+dnl Note also adjust exclude_expsyms for C++ above.
+  extract_expsyms_cmds=
+
+  case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  esac
+
+  _LT_TAGVAR(ld_shlibs, $1)=yes
+  if test "$with_gnu_ld" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then
+      _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+    else
+      _LT_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>&1` in
+      *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix[[3-9]]*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.9.1, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to modify your PATH
+*** so that a non-GNU linker is found, and then restart.
+
+_LT_EOF
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            _LT_TAGVAR(archive_expsym_cmds, $1)=''
+        ;;
+      m68k)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes
+        ;;
+      esac
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	_LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+	# Joseph Beckenbach <jrb3@best.com> says some releases of gcc
+	# support --undefined.  This deserves some investigation.  FIXME
+	_LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
+      # as there is no search path for DLLs.
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(always_export_symbols, $1)=no
+      _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols'
+
+      if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+	# If the export-symbols file already is a .def file (1st line
+	# is EXPORTS), use it as is; otherwise, prepend...
+	_LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	  cp $export_symbols $output_objdir/$soname.def;
+	else
+	  echo EXPORTS > $output_objdir/$soname.def;
+	  cat $export_symbols >> $output_objdir/$soname.def;
+	fi~
+	$CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    interix[[3-9]]*)
+      _LT_TAGVAR(hardcode_direct, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | tpf* | k*bsd*-gnu)
+      tmp_diet=no
+      if test "$host_os" = linux-dietlibc; then
+	case $cc_basename in
+	  diet\ *) tmp_diet=yes;;	# linux-dietlibc with static linking (!diet-dyn)
+	esac
+      fi
+      if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \
+	 && test "$tmp_diet" = no
+      then
+	tmp_addflag=
+	tmp_sharedflag='-shared'
+	case $cc_basename,$host_cpu in
+        pgcc*)				# Portland Group C compiler
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag'
+	  ;;
+	pgf77* | pgf90* | pgf95*)	# Portland Group f77 and f90 compilers
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+	  tmp_addflag=' $pic_flag -Mnomain' ;;
+	ecc*,ia64* | icc*,ia64*)	# Intel C compiler on ia64
+	  tmp_addflag=' -i_dynamic' ;;
+	efc*,ia64* | ifort*,ia64*)	# Intel Fortran compiler on ia64
+	  tmp_addflag=' -i_dynamic -nofor_main' ;;
+	ifc* | ifort*)			# Intel Fortran compiler
+	  tmp_addflag=' -nofor_main' ;;
+	lf95*)				# Lahey Fortran 8.1
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)=
+	  tmp_sharedflag='--shared' ;;
+	xl[[cC]]*)			# IBM XL C 8.0 on PPC (deal with xlf below)
+	  tmp_sharedflag='-qmkshrobj'
+	  tmp_addflag= ;;
+	esac
+	case `$CC -V 2>&1 | sed 5q` in
+	*Sun\ C*)			# Sun C 5.9
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+	  _LT_TAGVAR(compiler_needs_object, $1)=yes
+	  tmp_sharedflag='-G' ;;
+	*Sun\ F*)			# Sun Fortran 8.3
+	  tmp_sharedflag='-G' ;;
+	esac
+	_LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+        if test "x$supports_anon_versioning" = xyes; then
+          _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+	    cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	    echo "local: *; };" >> $output_objdir/$libname.ver~
+	    $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+        fi
+
+	case $cc_basename in
+	xlf*)
+	  # IBM XL Fortran 10.1 on PPC cannot create shared libs itself
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive'
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+	  _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir'
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib'
+	  if test "x$supports_anon_versioning" = xyes; then
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+	      cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	      echo "local: *; };" >> $output_objdir/$libname.ver~
+	      $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib'
+	  fi
+	  ;;
+	esac
+      else
+        _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	_LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+	wlarc=
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+      elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*)
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+	;;
+	*)
+	  # For security reasons, it is highly recommended that you always
+	  # use absolute paths for naming shared libraries, and exclude the
+	  # DT_RUNPATH tag from executables and libraries.  But doing so
+	  # requires that you compile everything twice, which is a pain.
+	  if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+	  else
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	  fi
+	;;
+      esac
+      ;;
+
+    sunos4*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+    esac
+
+    if test "$_LT_TAGVAR(ld_shlibs, $1)" = no; then
+      runpath_var=
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)=
+      _LT_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(always_export_symbols, $1)=yes
+      _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+	# Neither direct hardcoding nor static linking is supported with a
+	# broken collect2.
+	_LT_TAGVAR(hardcode_direct, $1)=unsupported
+      fi
+      ;;
+
+    aix[[4-9]]*)
+      if test "$host_cpu" = ia64; then
+	# On IA64, the linker does run time linking by default, so we don't
+	# have to do anything special.
+	aix_use_runtimelinking=no
+	exp_sym_flag='-Bexport'
+	no_entry_flag=""
+      else
+	# If we're using GNU nm, then we don't want the "-C" option.
+	# -C means demangle to AIX nm, but means don't demangle with GNU nm
+	if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+	  _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+	else
+	  _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+	fi
+	aix_use_runtimelinking=no
+
+	# Test if we are trying to use run time linking or normal
+	# AIX style linking. If -brtl is somewhere in LDFLAGS, we
+	# need to do runtime linking.
+	case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
+	  for ld_flag in $LDFLAGS; do
+	  if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+	    aix_use_runtimelinking=yes
+	    break
+	  fi
+	  done
+	  ;;
+	esac
+
+	exp_sym_flag='-bexport'
+	no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      _LT_TAGVAR(archive_cmds, $1)=''
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      _LT_TAGVAR(file_list_spec, $1)='${wl}-f,'
+
+      if test "$GCC" = yes; then
+	case $host_os in aix4.[[012]]|aix4.[[012]].*)
+	# We only want to do this on AIX 4.2 and lower, the check
+	# below for broken collect2 doesn't work under 4.3+
+	  collect2name=`${CC} -print-prog-name=collect2`
+	  if test -f "$collect2name" &&
+	   strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+	  then
+	  # We have reworked collect2
+	  :
+	  else
+	  # We have old collect2
+	  _LT_TAGVAR(hardcode_direct, $1)=unsupported
+	  # It fails to find uninstalled libraries when the uninstalled
+	  # path is not listed in the libpath.  Setting hardcode_minus_L
+	  # to unsupported forces relinking
+	  _LT_TAGVAR(hardcode_minus_L, $1)=yes
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+	  _LT_TAGVAR(hardcode_libdir_separator, $1)=
+	  fi
+	  ;;
+	esac
+	shared_flag='-shared'
+	if test "$aix_use_runtimelinking" = yes; then
+	  shared_flag="$shared_flag "'${wl}-G'
+	fi
+      else
+	# not using gcc
+	if test "$host_cpu" = ia64; then
+	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+	# chokes on -Wl,-G. The following line is correct:
+	  shared_flag='-G'
+	else
+	  if test "$aix_use_runtimelinking" = yes; then
+	    shared_flag='${wl}-G'
+	  else
+	    shared_flag='${wl}-bM:SRE'
+	  fi
+	fi
+      fi
+
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall'
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      _LT_TAGVAR(always_export_symbols, $1)=yes
+      if test "$aix_use_runtimelinking" = yes; then
+	# Warning - without using the other runtime loading flags (-brtl),
+	# -berok will link without error, but may produce a broken library.
+	_LT_TAGVAR(allow_undefined_flag, $1)='-berok'
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        _LT_SYS_MODULE_PATH_AIX
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+        _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+      else
+	if test "$host_cpu" = ia64; then
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
+	  _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
+	  _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+	else
+	 # Determine the default libpath from the value encoded in an
+	 # empty executable.
+	 _LT_SYS_MODULE_PATH_AIX
+	 _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+	  # Warning - without using the other run time loading flags,
+	  # -berok will link without error, but may produce a broken library.
+	  _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
+	  _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
+	  # Exported symbols can be pulled into shared objects from archives
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
+	  _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+	  # This is similar to how AIX traditionally builds its shared libraries.
+	  _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+	fi
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            _LT_TAGVAR(archive_expsym_cmds, $1)=''
+        ;;
+      m68k)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes
+        ;;
+      esac
+      ;;
+
+    bsdi[[45]]*)
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      # Tell ltmain to make .lib files, not .a files.
+      libext=lib
+      # Tell ltmain to make .dll files, not .so files.
+      shrext_cmds=".dll"
+      # FIXME: Setting linknames here is a bad hack.
+      _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames='
+      # The linker will automatically build a .lib file if we build a DLL.
+      _LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
+      # FIXME: Should let the user specify the lib program.
+      _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs'
+      _LT_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`'
+      _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+      ;;
+
+    darwin* | rhapsody*)
+      _LT_DARWIN_LINKER_FEATURES($1)
+      ;;
+
+    dgux*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    freebsd1*)
+      _LT_TAGVAR(ld_shlibs, $1)=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      _LT_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+	_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir'
+	_LT_TAGVAR(hardcode_libdir_separator, $1)=:
+	_LT_TAGVAR(hardcode_direct, $1)=yes
+	_LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+	_LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	# hardcode_minus_L: Not really in the search PATH,
+	# but as the default location of the library.
+	_LT_TAGVAR(hardcode_minus_L, $1)=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
+	case $host_cpu in
+	hppa*64*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      else
+	case $host_cpu in
+	hppa*64*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	ia64*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	esac
+      fi
+      if test "$with_gnu_ld" = no; then
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+	_LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	case $host_cpu in
+	hppa*64*|ia64*)
+	  _LT_TAGVAR(hardcode_direct, $1)=no
+	  _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	  ;;
+	*)
+	  _LT_TAGVAR(hardcode_direct, $1)=yes
+	  _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+	  _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+
+	  # hardcode_minus_L: Not really in the search PATH,
+	  # but as the default location of the library.
+	  _LT_TAGVAR(hardcode_minus_L, $1)=yes
+	  ;;
+	esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	# Try to use the -exported_symbol ld option, if it does not
+	# work, assume that -exports_file does not work either and
+	# implicitly export all symbols.
+        save_LDFLAGS="$LDFLAGS"
+        LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null"
+        AC_LINK_IFELSE(int foo(void) {},
+          _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib'
+        )
+        LDFLAGS="$save_LDFLAGS"
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(inherit_rpath, $1)=yes
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    netbsd*)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	_LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    newsos6)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *nto* | *qnx*)
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+	_LT_TAGVAR(hardcode_direct, $1)=yes
+	_LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	_LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+	if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	  _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	else
+	  case $host_os in
+	   openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*)
+	     _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+	     _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	     ;;
+	   *)
+	     _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+	     _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	     ;;
+	  esac
+	fi
+      else
+	_LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    os2*)
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+	_LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      ;;
+
+    osf4* | osf5*)	# as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      else
+	_LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~
+	$CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp'
+
+	# Both c and cxx compiler support -rpath directly
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      ;;
+
+    solaris*)
+      _LT_TAGVAR(no_undefined_flag, $1)=' -z defs'
+      if test "$GCC" = yes; then
+	wlarc='${wl}'
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+      else
+	case `$CC -V 2>&1` in
+	*"Compilers 5.0"*)
+	  wlarc=''
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp'
+	  ;;
+	*)
+	  wlarc='${wl}'
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	  $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+	  ;;
+	esac
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      case $host_os in
+      solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+      *)
+	# The compiler driver will combine and reorder linker options,
+	# but understands `-z linker_flag'.  GCC discards it without `$wl',
+	# but is careful enough not to reorder.
+	# Supported since Solaris 2.6 (maybe 2.5.1?)
+	if test "$GCC" = yes; then
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+	else
+	  _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
+	fi
+	;;
+      esac
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+	# Use $CC to link under sequent, because it throws in some extra .o
+	# files that make .init and .fini sections work.
+	_LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+	sni)
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true???
+	;;
+	siemens)
+	  ## LD is ld it makes a PLAMLIB
+	  ## CC just makes a GrossModule.
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs'
+	  _LT_TAGVAR(hardcode_direct, $1)=no
+        ;;
+	motorola)
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	  _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie
+	;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    sysv4.3*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+	_LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+	_LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	runpath_var=LD_RUN_PATH
+	hardcode_runpath_var=yes
+	_LT_TAGVAR(ld_shlibs, $1)=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+	_LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *)
+      _LT_TAGVAR(ld_shlibs, $1)=no
+      ;;
+    esac
+
+    if test x$host_vendor = xsni; then
+      case $host in
+      sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
+	_LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Blargedynsym'
+	;;
+      esac
+    fi
+  fi
+])
+AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)])
+test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld
+
+_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl
+_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl
+_LT_DECL([], [extract_expsyms_cmds], [2],
+    [The commands to extract the exported symbol list from a shared archive])
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in
+x|xyes)
+  # Assume -lc should be added
+  _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $_LT_TAGVAR(archive_cmds, $1) in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      AC_MSG_CHECKING([whether -lc should be explicitly linked in])
+      $RM conftest*
+      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+      if AC_TRY_EVAL(ac_compile) 2>conftest.err; then
+        soname=conftest
+        lib=conftest
+        libobjs=conftest.$ac_objext
+        deplibs=
+        wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1)
+	pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1)
+        compiler_flags=-v
+        linker_flags=-v
+        verstring=
+        output_objdir=.
+        libname=conftest
+        lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1)
+        _LT_TAGVAR(allow_undefined_flag, $1)=
+        if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1)
+        then
+	  _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+        else
+	  _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+        fi
+        _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag
+      else
+        cat conftest.err 1>&5
+      fi
+      $RM conftest*
+      AC_MSG_RESULT([$_LT_TAGVAR(archive_cmds_need_lc, $1)])
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0],
+    [Whether or not to add -lc for building shared libraries])
+_LT_TAGDECL([allow_libtool_libs_with_static_runtimes],
+    [enable_shared_with_static_runtimes], [0],
+    [Whether or not to disallow shared libs when runtime libs are static])
+_LT_TAGDECL([], [export_dynamic_flag_spec], [1],
+    [Compiler flag to allow reflexive dlopens])
+_LT_TAGDECL([], [whole_archive_flag_spec], [1],
+    [Compiler flag to generate shared objects directly from archives])
+_LT_TAGDECL([], [compiler_needs_object], [1],
+    [Whether the compiler copes with passing no objects directly])
+_LT_TAGDECL([], [old_archive_from_new_cmds], [2],
+    [Create an old-style archive from a shared archive])
+_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2],
+    [Create a temporary old-style archive to link instead of a shared archive])
+_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive])
+_LT_TAGDECL([], [archive_expsym_cmds], [2])
+_LT_TAGDECL([], [module_cmds], [2],
+    [Commands used to build a loadable module if different from building
+    a shared archive.])
+_LT_TAGDECL([], [module_expsym_cmds], [2])
+_LT_TAGDECL([], [with_gnu_ld], [1],
+    [Whether we are building with GNU ld or not])
+_LT_TAGDECL([], [allow_undefined_flag], [1],
+    [Flag that allows shared libraries with undefined symbols to be built])
+_LT_TAGDECL([], [no_undefined_flag], [1],
+    [Flag that enforces no undefined symbols])
+_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1],
+    [Flag to hardcode $libdir into a binary during linking.
+    This must work even if $libdir does not exist])
+_LT_TAGDECL([], [hardcode_libdir_flag_spec_ld], [1],
+    [[If ld is used when linking, flag to hardcode $libdir into a binary
+    during linking.  This must work even if $libdir does not exist]])
+_LT_TAGDECL([], [hardcode_libdir_separator], [1],
+    [Whether we need a single "-rpath" flag with a separated argument])
+_LT_TAGDECL([], [hardcode_direct], [0],
+    [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes
+    DIR into the resulting binary])
+_LT_TAGDECL([], [hardcode_direct_absolute], [0],
+    [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes
+    DIR into the resulting binary and the resulting library dependency is
+    "absolute", i.e impossible to change by setting ${shlibpath_var} if the
+    library is relocated])
+_LT_TAGDECL([], [hardcode_minus_L], [0],
+    [Set to "yes" if using the -LDIR flag during linking hardcodes DIR
+    into the resulting binary])
+_LT_TAGDECL([], [hardcode_shlibpath_var], [0],
+    [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR
+    into the resulting binary])
+_LT_TAGDECL([], [hardcode_automatic], [0],
+    [Set to "yes" if building a shared library automatically hardcodes DIR
+    into the library and all subsequent libraries and executables linked
+    against it])
+_LT_TAGDECL([], [inherit_rpath], [0],
+    [Set to yes if linker adds runtime paths of dependent libraries
+    to runtime path list])
+_LT_TAGDECL([], [link_all_deplibs], [0],
+    [Whether libtool must link a program against all its dependency libraries])
+_LT_TAGDECL([], [fix_srcfile_path], [1],
+    [Fix the shell variable $srcfile for the compiler])
+_LT_TAGDECL([], [always_export_symbols], [0],
+    [Set to "yes" if exported symbols are required])
+_LT_TAGDECL([], [export_symbols_cmds], [2],
+    [The commands to list exported symbols])
+_LT_TAGDECL([], [exclude_expsyms], [1],
+    [Symbols that should not be listed in the preloaded symbols])
+_LT_TAGDECL([], [include_expsyms], [1],
+    [Symbols that must always be exported])
+_LT_TAGDECL([], [prelink_cmds], [2],
+    [Commands necessary for linking programs (against libraries) with templates])
+_LT_TAGDECL([], [file_list_spec], [1],
+    [Specify filename containing input files])
+dnl FIXME: Not yet implemented
+dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1],
+dnl    [Compiler flag to generate thread safe objects])
+])# _LT_LINKER_SHLIBS
+
+
+# _LT_LANG_C_CONFIG([TAG])
+# ------------------------
+# Ensure that the configuration variables for a C compiler are suitably
+# defined.  These variables are subsequently used by _LT_CONFIG to write
+# the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_C_CONFIG],
+[m4_require([_LT_DECL_EGREP])dnl
+lt_save_CC="$CC"
+AC_LANG_PUSH(C)
+
+# Source file extension for C test sources.
+ac_ext=c
+
+# Object file extension for compiled C test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(){return(0);}'
+
+_LT_TAG_COMPILER
+# Save the default compiler, since it gets overwritten when the other
+# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP.
+compiler_DEFAULT=$CC
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+## CAVEAT EMPTOR:
+## There is no encapsulation within the following macros, do not change
+## the running order or otherwise move them around unless you know exactly
+## what you are doing...
+if test -n "$compiler"; then
+  _LT_COMPILER_NO_RTTI($1)
+  _LT_COMPILER_PIC($1)
+  _LT_COMPILER_C_O($1)
+  _LT_COMPILER_FILE_LOCKS($1)
+  _LT_LINKER_SHLIBS($1)
+  _LT_SYS_DYNAMIC_LINKER($1)
+  _LT_LINKER_HARDCODE_LIBPATH($1)
+  LT_SYS_DLOPEN_SELF
+  _LT_CMD_STRIPLIB
+
+  # Report which library types will actually be built
+  AC_MSG_CHECKING([if libtool supports shared libraries])
+  AC_MSG_RESULT([$can_build_shared])
+
+  AC_MSG_CHECKING([whether to build shared libraries])
+  test "$can_build_shared" = "no" && enable_shared=no
+
+  # On AIX, shared libraries and static libraries use the same namespace, and
+  # are all built from PIC.
+  case $host_os in
+  aix3*)
+    test "$enable_shared" = yes && enable_static=no
+    if test -n "$RANLIB"; then
+      archive_cmds="$archive_cmds~\$RANLIB \$lib"
+      postinstall_cmds='$RANLIB $lib'
+    fi
+    ;;
+
+  aix[[4-9]]*)
+    if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+      test "$enable_shared" = yes && enable_static=no
+    fi
+    ;;
+  esac
+  AC_MSG_RESULT([$enable_shared])
+
+  AC_MSG_CHECKING([whether to build static libraries])
+  # Make sure either enable_shared or enable_static is yes.
+  test "$enable_shared" = yes || enable_static=yes
+  AC_MSG_RESULT([$enable_static])
+
+  _LT_CONFIG($1)
+fi
+AC_LANG_POP
+CC="$lt_save_CC"
+])# _LT_LANG_C_CONFIG
+
+
+# _LT_PROG_CXX
+# ------------
+# Since AC_PROG_CXX is broken, in that it returns g++ if there is no c++
+# compiler, we have our own version here.
+m4_defun([_LT_PROG_CXX],
+[
+pushdef([AC_MSG_ERROR], [_lt_caught_CXX_error=yes])
+AC_PROG_CXX
+if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
+    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
+    (test "X$CXX" != "Xg++"))) ; then
+  AC_PROG_CXXCPP
+else
+  _lt_caught_CXX_error=yes
+fi
+popdef([AC_MSG_ERROR])
+])# _LT_PROG_CXX
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([_LT_PROG_CXX], [])
+
+
+# _LT_LANG_CXX_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for a C++ compiler are suitably
+# defined.  These variables are subsequently used by _LT_CONFIG to write
+# the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_CXX_CONFIG],
+[AC_REQUIRE([_LT_PROG_CXX])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_EGREP])dnl
+
+AC_LANG_PUSH(C++)
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(compiler_needs_object, $1)=no
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for C++ test sources.
+ac_ext=cpp
+
+# Object file extension for compiled C++ test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the CXX compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_caught_CXX_error" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="int some_variable = 0;"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }'
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC=$CC
+  lt_save_LD=$LD
+  lt_save_GCC=$GCC
+  GCC=$GXX
+  lt_save_with_gnu_ld=$with_gnu_ld
+  lt_save_path_LD=$lt_cv_path_LD
+  if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then
+    lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx
+  else
+    $as_unset lt_cv_prog_gnu_ld
+  fi
+  if test -n "${lt_cv_path_LDCXX+set}"; then
+    lt_cv_path_LD=$lt_cv_path_LDCXX
+  else
+    $as_unset lt_cv_path_LD
+  fi
+  test -z "${LDCXX+set}" || LD=$LDCXX
+  CC=${CXX-"c++"}
+  compiler=$CC
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+
+  if test -n "$compiler"; then
+    # We don't want -fno-exception when compiling C++ code, so set the
+    # no_builtin_flag separately
+    if test "$GXX" = yes; then
+      _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
+    else
+      _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
+    fi
+
+    if test "$GXX" = yes; then
+      # Set up default GNU C++ configuration
+
+      LT_PATH_LD
+
+      # Check if GNU C++ uses GNU ld as the underlying linker, since the
+      # archiving commands below assume that GNU ld is being used.
+      if test "$with_gnu_ld" = yes; then
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+        _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+
+        # If archive_cmds runs LD, not CC, wlarc should be empty
+        # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to
+        #     investigate it a little bit more. (MM)
+        wlarc='${wl}'
+
+        # ancient GNU ld didn't support --whole-archive et. al.
+        if eval "`$CC -print-prog-name=ld` --help 2>&1" |
+	  $GREP 'no-whole-archive' > /dev/null; then
+          _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+        else
+          _LT_TAGVAR(whole_archive_flag_spec, $1)=
+        fi
+      else
+        with_gnu_ld=no
+        wlarc=
+
+        # A generic and very simple default shared library creation
+        # command for GNU C++ for the case where it uses the native
+        # linker, instead of GNU ld.  If possible, this setting should
+        # overridden to take advantage of the native linker features on
+        # the platform it is being used on.
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+      fi
+
+      # Commands to make compiler produce verbose output that lists
+      # what "hidden" libraries, object files and flags are used when
+      # linking a shared library.
+      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
+
+    else
+      GXX=no
+      with_gnu_ld=no
+      wlarc=
+    fi
+
+    # PORTME: fill in a description of your system's C++ link characteristics
+    AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
+    _LT_TAGVAR(ld_shlibs, $1)=yes
+    case $host_os in
+      aix3*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+      aix[[4-9]]*)
+        if test "$host_cpu" = ia64; then
+          # On IA64, the linker does run time linking by default, so we don't
+          # have to do anything special.
+          aix_use_runtimelinking=no
+          exp_sym_flag='-Bexport'
+          no_entry_flag=""
+        else
+          aix_use_runtimelinking=no
+
+          # Test if we are trying to use run time linking or normal
+          # AIX style linking. If -brtl is somewhere in LDFLAGS, we
+          # need to do runtime linking.
+          case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
+	    for ld_flag in $LDFLAGS; do
+	      case $ld_flag in
+	      *-brtl*)
+	        aix_use_runtimelinking=yes
+	        break
+	        ;;
+	      esac
+	    done
+	    ;;
+          esac
+
+          exp_sym_flag='-bexport'
+          no_entry_flag='-bnoentry'
+        fi
+
+        # When large executables or shared objects are built, AIX ld can
+        # have problems creating the table of contents.  If linking a library
+        # or program results in "error TOC overflow" add -mminimal-toc to
+        # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+        # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+        _LT_TAGVAR(archive_cmds, $1)=''
+        _LT_TAGVAR(hardcode_direct, $1)=yes
+        _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+        _LT_TAGVAR(link_all_deplibs, $1)=yes
+        _LT_TAGVAR(file_list_spec, $1)='${wl}-f,'
+
+        if test "$GXX" = yes; then
+          case $host_os in aix4.[[012]]|aix4.[[012]].*)
+          # We only want to do this on AIX 4.2 and lower, the check
+          # below for broken collect2 doesn't work under 4.3+
+	  collect2name=`${CC} -print-prog-name=collect2`
+	  if test -f "$collect2name" &&
+	     strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+	  then
+	    # We have reworked collect2
+	    :
+	  else
+	    # We have old collect2
+	    _LT_TAGVAR(hardcode_direct, $1)=unsupported
+	    # It fails to find uninstalled libraries when the uninstalled
+	    # path is not listed in the libpath.  Setting hardcode_minus_L
+	    # to unsupported forces relinking
+	    _LT_TAGVAR(hardcode_minus_L, $1)=yes
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+	    _LT_TAGVAR(hardcode_libdir_separator, $1)=
+	  fi
+          esac
+          shared_flag='-shared'
+	  if test "$aix_use_runtimelinking" = yes; then
+	    shared_flag="$shared_flag "'${wl}-G'
+	  fi
+        else
+          # not using gcc
+          if test "$host_cpu" = ia64; then
+	  # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+	  # chokes on -Wl,-G. The following line is correct:
+	  shared_flag='-G'
+          else
+	    if test "$aix_use_runtimelinking" = yes; then
+	      shared_flag='${wl}-G'
+	    else
+	      shared_flag='${wl}-bM:SRE'
+	    fi
+          fi
+        fi
+
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall'
+        # It seems that -bexpall does not export symbols beginning with
+        # underscore (_), so it is better to generate a list of symbols to
+	# export.
+        _LT_TAGVAR(always_export_symbols, $1)=yes
+        if test "$aix_use_runtimelinking" = yes; then
+          # Warning - without using the other runtime loading flags (-brtl),
+          # -berok will link without error, but may produce a broken library.
+          _LT_TAGVAR(allow_undefined_flag, $1)='-berok'
+          # Determine the default libpath from the value encoded in an empty
+          # executable.
+          _LT_SYS_MODULE_PATH_AIX
+          _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+
+          _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+        else
+          if test "$host_cpu" = ia64; then
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
+	    _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
+	    _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+          else
+	    # Determine the default libpath from the value encoded in an
+	    # empty executable.
+	    _LT_SYS_MODULE_PATH_AIX
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+	    # Warning - without using the other run time loading flags,
+	    # -berok will link without error, but may produce a broken library.
+	    _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
+	    _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
+	    # Exported symbols can be pulled into shared objects from archives
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
+	    _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+	    # This is similar to how AIX traditionally builds its shared
+	    # libraries.
+	    _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+          fi
+        fi
+        ;;
+
+      beos*)
+	if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+	  _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+	  # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
+	  # support --undefined.  This deserves some investigation.  FIXME
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	else
+	  _LT_TAGVAR(ld_shlibs, $1)=no
+	fi
+	;;
+
+      chorus*)
+        case $cc_basename in
+          *)
+	  # FIXME: insert proper C++ library support
+	  _LT_TAGVAR(ld_shlibs, $1)=no
+	  ;;
+        esac
+        ;;
+
+      cygwin* | mingw* | pw32* | cegcc*)
+        # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
+        # as there is no search path for DLLs.
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+        _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+        _LT_TAGVAR(always_export_symbols, $1)=no
+        _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+
+        if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+          _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+          # If the export-symbols file already is a .def file (1st line
+          # is EXPORTS), use it as is; otherwise, prepend...
+          _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+	    cp $export_symbols $output_objdir/$soname.def;
+          else
+	    echo EXPORTS > $output_objdir/$soname.def;
+	    cat $export_symbols >> $output_objdir/$soname.def;
+          fi~
+          $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+        else
+          _LT_TAGVAR(ld_shlibs, $1)=no
+        fi
+        ;;
+      darwin* | rhapsody*)
+        _LT_DARWIN_LINKER_FEATURES($1)
+	;;
+
+      dgux*)
+        case $cc_basename in
+          ec++*)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          ghcx*)
+	    # Green Hills C++ Compiler
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          *)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+        esac
+        ;;
+
+      freebsd[[12]]*)
+        # C++ shared libraries reported to be fairly broken before
+	# switch to ELF
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      freebsd-elf*)
+        _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+        ;;
+
+      freebsd* | dragonfly*)
+        # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF
+        # conventions
+        _LT_TAGVAR(ld_shlibs, $1)=yes
+        ;;
+
+      gnu*)
+        ;;
+
+      hpux9*)
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+        _LT_TAGVAR(hardcode_direct, $1)=yes
+        _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
+				             # but as the default
+				             # location of the library.
+
+        case $cc_basename in
+          CC*)
+            # FIXME: insert proper C++ library support
+            _LT_TAGVAR(ld_shlibs, $1)=no
+            ;;
+          aCC*)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+            # Commands to make compiler produce verbose output that lists
+            # what "hidden" libraries, object files and flags are used when
+            # linking a shared library.
+            #
+            # There doesn't appear to be a way to prevent this compiler from
+            # explicitly linking system object files so we need to strip them
+            # from the output so that they don't get included in the library
+            # dependencies.
+            output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+            ;;
+          *)
+            if test "$GXX" = yes; then
+              _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+            else
+              # FIXME: insert proper C++ library support
+              _LT_TAGVAR(ld_shlibs, $1)=no
+            fi
+            ;;
+        esac
+        ;;
+
+      hpux10*|hpux11*)
+        if test $with_gnu_ld = no; then
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+	  _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+          case $host_cpu in
+            hppa*64*|ia64*)
+              ;;
+            *)
+	      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+              ;;
+          esac
+        fi
+        case $host_cpu in
+          hppa*64*|ia64*)
+            _LT_TAGVAR(hardcode_direct, $1)=no
+            _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+            ;;
+          *)
+            _LT_TAGVAR(hardcode_direct, $1)=yes
+            _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
+					         # but as the default
+					         # location of the library.
+            ;;
+        esac
+
+        case $cc_basename in
+          CC*)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          aCC*)
+	    case $host_cpu in
+	      hppa*64*)
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	        ;;
+	      ia64*)
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	        ;;
+	      *)
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	        ;;
+	    esac
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    #
+	    # There doesn't appear to be a way to prevent this compiler from
+	    # explicitly linking system object files so we need to strip them
+	    # from the output so that they don't get included in the library
+	    # dependencies.
+	    output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+	    ;;
+          *)
+	    if test "$GXX" = yes; then
+	      if test $with_gnu_ld = no; then
+	        case $host_cpu in
+	          hppa*64*)
+	            _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	            ;;
+	          ia64*)
+	            _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	            ;;
+	          *)
+	            _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	            ;;
+	        esac
+	      fi
+	    else
+	      # FIXME: insert proper C++ library support
+	      _LT_TAGVAR(ld_shlibs, $1)=no
+	    fi
+	    ;;
+        esac
+        ;;
+
+      interix[[3-9]]*)
+	_LT_TAGVAR(hardcode_direct, $1)=no
+	_LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	_LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	# Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+	# Instead, shared libraries are loaded at an image base (0x10000000 by
+	# default) and relocated if they conflict, which is a slow very memory
+	# consuming and fragmenting process.  To avoid this, we pick a random,
+	# 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+	# time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+	_LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+	;;
+      irix5* | irix6*)
+        case $cc_basename in
+          CC*)
+	    # SGI C++
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+
+	    # Archives containing C++ object files must be created using
+	    # "CC -ar", where "CC" is the IRIX C++ compiler.  This is
+	    # necessary to make sure instantiated templates are included
+	    # in the archive.
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs'
+	    ;;
+          *)
+	    if test "$GXX" = yes; then
+	      if test "$with_gnu_ld" = no; then
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+	      else
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` -o $lib'
+	      fi
+	    fi
+	    _LT_TAGVAR(link_all_deplibs, $1)=yes
+	    ;;
+        esac
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+        _LT_TAGVAR(inherit_rpath, $1)=yes
+        ;;
+
+      linux* | k*bsd*-gnu)
+        case $cc_basename in
+          KCC*)
+	    # Kuck and Associates, Inc. (KAI) C++ Compiler
+
+	    # KCC will only create a shared library if the output file
+	    # ends with ".so" (or ".sl" for HP-UX), so rename the library
+	    # to its proper name (with version) after linking.
+	    _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib'
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    #
+	    # There doesn't appear to be a way to prevent this compiler from
+	    # explicitly linking system object files so we need to strip them
+	    # from the output so that they don't get included in the library
+	    # dependencies.
+	    output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+
+	    # Archives containing C++ object files must be created using
+	    # "CC -Bstatic", where "CC" is the KAI C++ compiler.
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs'
+	    ;;
+	  icpc* | ecpc* )
+	    # Intel C++
+	    with_gnu_ld=yes
+	    # version 8.0 and above of icpc choke on multiply defined symbols
+	    # if we add $predep_objects and $postdep_objects, however 7.1 and
+	    # earlier do not add the objects themselves.
+	    case `$CC -V 2>&1` in
+	      *"Version 7."*)
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+		_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+		;;
+	      *)  # Version 8.0 or newer
+	        tmp_idyn=
+	        case $host_cpu in
+		  ia64*) tmp_idyn=' -i_dynamic';;
+		esac
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+		_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+		;;
+	    esac
+	    _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+	    ;;
+          pgCC* | pgcpp*)
+            # Portland Group C++ compiler
+	    case `$CC -V` in
+	    *pgCC\ [[1-5]]* | *pgcpp\ [[1-5]]*)
+	      _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~
+		rm -rf $tpldir~
+		$CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~
+		compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"'
+	      _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~
+		rm -rf $tpldir~
+		$CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~
+		$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~
+		$RANLIB $oldlib'
+	      _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~
+		rm -rf $tpldir~
+		$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
+		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~
+		rm -rf $tpldir~
+		$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
+		$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+	      ;;
+	    *) # Version 6 will use weak symbols
+	      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+	      ;;
+	    esac
+
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+            ;;
+	  cxx*)
+	    # Compaq C++
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname  -o $lib ${wl}-retain-symbols-file $wl$export_symbols'
+
+	    runpath_var=LD_RUN_PATH
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+	    _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    #
+	    # There doesn't appear to be a way to prevent this compiler from
+	    # explicitly linking system object files so we need to strip them
+	    # from the output so that they don't get included in the library
+	    # dependencies.
+	    output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+	    ;;
+	  xl*)
+	    # IBM XL 8.0 on PPC, with GNU ld
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+	    if test "x$supports_anon_versioning" = xyes; then
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+		cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+		echo "local: *; };" >> $output_objdir/$libname.ver~
+		$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+	    fi
+	    ;;
+	  *)
+	    case `$CC -V 2>&1 | sed 5q` in
+	    *Sun\ C*)
+	      # Sun C++ 5.9
+	      _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs'
+	      _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols'
+	      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	      _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
+	      _LT_TAGVAR(compiler_needs_object, $1)=yes
+
+	      # Not sure whether something based on
+	      # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1
+	      # would be better.
+	      output_verbose_link_cmd='echo'
+
+	      # Archives containing C++ object files must be created using
+	      # "CC -xar", where "CC" is the Sun C++ compiler.  This is
+	      # necessary to make sure instantiated templates are included
+	      # in the archive.
+	      _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
+	      ;;
+	    esac
+	    ;;
+	esac
+	;;
+
+      lynxos*)
+        # FIXME: insert proper C++ library support
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	;;
+
+      m88k*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+	;;
+
+      mvs*)
+        case $cc_basename in
+          cxx*)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+	  *)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+	esac
+	;;
+
+      netbsd*)
+        if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+	  _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable  -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags'
+	  wlarc=
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	  _LT_TAGVAR(hardcode_direct, $1)=yes
+	  _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	fi
+	# Workaround some broken pre-1.5 toolchains
+	output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"'
+	;;
+
+      *nto* | *qnx*)
+        _LT_TAGVAR(ld_shlibs, $1)=yes
+	;;
+
+      openbsd2*)
+        # C++ shared libraries are fairly broken
+	_LT_TAGVAR(ld_shlibs, $1)=no
+	;;
+
+      openbsd*)
+	if test -f /usr/libexec/ld.so; then
+	  _LT_TAGVAR(hardcode_direct, $1)=yes
+	  _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	  _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+	  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	  if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib'
+	    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+	    _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+	  fi
+	  output_verbose_link_cmd=echo
+	else
+	  _LT_TAGVAR(ld_shlibs, $1)=no
+	fi
+	;;
+
+      osf3* | osf4* | osf5*)
+        case $cc_basename in
+          KCC*)
+	    # Kuck and Associates, Inc. (KAI) C++ Compiler
+
+	    # KCC will only create a shared library if the output file
+	    # ends with ".so" (or ".sl" for HP-UX), so rename the library
+	    # to its proper name (with version) after linking.
+	    _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+	    _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	    # Archives containing C++ object files must be created using
+	    # the KAI C++ compiler.
+	    case $host in
+	      osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;;
+	      *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;;
+	    esac
+	    ;;
+          RCC*)
+	    # Rational C++ 2.4.1
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          cxx*)
+	    case $host in
+	      osf3*)
+	        _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && $ECHO "X${wl}-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+	        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+		;;
+	      *)
+	        _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
+	        _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~
+	          echo "-hidden">> $lib.exp~
+	          $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname ${wl}-input ${wl}$lib.exp  `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~
+	          $RM $lib.exp'
+	        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+		;;
+	    esac
+
+	    _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	    # Commands to make compiler produce verbose output that lists
+	    # what "hidden" libraries, object files and flags are used when
+	    # linking a shared library.
+	    #
+	    # There doesn't appear to be a way to prevent this compiler from
+	    # explicitly linking system object files so we need to strip them
+	    # from the output so that they don't get included in the library
+	    # dependencies.
+	    output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
+	    ;;
+	  *)
+	    if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+	      _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+	      case $host in
+	        osf3*)
+	          _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+		  ;;
+	        *)
+	          _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+		  ;;
+	      esac
+
+	      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+	      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+	      # Commands to make compiler produce verbose output that lists
+	      # what "hidden" libraries, object files and flags are used when
+	      # linking a shared library.
+	      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
+
+	    else
+	      # FIXME: insert proper C++ library support
+	      _LT_TAGVAR(ld_shlibs, $1)=no
+	    fi
+	    ;;
+        esac
+        ;;
+
+      psos*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      sunos4*)
+        case $cc_basename in
+          CC*)
+	    # Sun C++ 4.x
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          lcc*)
+	    # Lucid
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          *)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+        esac
+        ;;
+
+      solaris*)
+        case $cc_basename in
+          CC*)
+	    # Sun C++ 4.2, 5.x and Centerline C++
+            _LT_TAGVAR(archive_cmds_need_lc,$1)=yes
+	    _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs'
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag}  -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+	      $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+	    _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	    case $host_os in
+	      solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+	      *)
+		# The compiler driver will combine and reorder linker options,
+		# but understands `-z linker_flag'.
+	        # Supported since Solaris 2.6 (maybe 2.5.1?)
+		_LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
+	        ;;
+	    esac
+	    _LT_TAGVAR(link_all_deplibs, $1)=yes
+
+	    output_verbose_link_cmd='echo'
+
+	    # Archives containing C++ object files must be created using
+	    # "CC -xar", where "CC" is the Sun C++ compiler.  This is
+	    # necessary to make sure instantiated templates are included
+	    # in the archive.
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
+	    ;;
+          gcx*)
+	    # Green Hills C++ Compiler
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+
+	    # The C++ compiler must be used to create the archive.
+	    _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs'
+	    ;;
+          *)
+	    # GNU C++ compiler with Solaris linker
+	    if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+	      _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs'
+	      if $CC --version | $GREP -v '^2\.7' > /dev/null; then
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+	        _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+		  $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+	        # Commands to make compiler produce verbose output that lists
+	        # what "hidden" libraries, object files and flags are used when
+	        # linking a shared library.
+	        output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
+	      else
+	        # g++ 2.7 appears to require `-G' NOT `-shared' on this
+	        # platform.
+	        _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+	        _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+		  $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+	        # Commands to make compiler produce verbose output that lists
+	        # what "hidden" libraries, object files and flags are used when
+	        # linking a shared library.
+	        output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
+	      fi
+
+	      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir'
+	      case $host_os in
+		solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+		*)
+		  _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+		  ;;
+	      esac
+	    fi
+	    ;;
+        esac
+        ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      runpath_var='LD_RUN_PATH'
+
+      case $cc_basename in
+        CC*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+	*)
+	  _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	  ;;
+      esac
+      ;;
+
+      sysv5* | sco3.2v5* | sco5v6*)
+	# Note: We can NOT use -z defs as we might desire, because we do not
+	# link with -lc, and that would cause any symbols used from libc to
+	# always be unresolved, which means just about no library would
+	# ever link correctly.  If we're not using GNU ld we use -z text
+	# though, which does catch some bad symbols but isn't as heavy-handed
+	# as -z defs.
+	_LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+	_LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
+	_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+	_LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+	_LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir'
+	_LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+	_LT_TAGVAR(link_all_deplibs, $1)=yes
+	_LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
+	runpath_var='LD_RUN_PATH'
+
+	case $cc_basename in
+          CC*)
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	    ;;
+	  *)
+	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+	    ;;
+	esac
+      ;;
+
+      tandem*)
+        case $cc_basename in
+          NCC*)
+	    # NonStop-UX NCC 3.20
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+          *)
+	    # FIXME: insert proper C++ library support
+	    _LT_TAGVAR(ld_shlibs, $1)=no
+	    ;;
+        esac
+        ;;
+
+      vxworks*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      *)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+    esac
+
+    AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)])
+    test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+    _LT_TAGVAR(GCC, $1)="$GXX"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_SYS_HIDDEN_LIBDEPS($1)
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  CC=$lt_save_CC
+  LDCXX=$LD
+  LD=$lt_save_LD
+  GCC=$lt_save_GCC
+  with_gnu_ld=$lt_save_with_gnu_ld
+  lt_cv_path_LDCXX=$lt_cv_path_LD
+  lt_cv_path_LD=$lt_save_path_LD
+  lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld
+  lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld
+fi # test "$_lt_caught_CXX_error" != yes
+
+AC_LANG_POP
+])# _LT_LANG_CXX_CONFIG
+
+
+# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME])
+# ---------------------------------
+# Figure out "hidden" library dependencies from verbose
+# compiler output when linking a shared library.
+# Parse the compiler output and extract the necessary
+# objects, libraries and library flags.
+m4_defun([_LT_SYS_HIDDEN_LIBDEPS],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+# Dependencies to place before and after the object being linked:
+_LT_TAGVAR(predep_objects, $1)=
+_LT_TAGVAR(postdep_objects, $1)=
+_LT_TAGVAR(predeps, $1)=
+_LT_TAGVAR(postdeps, $1)=
+_LT_TAGVAR(compiler_lib_search_path, $1)=
+
+dnl we can't use the lt_simple_compile_test_code here,
+dnl because it contains code intended for an executable,
+dnl not a library.  It's possible we should let each
+dnl tag define a new lt_????_link_test_code variable,
+dnl but it's only used here...
+m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF
+int a;
+void foo (void) { a = 0; }
+_LT_EOF
+], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF
+class Foo
+{
+public:
+  Foo (void) { a = 0; }
+private:
+  int a;
+};
+_LT_EOF
+], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF
+      subroutine foo
+      implicit none
+      integer*4 a
+      a=0
+      return
+      end
+_LT_EOF
+], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF
+      subroutine foo
+      implicit none
+      integer a
+      a=0
+      return
+      end
+_LT_EOF
+], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF
+public class foo {
+  private int a;
+  public void bar (void) {
+    a = 0;
+  }
+};
+_LT_EOF
+])
+dnl Parse the compiler output and extract the necessary
+dnl objects, libraries and library flags.
+if AC_TRY_EVAL(ac_compile); then
+  # Parse the compiler output and extract the necessary
+  # objects, libraries and library flags.
+
+  # Sentinel used to keep track of whether or not we are before
+  # the conftest object file.
+  pre_test_object_deps_done=no
+
+  for p in `eval "$output_verbose_link_cmd"`; do
+    case $p in
+
+    -L* | -R* | -l*)
+       # Some compilers place space between "-{L,R}" and the path.
+       # Remove the space.
+       if test $p = "-L" ||
+          test $p = "-R"; then
+	 prev=$p
+	 continue
+       else
+	 prev=
+       fi
+
+       if test "$pre_test_object_deps_done" = no; then
+	 case $p in
+	 -L* | -R*)
+	   # Internal compiler library paths should come after those
+	   # provided the user.  The postdeps already come after the
+	   # user supplied libs so there is no need to process them.
+	   if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then
+	     _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}"
+	   else
+	     _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}"
+	   fi
+	   ;;
+	 # The "-l" case would never come before the object being
+	 # linked, so don't bother handling this case.
+	 esac
+       else
+	 if test -z "$_LT_TAGVAR(postdeps, $1)"; then
+	   _LT_TAGVAR(postdeps, $1)="${prev}${p}"
+	 else
+	   _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}"
+	 fi
+       fi
+       ;;
+
+    *.$objext)
+       # This assumes that the test object file only shows up
+       # once in the compiler output.
+       if test "$p" = "conftest.$objext"; then
+	 pre_test_object_deps_done=yes
+	 continue
+       fi
+
+       if test "$pre_test_object_deps_done" = no; then
+	 if test -z "$_LT_TAGVAR(predep_objects, $1)"; then
+	   _LT_TAGVAR(predep_objects, $1)="$p"
+	 else
+	   _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p"
+	 fi
+       else
+	 if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then
+	   _LT_TAGVAR(postdep_objects, $1)="$p"
+	 else
+	   _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p"
+	 fi
+       fi
+       ;;
+
+    *) ;; # Ignore the rest.
+
+    esac
+  done
+
+  # Clean up.
+  rm -f a.out a.exe
+else
+  echo "libtool.m4: error: problem compiling $1 test program"
+fi
+
+$RM -f confest.$objext
+
+# PORTME: override above test on systems where it is broken
+m4_if([$1], [CXX],
+[case $host_os in
+interix[[3-9]]*)
+  # Interix 3.5 installs completely hosed .la files for C++, so rather than
+  # hack all around it, let's just trust "g++" to DTRT.
+  _LT_TAGVAR(predep_objects,$1)=
+  _LT_TAGVAR(postdep_objects,$1)=
+  _LT_TAGVAR(postdeps,$1)=
+  ;;
+
+linux*)
+  case `$CC -V 2>&1 | sed 5q` in
+  *Sun\ C*)
+    # Sun C++ 5.9
+
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+
+    if test "$solaris_use_stlport4" != yes; then
+      _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+
+solaris*)
+  case $cc_basename in
+  CC*)
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+
+    # Adding this requires a known-good setup of shared libraries for
+    # Sun compiler versions before 5.6, else PIC objects from an old
+    # archive will be linked into the output, leading to subtle bugs.
+    if test "$solaris_use_stlport4" != yes; then
+      _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+esac
+])
+
+case " $_LT_TAGVAR(postdeps, $1) " in
+*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;;
+esac
+ _LT_TAGVAR(compiler_lib_search_dirs, $1)=
+if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then
+ _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'`
+fi
+_LT_TAGDECL([], [compiler_lib_search_dirs], [1],
+    [The directories searched by this compiler when creating a shared library])
+_LT_TAGDECL([], [predep_objects], [1],
+    [Dependencies to place before and after the objects being linked to
+    create a shared library])
+_LT_TAGDECL([], [postdep_objects], [1])
+_LT_TAGDECL([], [predeps], [1])
+_LT_TAGDECL([], [postdeps], [1])
+_LT_TAGDECL([], [compiler_lib_search_path], [1],
+    [The library search path used internally by the compiler when linking
+    a shared library])
+])# _LT_SYS_HIDDEN_LIBDEPS
+
+
+# _LT_PROG_F77
+# ------------
+# Since AC_PROG_F77 is broken, in that it returns the empty string
+# if there is no fortran compiler, we have our own version here.
+m4_defun([_LT_PROG_F77],
+[
+pushdef([AC_MSG_ERROR], [_lt_disable_F77=yes])
+AC_PROG_F77
+if test -z "$F77" || test "X$F77" = "Xno"; then
+  _lt_disable_F77=yes
+fi
+popdef([AC_MSG_ERROR])
+])# _LT_PROG_F77
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([_LT_PROG_F77], [])
+
+
+# _LT_LANG_F77_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for a Fortran 77 compiler are
+# suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_F77_CONFIG],
+[AC_REQUIRE([_LT_PROG_F77])dnl
+AC_LANG_PUSH(Fortran 77)
+
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for f77 test sources.
+ac_ext=f
+
+# Object file extension for compiled f77 test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the F77 compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_disable_F77" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="\
+      subroutine t
+      return
+      end
+"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code="\
+      program t
+      end
+"
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC="$CC"
+  lt_save_GCC=$GCC
+  CC=${F77-"f77"}
+  compiler=$CC
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+  GCC=$G77
+  if test -n "$compiler"; then
+    AC_MSG_CHECKING([if libtool supports shared libraries])
+    AC_MSG_RESULT([$can_build_shared])
+
+    AC_MSG_CHECKING([whether to build shared libraries])
+    test "$can_build_shared" = "no" && enable_shared=no
+
+    # On AIX, shared libraries and static libraries use the same namespace, and
+    # are all built from PIC.
+    case $host_os in
+      aix3*)
+        test "$enable_shared" = yes && enable_static=no
+        if test -n "$RANLIB"; then
+          archive_cmds="$archive_cmds~\$RANLIB \$lib"
+          postinstall_cmds='$RANLIB $lib'
+        fi
+        ;;
+      aix[[4-9]]*)
+	if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+	  test "$enable_shared" = yes && enable_static=no
+	fi
+        ;;
+    esac
+    AC_MSG_RESULT([$enable_shared])
+
+    AC_MSG_CHECKING([whether to build static libraries])
+    # Make sure either enable_shared or enable_static is yes.
+    test "$enable_shared" = yes || enable_static=yes
+    AC_MSG_RESULT([$enable_static])
+
+    _LT_TAGVAR(GCC, $1)="$G77"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  GCC=$lt_save_GCC
+  CC="$lt_save_CC"
+fi # test "$_lt_disable_F77" != yes
+
+AC_LANG_POP
+])# _LT_LANG_F77_CONFIG
+
+
+# _LT_PROG_FC
+# -----------
+# Since AC_PROG_FC is broken, in that it returns the empty string
+# if there is no fortran compiler, we have our own version here.
+m4_defun([_LT_PROG_FC],
+[
+pushdef([AC_MSG_ERROR], [_lt_disable_FC=yes])
+AC_PROG_FC
+if test -z "$FC" || test "X$FC" = "Xno"; then
+  _lt_disable_FC=yes
+fi
+popdef([AC_MSG_ERROR])
+])# _LT_PROG_FC
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([_LT_PROG_FC], [])
+
+
+# _LT_LANG_FC_CONFIG([TAG])
+# -------------------------
+# Ensure that the configuration variables for a Fortran compiler are
+# suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_FC_CONFIG],
+[AC_REQUIRE([_LT_PROG_FC])dnl
+AC_LANG_PUSH(Fortran)
+
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for fc test sources.
+ac_ext=${ac_fc_srcext-f}
+
+# Object file extension for compiled fc test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the FC compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_disable_FC" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="\
+      subroutine t
+      return
+      end
+"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code="\
+      program t
+      end
+"
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC="$CC"
+  lt_save_GCC=$GCC
+  CC=${FC-"f95"}
+  compiler=$CC
+  GCC=$ac_cv_fc_compiler_gnu
+
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+
+  if test -n "$compiler"; then
+    AC_MSG_CHECKING([if libtool supports shared libraries])
+    AC_MSG_RESULT([$can_build_shared])
+
+    AC_MSG_CHECKING([whether to build shared libraries])
+    test "$can_build_shared" = "no" && enable_shared=no
+
+    # On AIX, shared libraries and static libraries use the same namespace, and
+    # are all built from PIC.
+    case $host_os in
+      aix3*)
+        test "$enable_shared" = yes && enable_static=no
+        if test -n "$RANLIB"; then
+          archive_cmds="$archive_cmds~\$RANLIB \$lib"
+          postinstall_cmds='$RANLIB $lib'
+        fi
+        ;;
+      aix[[4-9]]*)
+	if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+	  test "$enable_shared" = yes && enable_static=no
+	fi
+        ;;
+    esac
+    AC_MSG_RESULT([$enable_shared])
+
+    AC_MSG_CHECKING([whether to build static libraries])
+    # Make sure either enable_shared or enable_static is yes.
+    test "$enable_shared" = yes || enable_static=yes
+    AC_MSG_RESULT([$enable_static])
+
+    _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_SYS_HIDDEN_LIBDEPS($1)
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  GCC=$lt_save_GCC
+  CC="$lt_save_CC"
+fi # test "$_lt_disable_FC" != yes
+
+AC_LANG_POP
+])# _LT_LANG_FC_CONFIG
+
+
+# _LT_LANG_GCJ_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for the GNU Java Compiler compiler
+# are suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_GCJ_CONFIG],
+[AC_REQUIRE([LT_PROG_GCJ])dnl
+AC_LANG_SAVE
+
+# Source file extension for Java test sources.
+ac_ext=java
+
+# Object file extension for compiled Java test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="class foo {}"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }'
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_TAG_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+lt_save_GCC=$GCC
+GCC=yes
+CC=${GCJ-"gcj"}
+compiler=$CC
+_LT_TAGVAR(compiler, $1)=$CC
+_LT_TAGVAR(LD, $1)="$LD"
+_LT_CC_BASENAME([$compiler])
+
+# GCJ did not exist at the time GCC didn't implicitly link libc in.
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+
+## CAVEAT EMPTOR:
+## There is no encapsulation within the following macros, do not change
+## the running order or otherwise move them around unless you know exactly
+## what you are doing...
+if test -n "$compiler"; then
+  _LT_COMPILER_NO_RTTI($1)
+  _LT_COMPILER_PIC($1)
+  _LT_COMPILER_C_O($1)
+  _LT_COMPILER_FILE_LOCKS($1)
+  _LT_LINKER_SHLIBS($1)
+  _LT_LINKER_HARDCODE_LIBPATH($1)
+
+  _LT_CONFIG($1)
+fi
+
+AC_LANG_RESTORE
+
+GCC=$lt_save_GCC
+CC="$lt_save_CC"
+])# _LT_LANG_GCJ_CONFIG
+
+
+# _LT_LANG_RC_CONFIG([TAG])
+# -------------------------
+# Ensure that the configuration variables for the Windows resource compiler
+# are suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_RC_CONFIG],
+[AC_REQUIRE([LT_PROG_RC])dnl
+AC_LANG_SAVE
+
+# Source file extension for RC test sources.
+ac_ext=rc
+
+# Object file extension for compiled RC test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }'
+
+# Code to be used in simple link tests
+lt_simple_link_test_code="$lt_simple_compile_test_code"
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_TAG_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+lt_save_GCC=$GCC
+GCC=
+CC=${RC-"windres"}
+compiler=$CC
+_LT_TAGVAR(compiler, $1)=$CC
+_LT_CC_BASENAME([$compiler])
+_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
+
+if test -n "$compiler"; then
+  :
+  _LT_CONFIG($1)
+fi
+
+GCC=$lt_save_GCC
+AC_LANG_RESTORE
+CC="$lt_save_CC"
+])# _LT_LANG_RC_CONFIG
+
+
+# LT_PROG_GCJ
+# -----------
+AC_DEFUN([LT_PROG_GCJ],
+[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ],
+  [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ],
+    [AC_CHECK_TOOL(GCJ, gcj,)
+      test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2"
+      AC_SUBST(GCJFLAGS)])])[]dnl
+])
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_GCJ], [])
+
+
+# LT_PROG_RC
+# ----------
+AC_DEFUN([LT_PROG_RC],
+[AC_CHECK_TOOL(RC, windres,)
+])
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_RC], [])
+
+
+# _LT_DECL_EGREP
+# --------------
+# If we don't have a new enough Autoconf to choose the best grep
+# available, choose the one first in the user's PATH.
+m4_defun([_LT_DECL_EGREP],
+[AC_REQUIRE([AC_PROG_EGREP])dnl
+AC_REQUIRE([AC_PROG_FGREP])dnl
+test -z "$GREP" && GREP=grep
+_LT_DECL([], [GREP], [1], [A grep program that handles long lines])
+_LT_DECL([], [EGREP], [1], [An ERE matcher])
+_LT_DECL([], [FGREP], [1], [A literal string matcher])
+dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too
+AC_SUBST([GREP])
+])
+
+
+# _LT_DECL_OBJDUMP
+# --------------
+# If we don't have a new enough Autoconf to choose the best objdump
+# available, choose the one first in the user's PATH.
+m4_defun([_LT_DECL_OBJDUMP],
+[AC_CHECK_TOOL(OBJDUMP, objdump, false)
+test -z "$OBJDUMP" && OBJDUMP=objdump
+_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper])
+AC_SUBST([OBJDUMP])
+])
+
+
+# _LT_DECL_SED
+# ------------
+# Check for a fully-functional sed program, that truncates
+# as few characters as possible.  Prefer GNU sed if found.
+m4_defun([_LT_DECL_SED],
+[AC_PROG_SED
+test -z "$SED" && SED=sed
+Xsed="$SED -e 1s/^X//"
+_LT_DECL([], [SED], [1], [A sed program that does not truncate output])
+_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"],
+    [Sed that helps us avoid accidentally triggering echo(1) options like -n])
+])# _LT_DECL_SED
+
+m4_ifndef([AC_PROG_SED], [
+############################################################
+# NOTE: This macro has been submitted for inclusion into   #
+#  GNU Autoconf as AC_PROG_SED.  When it is available in   #
+#  a released version of Autoconf we should remove this    #
+#  macro and use it instead.                               #
+############################################################
+
+m4_defun([AC_PROG_SED],
+[AC_MSG_CHECKING([for a sed that does not truncate output])
+AC_CACHE_VAL(lt_cv_path_SED,
+[# Loop through the user's path and test for sed and gsed.
+# Then use that list of sed's as ones to test for truncation.
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for lt_ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then
+        lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext"
+      fi
+    done
+  done
+done
+IFS=$as_save_IFS
+lt_ac_max=0
+lt_ac_count=0
+# Add /usr/xpg4/bin/sed as it is typically found on Solaris
+# along with /bin/sed that truncates output.
+for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do
+  test ! -f $lt_ac_sed && continue
+  cat /dev/null > conftest.in
+  lt_ac_count=0
+  echo $ECHO_N "0123456789$ECHO_C" >conftest.in
+  # Check for GNU sed and select it if it is found.
+  if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then
+    lt_cv_path_SED=$lt_ac_sed
+    break
+  fi
+  while true; do
+    cat conftest.in conftest.in >conftest.tmp
+    mv conftest.tmp conftest.in
+    cp conftest.in conftest.nl
+    echo >>conftest.nl
+    $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break
+    cmp -s conftest.out conftest.nl || break
+    # 10000 chars as input seems more than enough
+    test $lt_ac_count -gt 10 && break
+    lt_ac_count=`expr $lt_ac_count + 1`
+    if test $lt_ac_count -gt $lt_ac_max; then
+      lt_ac_max=$lt_ac_count
+      lt_cv_path_SED=$lt_ac_sed
+    fi
+  done
+done
+])
+SED=$lt_cv_path_SED
+AC_SUBST([SED])
+AC_MSG_RESULT([$SED])
+])#AC_PROG_SED
+])#m4_ifndef
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_SED], [])
+
+
+# _LT_CHECK_SHELL_FEATURES
+# ------------------------
+# Find out whether the shell is Bourne or XSI compatible,
+# or has some other useful features.
+m4_defun([_LT_CHECK_SHELL_FEATURES],
+[AC_MSG_CHECKING([whether the shell understands some XSI constructs])
+# Try some XSI features
+xsi_shell=no
+( _lt_dummy="a/b/c"
+  test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \
+      = c,a/b,, \
+    && eval 'test $(( 1 + 1 )) -eq 2 \
+    && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \
+  && xsi_shell=yes
+AC_MSG_RESULT([$xsi_shell])
+_LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell'])
+
+AC_MSG_CHECKING([whether the shell understands "+="])
+lt_shell_append=no
+( foo=bar; set foo baz; eval "$[1]+=\$[2]" && test "$foo" = barbaz ) \
+    >/dev/null 2>&1 \
+  && lt_shell_append=yes
+AC_MSG_RESULT([$lt_shell_append])
+_LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append'])
+
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  lt_unset=unset
+else
+  lt_unset=false
+fi
+_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl
+
+# test EBCDIC or ASCII
+case `echo X|tr X '\101'` in
+ A) # ASCII based system
+    # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
+  lt_SP2NL='tr \040 \012'
+  lt_NL2SP='tr \015\012 \040\040'
+  ;;
+ *) # EBCDIC based system
+  lt_SP2NL='tr \100 \n'
+  lt_NL2SP='tr \r\n \100\100'
+  ;;
+esac
+_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl
+_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl
+])# _LT_CHECK_SHELL_FEATURES
+
+
+# _LT_PROG_XSI_SHELLFNS
+# ---------------------
+# Bourne and XSI compatible variants of some useful shell functions.
+m4_defun([_LT_PROG_XSI_SHELLFNS],
+[case $xsi_shell in
+  yes)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+  case ${1} in
+    */*) func_dirname_result="${1%/*}${2}" ;;
+    *  ) func_dirname_result="${3}" ;;
+  esac
+}
+
+# func_basename file
+func_basename ()
+{
+  func_basename_result="${1##*/}"
+}
+
+# func_dirname_and_basename file append nondir_replacement
+# perform func_basename and func_dirname in a single function
+# call:
+#   dirname:  Compute the dirname of FILE.  If nonempty,
+#             add APPEND to the result, otherwise set result
+#             to NONDIR_REPLACEMENT.
+#             value returned in "$func_dirname_result"
+#   basename: Compute filename of FILE.
+#             value retuned in "$func_basename_result"
+# Implementation must be kept synchronized with func_dirname
+# and func_basename. For efficiency, we do not delegate to
+# those functions but instead duplicate the functionality here.
+func_dirname_and_basename ()
+{
+  case ${1} in
+    */*) func_dirname_result="${1%/*}${2}" ;;
+    *  ) func_dirname_result="${3}" ;;
+  esac
+  func_basename_result="${1##*/}"
+}
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+func_stripname ()
+{
+  # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
+  # positional parameters, so assign one to ordinary parameter first.
+  func_stripname_result=${3}
+  func_stripname_result=${func_stripname_result#"${1}"}
+  func_stripname_result=${func_stripname_result%"${2}"}
+}
+
+# func_opt_split
+func_opt_split ()
+{
+  func_opt_split_opt=${1%%=*}
+  func_opt_split_arg=${1#*=}
+}
+
+# func_lo2o object
+func_lo2o ()
+{
+  case ${1} in
+    *.lo) func_lo2o_result=${1%.lo}.${objext} ;;
+    *)    func_lo2o_result=${1} ;;
+  esac
+}
+
+# func_xform libobj-or-source
+func_xform ()
+{
+  func_xform_result=${1%.*}.lo
+}
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+  func_arith_result=$(( $[*] ))
+}
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+  func_len_result=${#1}
+}
+
+_LT_EOF
+    ;;
+  *) # Bourne compatible functions.
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+  # Extract subdirectory from the argument.
+  func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"`
+  if test "X$func_dirname_result" = "X${1}"; then
+    func_dirname_result="${3}"
+  else
+    func_dirname_result="$func_dirname_result${2}"
+  fi
+}
+
+# func_basename file
+func_basename ()
+{
+  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
+}
+
+dnl func_dirname_and_basename
+dnl A portable version of this function is already defined in general.m4sh
+dnl so there is no need for it here.
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+# func_strip_suffix prefix name
+func_stripname ()
+{
+  case ${2} in
+    .*) func_stripname_result=`$ECHO "X${3}" \
+           | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;;
+    *)  func_stripname_result=`$ECHO "X${3}" \
+           | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;;
+  esac
+}
+
+# sed scripts:
+my_sed_long_opt='1s/^\(-[[^=]]*\)=.*/\1/;q'
+my_sed_long_arg='1s/^-[[^=]]*=//'
+
+# func_opt_split
+func_opt_split ()
+{
+  func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"`
+  func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"`
+}
+
+# func_lo2o object
+func_lo2o ()
+{
+  func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"`
+}
+
+# func_xform libobj-or-source
+func_xform ()
+{
+  func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[[^.]]*$/.lo/'`
+}
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+  func_arith_result=`expr "$[@]"`
+}
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+  func_len_result=`expr "$[1]" : ".*" 2>/dev/null || echo $max_cmd_len`
+}
+
+_LT_EOF
+esac
+
+case $lt_shell_append in
+  yes)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+  eval "$[1]+=\$[2]"
+}
+_LT_EOF
+    ;;
+  *)
+    cat << \_LT_EOF >> "$cfgfile"
+
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+  eval "$[1]=\$$[1]\$[2]"
+}
+
+_LT_EOF
+    ;;
+  esac
+])
diff --git a/m4/ltoptions.m4 b/m4/ltoptions.m4
new file mode 100644
index 0000000..34151a3
--- /dev/null
+++ b/m4/ltoptions.m4
@@ -0,0 +1,368 @@
+# Helper functions for option handling.                    -*- Autoconf -*-
+#
+#   Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
+#   Written by Gary V. Vaughan, 2004
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 6 ltoptions.m4
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])])
+
+
+# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME)
+# ------------------------------------------
+m4_define([_LT_MANGLE_OPTION],
+[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])])
+
+
+# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME)
+# ---------------------------------------
+# Set option OPTION-NAME for macro MACRO-NAME, and if there is a
+# matching handler defined, dispatch to it.  Other OPTION-NAMEs are
+# saved as a flag.
+m4_define([_LT_SET_OPTION],
+[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl
+m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]),
+        _LT_MANGLE_DEFUN([$1], [$2]),
+    [m4_warning([Unknown $1 option `$2'])])[]dnl
+])
+
+
+# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET])
+# ------------------------------------------------------------
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
+m4_define([_LT_IF_OPTION],
+[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])])
+
+
+# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET)
+# -------------------------------------------------------
+# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME
+# are set.
+m4_define([_LT_UNLESS_OPTIONS],
+[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
+	    [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option),
+		      [m4_define([$0_found])])])[]dnl
+m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3
+])[]dnl
+])
+
+
+# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST)
+# ----------------------------------------
+# OPTION-LIST is a space-separated list of Libtool options associated
+# with MACRO-NAME.  If any OPTION has a matching handler declared with
+# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about
+# the unknown option and exit.
+m4_defun([_LT_SET_OPTIONS],
+[# Set options
+m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
+    [_LT_SET_OPTION([$1], _LT_Option)])
+
+m4_if([$1],[LT_INIT],[
+  dnl
+  dnl Simply set some default values (i.e off) if boolean options were not
+  dnl specified:
+  _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no
+  ])
+  _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no
+  ])
+  dnl
+  dnl If no reference was made to various pairs of opposing options, then
+  dnl we run the default mode handler for the pair.  For example, if neither
+  dnl `shared' nor `disable-shared' was passed, we enable building of shared
+  dnl archives by default:
+  _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED])
+  _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC])
+  _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC])
+  _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install],
+  		   [_LT_ENABLE_FAST_INSTALL])
+  ])
+])# _LT_SET_OPTIONS
+
+
+## --------------------------------- ##
+## Macros to handle LT_INIT options. ##
+## --------------------------------- ##
+
+# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME)
+# -----------------------------------------
+m4_define([_LT_MANGLE_DEFUN],
+[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])])
+
+
+# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE)
+# -----------------------------------------------
+m4_define([LT_OPTION_DEFINE],
+[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl
+])# LT_OPTION_DEFINE
+
+
+# dlopen
+# ------
+LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes
+])
+
+AU_DEFUN([AC_LIBTOOL_DLOPEN],
+[_LT_SET_OPTION([LT_INIT], [dlopen])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `dlopen' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], [])
+
+
+# win32-dll
+# ---------
+# Declare package support for building win32 dll's.
+LT_OPTION_DEFINE([LT_INIT], [win32-dll],
+[enable_win32_dll=yes
+
+case $host in
+*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-cegcc*)
+  AC_CHECK_TOOL(AS, as, false)
+  AC_CHECK_TOOL(DLLTOOL, dlltool, false)
+  AC_CHECK_TOOL(OBJDUMP, objdump, false)
+  ;;
+esac
+
+test -z "$AS" && AS=as
+_LT_DECL([], [AS],      [0], [Assembler program])dnl
+
+test -z "$DLLTOOL" && DLLTOOL=dlltool
+_LT_DECL([], [DLLTOOL], [0], [DLL creation program])dnl
+
+test -z "$OBJDUMP" && OBJDUMP=objdump
+_LT_DECL([], [OBJDUMP], [0], [Object dumper program])dnl
+])# win32-dll
+
+AU_DEFUN([AC_LIBTOOL_WIN32_DLL],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+_LT_SET_OPTION([LT_INIT], [win32-dll])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `win32-dll' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], [])
+
+
+# _LT_ENABLE_SHARED([DEFAULT])
+# ----------------------------
+# implement the --enable-shared flag, and supports the `shared' and
+# `disable-shared' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_SHARED],
+[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([shared],
+    [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@],
+	[build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_shared=yes ;;
+    no) enable_shared=no ;;
+    *)
+      enable_shared=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_shared=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_shared=]_LT_ENABLE_SHARED_DEFAULT)
+
+    _LT_DECL([build_libtool_libs], [enable_shared], [0],
+	[Whether or not to build shared libraries])
+])# _LT_ENABLE_SHARED
+
+LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])])
+
+# Old names:
+AC_DEFUN([AC_ENABLE_SHARED],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared])
+])
+
+AC_DEFUN([AC_DISABLE_SHARED],
+[_LT_SET_OPTION([LT_INIT], [disable-shared])
+])
+
+AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)])
+AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_ENABLE_SHARED], [])
+dnl AC_DEFUN([AM_DISABLE_SHARED], [])
+
+
+
+# _LT_ENABLE_STATIC([DEFAULT])
+# ----------------------------
+# implement the --enable-static flag, and support the `static' and
+# `disable-static' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_STATIC],
+[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([static],
+    [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@],
+	[build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_static=yes ;;
+    no) enable_static=no ;;
+    *)
+     enable_static=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_static=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_static=]_LT_ENABLE_STATIC_DEFAULT)
+
+    _LT_DECL([build_old_libs], [enable_static], [0],
+	[Whether or not to build static libraries])
+])# _LT_ENABLE_STATIC
+
+LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])])
+
+# Old names:
+AC_DEFUN([AC_ENABLE_STATIC],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static])
+])
+
+AC_DEFUN([AC_DISABLE_STATIC],
+[_LT_SET_OPTION([LT_INIT], [disable-static])
+])
+
+AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)])
+AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_ENABLE_STATIC], [])
+dnl AC_DEFUN([AM_DISABLE_STATIC], [])
+
+
+
+# _LT_ENABLE_FAST_INSTALL([DEFAULT])
+# ----------------------------------
+# implement the --enable-fast-install flag, and support the `fast-install'
+# and `disable-fast-install' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_FAST_INSTALL],
+[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([fast-install],
+    [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@],
+    [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_fast_install=yes ;;
+    no) enable_fast_install=no ;;
+    *)
+      enable_fast_install=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+	IFS="$lt_save_ifs"
+	if test "X$pkg" = "X$p"; then
+	  enable_fast_install=yes
+	fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT)
+
+_LT_DECL([fast_install], [enable_fast_install], [0],
+	 [Whether or not to optimize for fast installation])dnl
+])# _LT_ENABLE_FAST_INSTALL
+
+LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])])
+
+# Old names:
+AU_DEFUN([AC_ENABLE_FAST_INSTALL],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you put
+the `fast-install' option into LT_INIT's first parameter.])
+])
+
+AU_DEFUN([AC_DISABLE_FAST_INSTALL],
+[_LT_SET_OPTION([LT_INIT], [disable-fast-install])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you put
+the `disable-fast-install' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], [])
+dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], [])
+
+
+# _LT_WITH_PIC([MODE])
+# --------------------
+# implement the --with-pic flag, and support the `pic-only' and `no-pic'
+# LT_INIT options.
+# MODE is either `yes' or `no'.  If omitted, it defaults to `both'.
+m4_define([_LT_WITH_PIC],
+[AC_ARG_WITH([pic],
+    [AS_HELP_STRING([--with-pic],
+	[try to use only PIC/non-PIC objects @<:@default=use both@:>@])],
+    [pic_mode="$withval"],
+    [pic_mode=default])
+
+test -z "$pic_mode" && pic_mode=m4_default([$1], [default])
+
+_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl
+])# _LT_WITH_PIC
+
+LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])])
+LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])])
+
+# Old name:
+AU_DEFUN([AC_LIBTOOL_PICMODE],
+[_LT_SET_OPTION([LT_INIT], [pic-only])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `pic-only' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_PICMODE], [])
+
+## ----------------- ##
+## LTDL_INIT Options ##
+## ----------------- ##
+
+m4_define([_LTDL_MODE], [])
+LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive],
+		 [m4_define([_LTDL_MODE], [nonrecursive])])
+LT_OPTION_DEFINE([LTDL_INIT], [recursive],
+		 [m4_define([_LTDL_MODE], [recursive])])
+LT_OPTION_DEFINE([LTDL_INIT], [subproject],
+		 [m4_define([_LTDL_MODE], [subproject])])
+
+m4_define([_LTDL_TYPE], [])
+LT_OPTION_DEFINE([LTDL_INIT], [installable],
+		 [m4_define([_LTDL_TYPE], [installable])])
+LT_OPTION_DEFINE([LTDL_INIT], [convenience],
+		 [m4_define([_LTDL_TYPE], [convenience])])
diff --git a/m4/ltsugar.m4 b/m4/ltsugar.m4
new file mode 100644
index 0000000..9000a05
--- /dev/null
+++ b/m4/ltsugar.m4
@@ -0,0 +1,123 @@
+# ltsugar.m4 -- libtool m4 base layer.                         -*-Autoconf-*-
+#
+# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
+# Written by Gary V. Vaughan, 2004
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 6 ltsugar.m4
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
+
+
+# lt_join(SEP, ARG1, [ARG2...])
+# -----------------------------
+# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
+# associated separator.
+# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
+# versions in m4sugar had bugs.
+m4_define([lt_join],
+[m4_if([$#], [1], [],
+       [$#], [2], [[$2]],
+       [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
+m4_define([_lt_join],
+[m4_if([$#$2], [2], [],
+       [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
+
+
+# lt_car(LIST)
+# lt_cdr(LIST)
+# ------------
+# Manipulate m4 lists.
+# These macros are necessary as long as will still need to support
+# Autoconf-2.59 which quotes differently.
+m4_define([lt_car], [[$1]])
+m4_define([lt_cdr],
+[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
+       [$#], 1, [],
+       [m4_dquote(m4_shift($@))])])
+m4_define([lt_unquote], $1)
+
+
+# lt_append(MACRO-NAME, STRING, [SEPARATOR])
+# ------------------------------------------
+# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'.
+# Note that neither SEPARATOR nor STRING are expanded; they are appended
+# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
+# No SEPARATOR is output if MACRO-NAME was previously undefined (different
+# than defined and empty).
+#
+# This macro is needed until we can rely on Autoconf 2.62, since earlier
+# versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
+m4_define([lt_append],
+[m4_define([$1],
+	   m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
+
+
+
+# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
+# ----------------------------------------------------------
+# Produce a SEP delimited list of all paired combinations of elements of
+# PREFIX-LIST with SUFFIX1 through SUFFIXn.  Each element of the list
+# has the form PREFIXmINFIXSUFFIXn.
+# Needed until we can rely on m4_combine added in Autoconf 2.62.
+m4_define([lt_combine],
+[m4_if(m4_eval([$# > 3]), [1],
+       [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
+[[m4_foreach([_Lt_prefix], [$2],
+	     [m4_foreach([_Lt_suffix],
+		]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
+	[_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
+
+
+# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
+# -----------------------------------------------------------------------
+# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
+# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
+m4_define([lt_if_append_uniq],
+[m4_ifdef([$1],
+	  [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
+		 [lt_append([$1], [$2], [$3])$4],
+		 [$5])],
+	  [lt_append([$1], [$2], [$3])$4])])
+
+
+# lt_dict_add(DICT, KEY, VALUE)
+# -----------------------------
+m4_define([lt_dict_add],
+[m4_define([$1($2)], [$3])])
+
+
+# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
+# --------------------------------------------
+m4_define([lt_dict_add_subkey],
+[m4_define([$1($2:$3)], [$4])])
+
+
+# lt_dict_fetch(DICT, KEY, [SUBKEY])
+# ----------------------------------
+m4_define([lt_dict_fetch],
+[m4_ifval([$3],
+	m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
+    m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
+
+
+# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
+# -----------------------------------------------------------------
+m4_define([lt_if_dict_fetch],
+[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
+	[$5],
+    [$6])])
+
+
+# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
+# --------------------------------------------------------------
+m4_define([lt_dict_filter],
+[m4_if([$5], [], [],
+  [lt_join(m4_quote(m4_default([$4], [[, ]])),
+           lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
+		      [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
+])
diff --git a/m4/ltversion.m4 b/m4/ltversion.m4
new file mode 100644
index 0000000..b8e154f
--- /dev/null
+++ b/m4/ltversion.m4
@@ -0,0 +1,23 @@
+# ltversion.m4 -- version numbers			-*- Autoconf -*-
+#
+#   Copyright (C) 2004 Free Software Foundation, Inc.
+#   Written by Scott James Remnant, 2004
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# Generated from ltversion.in.
+
+# serial 3012 ltversion.m4
+# This file is part of GNU Libtool
+
+m4_define([LT_PACKAGE_VERSION], [2.2.6])
+m4_define([LT_PACKAGE_REVISION], [1.3012])
+
+AC_DEFUN([LTVERSION_VERSION],
+[macro_version='2.2.6'
+macro_revision='1.3012'
+_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
+_LT_DECL(, macro_revision, 0)
+])
diff --git a/m4/lt~obsolete.m4 b/m4/lt~obsolete.m4
new file mode 100644
index 0000000..637bb20
--- /dev/null
+++ b/m4/lt~obsolete.m4
@@ -0,0 +1,92 @@
+# lt~obsolete.m4 -- aclocal satisfying obsolete definitions.    -*-Autoconf-*-
+#
+#   Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
+#   Written by Scott James Remnant, 2004.
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 4 lt~obsolete.m4
+
+# These exist entirely to fool aclocal when bootstrapping libtool.
+#
+# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN)
+# which have later been changed to m4_define as they aren't part of the
+# exported API, or moved to Autoconf or Automake where they belong.
+#
+# The trouble is, aclocal is a bit thick.  It'll see the old AC_DEFUN
+# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us
+# using a macro with the same name in our local m4/libtool.m4 it'll
+# pull the old libtool.m4 in (it doesn't see our shiny new m4_define
+# and doesn't know about Autoconf macros at all.)
+#
+# So we provide this file, which has a silly filename so it's always
+# included after everything else.  This provides aclocal with the
+# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything
+# because those macros already exist, or will be overwritten later.
+# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 
+#
+# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here.
+# Yes, that means every name once taken will need to remain here until
+# we give up compatibility with versions before 1.7, at which point
+# we need to keep only those names which we still refer to.
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])])
+
+m4_ifndef([AC_LIBTOOL_LINKER_OPTION],	[AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])])
+m4_ifndef([AC_PROG_EGREP],		[AC_DEFUN([AC_PROG_EGREP])])
+m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH],	[AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])])
+m4_ifndef([_LT_AC_SHELL_INIT],		[AC_DEFUN([_LT_AC_SHELL_INIT])])
+m4_ifndef([_LT_AC_SYS_LIBPATH_AIX],	[AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])])
+m4_ifndef([_LT_PROG_LTMAIN],		[AC_DEFUN([_LT_PROG_LTMAIN])])
+m4_ifndef([_LT_AC_TAGVAR],		[AC_DEFUN([_LT_AC_TAGVAR])])
+m4_ifndef([AC_LTDL_ENABLE_INSTALL],	[AC_DEFUN([AC_LTDL_ENABLE_INSTALL])])
+m4_ifndef([AC_LTDL_PREOPEN],		[AC_DEFUN([AC_LTDL_PREOPEN])])
+m4_ifndef([_LT_AC_SYS_COMPILER],	[AC_DEFUN([_LT_AC_SYS_COMPILER])])
+m4_ifndef([_LT_AC_LOCK],		[AC_DEFUN([_LT_AC_LOCK])])
+m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE],	[AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])])
+m4_ifndef([_LT_AC_TRY_DLOPEN_SELF],	[AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])])
+m4_ifndef([AC_LIBTOOL_PROG_CC_C_O],	[AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])])
+m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])])
+m4_ifndef([AC_LIBTOOL_OBJDIR],		[AC_DEFUN([AC_LIBTOOL_OBJDIR])])
+m4_ifndef([AC_LTDL_OBJDIR],		[AC_DEFUN([AC_LTDL_OBJDIR])])
+m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])])
+m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP],	[AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])])
+m4_ifndef([AC_PATH_MAGIC],		[AC_DEFUN([AC_PATH_MAGIC])])
+m4_ifndef([AC_PROG_LD_GNU],		[AC_DEFUN([AC_PROG_LD_GNU])])
+m4_ifndef([AC_PROG_LD_RELOAD_FLAG],	[AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])])
+m4_ifndef([AC_DEPLIBS_CHECK_METHOD],	[AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])])
+m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])])
+m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])])
+m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])])
+m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS],	[AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])])
+m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP],	[AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])])
+m4_ifndef([LT_AC_PROG_EGREP],		[AC_DEFUN([LT_AC_PROG_EGREP])])
+m4_ifndef([LT_AC_PROG_SED],		[AC_DEFUN([LT_AC_PROG_SED])])
+m4_ifndef([_LT_CC_BASENAME],		[AC_DEFUN([_LT_CC_BASENAME])])
+m4_ifndef([_LT_COMPILER_BOILERPLATE],	[AC_DEFUN([_LT_COMPILER_BOILERPLATE])])
+m4_ifndef([_LT_LINKER_BOILERPLATE],	[AC_DEFUN([_LT_LINKER_BOILERPLATE])])
+m4_ifndef([_AC_PROG_LIBTOOL],		[AC_DEFUN([_AC_PROG_LIBTOOL])])
+m4_ifndef([AC_LIBTOOL_SETUP],		[AC_DEFUN([AC_LIBTOOL_SETUP])])
+m4_ifndef([_LT_AC_CHECK_DLFCN],		[AC_DEFUN([_LT_AC_CHECK_DLFCN])])
+m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER],	[AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])])
+m4_ifndef([_LT_AC_TAGCONFIG],		[AC_DEFUN([_LT_AC_TAGCONFIG])])
+m4_ifndef([AC_DISABLE_FAST_INSTALL],	[AC_DEFUN([AC_DISABLE_FAST_INSTALL])])
+m4_ifndef([_LT_AC_LANG_CXX],		[AC_DEFUN([_LT_AC_LANG_CXX])])
+m4_ifndef([_LT_AC_LANG_F77],		[AC_DEFUN([_LT_AC_LANG_F77])])
+m4_ifndef([_LT_AC_LANG_GCJ],		[AC_DEFUN([_LT_AC_LANG_GCJ])])
+m4_ifndef([AC_LIBTOOL_RC],		[AC_DEFUN([AC_LIBTOOL_RC])])
+m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])])
+m4_ifndef([_LT_AC_LANG_C_CONFIG],	[AC_DEFUN([_LT_AC_LANG_C_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])])
+m4_ifndef([_LT_AC_LANG_CXX_CONFIG],	[AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])])
+m4_ifndef([_LT_AC_LANG_F77_CONFIG],	[AC_DEFUN([_LT_AC_LANG_F77_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])])
+m4_ifndef([_LT_AC_LANG_GCJ_CONFIG],	[AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG],	[AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])])
+m4_ifndef([_LT_AC_LANG_RC_CONFIG],	[AC_DEFUN([_LT_AC_LANG_RC_CONFIG])])
+m4_ifndef([AC_LIBTOOL_CONFIG],		[AC_DEFUN([AC_LIBTOOL_CONFIG])])
+m4_ifndef([_LT_AC_FILE_LTDLL_C],	[AC_DEFUN([_LT_AC_FILE_LTDLL_C])])
diff --git a/m4/stdint.m4 b/m4/stdint.m4
new file mode 100644
index 0000000..62ac3e5
--- /dev/null
+++ b/m4/stdint.m4
@@ -0,0 +1,732 @@
+dnl AC_NEED_STDINT_H ( HEADER-TO-GENERATE )
+dnl Copyright 2001-2002 by Dan Fandrich <dan@coneharvesters.com>
+dnl This file may be copied and used freely without restrictions.  No warranty
+dnl is expressed or implied.
+dnl
+dnl Look for a header file that defines size-specific integer types like the
+dnl ones recommended to be in stdint.h in the C99 standard (e.g. uint32_t).
+dnl This is a dumbed-down version of the macro of the same name in the file
+dnl ac_need_stdint_h.m4 which is part of the ac-archive, available at
+dnl <URL:http://ac-archive.sourceforge.net/> (also, another macro
+dnl AC_CREATE_STDINT_H by the same author).  This version is not as smart,
+dnl but works on older autoconf versions and has a different license.
+
+dnl AX_CHECK_DEFINED_TYPE ( TYPE, FILE, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND )
+dnl This is similar to _AC_CHECK_TYPE_NEW (a.k.a. new syntax version of
+dnl AC_CHECK_TYPE) in autoconf 2.50 but works on older versions
+AC_DEFUN([AX_CHECK_DEFINED_TYPE],
+[AC_MSG_CHECKING([for $1 in $2])
+AC_EGREP_CPP(changequote(<<,>>)dnl
+<<(^|[^a-zA-Z_0-9])$1[^a-zA-Z_0-9]>>dnl
+changequote([,]), [#include <$2>],
+ac_cv_type_$1=yes, ac_cv_type_$1=no)dnl
+AC_MSG_RESULT($ac_cv_type_$1)
+if test $ac_cv_type_$1 = yes; then
+  $3
+else
+  $4
+fi
+])
+
+dnl Look for a header file that defines size-specific integer types
+AC_DEFUN([AX_NEED_STDINT_H],
+[
+ac_dir=`AS_DIRNAME(["$1"])`
+if test "$ac_dir" != "$1" && test "$ac_dir" != .; then
+  # The file is in a subdirectory.
+  test ! -d "$ac_dir" && AS_MKDIR_P(["$ac_dir"])
+fi
+
+AX_CHECK_DEFINED_TYPE(uint8_t,
+stdint.h,
+[
+cat > "$1" <<EOF
+/* This file is generated automatically by configure */
+#include <stdint.h>
+EOF],
+[AX_CHECK_DEFINED_TYPE(uint8_t,
+inttypes.h,
+[cat > "$1" <<EOF
+/* This file is generated automatically by configure */
+#include <inttypes.h>
+EOF],
+[AX_CHECK_DEFINED_TYPE(uint8_t,
+sys/types.h,
+[cat > "$1" <<EOF
+/* This file is generated automatically by configure */
+#include <sys/types.h>
+EOF],
+[AX_CHECK_DEFINED_TYPE(u_int8_t,
+sys/types.h,
+[cat > "$1" <<EOF
+/* This file is generated automatically by configure */
+#ifndef __STDINT_H
+#define __STDINT_H
+#include <sys/types.h>
+typedef u_int8_t uint8_t;
+typedef u_int16_t uint16_t;
+typedef u_int32_t uint32_t;
+EOF
+
+AX_CHECK_DEFINED_TYPE(u_int64_t,
+sys/types.h,
+[cat >> "$1" <<EOF
+typedef u_int64_t uint64_t;
+#endif /*!__STDINT_H*/
+EOF],
+[cat >> "$1" <<EOF
+/* 64-bit types are not available on this system */
+/* typedef u_int64_t uint64_t; */
+#endif /*!__STDINT_H*/
+EOF])
+
+],
+[AC_MSG_WARN([I can't find size-specific integer definitions on this system])
+if test -e "$1" ; then
+	rm -f "$1"
+fi
+])])])])dnl
+])
+
+AC_DEFUN([AX_CHECK_DATA_MODEL],[
+   AC_CHECK_SIZEOF(char)
+   AC_CHECK_SIZEOF(short)
+   AC_CHECK_SIZEOF(int)
+   AC_CHECK_SIZEOF(long)
+   AC_CHECK_SIZEOF(void*)
+   ac_cv_char_data_model=""
+   ac_cv_char_data_model="$ac_cv_char_data_model$ac_cv_sizeof_char"
+   ac_cv_char_data_model="$ac_cv_char_data_model$ac_cv_sizeof_short"
+   ac_cv_char_data_model="$ac_cv_char_data_model$ac_cv_sizeof_int"
+   ac_cv_long_data_model=""
+   ac_cv_long_data_model="$ac_cv_long_data_model$ac_cv_sizeof_int"
+   ac_cv_long_data_model="$ac_cv_long_data_model$ac_cv_sizeof_long"
+   ac_cv_long_data_model="$ac_cv_long_data_model$ac_cv_sizeof_voidp"
+   AC_MSG_CHECKING([data model])
+   case "$ac_cv_char_data_model/$ac_cv_long_data_model" in
+    122/242)     ac_cv_data_model="IP16"  ; n="standard 16bit machine" ;;
+    122/244)     ac_cv_data_model="LP32"  ; n="standard 32bit machine" ;;
+    122/*)       ac_cv_data_model="i16"   ; n="unusual int16 model" ;;
+    124/444)     ac_cv_data_model="ILP32" ; n="standard 32bit unixish" ;;
+    124/488)     ac_cv_data_model="LP64"  ; n="standard 64bit unixish" ;;
+    124/448)     ac_cv_data_model="LLP64" ; n="unusual 64bit unixish" ;;
+    124/*)       ac_cv_data_model="i32"   ; n="unusual int32 model" ;;
+    128/888)     ac_cv_data_model="ILP64" ; n="unusual 64bit numeric" ;;
+    128/*)       ac_cv_data_model="i64"   ; n="unusual int64 model" ;;
+    222/*2)      ac_cv_data_model="DSP16" ; n="strict 16bit dsptype" ;;
+    333/*3)      ac_cv_data_model="DSP24" ; n="strict 24bit dsptype" ;;
+    444/*4)      ac_cv_data_model="DSP32" ; n="strict 32bit dsptype" ;;
+    666/*6)      ac_cv_data_model="DSP48" ; n="strict 48bit dsptype" ;;
+    888/*8)      ac_cv_data_model="DSP64" ; n="strict 64bit dsptype" ;;
+    222/*|333/*|444/*|666/*|888/*) :
+                 ac_cv_data_model="iDSP"  ; n="unusual dsptype" ;;
+     *)          ac_cv_data_model="none"  ; n="very unusual model" ;;
+   esac
+   AC_MSG_RESULT([$ac_cv_data_model ($ac_cv_long_data_model, $n)])
+])
+
+dnl AX_CHECK_HEADER_STDINT_X([HEADERLIST][,ACTION-IF])
+AC_DEFUN([AX_CHECK_HEADER_STDINT_X],[
+AC_CACHE_CHECK([for stdint uintptr_t], [ac_cv_header_stdint_x],[
+ ac_cv_header_stdint_x="" # the 1997 typedefs (inttypes.h)
+  AC_MSG_RESULT([(..)])
+  for i in m4_ifval([$1],[$1],[stdint.h inttypes.h sys/inttypes.h]) ; do
+   unset ac_cv_type_uintptr_t
+   unset ac_cv_type_uint64_t
+   AC_CHECK_TYPE(uintptr_t,[ac_cv_header_stdint_x=$i],continue,[#include <$i>])
+   AC_CHECK_TYPE(uint64_t,[and64="/uint64_t"],[and64=""],[#include<$i>])
+   m4_ifvaln([$1],[$1]) break
+  done
+  AC_MSG_CHECKING([for stdint uintptr_t])
+ ])
+])
+
+AC_DEFUN([AX_CHECK_HEADER_STDINT_O],[
+AC_CACHE_CHECK([for stdint uint32_t], [ac_cv_header_stdint_o],[
+ ac_cv_header_stdint_o="" # the 1995 typedefs (sys/inttypes.h)
+  AC_MSG_RESULT([(..)])
+  for i in m4_ifval([$1],[$1],[inttypes.h sys/inttypes.h stdint.h]) ; do
+   unset ac_cv_type_uint32_t
+   unset ac_cv_type_uint64_t
+   AC_CHECK_TYPE(uint32_t,[ac_cv_header_stdint_o=$i],continue,[#include <$i>])
+   AC_CHECK_TYPE(uint64_t,[and64="/uint64_t"],[and64=""],[#include<$i>])
+   m4_ifvaln([$1],[$1]) break
+   break;
+  done
+  AC_MSG_CHECKING([for stdint uint32_t])
+ ])
+])
+
+AC_DEFUN([AX_CHECK_HEADER_STDINT_U],[
+AC_CACHE_CHECK([for stdint u_int32_t], [ac_cv_header_stdint_u],[
+ ac_cv_header_stdint_u="" # the BSD typedefs (sys/types.h)
+  AC_MSG_RESULT([(..)])
+  for i in m4_ifval([$1],[$1],[sys/types.h inttypes.h sys/inttypes.h]) ; do
+   unset ac_cv_type_u_int32_t
+   unset ac_cv_type_u_int64_t
+   AC_CHECK_TYPE(u_int32_t,[ac_cv_header_stdint_u=$i],continue,[#include <$i>])
+   AC_CHECK_TYPE(u_int64_t,[and64="/u_int64_t"],[and64=""],[#include<$i>])
+   m4_ifvaln([$1],[$1]) break
+   break;
+  done
+  AC_MSG_CHECKING([for stdint u_int32_t])
+ ])
+])
+
+AC_DEFUN([AX_CREATE_STDINT_H],
+[# ------ AX CREATE STDINT H -------------------------------------
+AC_MSG_CHECKING([for stdint types])
+ac_stdint_h=`echo ifelse($1, , _stdint.h, $1)`
+# try to shortcircuit - if the default include path of the compiler
+# can find a "stdint.h" header then we assume that all compilers can.
+AC_CACHE_VAL([ac_cv_header_stdint_t],[
+old_CXXFLAGS="$CXXFLAGS" ; CXXFLAGS=""
+old_CPPFLAGS="$CPPFLAGS" ; CPPFLAGS=""
+old_CFLAGS="$CFLAGS"     ; CFLAGS=""
+AC_TRY_COMPILE([#include <stdint.h>],[int_least32_t v = 0;],
+[ac_cv_stdint_result="(assuming C99 compatible system)"
+ ac_cv_header_stdint_t="stdint.h"; ],
+[ac_cv_header_stdint_t=""])
+CXXFLAGS="$old_CXXFLAGS"
+CPPFLAGS="$old_CPPFLAGS"
+CFLAGS="$old_CFLAGS" ])
+
+v="... $ac_cv_header_stdint_h"
+if test "$ac_stdint_h" = "stdint.h" ; then
+ AC_MSG_RESULT([(are you sure you want them in ./stdint.h?)])
+elif test "$ac_stdint_h" = "inttypes.h" ; then
+ AC_MSG_RESULT([(are you sure you want them in ./inttypes.h?)])
+elif test "_$ac_cv_header_stdint_t" = "_" ; then
+ AC_MSG_RESULT([(putting them into $ac_stdint_h)$v])
+else
+ ac_cv_header_stdint="$ac_cv_header_stdint_t"
+ AC_MSG_RESULT([$ac_cv_header_stdint (shortcircuit)])
+fi
+
+if test "_$ac_cv_header_stdint_t" = "_" ; then # can not shortcircuit..
+
+dnl .....intro message done, now do a few system checks.....
+dnl btw, all old CHECK_TYPE macros do automatically "DEFINE" a type,
+dnl therefore we use the autoconf implementation detail CHECK_TYPE_NEW
+dnl instead that is triggered with 3 or more arguments (see types.m4)
+
+inttype_headers=`echo $2 | sed -e 's/,/ /g'`
+
+ac_cv_stdint_result="(no helpful system typedefs seen)"
+AX_CHECK_HEADER_STDINT_X(dnl
+   stdint.h inttypes.h sys/inttypes.h $inttype_headers,
+   ac_cv_stdint_result="(seen uintptr_t$and64 in $i)")
+
+if test "_$ac_cv_header_stdint_x" = "_" ; then
+AX_CHECK_HEADER_STDINT_O(dnl,
+   inttypes.h sys/inttypes.h stdint.h $inttype_headers,
+   ac_cv_stdint_result="(seen uint32_t$and64 in $i)")
+fi
+
+if test "_$ac_cv_header_stdint_x" = "_" ; then
+if test "_$ac_cv_header_stdint_o" = "_" ; then
+AX_CHECK_HEADER_STDINT_U(dnl,
+   sys/types.h inttypes.h sys/inttypes.h $inttype_headers,
+   ac_cv_stdint_result="(seen u_int32_t$and64 in $i)")
+fi fi
+
+dnl if there was no good C99 header file, do some typedef checks...
+if test "_$ac_cv_header_stdint_x" = "_" ; then
+   AC_MSG_CHECKING([for stdint datatype model])
+   AC_MSG_RESULT([(..)])
+   AX_CHECK_DATA_MODEL
+fi
+
+if test "_$ac_cv_header_stdint_x" != "_" ; then
+   ac_cv_header_stdint="$ac_cv_header_stdint_x"
+elif  test "_$ac_cv_header_stdint_o" != "_" ; then
+   ac_cv_header_stdint="$ac_cv_header_stdint_o"
+elif  test "_$ac_cv_header_stdint_u" != "_" ; then
+   ac_cv_header_stdint="$ac_cv_header_stdint_u"
+else
+   ac_cv_header_stdint="stddef.h"
+fi
+
+AC_MSG_CHECKING([for extra inttypes in chosen header])
+AC_MSG_RESULT([($ac_cv_header_stdint)])
+dnl see if int_least and int_fast types are present in _this_ header.
+unset ac_cv_type_int_least32_t
+unset ac_cv_type_int_fast32_t
+AC_CHECK_TYPE(int_least32_t,,,[#include <$ac_cv_header_stdint>])
+AC_CHECK_TYPE(int_fast32_t,,,[#include<$ac_cv_header_stdint>])
+AC_CHECK_TYPE(intmax_t,,,[#include <$ac_cv_header_stdint>])
+
+fi # shortcircut to system "stdint.h"
+# ------------------ PREPARE VARIABLES ------------------------------
+if test "$GCC" = "yes" ; then
+ac_cv_stdint_message="using gnu compiler "`$CC --version | head -1`
+else
+ac_cv_stdint_message="using $CC"
+fi
+
+AC_MSG_RESULT([make use of $ac_cv_header_stdint in $ac_stdint_h dnl
+$ac_cv_stdint_result])
+
+dnl -----------------------------------------------------------------
+# ----------------- DONE inttypes.h checks START header -------------
+AC_CONFIG_COMMANDS([$ac_stdint_h],[
+AC_MSG_NOTICE(creating $ac_stdint_h : $_ac_stdint_h)
+ac_stdint=$tmp/_stdint.h
+
+echo "#ifndef" $_ac_stdint_h >$ac_stdint
+echo "#define" $_ac_stdint_h "1" >>$ac_stdint
+echo "#ifndef" _GENERATED_STDINT_H >>$ac_stdint
+echo "#define" _GENERATED_STDINT_H '"'$PACKAGE $VERSION'"' >>$ac_stdint
+echo "/* generated $ac_cv_stdint_message */" >>$ac_stdint
+if test "_$ac_cv_header_stdint_t" != "_" ; then
+echo "#define _STDINT_HAVE_STDINT_H" "1" >>$ac_stdint
+echo "#include <stdint.h>" >>$ac_stdint
+echo "#endif" >>$ac_stdint
+echo "#endif" >>$ac_stdint
+else
+
+cat >>$ac_stdint <<STDINT_EOF
+
+/* ................... shortcircuit part ........................... */
+
+#if defined HAVE_STDINT_H || defined _STDINT_HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <stddef.h>
+
+/* .................... configured part ............................ */
+
+STDINT_EOF
+
+echo "/* whether we have a C99 compatible stdint header file */" >>$ac_stdint
+if test "_$ac_cv_header_stdint_x" != "_" ; then
+  ac_header="$ac_cv_header_stdint_x"
+  echo "#define _STDINT_HEADER_INTPTR" '"'"$ac_header"'"' >>$ac_stdint
+else
+  echo "/* #undef _STDINT_HEADER_INTPTR */" >>$ac_stdint
+fi
+
+echo "/* whether we have a C96 compatible inttypes header file */" >>$ac_stdint
+if  test "_$ac_cv_header_stdint_o" != "_" ; then
+  ac_header="$ac_cv_header_stdint_o"
+  echo "#define _STDINT_HEADER_UINT32" '"'"$ac_header"'"' >>$ac_stdint
+else
+  echo "/* #undef _STDINT_HEADER_UINT32 */" >>$ac_stdint
+fi
+
+echo "/* whether we have a BSD compatible inet types header */" >>$ac_stdint
+if  test "_$ac_cv_header_stdint_u" != "_" ; then
+  ac_header="$ac_cv_header_stdint_u"
+  echo "#define _STDINT_HEADER_U_INT32" '"'"$ac_header"'"' >>$ac_stdint
+else
+  echo "/* #undef _STDINT_HEADER_U_INT32 */" >>$ac_stdint
+fi
+
+echo "" >>$ac_stdint
+
+if test "_$ac_header" != "_" ; then if test "$ac_header" != "stddef.h" ; then
+  echo "#include <$ac_header>" >>$ac_stdint
+  echo "" >>$ac_stdint
+fi fi
+
+echo "/* which 64bit typedef has been found */" >>$ac_stdint
+if test "$ac_cv_type_uint64_t" = "yes" ; then
+echo "#define   _STDINT_HAVE_UINT64_T" "1"  >>$ac_stdint
+else
+echo "/* #undef _STDINT_HAVE_UINT64_T */" >>$ac_stdint
+fi
+if test "$ac_cv_type_u_int64_t" = "yes" ; then
+echo "#define   _STDINT_HAVE_U_INT64_T" "1"  >>$ac_stdint
+else
+echo "/* #undef _STDINT_HAVE_U_INT64_T */" >>$ac_stdint
+fi
+echo "" >>$ac_stdint
+
+echo "/* which type model has been detected */" >>$ac_stdint
+if test "_$ac_cv_char_data_model" != "_" ; then
+echo "#define   _STDINT_CHAR_MODEL" "$ac_cv_char_data_model" >>$ac_stdint
+echo "#define   _STDINT_LONG_MODEL" "$ac_cv_long_data_model" >>$ac_stdint
+else
+echo "/* #undef _STDINT_CHAR_MODEL // skipped */" >>$ac_stdint
+echo "/* #undef _STDINT_LONG_MODEL // skipped */" >>$ac_stdint
+fi
+echo "" >>$ac_stdint
+
+echo "/* whether int_least types were detected */" >>$ac_stdint
+if test "$ac_cv_type_int_least32_t" = "yes"; then
+echo "#define   _STDINT_HAVE_INT_LEAST32_T" "1"  >>$ac_stdint
+else
+echo "/* #undef _STDINT_HAVE_INT_LEAST32_T */" >>$ac_stdint
+fi
+echo "/* whether int_fast types were detected */" >>$ac_stdint
+if test "$ac_cv_type_int_fast32_t" = "yes"; then
+echo "#define   _STDINT_HAVE_INT_FAST32_T" "1" >>$ac_stdint
+else
+echo "/* #undef _STDINT_HAVE_INT_FAST32_T */" >>$ac_stdint
+fi
+echo "/* whether intmax_t type was detected */" >>$ac_stdint
+if test "$ac_cv_type_intmax_t" = "yes"; then
+echo "#define   _STDINT_HAVE_INTMAX_T" "1" >>$ac_stdint
+else
+echo "/* #undef _STDINT_HAVE_INTMAX_T */" >>$ac_stdint
+fi
+echo "" >>$ac_stdint
+
+  cat >>$ac_stdint <<STDINT_EOF
+/* .................... detections part ............................ */
+
+/* whether we need to define bitspecific types from compiler base types */
+#ifndef _STDINT_HEADER_INTPTR
+#ifndef _STDINT_HEADER_UINT32
+#ifndef _STDINT_HEADER_U_INT32
+#define _STDINT_NEED_INT_MODEL_T
+#else
+#define _STDINT_HAVE_U_INT_TYPES
+#endif
+#endif
+#endif
+
+#ifdef _STDINT_HAVE_U_INT_TYPES
+#undef _STDINT_NEED_INT_MODEL_T
+#endif
+
+#ifdef  _STDINT_CHAR_MODEL
+#if     _STDINT_CHAR_MODEL+0 == 122 || _STDINT_CHAR_MODEL+0 == 124
+#ifndef _STDINT_BYTE_MODEL
+#define _STDINT_BYTE_MODEL 12
+#endif
+#endif
+#endif
+
+#ifndef _STDINT_HAVE_INT_LEAST32_T
+#define _STDINT_NEED_INT_LEAST_T
+#endif
+
+#ifndef _STDINT_HAVE_INT_FAST32_T
+#define _STDINT_NEED_INT_FAST_T
+#endif
+
+#ifndef _STDINT_HEADER_INTPTR
+#define _STDINT_NEED_INTPTR_T
+#ifndef _STDINT_HAVE_INTMAX_T
+#define _STDINT_NEED_INTMAX_T
+#endif
+#endif
+
+
+/* .................... definition part ............................ */
+
+/* some system headers have good uint64_t */
+#ifndef _HAVE_UINT64_T
+#if     defined _STDINT_HAVE_UINT64_T  || defined HAVE_UINT64_T
+#define _HAVE_UINT64_T
+#elif   defined _STDINT_HAVE_U_INT64_T || defined HAVE_U_INT64_T
+#define _HAVE_UINT64_T
+typedef u_int64_t uint64_t;
+#endif
+#endif
+
+#ifndef _HAVE_UINT64_T
+/* .. here are some common heuristics using compiler runtime specifics */
+#if defined __STDC_VERSION__ && defined __STDC_VERSION__ >= 199901L
+#define _HAVE_UINT64_T
+#define _HAVE_LONGLONG_UINT64_T
+typedef long long int64_t;
+typedef unsigned long long uint64_t;
+
+#elif !defined __STRICT_ANSI__
+#if defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__
+#define _HAVE_UINT64_T
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+
+#elif defined __GNUC__ || defined __MWERKS__ || defined __ELF__
+/* note: all ELF-systems seem to have loff-support which needs 64-bit */
+#if !defined _NO_LONGLONG
+#define _HAVE_UINT64_T
+#define _HAVE_LONGLONG_UINT64_T
+typedef long long int64_t;
+typedef unsigned long long uint64_t;
+#endif
+
+#elif defined __alpha || (defined __mips && defined _ABIN32)
+#if !defined _NO_LONGLONG
+typedef long int64_t;
+typedef unsigned long uint64_t;
+#endif
+  /* compiler/cpu type to define int64_t */
+#endif
+#endif
+#endif
+
+#if defined _STDINT_HAVE_U_INT_TYPES
+/* int8_t int16_t int32_t defined by inet code, redeclare the u_intXX types */
+typedef u_int8_t uint8_t;
+typedef u_int16_t uint16_t;
+typedef u_int32_t uint32_t;
+
+/* glibc compatibility */
+#ifndef __int8_t_defined
+#define __int8_t_defined
+#endif
+#endif
+
+#ifdef _STDINT_NEED_INT_MODEL_T
+/* we must guess all the basic types. Apart from byte-adressable system, */
+/* there a few 32-bit-only dsp-systems that we guard with BYTE_MODEL 8-} */
+/* (btw, those nibble-addressable systems are way off, or so we assume) */
+
+dnl   /* have a look at "64bit and data size neutrality" at */
+dnl   /* http://unix.org/version2/whatsnew/login_64bit.html */
+dnl   /* (the shorthand "ILP" types always have a "P" part) */
+
+#if defined _STDINT_BYTE_MODEL
+#if _STDINT_LONG_MODEL+0 == 242
+/* 2:4:2 =  IP16 = a normal 16-bit system                */
+typedef unsigned char   uint8_t;
+typedef unsigned short  uint16_t;
+typedef unsigned long   uint32_t;
+#ifndef __int8_t_defined
+#define __int8_t_defined
+typedef          char    int8_t;
+typedef          short   int16_t;
+typedef          long    int32_t;
+#endif
+#elif _STDINT_LONG_MODEL+0 == 244 || _STDINT_LONG_MODEL == 444
+/* 2:4:4 =  LP32 = a 32-bit system derived from a 16-bit */
+/* 4:4:4 = ILP32 = a normal 32-bit system                */
+typedef unsigned char   uint8_t;
+typedef unsigned short  uint16_t;
+typedef unsigned int    uint32_t;
+#ifndef __int8_t_defined
+#define __int8_t_defined
+typedef          char    int8_t;
+typedef          short   int16_t;
+typedef          int     int32_t;
+#endif
+#elif _STDINT_LONG_MODEL+0 == 484 || _STDINT_LONG_MODEL+0 == 488
+/* 4:8:4 =  IP32 = a 32-bit system prepared for 64-bit    */
+/* 4:8:8 =  LP64 = a normal 64-bit system                 */
+typedef unsigned char   uint8_t;
+typedef unsigned short  uint16_t;
+typedef unsigned int    uint32_t;
+#ifndef __int8_t_defined
+#define __int8_t_defined
+typedef          char    int8_t;
+typedef          short   int16_t;
+typedef          int     int32_t;
+#endif
+/* this system has a "long" of 64bit */
+#ifndef _HAVE_UINT64_T
+#define _HAVE_UINT64_T
+typedef unsigned long   uint64_t;
+typedef          long    int64_t;
+#endif
+#elif _STDINT_LONG_MODEL+0 == 448
+/*      LLP64   a 64-bit system derived from a 32-bit system */
+typedef unsigned char   uint8_t;
+typedef unsigned short  uint16_t;
+typedef unsigned int    uint32_t;
+#ifndef __int8_t_defined
+#define __int8_t_defined
+typedef          char    int8_t;
+typedef          short   int16_t;
+typedef          int     int32_t;
+#endif
+/* assuming the system has a "long long" */
+#ifndef _HAVE_UINT64_T
+#define _HAVE_UINT64_T
+#define _HAVE_LONGLONG_UINT64_T
+typedef unsigned long long uint64_t;
+typedef          long long  int64_t;
+#endif
+#else
+#define _STDINT_NO_INT32_T
+#endif
+#else
+#define _STDINT_NO_INT8_T
+#define _STDINT_NO_INT32_T
+#endif
+#endif
+
+/*
+ * quote from SunOS-5.8 sys/inttypes.h:
+ * Use at your own risk.  As of February 1996, the committee is squarely
+ * behind the fixed sized types; the "least" and "fast" types are still being
+ * discussed.  The probability that the "fast" types may be removed before
+ * the standard is finalized is high enough that they are not currently
+ * implemented.
+ */
+
+#if defined _STDINT_NEED_INT_LEAST_T
+typedef  int8_t    int_least8_t;
+typedef  int16_t   int_least16_t;
+typedef  int32_t   int_least32_t;
+#ifdef _HAVE_UINT64_T
+typedef  int64_t   int_least64_t;
+#endif
+
+typedef uint8_t   uint_least8_t;
+typedef uint16_t  uint_least16_t;
+typedef uint32_t  uint_least32_t;
+#ifdef _HAVE_UINT64_T
+typedef uint64_t  uint_least64_t;
+#endif
+  /* least types */
+#endif
+
+#if defined _STDINT_NEED_INT_FAST_T
+typedef  int8_t    int_fast8_t;
+typedef  int       int_fast16_t;
+typedef  int32_t   int_fast32_t;
+#ifdef _HAVE_UINT64_T
+typedef  int64_t   int_fast64_t;
+#endif
+
+typedef uint8_t   uint_fast8_t;
+typedef unsigned  uint_fast16_t;
+typedef uint32_t  uint_fast32_t;
+#ifdef _HAVE_UINT64_T
+typedef uint64_t  uint_fast64_t;
+#endif
+  /* fast types */
+#endif
+
+#ifdef _STDINT_NEED_INTMAX_T
+#ifdef _HAVE_UINT64_T
+typedef  int64_t       intmax_t;
+typedef uint64_t      uintmax_t;
+#else
+typedef          long  intmax_t;
+typedef unsigned long uintmax_t;
+#endif
+#endif
+
+#ifdef _STDINT_NEED_INTPTR_T
+#ifndef __intptr_t_defined
+#define __intptr_t_defined
+/* we encourage using "long" to store pointer values, never use "int" ! */
+#if   _STDINT_LONG_MODEL+0 == 242 || _STDINT_LONG_MODEL+0 == 484
+typedef  unsinged int   uintptr_t;
+typedef           int    intptr_t;
+#elif _STDINT_LONG_MODEL+0 == 244 || _STDINT_LONG_MODEL+0 == 444
+typedef  unsigned long  uintptr_t;
+typedef           long   intptr_t;
+#elif _STDINT_LONG_MODEL+0 == 448 && defined _HAVE_UINT64_T
+typedef        uint64_t uintptr_t;
+typedef         int64_t  intptr_t;
+#else /* matches typical system types ILP32 and LP64 - but not IP16 or LLP64 */
+typedef  unsigned long  uintptr_t;
+typedef           long   intptr_t;
+#endif
+#endif
+#endif
+
+/* The ISO C99 standard specifies that in C++ implementations these
+   should only be defined if explicitly requested.  */
+#if !defined __cplusplus || defined __STDC_CONSTANT_MACROS
+#ifndef UINT32_C
+
+/* Signed.  */
+# define INT8_C(c)      c
+# define INT16_C(c)     c
+# define INT32_C(c)     c
+# ifdef _HAVE_LONGLONG_UINT64_T
+#  define INT64_C(c)    c ## L
+# else
+#  define INT64_C(c)    c ## LL
+# endif
+
+/* Unsigned.  */
+# define UINT8_C(c)     c ## U
+# define UINT16_C(c)    c ## U
+# define UINT32_C(c)    c ## U
+# ifdef _HAVE_LONGLONG_UINT64_T
+#  define UINT64_C(c)   c ## UL
+# else
+#  define UINT64_C(c)   c ## ULL
+# endif
+
+/* Maximal type.  */
+# ifdef _HAVE_LONGLONG_UINT64_T
+#  define INTMAX_C(c)   c ## L
+#  define UINTMAX_C(c)  c ## UL
+# else
+#  define INTMAX_C(c)   c ## LL
+#  define UINTMAX_C(c)  c ## ULL
+# endif
+
+  /* literalnumbers */
+#endif
+#endif
+
+/* These limits are merily those of a two complement byte-oriented system */
+
+/* Minimum of signed integral types.  */
+# define INT8_MIN               (-128)
+# define INT16_MIN              (-32767-1)
+# define INT32_MIN              (-2147483647-1)
+# define INT64_MIN              (-__INT64_C(9223372036854775807)-1)
+/* Maximum of signed integral types.  */
+# define INT8_MAX               (127)
+# define INT16_MAX              (32767)
+# define INT32_MAX              (2147483647)
+# define INT64_MAX              (__INT64_C(9223372036854775807))
+
+/* Maximum of unsigned integral types.  */
+# define UINT8_MAX              (255)
+# define UINT16_MAX             (65535)
+# define UINT32_MAX             (4294967295U)
+# define UINT64_MAX             (__UINT64_C(18446744073709551615))
+
+/* Minimum of signed integral types having a minimum size.  */
+# define INT_LEAST8_MIN         INT8_MIN
+# define INT_LEAST16_MIN        INT16_MIN
+# define INT_LEAST32_MIN        INT32_MIN
+# define INT_LEAST64_MIN        INT64_MIN
+/* Maximum of signed integral types having a minimum size.  */
+# define INT_LEAST8_MAX         INT8_MAX
+# define INT_LEAST16_MAX        INT16_MAX
+# define INT_LEAST32_MAX        INT32_MAX
+# define INT_LEAST64_MAX        INT64_MAX
+
+/* Maximum of unsigned integral types having a minimum size.  */
+# define UINT_LEAST8_MAX        UINT8_MAX
+# define UINT_LEAST16_MAX       UINT16_MAX
+# define UINT_LEAST32_MAX       UINT32_MAX
+# define UINT_LEAST64_MAX       UINT64_MAX
+
+  /* shortcircuit*/
+#endif
+  /* once */
+#endif
+#endif
+STDINT_EOF
+fi
+    if cmp -s $ac_stdint_h $ac_stdint 2>/dev/null; then
+      AC_MSG_NOTICE([$ac_stdint_h is unchanged])
+    else
+      ac_dir=`AS_DIRNAME(["$ac_stdint_h"])`
+      AS_MKDIR_P(["$ac_dir"])
+      rm -f $ac_stdint_h
+      mv $ac_stdint $ac_stdint_h
+    fi
+],[# variables for create stdint.h replacement
+PACKAGE="$PACKAGE"
+VERSION="$VERSION"
+ac_stdint_h="$ac_stdint_h"
+_ac_stdint_h=AS_TR_CPP(_$PACKAGE-$ac_stdint_h)
+ac_cv_stdint_message="$ac_cv_stdint_message"
+ac_cv_header_stdint_t="$ac_cv_header_stdint_t"
+ac_cv_header_stdint_x="$ac_cv_header_stdint_x"
+ac_cv_header_stdint_o="$ac_cv_header_stdint_o"
+ac_cv_header_stdint_u="$ac_cv_header_stdint_u"
+ac_cv_type_uint64_t="$ac_cv_type_uint64_t"
+ac_cv_type_u_int64_t="$ac_cv_type_u_int64_t"
+ac_cv_char_data_model="$ac_cv_char_data_model"
+ac_cv_long_data_model="$ac_cv_long_data_model"
+ac_cv_type_int_least32_t="$ac_cv_type_int_least32_t"
+ac_cv_type_int_fast32_t="$ac_cv_type_int_fast32_t"
+ac_cv_type_intmax_t="$ac_cv_type_intmax_t"
+])
+])
diff --git a/missing b/missing
new file mode 100755
index 0000000..28055d2
--- /dev/null
+++ b/missing
@@ -0,0 +1,376 @@
+#! /bin/sh
+# Common stub for a few missing GNU programs while installing.
+
+scriptversion=2009-04-28.21; # UTC
+
+# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
+# 2008, 2009 Free Software Foundation, Inc.
+# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program 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 General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+if test $# -eq 0; then
+  echo 1>&2 "Try \`$0 --help' for more information"
+  exit 1
+fi
+
+run=:
+sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
+sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
+
+# In the cases where this matters, `missing' is being run in the
+# srcdir already.
+if test -f configure.ac; then
+  configure_ac=configure.ac
+else
+  configure_ac=configure.in
+fi
+
+msg="missing on your system"
+
+case $1 in
+--run)
+  # Try to run requested program, and just exit if it succeeds.
+  run=
+  shift
+  "$@" && exit 0
+  # Exit code 63 means version mismatch.  This often happens
+  # when the user try to use an ancient version of a tool on
+  # a file that requires a minimum version.  In this case we
+  # we should proceed has if the program had been absent, or
+  # if --run hadn't been passed.
+  if test $? = 63; then
+    run=:
+    msg="probably too old"
+  fi
+  ;;
+
+  -h|--h|--he|--hel|--help)
+    echo "\
+$0 [OPTION]... PROGRAM [ARGUMENT]...
+
+Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
+error status if there is no known handling for PROGRAM.
+
+Options:
+  -h, --help      display this help and exit
+  -v, --version   output version information and exit
+  --run           try to run the given command, and emulate it if it fails
+
+Supported PROGRAM values:
+  aclocal      touch file \`aclocal.m4'
+  autoconf     touch file \`configure'
+  autoheader   touch file \`config.h.in'
+  autom4te     touch the output file, or create a stub one
+  automake     touch all \`Makefile.in' files
+  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
+  flex         create \`lex.yy.c', if possible, from existing .c
+  help2man     touch the output file
+  lex          create \`lex.yy.c', if possible, from existing .c
+  makeinfo     touch the output file
+  tar          try tar, gnutar, gtar, then tar without non-portable flags
+  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
+
+Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
+\`g' are ignored when checking the name.
+
+Send bug reports to <bug-automake@gnu.org>."
+    exit $?
+    ;;
+
+  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
+    echo "missing $scriptversion (GNU Automake)"
+    exit $?
+    ;;
+
+  -*)
+    echo 1>&2 "$0: Unknown \`$1' option"
+    echo 1>&2 "Try \`$0 --help' for more information"
+    exit 1
+    ;;
+
+esac
+
+# normalize program name to check for.
+program=`echo "$1" | sed '
+  s/^gnu-//; t
+  s/^gnu//; t
+  s/^g//; t'`
+
+# Now exit if we have it, but it failed.  Also exit now if we
+# don't have it and --version was passed (most likely to detect
+# the program).  This is about non-GNU programs, so use $1 not
+# $program.
+case $1 in
+  lex*|yacc*)
+    # Not GNU programs, they don't have --version.
+    ;;
+
+  tar*)
+    if test -n "$run"; then
+       echo 1>&2 "ERROR: \`tar' requires --run"
+       exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       exit 1
+    fi
+    ;;
+
+  *)
+    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
+       # We have it, but it failed.
+       exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       # Could not run --version or --help.  This is probably someone
+       # running `$TOOL --version' or `$TOOL --help' to check whether
+       # $TOOL exists and not knowing $TOOL uses missing.
+       exit 1
+    fi
+    ;;
+esac
+
+# If it does not exist, or fails to run (possibly an outdated version),
+# try to emulate it.
+case $program in
+  aclocal*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
+         to install the \`Automake' and \`Perl' packages.  Grab them from
+         any GNU archive site."
+    touch aclocal.m4
+    ;;
+
+  autoconf*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`${configure_ac}'.  You might want to install the
+         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
+         archive site."
+    touch configure
+    ;;
+
+  autoheader*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`acconfig.h' or \`${configure_ac}'.  You might want
+         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
+         from any GNU archive site."
+    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
+    test -z "$files" && files="config.h"
+    touch_files=
+    for f in $files; do
+      case $f in
+      *:*) touch_files="$touch_files "`echo "$f" |
+				       sed -e 's/^[^:]*://' -e 's/:.*//'`;;
+      *) touch_files="$touch_files $f.in";;
+      esac
+    done
+    touch $touch_files
+    ;;
+
+  automake*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
+         You might want to install the \`Automake' and \`Perl' packages.
+         Grab them from any GNU archive site."
+    find . -type f -name Makefile.am -print |
+	   sed 's/\.am$/.in/' |
+	   while read f; do touch "$f"; done
+    ;;
+
+  autom4te*)
+    echo 1>&2 "\
+WARNING: \`$1' is needed, but is $msg.
+         You might have modified some files without having the
+         proper tools for further handling them.
+         You can get \`$1' as part of \`Autoconf' from any GNU
+         archive site."
+
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -f "$file"; then
+	touch $file
+    else
+	test -z "$file" || exec >$file
+	echo "#! /bin/sh"
+	echo "# Created by GNU Automake missing as a replacement of"
+	echo "#  $ $@"
+	echo "exit 0"
+	chmod +x $file
+	exit 1
+    fi
+    ;;
+
+  bison*|yacc*)
+    echo 1>&2 "\
+WARNING: \`$1' $msg.  You should only need it if
+         you modified a \`.y' file.  You may need the \`Bison' package
+         in order for those modifications to take effect.  You can get
+         \`Bison' from any GNU archive site."
+    rm -f y.tab.c y.tab.h
+    if test $# -ne 1; then
+        eval LASTARG="\${$#}"
+	case $LASTARG in
+	*.y)
+	    SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
+	    if test -f "$SRCFILE"; then
+	         cp "$SRCFILE" y.tab.c
+	    fi
+	    SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
+	    if test -f "$SRCFILE"; then
+	         cp "$SRCFILE" y.tab.h
+	    fi
+	  ;;
+	esac
+    fi
+    if test ! -f y.tab.h; then
+	echo >y.tab.h
+    fi
+    if test ! -f y.tab.c; then
+	echo 'main() { return 0; }' >y.tab.c
+    fi
+    ;;
+
+  lex*|flex*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified a \`.l' file.  You may need the \`Flex' package
+         in order for those modifications to take effect.  You can get
+         \`Flex' from any GNU archive site."
+    rm -f lex.yy.c
+    if test $# -ne 1; then
+        eval LASTARG="\${$#}"
+	case $LASTARG in
+	*.l)
+	    SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
+	    if test -f "$SRCFILE"; then
+	         cp "$SRCFILE" lex.yy.c
+	    fi
+	  ;;
+	esac
+    fi
+    if test ! -f lex.yy.c; then
+	echo 'main() { return 0; }' >lex.yy.c
+    fi
+    ;;
+
+  help2man*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+	 you modified a dependency of a manual page.  You may need the
+	 \`Help2man' package in order for those modifications to take
+	 effect.  You can get \`Help2man' from any GNU archive site."
+
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -f "$file"; then
+	touch $file
+    else
+	test -z "$file" || exec >$file
+	echo ".ab help2man is required to generate this page"
+	exit $?
+    fi
+    ;;
+
+  makeinfo*)
+    echo 1>&2 "\
+WARNING: \`$1' is $msg.  You should only need it if
+         you modified a \`.texi' or \`.texinfo' file, or any other file
+         indirectly affecting the aspect of the manual.  The spurious
+         call might also be the consequence of using a buggy \`make' (AIX,
+         DU, IRIX).  You might want to install the \`Texinfo' package or
+         the \`GNU make' package.  Grab either from any GNU archive site."
+    # The file to touch is that specified with -o ...
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -z "$file"; then
+      # ... or it is the one specified with @setfilename ...
+      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
+      file=`sed -n '
+	/^@setfilename/{
+	  s/.* \([^ ]*\) *$/\1/
+	  p
+	  q
+	}' $infile`
+      # ... or it is derived from the source name (dir/f.texi becomes f.info)
+      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
+    fi
+    # If the file does not exist, the user really needs makeinfo;
+    # let's fail without touching anything.
+    test -f $file || exit 1
+    touch $file
+    ;;
+
+  tar*)
+    shift
+
+    # We have already tried tar in the generic part.
+    # Look for gnutar/gtar before invocation to avoid ugly error
+    # messages.
+    if (gnutar --version > /dev/null 2>&1); then
+       gnutar "$@" && exit 0
+    fi
+    if (gtar --version > /dev/null 2>&1); then
+       gtar "$@" && exit 0
+    fi
+    firstarg="$1"
+    if shift; then
+	case $firstarg in
+	*o*)
+	    firstarg=`echo "$firstarg" | sed s/o//`
+	    tar "$firstarg" "$@" && exit 0
+	    ;;
+	esac
+	case $firstarg in
+	*h*)
+	    firstarg=`echo "$firstarg" | sed s/h//`
+	    tar "$firstarg" "$@" && exit 0
+	    ;;
+	esac
+    fi
+
+    echo 1>&2 "\
+WARNING: I can't seem to be able to run \`tar' with the given arguments.
+         You may want to install GNU tar or Free paxutils, or check the
+         command line arguments."
+    exit 1
+    ;;
+
+  *)
+    echo 1>&2 "\
+WARNING: \`$1' is needed, and is $msg.
+         You might have modified some files without having the
+         proper tools for further handling them.  Check the \`README' file,
+         it often tells you about the needed prerequisites for installing
+         this package.  You may also peek at any GNU archive site, in case
+         some other package would contain this missing \`$1' program."
+    exit 1
+    ;;
+esac
+
+exit 0
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..bd10139
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,61 @@
+lib_LTLIBRARIES=libmtp.la
+libmtp_la_SOURCES=libmtp.c unicode.c unicode.h util.c util.h playlist-spl.c \
+	libusb-glue.c libusb-glue.h \
+	gphoto2-endian.h libptp-stdint.h ptp.c ptp.h \
+	music-players.h device-flags.h playlist-spl.h
+include_HEADERS=libmtp.h
+EXTRA_DIST=libmtp.h.in libmtp.sym ptp-pack.c
+
+# ---------------------------------------------------------------------------
+# Advanced information about versioning:
+#   * "Writing shared libraries" by Mike Hearn
+#         http://navi.cx/~mike/writing-shared-libraries.html
+#   * libtool.info chapter "Versioning"
+#   * libtool.info chapter "Updating library version information"
+# ---------------------------------------------------------------------------
+# Versioning:
+#  - CURRENT (Major):  Increment if the interface has changes. AGE is always
+#                      *changed* at the same time.
+#  - AGE (Micro):      Increment if any interfaces have been added; set to 0
+#		         if any interfaces have been removed. Removal has
+#                      precedence over adding, so set to 0 if both happened.
+#                      It denotes upward compatibility.
+#  - REVISION (Minor): Increment any time the source changes; set to
+#			 0 if you incremented CURRENT.
+#
+#  To summarize. Any interface *change* increment CURRENT. If that interface
+#  change does not break upward compatibility (ie it is an addition),
+#  increment AGE, Otherwise AGE is reset to 0. If CURRENT has changed,
+#  REVISION is set to 0, otherwise REVISION is incremented.
+# ---------------------------------------------------------------------------
+CURRENT=11
+AGE=3
+REVISION=1
+SOVERSION=$(CURRENT):$(REVISION):$(AGE)
+LT_CURRENT_MINUS_AGE=`expr $(CURRENT) - $(AGE)`
+
+if COMPILE_MINGW32
+W32_LIBS=-lws2_32
+W32_LDFLAGS=-export-dynamic
+if MS_LIB_EXE
+noinst_DATA=libmtp.lib
+libmtp.def: $(srcdir)/libmtp.sym
+	echo "LIBRARY \"@PACKAGE@\"" > libmtp.def
+	echo "DESCRIPTION \"Media Transfer Protocol (MTP) library\"" >> libmtp.def
+	echo "VERSION @VERSION@" >> libmtp.def
+	echo >> libmtp.def
+	echo "EXPORTS" >> libmtp.def
+	cat $< >> libmtp.def
+libmtp.lib: libmtp.la libmtp.def
+	lib -name:libmtp-$(LT_CURRENT_MINUS_AGE).dll -def:libmtp.def -out:$@
+install-data-local: libmtp.lib libmtp.def
+	$(INSTALL) libmtp.def $(DESTDIR)$(libdir)
+	$(INSTALL) libmtp.lib $(DESTDIR)$(libdir)
+endif
+endif
+
+libmtp_la_LDFLAGS=@LDFLAGS@ -no-undefined -export-symbols $(srcdir)/libmtp.sym -version-info $(SOVERSION) $(W32_LDFLAGS)
+libmtp_la_LIBADD=$(W32_LIBS) $(LTLIBICONV)
+libmtp_la_DEPENDENCIES=$(srcdir)/libmtp.sym
+
+DISTCLEANFILES = _stdint.h
diff --git a/src/Makefile.in b/src/Makefile.in
new file mode 100644
index 0000000..3b294c0
--- /dev/null
+++ b/src/Makefile.in
@@ -0,0 +1,616 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = src
+DIST_COMMON = README $(include_HEADERS) $(srcdir)/Makefile.am \
+	$(srcdir)/Makefile.in $(srcdir)/libmtp.h.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/byteorder.m4 \
+	$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+	$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+	$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/stdint.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES = libmtp.h
+CONFIG_CLEAN_VPATH_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"
+LTLIBRARIES = $(lib_LTLIBRARIES)
+am__DEPENDENCIES_1 =
+am_libmtp_la_OBJECTS = libmtp.lo unicode.lo util.lo playlist-spl.lo \
+	libusb-glue.lo ptp.lo
+libmtp_la_OBJECTS = $(am_libmtp_la_OBJECTS)
+libmtp_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(libmtp_la_LDFLAGS) $(LDFLAGS) -o $@
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(libmtp_la_SOURCES)
+DIST_SOURCES = $(libmtp_la_SOURCES)
+DATA = $(noinst_DATA)
+HEADERS = $(include_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AS = @AS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+HAVE_DOXYGEN = @HAVE_DOXYGEN@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBICONV = @LIBICONV@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBICONV = @LTLIBICONV@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OSFLAGS = @OSFLAGS@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+effective_target = @effective_target@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+ms_lib_exe = @ms_lib_exe@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+lib_LTLIBRARIES = libmtp.la
+libmtp_la_SOURCES = libmtp.c unicode.c unicode.h util.c util.h playlist-spl.c \
+	libusb-glue.c libusb-glue.h \
+	gphoto2-endian.h libptp-stdint.h ptp.c ptp.h \
+	music-players.h device-flags.h playlist-spl.h
+
+include_HEADERS = libmtp.h
+EXTRA_DIST = libmtp.h.in libmtp.sym ptp-pack.c
+
+# ---------------------------------------------------------------------------
+# Advanced information about versioning:
+#   * "Writing shared libraries" by Mike Hearn
+#         http://navi.cx/~mike/writing-shared-libraries.html
+#   * libtool.info chapter "Versioning"
+#   * libtool.info chapter "Updating library version information"
+# ---------------------------------------------------------------------------
+# Versioning:
+#  - CURRENT (Major):  Increment if the interface has changes. AGE is always
+#                      *changed* at the same time.
+#  - AGE (Micro):      Increment if any interfaces have been added; set to 0
+#		         if any interfaces have been removed. Removal has
+#                      precedence over adding, so set to 0 if both happened.
+#                      It denotes upward compatibility.
+#  - REVISION (Minor): Increment any time the source changes; set to
+#			 0 if you incremented CURRENT.
+#
+#  To summarize. Any interface *change* increment CURRENT. If that interface
+#  change does not break upward compatibility (ie it is an addition),
+#  increment AGE, Otherwise AGE is reset to 0. If CURRENT has changed,
+#  REVISION is set to 0, otherwise REVISION is incremented.
+# ---------------------------------------------------------------------------
+CURRENT = 11
+AGE = 3
+REVISION = 1
+SOVERSION = $(CURRENT):$(REVISION):$(AGE)
+LT_CURRENT_MINUS_AGE = `expr $(CURRENT) - $(AGE)`
+@COMPILE_MINGW32_TRUE@W32_LIBS = -lws2_32
+@COMPILE_MINGW32_TRUE@W32_LDFLAGS = -export-dynamic
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@noinst_DATA = libmtp.lib
+libmtp_la_LDFLAGS = @LDFLAGS@ -no-undefined -export-symbols $(srcdir)/libmtp.sym -version-info $(SOVERSION) $(W32_LDFLAGS)
+libmtp_la_LIBADD = $(W32_LIBS) $(LTLIBICONV)
+libmtp_la_DEPENDENCIES = $(srcdir)/libmtp.sym
+DISTCLEANFILES = _stdint.h
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign src/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+libmtp.h: $(top_builddir)/config.status $(srcdir)/libmtp.h.in
+	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
+install-libLTLIBRARIES: $(lib_LTLIBRARIES)
+	@$(NORMAL_INSTALL)
+	test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
+	@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+	list2=; for p in $$list; do \
+	  if test -f $$p; then \
+	    list2="$$list2 $$p"; \
+	  else :; fi; \
+	done; \
+	test -z "$$list2" || { \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
+	}
+
+uninstall-libLTLIBRARIES:
+	@$(NORMAL_UNINSTALL)
+	@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
+	for p in $$list; do \
+	  $(am__strip_dir) \
+	  echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
+	  $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
+	done
+
+clean-libLTLIBRARIES:
+	-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
+	@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+	  dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+	  test "$$dir" != "$$p" || dir=.; \
+	  echo "rm -f \"$${dir}/so_locations\""; \
+	  rm -f "$${dir}/so_locations"; \
+	done
+libmtp.la: $(libmtp_la_OBJECTS) $(libmtp_la_DEPENDENCIES) 
+	$(libmtp_la_LINK) -rpath $(libdir) $(libmtp_la_OBJECTS) $(libmtp_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmtp.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libusb-glue.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/playlist-spl.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ptp.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unicode.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+install-includeHEADERS: $(include_HEADERS)
+	@$(NORMAL_INSTALL)
+	test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)"
+	@list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
+	for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  echo "$$d$$p"; \
+	done | $(am__base_list) | \
+	while read files; do \
+	  echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \
+	  $(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \
+	done
+
+uninstall-includeHEADERS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
+	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+	test -n "$$files" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(includedir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(includedir)" && rm -f $$files
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES) $(DATA) $(HEADERS)
+installdirs:
+	for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+	-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+@COMPILE_MINGW32_FALSE@install-data-local:
+@MS_LIB_EXE_FALSE@install-data-local:
+clean: clean-am
+
+clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
+	mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-data-local install-includeHEADERS
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-libLTLIBRARIES
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+	clean-libLTLIBRARIES clean-libtool ctags distclean \
+	distclean-compile distclean-generic distclean-libtool \
+	distclean-tags distdir dvi dvi-am html html-am info info-am \
+	install install-am install-data install-data-am \
+	install-data-local install-dvi install-dvi-am install-exec \
+	install-exec-am install-html install-html-am \
+	install-includeHEADERS install-info install-info-am \
+	install-libLTLIBRARIES install-man install-pdf install-pdf-am \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am uninstall-includeHEADERS \
+	uninstall-libLTLIBRARIES
+
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@libmtp.def: $(srcdir)/libmtp.sym
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@	echo "LIBRARY \"@PACKAGE@\"" > libmtp.def
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@	echo "DESCRIPTION \"Media Transfer Protocol (MTP) library\"" >> libmtp.def
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@	echo "VERSION @VERSION@" >> libmtp.def
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@	echo >> libmtp.def
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@	echo "EXPORTS" >> libmtp.def
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@	cat $< >> libmtp.def
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@libmtp.lib: libmtp.la libmtp.def
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@	lib -name:libmtp-$(LT_CURRENT_MINUS_AGE).dll -def:libmtp.def -out:$@
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@install-data-local: libmtp.lib libmtp.def
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@	$(INSTALL) libmtp.def $(DESTDIR)$(libdir)
+@COMPILE_MINGW32_TRUE@@MS_LIB_EXE_TRUE@	$(INSTALL) libmtp.lib $(DESTDIR)$(libdir)
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/README b/src/README
new file mode 100644
index 0000000..d7e0f3a
--- /dev/null
+++ b/src/README
@@ -0,0 +1,25 @@
+RELATION TO LIBPTP2
+-------------------
+
+Parts of libptp2 are copied (and modified) from version 1.1.0:
+
+ptp-pack.c
+ptp-pack.h
+ptp.c
+ptp.h
+
+These are just copies of the same files from libptp2.
+In order to avoid clashes with the libptp2 endianness scripts
+we have named libptp-endian.h and libptp-stdint.h the
+same way as in libptp2, though they are created by libmtp
+autoconfigure scripts.
+
+We will try to track libptp2 and fold changes back into
+libmtp.
+
+TODO: check if the following still holds! (Linus)
+
+I have changed the config script slightly for the le64atoh function 
+in libptp-endian.h. This is required for OS X on PowerPC (not sure why). 
+I've just cast the bytes to uint64_t to avoid shifting wrongly.
+
diff --git a/src/device-flags.h b/src/device-flags.h
new file mode 100644
index 0000000..1b842c0
--- /dev/null
+++ b/src/device-flags.h
@@ -0,0 +1,247 @@
+/**
+ * \file device-flags.h
+ * Special device flags to deal with bugs in specific devices.
+ *
+ * Copyright (C) 2005-2007 Richard A. Low <richard@wentnet.com>
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006-2007 Marcus Meissner
+ * Copyright (C) 2007 Ted Bullock
+ *
+ * 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.
+ *
+ * This file is supposed to be included by both libmtp and libgphoto2.
+ */
+
+/**
+ * These flags are used to indicate if some or other
+ * device need special treatment. These should be possible
+ * to concatenate using logical OR so please use one bit per
+ * feature and lets pray we don't need more than 32 bits...
+ */
+#define DEVICE_FLAG_NONE 0x00000000
+/**
+ * This means that the PTP_OC_MTP_GetObjPropList is broken
+ * in the sense that it won't return properly formatted metadata
+ * for ALL files on the device when you request an object 
+ * property list for object 0xFFFFFFFF with parameter 3 likewise
+ * set to 0xFFFFFFFF. Compare to 
+ * DEVICE_FLAG_BROKEN_MTPGETOBJECTPROPLIST which only signify
+ * that it's broken when getting metadata for a SINGLE object.
+ * A typical way the implementation may be broken is that it 
+ * may not return a proper count of the objects, and sometimes
+ * (like on the ZENs) objects are simply missing from the list
+ * if you use this. Sometimes it has been used incorrectly to
+ * mask bugs in the code (like handling transactions of data
+ * with size given to -1 (0xFFFFFFFFU), in that case please
+ * help us remove it now the code is fixed. Sometimes this is
+ * used because getting all the objects is just too slow and
+ * the USB transaction will time out if you use this command.
+ */
+#define DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL 0x00000001
+/**
+ * This means that under Linux, another kernel module may 
+ * be using this device's USB interface, so we need to detach 
+ * it if it is. Typically this is on dual-mode devices that
+ * will present both an MTP compliant interface and device
+ * descriptor *and* a USB mass storage interface. If the USB
+ * mass storage interface is in use, other apps (like our
+ * userspace libmtp through libusb access path) cannot get in
+ * and get cosy with it. So we can remove the offending 
+ * application. Typically this means you have to run the program
+ * as root as well.
+ */
+#define DEVICE_FLAG_UNLOAD_DRIVER 0x00000002
+/**
+ * This means that the PTP_OC_MTP_GetObjPropList is broken and
+ * won't properly return all object properties if parameter 3
+ * is set to 0xFFFFFFFFU.
+ */
+#define DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST 0x00000004
+/**
+ * This means the device doesn't send zero packets to indicate
+ * end of transfer when the transfer boundary occurs at a 
+ * multiple of 64 bytes (the USB 1.1 endpoint size). Instead, 
+ * exactly one extra byte is sent at the end of the transfer 
+ * if the size is an integer multiple of USB 1.1 endpoint size 
+ * (64 bytes).
+ *
+ * This behaviour is most probably a workaround due to the fact 
+ * that the hardware USB slave controller in the device cannot 
+ * handle zero writes at all, and the usage of the USB 1.1 
+ * endpoint size is due to the fact that the device will "gear 
+ * down" on a USB 1.1 hub, and since 64 bytes is a multiple of 
+ * 512 bytes, it will work with USB 1.1 and USB 2.0 alike.
+ */
+#define DEVICE_FLAG_NO_ZERO_READS 0x00000008
+/**
+ * This flag means that the device is prone to forgetting the
+ * OGG container file type, so that libmtp must look at the
+ * filename extensions in order to determine that a file is
+ * actually OGG. This is a clear and present firmware bug, and
+ * while firmware bugs should be fixed in firmware, we like
+ * OGG so much that we back it by introducing this flag.
+ * The error has only been seen on iriver devices. Turning this
+ * flag on won't hurt anything, just that the check against
+ * filename extension will be done for files of "unknown" type.
+ * If the player does not even know (reports) that it supports
+ * ogg even though it does, please use the stronger 
+ * OGG_IS_UNKNOWN flag, which will forcedly support ogg on
+ * anything with the .ogg filename extension.
+ */
+#define DEVICE_FLAG_IRIVER_OGG_ALZHEIMER 0x00000010
+/**
+ * This flag indicates a limitation in the filenames a device
+ * can accept - they must be 7 bit (all chars <= 127/0x7F).
+ * It was found first on the Philips Shoqbox, and is a deviation
+ * from the PTP standard which mandates that any unicode chars
+ * may be used for filenames. I guess this is caused by a 7bit-only
+ * filesystem being used intrinsically on the device.
+ */
+#define DEVICE_FLAG_ONLY_7BIT_FILENAMES 0x00000020
+/**
+ * This flag indicates that the device will lock up if you
+ * try to get status of endpoints and/or release the interface
+ * when closing the device. This fixes problems with SanDisk
+ * Sansa devices especially. It may be a side-effect of a
+ * Windows behaviour of never releasing interfaces.
+ */
+#define DEVICE_FLAG_NO_RELEASE_INTERFACE 0x00000040
+/**
+ * This flag was introduced with the advent of Creative ZEN
+ * 8GB. The device sometimes return a broken PTP header
+ * like this: < 1502 0000 0200 01d1 02d1 01d2 >
+ * the latter 6 bytes (representing "code" and "transaction ID")
+ * contain junk. This is breaking the PTP/MTP spec but works
+ * on Windows anyway, probably because the Windows implementation
+ * does not check that these bytes are valid. To interoperate
+ * with devices like this, we need this flag to emulate the 
+ * Windows bug.
+ */
+#define DEVICE_FLAG_IGNORE_HEADER_ERRORS 0x00000080
+/**
+ * The Motorola RAZR2 V8 (others?) has broken set object
+ * proplist causing the metadata setting to fail. (The
+ * set object prop to set individual properties work on
+ * this device, but the metadata is plain ignored on
+ * tracks, though e.g. playlist names can be set.)
+ */
+#define DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST 0x00000100
+/**
+ * The Samsung YP-T10 think Ogg files shall be sent with
+ * the "unknown" (PTP_OFC_Undefined) file type, this gives a 
+ * side effect that is a combination of the iRiver Ogg Alzheimer 
+ * problem (have to recognized Ogg files on file extension)
+ * and a need to report the Ogg support (the device itself does
+ * not properly claim to support it) and need to set filetype 
+ * to unknown when storing Ogg files, even though they're not
+ * actually unknown. Later iRivers seem to need this flag since
+ * they do not report to support OGG even though they actually
+ * do. Often the device supports OGG in USB mass storage mode,
+ * then the firmware simply miss to declare metadata support
+ * for OGG properly.
+ */
+#define DEVICE_FLAG_OGG_IS_UNKNOWN 0x00000200
+/**
+ * The Creative Zen is quite unstable in libmtp but seems to
+ * be better with later firmware versions. However, it still
+ * frequently crashes when setting album art dimensions. This
+ * flag disables setting the dimensions (which seems to make
+ * no difference to how the graphic is displayed).
+ */
+#define DEVICE_FLAG_BROKEN_SET_SAMPLE_DIMENSIONS 0x00000400
+/**
+ * Some devices, particularly SanDisk Sansas, need to always
+ * have their "OS Descriptor" probed in order to work correctly.
+ * This flag provides that extra massage.
+ */
+#define DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR 0x00000800
+/**
+ * Samsung has implimented its own playlist format as a .spl file
+ * stored in the normal file system, rather than a proper mtp
+ * playlist. There are multiple versions of the .spl format
+ * identified by a line in the file: VERSION X.XX
+ * Version 1.00 is just a simple playlist.
+ */
+#define DEVICE_FLAG_PLAYLIST_SPL_V1 0x00001000
+/**
+ * Samsung has implimented its own playlist format as a .spl file
+ * stored in the normal file system, rather than a proper mtp
+ * playlist. There are multiple versions of the .spl format
+ * identified by a line in the file: VERSION X.XX
+ * Version 2.00 is playlist but allows DNSe sound settings
+ * to be stored, per playlist.
+ */
+#define DEVICE_FLAG_PLAYLIST_SPL_V2 0x00002000
+/**
+ * The Sansa E250 is know to have this problem which is actually
+ * that the device claims that property PTP_OPC_DateModified
+ * is read/write but will still fail to update it. It can only
+ * be set properly the first time a file is sent.
+ */
+#define DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED 0x00004000
+/**
+ * This avoids use of the send object proplist which
+ * is used when creating new objects (not just updating)
+ * The DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST is related
+ * but only concerns the case where the object proplist
+ * is sent in to update an existing object. The Toshiba
+ * Gigabeat MEU202 for example has this problem.
+ */
+#define DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST 0x00008000
+/**
+ * Devices that cannot support reading out battery
+ * level.
+ */
+#define DEVICE_FLAG_BROKEN_BATTERY_LEVEL 0x00010000
+
+/**
+ * Devices that send "ObjectDeleted" events after deletion
+ * of images. (libgphoto2) 
+ */ 
+#define DEVICE_FLAG_DELETE_SENDS_EVENT	0x00020000
+
+/**
+ * Cameras that can capture images. (libgphoto2)
+ */ 
+#define DEVICE_FLAG_CAPTURE		0x00040000
+
+/**
+ * Cameras that can capture images. (libgphoto2)
+ */ 
+#define DEVICE_FLAG_CAPTURE_PREVIEW	0x00080000
+
+/**
+ * Nikon broken capture support without proper ObjectAdded events.
+ * (libgphoto2)
+ */ 
+#define DEVICE_FLAG_NIKON_BROKEN_CAPTURE	0x00100000
+
+/**
+ * Broken capture support where cameras do not send CaptureComplete events.
+ * (libgphoto2)
+ */ 
+#define DEVICE_FLAG_NO_CAPTURE_COMPLETE		0x00400000
+
+/**
+ * Direct PTP match required.
+ * (libgphoto2)
+ */ 
+#define DEVICE_FLAG_MATCH_PTP_INTERFACE		0x00800000
+/**
+ * This flag is like DEVICE_FLAG_OGG_IS_UNKNOWN but for FLAC
+ * files instead. Using the unknown filetype for FLAC files.
+ */
+#define DEVICE_FLAG_FLAC_IS_UNKNOWN 0x01000000
diff --git a/src/gphoto2-endian-intel.h b/src/gphoto2-endian-intel.h
new file mode 100644
index 0000000..89f84f6
--- /dev/null
+++ b/src/gphoto2-endian-intel.h
@@ -0,0 +1,137 @@
+/* This file is generated automatically by configure */
+/* It is valid only for the system type i386-apple-darwin10.4.0 */
+
+#ifndef __BYTEORDER_H
+#define __BYTEORDER_H
+
+/* ntohl and relatives live here */
+#include <arpa/inet.h>
+
+/* Define generic byte swapping functions */
+#include <machine/byte_order.h>
+#define swap16(x) NXSwapShort(x)
+#define swap32(x) NXSwapLong(x)
+#define swap64(x) NXSwapLongLong(x)
+
+/* The byte swapping macros have the form: */
+/*   EENN[a]toh or htoEENN[a] where EE is be (big endian) or */
+/* le (little-endian), NN is 16 or 32 (number of bits) and a, */
+/* if present, indicates that the endian side is a pointer to an */
+/* array of uint8_t bytes instead of an integer of the specified length. */
+/* h refers to the host's ordering method. */
+
+/* So, to convert a 32-bit integer stored in a buffer in little-endian */
+/* format into a uint32_t usable on this machine, you could use: */
+/*   uint32_t value = le32atoh(&buf[3]); */
+/* To put that value back into the buffer, you could use: */
+/*   htole32a(&buf[3], value); */
+
+/* Define aliases for the standard byte swapping macros */
+/* Arguments to these macros must be properly aligned on natural word */
+/* boundaries in order to work properly on all architectures */
+#ifndef htobe16
+# define htobe16(x) htons(x)
+#endif
+#ifndef htobe32
+# define htobe32(x) htonl(x)
+#endif
+#ifndef be16toh
+# define be16toh(x) ntohs(x)
+#endif
+#ifndef be32toh
+# define be32toh(x) ntohl(x)
+#endif
+
+#define HTOBE16(x) (x) = htobe16(x)
+#define HTOBE32(x) (x) = htobe32(x)
+#define BE32TOH(x) (x) = be32toh(x)
+#define BE16TOH(x) (x) = be16toh(x)
+
+/* On little endian machines, these macros are null */
+#ifndef htole16
+# define htole16(x)      (x)
+#endif
+#ifndef htole32
+# define htole32(x)      (x)
+#endif
+#ifndef htole64
+# define htole64(x)      (x)
+#endif
+#ifndef le16toh
+# define le16toh(x)      (x)
+#endif
+#ifndef le32toh
+# define le32toh(x)      (x)
+#endif
+#ifndef le64toh
+# define le64toh(x)      (x)
+#endif
+
+#define HTOLE16(x)      (void) (x)
+#define HTOLE32(x)      (void) (x)
+#define HTOLE64(x)      (void) (x)
+#define LE16TOH(x)      (void) (x)
+#define LE32TOH(x)      (void) (x)
+#define LE64TOH(x)      (void) (x)
+
+/* These don't have standard aliases */
+#ifndef htobe64
+# define htobe64(x)      swap64(x)
+#endif
+#ifndef be64toh
+# define be64toh(x)      swap64(x)
+#endif
+
+#define HTOBE64(x)      (x) = htobe64(x)
+#define BE64TOH(x)      (x) = be64toh(x)
+
+/* Define the C99 standard length-specific integer types */
+#include <stdint.h>
+
+/* Here are some macros to create integers from a byte array */
+/* These are used to get and put integers from/into a uint8_t array */
+/* with a specific endianness.  This is the most portable way to generate */
+/* and read messages to a network or serial device.  Each member of a */
+/* packet structure must be handled separately. */
+
+/* The i386 and compatibles can handle unaligned memory access, */
+/* so use the optimized macros above to do this job */
+#ifndef be16atoh
+# define be16atoh(x)     be16toh(*(uint16_t*)(x))
+#endif
+#ifndef be32atoh
+# define be32atoh(x)     be32toh(*(uint32_t*)(x))
+#endif
+#ifndef be64atoh
+# define be64atoh(x)     be64toh(*(uint64_t*)(x))
+#endif
+#ifndef le16atoh
+# define le16atoh(x)     le16toh(*(uint16_t*)(x))
+#endif
+#ifndef le32atoh
+# define le32atoh(x)     le32toh(*(uint32_t*)(x))
+#endif
+#ifndef le64atoh
+# define le64atoh(x)     le64toh(*(uint64_t*)(x))
+#endif
+
+#ifndef htob16a
+# define htobe16a(a,x)   *(uint16_t*)(a) = htobe16(x)
+#endif
+#ifndef htobe32a
+# define htobe32a(a,x)   *(uint32_t*)(a) = htobe32(x)
+#endif
+#ifndef htobe64a
+# define htobe64a(a,x)   *(uint64_t*)(a) = htobe64(x)
+#endif
+#ifndef htole16a
+# define htole16a(a,x)   *(uint16_t*)(a) = htole16(x)
+#endif
+#ifndef htole32a
+# define htole32a(a,x)   *(uint32_t*)(a) = htole32(x)
+#endif
+#ifndef htole64a
+# define htole64a(a,x)   *(uint64_t*)(a) = htole64(x)
+#endif
+
+#endif /*__BYTEORDER_H*/
diff --git a/src/gphoto2-endian-ppc.h b/src/gphoto2-endian-ppc.h
new file mode 100644
index 0000000..6ff07cc
--- /dev/null
+++ b/src/gphoto2-endian-ppc.h
@@ -0,0 +1,119 @@
+/* This file is generated automatically by configure */
+/* It is valid only for the system type powerpc-apple-darwin9.8.0 */
+
+#ifndef __BYTEORDER_H
+#define __BYTEORDER_H
+
+/* ntohl and relatives live here */
+#include <arpa/inet.h>
+
+/* Define generic byte swapping functions */
+#include <machine/byte_order.h>
+#define swap16(x) NXSwapShort(x)
+#define swap32(x) NXSwapLong(x)
+#define swap64(x) NXSwapLongLong(x)
+
+/* The byte swapping macros have the form: */
+/*   EENN[a]toh or htoEENN[a] where EE is be (big endian) or */
+/* le (little-endian), NN is 16 or 32 (number of bits) and a, */
+/* if present, indicates that the endian side is a pointer to an */
+/* array of uint8_t bytes instead of an integer of the specified length. */
+/* h refers to the host's ordering method. */
+
+/* So, to convert a 32-bit integer stored in a buffer in little-endian */
+/* format into a uint32_t usable on this machine, you could use: */
+/*   uint32_t value = le32atoh(&buf[3]); */
+/* To put that value back into the buffer, you could use: */
+/*   htole32a(&buf[3], value); */
+
+/* Define aliases for the standard byte swapping macros */
+/* Arguments to these macros must be properly aligned on natural word */
+/* boundaries in order to work properly on all architectures */
+#ifndef htobe16
+# define htobe16(x) htons(x)
+#endif
+#ifndef htobe32
+# define htobe32(x) htonl(x)
+#endif
+#ifndef be16toh
+# define be16toh(x) ntohs(x)
+#endif
+#ifndef be32toh
+# define be32toh(x) ntohl(x)
+#endif
+
+#define HTOBE16(x) (x) = htobe16(x)
+#define HTOBE32(x) (x) = htobe32(x)
+#define BE32TOH(x) (x) = be32toh(x)
+#define BE16TOH(x) (x) = be16toh(x)
+
+/* Define our own extended byte swapping macros for big-endian machines */
+#ifndef htole16
+# define htole16(x)      swap16(x)
+#endif
+#ifndef htole32
+# define htole32(x)      swap32(x)
+#endif
+#ifndef le16toh
+# define le16toh(x)      swap16(x)
+#endif
+#ifndef le32toh
+# define le32toh(x)      swap32(x)
+#endif
+#ifndef le64toh
+# define le64toh(x)      swap64(x)
+#endif
+
+#ifndef htobe64
+# define htobe64(x)      (x)
+#endif
+#ifndef be64toh
+# define be64toh(x)      (x)
+#endif
+
+#define HTOLE16(x)      (x) = htole16(x)
+#define HTOLE32(x)      (x) = htole32(x)
+#define LE16TOH(x)      (x) = le16toh(x)
+#define LE32TOH(x)      (x) = le32toh(x)
+#define LE64TOH(x)      (x) = le64toh(x)
+
+#define HTOBE64(x)      (void) (x)
+#define BE64TOH(x)      (void) (x)
+
+/* Define the C99 standard length-specific integer types */
+#include <stdint.h>
+
+/* Here are some macros to create integers from a byte array */
+/* These are used to get and put integers from/into a uint8_t array */
+/* with a specific endianness.  This is the most portable way to generate */
+/* and read messages to a network or serial device.  Each member of a */
+/* packet structure must be handled separately. */
+
+/* Non-optimized but portable macros */
+#define be16atoh(x)     ((uint16_t)(((x)[0]<<8)|(x)[1]))
+#define be32atoh(x)     ((uint32_t)(((x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]))
+#define be64atoh_x(x,off,shift) 	(((uint64_t)((x)[off]))<<shift)
+#define be64atoh(x)     ((uint64_t)(be64atoh_x(x,0,56)|be64atoh_x(x,1,48)|be64atoh_x(x,2,40)| \
+        be64atoh_x(x,3,32)|be64atoh_x(x,4,24)|be64atoh_x(x,5,16)|be64atoh_x(x,6,8)|((x)[7])))
+#define le16atoh(x)     ((uint16_t)(((x)[1]<<8)|(x)[0]))
+#define le32atoh(x)     ((uint32_t)(((x)[3]<<24)|((x)[2]<<16)|((x)[1]<<8)|(x)[0]))
+#define le64atoh_x(x,off,shift) (((uint64_t)(x)[off])<<shift)
+#define le64atoh(x)     ((uint64_t)(le64atoh_x(x,7,56)|le64atoh_x(x,6,48)|le64atoh_x(x,5,40)| \
+        le64atoh_x(x,4,32)|le64atoh_x(x,3,24)|le64atoh_x(x,2,16)|le64atoh_x(x,1,8)|((x)[0])))
+
+#define htobe16a(a,x)   (a)[0]=(uint8_t)((x)>>8), (a)[1]=(uint8_t)(x)
+#define htobe32a(a,x)   (a)[0]=(uint8_t)((x)>>24), (a)[1]=(uint8_t)((x)>>16), \
+        (a)[2]=(uint8_t)((x)>>8), (a)[3]=(uint8_t)(x)
+#define htobe64a(a,x)   (a)[0]=(uint8_t)((x)>>56), (a)[1]=(uint8_t)((x)>>48), \
+        (a)[2]=(uint8_t)((x)>>40), (a)[3]=(uint8_t)((x)>>32), \
+        (a)[4]=(uint8_t)((x)>>24), (a)[5]=(uint8_t)((x)>>16), \
+        (a)[6]=(uint8_t)((x)>>8), (a)[7]=(uint8_t)(x)
+#define htole16a(a,x)   (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
+#define htole32a(a,x)   (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \
+        (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
+#define htole64a(a,x)   (a)[7]=(uint8_t)((x)>>56), (a)[6]=(uint8_t)((x)>>48), \
+        (a)[5]=(uint8_t)((x)>>40), (a)[4]=(uint8_t)((x)>>32), \
+        (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \
+        (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
+
+#endif /*__BYTEORDER_H*/
diff --git a/src/gphoto2-endian.h b/src/gphoto2-endian.h
new file mode 100644
index 0000000..90cdeae
--- /dev/null
+++ b/src/gphoto2-endian.h
@@ -0,0 +1,7 @@
+/* added 10/26/2010 to deal with both archs on Mac */
+
+#ifdef __BIG_ENDIAN__
+#include "gphoto2-endian-ppc.h"
+#else
+#include "gphoto2-endian-intel.h"
+#endif
diff --git a/src/libmtp.c b/src/libmtp.c
new file mode 100644
index 0000000..90bdb04
--- /dev/null
+++ b/src/libmtp.c
@@ -0,0 +1,8372 @@
+/**
+ * \file libmtp.c
+ *
+ * Copyright (C) 2005-2009 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2005-2008 Richard A. Low <richard@wentnet.com>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ * Copyright (C) 2007 Tero Saarni <tero.saarni@gmail.com>
+ * Copyright (C) 2008 Florent Mertens <flomertens@gmail.com>
+ *
+ * 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.
+ *
+ * This file provides an interface "glue" to the underlying
+ * PTP implementation from libgphoto2. It uses some local
+ * code to convert from/to UTF-8 (stored in unicode.c/.h)
+ * and some small utility functions, mainly for debugging
+ * (stored in util.c/.h).
+ *
+ * The three PTP files (ptp.c, ptp.h and ptp-pack.c) are
+ * plain copied from the libhphoto2 codebase.
+ *
+ * The files libusb-glue.c/.h are just what they say: an
+ * interface to libusb for the actual, physical USB traffic.
+ */
+#include "config.h"
+#include "libmtp.h"
+#include "unicode.h"
+#include "ptp.h"
+#include "libusb-glue.h"
+#include "device-flags.h"
+#include "playlist-spl.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <time.h>
+#include <errno.h>
+#ifdef _MSC_VER // For MSVC++
+#define USE_WINDOWS_IO_H
+#include <io.h>
+#endif
+
+/* To enable PTP level debug prints (all ptp_debug(...)), switch on this */
+//#define ENABLE_PTP_DEBUG
+
+/*
+ * This is a mapping between libmtp internal MTP filetypes and
+ * the libgphoto2/PTP equivalent defines. We need this because
+ * otherwise the libmtp.h device has to be dependent on ptp.h
+ * to be installed too, and we don't want that.
+ */
+//typedef struct filemap_struct filemap_t;
+typedef struct filemap_struct {
+  char *description; /**< Text description for the file type */
+  LIBMTP_filetype_t id; /**< LIBMTP internal type for the file type */
+  uint16_t ptp_id; /**< PTP ID for the filetype */
+  struct filemap_struct *next;
+} filemap_t;
+
+/*
+ * This is a mapping between libmtp internal MTP properties and
+ * the libgphoto2/PTP equivalent defines. We need this because
+ * otherwise the libmtp.h device has to be dependent on ptp.h
+ * to be installed too, and we don't want that.
+ */
+typedef struct propertymap_struct {
+  char *description; /**< Text description for the property */
+  LIBMTP_property_t id; /**< LIBMTP internal type for the property */
+  uint16_t ptp_id; /**< PTP ID for the property */
+  struct propertymap_struct *next;
+} propertymap_t;
+
+// Global variables
+// This holds the global filetype mapping table
+static filemap_t *filemap = NULL;
+// This holds the global property mapping table
+static propertymap_t *propertymap = NULL;
+
+static int load_cache_on_demand = 0;
+/*
+ * Forward declarations of local (static) functions.
+ */
+static int register_filetype(char const * const description, LIBMTP_filetype_t const id,
+			     uint16_t const ptp_id);
+static void init_filemap();
+static int register_property(char const * const description, LIBMTP_property_t const id,
+			     uint16_t const ptp_id);
+static void init_propertymap();
+static void add_error_to_errorstack(LIBMTP_mtpdevice_t *device,
+				    LIBMTP_error_number_t errornumber,
+				    char const * const error_text);
+static void add_ptp_error_to_errorstack(LIBMTP_mtpdevice_t *device,
+					uint16_t ptp_error,
+					char const * const error_text);
+static void flush_handles(LIBMTP_mtpdevice_t *device);
+static void get_handles_recursively(LIBMTP_mtpdevice_t *device, 
+				    PTPParams *params, 
+				    uint32_t storageid,
+				    uint32_t parent);
+static void free_storage_list(LIBMTP_mtpdevice_t *device);
+static int sort_storage_by(LIBMTP_mtpdevice_t *device, int const sortby);
+static uint32_t get_writeable_storageid(LIBMTP_mtpdevice_t *device, uint64_t fitsize);
+static int get_storage_freespace(LIBMTP_mtpdevice_t *device,
+				 LIBMTP_devicestorage_t *storage,
+				 uint64_t *freespace);
+static int check_if_file_fits(LIBMTP_mtpdevice_t *device, 
+			      LIBMTP_devicestorage_t *storage,
+			      uint64_t const filesize);
+static uint16_t map_libmtp_type_to_ptp_type(LIBMTP_filetype_t intype);
+static LIBMTP_filetype_t map_ptp_type_to_libmtp_type(uint16_t intype);
+static uint16_t map_libmtp_property_to_ptp_property(LIBMTP_property_t inproperty);
+static LIBMTP_property_t map_ptp_property_to_libmtp_property(uint16_t intype);
+static int get_device_unicode_property(LIBMTP_mtpdevice_t *device,
+				       char **unicstring, uint16_t property);
+static uint16_t adjust_u16(uint16_t val, PTPObjectPropDesc *opd);
+static uint32_t adjust_u32(uint32_t val, PTPObjectPropDesc *opd);
+static char *get_iso8601_stamp(void);
+static char *get_string_from_object(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+				    uint16_t const attribute_id);
+static uint64_t get_u64_from_object(LIBMTP_mtpdevice_t *device,uint32_t const object_id,
+                                    uint16_t const attribute_id, uint64_t const value_default);
+static uint32_t get_u32_from_object(LIBMTP_mtpdevice_t *device,uint32_t const object_id,
+				    uint16_t const attribute_id, uint32_t const value_default);
+static uint16_t get_u16_from_object(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+				    uint16_t const attribute_id, uint16_t const value_default);
+static uint8_t get_u8_from_object(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+				  uint16_t const attribute_id, uint8_t const value_default);
+static int set_object_string(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+			     uint16_t const attribute_id, char const * const string);
+static int set_object_u32(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+			  uint16_t const attribute_id, uint32_t const value);
+static int set_object_u16(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+			  uint16_t const attribute_id, uint16_t const value);
+static int set_object_u8(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+			 uint16_t const attribute_id, uint8_t const value);
+static void get_track_metadata(LIBMTP_mtpdevice_t *device, uint16_t objectformat,
+			       LIBMTP_track_t *track);
+static LIBMTP_folder_t *get_subfolders_for_folder(LIBMTP_folder_t *list, uint32_t parent);
+static int create_new_abstract_list(LIBMTP_mtpdevice_t *device,
+				    char const * const name,
+				    char const * const artist,
+				    char const * const composer,
+				    char const * const genre,
+				    uint32_t const parenthandle,
+				    uint32_t const storageid,
+				    uint16_t const objectformat,
+				    char const * const suffix,
+				    uint32_t * const newid,
+				    uint32_t const * const tracks,
+				    uint32_t const no_tracks);
+static int update_abstract_list(LIBMTP_mtpdevice_t *device,
+				char const * const name,
+				char const * const artist,
+				char const * const composer,
+				char const * const genre,
+				uint32_t const objecthandle,
+				uint16_t const objectformat,
+				uint32_t const * const tracks,
+				uint32_t const no_tracks);
+static int send_file_object_info(LIBMTP_mtpdevice_t *device, LIBMTP_file_t *filedata);
+static void add_object_to_cache(LIBMTP_mtpdevice_t *device, uint32_t object_id);
+static void update_metadata_cache(LIBMTP_mtpdevice_t *device, uint32_t object_id);
+static int set_object_filename(LIBMTP_mtpdevice_t *device,
+		uint32_t object_id,
+		uint16_t ptp_type,
+                const char **newname);
+                
+/**
+ * These are to wrap the get/put handlers to convert from the MTP types to PTP types
+ * in a reliable way
+ */
+typedef struct _MTPDataHandler {
+	MTPDataGetFunc		getfunc;
+	MTPDataPutFunc		putfunc;
+	void			*priv;
+} MTPDataHandler;
+
+static uint16_t get_func_wrapper(PTPParams* params, void* priv, unsigned long wantlen, unsigned char *data, unsigned long *gotlen);
+static uint16_t put_func_wrapper(PTPParams* params, void* priv, unsigned long sendlen, unsigned char *data, unsigned long *putlen);
+                
+/**
+ * Checks if a filename ends with ".ogg". Used in various
+ * situations when the device has no idea that it support
+ * OGG but still does.
+ *
+ * @param name string to be checked.
+ * @return 0 if this does not end with ogg, any other
+ *           value means it does.
+ */
+static int has_ogg_extension(char *name) {
+  char *ptype;
+
+  if (name == NULL)
+    return 0;
+  ptype = strrchr(name,'.');
+  if (ptype == NULL)
+    return 0;
+  if (!strcasecmp (ptype, ".ogg"))
+    return 1;
+  return 0;
+}
+
+/**
+ * Checks if a filename ends with ".flac". Used in various
+ * situations when the device has no idea that it support
+ * FLAC but still does.
+ *
+ * @param name string to be checked.
+ * @return 0 if this does not end with flac, any other
+ *           value means it does.
+ */
+static int has_flac_extension(char *name) {
+  char *ptype;
+
+  if (name == NULL)
+    return 0;
+  ptype = strrchr(name,'.');
+  if (ptype == NULL)
+    return 0;
+  if (!strcasecmp (ptype, ".flac"))
+    return 1;
+  return 0;
+}
+
+
+
+/**
+ * Create a new file mapping entry
+ * @return a newly allocated filemapping entry.
+ */
+static filemap_t *new_filemap_entry()
+{
+  filemap_t *filemap;
+
+  filemap = (filemap_t *)malloc(sizeof(filemap_t));
+
+  if( filemap != NULL ) {
+    filemap->description = NULL;
+    filemap->id = LIBMTP_FILETYPE_UNKNOWN;
+    filemap->ptp_id = PTP_OFC_Undefined;
+    filemap->next = NULL;
+  }
+
+  return filemap;
+}
+
+/**
+ * Register an MTP or PTP filetype for data retrieval
+ *
+ * @param description Text description of filetype
+ * @param id libmtp internal filetype id
+ * @param ptp_id PTP filetype id
+ * @return 0 for success any other value means error.
+*/
+static int register_filetype(char const * const description, LIBMTP_filetype_t const id,
+			     uint16_t const ptp_id)
+{
+  filemap_t *new = NULL, *current;
+
+  // Has this LIBMTP filetype been registered before ?
+  current = filemap;
+  while (current != NULL) {
+    if(current->id == id) {
+      break;
+    }
+    current = current->next;
+  }
+
+  // Create the entry
+  if(current == NULL) {
+    new = new_filemap_entry();
+    if(new == NULL) {
+      return 1;
+    }
+
+    new->id = id;
+    if(description != NULL) {
+      new->description = strdup(description);
+    }
+    new->ptp_id = ptp_id;
+
+    // Add the entry to the list
+    if(filemap == NULL) {
+      filemap = new;
+    } else {
+      current = filemap;
+      while (current->next != NULL ) current=current->next;
+      current->next = new;
+    }
+    // Update the existing entry
+  } else {
+    if (current->description != NULL) {
+      free(current->description);
+    }
+    current->description = NULL;
+    if(description != NULL) {
+      current->description = strdup(description);
+    }
+    current->ptp_id = ptp_id;
+  }
+
+  return 0;
+}
+
+static void init_filemap()
+{
+  register_filetype("Folder", LIBMTP_FILETYPE_FOLDER, PTP_OFC_Association);
+  register_filetype("MediaCard", LIBMTP_FILETYPE_MEDIACARD, PTP_OFC_MTP_MediaCard);
+  register_filetype("RIFF WAVE file", LIBMTP_FILETYPE_WAV, PTP_OFC_WAV);
+  register_filetype("ISO MPEG-1 Audio Layer 3", LIBMTP_FILETYPE_MP3, PTP_OFC_MP3);
+  register_filetype("ISO MPEG-1 Audio Layer 2", LIBMTP_FILETYPE_MP2, PTP_OFC_MTP_MP2);
+  register_filetype("Microsoft Windows Media Audio", LIBMTP_FILETYPE_WMA, PTP_OFC_MTP_WMA);
+  register_filetype("Ogg container format", LIBMTP_FILETYPE_OGG, PTP_OFC_MTP_OGG);
+  register_filetype("Free Lossless Audio Codec (FLAC)", LIBMTP_FILETYPE_FLAC, PTP_OFC_MTP_FLAC);
+  register_filetype("Advanced Audio Coding (AAC)/MPEG-2 Part 7/MPEG-4 Part 3", LIBMTP_FILETYPE_AAC, PTP_OFC_MTP_AAC);
+  register_filetype("MPEG-4 Part 14 Container Format (Audio Emphasis)", LIBMTP_FILETYPE_M4A, PTP_OFC_MTP_M4A);
+  register_filetype("MPEG-4 Part 14 Container Format (Audio+Video Emphasis)", LIBMTP_FILETYPE_MP4, PTP_OFC_MTP_MP4);
+  register_filetype("Audible.com Audio Codec", LIBMTP_FILETYPE_AUDIBLE, PTP_OFC_MTP_AudibleCodec);
+  register_filetype("Undefined audio file", LIBMTP_FILETYPE_UNDEF_AUDIO, PTP_OFC_MTP_UndefinedAudio);
+  register_filetype("Microsoft Windows Media Video", LIBMTP_FILETYPE_WMV, PTP_OFC_MTP_WMV);
+  register_filetype("Audio Video Interleave", LIBMTP_FILETYPE_AVI, PTP_OFC_AVI);
+  register_filetype("MPEG video stream", LIBMTP_FILETYPE_MPEG, PTP_OFC_MPEG);
+  register_filetype("Microsoft Advanced Systems Format", LIBMTP_FILETYPE_ASF, PTP_OFC_ASF);
+  register_filetype("Apple Quicktime container format", LIBMTP_FILETYPE_QT, PTP_OFC_QT);
+  register_filetype("Undefined video file", LIBMTP_FILETYPE_UNDEF_VIDEO, PTP_OFC_MTP_UndefinedVideo);
+  register_filetype("JPEG file", LIBMTP_FILETYPE_JPEG, PTP_OFC_EXIF_JPEG);
+  register_filetype("JP2 file", LIBMTP_FILETYPE_JP2, PTP_OFC_JP2);
+  register_filetype("JPX file", LIBMTP_FILETYPE_JPX, PTP_OFC_JPX);
+  register_filetype("JFIF file", LIBMTP_FILETYPE_JFIF, PTP_OFC_JFIF);
+  register_filetype("TIFF bitmap file", LIBMTP_FILETYPE_TIFF, PTP_OFC_TIFF);
+  register_filetype("BMP bitmap file", LIBMTP_FILETYPE_BMP, PTP_OFC_BMP);
+  register_filetype("GIF bitmap file", LIBMTP_FILETYPE_GIF, PTP_OFC_GIF);
+  register_filetype("PICT bitmap file", LIBMTP_FILETYPE_PICT, PTP_OFC_PICT);
+  register_filetype("Portable Network Graphics", LIBMTP_FILETYPE_PNG, PTP_OFC_PNG);
+  register_filetype("Microsoft Windows Image Format", LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT, PTP_OFC_MTP_WindowsImageFormat);
+  register_filetype("VCalendar version 1", LIBMTP_FILETYPE_VCALENDAR1, PTP_OFC_MTP_vCalendar1);
+  register_filetype("VCalendar version 2", LIBMTP_FILETYPE_VCALENDAR2, PTP_OFC_MTP_vCalendar2);
+  register_filetype("VCard version 2", LIBMTP_FILETYPE_VCARD2, PTP_OFC_MTP_vCard2);
+  register_filetype("VCard version 3", LIBMTP_FILETYPE_VCARD3, PTP_OFC_MTP_vCard3);
+  register_filetype("Undefined Windows executable file", LIBMTP_FILETYPE_WINEXEC, PTP_OFC_MTP_UndefinedWindowsExecutable);
+  register_filetype("Text file", LIBMTP_FILETYPE_TEXT, PTP_OFC_Text);
+  register_filetype("HTML file", LIBMTP_FILETYPE_HTML, PTP_OFC_HTML);
+  register_filetype("XML file", LIBMTP_FILETYPE_XML, PTP_OFC_MTP_XMLDocument);
+  register_filetype("DOC file", LIBMTP_FILETYPE_DOC, PTP_OFC_MTP_MSWordDocument);
+  register_filetype("XLS file", LIBMTP_FILETYPE_XLS, PTP_OFC_MTP_MSExcelSpreadsheetXLS);
+  register_filetype("PPT file", LIBMTP_FILETYPE_PPT, PTP_OFC_MTP_MSPowerpointPresentationPPT);
+  register_filetype("MHT file", LIBMTP_FILETYPE_MHT, PTP_OFC_MTP_MHTCompiledHTMLDocument);
+  register_filetype("Firmware file", LIBMTP_FILETYPE_FIRMWARE, PTP_OFC_MTP_Firmware);
+  register_filetype("Abstract Album file", LIBMTP_FILETYPE_ALBUM, PTP_OFC_MTP_AbstractAudioAlbum);
+  register_filetype("Abstract Playlist file", LIBMTP_FILETYPE_PLAYLIST, PTP_OFC_MTP_AbstractAudioVideoPlaylist);
+  register_filetype("Undefined filetype", LIBMTP_FILETYPE_UNKNOWN, PTP_OFC_Undefined);
+}
+
+/**
+ * Returns the PTP filetype that maps to a certain libmtp internal file type.
+ * @param intype the MTP library interface type
+ * @return the PTP (libgphoto2) interface type
+ */
+static uint16_t map_libmtp_type_to_ptp_type(LIBMTP_filetype_t intype)
+{
+  filemap_t *current;
+
+  current = filemap;
+
+  while (current != NULL) {
+    if(current->id == intype) {
+      return current->ptp_id;
+    }
+    current = current->next;
+  }
+  // printf("map_libmtp_type_to_ptp_type: unknown filetype.\n");
+  return PTP_OFC_Undefined;
+}
+
+
+/**
+ * Returns the MTP internal interface type that maps to a certain ptp
+ * interface type.
+ * @param intype the PTP (libgphoto2) interface type
+ * @return the MTP library interface type
+ */
+static LIBMTP_filetype_t map_ptp_type_to_libmtp_type(uint16_t intype)
+{
+  filemap_t *current;
+
+  current = filemap;
+
+  while (current != NULL) {
+    if(current->ptp_id == intype) {
+      return current->id;
+    }
+    current = current->next;
+  }
+  // printf("map_ptp_type_to_libmtp_type: unknown filetype.\n");
+  return LIBMTP_FILETYPE_UNKNOWN;
+}
+
+/**
+ * Create a new property mapping entry
+ * @return a newly allocated propertymapping entry.
+ */
+static propertymap_t *new_propertymap_entry()
+{
+  propertymap_t *propertymap;
+
+  propertymap = (propertymap_t *)malloc(sizeof(propertymap_t));
+
+  if( propertymap != NULL ) {
+    propertymap->description = NULL;
+    propertymap->id = LIBMTP_PROPERTY_UNKNOWN;
+    propertymap->ptp_id = 0;
+    propertymap->next = NULL;
+  }
+
+  return propertymap;
+}
+
+/**
+ * Register an MTP or PTP property for data retrieval
+ *
+ * @param description Text description of property
+ * @param id libmtp internal property id
+ * @param ptp_id PTP property id
+ * @return 0 for success any other value means error.
+*/
+static int register_property(char const * const description, LIBMTP_property_t const id,
+			     uint16_t const ptp_id)
+{
+  propertymap_t *new = NULL, *current;
+
+  // Has this LIBMTP propety been registered before ?
+  current = propertymap;
+  while (current != NULL) {
+    if(current->id == id) {
+      break;
+    }
+    current = current->next;
+  }
+
+  // Create the entry
+  if(current == NULL) {
+    new = new_propertymap_entry();
+    if(new == NULL) {
+      return 1;
+    }
+
+    new->id = id;
+    if(description != NULL) {
+      new->description = strdup(description);
+    }
+    new->ptp_id = ptp_id;
+
+    // Add the entry to the list
+    if(propertymap == NULL) {
+      propertymap = new;
+    } else {
+      current = propertymap;
+      while (current->next != NULL ) current=current->next;
+      current->next = new;
+    }
+    // Update the existing entry
+  } else {
+    if (current->description != NULL) {
+      free(current->description);
+    }
+    current->description = NULL;
+    if(description != NULL) {
+      current->description = strdup(description);
+    }
+    current->ptp_id = ptp_id;
+  }
+
+  return 0;
+}
+
+static void init_propertymap()
+{
+  register_property("Storage ID", LIBMTP_PROPERTY_StorageID, PTP_OPC_StorageID);
+  register_property("Object Format", LIBMTP_PROPERTY_ObjectFormat, PTP_OPC_ObjectFormat);
+  register_property("Protection Status", LIBMTP_PROPERTY_ProtectionStatus, PTP_OPC_ProtectionStatus);
+  register_property("Object Size", LIBMTP_PROPERTY_ObjectSize, PTP_OPC_ObjectSize);
+  register_property("Association Type", LIBMTP_PROPERTY_AssociationType, PTP_OPC_AssociationType);
+  register_property("Association Desc", LIBMTP_PROPERTY_AssociationDesc, PTP_OPC_AssociationDesc);
+  register_property("Object File Name", LIBMTP_PROPERTY_ObjectFileName, PTP_OPC_ObjectFileName);
+  register_property("Date Created", LIBMTP_PROPERTY_DateCreated, PTP_OPC_DateCreated);
+  register_property("Date Modified", LIBMTP_PROPERTY_DateModified, PTP_OPC_DateModified);
+  register_property("Keywords", LIBMTP_PROPERTY_Keywords, PTP_OPC_Keywords);
+  register_property("Parent Object", LIBMTP_PROPERTY_ParentObject, PTP_OPC_ParentObject);
+  register_property("Allowed Folder Contents", LIBMTP_PROPERTY_AllowedFolderContents, PTP_OPC_AllowedFolderContents);
+  register_property("Hidden", LIBMTP_PROPERTY_Hidden, PTP_OPC_Hidden);
+  register_property("System Object", LIBMTP_PROPERTY_SystemObject, PTP_OPC_SystemObject);
+  register_property("Persistant Unique Object Identifier", LIBMTP_PROPERTY_PersistantUniqueObjectIdentifier, PTP_OPC_PersistantUniqueObjectIdentifier);
+  register_property("Sync ID", LIBMTP_PROPERTY_SyncID, PTP_OPC_SyncID);
+  register_property("Property Bag", LIBMTP_PROPERTY_PropertyBag, PTP_OPC_PropertyBag);
+  register_property("Name", LIBMTP_PROPERTY_Name, PTP_OPC_Name);
+  register_property("Created By", LIBMTP_PROPERTY_CreatedBy, PTP_OPC_CreatedBy);
+  register_property("Artist", LIBMTP_PROPERTY_Artist, PTP_OPC_Artist);
+  register_property("Date Authored", LIBMTP_PROPERTY_DateAuthored, PTP_OPC_DateAuthored);
+  register_property("Description", LIBMTP_PROPERTY_Description, PTP_OPC_Description);
+  register_property("URL Reference", LIBMTP_PROPERTY_URLReference, PTP_OPC_URLReference);
+  register_property("Language Locale", LIBMTP_PROPERTY_LanguageLocale, PTP_OPC_LanguageLocale);
+  register_property("Copyright Information", LIBMTP_PROPERTY_CopyrightInformation, PTP_OPC_CopyrightInformation);
+  register_property("Source", LIBMTP_PROPERTY_Source, PTP_OPC_Source);
+  register_property("Origin Location", LIBMTP_PROPERTY_OriginLocation, PTP_OPC_OriginLocation);
+  register_property("Date Added", LIBMTP_PROPERTY_DateAdded, PTP_OPC_DateAdded);
+  register_property("Non Consumable", LIBMTP_PROPERTY_NonConsumable, PTP_OPC_NonConsumable);
+  register_property("Corrupt Or Unplayable", LIBMTP_PROPERTY_CorruptOrUnplayable, PTP_OPC_CorruptOrUnplayable);
+  register_property("Producer Serial Number", LIBMTP_PROPERTY_ProducerSerialNumber, PTP_OPC_ProducerSerialNumber);
+  register_property("Representative Sample Format", LIBMTP_PROPERTY_RepresentativeSampleFormat, PTP_OPC_RepresentativeSampleFormat);
+  register_property("Representative Sample Sise", LIBMTP_PROPERTY_RepresentativeSampleSize, PTP_OPC_RepresentativeSampleSize);
+  register_property("Representative Sample Height", LIBMTP_PROPERTY_RepresentativeSampleHeight, PTP_OPC_RepresentativeSampleHeight);
+  register_property("Representative Sample Width", LIBMTP_PROPERTY_RepresentativeSampleWidth, PTP_OPC_RepresentativeSampleWidth);
+  register_property("Representative Sample Duration", LIBMTP_PROPERTY_RepresentativeSampleDuration, PTP_OPC_RepresentativeSampleDuration);
+  register_property("Representative Sample Data", LIBMTP_PROPERTY_RepresentativeSampleData, PTP_OPC_RepresentativeSampleData);
+  register_property("Width", LIBMTP_PROPERTY_Width, PTP_OPC_Width);
+  register_property("Height", LIBMTP_PROPERTY_Height, PTP_OPC_Height);
+  register_property("Duration", LIBMTP_PROPERTY_Duration, PTP_OPC_Duration);
+  register_property("Rating", LIBMTP_PROPERTY_Rating, PTP_OPC_Rating);
+  register_property("Track", LIBMTP_PROPERTY_Track, PTP_OPC_Track);
+  register_property("Genre", LIBMTP_PROPERTY_Genre, PTP_OPC_Genre);
+  register_property("Credits", LIBMTP_PROPERTY_Credits, PTP_OPC_Credits);
+  register_property("Lyrics", LIBMTP_PROPERTY_Lyrics, PTP_OPC_Lyrics);
+  register_property("Subscription Content ID", LIBMTP_PROPERTY_SubscriptionContentID, PTP_OPC_SubscriptionContentID);
+  register_property("Produced By", LIBMTP_PROPERTY_ProducedBy, PTP_OPC_ProducedBy);
+  register_property("Use Count", LIBMTP_PROPERTY_UseCount, PTP_OPC_UseCount);
+  register_property("Skip Count", LIBMTP_PROPERTY_SkipCount, PTP_OPC_SkipCount);
+  register_property("Last Accessed", LIBMTP_PROPERTY_LastAccessed, PTP_OPC_LastAccessed);
+  register_property("Parental Rating", LIBMTP_PROPERTY_ParentalRating, PTP_OPC_ParentalRating);
+  register_property("Meta Genre", LIBMTP_PROPERTY_MetaGenre, PTP_OPC_MetaGenre);
+  register_property("Composer", LIBMTP_PROPERTY_Composer, PTP_OPC_Composer);
+  register_property("Effective Rating", LIBMTP_PROPERTY_EffectiveRating, PTP_OPC_EffectiveRating);
+  register_property("Subtitle", LIBMTP_PROPERTY_Subtitle, PTP_OPC_Subtitle);
+  register_property("Original Release Date", LIBMTP_PROPERTY_OriginalReleaseDate, PTP_OPC_OriginalReleaseDate);
+  register_property("Album Name", LIBMTP_PROPERTY_AlbumName, PTP_OPC_AlbumName);
+  register_property("Album Artist", LIBMTP_PROPERTY_AlbumArtist, PTP_OPC_AlbumArtist);
+  register_property("Mood", LIBMTP_PROPERTY_Mood, PTP_OPC_Mood);
+  register_property("DRM Status", LIBMTP_PROPERTY_DRMStatus, PTP_OPC_DRMStatus);
+  register_property("Sub Description", LIBMTP_PROPERTY_SubDescription, PTP_OPC_SubDescription);
+  register_property("Is Cropped", LIBMTP_PROPERTY_IsCropped, PTP_OPC_IsCropped);
+  register_property("Is Color Corrected", LIBMTP_PROPERTY_IsColorCorrected, PTP_OPC_IsColorCorrected);
+  register_property("Image Bit Depth", LIBMTP_PROPERTY_ImageBitDepth, PTP_OPC_ImageBitDepth);
+  register_property("f Number", LIBMTP_PROPERTY_Fnumber, PTP_OPC_Fnumber);
+  register_property("Exposure Time", LIBMTP_PROPERTY_ExposureTime, PTP_OPC_ExposureTime);
+  register_property("Exposure Index", LIBMTP_PROPERTY_ExposureIndex, PTP_OPC_ExposureIndex);
+  register_property("Display Name", LIBMTP_PROPERTY_DisplayName, PTP_OPC_DisplayName);
+  register_property("Body Text", LIBMTP_PROPERTY_BodyText, PTP_OPC_BodyText);
+  register_property("Subject", LIBMTP_PROPERTY_Subject, PTP_OPC_Subject);
+  register_property("Priority", LIBMTP_PROPERTY_Priority, PTP_OPC_Priority);
+  register_property("Given Name", LIBMTP_PROPERTY_GivenName, PTP_OPC_GivenName);
+  register_property("Middle Names", LIBMTP_PROPERTY_MiddleNames, PTP_OPC_MiddleNames);
+  register_property("Family Name", LIBMTP_PROPERTY_FamilyName, PTP_OPC_FamilyName);
+  register_property("Prefix", LIBMTP_PROPERTY_Prefix, PTP_OPC_Prefix);
+  register_property("Suffix", LIBMTP_PROPERTY_Suffix, PTP_OPC_Suffix);
+  register_property("Phonetic Given Name", LIBMTP_PROPERTY_PhoneticGivenName, PTP_OPC_PhoneticGivenName);
+  register_property("Phonetic Family Name", LIBMTP_PROPERTY_PhoneticFamilyName, PTP_OPC_PhoneticFamilyName);
+  register_property("Email: Primary", LIBMTP_PROPERTY_EmailPrimary, PTP_OPC_EmailPrimary);
+  register_property("Email: Personal 1", LIBMTP_PROPERTY_EmailPersonal1, PTP_OPC_EmailPersonal1);
+  register_property("Email: Personal 2", LIBMTP_PROPERTY_EmailPersonal2, PTP_OPC_EmailPersonal2);
+  register_property("Email: Business 1", LIBMTP_PROPERTY_EmailBusiness1, PTP_OPC_EmailBusiness1);
+  register_property("Email: Business 2", LIBMTP_PROPERTY_EmailBusiness2, PTP_OPC_EmailBusiness2);
+  register_property("Email: Others", LIBMTP_PROPERTY_EmailOthers, PTP_OPC_EmailOthers);
+  register_property("Phone Number: Primary", LIBMTP_PROPERTY_PhoneNumberPrimary, PTP_OPC_PhoneNumberPrimary);
+  register_property("Phone Number: Personal", LIBMTP_PROPERTY_PhoneNumberPersonal, PTP_OPC_PhoneNumberPersonal);
+  register_property("Phone Number: Personal 2", LIBMTP_PROPERTY_PhoneNumberPersonal2, PTP_OPC_PhoneNumberPersonal2);
+  register_property("Phone Number: Business", LIBMTP_PROPERTY_PhoneNumberBusiness, PTP_OPC_PhoneNumberBusiness);
+  register_property("Phone Number: Business 2", LIBMTP_PROPERTY_PhoneNumberBusiness2, PTP_OPC_PhoneNumberBusiness2);
+  register_property("Phone Number: Mobile", LIBMTP_PROPERTY_PhoneNumberMobile, PTP_OPC_PhoneNumberMobile);
+  register_property("Phone Number: Mobile 2", LIBMTP_PROPERTY_PhoneNumberMobile2, PTP_OPC_PhoneNumberMobile2);
+  register_property("Fax Number: Primary", LIBMTP_PROPERTY_FaxNumberPrimary, PTP_OPC_FaxNumberPrimary);
+  register_property("Fax Number: Personal", LIBMTP_PROPERTY_FaxNumberPersonal, PTP_OPC_FaxNumberPersonal);
+  register_property("Fax Number: Business", LIBMTP_PROPERTY_FaxNumberBusiness, PTP_OPC_FaxNumberBusiness);
+  register_property("Pager Number", LIBMTP_PROPERTY_PagerNumber, PTP_OPC_PagerNumber);
+  register_property("Phone Number: Others", LIBMTP_PROPERTY_PhoneNumberOthers, PTP_OPC_PhoneNumberOthers);
+  register_property("Primary Web Address", LIBMTP_PROPERTY_PrimaryWebAddress, PTP_OPC_PrimaryWebAddress);
+  register_property("Personal Web Address", LIBMTP_PROPERTY_PersonalWebAddress, PTP_OPC_PersonalWebAddress);
+  register_property("Business Web Address", LIBMTP_PROPERTY_BusinessWebAddress, PTP_OPC_BusinessWebAddress);
+  register_property("Instant Messenger Address 1", LIBMTP_PROPERTY_InstantMessengerAddress, PTP_OPC_InstantMessengerAddress);
+  register_property("Instant Messenger Address 2", LIBMTP_PROPERTY_InstantMessengerAddress2, PTP_OPC_InstantMessengerAddress2);
+  register_property("Instant Messenger Address 3", LIBMTP_PROPERTY_InstantMessengerAddress3, PTP_OPC_InstantMessengerAddress3);
+  register_property("Postal Address: Personal: Full", LIBMTP_PROPERTY_PostalAddressPersonalFull, PTP_OPC_PostalAddressPersonalFull);
+  register_property("Postal Address: Personal: Line 1", LIBMTP_PROPERTY_PostalAddressPersonalFullLine1, PTP_OPC_PostalAddressPersonalFullLine1);
+  register_property("Postal Address: Personal: Line 2", LIBMTP_PROPERTY_PostalAddressPersonalFullLine2, PTP_OPC_PostalAddressPersonalFullLine2);
+  register_property("Postal Address: Personal: City", LIBMTP_PROPERTY_PostalAddressPersonalFullCity, PTP_OPC_PostalAddressPersonalFullCity);
+  register_property("Postal Address: Personal: Region", LIBMTP_PROPERTY_PostalAddressPersonalFullRegion, PTP_OPC_PostalAddressPersonalFullRegion);
+  register_property("Postal Address: Personal: Postal Code", LIBMTP_PROPERTY_PostalAddressPersonalFullPostalCode, PTP_OPC_PostalAddressPersonalFullPostalCode);
+  register_property("Postal Address: Personal: Country", LIBMTP_PROPERTY_PostalAddressPersonalFullCountry, PTP_OPC_PostalAddressPersonalFullCountry);
+  register_property("Postal Address: Business: Full", LIBMTP_PROPERTY_PostalAddressBusinessFull, PTP_OPC_PostalAddressBusinessFull);
+  register_property("Postal Address: Business: Line 1", LIBMTP_PROPERTY_PostalAddressBusinessLine1, PTP_OPC_PostalAddressBusinessLine1);
+  register_property("Postal Address: Business: Line 2", LIBMTP_PROPERTY_PostalAddressBusinessLine2, PTP_OPC_PostalAddressBusinessLine2);
+  register_property("Postal Address: Business: City", LIBMTP_PROPERTY_PostalAddressBusinessCity, PTP_OPC_PostalAddressBusinessCity);
+  register_property("Postal Address: Business: Region", LIBMTP_PROPERTY_PostalAddressBusinessRegion, PTP_OPC_PostalAddressBusinessRegion);
+  register_property("Postal Address: Business: Postal Code", LIBMTP_PROPERTY_PostalAddressBusinessPostalCode, PTP_OPC_PostalAddressBusinessPostalCode);
+  register_property("Postal Address: Business: Country", LIBMTP_PROPERTY_PostalAddressBusinessCountry, PTP_OPC_PostalAddressBusinessCountry);
+  register_property("Postal Address: Other: Full", LIBMTP_PROPERTY_PostalAddressOtherFull, PTP_OPC_PostalAddressOtherFull);
+  register_property("Postal Address: Other: Line 1", LIBMTP_PROPERTY_PostalAddressOtherLine1, PTP_OPC_PostalAddressOtherLine1);
+  register_property("Postal Address: Other: Line 2", LIBMTP_PROPERTY_PostalAddressOtherLine2, PTP_OPC_PostalAddressOtherLine2);
+  register_property("Postal Address: Other: City", LIBMTP_PROPERTY_PostalAddressOtherCity, PTP_OPC_PostalAddressOtherCity);
+  register_property("Postal Address: Other: Region", LIBMTP_PROPERTY_PostalAddressOtherRegion, PTP_OPC_PostalAddressOtherRegion);
+  register_property("Postal Address: Other: Postal Code", LIBMTP_PROPERTY_PostalAddressOtherPostalCode, PTP_OPC_PostalAddressOtherPostalCode);
+  register_property("Postal Address: Other: Counrtry", LIBMTP_PROPERTY_PostalAddressOtherCountry, PTP_OPC_PostalAddressOtherCountry);
+  register_property("Organization Name", LIBMTP_PROPERTY_OrganizationName, PTP_OPC_OrganizationName);
+  register_property("Phonetic Organization Name", LIBMTP_PROPERTY_PhoneticOrganizationName, PTP_OPC_PhoneticOrganizationName);
+  register_property("Role", LIBMTP_PROPERTY_Role, PTP_OPC_Role);
+  register_property("Birthdate", LIBMTP_PROPERTY_Birthdate, PTP_OPC_Birthdate);
+  register_property("Message To", LIBMTP_PROPERTY_MessageTo, PTP_OPC_MessageTo);
+  register_property("Message CC", LIBMTP_PROPERTY_MessageCC, PTP_OPC_MessageCC);
+  register_property("Message BCC", LIBMTP_PROPERTY_MessageBCC, PTP_OPC_MessageBCC);
+  register_property("Message Read", LIBMTP_PROPERTY_MessageRead, PTP_OPC_MessageRead);
+  register_property("Message Received Time", LIBMTP_PROPERTY_MessageReceivedTime, PTP_OPC_MessageReceivedTime);
+  register_property("Message Sender", LIBMTP_PROPERTY_MessageSender, PTP_OPC_MessageSender);
+  register_property("Activity Begin Time", LIBMTP_PROPERTY_ActivityBeginTime, PTP_OPC_ActivityBeginTime);
+  register_property("Activity End Time", LIBMTP_PROPERTY_ActivityEndTime, PTP_OPC_ActivityEndTime);
+  register_property("Activity Location", LIBMTP_PROPERTY_ActivityLocation, PTP_OPC_ActivityLocation);
+  register_property("Activity Required Attendees", LIBMTP_PROPERTY_ActivityRequiredAttendees, PTP_OPC_ActivityRequiredAttendees);
+  register_property("Optional Attendees", LIBMTP_PROPERTY_ActivityOptionalAttendees, PTP_OPC_ActivityOptionalAttendees);
+  register_property("Activity Resources", LIBMTP_PROPERTY_ActivityResources, PTP_OPC_ActivityResources);
+  register_property("Activity Accepted", LIBMTP_PROPERTY_ActivityAccepted, PTP_OPC_ActivityAccepted);
+  register_property("Owner", LIBMTP_PROPERTY_Owner, PTP_OPC_Owner);
+  register_property("Editor", LIBMTP_PROPERTY_Editor, PTP_OPC_Editor);
+  register_property("Webmaster", LIBMTP_PROPERTY_Webmaster, PTP_OPC_Webmaster);
+  register_property("URL Source", LIBMTP_PROPERTY_URLSource, PTP_OPC_URLSource);
+  register_property("URL Destination", LIBMTP_PROPERTY_URLDestination, PTP_OPC_URLDestination);
+  register_property("Time Bookmark", LIBMTP_PROPERTY_TimeBookmark, PTP_OPC_TimeBookmark);
+  register_property("Object Bookmark", LIBMTP_PROPERTY_ObjectBookmark, PTP_OPC_ObjectBookmark);
+  register_property("Byte Bookmark", LIBMTP_PROPERTY_ByteBookmark, PTP_OPC_ByteBookmark);
+  register_property("Last Build Date", LIBMTP_PROPERTY_LastBuildDate, PTP_OPC_LastBuildDate);
+  register_property("Time To Live", LIBMTP_PROPERTY_TimetoLive, PTP_OPC_TimetoLive);
+  register_property("Media GUID", LIBMTP_PROPERTY_MediaGUID, PTP_OPC_MediaGUID);
+  register_property("Total Bit Rate", LIBMTP_PROPERTY_TotalBitRate, PTP_OPC_TotalBitRate);
+  register_property("Bit Rate Type", LIBMTP_PROPERTY_BitRateType, PTP_OPC_BitRateType);
+  register_property("Sample Rate", LIBMTP_PROPERTY_SampleRate, PTP_OPC_SampleRate);
+  register_property("Number Of Channels", LIBMTP_PROPERTY_NumberOfChannels, PTP_OPC_NumberOfChannels);
+  register_property("Audio Bit Depth", LIBMTP_PROPERTY_AudioBitDepth, PTP_OPC_AudioBitDepth);
+  register_property("Scan Depth", LIBMTP_PROPERTY_ScanDepth, PTP_OPC_ScanDepth);
+  register_property("Audio WAVE Codec", LIBMTP_PROPERTY_AudioWAVECodec, PTP_OPC_AudioWAVECodec);
+  register_property("Audio Bit Rate", LIBMTP_PROPERTY_AudioBitRate, PTP_OPC_AudioBitRate);
+  register_property("Video Four CC Codec", LIBMTP_PROPERTY_VideoFourCCCodec, PTP_OPC_VideoFourCCCodec);
+  register_property("Video Bit Rate", LIBMTP_PROPERTY_VideoBitRate, PTP_OPC_VideoBitRate);
+  register_property("Frames Per Thousand Seconds", LIBMTP_PROPERTY_FramesPerThousandSeconds, PTP_OPC_FramesPerThousandSeconds);
+  register_property("Key Frame Distance", LIBMTP_PROPERTY_KeyFrameDistance, PTP_OPC_KeyFrameDistance);
+  register_property("Buffer Size", LIBMTP_PROPERTY_BufferSize, PTP_OPC_BufferSize);
+  register_property("Encoding Quality", LIBMTP_PROPERTY_EncodingQuality, PTP_OPC_EncodingQuality);
+  register_property("Encoding Profile", LIBMTP_PROPERTY_EncodingProfile, PTP_OPC_EncodingProfile);
+  register_property("Buy flag", LIBMTP_PROPERTY_BuyFlag, PTP_OPC_BuyFlag);
+  register_property("Unknown property", LIBMTP_PROPERTY_UNKNOWN, 0);
+}
+
+/**
+ * Returns the PTP property that maps to a certain libmtp internal property type.
+ * @param inproperty the MTP library interface property
+ * @return the PTP (libgphoto2) property type
+ */
+static uint16_t map_libmtp_property_to_ptp_property(LIBMTP_property_t inproperty)
+{
+  propertymap_t *current;
+
+  current = propertymap;
+
+  while (current != NULL) {
+    if(current->id == inproperty) {
+      return current->ptp_id;
+    }
+    current = current->next;
+  }
+  return 0;
+}
+
+
+/**
+ * Returns the MTP internal interface property that maps to a certain ptp
+ * interface property.
+ * @param inproperty the PTP (libgphoto2) interface property
+ * @return the MTP library interface property
+ */
+static LIBMTP_property_t map_ptp_property_to_libmtp_property(uint16_t inproperty)
+{
+  propertymap_t *current;
+
+  current = propertymap;
+
+  while (current != NULL) {
+    if(current->ptp_id == inproperty) {
+      return current->id;
+    }
+    current = current->next;
+  }
+  // printf("map_ptp_type_to_libmtp_type: unknown filetype.\n");
+  return LIBMTP_PROPERTY_UNKNOWN;
+}
+
+
+/**
+ * Initialize the library. You are only supposed to call this
+ * one, before using the library for the first time in a program.
+ * Never re-initialize libmtp!
+ *
+ * The only thing this does at the moment is to initialise the
+ * filetype mapping table.
+ */
+void LIBMTP_Init(void)
+{
+  init_filemap();
+  init_propertymap();
+  return;
+}
+
+
+/**
+ * This helper function returns a textual description for a libmtp
+ * file type to be used in dialog boxes etc.
+ * @param intype the libmtp internal filetype to get a description for.
+ * @return a string representing the filetype, this must <b>NOT</b>
+ *         be free():ed by the caller!
+ */
+char const * LIBMTP_Get_Filetype_Description(LIBMTP_filetype_t intype)
+{
+  filemap_t *current;
+
+  current = filemap;
+
+  while (current != NULL) {
+    if(current->id == intype) {
+      return current->description;
+    }
+    current = current->next;
+  }
+
+  return "Unknown filetype";
+}
+
+/**
+ * This helper function returns a textual description for a libmtp
+ * property to be used in dialog boxes etc.
+ * @param inproperty the libmtp internal property to get a description for.
+ * @return a string representing the filetype, this must <b>NOT</b>
+ *         be free():ed by the caller!
+ */
+char const * LIBMTP_Get_Property_Description(LIBMTP_property_t inproperty)
+{
+  propertymap_t *current;
+
+  current = propertymap;
+
+  while (current != NULL) {
+    if(current->id == inproperty) {
+      return current->description;
+    }
+    current = current->next;
+  }
+
+  return "Unknown property";
+}
+
+/**
+ * This function will do its best to fit a 16bit
+ * value into a PTP object property if the property
+ * is limited in range or step sizes.
+ */
+static uint16_t adjust_u16(uint16_t val, PTPObjectPropDesc *opd)
+{
+  switch (opd->FormFlag) {
+  case PTP_DPFF_Range:
+    if (val < opd->FORM.Range.MinimumValue.u16) {
+      return opd->FORM.Range.MinimumValue.u16;
+    }
+    if (val > opd->FORM.Range.MaximumValue.u16) {
+      return opd->FORM.Range.MaximumValue.u16;
+    }
+    // Round down to last step.
+    if (val % opd->FORM.Range.StepSize.u16 != 0) {
+      return val - (val % opd->FORM.Range.StepSize.u16);
+    }
+    return val;
+    break;
+  case PTP_DPFF_Enumeration:
+    {
+      int i;
+      uint16_t bestfit = opd->FORM.Enum.SupportedValue[0].u16;
+      
+      for (i=0; i<opd->FORM.Enum.NumberOfValues; i++) {
+	if (val == opd->FORM.Enum.SupportedValue[i].u16) {
+	  return val;
+	}
+	// Rough guess of best fit
+	if (opd->FORM.Enum.SupportedValue[i].u16 < val) {
+	  bestfit = opd->FORM.Enum.SupportedValue[i].u16;
+	}
+      }
+      // Just some default that'll work.
+      return bestfit;
+    }
+  default:
+    // Will accept any value
+    break;
+  }
+  return val;
+}
+
+/**
+ * This function will do its best to fit a 32bit
+ * value into a PTP object property if the property
+ * is limited in range or step sizes.
+ */
+static uint32_t adjust_u32(uint32_t val, PTPObjectPropDesc *opd)
+{
+  switch (opd->FormFlag) {
+  case PTP_DPFF_Range:
+    if (val < opd->FORM.Range.MinimumValue.u32) {
+      return opd->FORM.Range.MinimumValue.u32;
+    }
+    if (val > opd->FORM.Range.MaximumValue.u32) {
+      return opd->FORM.Range.MaximumValue.u32;
+    }
+    // Round down to last step.
+    if (val % opd->FORM.Range.StepSize.u32 != 0) {
+      return val - (val % opd->FORM.Range.StepSize.u32);
+    }
+    return val;
+    break;
+  case PTP_DPFF_Enumeration:
+    {
+      int i;
+      uint32_t bestfit = opd->FORM.Enum.SupportedValue[0].u32;
+
+      for (i=0; i<opd->FORM.Enum.NumberOfValues; i++) {
+	if (val == opd->FORM.Enum.SupportedValue[i].u32) {
+	  return val;
+	}
+	// Rough guess of best fit
+	if (opd->FORM.Enum.SupportedValue[i].u32 < val) {
+	  bestfit = opd->FORM.Enum.SupportedValue[i].u32;
+	}
+      }
+      // Just some default that'll work.
+      return bestfit;
+    }
+  default:
+    // Will accept any value
+    break;
+  }
+  return val;
+}
+
+/**
+ * This function returns a newly created ISO 8601 timestamp with the
+ * current time in as high precision as possible. It even adds
+ * the time zone if it can.
+ */
+static char *get_iso8601_stamp(void)
+{
+  time_t curtime;
+  struct tm *loctime;
+  char tmp[64];
+
+  curtime = time(NULL);
+  loctime = localtime(&curtime);
+  strftime (tmp, sizeof(tmp), "%Y%m%dT%H%M%S.0%z", loctime);
+  return strdup(tmp);
+}
+
+/**
+ * Gets the allowed values (range or enum) for a property
+ * @param device a pointer to an MTP device
+ * @param property the property to query
+ * @param filetype the filetype of the object you want to set values for
+ * @param allowed_vals pointer to a LIBMTP_allowed_values_t struct to
+ *        receive the allowed values.  Call LIBMTP_destroy_allowed_values_t
+ *        on this on successful completion.
+ * @return 0 on success, any other value means failure
+ */
+int LIBMTP_Get_Allowed_Property_Values(LIBMTP_mtpdevice_t *device, LIBMTP_property_t const property,
+            LIBMTP_filetype_t const filetype, LIBMTP_allowed_values_t *allowed_vals)
+{
+  PTPObjectPropDesc opd;
+  uint16_t ret = 0;
+  
+  ret = ptp_mtp_getobjectpropdesc(device->params, map_libmtp_property_to_ptp_property(property), map_libmtp_type_to_ptp_type(filetype), &opd);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Allowed_Property_Values(): could not get property description.");
+    return -1;
+  }
+
+  if (opd.FormFlag == PTP_OPFF_Enumeration) {
+    int i = 0;
+    
+    allowed_vals->is_range = 0;
+    allowed_vals->num_entries = opd.FORM.Enum.NumberOfValues;
+
+    switch (opd.DataType)
+    {
+      case PTP_DTC_INT8:
+        allowed_vals->i8vals = malloc(sizeof(int8_t) * opd.FORM.Enum.NumberOfValues);
+        allowed_vals->datatype = LIBMTP_DATATYPE_INT8;
+        break;
+      case PTP_DTC_UINT8:
+        allowed_vals->u8vals = malloc(sizeof(uint8_t) * opd.FORM.Enum.NumberOfValues);
+        allowed_vals->datatype = LIBMTP_DATATYPE_UINT8;
+        break;
+      case PTP_DTC_INT16:
+        allowed_vals->i16vals = malloc(sizeof(int16_t) * opd.FORM.Enum.NumberOfValues);
+        allowed_vals->datatype = LIBMTP_DATATYPE_INT16;
+        break;
+      case PTP_DTC_UINT16:
+        allowed_vals->u16vals = malloc(sizeof(uint16_t) * opd.FORM.Enum.NumberOfValues);
+        allowed_vals->datatype = LIBMTP_DATATYPE_UINT16;
+        break;
+      case PTP_DTC_INT32:
+        allowed_vals->i32vals = malloc(sizeof(int32_t) * opd.FORM.Enum.NumberOfValues);
+        allowed_vals->datatype = LIBMTP_DATATYPE_INT32;
+        break;
+      case PTP_DTC_UINT32:
+        allowed_vals->u32vals = malloc(sizeof(uint32_t) * opd.FORM.Enum.NumberOfValues);
+        allowed_vals->datatype = LIBMTP_DATATYPE_UINT32;
+        break;
+      case PTP_DTC_INT64:
+        allowed_vals->i64vals = malloc(sizeof(int64_t) * opd.FORM.Enum.NumberOfValues);
+        allowed_vals->datatype = LIBMTP_DATATYPE_INT64;
+        break;
+      case PTP_DTC_UINT64:
+        allowed_vals->u64vals = malloc(sizeof(uint64_t) * opd.FORM.Enum.NumberOfValues);
+        allowed_vals->datatype = LIBMTP_DATATYPE_UINT64;
+        break;
+    }
+    
+    for (i = 0; i < opd.FORM.Enum.NumberOfValues; i++) {
+      switch (opd.DataType)
+      {
+        case PTP_DTC_INT8:
+          allowed_vals->i8vals[i] = opd.FORM.Enum.SupportedValue[i].i8;
+          break;
+        case PTP_DTC_UINT8:
+          allowed_vals->u8vals[i] = opd.FORM.Enum.SupportedValue[i].u8;
+          break;
+        case PTP_DTC_INT16:
+          allowed_vals->i16vals[i] = opd.FORM.Enum.SupportedValue[i].i16;
+          break;
+        case PTP_DTC_UINT16:
+          allowed_vals->u16vals[i] = opd.FORM.Enum.SupportedValue[i].u16;
+          break;
+        case PTP_DTC_INT32:
+          allowed_vals->i32vals[i] = opd.FORM.Enum.SupportedValue[i].i32;
+          break;
+        case PTP_DTC_UINT32:
+          allowed_vals->u32vals[i] = opd.FORM.Enum.SupportedValue[i].u32;
+          break;
+        case PTP_DTC_INT64:
+          allowed_vals->i64vals[i] = opd.FORM.Enum.SupportedValue[i].i64;
+          break;
+        case PTP_DTC_UINT64:
+          allowed_vals->u64vals[i] = opd.FORM.Enum.SupportedValue[i].u64;
+          break;
+      }
+    }
+    ptp_free_objectpropdesc(&opd);
+    return 0;
+  } else if (opd.FormFlag == PTP_OPFF_Range) {
+    allowed_vals->is_range = 1;
+    
+    switch (opd.DataType)
+    {
+      case PTP_DTC_INT8:
+        allowed_vals->i8min = opd.FORM.Range.MinimumValue.i8;
+        allowed_vals->i8max = opd.FORM.Range.MaximumValue.i8;
+        allowed_vals->i8step = opd.FORM.Range.StepSize.i8;
+        allowed_vals->datatype = LIBMTP_DATATYPE_INT8;
+        break;
+      case PTP_DTC_UINT8:
+        allowed_vals->u8min = opd.FORM.Range.MinimumValue.u8;
+        allowed_vals->u8max = opd.FORM.Range.MaximumValue.u8;
+        allowed_vals->u8step = opd.FORM.Range.StepSize.u8;
+        allowed_vals->datatype = LIBMTP_DATATYPE_UINT8;
+        break;
+      case PTP_DTC_INT16:
+        allowed_vals->i16min = opd.FORM.Range.MinimumValue.i16;
+        allowed_vals->i16max = opd.FORM.Range.MaximumValue.i16;
+        allowed_vals->i16step = opd.FORM.Range.StepSize.i16;
+        allowed_vals->datatype = LIBMTP_DATATYPE_INT16;
+        break;
+      case PTP_DTC_UINT16:
+        allowed_vals->u16min = opd.FORM.Range.MinimumValue.u16;
+        allowed_vals->u16max = opd.FORM.Range.MaximumValue.u16;
+        allowed_vals->u16step = opd.FORM.Range.StepSize.u16;
+        allowed_vals->datatype = LIBMTP_DATATYPE_UINT16;
+        break;
+      case PTP_DTC_INT32:
+        allowed_vals->i32min = opd.FORM.Range.MinimumValue.i32;
+        allowed_vals->i32max = opd.FORM.Range.MaximumValue.i32;
+        allowed_vals->i32step = opd.FORM.Range.StepSize.i32;
+        allowed_vals->datatype = LIBMTP_DATATYPE_INT32;
+        break;
+      case PTP_DTC_UINT32:
+        allowed_vals->u32min = opd.FORM.Range.MinimumValue.u32;
+        allowed_vals->u32max = opd.FORM.Range.MaximumValue.u32;
+        allowed_vals->u32step = opd.FORM.Range.StepSize.u32;
+        allowed_vals->datatype = LIBMTP_DATATYPE_UINT32;
+        break;
+      case PTP_DTC_INT64:
+        allowed_vals->i64min = opd.FORM.Range.MinimumValue.i64;
+        allowed_vals->i64max = opd.FORM.Range.MaximumValue.i64;
+        allowed_vals->i64step = opd.FORM.Range.StepSize.i64;
+        allowed_vals->datatype = LIBMTP_DATATYPE_INT64;
+        break;
+      case PTP_DTC_UINT64:
+        allowed_vals->u64min = opd.FORM.Range.MinimumValue.u64;
+        allowed_vals->u64max = opd.FORM.Range.MaximumValue.u64;
+        allowed_vals->u64step = opd.FORM.Range.StepSize.u64;
+        allowed_vals->datatype = LIBMTP_DATATYPE_UINT64;
+        break;
+    }
+    return 0; 
+  } else
+    return -1;
+}
+
+/**
+ * Destroys a LIBMTP_allowed_values_t struct
+ * @param allowed_vals the struct to destroy
+ */
+void LIBMTP_destroy_allowed_values_t(LIBMTP_allowed_values_t *allowed_vals)
+{
+  if (!allowed_vals->is_range)
+  {
+    switch (allowed_vals->datatype)
+    {
+      case LIBMTP_DATATYPE_INT8:
+        if (allowed_vals->i8vals)
+          free(allowed_vals->i8vals);
+        break;
+      case LIBMTP_DATATYPE_UINT8:
+        if (allowed_vals->u8vals)
+          free(allowed_vals->u8vals);
+        break;
+      case LIBMTP_DATATYPE_INT16:
+        if (allowed_vals->i16vals)
+          free(allowed_vals->i16vals);
+        break;
+      case LIBMTP_DATATYPE_UINT16:
+        if (allowed_vals->u16vals)
+          free(allowed_vals->u16vals);
+        break;
+      case LIBMTP_DATATYPE_INT32:
+        if (allowed_vals->i32vals)
+          free(allowed_vals->i32vals);
+        break;
+      case LIBMTP_DATATYPE_UINT32:
+        if (allowed_vals->u32vals)
+          free(allowed_vals->u32vals);
+        break;
+      case LIBMTP_DATATYPE_INT64:
+        if (allowed_vals->i64vals)
+          free(allowed_vals->i64vals);
+        break;
+      case LIBMTP_DATATYPE_UINT64:
+        if (allowed_vals->u64vals)
+          free(allowed_vals->u64vals);
+        break;
+    }
+  }
+}
+
+/**
+ * Determine if a property is supported for a given file type
+ * @param device a pointer to an MTP device
+ * @param property the property to query
+ * @param filetype the filetype of the object you want to set values for
+ * @return 0 if not supported, positive if supported, negative on error
+ */
+int LIBMTP_Is_Property_Supported(LIBMTP_mtpdevice_t *device, LIBMTP_property_t const property,
+            LIBMTP_filetype_t const filetype)
+{
+  uint16_t *props = NULL;
+  uint32_t propcnt = 0;
+  uint16_t ret = 0;
+  int i = 0;
+  int supported = 0;
+  uint16_t ptp_prop = map_libmtp_property_to_ptp_property(property);
+  
+  ret = ptp_mtp_getobjectpropssupported(device->params, map_libmtp_type_to_ptp_type(filetype), &propcnt, &props);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Is_Property_Supported(): could not get properties supported.");
+    return -1;
+  }
+
+	for (i = 0; i < propcnt; i++) {
+    if (props[i] == ptp_prop) {
+      supported = 1;
+      break;
+    }
+  }
+  
+  free(props);
+  
+  return supported;
+}
+
+/**
+ * Retrieves a string from an object
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id MTP attribute ID
+ * @return valid string or NULL on failure. The returned string
+ *         must bee <code>free()</code>:ed by the caller after
+ *         use.
+ */
+char *LIBMTP_Get_String_From_Object(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+				    LIBMTP_property_t const attribute_id)
+{
+  return get_string_from_object(device, object_id, attribute_id);
+}
+
+/**
+* Retrieves an unsigned 64-bit integer from an object attribute
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id MTP attribute ID
+ * @param value_default Default value to return on failure
+ * @return the value
+ */
+uint64_t LIBMTP_Get_u64_From_Object(LIBMTP_mtpdevice_t *device,uint32_t const object_id,
+                                    LIBMTP_property_t const attribute_id, uint64_t const value_default)
+{
+  return get_u64_from_object(device, object_id, map_libmtp_property_to_ptp_property(attribute_id), value_default);
+}
+
+/**
+ * Retrieves an unsigned 32-bit integer from an object attribute
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id MTP attribute ID
+ * @param value_default Default value to return on failure
+ * @return the value
+ */
+uint32_t LIBMTP_Get_u32_From_Object(LIBMTP_mtpdevice_t *device,uint32_t const object_id,
+				    LIBMTP_property_t const attribute_id, uint32_t const value_default)
+{
+  return get_u32_from_object(device, object_id, map_libmtp_property_to_ptp_property(attribute_id), value_default);
+}
+
+/**
+ * Retrieves an unsigned 16-bit integer from an object attribute
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id MTP attribute ID
+ * @param value_default Default value to return on failure
+ * @return a value
+ */
+uint16_t LIBMTP_Get_u16_From_Object(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+				    LIBMTP_property_t const attribute_id, uint16_t const value_default)
+{
+  return get_u16_from_object(device, object_id, map_libmtp_property_to_ptp_property(attribute_id), value_default);
+}
+
+/**
+ * Retrieves an unsigned 8-bit integer from an object attribute
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id MTP attribute ID
+ * @param value_default Default value to return on failure
+ * @return a value
+ */
+uint8_t LIBMTP_Get_u8_From_Object(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+				  LIBMTP_property_t const attribute_id, uint8_t const value_default)
+{
+  return get_u8_from_object(device, object_id, map_libmtp_property_to_ptp_property(attribute_id), value_default);
+}
+
+/**
+ * Sets an object attribute from a string
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id MTP attribute ID
+ * @param string string value to set
+ * @return 0 on success, any other value means failure
+ */
+int LIBMTP_Set_Object_String(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+			     LIBMTP_property_t const attribute_id, char const * const string)
+{
+  return set_object_string(device, object_id, map_libmtp_property_to_ptp_property(attribute_id), string);
+}
+
+
+/**
+ * Sets an object attribute from an unsigned 32-bit integer
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id MTP attribute ID
+ * @param value 32-bit unsigned integer to set
+ * @return 0 on success, any other value means failure
+ */
+int LIBMTP_Set_Object_u32(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+			  LIBMTP_property_t const attribute_id, uint32_t const value)
+{
+  return set_object_u32(device, object_id, map_libmtp_property_to_ptp_property(attribute_id), value);
+}
+
+/**
+ * Sets an object attribute from an unsigned 16-bit integer
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id MTP attribute ID
+ * @param value 16-bit unsigned integer to set
+ * @return 0 on success, any other value means failure
+ */
+int LIBMTP_Set_Object_u16(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+			  LIBMTP_property_t const attribute_id, uint16_t const value)
+{
+  return set_object_u16(device, object_id, map_libmtp_property_to_ptp_property(attribute_id), value);
+}
+
+/**
+ * Sets an object attribute from an unsigned 8-bit integer
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id MTP attribute ID
+ * @param value 8-bit unsigned integer to set
+ * @return 0 on success, any other value means failure
+ */
+int LIBMTP_Set_Object_u8(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+			 LIBMTP_property_t const attribute_id, uint8_t const value)
+{
+  return set_object_u8(device, object_id, map_libmtp_property_to_ptp_property(attribute_id), value);
+}
+
+/**
+ * Retrieves a string from an object
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id PTP attribute ID
+ * @return valid string or NULL on failure. The returned string
+ *         must bee <code>free()</code>:ed by the caller after
+ *         use.
+ */
+static char *get_string_from_object(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+				    uint16_t const attribute_id)
+{
+  PTPPropertyValue propval;
+  char *retstring = NULL;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+  MTPProperties *prop;
+
+  if ( device == NULL || object_id == 0) {
+    return NULL;
+  }
+  
+  prop = ptp_find_object_prop_in_cache(params, object_id, attribute_id);
+  if (prop) {
+    if (prop->propval.str != NULL)
+      return strdup(prop->propval.str);
+    else
+      return NULL;
+  }
+
+  ret = ptp_mtp_getobjectpropvalue(params, object_id, attribute_id, &propval, PTP_DTC_STR);
+  if (ret == PTP_RC_OK) {
+    if (propval.str != NULL) {
+      retstring = (char *) strdup(propval.str);
+      free(propval.str);
+    }
+  } else {
+    add_ptp_error_to_errorstack(device, ret, "get_string_from_object(): could not get object string.");
+  }
+
+  return retstring;
+}
+
+/**
+* Retrieves an unsigned 64-bit integer from an object attribute
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id PTP attribute ID
+ * @param value_default Default value to return on failure
+ * @return the value
+ */
+static uint64_t get_u64_from_object(LIBMTP_mtpdevice_t *device,uint32_t const object_id,
+                                    uint16_t const attribute_id, uint64_t const value_default)
+{
+  PTPPropertyValue propval;
+  uint64_t retval = value_default;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+  MTPProperties *prop;
+  
+  if ( device == NULL ) {
+    return value_default;
+  }
+  
+  prop = ptp_find_object_prop_in_cache(params, object_id, attribute_id);
+  if (prop)
+    return prop->propval.u64;
+
+  ret = ptp_mtp_getobjectpropvalue(params, object_id,
+                                   attribute_id,
+                                   &propval,
+                                   PTP_DTC_UINT64);
+  if (ret == PTP_RC_OK) {
+    retval = propval.u64;
+  } else {
+    add_ptp_error_to_errorstack(device, ret, "get_u64_from_object(): could not get unsigned 64bit integer from object.");
+  }
+  
+  return retval;
+}
+
+/**
+ * Retrieves an unsigned 32-bit integer from an object attribute
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id PTP attribute ID
+ * @param value_default Default value to return on failure
+ * @return the value
+ */
+static uint32_t get_u32_from_object(LIBMTP_mtpdevice_t *device,uint32_t const object_id,
+				    uint16_t const attribute_id, uint32_t const value_default)
+{
+  PTPPropertyValue propval;
+  uint32_t retval = value_default;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+  MTPProperties *prop;
+
+  if ( device == NULL ) {
+    return value_default;
+  }
+
+  prop = ptp_find_object_prop_in_cache(params, object_id, attribute_id);
+  if (prop)
+    return prop->propval.u32;
+
+  ret = ptp_mtp_getobjectpropvalue(params, object_id,
+                                   attribute_id,
+                                   &propval,
+                                   PTP_DTC_UINT32);
+  if (ret == PTP_RC_OK) {
+    retval = propval.u32;
+  } else {
+    add_ptp_error_to_errorstack(device, ret, "get_u32_from_object(): could not get unsigned 32bit integer from object.");
+  }
+  return retval;
+}
+
+/**
+ * Retrieves an unsigned 16-bit integer from an object attribute
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id PTP attribute ID
+ * @param value_default Default value to return on failure
+ * @return a value
+ */
+static uint16_t get_u16_from_object(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+				    uint16_t const attribute_id, uint16_t const value_default)
+{
+  PTPPropertyValue propval;
+  uint16_t retval = value_default;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+  MTPProperties *prop;
+
+  if ( device == NULL ) {
+    return value_default;
+  }
+
+  // This O(n) search should not be used so often, since code
+  // using the cached properties don't usually call this function.
+  prop = ptp_find_object_prop_in_cache(params, object_id, attribute_id);
+  if (prop)
+    return prop->propval.u16;
+
+  ret = ptp_mtp_getobjectpropvalue(params, object_id,
+                                   attribute_id,
+                                   &propval,
+                                   PTP_DTC_UINT16);
+  if (ret == PTP_RC_OK) {
+    retval = propval.u16;
+  } else {
+    add_ptp_error_to_errorstack(device, ret, "get_u16_from_object(): could not get unsigned 16bit integer from object.");
+  }
+
+  return retval;
+}
+
+/**
+ * Retrieves an unsigned 8-bit integer from an object attribute
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id PTP attribute ID
+ * @param value_default Default value to return on failure
+ * @return a value
+ */
+static uint8_t get_u8_from_object(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+				  uint16_t const attribute_id, uint8_t const value_default)
+{
+  PTPPropertyValue propval;
+  uint8_t retval = value_default;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+  MTPProperties *prop;
+
+  if ( device == NULL ) {
+    return value_default;
+  }
+
+  // This O(n) search should not be used so often, since code
+  // using the cached properties don't usually call this function.
+  prop = ptp_find_object_prop_in_cache(params, object_id, attribute_id);
+  if (prop)
+    return prop->propval.u8;
+
+  ret = ptp_mtp_getobjectpropvalue(params, object_id,
+                                   attribute_id,
+                                   &propval,
+                                   PTP_DTC_UINT8);
+  if (ret == PTP_RC_OK) {
+    retval = propval.u8;
+  } else {
+    add_ptp_error_to_errorstack(device, ret, "get_u8_from_object(): could not get unsigned 8bit integer from object.");
+  }
+
+  return retval;
+}
+
+/**
+ * Sets an object attribute from a string
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id PTP attribute ID
+ * @param string string value to set
+ * @return 0 on success, any other value means failure
+ */
+static int set_object_string(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+			     uint16_t const attribute_id, char const * const string)
+{
+  PTPPropertyValue propval;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+
+  if (device == NULL || string == NULL) {
+    return -1;
+  }
+  
+  if (!ptp_operation_issupported(params,PTP_OC_MTP_SetObjectPropValue)) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "set_object_string(): could not set object string: "
+				"PTP_OC_MTP_SetObjectPropValue not supported.");
+    return -1;
+  }
+  propval.str = (char *) string;
+  ret = ptp_mtp_setobjectpropvalue(params, object_id, attribute_id, &propval, PTP_DTC_STR);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "set_object_string(): could not set object string.");
+    return -1;
+  }
+
+  return 0;
+}
+
+
+/**
+ * Sets an object attribute from an unsigned 32-bit integer
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id PTP attribute ID
+ * @param value 32-bit unsigned integer to set
+ * @return 0 on success, any other value means failure
+ */
+static int set_object_u32(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+			  uint16_t const attribute_id, uint32_t const value)
+{
+  PTPPropertyValue propval;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+
+  if (device == NULL) {
+    return -1;
+  }
+
+  if (!ptp_operation_issupported(params,PTP_OC_MTP_SetObjectPropValue)) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "set_object_u32(): could not set unsigned 32bit integer property: "
+				"PTP_OC_MTP_SetObjectPropValue not supported.");
+    return -1;
+  }
+  
+  propval.u32 = value;
+  ret = ptp_mtp_setobjectpropvalue(params, object_id, attribute_id, &propval, PTP_DTC_UINT32);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "set_object_u32(): could not set unsigned 32bit integer property.");
+    return -1;
+  }
+
+  return 0;
+}
+
+/**
+ * Sets an object attribute from an unsigned 16-bit integer
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id PTP attribute ID
+ * @param value 16-bit unsigned integer to set
+ * @return 0 on success, any other value means failure
+ */
+static int set_object_u16(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+			  uint16_t const attribute_id, uint16_t const value)
+{
+  PTPPropertyValue propval;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+
+  if (device == NULL) {
+    return 1;
+  }
+
+  if (!ptp_operation_issupported(params,PTP_OC_MTP_SetObjectPropValue)) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "set_object_u16(): could not set unsigned 16bit integer property: "
+				"PTP_OC_MTP_SetObjectPropValue not supported.");
+    return -1;
+  }
+  propval.u16 = value;
+  ret = ptp_mtp_setobjectpropvalue(params, object_id, attribute_id, &propval, PTP_DTC_UINT16);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "set_object_u16(): could not set unsigned 16bit integer property.");
+    return 1;
+  }
+
+  return 0;
+}
+
+/**
+ * Sets an object attribute from an unsigned 8-bit integer
+ *
+ * @param device a pointer to an MTP device.
+ * @param object_id Object reference
+ * @param attribute_id PTP attribute ID
+ * @param value 8-bit unsigned integer to set
+ * @return 0 on success, any other value means failure
+ */
+static int set_object_u8(LIBMTP_mtpdevice_t *device, uint32_t const object_id,
+			 uint16_t const attribute_id, uint8_t const value)
+{
+  PTPPropertyValue propval;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+
+  if (device == NULL) {
+    return 1;
+  }
+
+  if (!ptp_operation_issupported(params,PTP_OC_MTP_SetObjectPropValue)) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "set_object_u8(): could not set unsigned 8bit integer property: "
+			    "PTP_OC_MTP_SetObjectPropValue not supported.");
+    return -1;
+  }
+  propval.u8 = value;
+  ret = ptp_mtp_setobjectpropvalue(params, object_id, attribute_id, &propval, PTP_DTC_UINT8);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "set_object_u8(): could not set unsigned 8bit integer property.");
+    return 1;
+  }
+
+  return 0;
+}
+
+/**
+ * Get the first (as in "first in the list of") connected MTP device.
+ * @return a device pointer.
+ * @see LIBMTP_Get_Connected_Devices()
+ */
+LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void)
+{
+  LIBMTP_mtpdevice_t *first_device = NULL;
+  LIBMTP_raw_device_t *devices;
+  int numdevs;
+  LIBMTP_error_number_t ret;
+  
+  ret = LIBMTP_Detect_Raw_Devices(&devices, &numdevs);
+  if (ret != LIBMTP_ERROR_NONE) {
+    return NULL;
+  }
+
+  if (devices == NULL || numdevs == 0) {
+    return NULL;
+  }
+
+  first_device = LIBMTP_Open_Raw_Device(&devices[0]);
+  free(devices);
+  return first_device;
+}
+
+/**
+ * Overriding debug function.
+ * This way we can disable debug prints.
+ */
+static void
+#ifdef __GNUC__
+__attribute__((__format__(printf,2,0)))
+#endif
+LIBMTP_ptp_debug(void *data, const char *format, va_list args)
+{
+#ifdef ENABLE_PTP_DEBUG
+  vfprintf (stderr, format, args);
+  fflush (stderr);
+#endif
+}
+
+/**
+ * Overriding error function.
+ * This way we can capture all error etc to our errorstack.
+ */
+static void
+#ifdef __GNUC__
+__attribute__((__format__(printf,2,0)))
+#endif
+LIBMTP_ptp_error(void *data, const char *format, va_list args)
+{
+  // if (data == NULL) {
+    vfprintf (stderr, format, args);
+    fflush (stderr);
+  /*
+    FIXME: find out how we shall get the device here.
+  } else {
+    PTP_USB *ptp_usb = data;
+    LIBMTP_mtpdevice_t *device = ...;
+    char buf[2048];
+
+    vsnprintf (buf, sizeof (buf), format, args);
+    add_error_to_errorstack(device,
+			    LIBMTP_ERROR_PTP_LAYER,
+			    buf);
+  }
+  */
+}
+
+/**
+ * This function opens a device from a raw device. It is the
+ * preferred way to access devices in the new interface where
+ * several devices can come and go as the library is working
+ * on a certain device.
+ * @param rawdevice the raw device to open a "real" device for.
+ * @return an open device.
+ */
+LIBMTP_mtpdevice_t *LIBMTP_Open_Raw_Device(LIBMTP_raw_device_t *rawdevice)
+{
+  LIBMTP_mtpdevice_t *mtp_device;
+  uint8_t bs = 0;
+  PTPParams *current_params;
+  PTP_USB *ptp_usb;
+  LIBMTP_error_number_t err;
+  int i;
+
+  /* Allocate dynamic space for our device */
+  mtp_device = (LIBMTP_mtpdevice_t *) malloc(sizeof(LIBMTP_mtpdevice_t));
+  memset(mtp_device, 0, sizeof(LIBMTP_mtpdevice_t));
+  /* Check if there was a memory allocation error */
+  if(mtp_device == NULL) {
+    /* There has been an memory allocation error. We are going to ignore this
+       device and attempt to continue */
+    
+    /* TODO: This error statement could probably be a bit more robust */
+    fprintf(stderr, "LIBMTP PANIC: connect_usb_devices encountered a memory "
+	    "allocation error with device %d on bus %d, trying to continue",
+	    rawdevice->devnum, rawdevice->bus_location);
+    
+    return NULL;
+  }
+
+  /* Create PTP params */
+  current_params = (PTPParams *) malloc(sizeof(PTPParams));
+  if (current_params == NULL) {
+    free(mtp_device);
+    return NULL;
+  }
+  memset(current_params, 0, sizeof(PTPParams));
+  current_params->device_flags = rawdevice->device_entry.device_flags;
+  current_params->nrofobjects = 0;
+  current_params->objects = NULL;
+  current_params->response_packet_size = 0;
+  current_params->response_packet = NULL;
+  /* This will be a pointer to PTP_USB later */
+  current_params->data = NULL;
+  /* Set upp local debug and error functions */
+  current_params->debug_func = LIBMTP_ptp_debug;
+  current_params->error_func = LIBMTP_ptp_error;
+  /* TODO: Will this always be little endian? */
+  current_params->byteorder = PTP_DL_LE;
+  current_params->cd_locale_to_ucs2 = iconv_open("UCS-2LE", "UTF-8");
+  current_params->cd_ucs2_to_locale = iconv_open("UTF-8", "UCS-2LE");
+    
+  if(current_params->cd_locale_to_ucs2 == (iconv_t) -1 ||
+     current_params->cd_ucs2_to_locale == (iconv_t) -1) {
+    fprintf(stderr, "LIBMTP PANIC: Cannot open iconv() converters to/from UCS-2!\n"
+	    "Too old stdlibc, glibc and libiconv?\n");
+    free(current_params);
+    free(mtp_device);
+    return NULL;
+  }
+  mtp_device->params = current_params;
+
+  
+  /* Create usbinfo, this also opens the session */
+  err = configure_usb_device(rawdevice,
+			     current_params,
+			     &mtp_device->usbinfo);
+  if (err != LIBMTP_ERROR_NONE) {
+    free(current_params);
+    free(mtp_device);
+    return NULL;
+  }
+  ptp_usb = (PTP_USB*) mtp_device->usbinfo;
+  /* Set pointer back to params */
+  ptp_usb->params = current_params;
+
+  
+  /* Cache the device information for later use */
+  if (ptp_getdeviceinfo(current_params,
+			&current_params->deviceinfo) != PTP_RC_OK) {
+    fprintf(stderr, "LIBMTP PANIC: Unable to read device information on device "
+	    "%d on bus %d, trying to continue",
+	    rawdevice->devnum, rawdevice->bus_location);
+    
+    /* Prevent memory leaks for this device */
+    free(mtp_device->usbinfo);
+    free(mtp_device->params);
+    current_params = NULL;
+    free(mtp_device);    
+    return NULL;
+  }
+  
+  /* Determine if the object size supported is 32 or 64 bit wide */
+  for (i=0;i<current_params->deviceinfo.ImageFormats_len;i++) {
+    PTPObjectPropDesc opd;
+    
+    if (ptp_mtp_getobjectpropdesc(current_params, 
+				  PTP_OPC_ObjectSize, 
+				  current_params->deviceinfo.ImageFormats[i], 
+				  &opd) != PTP_RC_OK) {
+      printf("LIBMTP PANIC: "
+	     "could not inspect object property descriptions!\n");
+    } else {
+      if (opd.DataType == PTP_DTC_UINT32) {
+	if (bs == 0) {
+	  bs = 32;
+	} else if (bs != 32) {
+	  printf("LIBMTP PANIC: "
+		 "different objects support different object sizes!\n");
+	  bs = 0;
+	  break;
+	}
+      } else if (opd.DataType == PTP_DTC_UINT64) {
+	if (bs == 0) {
+	  bs = 64;
+	} else if (bs != 64) {
+	  printf("LIBMTP PANIC: "
+		 "different objects support different object sizes!\n");
+	  bs = 0;
+	  break;
+	}
+      } else {
+	// Ignore if other size.
+	printf("LIBMTP PANIC: "
+	       "awkward object size data type: %04x\n", opd.DataType);
+	bs = 0;
+	break;
+      }
+    }
+  }
+  if (bs == 0) {
+    // Could not detect object bitsize, assume 32 bits
+    bs = 32;
+  }
+  mtp_device->object_bitsize = bs;
+  
+  /* No Errors yet for this device */
+  mtp_device->errorstack = NULL;
+  
+  /* Default Max Battery Level, we will adjust this if possible */
+  mtp_device->maximum_battery_level = 100;
+  
+  /* Check if device supports reading maximum battery level */
+  if(!FLAG_BROKEN_BATTERY_LEVEL(ptp_usb) && 
+     ptp_property_issupported( current_params, PTP_DPC_BatteryLevel)) {
+    PTPDevicePropDesc dpd;
+    
+    /* Try to read maximum battery level */
+    if(ptp_getdevicepropdesc(current_params,
+			     PTP_DPC_BatteryLevel,
+			     &dpd) != PTP_RC_OK) {
+      add_error_to_errorstack(mtp_device,
+			      LIBMTP_ERROR_CONNECTING,
+			      "Unable to read Maximum Battery Level for this "
+			      "device even though the device supposedly "
+			      "supports this functionality");
+    }
+    
+    /* TODO: is this appropriate? */
+    /* If max battery level is 0 then leave the default, otherwise assign */
+    if (dpd.FORM.Range.MaximumValue.u8 != 0) {
+      mtp_device->maximum_battery_level = dpd.FORM.Range.MaximumValue.u8;
+    }
+    
+    ptp_free_devicepropdesc(&dpd);
+  }
+  
+  /* Set all default folders to 0 (root directory) */
+  mtp_device->default_music_folder = 0;
+  mtp_device->default_playlist_folder = 0;
+  mtp_device->default_picture_folder = 0;
+  mtp_device->default_video_folder = 0;
+  mtp_device->default_organizer_folder = 0;
+  mtp_device->default_zencast_folder = 0;
+  mtp_device->default_album_folder = 0;
+  mtp_device->default_text_folder = 0;
+  
+  /* Set initial storage information */
+  mtp_device->storage = NULL;
+  if (LIBMTP_Get_Storage(mtp_device, LIBMTP_STORAGE_SORTBY_NOTSORTED) == -1) {
+    add_error_to_errorstack(mtp_device,
+			    LIBMTP_ERROR_GENERAL,
+			    "Get Storage information failed.");
+    mtp_device->storage = NULL;
+  }
+  
+  /*
+   * Then get the handles and try to locate the default folders.
+   * This has the desired side effect of caching all handles from
+   * the device which speeds up later operations.
+   */
+  flush_handles(mtp_device);
+
+  return mtp_device;
+}
+
+/**
+ * Recursive function that adds MTP devices to a linked list
+ * @param devices a list of raw devices to have real devices created for.
+ * @return a device pointer to a newly created mtpdevice (used in linked
+ * list creation).
+ */
+static LIBMTP_mtpdevice_t * create_usb_mtp_devices(LIBMTP_raw_device_t *devices, int numdevs)
+{
+  uint8_t i;
+  LIBMTP_mtpdevice_t *mtp_device_list = NULL;
+  LIBMTP_mtpdevice_t *current_device = NULL;
+
+  for (i=0; i < numdevs; i++) {
+    LIBMTP_mtpdevice_t *mtp_device;
+    mtp_device = LIBMTP_Open_Raw_Device(&devices[i]);
+
+    /* On error, try next device */
+    if (mtp_device == NULL)
+      continue;
+
+    /* Add the device to the list */
+    mtp_device->next = NULL;
+    if (mtp_device_list == NULL) {
+      mtp_device_list = current_device = mtp_device;
+    } else {
+      current_device->next = mtp_device;
+      current_device = mtp_device;
+    }
+  }
+  return mtp_device_list;
+}
+
+/**
+ * Get the number of devices that are available in the listed device list
+ * @param device_list Pointer to a linked list of devices
+ * @return Number of devices in the device list device_list
+ * @see LIBMTP_Get_Connected_Devices()
+ */ 
+uint32_t LIBMTP_Number_Devices_In_List(LIBMTP_mtpdevice_t *device_list)
+{
+  uint32_t numdevices = 0;
+  LIBMTP_mtpdevice_t *iter;
+  for(iter = device_list; iter != NULL; iter = iter->next)
+    numdevices++;
+  
+  return numdevices;
+}
+
+/**
+ * Get the first connected MTP device node in the linked list of devices.
+ * Currently this only provides access to USB devices
+ * @param device_list A list of devices ready to be used by the caller. You
+ *        need to know how many there are.
+ * @return Any error information gathered from device connections
+ * @see LIBMTP_Number_Devices_In_List()
+ */
+LIBMTP_error_number_t LIBMTP_Get_Connected_Devices(LIBMTP_mtpdevice_t **device_list)
+{
+  LIBMTP_raw_device_t *devices;
+  int numdevs;
+  LIBMTP_error_number_t ret;
+  
+  ret = LIBMTP_Detect_Raw_Devices(&devices, &numdevs);
+  if (ret != LIBMTP_ERROR_NONE) {
+    *device_list = NULL;
+    return ret;
+  }
+
+  /* Assign linked list of devices */
+  if (devices == NULL || numdevs == 0) {
+    *device_list = NULL;
+    return LIBMTP_ERROR_NO_DEVICE_ATTACHED;
+  }
+
+  *device_list = create_usb_mtp_devices(devices, numdevs);
+  free(devices);
+
+  /* TODO: Add wifi device access here */
+  
+  /* We have found some devices but create failed */
+  if (*device_list == NULL)
+    return LIBMTP_ERROR_CONNECTING;
+
+  return LIBMTP_ERROR_NONE;
+}
+
+/**
+ * This closes and releases an allocated MTP device.
+ * @param device a pointer to the MTP device to release.
+ */
+void LIBMTP_Release_Device_List(LIBMTP_mtpdevice_t *device)
+{
+  if(device != NULL)
+  {
+    if(device->next != NULL)
+    {
+      LIBMTP_Release_Device_List(device->next);
+    }
+    
+    LIBMTP_Release_Device(device);
+  }
+}
+
+/**
+ * This closes and releases an allocated MTP device.
+ * @param device a pointer to the MTP device to release.
+ */
+void LIBMTP_Release_Device(LIBMTP_mtpdevice_t *device)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+
+  close_device(ptp_usb, params);
+  // Clear error stack
+  LIBMTP_Clear_Errorstack(device);
+  // Free iconv() converters...
+  iconv_close(params->cd_locale_to_ucs2);
+  iconv_close(params->cd_ucs2_to_locale);
+  free(ptp_usb);  
+  ptp_free_params(params);
+  free_storage_list(device);
+  free(device);
+}
+
+/**
+ * This can be used by any libmtp-intrinsic code that
+ * need to stack up an error on the stack. You are only
+ * supposed to add errors to the error stack using this
+ * function, do not create and reference error entries
+ * directly.
+ */
+static void add_error_to_errorstack(LIBMTP_mtpdevice_t *device,
+				    LIBMTP_error_number_t errornumber,
+				    char const * const error_text)
+{
+  LIBMTP_error_t *newerror;
+  
+  if (device == NULL) {
+    fprintf(stderr, "LIBMTP PANIC: Trying to add error to a NULL device!\n");
+    return;
+  }
+  newerror = (LIBMTP_error_t *) malloc(sizeof(LIBMTP_error_t));
+  newerror->errornumber = errornumber;
+  newerror->error_text = strdup(error_text);
+  newerror->next = NULL;
+  if (device->errorstack == NULL) {
+    device->errorstack = newerror;
+  } else {
+    LIBMTP_error_t *tmp = device->errorstack;
+    
+    while (tmp->next != NULL) {
+      tmp = tmp->next;
+    }
+    tmp->next = newerror;
+  }
+}
+
+/**
+ * Adds an error from the PTP layer to the error stack.
+ */
+static void add_ptp_error_to_errorstack(LIBMTP_mtpdevice_t *device,
+					uint16_t ptp_error,
+					char const * const error_text)
+{
+  if (device == NULL) {
+    fprintf(stderr, "LIBMTP PANIC: Trying to add PTP error to a NULL device!\n");
+    return;
+  } else {
+    char outstr[256];
+    snprintf(outstr, sizeof(outstr), "PTP Layer error %04x: %s", ptp_error, error_text);
+    outstr[sizeof(outstr)-1] = '\0';
+    add_error_to_errorstack(device, LIBMTP_ERROR_PTP_LAYER, outstr);
+    add_error_to_errorstack(device, LIBMTP_ERROR_PTP_LAYER, "(Look this up in ptp.h for an explanation.)");
+  }
+}
+
+/**
+ * This returns the error stack for a device in case you
+ * need to either reference the error numbers (e.g. when
+ * creating multilingual apps with multiple-language text
+ * representations for each error number) or when you need
+ * to build a multi-line error text widget or something like
+ * that. You need to call the <code>LIBMTP_Clear_Errorstack</code>
+ * to clear it when you're finished with it.
+ * @param device a pointer to the MTP device to get the error
+ *        stack for.
+ * @return the error stack or NULL if there are no errors
+ *         on the stack.
+ * @see LIBMTP_Clear_Errorstack()
+ * @see LIBMTP_Dump_Errorstack()
+ */
+LIBMTP_error_t *LIBMTP_Get_Errorstack(LIBMTP_mtpdevice_t *device)
+{
+  if (device == NULL) {
+    fprintf(stderr, "LIBMTP PANIC: Trying to get the error stack of a NULL device!\n");
+    return NULL;
+  }
+  return device->errorstack;
+}
+
+/**
+ * This function clears the error stack of a device and frees
+ * any memory used by it. Call this when you're finished with
+ * using the errors.
+ * @param device a pointer to the MTP device to clear the error
+ *        stack for.
+ */
+void LIBMTP_Clear_Errorstack(LIBMTP_mtpdevice_t *device)
+{
+  if (device == NULL) {
+    fprintf(stderr, "LIBMTP PANIC: Trying to clear the error stack of a NULL device!\n");
+  } else {
+    LIBMTP_error_t *tmp = device->errorstack;
+  
+    while (tmp != NULL) {
+      LIBMTP_error_t *tmp2;
+      
+      if (tmp->error_text != NULL) {
+	free(tmp->error_text);
+      }
+      tmp2 = tmp;
+      tmp = tmp->next;
+      free(tmp2);
+    }
+    device->errorstack = NULL;
+  }
+}
+
+/**
+ * This function dumps the error stack to <code>stderr</code>.
+ * (You still have to clear the stack though.)
+ * @param device a pointer to the MTP device to dump the error
+ *        stack for.
+ */
+void LIBMTP_Dump_Errorstack(LIBMTP_mtpdevice_t *device)
+{
+  if (device == NULL) {
+    fprintf(stderr, "LIBMTP PANIC: Trying to dump the error stack of a NULL device!\n");
+  } else {
+    LIBMTP_error_t *tmp = device->errorstack;
+
+    while (tmp != NULL) {
+      if (tmp->error_text != NULL) {
+	fprintf(stderr, "Error %d: %s\n", tmp->errornumber, tmp->error_text);
+      } else {
+	fprintf(stderr, "Error %d: (unknown)\n", tmp->errornumber);
+      }
+      tmp = tmp->next;
+    }
+  }
+}
+
+void LIBMTP_Set_Device_Timeout(LIBMTP_mtpdevice_t *device, int milliseconds)
+{
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  set_usb_device_timeout(ptp_usb, milliseconds);
+}
+
+void LIBMTP_Get_Device_Timeout(LIBMTP_mtpdevice_t *device, int * milliseconds)
+{
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  get_usb_device_timeout(ptp_usb, milliseconds);
+}
+
+/**
+ * This command gets all handles and stuff by FAST directory retrieveal 
+ * which is available by getting all metadata for object 
+ * <code>0xffffffff</code> which simply means "all metadata for all objects".
+ * This works on the vast majority of MTP devices (there ARE exceptions!)
+ * and is quite quick. Check the error stack to see if there were
+ * problems getting the metadata.
+ * @return 0 if all was OK, -1 on failure.
+ */
+static int get_all_metadata_fast(LIBMTP_mtpdevice_t *device,
+				 uint32_t storage)
+{
+  PTPParams      *params = (PTPParams *) device->params;
+  int		 cnt = 0;
+  int            i, j, nrofprops;
+  uint32_t	 lasthandle = 0xffffffff;
+  MTPProperties  *props = NULL;
+  MTPProperties  *prop;
+  uint16_t       ret;
+  int            oldtimeout;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+
+  /* The follow request causes the device to generate
+   * a list of very file on the device and return it
+   * in a single response.
+   *
+   * Some slow devices as well as devices with very
+   * large file systems can easily take longer then
+   * the standard timeout value before it is able
+   * to return a response.
+   *
+   * Temporarly set timeout to allow working with
+   * widest range of devices.
+   */
+  get_usb_device_timeout(ptp_usb, &oldtimeout);
+  set_usb_device_timeout(ptp_usb, 60000);
+  
+  ret = ptp_mtp_getobjectproplist(params, 0xffffffff, &props, &nrofprops);
+  set_usb_device_timeout(ptp_usb, oldtimeout);
+
+  if (ret == PTP_RC_MTP_Specification_By_Group_Unsupported) {
+    // What's the point in the device implementing this command if 
+    // you cannot use it to get all props for AT LEAST one object?
+    // Well, whatever...
+    add_ptp_error_to_errorstack(device, ret, "get_all_metadata_fast(): "
+    "cannot retrieve all metadata for an object on this device.");
+    return -1;
+  }
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "get_all_metadata_fast(): "
+    "could not get proplist of all objects.");
+    return -1;
+  }
+  if (props == NULL && nrofprops != 0) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL,
+			    "get_all_metadata_fast(): "
+			    "call to ptp_mtp_getobjectproplist() returned "
+			    "inconsistent results.");
+    return -1;
+  }
+  /* 
+   * We count the number of objects by counting the ObjectHandle
+   * references, whenever it changes we get a new object, when it's
+   * the same, it is just different properties of the same object.
+   */
+  prop = props;
+  for (i=0;i<nrofprops;i++) {
+      if (lasthandle != prop->ObjectHandle) {
+	cnt++;
+	lasthandle = prop->ObjectHandle;
+      }
+      prop++;
+  }
+  lasthandle = 0xffffffff;
+  params->objects = calloc (sizeof(PTPObject),cnt);
+  prop = props;
+  i = -1;
+  for (j=0;j<nrofprops;j++) {
+    if (lasthandle != prop->ObjectHandle) {
+      if (i >= 0) {
+        params->objects[i].flags |= PTPOBJECT_OBJECTINFO_LOADED;
+	if (!params->objects[i].oi.Filename) {
+	  /* I have one such file on my Creative (Marcus) */
+	  params->objects[i].oi.Filename = strdup("<null>");
+	}
+      }
+      i++;
+      lasthandle = prop->ObjectHandle;
+      params->objects[i].oid = prop->ObjectHandle;
+    }
+    switch (prop->property) {
+    case PTP_OPC_ParentObject:
+      params->objects[i].oi.ParentObject = prop->propval.u32;
+      params->objects[i].flags |= PTPOBJECT_PARENTOBJECT_LOADED;
+      break;
+    case PTP_OPC_ObjectFormat:
+      params->objects[i].oi.ObjectFormat = prop->propval.u16;
+      break;
+    case PTP_OPC_ObjectSize:
+      // We loose precision here, up to 32 bits! However the commands that
+      // retrieve metadata for files and tracks will make sure that the
+      // PTP_OPC_ObjectSize is read in and duplicated again.
+      if (device->object_bitsize == 64) {
+	params->objects[i].oi.ObjectCompressedSize = (uint32_t) prop->propval.u64;
+      } else {
+	params->objects[i].oi.ObjectCompressedSize = prop->propval.u32;
+      }
+      break;
+    case PTP_OPC_StorageID:
+      params->objects[i].oi.StorageID = prop->propval.u32;
+      params->objects[i].flags |= PTPOBJECT_STORAGEID_LOADED;
+      break;
+    case PTP_OPC_ObjectFileName:
+      if (prop->propval.str != NULL)
+        params->objects[i].oi.Filename = strdup(prop->propval.str);
+      break;
+    default: {
+      MTPProperties *newprops;
+
+      /* Copy all of the other MTP oprierties into the per-object proplist */
+      if (params->objects[i].nrofmtpprops) {
+        newprops = realloc(params->objects[i].mtpprops,(params->objects[i].nrofmtpprops+1)*sizeof(MTPProperties));
+      } else {
+        newprops = calloc(sizeof(MTPProperties),1);
+      }
+      if (!newprops) return 0; /* FIXME: error handling? */
+      params->objects[i].mtpprops = newprops;
+      memcpy(&params->objects[i].mtpprops[params->objects[i].nrofmtpprops],&props[j],sizeof(props[j]));
+      params->objects[i].nrofmtpprops++;
+      params->objects[i].flags |= PTPOBJECT_MTPPROPLIST_LOADED;
+      break;
+    }
+    }
+    prop++;
+  }
+  /* mark last entry also */
+  params->objects[i].flags |= PTPOBJECT_OBJECTINFO_LOADED;
+  params->nrofobjects = i+1;
+  /* The device might not give the list in linear ascending order */
+  ptp_objects_sort (params);
+  return 0;
+}
+
+/**
+ * This function will recurse through all the directories on the device,
+ * starting at the root directory, gathering metadata as it moves along.
+ * It works better on some devices that will only return data for a
+ * certain directory and does not respect the option to get all metadata
+ * for all objects.
+ */
+static void get_handles_recursively(LIBMTP_mtpdevice_t *device, 
+				    PTPParams *params, 
+				    uint32_t storageid,
+				    uint32_t parent)
+{
+  PTPObjectHandles currentHandles;
+  int i = 0;
+  uint16_t ret = ptp_getobjecthandles(params,
+                                      storageid,
+                                      PTP_GOH_ALL_FORMATS,
+                                      parent,
+                                      &currentHandles);
+  
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "get_handles_recursively(): could not get object handles.");
+    return;
+  }
+  
+  if (currentHandles.Handler == NULL || currentHandles.n == 0)
+    return;
+
+  // Now descend into any subdirectories found
+  for (i = 0; i < currentHandles.n; i++) {    
+    PTPObject *ob;
+    ret = ptp_object_want(params,currentHandles.Handler[i],PTPOBJECT_OBJECTINFO_LOADED, &ob);
+    if (ret == PTP_RC_OK) {
+      if (ob->oi.ObjectFormat == PTP_OFC_Association)
+        get_handles_recursively(device, params, storageid, currentHandles.Handler[i]);
+    } else {
+      add_error_to_errorstack(device,
+			      LIBMTP_ERROR_CONNECTING,
+			      "Found a bad handle, trying to ignore it.");
+    }
+  }
+  free(currentHandles.Handler);
+}
+
+
+LIBMTP_file_t * obj2file(LIBMTP_mtpdevice_t *device, PTPObject *ob)
+{
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  PTPParams *params = (PTPParams *) device->params;
+  LIBMTP_file_t *file;
+  PTPObject *xob;
+  uint16_t ret;
+
+
+  if (ob->oi.Filename == NULL)
+    ob->oi.Filename = strdup("<null>");
+
+  if (ob->oi.Keywords == NULL)
+    ob->oi.Keywords = strdup("<null>");
+
+  // Allocate a new file type
+  file = LIBMTP_new_file_t();
+
+  file->parent_id = ob->oi.ParentObject;
+  file->storage_id = ob->oi.StorageID;
+
+  // This is some sort of unique ID so we can keep track of the track.
+  file->item_id = ob->oid;
+
+    // Set the filetype
+  file->filetype = map_ptp_type_to_libmtp_type(ob->oi.ObjectFormat);
+
+  // Set the modification date
+  file->modificationdate = ob->oi.ModificationDate;
+
+  // Original file-specific properties
+  // We only have 32-bit file size here; if we find it, we use the
+  // PTP_OPC_ObjectSize property which has 64bit precision.
+  file->filesize = ob->oi.ObjectCompressedSize;
+  if (ob->oi.Filename != NULL) {
+      file->filename = strdup(ob->oi.Filename);
+  }
+
+  /*
+  * A special quirk for devices that doesn't quite
+  * remember that some files marked as "unknown" type are
+  * actually OGG or FLAC files. We look at the filename extension
+  * and see if it happens that this was atleast named "ogg" or "flac"
+  * and fall back on this heuristic approach in that case,
+  * for these bugged devices only.
+  */
+  if (file->filetype == LIBMTP_FILETYPE_UNKNOWN) {
+    if ((FLAG_IRIVER_OGG_ALZHEIMER(ptp_usb) ||
+        FLAG_OGG_IS_UNKNOWN(ptp_usb)) &&
+        has_ogg_extension(file->filename))
+
+      file->filetype = LIBMTP_FILETYPE_OGG;
+
+      if (FLAG_FLAC_IS_UNKNOWN(ptp_usb) && has_flac_extension(file->filename))
+        file->filetype = LIBMTP_FILETYPE_FLAC;
+    }
+
+  /*
+  * If we have a cached, large set of metadata, then use it!
+  */
+  ret = ptp_object_want (params, ob->oid, PTPOBJECT_MTPPROPLIST_LOADED, &xob);
+  if (ob->mtpprops) {
+    MTPProperties *prop = ob->mtpprops;
+    int i;
+
+    for (i=0;i<ob->nrofmtpprops;i++) {
+      // Pick ObjectSize here...
+      if (prop->property == PTP_OPC_ObjectSize) {
+        if (device->object_bitsize == 64) {
+          file->filesize = prop->propval.u64;
+        } else {
+          file->filesize = prop->propval.u32;
+        }
+        break;
+      }
+      prop++;
+    }
+  } else {
+    uint16_t *props = NULL;
+    uint32_t propcnt = 0;
+
+    // First see which properties can be retrieved for this object format
+    ret = ptp_mtp_getobjectpropssupported(params, ob->oi.ObjectFormat, &propcnt, &props);
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "obj2file(): call to ptp_mtp_getobjectpropssupported() failed.");
+      // Silently fall through.
+    } else {
+      int i;
+      for (i=0;i<propcnt;i++) {
+
+/*
+    TODO: (yavor) See what is a sensible thing to do for Folders
+    if (ob->oi.ObjectFormat == PTP_OFC_Association)
+*/
+      switch (props[i]) {
+        case PTP_OPC_ObjectSize:
+          if (device->object_bitsize == 64) {
+            file->filesize = get_u64_from_object(device, file->item_id, PTP_OPC_ObjectSize, 0);
+          } else {
+            file->filesize = get_u32_from_object(device, file->item_id, PTP_OPC_ObjectSize, 0);
+          }
+          break;
+        default:
+            break;
+        }
+      }
+      free(props);
+    }
+  }
+
+  return file;
+}
+
+
+
+static LIBMTP_file_t * get_files(LIBMTP_mtpdevice_t *device,
+                        PTPParams *params,
+                        uint32_t storageid,
+                        uint32_t parentId
+                        )
+{
+  int i = 0;
+  LIBMTP_file_t *curfile = NULL;
+  LIBMTP_file_t *retfiles = NULL;
+  PTPObjectHandles currentHandles;
+
+  uint16_t ret = ptp_getobjecthandles(params,
+                                      storageid,
+                                      PTP_GOH_ALL_FORMATS,
+                                      parentId,
+                                      &currentHandles);
+
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "get_files(): could not get object handles.");
+    return NULL;
+  }
+
+  if (currentHandles.Handler == NULL || currentHandles.n == 0)
+    return NULL;
+
+  for (i = 0; i < currentHandles.n; i++) {
+    PTPObject *ob;
+    LIBMTP_file_t *file;
+
+    ret = ptp_object_want(params, currentHandles.Handler[i],PTPOBJECT_OBJECTINFO_LOADED, &ob);
+    if (ret != PTP_RC_OK)
+      return NULL;
+
+    file = obj2file(device, ob);
+
+    if (file == NULL)
+      continue;
+
+    // Add track to a list that will be returned afterwards.
+    if (curfile == NULL) {
+      curfile = file;
+      retfiles = file;
+    } else {
+      curfile->next = file;
+      curfile = file;
+    }
+ }
+
+  free(currentHandles.Handler);
+
+  // Return a pointer to the original first file
+  // in the big list.
+  return retfiles;
+}
+
+/**
+ * This function controls the usage of the internal object cache.
+ * The default configuration loads all object handles on initialization.
+ * In order to handle large number of files turn on the on demand
+ * loading by calling this function with parameter 1, and use
+ * LIBMTP_Get_Files_And_Folders() to load content when needed.
+ *
+ * @param flag - 0 means turn off on demand loading.
+ *             - 1 means turn on on demand loading.
+ */
+void LIBMTP_Set_Load_Cache_On_Demand(int flag)
+{
+    load_cache_on_demand = flag;
+}
+
+/**
+ * This function retrieves the content of a folder with id - parentId.
+ * The result contains both files and folders.
+ * NOTE: the request will always perform I/O with the device.
+ * @param device a pointer to the MTP device to report info from.
+ * @storageId the id for the storage.
+ * @param parentId the parent folder id.
+ */
+LIBMTP_file_t * LIBMTP_Get_Files_And_Folders(LIBMTP_mtpdevice_t *device, uint32_t storageId, uint32_t parentId)
+{
+  LIBMTP_file_t *retfiles = NULL;
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  int ret;
+  uint32_t i;
+
+#if 0
+  //TODO: (yavor) Try to use get_all_metadata_fast for a parendId.
+  if (ptp_operation_issupported(params,PTP_OC_MTP_GetObjPropList)
+      && !FLAG_BROKEN_MTPGETOBJPROPLIST(ptp_usb)
+      && !FLAG_BROKEN_MTPGETOBJPROPLIST_ALL(ptp_usb)) {
+    // Use the fast method. Ignore return value for now.
+    ret = get_all_metadata_fast(device, PTP_GOH_ALL_STORAGE);
+  }
+#endif
+
+
+  retfiles = get_files(device, params, storageId, parentId);
+
+  return retfiles;
+}
+
+/**
+ * This function refresh the internal handle list whenever
+ * the items stored inside the device is altered. On operations
+ * that do not add or remove objects, this is typically not
+ * called.
+ * @param device a pointer to the MTP device to flush handles for.
+ */
+static void flush_handles(LIBMTP_mtpdevice_t *device)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  int ret;
+  uint32_t i;
+
+  if (load_cache_on_demand) {
+    return;
+  }
+
+  if (params->objects != NULL) {
+    for (i=0;i<params->nrofobjects;i++)
+      ptp_free_object (&params->objects[i]);
+    free(params->objects);
+    params->objects = NULL;
+    params->nrofobjects = 0;
+  }
+
+  if (ptp_operation_issupported(params,PTP_OC_MTP_GetObjPropList)
+      && !FLAG_BROKEN_MTPGETOBJPROPLIST(ptp_usb)
+      && !FLAG_BROKEN_MTPGETOBJPROPLIST_ALL(ptp_usb)) {
+    // Use the fast method. Ignore return value for now.
+    ret = get_all_metadata_fast(device, PTP_GOH_ALL_STORAGE);
+  }
+
+  // If the previous failed or returned no objects, use classic
+  // methods instead.
+  if (params->nrofobjects == 0) {
+    // Get all the handles using just standard commands.
+    if (device->storage == NULL) {
+      get_handles_recursively(device, params,
+			      PTP_GOH_ALL_STORAGE,
+			      PTP_GOH_ROOT_PARENT);
+    } else {
+      // Get handles for each storage in turn.
+      LIBMTP_devicestorage_t *storage = device->storage;
+      while(storage != NULL) {
+	get_handles_recursively(device, params,
+				storage->id,
+				PTP_GOH_ROOT_PARENT);
+	storage = storage->next;
+      }
+    }
+  }
+  
+  /*
+   * Loop over the handles, fix up any NULL filenames or
+   * keywords, then attempt to locate some default folders
+   * in the root directory of the primary storage.
+   */
+  for(i = 0; i < params->nrofobjects; i++) {
+    PTPObject *ob, *xob;
+ 
+    ob = &params->objects[i];
+    ret = ptp_object_want(params,params->objects[i].oid,PTPOBJECT_OBJECTINFO_LOADED, &xob);
+    if (ret != PTP_RC_OK) {
+	fprintf(stderr,"broken! %x not found\n", params->objects[i].oid);
+    }
+    if (ob->oi.Filename == NULL)
+      ob->oi.Filename = strdup("<null>");
+    if (ob->oi.Keywords == NULL)
+      ob->oi.Keywords = strdup("<null>");
+
+    /* Ignore handles that point to non-folders */
+    if(ob->oi.ObjectFormat != PTP_OFC_Association)
+      continue;
+    /* Only look in the root folder */
+    if (ob->oi.ParentObject != 0x00000000U)
+      continue;
+    /* Only look in the primary storage */
+    if (device->storage != NULL && ob->oi.StorageID != device->storage->id)
+      continue;
+
+    
+    /* Is this the Music Folder */
+    if (!strcasecmp(ob->oi.Filename, "My Music") ||
+	!strcasecmp(ob->oi.Filename, "Music")) {
+      device->default_music_folder = ob->oid;
+    }
+    else if (!strcasecmp(ob->oi.Filename, "My Playlists") ||
+	     !strcasecmp(ob->oi.Filename, "Playlists")) {
+      device->default_playlist_folder = ob->oid;
+    }
+    else if (!strcasecmp(ob->oi.Filename, "My Pictures") ||
+	     !strcasecmp(ob->oi.Filename, "Pictures")) {
+      device->default_picture_folder = ob->oid;
+    }
+    else if (!strcasecmp(ob->oi.Filename, "My Video") ||
+	     !strcasecmp(ob->oi.Filename, "Video")) {
+	device->default_video_folder = ob->oid;
+    }
+    else if (!strcasecmp(ob->oi.Filename, "My Organizer")) {
+      device->default_organizer_folder = ob->oid;
+    }
+    else if (!strcasecmp(ob->oi.Filename, "ZENcast") ||
+	     !strcasecmp(ob->oi.Filename, "Datacasts")) {
+      device->default_zencast_folder = ob->oid;
+    }
+    else if (!strcasecmp(ob->oi.Filename, "My Albums") ||
+	     !strcasecmp(ob->oi.Filename, "Albums")) {
+      device->default_album_folder = ob->oid;
+    }
+    else if (!strcasecmp(ob->oi.Filename, "Text") ||
+	     !strcasecmp(ob->oi.Filename, "Texts")) {
+      device->default_text_folder = ob->oid;
+    }
+  }
+}
+
+/**
+ * This function traverses a devices storage list freeing up the 
+ * strings and the structs.
+ * @param device a pointer to the MTP device to free the storage 
+ * list for.
+ */
+static void free_storage_list(LIBMTP_mtpdevice_t *device)
+{
+  LIBMTP_devicestorage_t *storage;
+  LIBMTP_devicestorage_t *tmp;
+
+  storage = device->storage;
+  while(storage != NULL) {  
+    if (storage->StorageDescription != NULL) {
+      free(storage->StorageDescription);
+    }
+    if (storage->VolumeIdentifier != NULL) {
+      free(storage->VolumeIdentifier);
+    }
+    tmp = storage;
+    storage = storage->next;
+    free(tmp);
+  }
+  device->storage = NULL;
+
+  return;
+}
+
+/**
+ * This function traverses a devices storage list freeing up the
+ * strings and the structs.
+ * @param device a pointer to the MTP device to free the storage
+ * list for.
+ */
+static int sort_storage_by(LIBMTP_mtpdevice_t *device,int const sortby)
+{
+  LIBMTP_devicestorage_t *oldhead, *ptr1, *ptr2, *newlist;
+
+  if (device->storage == NULL)
+    return -1;
+  if (sortby == LIBMTP_STORAGE_SORTBY_NOTSORTED) 
+    return 0;
+
+  oldhead = ptr1 = ptr2 = device->storage;
+
+  newlist = NULL;
+
+  while(oldhead != NULL) {
+    ptr1 = ptr2 = oldhead;
+    while(ptr1 != NULL) {
+
+      if (sortby == LIBMTP_STORAGE_SORTBY_FREESPACE && ptr1->FreeSpaceInBytes > ptr2->FreeSpaceInBytes) 
+        ptr2 = ptr1;
+      if (sortby == LIBMTP_STORAGE_SORTBY_MAXSPACE && ptr1->FreeSpaceInBytes > ptr2->FreeSpaceInBytes) 
+        ptr2 = ptr1;
+
+      ptr1 = ptr1->next;
+    }
+
+    // Make our previous entries next point to our next
+    if(ptr2->prev != NULL) {
+      ptr1 = ptr2->prev;
+      ptr1->next = ptr2->next; 
+    } else {
+      oldhead = ptr2->next;
+      if(oldhead != NULL)
+        oldhead->prev = NULL;
+    }
+
+    // Make our next entries previous point to our previous
+    ptr1 = ptr2->next;
+    if(ptr1 != NULL) {
+      ptr1->prev = ptr2->prev;
+    } else {
+      ptr1 = ptr2->prev;
+      if(ptr1 != NULL)
+        ptr1->next = NULL;
+    }
+  
+    if(newlist == NULL) {
+      newlist = ptr2;
+      newlist->prev = NULL;
+    } else {
+      ptr2->prev = newlist;
+      newlist->next = ptr2;
+      newlist = newlist->next;
+    }
+  }
+ 
+  if (newlist != NULL) {
+    newlist->next = NULL;
+    while(newlist->prev != NULL) 
+      newlist = newlist->prev;
+    device->storage = newlist;
+  }
+
+  return 0;
+}
+
+/**
+ * This function grabs the first writeable storageid from the 
+ * device storage list.
+ * @param device a pointer to the MTP device to locate writeable 
+ *        storage for.
+ * @param fitsize a file of this file must fit on the device.
+ */
+static uint32_t get_writeable_storageid(LIBMTP_mtpdevice_t *device, uint64_t fitsize)
+{
+  LIBMTP_devicestorage_t *storage;
+  uint32_t store = 0x00000000; //Should this be 0xffffffffu instead?
+  int subcall_ret;
+
+  // See if there is some storage we can fit this file on.
+  storage = device->storage;
+  if (storage == NULL) {
+    // Sometimes the storage just cannot be detected.
+    store = 0x00000000U;
+  } else {
+    while(storage != NULL) {
+      // These storages cannot be used.
+      if (storage->StorageType == PTP_ST_FixedROM || storage->StorageType == PTP_ST_RemovableROM) {
+	storage = storage->next;
+	continue;
+      }
+      // Storage IDs with the lower 16 bits 0x0000 are not supposed
+      // to be writeable.
+      if ((storage->id & 0x0000FFFFU) == 0x00000000U) {
+	storage = storage->next;
+	continue;
+      }
+      // Also check the access capability to avoid e.g. deletable only storages
+      if (storage->AccessCapability == PTP_AC_ReadOnly || storage->AccessCapability == PTP_AC_ReadOnly_with_Object_Deletion) {
+	storage = storage->next;
+	continue;
+      }
+      // Then see if we can fit the file.
+      subcall_ret = check_if_file_fits(device, storage, fitsize);
+      if (subcall_ret != 0) {
+	storage = storage->next;
+      } else {
+	// We found a storage that is writable and can fit the file!
+	break;
+      }
+    }
+    if (storage == NULL) {
+      add_error_to_errorstack(device, LIBMTP_ERROR_STORAGE_FULL, "LIBMTP_Send_File_From_File_Descriptor(): " 
+			      "all device storage is full or corrupt.");
+      return -1;
+    }
+    store = storage->id;
+  }
+
+  return store;
+}
+
+/**
+ * This function grabs the freespace from a certain storage in
+ * device storage list.
+ * @param device a pointer to the MTP device to free the storage
+ * list for.
+ * @param storageid the storage ID for the storage to flush and
+ * get free space for.
+ * @param freespace the free space on this storage will be returned
+ * in this variable.
+ */
+static int get_storage_freespace(LIBMTP_mtpdevice_t *device, 
+				 LIBMTP_devicestorage_t *storage,
+				 uint64_t *freespace)
+{
+  PTPParams *params = (PTPParams *) device->params;
+
+  // Always query the device about this, since some models explicitly
+  // needs that. We flush all data on queries storage here.
+  if (ptp_operation_issupported(params,PTP_OC_GetStorageInfo)) {
+    PTPStorageInfo storageInfo;
+    uint16_t ret;
+    
+    ret = ptp_getstorageinfo(params, storage->id, &storageInfo);
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "get_first_storage_freespace(): could not get storage info.");
+      return -1;
+    }
+    if (storage->StorageDescription != NULL) {
+      free(storage->StorageDescription);
+    }
+    if (storage->VolumeIdentifier != NULL) {
+      free(storage->VolumeIdentifier);
+    }
+    storage->StorageType = storageInfo.StorageType;
+    storage->FilesystemType = storageInfo.FilesystemType;
+    storage->AccessCapability = storageInfo.AccessCapability;
+    storage->MaxCapacity = storageInfo.MaxCapability;
+    storage->FreeSpaceInBytes = storageInfo.FreeSpaceInBytes;
+    storage->FreeSpaceInObjects = storageInfo.FreeSpaceInImages;
+    storage->StorageDescription = storageInfo.StorageDescription;
+    storage->VolumeIdentifier = storageInfo.VolumeLabel;
+  }
+  if(storage->FreeSpaceInBytes == (uint64_t) -1)
+    return -1;
+  *freespace = storage->FreeSpaceInBytes;
+  return 0;
+}
+
+/**
+ * This function dumps out a large chunk of textual information
+ * provided from the PTP protocol and additionally some extra
+ * MTP-specific information where applicable.
+ * @param device a pointer to the MTP device to report info from.
+ */
+void LIBMTP_Dump_Device_Info(LIBMTP_mtpdevice_t *device)
+{
+  int i;
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  LIBMTP_devicestorage_t *storage = device->storage;
+
+  printf("USB low-level info:\n");
+  dump_usbinfo(ptp_usb);
+  /* Print out some verbose information */
+  printf("Device info:\n");
+  printf("   Manufacturer: %s\n", params->deviceinfo.Manufacturer);
+  printf("   Model: %s\n", params->deviceinfo.Model);
+  printf("   Device version: %s\n", params->deviceinfo.DeviceVersion);
+  printf("   Serial number: %s\n", params->deviceinfo.SerialNumber);
+  printf("   Vendor extension ID: 0x%08x\n", params->deviceinfo.VendorExtensionID);
+  printf("   Vendor extension description: %s\n", params->deviceinfo.VendorExtensionDesc);
+  printf("   Detected object size: %d bits\n", device->object_bitsize);
+  printf("Supported operations:\n");
+  for (i=0;i<params->deviceinfo.OperationsSupported_len;i++) {
+    char txt[256];
+
+    (void) ptp_render_opcode (params, params->deviceinfo.OperationsSupported[i], sizeof(txt), txt);
+    printf("   %04x: %s\n", params->deviceinfo.OperationsSupported[i], txt);
+  }
+  printf("Events supported:\n");
+  if (params->deviceinfo.EventsSupported_len == 0) {
+    printf("   None.\n");
+  } else {
+    for (i=0;i<params->deviceinfo.EventsSupported_len;i++) {
+      printf("   0x%04x\n", params->deviceinfo.EventsSupported[i]);
+    }
+  }
+  printf("Device Properties Supported:\n");
+  for (i=0;i<params->deviceinfo.DevicePropertiesSupported_len;i++) {
+    char const *propdesc = ptp_get_property_description(params, params->deviceinfo.DevicePropertiesSupported[i]);
+
+    if (propdesc != NULL) {
+      printf("   0x%04x: %s\n", params->deviceinfo.DevicePropertiesSupported[i], propdesc);
+    } else {
+      uint16_t prop = params->deviceinfo.DevicePropertiesSupported[i];
+      printf("   0x%04x: Unknown property\n", prop);
+    }
+  }
+
+  if (ptp_operation_issupported(params,PTP_OC_MTP_GetObjectPropsSupported)) {
+    printf("Playable File (Object) Types and Object Properties Supported:\n");
+    for (i=0;i<params->deviceinfo.ImageFormats_len;i++) {
+      char txt[256];
+      uint16_t ret;
+      uint16_t *props = NULL;
+      uint32_t propcnt = 0;
+      int j;
+
+      (void) ptp_render_ofc (params, params->deviceinfo.ImageFormats[i], sizeof(txt), txt);
+      printf("   %04x: %s\n", params->deviceinfo.ImageFormats[i], txt);
+
+      ret = ptp_mtp_getobjectpropssupported (params, params->deviceinfo.ImageFormats[i], &propcnt, &props);
+      if (ret != PTP_RC_OK) {
+	add_ptp_error_to_errorstack(device, ret, "LIBMTP_Dump_Device_Info(): error on query for object properties.");
+      } else {
+	for (j=0;j<propcnt;j++) {
+	  PTPObjectPropDesc opd;
+	  int k;
+	  
+	  printf("      %04x: %s", props[j], LIBMTP_Get_Property_Description(map_ptp_property_to_libmtp_property(props[j])));
+	  // Get a more verbose description
+	  ret = ptp_mtp_getobjectpropdesc(params, props[j], params->deviceinfo.ImageFormats[i], &opd);
+	  if (ret != PTP_RC_OK) {
+	    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Dump_Device_Info(): "
+				    "could not get property description.");
+	    break;
+	  }
+
+	  if (opd.DataType == PTP_DTC_STR) {
+	    printf(" STRING data type");
+	    switch (opd.FormFlag) {
+	    case PTP_OPFF_DateTime:
+	      printf(" DATETIME FORM");
+	      break;
+	    case PTP_OPFF_RegularExpression:
+	      printf(" REGULAR EXPRESSION FORM");
+	      break;
+	    case PTP_OPFF_LongString:
+	      printf(" LONG STRING FORM");
+	      break;
+	    default:
+	      break;
+	    }
+	  } else {
+	    if (opd.DataType & PTP_DTC_ARRAY_MASK) {
+	      printf(" array of");
+	    }
+
+	    switch (opd.DataType & (~PTP_DTC_ARRAY_MASK)) {
+
+	    case PTP_DTC_UNDEF:
+	      printf(" UNDEFINED data type");
+	      break;
+	      
+	    case PTP_DTC_INT8:
+	      printf(" INT8 data type");
+	      switch (opd.FormFlag) {
+	      case PTP_OPFF_Range:
+		printf(" range: MIN %d, MAX %d, STEP %d",
+		       opd.FORM.Range.MinimumValue.i8,
+		       opd.FORM.Range.MaximumValue.i8,
+		       opd.FORM.Range.StepSize.i8);
+		break;
+	      case PTP_OPFF_Enumeration:
+		printf(" enumeration: ");
+		for(k=0;k<opd.FORM.Enum.NumberOfValues;k++) {
+		  printf("%d, ", opd.FORM.Enum.SupportedValue[k].i8);
+		}
+		break;
+	      case PTP_OPFF_ByteArray:
+		printf(" byte array: ");
+		break;
+	      default:
+		printf(" ANY 8BIT VALUE form");
+		break;
+	      }
+	      break;
+	      
+	    case PTP_DTC_UINT8:
+	      printf(" UINT8 data type");
+	      switch (opd.FormFlag) {
+	      case PTP_OPFF_Range:
+		printf(" range: MIN %d, MAX %d, STEP %d",
+		       opd.FORM.Range.MinimumValue.u8,
+		       opd.FORM.Range.MaximumValue.u8,
+		       opd.FORM.Range.StepSize.u8);
+		break;
+	      case PTP_OPFF_Enumeration:
+		printf(" enumeration: ");
+		for(k=0;k<opd.FORM.Enum.NumberOfValues;k++) {
+		  printf("%d, ", opd.FORM.Enum.SupportedValue[k].u8);
+		}
+		break;
+	      case PTP_OPFF_ByteArray:
+		printf(" byte array: ");
+		break;
+	      default:
+		printf(" ANY 8BIT VALUE form");
+		break;
+	      }
+	      break;
+	      
+	    case PTP_DTC_INT16:
+	      printf(" INT16 data type");
+	      switch (opd.FormFlag) {
+	      case PTP_OPFF_Range:
+	      printf(" range: MIN %d, MAX %d, STEP %d",
+		     opd.FORM.Range.MinimumValue.i16,
+		     opd.FORM.Range.MaximumValue.i16,
+		     opd.FORM.Range.StepSize.i16);
+	      break;
+	      case PTP_OPFF_Enumeration:
+		printf(" enumeration: ");
+		for(k=0;k<opd.FORM.Enum.NumberOfValues;k++) {
+		  printf("%d, ", opd.FORM.Enum.SupportedValue[k].i16);
+		}
+		break;
+	      default:
+		printf(" ANY 16BIT VALUE form");
+		break;
+	      }
+	      break;
+	      
+	    case PTP_DTC_UINT16:
+	      printf(" UINT16 data type");
+	      switch (opd.FormFlag) {
+	      case PTP_OPFF_Range:
+		printf(" range: MIN %d, MAX %d, STEP %d",
+		       opd.FORM.Range.MinimumValue.u16,
+		       opd.FORM.Range.MaximumValue.u16,
+		       opd.FORM.Range.StepSize.u16);
+		break;
+	      case PTP_OPFF_Enumeration:
+		printf(" enumeration: ");
+		for(k=0;k<opd.FORM.Enum.NumberOfValues;k++) {
+		  printf("%d, ", opd.FORM.Enum.SupportedValue[k].u16);
+		}
+		break;
+	      default:
+		printf(" ANY 16BIT VALUE form");
+		break;
+	      }
+	      break;
+	      
+	    case PTP_DTC_INT32:
+	      printf(" INT32 data type");
+	      switch (opd.FormFlag) {
+	      case PTP_OPFF_Range:
+		printf(" range: MIN %d, MAX %d, STEP %d",
+		       opd.FORM.Range.MinimumValue.i32,
+		       opd.FORM.Range.MaximumValue.i32,
+		       opd.FORM.Range.StepSize.i32);
+		break;
+	      case PTP_OPFF_Enumeration:
+		printf(" enumeration: ");
+		for(k=0;k<opd.FORM.Enum.NumberOfValues;k++) {
+		  printf("%d, ", opd.FORM.Enum.SupportedValue[k].i32);
+		}
+		break;
+	      default:
+		printf(" ANY 32BIT VALUE form");
+		break;
+	      }
+	      break;
+	      
+	    case PTP_DTC_UINT32:
+	      printf(" UINT32 data type");
+	      switch (opd.FormFlag) {
+	      case PTP_OPFF_Range:
+		printf(" range: MIN %d, MAX %d, STEP %d",
+		       opd.FORM.Range.MinimumValue.u32,
+		       opd.FORM.Range.MaximumValue.u32,
+		       opd.FORM.Range.StepSize.u32);
+		break;
+	      case PTP_OPFF_Enumeration:
+		// Special pretty-print for FOURCC codes
+		if (params->deviceinfo.ImageFormats[i] == PTP_OPC_VideoFourCCCodec) {
+		  printf(" enumeration of u32 casted FOURCC: ");
+		  for (k=0;k<opd.FORM.Enum.NumberOfValues;k++) {
+		    if (opd.FORM.Enum.SupportedValue[k].u32 == 0) {
+		      printf("ANY, ");
+		    } else {
+		      char fourcc[6];
+		      fourcc[0] = (opd.FORM.Enum.SupportedValue[k].u32 >> 24) & 0xFFU;
+		      fourcc[1] = (opd.FORM.Enum.SupportedValue[k].u32 >> 16) & 0xFFU;
+		      fourcc[2] = (opd.FORM.Enum.SupportedValue[k].u32 >> 8) & 0xFFU;
+		      fourcc[3] = opd.FORM.Enum.SupportedValue[k].u32 & 0xFFU;
+		      fourcc[4] = '\n';
+		      fourcc[5] = '\0';
+		      printf("\"%s\", ", fourcc);
+		    }
+		  }
+		} else {
+		  printf(" enumeration: ");
+		  for(k=0;k<opd.FORM.Enum.NumberOfValues;k++) {
+		    printf("%d, ", opd.FORM.Enum.SupportedValue[k].u32);
+		  }
+		}
+		break;
+	      default:
+		printf(" ANY 32BIT VALUE form");
+		break;
+	      }
+	      break;
+	      
+	    case PTP_DTC_INT64:
+	      printf(" INT64 data type");
+	      break;
+	      
+	    case PTP_DTC_UINT64:
+	      printf(" UINT64 data type");
+	      break;
+	      
+	    case PTP_DTC_INT128:
+	      printf(" INT128 data type");
+	      break;
+	      
+	    case PTP_DTC_UINT128:
+	      printf(" UINT128 data type");
+	      break;
+	      
+	    default:
+	      printf(" UNKNOWN data type");
+	      break;
+	    }
+	  }
+	  if (opd.GetSet) {
+	    printf(" GET/SET");
+	  } else {
+	    printf(" READ ONLY");
+	  }
+	  printf("\n");
+	  ptp_free_objectpropdesc(&opd);
+	}
+	free(props);
+      }
+    }
+  }
+
+  if(storage != NULL && ptp_operation_issupported(params,PTP_OC_GetStorageInfo)) {
+    printf("Storage Devices:\n");
+    while(storage != NULL) {
+      printf("   StorageID: 0x%08x\n",storage->id);
+      printf("      StorageType: 0x%04x ",storage->StorageType);
+      switch (storage->StorageType) {
+      case PTP_ST_Undefined:
+	printf("(undefined)\n");
+	break;
+      case PTP_ST_FixedROM:
+	printf("fixed ROM storage\n");
+	break;
+      case PTP_ST_RemovableROM:
+	printf("removable ROM storage\n");
+	break;
+      case PTP_ST_FixedRAM:
+	printf("fixed RAM storage\n");
+	break;
+      case PTP_ST_RemovableRAM:
+	printf("removable RAM storage\n");
+	break;
+      default:
+	printf("UNKNOWN storage\n");
+	break;
+      }
+      printf("      FilesystemType: 0x%04x ",storage->FilesystemType);
+      switch(storage->FilesystemType) {
+      case PTP_FST_Undefined:
+	printf("(undefined)\n");
+	break;
+      case PTP_FST_GenericFlat:
+	printf("generic flat filesystem\n");
+	break;
+      case PTP_FST_GenericHierarchical:
+	printf("generic hierarchical\n");
+	break;
+      case PTP_FST_DCF:
+	printf("DCF\n");
+	break;
+      default:
+	printf("UNKNONWN filesystem type\n");
+	break;
+      }
+      printf("      AccessCapability: 0x%04x ",storage->AccessCapability);
+      switch(storage->AccessCapability) {
+      case PTP_AC_ReadWrite:
+	printf("read/write\n");
+	break;
+      case PTP_AC_ReadOnly:
+	printf("read only\n");
+	break;
+      case PTP_AC_ReadOnly_with_Object_Deletion:
+	printf("read only + object deletion\n");
+	break;
+      default:
+	printf("UNKNOWN access capability\n");
+	break;
+      }
+      printf("      MaxCapacity: %llu\n", (long long unsigned int) storage->MaxCapacity);
+      printf("      FreeSpaceInBytes: %llu\n", (long long unsigned int) storage->FreeSpaceInBytes);
+      printf("      FreeSpaceInObjects: %llu\n", (long long unsigned int) storage->FreeSpaceInObjects);
+      printf("      StorageDescription: %s\n",storage->StorageDescription);
+      printf("      VolumeIdentifier: %s\n",storage->VolumeIdentifier);
+      storage = storage->next;
+    }
+  }
+
+  printf("Special directories:\n");
+  printf("   Default music folder: 0x%08x\n", device->default_music_folder);
+  printf("   Default playlist folder: 0x%08x\n", device->default_playlist_folder);
+  printf("   Default picture folder: 0x%08x\n", device->default_picture_folder);
+  printf("   Default video folder: 0x%08x\n", device->default_video_folder);
+  printf("   Default organizer folder: 0x%08x\n", device->default_organizer_folder);
+  printf("   Default zencast folder: 0x%08x\n", device->default_zencast_folder);
+  printf("   Default album folder: 0x%08x\n", device->default_album_folder);
+  printf("   Default text folder: 0x%08x\n", device->default_text_folder);
+}
+
+/**
+ * This resets a device in case it supports the <code>PTP_OC_ResetDevice</code>
+ * operation code (0x1010).
+ * @param device a pointer to the device to reset.
+ * @return 0 on success, any other value means failure.
+ */
+int LIBMTP_Reset_Device(LIBMTP_mtpdevice_t *device)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+
+  if (!ptp_operation_issupported(params,PTP_OC_ResetDevice)) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, 
+			    "LIBMTP_Reset_Device(): device does not support resetting.");
+    return -1;
+  }
+  ret = ptp_resetdevice(params);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "Error resetting.");
+    return -1;
+  }
+  return 0;
+}
+
+/**
+ * This retrieves the manufacturer name of an MTP device.
+ * @param device a pointer to the device to get the manufacturer name for.
+ * @return a newly allocated UTF-8 string representing the manufacturer name.
+ *         The string must be freed by the caller after use. If the call
+ *         was unsuccessful this will contain NULL.
+ */
+char *LIBMTP_Get_Manufacturername(LIBMTP_mtpdevice_t *device)
+{
+  char *retmanuf = NULL;
+  PTPParams *params = (PTPParams *) device->params;
+
+  if (params->deviceinfo.Manufacturer != NULL) {
+    retmanuf = strdup(params->deviceinfo.Manufacturer);
+  }
+  return retmanuf;
+}
+
+/**
+ * This retrieves the model name (often equal to product name)
+ * of an MTP device.
+ * @param device a pointer to the device to get the model name for.
+ * @return a newly allocated UTF-8 string representing the model name.
+ *         The string must be freed by the caller after use. If the call
+ *         was unsuccessful this will contain NULL.
+ */
+char *LIBMTP_Get_Modelname(LIBMTP_mtpdevice_t *device)
+{
+  char *retmodel = NULL;
+  PTPParams *params = (PTPParams *) device->params;
+
+  if (params->deviceinfo.Model != NULL) {
+    retmodel = strdup(params->deviceinfo.Model);
+  }
+  return retmodel;
+}
+
+/**
+ * This retrieves the serial number of an MTP device.
+ * @param device a pointer to the device to get the serial number for.
+ * @return a newly allocated UTF-8 string representing the serial number.
+ *         The string must be freed by the caller after use. If the call
+ *         was unsuccessful this will contain NULL.
+ */
+char *LIBMTP_Get_Serialnumber(LIBMTP_mtpdevice_t *device)
+{
+  char *retnumber = NULL;
+  PTPParams *params = (PTPParams *) device->params;
+
+  if (params->deviceinfo.SerialNumber != NULL) {
+    retnumber = strdup(params->deviceinfo.SerialNumber);
+  }
+  return retnumber;
+}
+
+/**
+ * This retrieves the device version (hardware and firmware version) of an
+ * MTP device.
+ * @param device a pointer to the device to get the device version for.
+ * @return a newly allocated UTF-8 string representing the device version.
+ *         The string must be freed by the caller after use. If the call
+ *         was unsuccessful this will contain NULL.
+ */
+char *LIBMTP_Get_Deviceversion(LIBMTP_mtpdevice_t *device)
+{
+  char *retversion = NULL;
+  PTPParams *params = (PTPParams *) device->params;
+
+  if (params->deviceinfo.DeviceVersion != NULL) {
+    retversion = strdup(params->deviceinfo.DeviceVersion);
+  }
+  return retversion;
+}
+
+
+/**
+ * This retrieves the "friendly name" of an MTP device. Usually
+ * this is simply the name of the owner or something like
+ * "John Doe's Digital Audio Player". This property should be supported
+ * by all MTP devices.
+ * @param device a pointer to the device to get the friendly name for.
+ * @return a newly allocated UTF-8 string representing the friendly name.
+ *         The string must be freed by the caller after use.
+ * @see LIBMTP_Set_Friendlyname()
+ */
+char *LIBMTP_Get_Friendlyname(LIBMTP_mtpdevice_t *device)
+{
+  PTPPropertyValue propval;
+  char *retstring = NULL;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+
+  if (!ptp_property_issupported(params, PTP_DPC_MTP_DeviceFriendlyName)) {
+    return NULL;
+  }
+
+  ret = ptp_getdevicepropvalue(params,
+			       PTP_DPC_MTP_DeviceFriendlyName,
+			       &propval,
+			       PTP_DTC_STR);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "Error getting friendlyname.");
+    return NULL;
+  }
+  if (propval.str != NULL) {
+    retstring = strdup(propval.str);
+    free(propval.str);
+  }
+  return retstring;
+}
+
+/**
+ * Sets the "friendly name" of an MTP device.
+ * @param device a pointer to the device to set the friendly name for.
+ * @param friendlyname the new friendly name for the device.
+ * @return 0 on success, any other value means failure.
+ * @see LIBMTP_Get_Friendlyname()
+ */
+int LIBMTP_Set_Friendlyname(LIBMTP_mtpdevice_t *device,
+			 char const * const friendlyname)
+{
+  PTPPropertyValue propval;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+
+  if (!ptp_property_issupported(params, PTP_DPC_MTP_DeviceFriendlyName)) {
+    return -1;
+  }
+  propval.str = (char *) friendlyname;
+  ret = ptp_setdevicepropvalue(params,
+			       PTP_DPC_MTP_DeviceFriendlyName,
+			       &propval,
+			       PTP_DTC_STR);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "Error setting friendlyname.");
+    return -1;
+  }
+  return 0;
+}
+
+/**
+ * This retrieves the syncronization partner of an MTP device. This
+ * property should be supported by all MTP devices.
+ * @param device a pointer to the device to get the sync partner for.
+ * @return a newly allocated UTF-8 string representing the synchronization
+ *         partner. The string must be freed by the caller after use.
+ * @see LIBMTP_Set_Syncpartner()
+ */
+char *LIBMTP_Get_Syncpartner(LIBMTP_mtpdevice_t *device)
+{
+  PTPPropertyValue propval;
+  char *retstring = NULL;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+
+  if (!ptp_property_issupported(params, PTP_DPC_MTP_SynchronizationPartner)) {
+    return NULL;
+  }
+
+  ret = ptp_getdevicepropvalue(params,
+			       PTP_DPC_MTP_SynchronizationPartner,
+			       &propval,
+			       PTP_DTC_STR);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "Error getting syncpartner.");
+    return NULL;
+  }
+  if (propval.str != NULL) {
+    retstring = strdup(propval.str);
+    free(propval.str);
+  }
+  return retstring;
+}
+
+
+/**
+ * Sets the synchronization partner of an MTP device. Note that
+ * we have no idea what the effect of setting this to "foobar"
+ * may be. But the general idea seems to be to tell which program
+ * shall synchronize with this device and tell others to leave
+ * it alone.
+ * @param device a pointer to the device to set the sync partner for.
+ * @param syncpartner the new synchronization partner for the device.
+ * @return 0 on success, any other value means failure.
+ * @see LIBMTP_Get_Syncpartner()
+ */
+int LIBMTP_Set_Syncpartner(LIBMTP_mtpdevice_t *device,
+			 char const * const syncpartner)
+{
+  PTPPropertyValue propval;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+
+  if (!ptp_property_issupported(params, PTP_DPC_MTP_SynchronizationPartner)) {
+    return -1;
+  }
+  propval.str = (char *) syncpartner;
+  ret = ptp_setdevicepropvalue(params,
+			       PTP_DPC_MTP_SynchronizationPartner,
+			       &propval,
+			       PTP_DTC_STR);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "Error setting syncpartner.");
+    return -1;
+  }
+  return 0;
+}
+
+/**
+ * Checks if the device can stora a file of this size or
+ * if it's too big.
+ * @param device a pointer to the device.
+ * @param filesize the size of the file to check whether it will fit.
+ * @param storageid the ID of the storage to try to fit the file on.
+ * @return 0 if the file fits, any other value means failure.
+ */
+static int check_if_file_fits(LIBMTP_mtpdevice_t *device,
+			      LIBMTP_devicestorage_t *storage,
+			      uint64_t const filesize) {
+  PTPParams *params = (PTPParams *) device->params;
+  uint64_t freebytes;
+  int ret;
+
+  // If we cannot check the storage, no big deal.
+  if (!ptp_operation_issupported(params,PTP_OC_GetStorageInfo)) {
+    return 0;
+  }
+  
+  ret = get_storage_freespace(device, storage, &freebytes);
+  if (ret != 0) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, 
+			    "check_if_file_fits(): error checking free storage.");
+    return -1;
+  } else {
+    // See if it fits.
+    if (filesize > freebytes) {
+      return -1;
+    }
+  }
+  return 0;
+}
+
+
+/**
+ * This function retrieves the current battery level on the device.
+ * @param device a pointer to the device to get the battery level for.
+ * @param maximum_level a pointer to a variable that will hold the
+ *        maximum level of the battery if the call was successful.
+ * @param current_level a pointer to a variable that will hold the
+ *        current level of the battery if the call was successful.
+ *        A value of 0 means that the device is on external power.
+ * @return 0 if the storage info was successfully retrieved, any other
+ *        means failure. A typical cause of failure is that
+ *        the device does not support the battery level property.
+ */
+int LIBMTP_Get_Batterylevel(LIBMTP_mtpdevice_t *device,
+			    uint8_t * const maximum_level,
+			    uint8_t * const current_level)
+{
+  PTPPropertyValue propval;
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+
+  *maximum_level = 0;
+  *current_level = 0;
+
+  if (FLAG_BROKEN_BATTERY_LEVEL(ptp_usb) ||
+      !ptp_property_issupported(params, PTP_DPC_BatteryLevel)) {
+    return -1;
+  }
+
+  ret = ptp_getdevicepropvalue(params, PTP_DPC_BatteryLevel, &propval, PTP_DTC_UINT8);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Batterylevel(): could not get device property value.");
+    return -1;
+  }
+
+  *maximum_level = device->maximum_battery_level;
+  *current_level = propval.u8;
+
+  return 0;
+}
+
+
+/**
+ * Formats device storage (if the device supports the operation).
+ * WARNING: This WILL delete all data from the device. Make sure you've
+ * got confirmation from the user BEFORE you call this function.
+ *
+ * @param device a pointer to the device containing the storage to format.
+ * @param storage the actual storage to format.
+ * @return 0 on success, any other value means failure.
+ */
+int LIBMTP_Format_Storage(LIBMTP_mtpdevice_t *device, LIBMTP_devicestorage_t *storage)
+{
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+
+  if (!ptp_operation_issupported(params,PTP_OC_FormatStore)) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, 
+			    "LIBMTP_Format_Storage(): device does not support formatting storage.");
+    return -1;
+  }
+  ret = ptp_formatstore(params, storage->id);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Format_Storage(): failed to format storage.");
+    return -1;
+  }
+  return 0;
+}
+
+/**
+ * Helper function to extract a unicode property off a device.
+ * This is the standard way of retrieveing unicode device
+ * properties as described by the PTP spec.
+ * @param device a pointer to the device to get the property from.
+ * @param unicstring a pointer to a pointer that will hold the
+ *        property after this call is completed.
+ * @param property the property to retrieve.
+ * @return 0 on success, any other value means failure.
+ */
+static int get_device_unicode_property(LIBMTP_mtpdevice_t *device,
+				       char **unicstring, uint16_t property)
+{
+  PTPPropertyValue propval;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t *tmp;
+  uint16_t ret;
+  int i;
+
+  if (!ptp_property_issupported(params, property)) {
+    return -1;
+  }
+
+  // Unicode strings are 16bit unsigned integer arrays.
+  ret = ptp_getdevicepropvalue(params,
+			       property,
+			       &propval,
+			       PTP_DTC_AUINT16);
+  if (ret != PTP_RC_OK) {
+    // TODO: add a note on WHICH property that we failed to get.
+    *unicstring = NULL;
+    add_ptp_error_to_errorstack(device, ret, "get_device_unicode_property(): failed to get unicode property.");
+    return -1;
+  }
+
+  // Extract the actual array.
+  // printf("Array of %d elements\n", propval.a.count);
+  tmp = malloc((propval.a.count + 1)*sizeof(uint16_t));
+  for (i = 0; i < propval.a.count; i++) {
+    tmp[i] = propval.a.v[i].u16;
+    // printf("%04x ", tmp[i]);
+  }
+  tmp[propval.a.count] = 0x0000U;
+  free(propval.a.v);
+
+  *unicstring = utf16_to_utf8(device, tmp);
+
+  free(tmp);
+
+  return 0;
+}
+
+/**
+ * This function returns the secure time as an XML document string from
+ * the device.
+ * @param device a pointer to the device to get the secure time for.
+ * @param sectime the secure time string as an XML document or NULL if the call
+ *         failed or the secure time property is not supported. This string
+ *         must be <code>free()</code>:ed by the caller after use.
+ * @return 0 on success, any other value means failure.
+ */
+int LIBMTP_Get_Secure_Time(LIBMTP_mtpdevice_t *device, char ** const sectime)
+{
+  return get_device_unicode_property(device, sectime, PTP_DPC_MTP_SecureTime);
+}
+
+/**
+ * This function returns the device (public key) certificate as an
+ * XML document string from the device.
+ * @param device a pointer to the device to get the device certificate for.
+ * @param devcert the device certificate as an XML string or NULL if the call
+ *        failed or the device certificate property is not supported. This
+ *        string must be <code>free()</code>:ed by the caller after use.
+ * @return 0 on success, any other value means failure.
+ */
+int LIBMTP_Get_Device_Certificate(LIBMTP_mtpdevice_t *device, char ** const devcert)
+{
+  return get_device_unicode_property(device, devcert, PTP_DPC_MTP_DeviceCertificate);
+}
+
+/**
+ * This function retrieves a list of supported file types, i.e. the file
+ * types that this device claims it supports, e.g. audio file types that
+ * the device can play etc. This list is mitigated to
+ * inlcude the file types that libmtp can handle, i.e. it will not list
+ * filetypes that libmtp will handle internally like playlists and folders.
+ * @param device a pointer to the device to get the filetype capabilities for.
+ * @param filetypes a pointer to a pointer that will hold the list of
+ *        supported filetypes if the call was successful. This list must
+ *        be <code>free()</code>:ed by the caller after use.
+ * @param length a pointer to a variable that will hold the length of the
+ *        list of supported filetypes if the call was successful.
+ * @return 0 on success, any other value means failure.
+ * @see LIBMTP_Get_Filetype_Description()
+ */
+int LIBMTP_Get_Supported_Filetypes(LIBMTP_mtpdevice_t *device, uint16_t ** const filetypes,
+				  uint16_t * const length)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  uint16_t *localtypes;
+  uint16_t localtypelen;
+  uint32_t i;
+
+  // This is more memory than needed if there are unknown types, but what the heck.
+  localtypes = (uint16_t *) malloc(params->deviceinfo.ImageFormats_len * sizeof(uint16_t));
+  localtypelen = 0;
+
+  for (i=0;i<params->deviceinfo.ImageFormats_len;i++) {
+    uint16_t localtype = map_ptp_type_to_libmtp_type(params->deviceinfo.ImageFormats[i]);
+    if (localtype != LIBMTP_FILETYPE_UNKNOWN) {
+      localtypes[localtypelen] = localtype;
+      localtypelen++;
+    }
+  }
+  // The forgotten Ogg support on YP-10 and others...
+  if (FLAG_OGG_IS_UNKNOWN(ptp_usb)) {
+    localtypes = (uint16_t *) realloc(localtypes, (params->deviceinfo.ImageFormats_len+1) * sizeof(uint16_t));
+    localtypes[localtypelen] = LIBMTP_FILETYPE_OGG;
+    localtypelen++;
+  }
+  // The forgotten FLAC support on Cowon iAudio S9 and others...
+  if (FLAG_FLAC_IS_UNKNOWN(ptp_usb)) {
+    localtypes = (uint16_t *) realloc(localtypes, (params->deviceinfo.ImageFormats_len+1) * sizeof(uint16_t));
+    localtypes[localtypelen] = LIBMTP_FILETYPE_FLAC;
+    localtypelen++;
+  }
+
+  *filetypes = localtypes;
+  *length = localtypelen;
+
+  return 0;
+}
+
+/**
+ * This function updates all the storage id's of a device and their
+ * properties, then creates a linked list and puts the list head into 
+ * the device struct. It also optionally sorts this list. If you want
+ * to display storage information in your application you should call
+ * this function, then dereference the device struct  
+ * (<code>device-&gt;storage</code>) to get out information on the storage.
+ *
+ * You need to call this everytime you want to update the
+ * <code>device-&gt;storage</code> list, for example anytime you need
+ * to check available storage somewhere.
+ *
+ * <b>WARNING:</b> since this list is dynamically updated, do not
+ * reference its fields in external applications by pointer! E.g
+ * do not put a reference to any <code>char *</code> field. instead
+ * <code>strncpy()</code> it!
+ *
+ * @param device a pointer to the device to get the storage for.
+ * @param sortby an integer that determines the sorting of the storage list. 
+ *        Valid sort methods are defined in libmtp.h with beginning with
+ *        LIBMTP_STORAGE_SORTBY_. 0 or LIBMTP_STORAGE_SORTBY_NOTSORTED to not 
+ *        sort.
+ * @return 0 on success, 1 success but only with storage id's, storage 
+ *        properities could not be retrieved and -1 means failure.
+ */
+int LIBMTP_Get_Storage(LIBMTP_mtpdevice_t *device, int const sortby)
+{
+  uint32_t i = 0;
+  PTPStorageInfo storageInfo;
+  PTPParams *params = (PTPParams *) device->params;
+  PTPStorageIDs storageIDs;
+  LIBMTP_devicestorage_t *storage = NULL;
+  LIBMTP_devicestorage_t *storageprev = NULL;
+
+  if (device->storage != NULL)
+    free_storage_list(device);
+
+  // if (!ptp_operation_issupported(params,PTP_OC_GetStorageIDs)) 
+  //   return -1;
+  if (ptp_getstorageids (params, &storageIDs) != PTP_RC_OK) 
+    return -1;
+  if (storageIDs.n < 1) 
+    return -1;
+
+  if (!ptp_operation_issupported(params,PTP_OC_GetStorageInfo)) {
+    for (i = 0; i < storageIDs.n; i++) {
+
+      storage = (LIBMTP_devicestorage_t *) malloc(sizeof(LIBMTP_devicestorage_t));
+      storage->prev = storageprev;
+      if (storageprev != NULL)
+        storageprev->next = storage;
+      if (device->storage == NULL) 
+        device->storage = storage;
+
+      storage->id = storageIDs.Storage[i];
+      storage->StorageType = PTP_ST_Undefined;
+      storage->FilesystemType = PTP_FST_Undefined;
+      storage->AccessCapability = PTP_AC_ReadWrite;
+      storage->MaxCapacity = (uint64_t) -1;
+      storage->FreeSpaceInBytes = (uint64_t) -1;
+      storage->FreeSpaceInObjects = (uint64_t) -1;
+      storage->StorageDescription = strdup("Unknown storage");
+      storage->VolumeIdentifier = strdup("Unknown volume");
+      storage->next = NULL;
+
+      storageprev = storage;
+    }
+    free(storageIDs.Storage);
+    return 1;
+  } else {
+    for (i = 0; i < storageIDs.n; i++) {
+      uint16_t ret;
+      ret = ptp_getstorageinfo(params, storageIDs.Storage[i], &storageInfo);
+      if (ret != PTP_RC_OK) {
+	add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Storage(): Could not get storage info.");
+	if (device->storage != NULL) {
+          free_storage_list(device);
+	}
+	return -1;
+      }
+
+      storage = (LIBMTP_devicestorage_t *) malloc(sizeof(LIBMTP_devicestorage_t));
+      storage->prev = storageprev;
+      if (storageprev != NULL)
+        storageprev->next = storage;
+      if (device->storage == NULL)
+        device->storage = storage;
+
+      storage->id = storageIDs.Storage[i];
+      storage->StorageType = storageInfo.StorageType;
+      storage->FilesystemType = storageInfo.FilesystemType;
+      storage->AccessCapability = storageInfo.AccessCapability;
+      storage->MaxCapacity = storageInfo.MaxCapability;
+      storage->FreeSpaceInBytes = storageInfo.FreeSpaceInBytes;
+      storage->FreeSpaceInObjects = storageInfo.FreeSpaceInImages;
+      storage->StorageDescription = storageInfo.StorageDescription;
+      storage->VolumeIdentifier = storageInfo.VolumeLabel;
+      storage->next = NULL;
+
+      storageprev = storage;
+    }
+
+    if (storage != NULL)
+      storage->next = NULL;
+
+    sort_storage_by(device,sortby);
+    free(storageIDs.Storage);
+    return 0;
+  }
+}
+
+/**
+ * This creates a new file metadata structure and allocates memory
+ * for it. Notice that if you add strings to this structure they
+ * will be freed by the corresponding <code>LIBMTP_destroy_file_t</code>
+ * operation later, so be careful of using strdup() when assigning
+ * strings, e.g.:
+ *
+ * <pre>
+ * LIBMTP_file_t *file = LIBMTP_new_file_t();
+ * file->filename = strdup(namestr);
+ * ....
+ * LIBMTP_destroy_file_t(file);
+ * </pre>
+ *
+ * @return a pointer to the newly allocated metadata structure.
+ * @see LIBMTP_destroy_file_t()
+ */
+LIBMTP_file_t *LIBMTP_new_file_t(void)
+{
+  LIBMTP_file_t *new = (LIBMTP_file_t *) malloc(sizeof(LIBMTP_file_t));
+  if (new == NULL) {
+    return NULL;
+  }
+  new->filename = NULL;
+  new->item_id = 0;
+  new->parent_id = 0;
+  new->storage_id = 0;
+  new->filesize = 0;
+  new->modificationdate = 0;
+  new->filetype = LIBMTP_FILETYPE_UNKNOWN;
+  new->next = NULL;
+  return new;
+}
+
+/**
+ * This destroys a file metadata structure and deallocates the memory
+ * used by it, including any strings. Never use a file metadata
+ * structure again after calling this function on it.
+ * @param file the file metadata to destroy.
+ * @see LIBMTP_new_file_t()
+ */
+void LIBMTP_destroy_file_t(LIBMTP_file_t *file)
+{
+  if (file == NULL) {
+    return;
+  }
+  if (file->filename != NULL)
+    free(file->filename);
+  free(file);
+  return;
+}
+
+/**
+* THIS FUNCTION IS DEPRECATED. PLEASE UPDATE YOUR CODE IN ORDER
+ * NOT TO USE IT.
+ * @see LIBMTP_Get_Filelisting_With_Callback()
+ */
+LIBMTP_file_t *LIBMTP_Get_Filelisting(LIBMTP_mtpdevice_t *device)
+{
+  printf("WARNING: LIBMTP_Get_Filelisting() is deprecated.\n");
+  printf("WARNING: please update your code to use LIBMTP_Get_Filelisting_With_Callback()\n");
+  return LIBMTP_Get_Filelisting_With_Callback(device, NULL, NULL);
+}
+
+/**
+ * This returns a long list of all files available
+ * on the current MTP device. Folders will not be returned, but abstract
+ * entities like playlists and albums will show up as "files". Typical usage:
+ *
+ * <pre>
+ * LIBMTP_file_t *filelist;
+ *
+ * filelist = LIBMTP_Get_Filelisting_With_Callback(device, callback, data);
+ * while (filelist != NULL) {
+ *   LIBMTP_file_t *tmp;
+ *
+ *   // Do something on each element in the list here...
+ *   tmp = filelist;
+ *   filelist = filelist->next;
+ *   LIBMTP_destroy_file_t(tmp);
+ * }
+ * </pre>
+ *
+ * If you want to group your file listing by storage (per storage unit) or
+ * arrange files into folders, you must dereference the <code>storage_id</code>
+ * and/or <code>parent_id</code> field of the returned <code>LIBMTP_file_t</code>
+ * struct. To arrange by folders or files you typically have to create the proper
+ * trees by calls to <code>LIBMTP_Get_Storage()</code> and/or 
+ * <code>LIBMTP_Get_Folder_List()</code> first.
+ *
+ * @param device a pointer to the device to get the file listing for.
+ * @param callback a function to be called during the tracklisting retrieveal
+ *        for displaying progress bars etc, or NULL if you don't want
+ *        any callbacks.
+ * @param data a user-defined pointer that is passed along to
+ *        the <code>progress</code> function in order to
+ *        pass along some user defined data to the progress
+ *        updates. If not used, set this to NULL.
+ * @return a list of files that can be followed using the <code>next</code>
+ *        field of the <code>LIBMTP_file_t</code> data structure.
+ *        Each of the metadata tags must be freed after use, and may
+ *        contain only partial metadata information, i.e. one or several
+ *        fields may be NULL or 0.
+ * @see LIBMTP_Get_Filemetadata()
+ */
+LIBMTP_file_t *LIBMTP_Get_Filelisting_With_Callback(LIBMTP_mtpdevice_t *device,
+                                                    LIBMTP_progressfunc_t const callback,
+                                                    void const * const data)
+{
+  uint32_t i = 0;
+  LIBMTP_file_t *retfiles = NULL;
+  LIBMTP_file_t *curfile = NULL;
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  uint16_t ret;
+
+  // Get all the handles if we haven't already done that
+  if (params->nrofobjects == 0) {
+    flush_handles(device);
+  }
+
+  for (i = 0; i < params->nrofobjects; i++) {
+    LIBMTP_file_t *file;
+    PTPObject *ob, *xob;
+
+    if (callback != NULL)
+      callback(i, params->nrofobjects, data);
+
+    ob = &params->objects[i];
+
+    if (ob->oi.ObjectFormat == PTP_OFC_Association) {
+      // MTP use this object format for folders which means
+      // these "files" will turn up on a folder listing instead.
+      continue;
+    }
+
+    // Allocate a new file type
+    file = LIBMTP_new_file_t();
+
+    file->parent_id = ob->oi.ParentObject;
+    file->storage_id = ob->oi.StorageID;
+
+    // This is some sort of unique ID so we can keep track of the track.
+    file->item_id = ob->oid;
+
+    // Set the filetype
+    file->filetype = map_ptp_type_to_libmtp_type(ob->oi.ObjectFormat);
+    
+    // Set the modification date
+    file->modificationdate = ob->oi.ModificationDate;
+
+    // Original file-specific properties
+    // We only have 32-bit file size here; if we find it, we use the 
+    // PTP_OPC_ObjectSize property which has 64bit precision.
+    file->filesize = ob->oi.ObjectCompressedSize;
+    if (ob->oi.Filename != NULL) {
+      file->filename = strdup(ob->oi.Filename);
+    }
+
+    /*
+     * A special quirk for devices that doesn't quite
+     * remember that some files marked as "unknown" type are
+     * actually OGG or FLAC files. We look at the filename extension
+     * and see if it happens that this was atleast named "ogg" or "flac"
+     * and fall back on this heuristic approach in that case, 
+     * for these bugged devices only.
+     */
+    if (file->filetype == LIBMTP_FILETYPE_UNKNOWN) {
+      if ((FLAG_IRIVER_OGG_ALZHEIMER(ptp_usb) ||
+	   FLAG_OGG_IS_UNKNOWN(ptp_usb)) &&
+	  has_ogg_extension(file->filename))
+	file->filetype = LIBMTP_FILETYPE_OGG;
+      if (FLAG_FLAC_IS_UNKNOWN(ptp_usb) &&
+	  has_flac_extension(file->filename))
+	file->filetype = LIBMTP_FILETYPE_FLAC;
+    }
+
+    /*
+     * If we have a cached, large set of metadata, then use it!
+     */
+    ret = ptp_object_want (params, ob->oid, PTPOBJECT_MTPPROPLIST_LOADED, &xob);
+    if (ob->mtpprops) {
+      MTPProperties *prop = ob->mtpprops;
+      int i;
+
+      for (i=0;i<ob->nrofmtpprops;i++) {
+	// Pick ObjectSize here...
+	if (prop->property == PTP_OPC_ObjectSize) {
+	  if (device->object_bitsize == 64) {
+	    file->filesize = prop->propval.u64;
+	  } else {
+	    file->filesize = prop->propval.u32;
+	  }
+	  break;
+	}
+	prop++;
+      }
+    } else {
+      uint16_t *props = NULL;
+      uint32_t propcnt = 0;
+      
+      // First see which properties can be retrieved for this object format
+      ret = ptp_mtp_getobjectpropssupported(params, ob->oi.ObjectFormat, &propcnt, &props);
+      if (ret != PTP_RC_OK) {
+	add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Filelisting_With_Callback(): call to ptp_mtp_getobjectpropssupported() failed.");
+	// Silently fall through.
+      } else {
+        int i;
+	for (i=0;i<propcnt;i++) {
+	  switch (props[i]) {
+	  case PTP_OPC_ObjectSize:
+	    if (device->object_bitsize == 64) {
+	      file->filesize = get_u64_from_object(device, file->item_id, PTP_OPC_ObjectSize, 0);
+	    } else {
+	      file->filesize = get_u32_from_object(device, file->item_id, PTP_OPC_ObjectSize, 0);
+	    }
+	    break;
+	  default:
+	    break;
+	  }
+	}
+	free(props);
+      }
+    }
+    
+    // Add track to a list that will be returned afterwards.
+    if (retfiles == NULL) {
+      retfiles = file;
+      curfile = file;
+    } else {
+      curfile->next = file;
+      curfile = file;
+    }
+
+    // Call listing callback
+    // double progressPercent = (double)i*(double)100.0 / (double)params->handles.n;
+    
+  } // Handle counting loop
+  return retfiles;
+}
+
+/**
+ * This function retrieves the metadata for a single file off
+ * the device.
+ *
+ * Do not call this function repeatedly! The file handles are linearly
+ * searched O(n) and the call may involve (slow) USB traffic, so use
+ * <code>LIBMTP_Get_Filelisting()</code> and cache the file, preferably
+ * as an efficient data structure such as a hash list.
+ *
+ * Incidentally this function will return metadata for
+ * a folder (association) as well, but this is not a proper use
+ * of it, it is intended for file manipulation, not folder manipulation.
+ *
+ * @param device a pointer to the device to get the file metadata from.
+ * @param fileid the object ID of the file that you want the metadata for.
+ * @return a metadata entry on success or NULL on failure.
+ * @see LIBMTP_Get_Filelisting()
+ */
+LIBMTP_file_t *LIBMTP_Get_Filemetadata(LIBMTP_mtpdevice_t *device, uint32_t const fileid)
+{
+  uint32_t i = 0;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+  PTPObject *ob;
+  LIBMTP_file_t *file;
+
+  // Get all the handles if we haven't already done that
+  if (params->nrofobjects == 0) {
+    flush_handles(device);
+  }
+
+  ret = ptp_object_want (params, fileid, PTPOBJECT_OBJECTINFO_LOADED|PTPOBJECT_MTPPROPLIST_LOADED, &ob);
+  if (ret != PTP_RC_OK)
+    return NULL;
+
+  // Allocate a new file type
+  file = LIBMTP_new_file_t();
+  
+  file->parent_id = ob->oi.ParentObject;
+  file->storage_id = ob->oi.StorageID;
+
+  // Set the filetype
+  file->filetype = map_ptp_type_to_libmtp_type(ob->oi.ObjectFormat);
+
+  // Original file-specific properties
+  
+  // We only have 32-bit file size here; later we use the PTP_OPC_ObjectSize property
+  file->filesize = ob->oi.ObjectCompressedSize;
+  if (ob->oi.Filename != NULL) {
+    file->filename = strdup(ob->oi.Filename);
+  }
+
+  // This is some sort of unique ID so we can keep track of the file.
+  file->item_id = fileid;
+
+  /*
+   * If we have a cached, large set of metadata, then use it!
+   */
+  if (ob->mtpprops) {
+    MTPProperties *prop = ob->mtpprops;
+    
+    for (i=0;i<ob->nrofmtpprops;i++,prop++) {
+      // Pick ObjectSize here...
+      if (prop->property == PTP_OPC_ObjectSize) {
+	// This may already be set, but this 64bit precision value 
+	// is better than the PTP 32bit value, so let it override.
+	if (device->object_bitsize == 64) {
+	  file->filesize = prop->propval.u64;
+	} else {
+	  file->filesize = prop->propval.u32;
+	}
+	break;
+      }
+    }
+  } else {
+    uint16_t *props = NULL;
+    uint32_t propcnt = 0;
+    
+    // First see which properties can be retrieved for this object format
+    ret = ptp_mtp_getobjectpropssupported(params, map_libmtp_type_to_ptp_type(file->filetype), &propcnt, &props);
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Filemetadata(): call to ptp_mtp_getobjectpropssupported() failed.");
+      // Silently fall through.
+    } else {
+      for (i=0;i<propcnt;i++) {
+	switch (props[i]) {
+	case PTP_OPC_ObjectSize:
+	  if (device->object_bitsize == 64) {
+	    file->filesize = get_u64_from_object(device, file->item_id, PTP_OPC_ObjectSize, 0);
+	  } else {
+	    file->filesize = get_u32_from_object(device, file->item_id, PTP_OPC_ObjectSize, 0);
+	  }
+	  break;
+	default:
+	  break;
+	}
+      }
+      free(props);
+    }
+  }
+  
+  return file;
+}
+
+/**
+ * This creates a new track metadata structure and allocates memory
+ * for it. Notice that if you add strings to this structure they
+ * will be freed by the corresponding <code>LIBMTP_destroy_track_t</code>
+ * operation later, so be careful of using strdup() when assigning
+ * strings, e.g.:
+ *
+ * <pre>
+ * LIBMTP_track_t *track = LIBMTP_new_track_t();
+ * track->title = strdup(titlestr);
+ * ....
+ * LIBMTP_destroy_track_t(track);
+ * </pre>
+ *
+ * @return a pointer to the newly allocated metadata structure.
+ * @see LIBMTP_destroy_track_t()
+ */
+LIBMTP_track_t *LIBMTP_new_track_t(void)
+{
+  LIBMTP_track_t *new = (LIBMTP_track_t *) malloc(sizeof(LIBMTP_track_t));
+  if (new == NULL) {
+    return NULL;
+  }
+  new->item_id = 0;
+  new->parent_id = 0;
+  new->storage_id = 0;
+  new->title = NULL;
+  new->artist = NULL;
+  new->composer = NULL;
+  new->album = NULL;
+  new->genre = NULL;
+  new->date = NULL;
+  new->filename = NULL;
+  new->duration = 0;
+  new->tracknumber = 0;
+  new->filesize = 0;
+  new->filetype = LIBMTP_FILETYPE_UNKNOWN;
+  new->samplerate = 0;
+  new->nochannels = 0;
+  new->wavecodec = 0;
+  new->bitrate = 0;
+  new->bitratetype = 0;
+  new->rating = 0;
+  new->usecount = 0;
+  new->modificationdate = 0;
+  new->next = NULL;
+  return new;
+}
+
+/**
+ * This destroys a track metadata structure and deallocates the memory
+ * used by it, including any strings. Never use a track metadata
+ * structure again after calling this function on it.
+ * @param track the track metadata to destroy.
+ * @see LIBMTP_new_track_t()
+ */
+void LIBMTP_destroy_track_t(LIBMTP_track_t *track)
+{
+  if (track == NULL) {
+    return;
+  }
+  if (track->title != NULL)
+    free(track->title);
+  if (track->artist != NULL)
+    free(track->artist);
+  if (track->composer != NULL)
+    free(track->composer);
+  if (track->album != NULL)
+    free(track->album);
+  if (track->genre != NULL)
+    free(track->genre);
+  if (track->date != NULL)
+    free(track->date);
+  if (track->filename != NULL)
+    free(track->filename);
+  free(track);
+  return;
+}
+
+/**
+ * This function maps and copies a property onto the track metadata if applicable.
+ */
+static void pick_property_to_track_metadata(LIBMTP_mtpdevice_t *device, MTPProperties *prop, LIBMTP_track_t *track)
+{
+  switch (prop->property) {
+  case PTP_OPC_Name:
+    if (prop->propval.str != NULL)
+      track->title = strdup(prop->propval.str);
+    else
+      track->title = NULL;
+    break;
+  case PTP_OPC_Artist:
+    if (prop->propval.str != NULL)
+      track->artist = strdup(prop->propval.str);
+    else
+      track->artist = NULL;
+    break;
+  case PTP_OPC_Composer:
+    if (prop->propval.str != NULL)
+      track->composer = strdup(prop->propval.str);
+    else
+      track->composer = NULL;
+    break;
+  case PTP_OPC_Duration:
+    track->duration = prop->propval.u32;
+    break;
+  case PTP_OPC_Track:
+    track->tracknumber = prop->propval.u16;
+    break;
+  case PTP_OPC_Genre:
+    if (prop->propval.str != NULL)
+      track->genre = strdup(prop->propval.str);
+    else
+      track->genre = NULL;
+    break;
+  case PTP_OPC_AlbumName:
+    if (prop->propval.str != NULL)
+      track->album = strdup(prop->propval.str);
+    else
+      track->album = NULL;
+    break;
+  case PTP_OPC_OriginalReleaseDate:
+    if (prop->propval.str != NULL)
+      track->date = strdup(prop->propval.str);
+    else
+      track->date = NULL;
+    break;
+    // These are, well not so important.
+  case PTP_OPC_SampleRate:
+    track->samplerate = prop->propval.u32;
+    break;
+  case PTP_OPC_NumberOfChannels:
+    track->nochannels = prop->propval.u16;
+    break;
+  case PTP_OPC_AudioWAVECodec:
+    track->wavecodec = prop->propval.u32;
+    break;
+  case PTP_OPC_AudioBitRate:
+    track->bitrate = prop->propval.u32;
+    break;
+  case PTP_OPC_BitRateType:
+    track->bitratetype = prop->propval.u16;
+    break;
+  case PTP_OPC_Rating:
+    track->rating = prop->propval.u16;
+    break;
+  case PTP_OPC_UseCount:
+    track->usecount = prop->propval.u32;
+    break;
+  case PTP_OPC_ObjectSize:
+    if (device->object_bitsize == 64) {
+      track->filesize = prop->propval.u64;
+    } else {
+      track->filesize = prop->propval.u32;
+    }
+    break;
+  default:
+    break;
+  }
+}
+
+/**
+ * This function retrieves the track metadata for a track
+ * given by a unique ID.
+ * @param device a pointer to the device to get the track metadata off.
+ * @param trackid the unique ID of the track.
+ * @param objectformat the object format of this track, so we know what it supports.
+ * @param track a metadata set to fill in.
+ */
+static void get_track_metadata(LIBMTP_mtpdevice_t *device, uint16_t objectformat,
+			       LIBMTP_track_t *track)
+{
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+  uint32_t i;
+  MTPProperties *prop;
+  PTPObject *ob;
+
+  /*
+   * If we have a cached, large set of metadata, then use it!
+   */
+  ret = ptp_object_want(params, track->item_id, PTPOBJECT_MTPPROPLIST_LOADED, &ob);
+  if (ob->mtpprops) {
+    prop = ob->mtpprops;
+    for (i=0;i<ob->nrofmtpprops;i++,prop++)
+      pick_property_to_track_metadata(device, prop, track);
+  } else {
+    uint16_t *props = NULL;
+    uint32_t propcnt = 0;
+
+    // First see which properties can be retrieved for this object format
+    ret = ptp_mtp_getobjectpropssupported(params, map_libmtp_type_to_ptp_type(track->filetype), &propcnt, &props);
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "get_track_metadata(): call to ptp_mtp_getobjectpropssupported() failed.");
+      // Just bail out for now, nothing is ever set.
+      return;
+    } else {
+      for (i=0;i<propcnt;i++) {
+	switch (props[i]) {
+	case PTP_OPC_Name:
+	  track->title = get_string_from_object(device, track->item_id, PTP_OPC_Name);
+	  break;
+	case PTP_OPC_Artist:
+	  track->artist = get_string_from_object(device, track->item_id, PTP_OPC_Artist);
+	  break;
+	case PTP_OPC_Composer:
+	  track->composer = get_string_from_object(device, track->item_id, PTP_OPC_Composer);
+	  break;
+	case PTP_OPC_Duration:
+	  track->duration = get_u32_from_object(device, track->item_id, PTP_OPC_Duration, 0);
+	  break;
+	case PTP_OPC_Track:
+	  track->tracknumber = get_u16_from_object(device, track->item_id, PTP_OPC_Track, 0);
+	  break;
+	case PTP_OPC_Genre:
+	  track->genre = get_string_from_object(device, track->item_id, PTP_OPC_Genre);
+	  break;
+	case PTP_OPC_AlbumName:
+	  track->album = get_string_from_object(device, track->item_id, PTP_OPC_AlbumName);
+	  break;
+	case PTP_OPC_OriginalReleaseDate:
+	  track->date = get_string_from_object(device, track->item_id, PTP_OPC_OriginalReleaseDate);
+	  break;
+	  // These are, well not so important.
+	case PTP_OPC_SampleRate:
+	  track->samplerate = get_u32_from_object(device, track->item_id, PTP_OPC_SampleRate, 0);
+	  break;
+	case PTP_OPC_NumberOfChannels:
+	  track->nochannels = get_u16_from_object(device, track->item_id, PTP_OPC_NumberOfChannels, 0);
+	  break;
+	case PTP_OPC_AudioWAVECodec:
+	  track->wavecodec = get_u32_from_object(device, track->item_id, PTP_OPC_AudioWAVECodec, 0);
+	  break;
+	case PTP_OPC_AudioBitRate:
+	  track->bitrate = get_u32_from_object(device, track->item_id, PTP_OPC_AudioBitRate, 0);
+	  break;
+	case PTP_OPC_BitRateType:
+	  track->bitratetype = get_u16_from_object(device, track->item_id, PTP_OPC_BitRateType, 0);
+	  break;
+	case PTP_OPC_Rating:
+	  track->rating = get_u16_from_object(device, track->item_id, PTP_OPC_Rating, 0);
+	  break;
+	case PTP_OPC_UseCount:
+	  track->usecount = get_u32_from_object(device, track->item_id, PTP_OPC_UseCount, 0);
+	  break;
+	case PTP_OPC_ObjectSize:
+	  if (device->object_bitsize == 64) {
+	    track->filesize = get_u64_from_object(device, track->item_id, PTP_OPC_ObjectSize, 0);
+	  } else {
+	    track->filesize = (uint64_t) get_u32_from_object(device, track->item_id, PTP_OPC_ObjectSize, 0);
+	  }
+	  break;
+	}
+      }
+      free(props);
+    }
+  }
+}
+
+/**
+ * THIS FUNCTION IS DEPRECATED. PLEASE UPDATE YOUR CODE IN ORDER
+ * NOT TO USE IT.
+ * @see LIBMTP_Get_Tracklisting_With_Callback()
+ */
+LIBMTP_track_t *LIBMTP_Get_Tracklisting(LIBMTP_mtpdevice_t *device)
+{
+  printf("WARNING: LIBMTP_Get_Tracklisting() is deprecated.\n");
+  printf("WARNING: please update your code to use LIBMTP_Get_Tracklisting_With_Callback()\n");
+  return LIBMTP_Get_Tracklisting_With_Callback(device, NULL, NULL);
+}
+
+/**
+ * This returns a long list of all tracks available on the current MTP device.
+ * Tracks include multimedia objects, both music tracks and video tracks.
+ * Typical usage:
+ *
+ * <pre>
+ * LIBMTP_track_t *tracklist;
+ *
+ * tracklist = LIBMTP_Get_Tracklisting_With_Callback(device, callback, data);
+ * while (tracklist != NULL) {
+ *   LIBMTP_track_t *tmp;
+ *
+ *   // Do something on each element in the list here...
+ *   tmp = tracklist;
+ *   tracklist = tracklist->next;
+ *   LIBMTP_destroy_track_t(tmp);
+ * }
+ * </pre>
+ *
+ * If you want to group your track listing by storage (per storage unit) or
+ * arrange tracks into folders, you must dereference the <code>storage_id</code>
+ * and/or <code>parent_id</code> field of the returned <code>LIBMTP_track_t</code>
+ * struct. To arrange by folders or files you typically have to create the proper
+ * trees by calls to <code>LIBMTP_Get_Storage()</code> and/or 
+ * <code>LIBMTP_Get_Folder_List()</code> first.
+ *
+ * @param device a pointer to the device to get the track listing for.
+ * @param callback a function to be called during the tracklisting retrieveal
+ *        for displaying progress bars etc, or NULL if you don't want
+ *        any callbacks.
+ * @param data a user-defined pointer that is passed along to
+ *        the <code>progress</code> function in order to
+ *        pass along some user defined data to the progress
+ *        updates. If not used, set this to NULL.
+ * @return a list of tracks that can be followed using the <code>next</code>
+ *        field of the <code>LIBMTP_track_t</code> data structure.
+ *        Each of the metadata tags must be freed after use, and may
+ *        contain only partial metadata information, i.e. one or several
+ *        fields may be NULL or 0.
+ * @see LIBMTP_Get_Trackmetadata()
+ */
+LIBMTP_track_t *LIBMTP_Get_Tracklisting_With_Callback(LIBMTP_mtpdevice_t *device,
+                                                      LIBMTP_progressfunc_t const callback,
+                                                      void const * const data)
+{
+  uint32_t i = 0;
+  LIBMTP_track_t *retracks = NULL;
+  LIBMTP_track_t *curtrack = NULL;
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+
+  // Get all the handles if we haven't already done that
+  if (params->nrofobjects == 0) {
+    flush_handles(device);
+  }
+
+  for (i = 0; i < params->nrofobjects; i++) {
+    LIBMTP_track_t *track;
+    PTPObject *ob;
+    LIBMTP_filetype_t mtptype;
+
+    if (callback != NULL)
+      callback(i, params->nrofobjects, data);
+
+    ob = &params->objects[i];
+    mtptype = map_ptp_type_to_libmtp_type(ob->oi.ObjectFormat);
+
+    // Ignore stuff we don't know how to handle...
+    // TODO: get this list as an intersection of the sets
+    // supported by the device and the from the device and
+    // all known track files?
+    if (!LIBMTP_FILETYPE_IS_TRACK(mtptype) &&
+	// This row lets through undefined files for examination since they may be forgotten OGG files.
+	(ob->oi.ObjectFormat != PTP_OFC_Undefined || 
+	 (!FLAG_IRIVER_OGG_ALZHEIMER(ptp_usb) &&
+	  !FLAG_OGG_IS_UNKNOWN(ptp_usb) &&
+	  !FLAG_FLAC_IS_UNKNOWN(ptp_usb)))
+	) {
+      //printf("Not a music track (name: %s format: %d), skipping...\n", oi->Filename, oi->ObjectFormat);
+      continue;
+    }
+
+    // Allocate a new track type
+    track = LIBMTP_new_track_t();
+      
+    // This is some sort of unique ID so we can keep track of the track.
+    track->item_id = ob->oid;
+    track->parent_id = ob->oi.ParentObject;
+    track->storage_id = ob->oi.StorageID;
+    track->modificationdate = ob->oi.ModificationDate;
+
+    track->filetype = mtptype;
+
+    // Original file-specific properties
+    track->filesize = ob->oi.ObjectCompressedSize;
+    if (ob->oi.Filename != NULL) {
+      track->filename = strdup(ob->oi.Filename);
+    }
+
+    get_track_metadata(device, ob->oi.ObjectFormat, track);
+
+    /*
+     * A special quirk for iriver devices that doesn't quite
+     * remember that some files marked as "unknown" type are
+     * actually OGG or FLAC files. We look at the filename extension
+     * and see if it happens that this was atleast named "ogg" or "flac"
+     * and fall back on this heuristic approach in that case,
+     * for these bugged devices only.
+     */
+    if (track->filetype == LIBMTP_FILETYPE_UNKNOWN &&
+	track->filename != NULL) {
+      if ((FLAG_IRIVER_OGG_ALZHEIMER(ptp_usb) ||
+	   FLAG_OGG_IS_UNKNOWN(ptp_usb)) &&
+	  has_ogg_extension(track->filename))
+	track->filetype = LIBMTP_FILETYPE_OGG;
+      else if (FLAG_FLAC_IS_UNKNOWN(ptp_usb) &&
+	       has_flac_extension(track->filename))
+	track->filetype = LIBMTP_FILETYPE_FLAC;
+      else {
+	// This was not an OGG/FLAC file so discard it and continue
+	LIBMTP_destroy_track_t(track);
+	continue;
+      }
+    }
+    
+    // Add track to a list that will be returned afterwards.
+    if (retracks == NULL) {
+      retracks = track;
+      curtrack = track;
+    } else {
+      curtrack->next = track;
+      curtrack = track;
+    }
+    
+    // Call listing callback
+    // double progressPercent = (double)i*(double)100.0 / (double)params->handles.n;
+    
+    
+  } // Handle counting loop
+  return retracks;
+}
+
+/**
+ * This function retrieves the metadata for a single track off
+ * the device.
+ *
+ * Do not call this function repeatedly! The track handles are linearly
+ * searched O(n) and the call may involve (slow) USB traffic, so use
+ * <code>LIBMTP_Get_Tracklisting()</code> and cache the tracks, preferably
+ * as an efficient data structure such as a hash list.
+ *
+ * @param device a pointer to the device to get the track metadata from.
+ * @param trackid the object ID of the track that you want the metadata for.
+ * @return a track metadata entry on success or NULL on failure.
+ * @see LIBMTP_Get_Tracklisting()
+ */
+LIBMTP_track_t *LIBMTP_Get_Trackmetadata(LIBMTP_mtpdevice_t *device, uint32_t const trackid)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  PTPObject *ob;
+  LIBMTP_track_t *track;
+  LIBMTP_filetype_t mtptype;
+  uint16_t ret;
+
+  // Get all the handles if we haven't already done that
+  if (params->nrofobjects == 0)
+    flush_handles(device);
+
+  ret = ptp_object_want (params, trackid, PTPOBJECT_OBJECTINFO_LOADED, &ob);
+  if (ret != PTP_RC_OK)
+    return NULL;
+
+  mtptype = map_ptp_type_to_libmtp_type(ob->oi.ObjectFormat);
+
+  // Ignore stuff we don't know how to handle...
+  if (!LIBMTP_FILETYPE_IS_TRACK(mtptype) &&
+      /*
+       * This row lets through undefined files for examination
+       * since they may be forgotten OGG or FLAC files.
+       */
+      (ob->oi.ObjectFormat != PTP_OFC_Undefined || 
+       (!FLAG_IRIVER_OGG_ALZHEIMER(ptp_usb) &&
+	!FLAG_OGG_IS_UNKNOWN(ptp_usb) &&
+	!FLAG_FLAC_IS_UNKNOWN(ptp_usb)))
+      ) {
+    //printf("Not a music track (name: %s format: %d), skipping...\n", oi->Filename, oi->ObjectFormat);
+    return NULL;
+  }
+
+  // Allocate a new track type
+  track = LIBMTP_new_track_t();
+  
+  // This is some sort of unique ID so we can keep track of the track.
+  track->item_id = ob->oid;
+  track->parent_id = ob->oi.ParentObject;
+  track->storage_id = ob->oi.StorageID;
+  track->modificationdate = ob->oi.ModificationDate;
+
+  track->filetype = mtptype;
+
+  // Original file-specific properties
+  track->filesize = ob->oi.ObjectCompressedSize;
+  if (ob->oi.Filename != NULL) {
+    track->filename = strdup(ob->oi.Filename);
+  }
+
+  /*
+   * A special quirk for devices that doesn't quite
+   * remember that some files marked as "unknown" type are
+   * actually OGG or FLAC files. We look at the filename extension
+   * and see if it happens that this was atleast named "ogg"
+   * and fall back on this heuristic approach in that case, 
+   * for these bugged devices only.
+   */
+  if (track->filetype == LIBMTP_FILETYPE_UNKNOWN &&
+      track->filename != NULL) {
+    if ((FLAG_IRIVER_OGG_ALZHEIMER(ptp_usb) ||
+	 FLAG_OGG_IS_UNKNOWN(ptp_usb)) &&
+	has_ogg_extension(track->filename))
+      track->filetype = LIBMTP_FILETYPE_OGG;
+    else if (FLAG_FLAC_IS_UNKNOWN(ptp_usb) &&
+	     has_flac_extension(track->filename))
+      track->filetype = LIBMTP_FILETYPE_FLAC;
+    else {
+      // This was not an OGG/FLAC file so discard it
+      LIBMTP_destroy_track_t(track);
+      return NULL;
+    }
+  }
+  get_track_metadata(device, ob->oi.ObjectFormat, track);
+  return track;
+}
+
+/**
+ * This is a manual conversion from MTPDataGetFunc to PTPDataGetFunc
+ * to isolate the internal type.
+ */
+static uint16_t get_func_wrapper(PTPParams* params, void* priv, unsigned long wantlen, unsigned char *data, unsigned long *gotlen)
+{
+  MTPDataHandler *handler = (MTPDataHandler *)priv;
+  uint16_t ret;
+  uint32_t local_gotlen = 0;
+  ret = handler->getfunc(params, handler->priv, wantlen, data, &local_gotlen);
+  *gotlen = local_gotlen;
+  switch (ret)
+  {
+    case LIBMTP_HANDLER_RETURN_OK:
+      return PTP_RC_OK;
+    case LIBMTP_HANDLER_RETURN_ERROR:
+      return PTP_ERROR_IO;
+    case LIBMTP_HANDLER_RETURN_CANCEL:
+      return PTP_ERROR_CANCEL;
+    default:
+      return PTP_ERROR_IO;
+  }
+}
+
+/**
+ * This is a manual conversion from MTPDataPutFunc to PTPDataPutFunc
+ * to isolate the internal type.
+ */
+static uint16_t put_func_wrapper(PTPParams* params, void* priv, unsigned long sendlen, unsigned char *data, unsigned long *putlen)
+{
+  MTPDataHandler *handler = (MTPDataHandler *)priv;
+  uint16_t ret;
+  uint32_t local_putlen = 0;
+  ret = handler->putfunc(params, handler->priv, sendlen, data, &local_putlen);
+  *putlen = local_putlen;
+  switch (ret)
+  {
+    case LIBMTP_HANDLER_RETURN_OK:
+      return PTP_RC_OK;
+    case LIBMTP_HANDLER_RETURN_ERROR:
+      return PTP_ERROR_IO;
+    case LIBMTP_HANDLER_RETURN_CANCEL:
+      return PTP_ERROR_CANCEL;
+    default:
+      return PTP_ERROR_IO;
+  }
+}
+
+/**
+ * This gets a file off the device to a local file identified
+ * by a filename.
+ * @param device a pointer to the device to get the track from.
+ * @param id the file ID of the file to retrieve.
+ * @param path a filename to use for the retrieved file.
+ * @param callback a progress indicator function or NULL to ignore.
+ * @param data a user-defined pointer that is passed along to
+ *             the <code>progress</code> function in order to
+ *             pass along some user defined data to the progress
+ *             updates. If not used, set this to NULL.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ * @see LIBMTP_Get_File_To_File_Descriptor()
+ */
+int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t *device, uint32_t const id,
+			 char const * const path, LIBMTP_progressfunc_t const callback,
+			 void const * const data)
+{
+  int fd = -1;
+  int ret;
+
+  // Sanity check
+  if (path == NULL) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_To_File(): Bad arguments, path was NULL.");
+    return -1;
+  }
+
+  // Open file
+#ifdef __WIN32__
+#ifdef USE_WINDOWS_IO_H
+  if ( (fd = _open(path, O_RDWR|O_CREAT|O_TRUNC|O_BINARY,_S_IREAD)) == -1 ) {
+#else
+  if ( (fd = open(path, O_RDWR|O_CREAT|O_TRUNC|O_BINARY,S_IRWXU)) == -1 ) {
+#endif
+#else
+  if ( (fd = open(path, O_RDWR|O_CREAT|O_TRUNC,S_IRWXU|S_IRGRP)) == -1) {
+#endif
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_To_File(): Could not create file.");
+    return -1;
+  }
+
+  ret = LIBMTP_Get_File_To_File_Descriptor(device, id, fd, callback, data);
+
+  // Close file
+  close(fd);
+
+  // Delete partial file.
+  if (ret == -1) {
+    unlink(path);
+  }
+
+  return ret;
+}
+
+/**
+ * This gets a file off the device to a file identified
+ * by a file descriptor.
+ *
+ * This function can potentially be used for streaming
+ * files off the device for playback or broadcast for example,
+ * by downloading the file into a stream sink e.g. a socket.
+ *
+ * @param device a pointer to the device to get the file from.
+ * @param id the file ID of the file to retrieve.
+ * @param fd a local file descriptor to write the file to.
+ * @param callback a progress indicator function or NULL to ignore.
+ * @param data a user-defined pointer that is passed along to
+ *             the <code>progress</code> function in order to
+ *             pass along some user defined data to the progress
+ *             updates. If not used, set this to NULL.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ * @see LIBMTP_Get_File_To_File()
+ */
+int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t *device,
+					uint32_t const id,
+					int const fd,
+					LIBMTP_progressfunc_t const callback,
+					void const * const data)
+{
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  PTPObject *ob;
+
+  ret = ptp_object_want (params, id, PTPOBJECT_OBJECTINFO_LOADED, &ob);
+  if (ret != PTP_RC_OK) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_To_File_Descriptor(): Could not get object info.");
+    return -1;
+  }
+  if (ob->oi.ObjectFormat == PTP_OFC_Association) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_To_File_Descriptor(): Bad object format.");
+    return -1;
+  }
+
+  // Callbacks
+  ptp_usb->callback_active = 1;
+  ptp_usb->current_transfer_total = ob->oi.ObjectCompressedSize+
+    PTP_USB_BULK_HDR_LEN+sizeof(uint32_t); // Request length, one parameter
+  ptp_usb->current_transfer_complete = 0;
+  ptp_usb->current_transfer_callback = callback;
+  ptp_usb->current_transfer_callback_data = data;
+
+  ret = ptp_getobject_tofd(params, id, fd);
+
+  ptp_usb->callback_active = 0;
+  ptp_usb->current_transfer_callback = NULL;
+  ptp_usb->current_transfer_callback_data = NULL;
+
+  if (ret == PTP_ERROR_CANCEL) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_CANCELLED, "LIBMTP_Get_File_From_File_Descriptor(): Cancelled transfer.");
+    return -1;
+  }
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_File_To_File_Descriptor(): Could not get file from device.");
+    return -1;
+  }
+
+  return 0;
+}
+
+/**
+ * This gets a file off the device and calls put_func
+ * with chunks of data
+ *
+ * @param device a pointer to the device to get the file from.
+ * @param id the file ID of the file to retrieve.
+ * @param put_func the function to call when we have data.
+ * @param priv the user-defined pointer that is passed to
+ *             <code>put_func</code>.
+ * @param callback a progress indicator function or NULL to ignore.
+ * @param data a user-defined pointer that is passed along to
+ *             the <code>progress</code> function in order to
+ *             pass along some user defined data to the progress
+ *             updates. If not used, set this to NULL.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ */
+int LIBMTP_Get_File_To_Handler(LIBMTP_mtpdevice_t *device,
+					uint32_t const id,
+					MTPDataPutFunc put_func,
+          void * priv,
+					LIBMTP_progressfunc_t const callback,
+					void const * const data)
+{
+  PTPObject *ob;
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+
+  ret = ptp_object_want (params, id, PTPOBJECT_OBJECTINFO_LOADED, &ob);
+  if (ret != PTP_RC_OK) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_To_File_Descriptor(): Could not get object info.");
+    return -1;
+  }
+  if (ob->oi.ObjectFormat == PTP_OFC_Association) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_File_To_File_Descriptor(): Bad object format.");
+    return -1;
+  }
+
+  // Callbacks
+  ptp_usb->callback_active = 1;
+  ptp_usb->current_transfer_total = ob->oi.ObjectCompressedSize+
+    PTP_USB_BULK_HDR_LEN+sizeof(uint32_t); // Request length, one parameter
+  ptp_usb->current_transfer_complete = 0;
+  ptp_usb->current_transfer_callback = callback;
+  ptp_usb->current_transfer_callback_data = data;
+
+  MTPDataHandler mtp_handler;
+  mtp_handler.getfunc = NULL;
+  mtp_handler.putfunc = put_func;
+  mtp_handler.priv = priv;
+
+  PTPDataHandler handler;
+  handler.getfunc = NULL;
+  handler.putfunc = put_func_wrapper;
+  handler.priv = &mtp_handler;
+
+  ret = ptp_getobject_to_handler(params, id, &handler);
+
+  ptp_usb->callback_active = 0;
+  ptp_usb->current_transfer_callback = NULL;
+  ptp_usb->current_transfer_callback_data = NULL;
+
+  if (ret == PTP_ERROR_CANCEL) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_CANCELLED, "LIBMTP_Get_File_From_File_Descriptor(): Cancelled transfer.");
+    return -1;
+  }
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_File_To_File_Descriptor(): Could not get file from device.");
+    return -1;
+  }
+
+  return 0;
+}
+
+
+/**
+ * This gets a track off the device to a file identified
+ * by a filename. This is actually just a wrapper for the
+ * \c LIBMTP_Get_Track_To_File() function.
+ * @param device a pointer to the device to get the track from.
+ * @param id the track ID of the track to retrieve.
+ * @param path a filename to use for the retrieved track.
+ * @param callback a progress indicator function or NULL to ignore.
+ * @param data a user-defined pointer that is passed along to
+ *             the <code>progress</code> function in order to
+ *             pass along some user defined data to the progress
+ *             updates. If not used, set this to NULL.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ * @see LIBMTP_Get_Track_To_File_Descriptor()
+ */
+int LIBMTP_Get_Track_To_File(LIBMTP_mtpdevice_t *device, uint32_t const id,
+			 char const * const path, LIBMTP_progressfunc_t const callback,
+			 void const * const data)
+{
+  // This is just a wrapper
+  return LIBMTP_Get_File_To_File(device, id, path, callback, data);
+}
+
+/**
+ * This gets a track off the device to a file identified
+ * by a file descriptor. This is actually just a wrapper for
+ * the \c LIBMTP_Get_File_To_File_Descriptor() function.
+ * @param device a pointer to the device to get the track from.
+ * @param id the track ID of the track to retrieve.
+ * @param fd a file descriptor to write the track to.
+ * @param callback a progress indicator function or NULL to ignore.
+ * @param data a user-defined pointer that is passed along to
+ *             the <code>progress</code> function in order to
+ *             pass along some user defined data to the progress
+ *             updates. If not used, set this to NULL.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ * @see LIBMTP_Get_Track_To_File()
+ */
+int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t *device,
+					uint32_t const id,
+					int const fd,
+					LIBMTP_progressfunc_t const callback,
+					void const * const data)
+{
+  // This is just a wrapper
+  return LIBMTP_Get_File_To_File_Descriptor(device, id, fd, callback, data);
+}
+
+/**
+ * This gets a track off the device to a handler function.
+ * This is actually just a wrapper for
+ * the \c LIBMTP_Get_File_To_Handler() function.
+ * @param device a pointer to the device to get the track from.
+ * @param id the track ID of the track to retrieve.
+ * @param put_func the function to call when we have data.
+ * @param priv the user-defined pointer that is passed to
+ *             <code>put_func</code>.
+ * @param callback a progress indicator function or NULL to ignore.
+ * @param data a user-defined pointer that is passed along to
+ *             the <code>progress</code> function in order to
+ *             pass along some user defined data to the progress
+ *             updates. If not used, set this to NULL.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ */
+int LIBMTP_Get_Track_To_Handler(LIBMTP_mtpdevice_t *device,
+					uint32_t const id,
+					MTPDataPutFunc put_func,
+          void * priv,
+					LIBMTP_progressfunc_t const callback,
+					void const * const data)
+{
+  // This is just a wrapper
+  return LIBMTP_Get_File_To_Handler(device, id, put_func, priv, callback, data);
+}
+
+/**
+ * This function sends a track from a local file to an
+ * MTP device. A filename and a set of metadata must be
+ * given as input.
+ * @param device a pointer to the device to send the track to.
+ * @param path the filename of a local file which will be sent.
+ * @param metadata a track metadata set to be written along with the file.
+ *        After this call the field <code>metadata-&gt;item_id</code>
+ *        will contain the new track ID. Other fields such
+ *        as the <code>metadata-&gt;filename</code>, <code>metadata-&gt;parent_id</code>
+ *        or <code>metadata-&gt;storage_id</code> may also change during this 
+ *        operation due to device restrictions, so do not rely on the
+ *        contents of this struct to be preserved in any way.
+ *        <ul>
+ *        <li><code>metadata-&gt;parent_id</code> should be set to the parent 
+ *        (e.g. folder) to store this track in. Since some 
+ *        devices are a bit picky about where files
+ *        are placed, a default folder will be chosen if libmtp
+ *        has detected one for the current filetype and this
+ *        parameter is set to 0. If this is 0 and no default folder
+ *        can be found, the file will be stored in the root folder.
+ *        <li><code>metadata-&gt;storage_id</code> should be set to the
+ *        desired storage (e.g. memory card or whatever your device
+ *        presents) to store this track in. Setting this to 0 will store
+ *        the track on the primary storage.
+ *        </ul>
+ * @param callback a progress indicator function or NULL to ignore.
+ * @param data a user-defined pointer that is passed along to
+ *             the <code>progress</code> function in order to
+ *             pass along some user defined data to the progress
+ *             updates. If not used, set this to NULL.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ * @see LIBMTP_Send_Track_From_File_Descriptor()
+ * @see LIBMTP_Send_File_From_File()
+ * @see LIBMTP_Delete_Object()
+ */
+int LIBMTP_Send_Track_From_File(LIBMTP_mtpdevice_t *device,
+			 char const * const path, LIBMTP_track_t * const metadata,
+                         LIBMTP_progressfunc_t const callback,
+			 void const * const data)
+{
+  int fd;
+  int ret;
+
+  // Sanity check
+  if (path == NULL) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Send_Track_From_File(): Bad arguments, path was NULL.");
+    return -1;
+  }
+
+  // Open file
+#ifdef __WIN32__
+#ifdef USE_WINDOWS_IO_H
+  if ( (fd = _open(path, O_RDONLY|O_BINARY) == -1) ) {
+#else
+  if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
+#endif
+#else
+  if ( (fd = open(path, O_RDONLY)) == -1) {
+#endif
+    printf("LIBMTP_Send_Track_From_File(): Could not open source file \"%s\"\n", path);
+    return -1;
+  }
+
+  ret = LIBMTP_Send_Track_From_File_Descriptor(device, fd, metadata, callback, data);
+
+  // Close file.
+#ifdef USE_WINDOWS_IO_H
+  _close(fd);
+#else
+  close(fd);
+#endif
+
+  return ret;
+}
+
+/**
+ * This function sends a track from a file descriptor to an
+ * MTP device. A filename and a set of metadata must be
+ * given as input.
+ * @param device a pointer to the device to send the track to.
+ * @param fd the filedescriptor for a local file which will be sent.
+ * @param metadata a track metadata set to be written along with the file.
+ *        After this call the field <code>metadata-&gt;item_id</code>
+ *        will contain the new track ID. Other fields such
+ *        as the <code>metadata-&gt;filename</code>, <code>metadata-&gt;parent_id</code>
+ *        or <code>metadata-&gt;storage_id</code> may also change during this 
+ *        operation due to device restrictions, so do not rely on the
+ *        contents of this struct to be preserved in any way.
+ *        <ul>
+ *        <li><code>metadata-&gt;parent_id</code> should be set to the parent 
+ *        (e.g. folder) to store this track in. Since some 
+ *        devices are a bit picky about where files
+ *        are placed, a default folder will be chosen if libmtp
+ *        has detected one for the current filetype and this
+ *        parameter is set to 0. If this is 0 and no default folder
+ *        can be found, the file will be stored in the root folder.
+ *        <li><code>metadata-&gt;storage_id</code> should be set to the
+ *        desired storage (e.g. memory card or whatever your device
+ *        presents) to store this track in. Setting this to 0 will store
+ *        the track on the primary storage.
+ *        </ul>
+ * @param callback a progress indicator function or NULL to ignore.
+ * @param data a user-defined pointer that is passed along to
+ *             the <code>progress</code> function in order to
+ *             pass along some user defined data to the progress
+ *             updates. If not used, set this to NULL.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ * @see LIBMTP_Send_Track_From_File()
+ * @see LIBMTP_Delete_Object()
+ */
+int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *device,
+			 int const fd, LIBMTP_track_t * const metadata,
+                         LIBMTP_progressfunc_t const callback,
+			 void const * const data)
+{
+  int subcall_ret;
+  LIBMTP_file_t filedata;
+
+  // Sanity check, is this really a track?
+  if (!LIBMTP_FILETYPE_IS_TRACK(metadata->filetype)) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, 
+			    "LIBMTP_Send_Track_From_File_Descriptor(): "
+			    "I don't think this is actually a track, strange filetype...");
+  }
+
+  // Wrap around the file transfer function
+  filedata.item_id = metadata->item_id;
+  filedata.parent_id = metadata->parent_id;
+  filedata.storage_id = metadata->storage_id;
+  filedata.filename = metadata->filename;
+  filedata.filesize = metadata->filesize;
+  filedata.filetype = metadata->filetype;
+  filedata.next = NULL;
+
+  subcall_ret = LIBMTP_Send_File_From_File_Descriptor(device,
+						      fd, 
+						      &filedata,
+						      callback,
+						      data);
+
+  if (subcall_ret != 0) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, 
+			    "LIBMTP_Send_Track_From_File_Descriptor(): "
+			    "subcall to LIBMTP_Send_File_From_File_Descriptor failed.");
+    // We used to delete the file here, but don't... It might be OK after all.
+    // (void) LIBMTP_Delete_Object(device, metadata->item_id);
+    return -1;
+  }
+  
+  // Pick up new item (and parent, storage) ID
+  metadata->item_id = filedata.item_id;
+  metadata->parent_id = filedata.parent_id;
+  metadata->storage_id = filedata.storage_id;
+
+  // Set track metadata for the new fine track
+  subcall_ret = LIBMTP_Update_Track_Metadata(device, metadata);
+  if (subcall_ret != 0) {
+    // Subcall will add error to errorstack
+    // We used to delete the file here, but don't... It might be OK after all.
+    // (void) LIBMTP_Delete_Object(device, metadata->item_id);
+    return -1;
+  }
+
+  // note we don't need to update the cache here because LIBMTP_Send_File_From_File_Descriptor
+  // has added the object handle and LIBMTP_Update_Track_Metadata has added the metadata.
+
+  return 0;
+}
+
+/**
+ * This function sends a track from a handler function to an
+ * MTP device. A filename and a set of metadata must be
+ * given as input.
+ * @param device a pointer to the device to send the track to.
+ * @param get_func the function to call when we have data.
+ * @param priv the user-defined pointer that is passed to
+ *             <code>get_func</code>.
+ * @param metadata a track metadata set to be written along with the file.
+ *        After this call the field <code>metadata-&gt;item_id</code>
+ *        will contain the new track ID. Other fields such
+ *        as the <code>metadata-&gt;filename</code>, <code>metadata-&gt;parent_id</code>
+ *        or <code>metadata-&gt;storage_id</code> may also change during this 
+ *        operation due to device restrictions, so do not rely on the
+ *        contents of this struct to be preserved in any way.
+ *        <ul>
+ *        <li><code>metadata-&gt;parent_id</code> should be set to the parent 
+ *        (e.g. folder) to store this track in. Since some 
+ *        devices are a bit picky about where files
+ *        are placed, a default folder will be chosen if libmtp
+ *        has detected one for the current filetype and this
+ *        parameter is set to 0. If this is 0 and no default folder
+ *        can be found, the file will be stored in the root folder.
+ *        <li><code>metadata-&gt;storage_id</code> should be set to the
+ *        desired storage (e.g. memory card or whatever your device
+ *        presents) to store this track in. Setting this to 0 will store
+ *        the track on the primary storage.
+ *        </ul>
+ * @param callback a progress indicator function or NULL to ignore.
+ * @param data a user-defined pointer that is passed along to
+ *             the <code>progress</code> function in order to
+ *             pass along some user defined data to the progress
+ *             updates. If not used, set this to NULL.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ * @see LIBMTP_Send_Track_From_File()
+ * @see LIBMTP_Delete_Object()
+ */
+int LIBMTP_Send_Track_From_Handler(LIBMTP_mtpdevice_t *device,
+			 MTPDataGetFunc get_func, void * priv, LIBMTP_track_t * const metadata,
+                         LIBMTP_progressfunc_t const callback,
+			 void const * const data)
+{
+  int subcall_ret;
+  LIBMTP_file_t filedata;
+
+  // Sanity check, is this really a track?
+  if (!LIBMTP_FILETYPE_IS_TRACK(metadata->filetype)) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, 
+			    "LIBMTP_Send_Track_From_Handler(): "
+			    "I don't think this is actually a track, strange filetype...");
+  }
+
+  // Wrap around the file transfer function
+  filedata.item_id = metadata->item_id;
+  filedata.parent_id = metadata->parent_id;
+  filedata.storage_id = metadata->storage_id;
+  filedata.filename = metadata->filename;
+  filedata.filesize = metadata->filesize;
+  filedata.filetype = metadata->filetype;
+  filedata.next = NULL;
+
+  subcall_ret = LIBMTP_Send_File_From_Handler(device,
+						      get_func,
+                  priv, 
+						      &filedata,
+						      callback,
+						      data);
+
+  if (subcall_ret != 0) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, 
+			    "LIBMTP_Send_Track_From_Handler(): "
+			    "subcall to LIBMTP_Send_File_From_Handler failed.");
+    // We used to delete the file here, but don't... It might be OK after all.
+    // (void) LIBMTP_Delete_Object(device, metadata->item_id);
+    return -1;
+  }
+
+  // Pick up new item (and parent, storage) ID
+  metadata->item_id = filedata.item_id;
+  metadata->parent_id = filedata.parent_id;
+  metadata->storage_id = filedata.storage_id;
+
+  // Set track metadata for the new fine track
+  subcall_ret = LIBMTP_Update_Track_Metadata(device, metadata);
+  if (subcall_ret != 0) {
+    // Subcall will add error to errorstack
+    // We used to delete the file here, but don't... It might be OK after all.
+    // (void) LIBMTP_Delete_Object(device, metadata->item_id);
+    return -1;
+  }
+
+  // note we don't need to update the cache here because LIBMTP_Send_File_From_File_Descriptor
+  // has added the object handle and LIBMTP_Update_Track_Metadata has added the metadata.
+
+  return 0;
+}
+
+/**
+ * This function sends a local file to an MTP device.
+ * A filename and a set of metadata must be
+ * given as input.
+ * @param device a pointer to the device to send the track to.
+ * @param path the filename of a local file which will be sent.
+ * @param filedata a file metadata set to be written along with the file.
+ *        After this call the field <code>filedata-&gt;item_id</code>
+ *        will contain the new file ID. Other fields such
+ *        as the <code>filedata-&gt;filename</code>, <code>filedata-&gt;parent_id</code>
+ *        or <code>filedata-&gt;storage_id</code> may also change during this
+ *        operation due to device restrictions, so do not rely on the
+ *        contents of this struct to be preserved in any way.
+ *        <ul>
+ *        <li><code>filedata-&gt;parent_id</code> should be set to the parent
+ *        (e.g. folder) to store this file in. If this is 0,
+ *        the file will be stored in the root folder.
+ *        <li><code>filedata-&gt;storage_id</code> should be set to the
+ *        desired storage (e.g. memory card or whatever your device
+ *        presents) to store this file in. Setting this to 0 will store
+ *        the file on the primary storage.
+ *        </ul>
+ * @param callback a progress indicator function or NULL to ignore.
+ * @param data a user-defined pointer that is passed along to
+ *             the <code>progress</code> function in order to
+ *             pass along some user defined data to the progress
+ *             updates. If not used, set this to NULL.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ * @see LIBMTP_Send_File_From_File_Descriptor()
+ * @see LIBMTP_Delete_Object()
+ */
+int LIBMTP_Send_File_From_File(LIBMTP_mtpdevice_t *device,
+			       char const * const path, LIBMTP_file_t * const filedata,
+			       LIBMTP_progressfunc_t const callback,
+			       void const * const data)
+{
+  int fd;
+  int ret;
+
+  // Sanity check
+  if (path == NULL) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Send_File_From_File(): Bad arguments, path was NULL.");
+    return -1;
+  }
+
+  // Open file
+#ifdef __WIN32__
+#ifdef USE_WINDOWS_IO_H
+  if ( (fd = _open(path, O_RDONLY|O_BINARY) == -1) ) {
+#else
+  if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
+#endif
+#else
+  if ( (fd = open(path, O_RDONLY)) == -1) {
+#endif
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Send_File_From_File(): Could not open source file.");
+    return -1;
+  }
+
+  ret = LIBMTP_Send_File_From_File_Descriptor(device, fd, filedata, callback, data);
+
+  // Close file.
+#ifdef USE_WINDOWS_IO_H
+  _close(fd);
+#else
+  close(fd);
+#endif
+
+  return ret;
+}
+
+/**
+ * This function sends a generic file from a file descriptor to an
+ * MTP device. A filename and a set of metadata must be
+ * given as input.
+ *
+ * This can potentially be used for sending in a stream of unknown
+ * length. Send music files with
+ * <code>LIBMTP_Send_Track_From_File_Descriptor()</code>
+ *
+ * @param device a pointer to the device to send the file to.
+ * @param fd the filedescriptor for a local file which will be sent.
+ * @param filedata a file metadata set to be written along with the file.
+ *        After this call the field <code>filedata-&gt;item_id</code>
+ *        will contain the new file ID. Other fields such
+ *        as the <code>filedata-&gt;filename</code>, <code>filedata-&gt;parent_id</code>
+ *        or <code>filedata-&gt;storage_id</code> may also change during this
+ *        operation due to device restrictions, so do not rely on the
+ *        contents of this struct to be preserved in any way.
+ *        <ul>
+ *        <li><code>filedata-&gt;parent_id</code> should be set to the parent
+ *        (e.g. folder) to store this file in. If this is 0,
+ *        the file will be stored in the root folder.
+ *        <li><code>filedata-&gt;storage_id</code> should be set to the
+ *        desired storage (e.g. memory card or whatever your device
+ *        presents) to store this file in. Setting this to 0 will store
+ *        the file on the primary storage.
+ *        </ul>
+ * @param callback a progress indicator function or NULL to ignore.
+ * @param data a user-defined pointer that is passed along to
+ *             the <code>progress</code> function in order to
+ *             pass along some user defined data to the progress
+ *             updates. If not used, set this to NULL.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ * @see LIBMTP_Send_File_From_File()
+ * @see LIBMTP_Send_Track_From_File_Descriptor()
+ * @see LIBMTP_Delete_Object()
+ */
+int LIBMTP_Send_File_From_File_Descriptor(LIBMTP_mtpdevice_t *device,
+			 int const fd, LIBMTP_file_t * const filedata,
+                         LIBMTP_progressfunc_t const callback,
+			 void const * const data)
+{
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  LIBMTP_file_t *newfilemeta;
+
+  if (send_file_object_info(device, filedata))
+  {
+    // no need to output an error since send_file_object_info will already have done so
+    return -1;
+  }
+
+  // Callbacks
+  ptp_usb->callback_active = 1;
+  // The callback will deactivate itself after this amount of data has been sent
+  // One BULK header for the request, one for the data phase. No parameters to the request.
+  ptp_usb->current_transfer_total = filedata->filesize+PTP_USB_BULK_HDR_LEN*2;
+  ptp_usb->current_transfer_complete = 0;
+  ptp_usb->current_transfer_callback = callback;
+  ptp_usb->current_transfer_callback_data = data;
+
+  ret = ptp_sendobject_fromfd(params, fd, filedata->filesize);
+
+  ptp_usb->callback_active = 0;
+  ptp_usb->current_transfer_callback = NULL;
+  ptp_usb->current_transfer_callback_data = NULL;
+
+  if (ret == PTP_ERROR_CANCEL) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_CANCELLED, "LIBMTP_Send_File_From_File_Descriptor(): Cancelled transfer.");
+    return -1;
+  }
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Send_File_From_File_Descriptor(): "
+				"Could not send object.");
+    return -1;
+  }
+
+  add_object_to_cache(device, filedata->item_id);
+
+  /*
+   * Get the device-assined parent_id from the cache.
+   * The operation that adds it to the cache will
+   * look it up from the device, so we get the new
+   * parent_id from the cache.
+   */
+  newfilemeta = LIBMTP_Get_Filemetadata(device, filedata->item_id);
+  if (newfilemeta != NULL) {
+    filedata->parent_id = newfilemeta->parent_id;
+    filedata->storage_id = newfilemeta->storage_id;
+    LIBMTP_destroy_file_t(newfilemeta);
+  } else {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL,
+			    "LIBMTP_Send_File_From_File_Descriptor(): "
+			    "Could not retrieve updated metadata.");
+    return -1;
+  }
+
+  return 0;
+}
+
+/**
+ * This function sends a generic file from a handler function to an
+ * MTP device. A filename and a set of metadata must be
+ * given as input.
+ *
+ * This can potentially be used for sending in a stream of unknown
+ * length. Send music files with
+ * <code>LIBMTP_Send_Track_From_Handler()</code>
+ *
+ * @param device a pointer to the device to send the file to.
+ * @param get_func the function to call to get data to write
+ * @param priv a user-defined pointer that is passed along to
+ *        <code>get_func</code>. If not used, this is set to NULL.
+ * @param filedata a file metadata set to be written along with the file.
+ *        After this call the field <code>filedata-&gt;item_id</code>
+ *        will contain the new file ID. Other fields such
+ *        as the <code>filedata-&gt;filename</code>, <code>filedata-&gt;parent_id</code>
+ *        or <code>filedata-&gt;storage_id</code> may also change during this
+ *        operation due to device restrictions, so do not rely on the
+ *        contents of this struct to be preserved in any way.
+ *        <ul>
+ *        <li><code>filedata-&gt;parent_id</code> should be set to the parent
+ *        (e.g. folder) to store this file in. If this is 0,
+ *        the file will be stored in the root folder.
+ *        <li><code>filedata-&gt;storage_id</code> should be set to the
+ *        desired storage (e.g. memory card or whatever your device
+ *        presents) to store this file in. Setting this to 0 will store
+ *        the file on the primary storage.
+ *        </ul>
+ * @param callback a progress indicator function or NULL to ignore.
+ * @param data a user-defined pointer that is passed along to
+ *             the <code>progress</code> function in order to
+ *             pass along some user defined data to the progress
+ *             updates. If not used, set this to NULL.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ * @see LIBMTP_Send_File_From_File()
+ * @see LIBMTP_Send_Track_From_File_Descriptor()
+ * @see LIBMTP_Delete_Object()
+ */
+int LIBMTP_Send_File_From_Handler(LIBMTP_mtpdevice_t *device,
+			 MTPDataGetFunc get_func, void * priv, LIBMTP_file_t * const filedata,
+       LIBMTP_progressfunc_t const callback, void const * const data)
+{
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  LIBMTP_file_t *newfilemeta;
+
+  if (send_file_object_info(device, filedata))
+  {
+    // no need to output an error since send_file_object_info will already have done so
+    return -1;
+  }
+
+  // Callbacks
+  ptp_usb->callback_active = 1;
+  // The callback will deactivate itself after this amount of data has been sent
+  // One BULK header for the request, one for the data phase. No parameters to the request.
+  ptp_usb->current_transfer_total = filedata->filesize+PTP_USB_BULK_HDR_LEN*2;
+  ptp_usb->current_transfer_complete = 0;
+  ptp_usb->current_transfer_callback = callback;
+  ptp_usb->current_transfer_callback_data = data;
+
+  MTPDataHandler mtp_handler;
+  mtp_handler.getfunc = get_func;
+  mtp_handler.putfunc = NULL;
+  mtp_handler.priv = priv;
+
+  PTPDataHandler handler;
+  handler.getfunc = get_func_wrapper;
+  handler.putfunc = NULL;
+  handler.priv = &mtp_handler;
+
+  ret = ptp_sendobject_from_handler(params, &handler, filedata->filesize);
+
+  ptp_usb->callback_active = 0;
+  ptp_usb->current_transfer_callback = NULL;
+  ptp_usb->current_transfer_callback_data = NULL;
+
+  if (ret == PTP_ERROR_CANCEL) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_CANCELLED, "LIBMTP_Send_File_From_Handler(): Cancelled transfer.");
+    return -1;
+  }
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Send_File_From_Handler(): "
+				"Could not send object.");
+    return -1;
+  }
+
+  add_object_to_cache(device, filedata->item_id);
+
+  /*
+   * Get the device-assined parent_id from the cache.
+   * The operation that adds it to the cache will
+   * look it up from the device, so we get the new
+   * parent_id from the cache.
+   */
+  newfilemeta = LIBMTP_Get_Filemetadata(device, filedata->item_id);
+  if (newfilemeta != NULL) {
+    filedata->parent_id = newfilemeta->parent_id;
+    filedata->storage_id = newfilemeta->storage_id;
+    LIBMTP_destroy_file_t(newfilemeta);
+  } else {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL,
+			    "LIBMTP_Send_File_From_Handler(): "
+			    "Could not retrieve updated metadata.");
+    return -1;
+  }
+
+  return 0;
+}
+
+/**
+ * This function sends the file object info, ready for sendobject
+ * @param device a pointer to the device to send the file to.
+ * @param filedata a file metadata set to be written along with the file.
+ * @return 0 if the transfer was successful, any other value means
+ *           failure.
+ */
+static int send_file_object_info(LIBMTP_mtpdevice_t *device, LIBMTP_file_t *filedata)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  uint32_t store;
+  int use_primary_storage = 1;
+  uint16_t of = map_libmtp_type_to_ptp_type(filedata->filetype);
+  LIBMTP_devicestorage_t *storage;
+  uint32_t localph = filedata->parent_id;
+  uint16_t ret;
+  int i;
+
+  if (filedata->storage_id != 0) {
+    store = filedata->storage_id;
+  } else {
+    store = get_writeable_storageid(device, filedata->filesize);
+  }
+  // Detect if something non-primary is in use.
+  storage = device->storage;
+  if (storage != NULL && store != storage->id) {
+    use_primary_storage = 0;
+  }
+
+  /*
+   * If no destination folder was given, look up a default
+   * folder if possible. Perhaps there is some way of retrieveing
+   * the default folder for different forms of content, what
+   * do I know, we use a fixed list in lack of any better method.
+   * Some devices obviously need to have their files in certain
+   * folders in order to find/display them at all (hello Creative),
+   * so we have to have a method for this. We only do this if the
+   * primary storage is in use.
+   */
+
+  if (localph == 0 && use_primary_storage) {
+    if (LIBMTP_FILETYPE_IS_AUDIO(filedata->filetype)) {
+      localph = device->default_music_folder;
+    } else if (LIBMTP_FILETYPE_IS_VIDEO(filedata->filetype)) {
+      localph = device->default_video_folder;
+    } else if (of == PTP_OFC_EXIF_JPEG ||
+	       of == PTP_OFC_JP2 ||
+	       of == PTP_OFC_JPX ||
+	       of == PTP_OFC_JFIF ||
+	       of == PTP_OFC_TIFF ||
+	       of == PTP_OFC_TIFF_IT ||
+	       of == PTP_OFC_BMP ||
+	       of == PTP_OFC_GIF ||
+	       of == PTP_OFC_PICT ||
+	       of == PTP_OFC_PNG ||
+	       of == PTP_OFC_MTP_WindowsImageFormat) {
+      localph = device->default_picture_folder;
+    } else if (of == PTP_OFC_MTP_vCalendar1 ||
+	       of == PTP_OFC_MTP_vCalendar2 ||
+	       of == PTP_OFC_MTP_UndefinedContact ||
+	       of == PTP_OFC_MTP_vCard2 ||
+	       of == PTP_OFC_MTP_vCard3 ||
+	       of == PTP_OFC_MTP_UndefinedCalendarItem) {
+      localph = device->default_organizer_folder;
+    } else if (of == PTP_OFC_Text) {
+      localph = device->default_text_folder;
+    }
+  }
+
+  // Here we wire the type to unknown on bugged, but
+  // Ogg or FLAC-supportive devices.
+  if (FLAG_OGG_IS_UNKNOWN(ptp_usb) && of == PTP_OFC_MTP_OGG) {
+    of = PTP_OFC_Undefined;
+  }
+  if (FLAG_FLAC_IS_UNKNOWN(ptp_usb) && of == PTP_OFC_MTP_FLAC) {
+    of = PTP_OFC_Undefined;
+  }
+
+  if (ptp_operation_issupported(params, PTP_OC_MTP_SendObjectPropList) &&
+      !FLAG_BROKEN_SEND_OBJECT_PROPLIST(ptp_usb)) {
+    /*
+     * MTP enhanched does it this way (from a sniff):
+     * -> PTP_OC_MTP_SendObjectPropList (0x9808):
+     *    20 00 00 00 01 00 08 98 1B 00 00 00 01 00 01 00
+     *    FF FF FF FF 00 30 00 00 00 00 00 00 12 5E 00 00
+     *    Length: 0x00000020
+     *    Type:   0x0001 PTP_USB_CONTAINER_COMMAND
+     *    Code:   0x9808
+     *    Transaction ID: 0x0000001B
+     *    Param1: 0x00010001 <- store
+     *    Param2: 0xffffffff <- parent handle (-1 ?)
+     *    Param3: 0x00003000 <- file type PTP_OFC_Undefined - we don't know about PDF files
+     *    Param4: 0x00000000 <- file length MSB (-0x0c header len)
+     *    Param5: 0x00005e12 <- file length LSB (-0x0c header len)
+     *
+     * -> PTP_OC_MTP_SendObjectPropList (0x9808):
+     *    46 00 00 00 02 00 08 98 1B 00 00 00 03 00 00 00
+     *    00 00 00 00 07 DC FF FF 0D 4B 00 53 00 30 00 36 - dc07 = file name
+     *    00 30 00 33 00 30 00 36 00 2E 00 70 00 64 00 66
+     *    00 00 00 00 00 00 00 03 DC 04 00 00 00 00 00 00 - dc03 = protection status
+     *    00 4F DC 02 00 01                               - dc4f = non consumable
+     *    Length: 0x00000046
+     *    Type:   0x0002 PTP_USB_CONTAINER_DATA
+     *    Code:   0x9808
+     *    Transaction ID: 0x0000001B
+     *    Metadata....
+     *    0x00000003 <- Number of metadata items
+     *    0x00000000 <- Object handle, set to 0x00000000 since it is unknown!
+     *    0xdc07     <- metadata type: file name
+     *    0xffff     <- metadata type: string
+     *    0x0d       <- number of (uint16_t) characters
+     *    4b 53 30 36 30 33 30 36 2e 50 64 66 00 "KS060306.pdf", null terminated
+     *    0x00000000 <- Object handle, set to 0x00000000 since it is unknown!
+     *    0xdc03     <- metadata type: protection status
+     *    0x0004     <- metadata type: uint16_t
+     *    0x0000     <- not protected
+     *    0x00000000 <- Object handle, set to 0x00000000 since it is unknown!
+     *    0xdc4f     <- non consumable
+     *    0x0002     <- metadata type: uint8_t
+     *    0x01       <- non-consumable (this device cannot display PDF)
+     *
+     * <- Read 0x18 bytes back
+     *    18 00 00 00 03 00 01 20 1B 00 00 00 01 00 01 00
+     *    00 00 00 00 01 40 00 00
+     *    Length: 0x000000018
+     *    Type:   0x0003 PTP_USB_CONTAINER_RESPONSE
+     *    Code:   0x2001 PTP_OK
+     *    Transaction ID: 0x0000001B
+     *    Param1: 0x00010001 <- store
+     *    Param2: 0x00000000 <- parent handle
+     *    Param3: 0x00004001 <- new file/object ID
+     *
+     * -> PTP_OC_SendObject (0x100d)
+     *    0C 00 00 00 01 00 0D 10 1C 00 00 00
+     * -> ... all the bytes ...
+     * <- Read 0x0c bytes back
+     *    0C 00 00 00 03 00 01 20 1C 00 00 00
+     *    ... Then update metadata one-by one, actually (instead of sending it first!) ...
+     */
+    MTPProperties *props = NULL;
+    int nrofprops = 0;
+    MTPProperties *prop = NULL;
+    uint16_t *properties = NULL;
+    uint32_t propcnt = 0;
+
+    // default parent handle
+    if (localph == 0)
+      localph = 0xFFFFFFFFU; // Set to -1
+
+    // Must be 0x00000000U for new objects
+    filedata->item_id = 0x00000000U;
+
+    ret = ptp_mtp_getobjectpropssupported(params, of, &propcnt, &properties);
+
+    for (i=0;i<propcnt;i++) {
+      PTPObjectPropDesc opd;
+
+      ret = ptp_mtp_getobjectpropdesc(params, properties[i], of, &opd);
+      if (ret != PTP_RC_OK) {
+	add_ptp_error_to_errorstack(device, ret, "send_file_object_info(): "
+				"could not get property description.");
+      } else if (opd.GetSet) {
+	switch (properties[i]) {
+	case PTP_OPC_ObjectFileName:
+	  prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	  prop->ObjectHandle = filedata->item_id;
+	  prop->property = PTP_OPC_ObjectFileName;
+	  prop->datatype = PTP_DTC_STR;
+	  if (filedata->filename != NULL) {
+	    prop->propval.str = strdup(filedata->filename);
+	    if (FLAG_ONLY_7BIT_FILENAMES(ptp_usb)) {
+	      strip_7bit_from_utf8(prop->propval.str);
+	    }
+	  }
+	  break;
+	case PTP_OPC_ProtectionStatus:
+	  prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	  prop->ObjectHandle = filedata->item_id;
+	  prop->property = PTP_OPC_ProtectionStatus;
+	  prop->datatype = PTP_DTC_UINT16;
+	  prop->propval.u16 = 0x0000U; /* Not protected */
+	  break;
+	case PTP_OPC_NonConsumable:
+	  prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	  prop->ObjectHandle = filedata->item_id;
+	  prop->property = PTP_OPC_NonConsumable;
+	  prop->datatype = PTP_DTC_UINT8;
+	  prop->propval.u8 = 0x00; /* It is supported, then it is consumable */
+	  break;
+	case PTP_OPC_Name:
+	  prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	  prop->ObjectHandle = filedata->item_id;
+	  prop->property = PTP_OPC_Name;
+	  prop->datatype = PTP_DTC_STR;
+	  if (filedata->filename != NULL)
+	    prop->propval.str = strdup(filedata->filename);
+	  break;
+	case PTP_OPC_DateModified:
+	  // Tag with current time if that is supported
+	  if (!FLAG_CANNOT_HANDLE_DATEMODIFIED(ptp_usb)) {
+	    prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	    prop->ObjectHandle = filedata->item_id;
+	    prop->property = PTP_OPC_DateModified;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = get_iso8601_stamp();
+	    filedata->modificationdate = time(NULL);
+	  }
+	  break;
+	}
+      }
+      ptp_free_objectpropdesc(&opd);
+    }
+    free(properties);
+
+    ret = ptp_mtp_sendobjectproplist(params, &store, &localph, &filedata->item_id,
+				     of, filedata->filesize, props, nrofprops);
+
+    /* Free property list */
+    ptp_destroy_object_prop_list(props, nrofprops);
+
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "send_file_object_info():"
+				  "Could not send object property list.");
+      if (ret == PTP_RC_AccessDenied) {
+	add_ptp_error_to_errorstack(device, ret, "ACCESS DENIED.");
+      }
+      return -1;
+    }
+  } else if (ptp_operation_issupported(params,PTP_OC_SendObjectInfo)) {
+    PTPObjectInfo new_file;
+
+    memset(&new_file, 0, sizeof(PTPObjectInfo));
+
+    new_file.Filename = filedata->filename;
+    if (FLAG_ONLY_7BIT_FILENAMES(ptp_usb)) {
+      strip_7bit_from_utf8(new_file.Filename);
+    }
+    // We lose precision here.
+    new_file.ObjectCompressedSize = (uint32_t) filedata->filesize;
+    new_file.ObjectFormat = of;
+    new_file.StorageID = store;
+    new_file.ParentObject = localph;
+    new_file.ModificationDate = time(NULL);
+
+    // Create the object
+    ret = ptp_sendobjectinfo(params, &store, &localph, &filedata->item_id, &new_file);
+
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "send_file_object_info(): "
+				  "Could not send object info.");
+      if (ret == PTP_RC_AccessDenied) {
+	add_ptp_error_to_errorstack(device, ret, "ACCESS DENIED.");
+      }
+      return -1;
+    }
+    // NOTE: the char* pointers inside new_file are not copies so don't
+    // try to destroy this objectinfo!
+  }
+
+  // Now there IS an object with this parent handle.
+  filedata->parent_id = localph;
+
+  return 0;
+}
+
+/**
+ * This function updates the MTP track object metadata on a
+ * single file identified by an object ID.
+ * @param device a pointer to the device to update the track
+ *        metadata on.
+ * @param metadata a track metadata set to be written to the file.
+ *        notice that the <code>track_id</code> field of the
+ *        metadata structure must be correct so that the
+ *        function can update the right file. If some properties
+ *        of this metadata are set to NULL (strings) or 0
+ *        (numerical values) they will be discarded and the
+ *        track will not be tagged with these blank values.
+ * @return 0 on success, any other value means failure. If some
+ *        or all of the properties fail to update we will still
+ *        return success. On some devices (notably iRiver T30)
+ *        properties that exist cannot be updated.
+ */
+int LIBMTP_Update_Track_Metadata(LIBMTP_mtpdevice_t *device,
+				 LIBMTP_track_t const * const metadata)
+{
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  uint32_t i;
+  uint16_t *properties = NULL;
+  uint32_t propcnt = 0;
+
+  // First see which properties can be set on this file format and apply accordingly
+  // i.e only try to update this metadata for object tags that exist on the current player.
+  ret = ptp_mtp_getobjectpropssupported(params, map_libmtp_type_to_ptp_type(metadata->filetype), &propcnt, &properties);
+  if (ret != PTP_RC_OK) {
+    // Just bail out for now, nothing is ever set.
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+			    "could not retrieve supported object properties.");
+    return -1;
+  }
+  if (ptp_operation_issupported(params, PTP_OC_MTP_SetObjPropList) &&
+      !FLAG_BROKEN_SET_OBJECT_PROPLIST(ptp_usb)) {
+    MTPProperties *props = NULL;
+    MTPProperties *prop = NULL;
+    int nrofprops = 0;
+
+    for (i=0;i<propcnt;i++) {
+      PTPObjectPropDesc opd;
+
+      ret = ptp_mtp_getobjectpropdesc(params, properties[i], map_libmtp_type_to_ptp_type(metadata->filetype), &opd);
+      if (ret != PTP_RC_OK) {
+	add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				"could not get property description.");
+      } else if (opd.GetSet) {
+	switch (properties[i]) {
+	case PTP_OPC_Name:
+	  if (metadata->title == NULL)
+	    break;
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_Name;
+	  prop->datatype = PTP_DTC_STR;
+	  prop->propval.str = strdup(metadata->title);
+	  break;
+	case PTP_OPC_AlbumName:
+	  if (metadata->album == NULL)
+	    break;
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_AlbumName;
+	  prop->datatype = PTP_DTC_STR;
+	  prop->propval.str = strdup(metadata->album);
+	  break;
+	case PTP_OPC_Artist:
+	  if (metadata->artist == NULL)
+	    break;
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_Artist;
+	  prop->datatype = PTP_DTC_STR;
+	  prop->propval.str = strdup(metadata->artist);
+	  break;
+	case PTP_OPC_Composer:
+	  if (metadata->composer == NULL)
+	    break;
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_Composer;
+	  prop->datatype = PTP_DTC_STR;
+	  prop->propval.str = strdup(metadata->composer);
+	  break;
+	case PTP_OPC_Genre:
+	  if (metadata->genre == NULL)
+	    break;
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_Genre;
+	  prop->datatype = PTP_DTC_STR;
+	  prop->propval.str = strdup(metadata->genre);
+	  break;
+	case PTP_OPC_Duration:
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_Duration;
+	  prop->datatype = PTP_DTC_UINT32;
+	  prop->propval.u32 = adjust_u32(metadata->duration, &opd);
+	  break;
+	case PTP_OPC_Track:
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_Track;
+	  prop->datatype = PTP_DTC_UINT16;
+	  prop->propval.u16 = adjust_u16(metadata->tracknumber, &opd);
+	  break;
+	case PTP_OPC_OriginalReleaseDate:
+	  if (metadata->date == NULL)
+	    break;
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_OriginalReleaseDate;
+	  prop->datatype = PTP_DTC_STR;
+	  prop->propval.str = strdup(metadata->date);
+	  break;
+	case PTP_OPC_SampleRate:
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_SampleRate;
+	  prop->datatype = PTP_DTC_UINT32;
+	  prop->propval.u32 = adjust_u32(metadata->samplerate, &opd);
+	  break;
+	case PTP_OPC_NumberOfChannels:
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_NumberOfChannels;
+	  prop->datatype = PTP_DTC_UINT16;
+	  prop->propval.u16 = adjust_u16(metadata->nochannels, &opd);
+	  break;
+	case PTP_OPC_AudioWAVECodec:
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_AudioWAVECodec;
+	  prop->datatype = PTP_DTC_UINT32;
+	  prop->propval.u32 = adjust_u32(metadata->wavecodec, &opd);
+	  break;
+	case PTP_OPC_AudioBitRate:
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_AudioBitRate;
+	  prop->datatype = PTP_DTC_UINT32;
+	  prop->propval.u32 = adjust_u32(metadata->bitrate, &opd);
+	  break;
+	case PTP_OPC_BitRateType:
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_BitRateType;
+	  prop->datatype = PTP_DTC_UINT16;
+	  prop->propval.u16 = adjust_u16(metadata->bitratetype, &opd);
+	  break;
+	case PTP_OPC_Rating:
+	  // TODO: shall this be set for rating 0?
+	  if (metadata->rating == 0)
+	    break;
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_Rating;
+	  prop->datatype = PTP_DTC_UINT16;
+	  prop->propval.u16 = adjust_u16(metadata->rating, &opd);
+	  break;
+	case PTP_OPC_UseCount:
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = metadata->item_id;
+	  prop->property = PTP_OPC_UseCount;
+	  prop->datatype = PTP_DTC_UINT32;
+	  prop->propval.u32 = adjust_u32(metadata->usecount, &opd);
+	  break;
+	case PTP_OPC_DateModified:
+	  if (!FLAG_CANNOT_HANDLE_DATEMODIFIED(ptp_usb)) {
+	    // Tag with current time if that is supported
+	    prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	    prop->ObjectHandle = metadata->item_id;
+	    prop->property = PTP_OPC_DateModified;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = get_iso8601_stamp();
+	  }
+	  break;
+	default:
+	  break;
+	}
+      }
+      ptp_free_objectpropdesc(&opd);
+    }
+
+    // NOTE: File size is not updated, this should not change anyway.
+    // neither will we change the filename.
+
+    ret = ptp_mtp_setobjectproplist(params, props, nrofprops);
+
+    ptp_destroy_object_prop_list(props, nrofprops);
+
+    if (ret != PTP_RC_OK) {
+      // TODO: return error of which property we couldn't set
+      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+			      "could not set object property list.");
+      free(properties);
+      return -1;
+    }
+
+  } else if (ptp_operation_issupported(params,PTP_OC_MTP_SetObjectPropValue)) {
+    for (i=0;i<propcnt;i++) {
+      PTPObjectPropDesc opd;
+
+      ret = ptp_mtp_getobjectpropdesc(params, properties[i], map_libmtp_type_to_ptp_type(metadata->filetype), &opd);
+      if (ret != PTP_RC_OK) {
+	add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				"could not get property description.");
+      } else if (opd.GetSet) {
+	switch (properties[i]) {
+	case PTP_OPC_Name:
+	  // Update title
+	  ret = set_object_string(device, metadata->item_id, PTP_OPC_Name, metadata->title);
+	  if (ret != 0) {
+	    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				    "could not set track title.");
+	  }
+	  break;
+	case PTP_OPC_AlbumName:
+	  // Update album
+	  ret = set_object_string(device, metadata->item_id, PTP_OPC_AlbumName, metadata->album);
+	  if (ret != 0) {
+	    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				    "could not set track album name.");
+	  }
+	  break;
+	case PTP_OPC_Artist:
+	  // Update artist
+	  ret = set_object_string(device, metadata->item_id, PTP_OPC_Artist, metadata->artist);
+	  if (ret != 0) {
+	    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				    "could not set track artist name.");
+	  }
+	  break;
+	case PTP_OPC_Composer:
+	  // Update composer
+	  ret = set_object_string(device, metadata->item_id, PTP_OPC_Composer, metadata->composer);
+	  if (ret != 0) {
+	    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				    "could not set track composer name.");
+	  }
+	  break;
+	case PTP_OPC_Genre:
+	  // Update genre
+	  ret = set_object_string(device, metadata->item_id, PTP_OPC_Genre, metadata->genre);
+	  if (ret != 0) {
+	    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				    "could not set track genre name.");
+	  }
+	  break;
+	case PTP_OPC_Duration:
+	  // Update duration
+	  if (metadata->duration != 0) {
+	    ret = set_object_u32(device, metadata->item_id, PTP_OPC_Duration, adjust_u32(metadata->duration, &opd));
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				      "could not set track duration.");
+	    }
+	  }
+	  break;
+	case PTP_OPC_Track:
+	  // Update track number.
+	  if (metadata->tracknumber != 0) {
+	    ret = set_object_u16(device, metadata->item_id, PTP_OPC_Track, adjust_u16(metadata->tracknumber, &opd));
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				      "could not set track tracknumber.");
+	    }
+	  }
+	  break;
+	case PTP_OPC_OriginalReleaseDate:
+	  // Update creation datetime
+	  ret = set_object_string(device, metadata->item_id, PTP_OPC_OriginalReleaseDate, metadata->date);
+	  if (ret != 0) {
+	    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				    "could not set track release date.");
+	  }
+	  break;
+	  // These are, well not so important.
+	case PTP_OPC_SampleRate:
+	  // Update sample rate
+	  if (metadata->samplerate != 0) {
+	    ret = set_object_u32(device, metadata->item_id, PTP_OPC_SampleRate, adjust_u32(metadata->samplerate, &opd));
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				      "could not set samplerate.");
+	    }
+	  }
+	  break;
+	case PTP_OPC_NumberOfChannels:
+	  // Update number of channels
+	  if (metadata->nochannels != 0) {
+	    ret = set_object_u16(device, metadata->item_id, PTP_OPC_NumberOfChannels, adjust_u16(metadata->nochannels, &opd));
+	  if (ret != 0) {
+	    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				    "could not set number of channels.");
+	  }
+	}
+	  break;
+	case PTP_OPC_AudioWAVECodec:
+	  // Update WAVE codec
+	  if (metadata->wavecodec != 0) {
+	    ret = set_object_u32(device, metadata->item_id, PTP_OPC_AudioWAVECodec, adjust_u32(metadata->wavecodec, &opd));
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				      "could not set WAVE codec.");
+	    }
+	  }
+	  break;
+	case PTP_OPC_AudioBitRate:
+	  // Update bitrate
+	  if (metadata->bitrate != 0) {
+	    ret = set_object_u32(device, metadata->item_id, PTP_OPC_AudioBitRate, adjust_u32(metadata->bitrate, &opd));
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				      "could not set bitrate.");
+	  }
+	  }
+	  break;
+	case PTP_OPC_BitRateType:
+	  // Update bitrate type
+	  if (metadata->bitratetype != 0) {
+	    ret = set_object_u16(device, metadata->item_id, PTP_OPC_BitRateType, adjust_u16(metadata->bitratetype, &opd));
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				      "could not set bitratetype.");
+	    }
+	  }
+	  break;
+	case PTP_OPC_Rating:
+	  // Update user rating
+	  // TODO: shall this be set for rating 0?
+	  if (metadata->rating != 0) {
+	    ret = set_object_u16(device, metadata->item_id, PTP_OPC_Rating, adjust_u16(metadata->rating, &opd));
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				      "could not set user rating.");
+	    }
+	  }
+	  break;
+	case PTP_OPC_UseCount:
+	  // Update use count, set even to zero if desired.
+	  ret = set_object_u32(device, metadata->item_id, PTP_OPC_UseCount, adjust_u32(metadata->usecount, &opd));
+	  if (ret != 0) {
+	    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				  "could not set use count.");
+	  }
+	  break;
+	case PTP_OPC_DateModified:
+	  if (!FLAG_CANNOT_HANDLE_DATEMODIFIED(ptp_usb)) {
+	    // Update modification time if supported
+	    char *tmpstamp = get_iso8601_stamp();
+	    ret = set_object_string(device, metadata->item_id, PTP_OPC_DateModified, tmpstamp);
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+				      "could not set modification date.");
+	    }
+	    free(tmpstamp);
+	  }
+	  break;
+
+	  // NOTE: File size is not updated, this should not change anyway.
+	  // neither will we change the filename.
+	default:
+	  break;
+	}
+      }
+      ptp_free_objectpropdesc(&opd);
+    }
+  } else {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Update_Track_Metadata(): "
+                            "Your device doesn't seem to support any known way of setting metadata.");
+    free(properties);
+    return -1;
+  }
+
+  // update cached object properties if metadata cache exists
+  update_metadata_cache(device, metadata->item_id);
+
+  free(properties);
+
+  return 0;
+}
+
+/**
+ * This function deletes a single file, track, playlist, folder or
+ * any other object off the MTP device, identified by the object ID.
+ *
+ * If you delete a folder, there is no guarantee that the device will
+ * really delete all the files that were in that folder, rather it is
+ * expected that they will not be deleted, and will turn up in object
+ * listings with parent set to a non-existant object ID. The safe way
+ * to do this is to recursively delete all files (and folders) contained
+ * in the folder, then the folder itself.
+ *
+ * @param device a pointer to the device to delete the object from.
+ * @param object_id the object to delete.
+ * @return 0 on success, any other value means failure.
+ */
+int LIBMTP_Delete_Object(LIBMTP_mtpdevice_t *device,
+			 uint32_t object_id)
+{
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+
+  ret = ptp_deleteobject(params, object_id, 0);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Delete_Object(): could not delete object.");
+    return -1;
+  }
+
+  return 0;
+}
+
+/**
+ * Internal function to update an object filename property.
+ */
+static int set_object_filename(LIBMTP_mtpdevice_t *device,
+			       uint32_t object_id, uint16_t ptp_type,
+			       const char **newname_ptr)
+{
+  PTPParams             *params = (PTPParams *) device->params;
+  PTP_USB               *ptp_usb = (PTP_USB*) device->usbinfo;
+  PTPObjectPropDesc     opd;
+  uint16_t              ret;
+  char                  *newname;
+
+  // See if we can modify the filename on this kind of files.
+  ret = ptp_mtp_getobjectpropdesc(params, PTP_OPC_ObjectFileName, ptp_type, &opd);
+  if (ret != PTP_RC_OK) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "set_object_filename(): "
+			    "could not get property description.");
+    return -1;
+  }
+
+  if (!opd.GetSet) {
+    ptp_free_objectpropdesc(&opd);
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "set_object_filename(): "
+            " property is not settable.");
+    // TODO: we COULD actually upload/download the object here, if we feel
+    //       like wasting time for the user.
+    return -1;
+  }
+
+  newname = strdup(*newname_ptr);
+
+  if (FLAG_ONLY_7BIT_FILENAMES(ptp_usb)) {
+    strip_7bit_from_utf8(newname);
+  }
+
+  if (ptp_operation_issupported(params, PTP_OC_MTP_SetObjPropList) &&
+      !FLAG_BROKEN_SET_OBJECT_PROPLIST(ptp_usb)) {
+    MTPProperties *props = NULL;
+    MTPProperties *prop = NULL;
+    int nrofprops = 0;
+
+    prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+    prop->ObjectHandle = object_id;
+    prop->property = PTP_OPC_ObjectFileName;
+    prop->datatype = PTP_DTC_STR;
+    prop->propval.str = newname;
+
+    ret = ptp_mtp_setobjectproplist(params, props, nrofprops);
+
+    ptp_destroy_object_prop_list(props, nrofprops);
+
+    if (ret != PTP_RC_OK) {
+        add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "set_object_filename(): "
+              " could not set object property list.");
+        ptp_free_objectpropdesc(&opd);
+        return -1;
+    }
+  } else if (ptp_operation_issupported(params, PTP_OC_MTP_SetObjectPropValue)) {
+    ret = set_object_string(device, object_id, PTP_OPC_ObjectFileName, newname);
+    if (ret != 0) {
+      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "set_object_filename(): "
+              " could not set object filename.");
+      ptp_free_objectpropdesc(&opd);
+      return -1;
+    }
+  } else {
+    free(newname);
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "set_object_filename(): "
+              " your device doesn't seem to support any known way of setting metadata.");
+    ptp_free_objectpropdesc(&opd);
+    return -1;
+  }
+
+  ptp_free_objectpropdesc(&opd);
+
+  // update cached object properties if metadata cache exists
+  update_metadata_cache(device, object_id);
+
+  return 0;
+}
+
+/**
+ * This function renames a single file.
+ * This simply means that the PTP_OPC_ObjectFileName property
+ * is updated, if this is supported by the device.
+ *
+ * @param device a pointer to the device that contains the file.
+ * @param file the file metadata of the file to rename.
+ *        On success, the filename member is updated. Be aware, that
+ *        this name can be different than newname depending of device restrictions.
+ * @param newname the new filename for this object.
+ * @return 0 on success, any other value means failure.
+ */
+int LIBMTP_Set_File_Name(LIBMTP_mtpdevice_t *device,
+                   LIBMTP_file_t *file, const char *newname)
+{
+  int         ret;
+
+  ret = set_object_filename(device, file->item_id,
+			    map_libmtp_type_to_ptp_type(file->filetype),
+			    &newname);
+
+  if (ret != 0) {
+    return ret;
+  }
+
+  free(file->filename);
+  file->filename = strdup(newname);
+  return ret;
+}
+
+/**
+ * This function renames a single folder.
+ * This simply means that the PTP_OPC_ObjectFileName property
+ * is updated, if this is supported by the device.
+ *
+ * @param device a pointer to the device that contains the file.
+ * @param folder the folder metadata of the folder to rename.
+ *        On success, the name member is updated. Be aware, that
+ *        this name can be different than newname depending of device restrictions.
+ * @param newname the new name for this object.
+ * @return 0 on success, any other value means failure.
+ */
+int LIBMTP_Set_Folder_Name(LIBMTP_mtpdevice_t *device,
+                   LIBMTP_folder_t *folder, const char* newname)
+{
+  int ret;
+
+  ret = set_object_filename(device, folder->folder_id,
+			    PTP_OFC_Association,
+			    &newname);
+
+  if (ret != 0) {
+    return ret;
+    }
+
+  free(folder->name);
+  folder->name = strdup(newname);
+  return ret;
+}
+
+/**
+ * This function renames a single track.
+ * This simply means that the PTP_OPC_ObjectFileName property
+ * is updated, if this is supported by the device.
+ *
+ * @param device a pointer to the device that contains the file.
+ * @param track the track metadata of the track to rename.
+ *        On success, the filename member is updated. Be aware, that
+ *        this name can be different than newname depending of device restrictions.
+ * @param newname the new filename for this object.
+ * @return 0 on success, any other value means failure.
+ */
+int LIBMTP_Set_Track_Name(LIBMTP_mtpdevice_t *device,
+                   LIBMTP_track_t *track, const char* newname)
+{
+  int         ret;
+
+  ret = set_object_filename(device, track->item_id,
+			    map_libmtp_type_to_ptp_type(track->filetype),
+			    &newname);
+
+  if (ret != 0) {
+    return ret;
+  }
+
+  free(track->filename);
+  track->filename = strdup(newname);
+  return ret;
+}
+
+/**
+ * This function renames a single playlist object file holder.
+ * This simply means that the <code>PTP_OPC_ObjectFileName</code>
+ * property is updated, if this is supported by the device.
+ * The playlist filename should nominally end with an extension
+ * like ".pla".
+ *
+ * NOTE: if you want to change the metadata the device display
+ * about a playlist you must <i>not</i> use this function,
+ * use <code>LIBMTP_Update_Playlist()</code> instead!
+ *
+ * @param device a pointer to the device that contains the file.
+ * @param playlist the playlist metadata of the playlist to rename.
+ *        On success, the name member is updated. Be aware, that
+ *        this name can be different than newname depending of device restrictions.
+ * @param newname the new name for this object.
+ * @return 0 on success, any other value means failure.
+ * @see LIBMTP_Update_Playlist()
+ */
+int LIBMTP_Set_Playlist_Name(LIBMTP_mtpdevice_t *device,
+                   LIBMTP_playlist_t *playlist, const char* newname)
+{
+  int ret;
+
+  ret = set_object_filename(device, playlist->playlist_id,
+			    PTP_OFC_MTP_AbstractAudioVideoPlaylist,
+			    &newname);
+
+  if (ret != 0) {
+    return ret;
+  }
+
+  free(playlist->name);
+  playlist->name = strdup(newname);
+  return ret;
+}
+
+/**
+ * This function renames a single album.
+ * This simply means that the <code>PTP_OPC_ObjectFileName</code>
+ * property is updated, if this is supported by the device.
+ * The album filename should nominally end with an extension
+ * like ".alb".
+ *
+ * NOTE: if you want to change the metadata the device display
+ * about a playlist you must <i>not</i> use this function,
+ * use <code>LIBMTP_Update_Album()</code> instead!
+ *
+ * @param device a pointer to the device that contains the file.
+ * @param album the album metadata of the album to rename.
+ *        On success, the name member is updated. Be aware, that
+ *        this name can be different than newname depending of device restrictions.
+ * @param newname the new name for this object.
+ * @return 0 on success, any other value means failure.
+ * @see LIBMTP_Update_Album()
+ */
+int LIBMTP_Set_Album_Name(LIBMTP_mtpdevice_t *device,
+                   LIBMTP_album_t *album, const char* newname)
+{
+  int ret;
+
+  ret = set_object_filename(device, album->album_id,
+			    PTP_OFC_MTP_AbstractAudioAlbum,
+			    &newname);
+
+  if (ret != 0) {
+    return ret;
+  }
+
+  free(album->name);
+  album->name = strdup(newname);
+  return ret;
+}
+
+/**
+ * THIS FUNCTION IS DEPRECATED. PLEASE UPDATE YOUR CODE IN ORDER
+ * NOT TO USE IT.
+ *
+ * @see LIBMTP_Set_File_Name()
+ * @see LIBMTP_Set_Track_Name()
+ * @see LIBMTP_Set_Folder_Name()
+ * @see LIBMTP_Set_Playlist_Name()
+ * @see LIBMTP_Set_Album_Name()
+ */
+int LIBMTP_Set_Object_Filename(LIBMTP_mtpdevice_t *device,
+                   uint32_t object_id, char* newname)
+{
+  int             ret;
+  LIBMTP_file_t   *file;
+
+  file = LIBMTP_Get_Filemetadata(device, object_id);
+
+  if (file == NULL) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Set_Object_Filename(): "
+			    "could not get file metadata for target object.");
+    return -1;
+  }
+
+  ret = set_object_filename(device, object_id, map_libmtp_type_to_ptp_type(file->filetype), (const char **) &newname);
+
+  free(file);
+
+  return ret;
+}
+
+/**
+ * Helper function. This indicates if a track exists on the device
+ * @param device a pointer to the device to get the track from.
+ * @param id the track ID of the track to retrieve.
+ * @return TRUE (!=0) if the track exists, FALSE (0) if not
+ */
+int LIBMTP_Track_Exists(LIBMTP_mtpdevice_t *device,
+           uint32_t const id)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+  PTPObject *ob;
+
+  ret = ptp_object_want (params, id, 0, &ob);
+  if (ret == PTP_RC_OK)
+      return -1;
+  return 0;
+}
+
+/**
+ * This creates a new folder structure and allocates memory
+ * for it. Notice that if you add strings to this structure they
+ * will be freed by the corresponding <code>LIBMTP_folder_track_t</code>
+ * operation later, so be careful of using strdup() when assigning
+ * strings, e.g.:
+ *
+ * @return a pointer to the newly allocated folder structure.
+ * @see LIBMTP_destroy_folder_t()
+ */
+LIBMTP_folder_t *LIBMTP_new_folder_t(void)
+{
+  LIBMTP_folder_t *new = (LIBMTP_folder_t *) malloc(sizeof(LIBMTP_folder_t));
+  if (new == NULL) {
+    return NULL;
+  }
+  new->folder_id = 0;
+  new->parent_id = 0;
+  new->storage_id = 0;
+  new->name = NULL;
+  new->sibling = NULL;
+  new->child = NULL;
+  return new;
+}
+
+/**
+ * This recursively deletes the memory for a folder structure.
+ * This shall typically be called on a top-level folder list to
+ * detsroy the entire folder tree.
+ *
+ * @param folder folder structure to destroy
+ * @see LIBMTP_new_folder_t()
+ */
+void LIBMTP_destroy_folder_t(LIBMTP_folder_t *folder)
+{
+
+  if(folder == NULL) {
+     return;
+  }
+
+  //Destroy from the bottom up
+  if(folder->child != NULL) {
+     LIBMTP_destroy_folder_t(folder->child);
+  }
+
+  if(folder->sibling != NULL) {
+    LIBMTP_destroy_folder_t(folder->sibling);
+  }
+
+  if(folder->name != NULL) {
+    free(folder->name);
+  }
+
+  free(folder);
+}
+
+/**
+ * Helper function. Returns a folder structure for a
+ * specified id.
+ *
+ * @param folderlist list of folders to search
+ * @id id of folder to look for
+ * @return a folder or NULL if not found
+ */
+LIBMTP_folder_t *LIBMTP_Find_Folder(LIBMTP_folder_t *folderlist, uint32_t id)
+{
+  LIBMTP_folder_t *ret = NULL;
+
+  if(folderlist == NULL) {
+    return NULL;
+  }
+
+  if(folderlist->folder_id == id) {
+    return folderlist;
+  }
+
+  if(folderlist->sibling) {
+    ret = LIBMTP_Find_Folder(folderlist->sibling, id);
+  }
+
+  if(folderlist->child && ret == NULL) {
+    ret = LIBMTP_Find_Folder(folderlist->child, id);
+  }
+
+  return ret;
+}
+
+/**
+ * Function used to recursively get subfolders from params.
+ */
+static LIBMTP_folder_t *get_subfolders_for_folder(LIBMTP_folder_t *list, uint32_t parent)
+{
+  LIBMTP_folder_t *retfolders = NULL, *children, *iter, *curr;
+
+  iter = list->sibling;
+  while(iter != list) {
+    if (iter->parent_id != parent) {
+      iter = iter->sibling;
+      continue;
+    }
+
+    /* We know that iter is a child of 'parent', therefore we can safely
+     * hold on to 'iter' locally since no one else will steal it
+     * from the 'list' as we recurse. */
+    children = get_subfolders_for_folder(list, iter->folder_id);
+
+    curr = iter;
+    iter = iter->sibling;
+
+    // Remove curr from the list.
+    curr->child->sibling = curr->sibling;
+    curr->sibling->child = curr->child;
+
+    // Attach the children to curr.
+    curr->child = children;
+
+    // Put this folder into the list of siblings.
+    curr->sibling = retfolders;
+    retfolders = curr;
+  }
+
+  return retfolders;
+}
+
+/**
+ * This returns a list of all folders available
+ * on the current MTP device.
+ *
+ * @param device a pointer to the device to get the folder listing for.
+ * @return a list of folders
+ */
+LIBMTP_folder_t *LIBMTP_Get_Folder_List(LIBMTP_mtpdevice_t *device)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  LIBMTP_folder_t head, *rv;
+  int i;
+
+  // Get all the handles if we haven't already done that
+  if (params->nrofobjects == 0) {
+    flush_handles(device);
+  }
+
+  /*
+   * This creates a temporary list of the folders, this is in a
+   * reverse order and uses the Folder pointers that are already
+   * in the Folder structure. From this we can then build up the
+   * folder hierarchy with only looking at this temporary list,
+   * and removing the folders from this temporary list as we go.
+   * This significantly reduces the number of operations that we
+   * have to do in building the folder hierarchy. Also since the
+   * temp list is in reverse order, when we prepend to the sibling
+   * list things are in the same order as they were originally
+   * in the handle list.
+   */
+  head.sibling = &head;
+  head.child = &head;
+  for (i = 0; i < params->nrofobjects; i++) {
+    LIBMTP_folder_t *folder;
+    PTPObject *ob;
+
+    ob = &params->objects[i];
+    if (ob->oi.ObjectFormat != PTP_OFC_Association) {
+      continue;
+    }
+    /*
+     * Do we know how to handle these? They are part
+     * of the MTP 1.0 specification paragraph 3.6.4.
+     * For AssociationDesc 0x00000001U ptp_mtp_getobjectreferences()
+     * should be called on these to get the contained objects, but
+     * we basically don't care. Hopefully parent_id is maintained for all
+     * children, because we rely on that instead.
+     */
+    if (ob->oi.AssociationDesc != 0x00000000U) {
+      printf("MTP extended association type 0x%08x encountered\n", ob->oi.AssociationDesc);
+    }
+
+    // Create a folder struct...
+    folder = LIBMTP_new_folder_t();
+    if (folder == NULL) {
+      // malloc failure or so.
+      return NULL;
+    }
+    folder->folder_id = ob->oid;
+    folder->parent_id = ob->oi.ParentObject;
+    folder->storage_id = ob->oi.StorageID;
+    folder->name = (ob->oi.Filename) ? (char *)strdup(ob->oi.Filename) : NULL;
+
+    // pretend sibling says next, and child says prev.
+    folder->sibling = head.sibling;
+    folder->child = &head;
+    head.sibling->child = folder;
+    head.sibling = folder;
+  }
+
+  // We begin at the root folder and get them all recursively
+  rv = get_subfolders_for_folder(&head, 0x00000000);
+
+  // The temp list should be empty. Clean up any orphans just in case.
+  while(head.sibling != &head) {
+    LIBMTP_folder_t *curr = head.sibling;
+
+    printf("Orphan folder with ID: 0x%08x name: \"%s\" encountered.\n",
+	   curr->folder_id,
+	   curr->name);
+    curr->sibling->child = curr->child;
+    curr->child->sibling = curr->sibling;
+    curr->child = NULL;
+    curr->sibling = NULL;
+    LIBMTP_destroy_folder_t(curr);
+  }
+
+  return rv;
+}
+
+/**
+ * This create a folder on the current MTP device. The PTP name
+ * for a folder is "association". The PTP/MTP devices does not
+ * have an internal "folder" concept really, it contains a flat
+ * list of all files and some file are "associations" that other
+ * files and folders may refer to as its "parent".
+ *
+ * @param device a pointer to the device to create the folder on.
+ * @param name the name of the new folder. Note this can be modified
+ *        if the device does not support all the characters in the
+ *        name.
+ * @param parent_id id of parent folder to add the new folder to,
+ *        or 0 to put it in the root directory.
+ * @param storage_id id of the storage to add this new folder to.
+ *        notice that you cannot mismatch storage id and parent id:
+ *        they must both be on the same storage! Pass in 0 if you
+ *        want to create this folder on the default storage.
+ * @return id to new folder or 0 if an error occured
+ */
+uint32_t LIBMTP_Create_Folder(LIBMTP_mtpdevice_t *device, char *name,
+			      uint32_t parent_id, uint32_t storage_id)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  uint32_t parenthandle = 0;
+  uint32_t store;
+  PTPObjectInfo new_folder;
+  uint16_t ret;
+  uint32_t new_id = 0;
+
+  if (storage_id == 0) {
+    // I'm just guessing that a folder may require 512 bytes
+    store = get_writeable_storageid(device, 512);
+  } else {
+    store = storage_id;
+  }
+  parenthandle = parent_id;
+
+  memset(&new_folder, 0, sizeof(new_folder));
+  new_folder.Filename = name;
+  if (FLAG_ONLY_7BIT_FILENAMES(ptp_usb)) {
+    strip_7bit_from_utf8(new_folder.Filename);
+  }
+  new_folder.ObjectCompressedSize = 1;
+  new_folder.ObjectFormat = PTP_OFC_Association;
+  new_folder.ProtectionStatus = PTP_PS_NoProtection;
+  new_folder.AssociationType = PTP_AT_GenericFolder;
+  new_folder.ParentObject = parent_id;
+  new_folder.StorageID = store;
+
+  // Create the object
+  // FIXME: use send list here if available.
+  ret = ptp_sendobjectinfo(params, &store, &parenthandle, &new_id, &new_folder);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Create_Folder: Could not send object info.");
+    if (ret == PTP_RC_AccessDenied) {
+      add_ptp_error_to_errorstack(device, ret, "ACCESS DENIED.");
+    }
+    return 0;
+  }
+  // NOTE: don't destroy the new_folder objectinfo, because it is statically referencing
+  // several strings.
+
+  add_object_to_cache(device, new_id);
+
+  return new_id;
+}
+
+/**
+ * This creates a new playlist metadata structure and allocates memory
+ * for it. Notice that if you add strings to this structure they
+ * will be freed by the corresponding <code>LIBMTP_destroy_playlist_t</code>
+ * operation later, so be careful of using strdup() when assigning
+ * strings, e.g.:
+ *
+ * <pre>
+ * LIBMTP_playlist_t *pl = LIBMTP_new_playlist_t();
+ * pl->name = strdup(str);
+ * ....
+ * LIBMTP_destroy_playlist_t(pl);
+ * </pre>
+ *
+ * @return a pointer to the newly allocated metadata structure.
+ * @see LIBMTP_destroy_playlist_t()
+ */
+LIBMTP_playlist_t *LIBMTP_new_playlist_t(void)
+{
+  LIBMTP_playlist_t *new = (LIBMTP_playlist_t *) malloc(sizeof(LIBMTP_playlist_t));
+  if (new == NULL) {
+    return NULL;
+  }
+  new->playlist_id = 0;
+  new->parent_id = 0;
+  new->storage_id = 0;
+  new->name = NULL;
+  new->tracks = NULL;
+  new->no_tracks = 0;
+  new->next = NULL;
+  return new;
+}
+
+/**
+ * This destroys a playlist metadata structure and deallocates the memory
+ * used by it, including any strings. Never use a track metadata
+ * structure again after calling this function on it.
+ * @param playlist the playlist metadata to destroy.
+ * @see LIBMTP_new_playlist_t()
+ */
+void LIBMTP_destroy_playlist_t(LIBMTP_playlist_t *playlist)
+{
+  if (playlist == NULL) {
+    return;
+  }
+  if (playlist->name != NULL)
+    free(playlist->name);
+  if (playlist->tracks != NULL)
+    free(playlist->tracks);
+  free(playlist);
+  return;
+}
+
+/**
+ * This function returns a list of the playlists available on the
+ * device. Typical usage:
+ *
+ * <pre>
+ * </pre>
+ *
+ * @param device a pointer to the device to get the playlist listing from.
+ * @return a playlist list on success, else NULL. If there are no playlists
+ *         on the device, NULL will be returned as well.
+ * @see LIBMTP_Get_Playlist()
+ */
+LIBMTP_playlist_t *LIBMTP_Get_Playlist_List(LIBMTP_mtpdevice_t *device)
+{
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  const int REQ_SPL = FLAG_PLAYLIST_SPL(ptp_usb);
+  PTPParams *params = (PTPParams *) device->params;
+  LIBMTP_playlist_t *retlists = NULL;
+  LIBMTP_playlist_t *curlist = NULL;
+  uint32_t i;
+
+  // Get all the handles if we haven't already done that
+  if (params->nrofobjects == 0) {
+    flush_handles(device);
+  }
+
+  for (i = 0; i < params->nrofobjects; i++) {
+    LIBMTP_playlist_t *pl;
+    PTPObject *ob;
+    uint16_t ret;
+
+    ob = &params->objects[i];
+
+    // Ignore stuff that isn't playlists
+
+    // For Samsung players we must look for the .spl extension explicitly since
+    // playlists are not stored as playlist objects.
+    if ( REQ_SPL && is_spl_playlist(&ob->oi) ) {
+      // Allocate a new playlist type
+      pl = LIBMTP_new_playlist_t();
+      spl_to_playlist_t(device, &ob->oi, ob->oid, pl);
+    }
+    else if ( ob->oi.ObjectFormat != PTP_OFC_MTP_AbstractAudioVideoPlaylist ) {
+      continue;
+    }
+    else {
+      // Allocate a new playlist type
+      pl = LIBMTP_new_playlist_t();
+
+      // Try to look up proper name, else use the oi->Filename field.
+      pl->name = get_string_from_object(device, ob->oid, PTP_OPC_Name);
+      if (pl->name == NULL) {
+	pl->name = strdup(ob->oi.Filename);
+      }
+      pl->playlist_id = ob->oid;
+      pl->parent_id = ob->oi.ParentObject;
+      pl->storage_id = ob->oi.StorageID;
+
+      // Then get the track listing for this playlist
+      ret = ptp_mtp_getobjectreferences(params, pl->playlist_id, &pl->tracks, &pl->no_tracks);
+      if (ret != PTP_RC_OK) {
+        add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Playlist_List(): "
+				    "could not get object references.");
+        pl->tracks = NULL;
+        pl->no_tracks = 0;
+      }
+    }
+
+    // Add playlist to a list that will be returned afterwards.
+    if (retlists == NULL) {
+      retlists = pl;
+      curlist = pl;
+    } else {
+      curlist->next = pl;
+      curlist = pl;
+    }
+
+    // Call callback here if we decide to add that possibility...
+  }
+  return retlists;
+}
+
+
+/**
+ * This function retrieves an individual playlist from the device.
+ * @param device a pointer to the device to get the playlist from.
+ * @param plid the unique ID of the playlist to retrieve.
+ * @return a valid playlist metadata post or NULL on failure.
+ * @see LIBMTP_Get_Playlist_List()
+ */
+LIBMTP_playlist_t *LIBMTP_Get_Playlist(LIBMTP_mtpdevice_t *device, uint32_t const plid)
+{
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  const int REQ_SPL = FLAG_PLAYLIST_SPL(ptp_usb);
+  PTPParams *params = (PTPParams *) device->params;
+  PTPObject *ob;
+  LIBMTP_playlist_t *pl;
+  uint16_t ret;
+
+  // Get all the handles if we haven't already done that
+  if (params->nrofobjects == 0) {
+    flush_handles(device);
+  }
+
+  ret = ptp_object_want (params, plid, PTPOBJECT_OBJECTINFO_LOADED, &ob);
+  if (ret != PTP_RC_OK)
+    return NULL;
+
+  // For Samsung players we must look for the .spl extension explicitly since
+  // playlists are not stored as playlist objects.
+  if ( REQ_SPL && is_spl_playlist(&ob->oi) ) {
+    // Allocate a new playlist type
+    pl = LIBMTP_new_playlist_t();
+    spl_to_playlist_t(device, &ob->oi, ob->oid, pl);
+    return pl;
+  }
+
+  // Ignore stuff that isn't playlists
+  else if ( ob->oi.ObjectFormat != PTP_OFC_MTP_AbstractAudioVideoPlaylist ) {
+    return NULL;
+  }
+
+  // Allocate a new playlist type
+  pl = LIBMTP_new_playlist_t();
+
+  pl->name = get_string_from_object(device, ob->oid, PTP_OPC_Name);
+  if (pl->name == NULL) {
+    pl->name = strdup(ob->oi.Filename);
+  }
+  pl->playlist_id = ob->oid;
+  pl->parent_id = ob->oi.ParentObject;
+  pl->storage_id = ob->oi.StorageID;
+
+  // Then get the track listing for this playlist
+  ret = ptp_mtp_getobjectreferences(params, pl->playlist_id, &pl->tracks, &pl->no_tracks);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Playlist(): Could not get object references.");
+    pl->tracks = NULL;
+    pl->no_tracks = 0;
+  }
+
+  return pl;
+}
+
+/**
+ * This function creates a new abstract list such as a playlist
+ * or an album.
+ *
+ * @param device a pointer to the device to create the new abstract list
+ *        on.
+ * @param name the name of the new abstract list.
+ * @param artist the artist of the new abstract list or NULL.
+ * @param genre the genre of the new abstract list or NULL.
+ * @param parenthandle the handle of the parent or 0 for no parent
+ *        i.e. the root folder.
+ * @param objectformat the abstract list type to create.
+ * @param suffix the ".foo" (4 characters) suffix to use for the virtual
+ *        "file" created by this operation.
+ * @param newid a pointer to a variable that will hold the new object
+ *        ID if this call is successful.
+ * @param tracks an array of tracks to associate with this list.
+ * @param no_tracks the number of tracks in the list.
+ * @return 0 on success, any other value means failure.
+ */
+static int create_new_abstract_list(LIBMTP_mtpdevice_t *device,
+				    char const * const name,
+				    char const * const artist,
+				    char const * const composer,
+				    char const * const genre,
+				    uint32_t const parenthandle,
+				    uint32_t const storageid,
+				    uint16_t const objectformat,
+				    char const * const suffix,
+				    uint32_t * const newid,
+				    uint32_t const * const tracks,
+				    uint32_t const no_tracks)
+
+{
+  int i;
+  int supported = 0;
+  uint16_t ret;
+  uint16_t *properties = NULL;
+  uint32_t propcnt = 0;
+  uint32_t store;
+  uint32_t localph = parenthandle;
+  uint8_t nonconsumable = 0x00U; /* By default it is consumable */
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  char fname[256];
+  uint8_t data[2];
+
+  if (storageid == 0) {
+    // I'm just guessing that an abstract list may require 512 bytes
+    store = get_writeable_storageid(device, 512);
+  } else {
+    store = storageid;
+  }
+
+  // Check if we can create an object of this type
+  for ( i=0; i < params->deviceinfo.ImageFormats_len; i++ ) {
+    if (params->deviceinfo.ImageFormats[i] == objectformat) {
+      supported = 1;
+      break;
+    }
+  }
+  if (!supported) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "create_new_abstract_list(): player does not support this abstract type.");
+    printf("Unsupported abstract list type: %04x\n", objectformat);
+    return -1;
+  }
+
+  // add the new suffix if it isn't there
+  fname[0] = '\0';
+  if (strlen(name) > strlen(suffix)) {
+    char const * const suff = &name[strlen(name)-strlen(suffix)];
+    if (!strcmp(suff, suffix)) {
+      // Home free.
+      strncpy(fname, name, sizeof(fname));
+    }
+  }
+  // If it didn't end with "<suffix>" then add that here.
+  if (fname[0] == '\0') {
+    strncpy(fname, name, sizeof(fname)-strlen(suffix)-1);
+    strcat(fname, suffix);
+    fname[sizeof(fname)-1] = '\0';
+  }
+
+  if (ptp_operation_issupported(params, PTP_OC_MTP_SendObjectPropList) &&
+      !FLAG_BROKEN_SEND_OBJECT_PROPLIST(ptp_usb)) {
+    MTPProperties *props = NULL;
+    MTPProperties *prop = NULL;
+    int nrofprops = 0;
+
+    *newid = 0x00000000U;
+
+    ret = ptp_mtp_getobjectpropssupported(params, objectformat, &propcnt, &properties);
+
+    for (i=0;i<propcnt;i++) {
+      PTPObjectPropDesc opd;
+
+      ret = ptp_mtp_getobjectpropdesc(params, properties[i], objectformat, &opd);
+      if (ret != PTP_RC_OK) {
+	add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "create_new_abstract_list(): "
+				"could not get property description.");
+      } else if (opd.GetSet) {
+	switch (properties[i]) {
+	case PTP_OPC_ObjectFileName:
+	  prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	  prop->ObjectHandle = *newid;
+	  prop->property = PTP_OPC_ObjectFileName;
+	  prop->datatype = PTP_DTC_STR;
+	  prop->propval.str = strdup(fname);
+	  if (FLAG_ONLY_7BIT_FILENAMES(ptp_usb)) {
+	    strip_7bit_from_utf8(prop->propval.str);
+	  }
+	  break;
+	case PTP_OPC_ProtectionStatus:
+	  prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	  prop->ObjectHandle = *newid;
+	  prop->property = PTP_OPC_ProtectionStatus;
+	  prop->datatype = PTP_DTC_UINT16;
+	  prop->propval.u16 = 0x0000U; /* Not protected */
+	  break;
+	case PTP_OPC_NonConsumable:
+	  prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	  prop->ObjectHandle = *newid;
+	  prop->property = PTP_OPC_NonConsumable;
+	  prop->datatype = PTP_DTC_UINT8;
+	  prop->propval.u8 = nonconsumable;
+	  break;
+	case PTP_OPC_Name:
+	  if (name != NULL) {
+	    prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	    prop->ObjectHandle = *newid;
+	    prop->property = PTP_OPC_Name;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = strdup(name);
+	  }
+	  break;
+	case PTP_OPC_AlbumArtist:
+	  if (artist != NULL) {
+	    prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	    prop->ObjectHandle = *newid;
+	    prop->property = PTP_OPC_AlbumArtist;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = strdup(artist);
+	  }
+	  break;
+	case PTP_OPC_Artist:
+	  if (artist != NULL) {
+	    prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	    prop->ObjectHandle = *newid;
+	    prop->property = PTP_OPC_Artist;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = strdup(artist);
+	  }
+	  break;
+	case PTP_OPC_Composer:
+	  if (composer != NULL) {
+	    prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	    prop->ObjectHandle = *newid;
+	    prop->property = PTP_OPC_Composer;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = strdup(composer);
+	  }
+	  break;
+	case PTP_OPC_Genre:
+	  if (genre != NULL) {
+	    prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	    prop->ObjectHandle = *newid;
+	    prop->property = PTP_OPC_Genre;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = strdup(genre);
+	  }
+	  break;
+ 	case PTP_OPC_DateModified:
+	  // Tag with current time if that is supported
+	  if (!FLAG_CANNOT_HANDLE_DATEMODIFIED(ptp_usb)) {
+	    prop = ptp_get_new_object_prop_entry(&props,&nrofprops);
+	    prop->ObjectHandle = *newid;
+	    prop->property = PTP_OPC_DateModified;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = get_iso8601_stamp();
+	  }
+	  break;
+	}
+      }
+      ptp_free_objectpropdesc(&opd);
+    }
+    free(properties);
+
+    ret = ptp_mtp_sendobjectproplist(params, &store, &localph, newid,
+				     objectformat, 0, props, nrofprops);
+
+    /* Free property list */
+    ptp_destroy_object_prop_list(props, nrofprops);
+
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "create_new_abstract_list(): Could not send object property list.");
+      if (ret == PTP_RC_AccessDenied) {
+	add_ptp_error_to_errorstack(device, ret, "ACCESS DENIED.");
+      }
+      return -1;
+    }
+
+    // now send the blank object
+    ret = ptp_sendobject(params, NULL, 0);
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "create_new_abstract_list(): Could not send blank object data.");
+      return -1;
+    }
+
+  } else if (ptp_operation_issupported(params,PTP_OC_SendObjectInfo)) {
+    PTPObjectInfo new_object;
+
+    new_object.Filename = fname;
+    if (FLAG_ONLY_7BIT_FILENAMES(ptp_usb)) {
+      strip_7bit_from_utf8(new_object.Filename);
+    }
+    new_object.ObjectCompressedSize = 1;
+    new_object.ObjectFormat = objectformat;
+
+    // Create the object
+    ret = ptp_sendobjectinfo(params, &store, &localph, newid, &new_object);
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "create_new_abstract_list(): Could not send object info (the playlist itself).");
+      if (ret == PTP_RC_AccessDenied) {
+	add_ptp_error_to_errorstack(device, ret, "ACCESS DENIED.");
+      }
+      return -1;
+    }
+    // NOTE: don't destroy new_object objectinfo afterwards - the strings it contains are
+    // not copies.
+    /*
+     * We have to send this one blank data byte.
+     * If we don't, the handle will not be created and thus there is no playlist.
+     */
+    data[0] = '\0';
+    data[1] = '\0';
+    ret = ptp_sendobject(params, data, 1);
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "create_new_abstract_list(): Could not send blank object data.");
+      return -1;
+    }
+
+    // set the properties one by one
+    ret = ptp_mtp_getobjectpropssupported(params, objectformat, &propcnt, &properties);
+
+    for (i=0;i<propcnt;i++) {
+      PTPObjectPropDesc opd;
+
+      ret = ptp_mtp_getobjectpropdesc(params, properties[i], objectformat, &opd);
+      if (ret != PTP_RC_OK) {
+	add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "create_new_abstract_list(): "
+				"could not get property description.");
+      } else if (opd.GetSet) {
+	switch (properties[i]) {
+	case PTP_OPC_Name:
+	  if (name != NULL) {
+	    ret = set_object_string(device, *newid, PTP_OPC_Name, name);
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "create_new_abstract_list(): could not set entity name.");
+	      return -1;
+	    }
+	  }
+	  break;
+	case PTP_OPC_AlbumArtist:
+	  if (artist != NULL) {
+	    ret = set_object_string(device, *newid, PTP_OPC_AlbumArtist, artist);
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "create_new_abstract_list(): could not set entity album artist.");
+	      return -1;
+	    }
+	  }
+	  break;
+	case PTP_OPC_Artist:
+	  if (artist != NULL) {
+	    ret = set_object_string(device, *newid, PTP_OPC_Artist, artist);
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "create_new_abstract_list(): could not set entity artist.");
+	      return -1;
+	    }
+	  }
+	  break;
+	case PTP_OPC_Composer:
+	  if (composer != NULL) {
+	    ret = set_object_string(device, *newid, PTP_OPC_Composer, composer);
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "create_new_abstract_list(): could not set entity composer.");
+	      return -1;
+	    }
+	  }
+	  break;
+	case PTP_OPC_Genre:
+	  if (genre != NULL) {
+	    ret = set_object_string(device, *newid, PTP_OPC_Genre, genre);
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "create_new_abstract_list(): could not set entity genre.");
+	      return -1;
+	    }
+	  }
+	  break;
+ 	case PTP_OPC_DateModified:
+	  if (!FLAG_CANNOT_HANDLE_DATEMODIFIED(ptp_usb)) {
+	    ret = set_object_string(device, *newid, PTP_OPC_DateModified, get_iso8601_stamp());
+	    if (ret != 0) {
+	      add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "create_new_abstract_list(): could not set date modified.");
+	      return -1;
+	    }
+	  }
+	  break;
+	}
+      }
+      ptp_free_objectpropdesc(&opd);
+    }
+    free(properties);
+  }
+
+  if (no_tracks > 0) {
+    // Add tracks to the list as object references.
+    ret = ptp_mtp_setobjectreferences (params, *newid, (uint32_t *) tracks, no_tracks);
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "create_new_abstract_list(): could not add tracks as object references.");
+      return -1;
+    }
+  }
+
+  add_object_to_cache(device, *newid);
+
+  return 0;
+}
+
+/**
+ * This updates the metadata and track listing
+ * for an abstract list.
+ * @param device a pointer to the device that the abstract list
+ *        resides on.
+ * @param name the name of the abstract list.
+ * @param artist the artist of the abstract list or NULL.
+ * @param genre the genre of the abstract list or NULL.
+ * @param objecthandle the object to be updated.
+ * @param objectformat the abstract list type to update.
+ * @param tracks an array of tracks to associate with this list.
+ * @param no_tracks the number of tracks in the list.
+ * @return 0 on success, any other value means failure.
+ */
+static int update_abstract_list(LIBMTP_mtpdevice_t *device,
+				char const * const name,
+				char const * const artist,
+				char const * const composer,
+				char const * const genre,
+				uint32_t const objecthandle,
+				uint16_t const objectformat,
+				uint32_t const * const tracks,
+				uint32_t const no_tracks)
+{
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  uint16_t *properties = NULL;
+  uint32_t propcnt = 0;
+  int i;
+
+  // First see which properties can be set
+  // i.e only try to update this metadata for object tags that exist on the current player.
+  ret = ptp_mtp_getobjectpropssupported(params, objectformat, &propcnt, &properties);
+  if (ret != PTP_RC_OK) {
+    // Just bail out for now, nothing is ever set.
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "update_abstract_list(): "
+			    "could not retrieve supported object properties.");
+    return -1;
+  }
+  if (ptp_operation_issupported(params,PTP_OC_MTP_SetObjPropList) &&
+      !FLAG_BROKEN_SET_OBJECT_PROPLIST(ptp_usb)) {
+    MTPProperties *props = NULL;
+    MTPProperties *prop = NULL;
+    int nrofprops = 0;
+
+    for (i=0;i<propcnt;i++) {
+      PTPObjectPropDesc opd;
+
+      ret = ptp_mtp_getobjectpropdesc(params, properties[i], objectformat, &opd);
+      if (ret != PTP_RC_OK) {
+	add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "update_abstract_list(): "
+				"could not get property description.");
+      } else if (opd.GetSet) {
+	switch (properties[i]) {
+	case PTP_OPC_Name:
+	  prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	  prop->ObjectHandle = objecthandle;
+	  prop->property = PTP_OPC_Name;
+	  prop->datatype = PTP_DTC_STR;
+	  if (name != NULL)
+	    prop->propval.str = strdup(name);
+	  break;
+	case PTP_OPC_AlbumArtist:
+	  if (artist != NULL) {
+	    prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	    prop->ObjectHandle = objecthandle;
+	    prop->property = PTP_OPC_AlbumArtist;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = strdup(artist);
+	  }
+	  break;
+	case PTP_OPC_Artist:
+	  if (artist != NULL) {
+	    prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	    prop->ObjectHandle = objecthandle;
+	    prop->property = PTP_OPC_Artist;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = strdup(artist);
+	  }
+	  break;
+	case PTP_OPC_Composer:
+	  if (composer != NULL) {
+	    prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	    prop->ObjectHandle = objecthandle;
+	    prop->property = PTP_OPC_Composer;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = strdup(composer);
+	  }
+	  break;
+	case PTP_OPC_Genre:
+	  if (genre != NULL) {
+	    prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	    prop->ObjectHandle = objecthandle;
+	    prop->property = PTP_OPC_Genre;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = strdup(genre);
+	  }
+	  break;
+ 	case PTP_OPC_DateModified:
+	  if (!FLAG_CANNOT_HANDLE_DATEMODIFIED(ptp_usb)) {
+	    // Tag with current time if that is supported
+	    prop = ptp_get_new_object_prop_entry(&props, &nrofprops);
+	    prop->ObjectHandle = objecthandle;
+	    prop->property = PTP_OPC_DateModified;
+	    prop->datatype = PTP_DTC_STR;
+	    prop->propval.str = get_iso8601_stamp();
+	  }
+	  break;
+	default:
+	  break;
+	}
+      }
+      ptp_free_objectpropdesc(&opd);
+    }
+
+    // proplist could be NULL if we can't write any properties
+    if (props != NULL) {
+      ret = ptp_mtp_setobjectproplist(params, props, nrofprops);
+
+      ptp_destroy_object_prop_list(props, nrofprops);
+
+      if (ret != PTP_RC_OK) {
+        // TODO: return error of which property we couldn't set
+        add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "update_abstract_list(): "
+                                "could not set object property list.");
+        free(properties);
+        return -1;
+      }
+    }
+
+  } else if (ptp_operation_issupported(params,PTP_OC_MTP_SetObjectPropValue)) {
+    for (i=0;i<propcnt;i++) {
+      switch (properties[i]) {
+      case PTP_OPC_Name:
+	// Update title
+	ret = set_object_string(device, objecthandle, PTP_OPC_Name, name);
+	if (ret != 0) {
+	  add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "update_abstract_list(): "
+				  "could not set title.");
+	}
+	break;
+      case PTP_OPC_AlbumArtist:
+	// Update album artist
+	ret = set_object_string(device, objecthandle, PTP_OPC_AlbumArtist, artist);
+	if (ret != 0) {
+	  add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "update_abstract_list(): "
+				  "could not set album artist name.");
+	}
+	break;
+      case PTP_OPC_Artist:
+	// Update artist
+	ret = set_object_string(device, objecthandle, PTP_OPC_Artist, artist);
+	if (ret != 0) {
+	  add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "update_abstract_list(): "
+				  "could not set artist name.");
+	}
+      case PTP_OPC_Composer:
+	// Update composer
+	ret = set_object_string(device, objecthandle, PTP_OPC_Composer, composer);
+	if (ret != 0) {
+	  add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "update_abstract_list(): "
+				  "could not set composer name.");
+	}
+	break;
+      case PTP_OPC_Genre:
+	// Update genre
+	ret = set_object_string(device, objecthandle, PTP_OPC_Genre, genre);
+	if (ret != 0) {
+	  add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "update_abstract_list(): "
+				  "could not set genre.");
+	}
+	break;
+      case PTP_OPC_DateModified:
+	// Update date modified
+	if (!FLAG_CANNOT_HANDLE_DATEMODIFIED(ptp_usb)) {
+	  char *tmpdate = get_iso8601_stamp();
+	  ret = set_object_string(device, objecthandle, PTP_OPC_DateModified, tmpdate);
+	  if (ret != 0) {
+	    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "update_abstract_list(): "
+				    "could not set modification date.");
+	  }
+	  free(tmpdate);
+	}
+      default:
+	break;
+      }
+    }
+  } else {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "update_abstract_list(): "
+                            "Your device doesn't seem to support any known way of setting metadata.");
+    free(properties);
+    return -1;
+  }
+
+  // Then the object references...
+  ret = ptp_mtp_setobjectreferences (params, objecthandle, (uint32_t *) tracks, no_tracks);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "update_abstract_list(): could not add tracks as object references.");
+    free(properties);
+    return -1;
+  }
+
+  free(properties);
+
+  update_metadata_cache(device, objecthandle);
+
+  return 0;
+}
+
+
+/**
+ * This routine creates a new playlist based on the metadata
+ * supplied. If the <code>tracks</code> field of the metadata
+ * contains a track listing, these tracks will be added to the
+ * playlist.
+ * @param device a pointer to the device to create the new playlist on.
+ * @param metadata the metadata for the new playlist. If the function
+ *        exits with success, the <code>playlist_id</code> field of this
+ *        struct will contain the new playlist ID of the playlist.
+ *        <ul>
+ *        <li><code>metadata-&gt;parent_id</code> should be set to the parent 
+ *        (e.g. folder) to store this track in. Since some 
+ *        devices are a bit picky about where files
+ *        are placed, a default folder will be chosen if libmtp
+ *        has detected one for the current filetype and this
+ *        parameter is set to 0. If this is 0 and no default folder
+ *        can be found, the file will be stored in the root folder.
+ *        <li><code>metadata-&gt;storage_id</code> should be set to the
+ *        desired storage (e.g. memory card or whatever your device
+ *        presents) to store this track in. Setting this to 0 will store
+ *        the track on the primary storage.
+ *        </ul>
+ * @return 0 on success, any other value means failure.
+ * @see LIBMTP_Update_Playlist()
+ * @see LIBMTP_Delete_Object()
+ */
+int LIBMTP_Create_New_Playlist(LIBMTP_mtpdevice_t *device,
+			       LIBMTP_playlist_t * const metadata)
+{
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  uint32_t localph = metadata->parent_id;
+
+  // Use a default folder if none given
+  if (localph == 0) {
+    if (device->default_playlist_folder != 0)
+      localph = device->default_playlist_folder;
+    else
+      localph = device->default_music_folder;
+  }
+  metadata->parent_id = localph;
+
+  // Samsung needs its own special type of playlists
+  if(FLAG_PLAYLIST_SPL(ptp_usb)) {
+    return playlist_t_to_spl(device, metadata);
+  }
+
+  // Just create a new abstract audio/video playlist...
+  return create_new_abstract_list(device,
+				  metadata->name,
+				  NULL,
+				  NULL,
+				  NULL,
+				  localph,
+				  metadata->storage_id,
+				  PTP_OFC_MTP_AbstractAudioVideoPlaylist,
+				  get_playlist_extension(ptp_usb),
+				  &metadata->playlist_id,
+				  metadata->tracks,
+				  metadata->no_tracks);
+}
+
+/**
+ * This routine updates a playlist based on the metadata
+ * supplied. If the <code>tracks</code> field of the metadata
+ * contains a track listing, these tracks will be added to the
+ * playlist in place of those already present, i.e. the
+ * previous track listing will be deleted. For Samsung devices the
+ * playlist id (metadata->playlist_id) is likely to change.
+ * @param device a pointer to the device to create the new playlist on.
+ * @param metadata the metadata for the playlist to be updated.
+ *                 notice that the field <code>playlist_id</code>
+ *                 must contain the apropriate playlist ID. Playlist ID
+ *                 be modified to a new playlist ID by the time the
+ *                 function returns since edit-in-place is not always possible.
+ * @return 0 on success, any other value means failure.
+ * @see LIBMTP_Create_New_Playlist()
+ * @see LIBMTP_Delete_Object()
+ */
+int LIBMTP_Update_Playlist(LIBMTP_mtpdevice_t *device,
+			   LIBMTP_playlist_t * const metadata)
+{
+
+  // Samsung needs its own special type of playlists
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  if(FLAG_PLAYLIST_SPL(ptp_usb)) {
+    return update_spl_playlist(device, metadata);
+  }
+
+  return update_abstract_list(device,
+			      metadata->name,
+			      NULL,
+			      NULL,
+			      NULL,
+			      metadata->playlist_id,
+			      PTP_OFC_MTP_AbstractAudioVideoPlaylist,
+			      metadata->tracks,
+			      metadata->no_tracks);
+}
+
+/**
+ * This creates a new album metadata structure and allocates memory
+ * for it. Notice that if you add strings to this structure they
+ * will be freed by the corresponding <code>LIBMTP_destroy_album_t</code>
+ * operation later, so be careful of using strdup() when assigning
+ * strings.
+ *
+ * @return a pointer to the newly allocated metadata structure.
+ * @see LIBMTP_destroy_album_t()
+ */
+LIBMTP_album_t *LIBMTP_new_album_t(void)
+{
+  LIBMTP_album_t *new = (LIBMTP_album_t *) malloc(sizeof(LIBMTP_album_t));
+  if (new == NULL) {
+    return NULL;
+  }
+  new->album_id = 0;
+  new->parent_id = 0;
+  new->storage_id = 0;
+  new->name = NULL;
+  new->artist = NULL;
+  new->composer = NULL;
+  new->genre = NULL;
+  new->tracks = NULL;
+  new->no_tracks = 0;
+  new->next = NULL;
+  return new;
+}
+
+/**
+ * This recursively deletes the memory for an album structure
+ *
+ * @param album structure to destroy
+ * @see LIBMTP_new_album_t()
+ */
+void LIBMTP_destroy_album_t(LIBMTP_album_t *album)
+{
+  if (album == NULL) {
+    return;
+  }
+  if (album->name != NULL)
+    free(album->name);
+  if (album->artist != NULL)
+    free(album->artist);
+  if (album->composer != NULL)
+    free(album->composer);
+  if (album->genre != NULL)
+    free(album->genre);
+  if (album->tracks != NULL)
+    free(album->tracks);
+  free(album);
+  return;
+}
+
+/**
+ * This function maps and copies a property onto the album metadata if applicable.
+ */
+static void pick_property_to_album_metadata(LIBMTP_mtpdevice_t *device,
+					    MTPProperties *prop, LIBMTP_album_t *alb)
+{
+  switch (prop->property) {
+  case PTP_OPC_Name:
+    if (prop->propval.str != NULL)
+      alb->name = strdup(prop->propval.str);
+    else
+      alb->name = NULL;
+    break;
+  case PTP_OPC_AlbumArtist:
+    if (prop->propval.str != NULL) {
+      // This should take precedence over plain "Artist"
+      if (alb->artist != NULL)
+	free(alb->artist);
+      alb->artist = strdup(prop->propval.str);
+    } else
+      alb->artist = NULL;
+    break;
+  case PTP_OPC_Artist:
+    if (prop->propval.str != NULL) {
+      // Only use of AlbumArtist is not set
+      if (alb->artist == NULL)
+	alb->artist = strdup(prop->propval.str);
+    } else
+      alb->artist = NULL;
+    break;
+  case PTP_OPC_Composer:
+    if (prop->propval.str != NULL)
+      alb->composer = strdup(prop->propval.str);
+    else
+      alb->composer = NULL;
+    break;
+  case PTP_OPC_Genre:
+    if (prop->propval.str != NULL)
+      alb->genre = strdup(prop->propval.str);
+    else
+      alb->genre = NULL;
+    break;
+  }
+}
+
+/**
+ * This function retrieves the album metadata for an album
+ * given by a unique ID.
+ * @param device a pointer to the device to get the track metadata off.
+ * @param alb an album metadata metadata set to fill in.
+ */
+static void get_album_metadata(LIBMTP_mtpdevice_t *device,
+			       LIBMTP_album_t *alb)
+{
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+  uint32_t i;
+  MTPProperties *prop;
+  PTPObject *ob;
+
+  /*
+   * If we have a cached, large set of metadata, then use it!
+   */
+  ret = ptp_object_want(params, alb->album_id, PTPOBJECT_MTPPROPLIST_LOADED, &ob);
+  if (ob->mtpprops) {
+    prop = ob->mtpprops;
+    for (i=0;i<ob->nrofmtpprops;i++,prop++)
+      pick_property_to_album_metadata(device, prop, alb);
+  } else {
+    uint16_t *props = NULL;
+    uint32_t propcnt = 0;
+
+    // First see which properties can be retrieved for albums
+    ret = ptp_mtp_getobjectpropssupported(params, PTP_OFC_MTP_AbstractAudioAlbum, &propcnt, &props);
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "get_album_metadata(): call to ptp_mtp_getobjectpropssupported() failed.");
+      // Just bail out for now, nothing is ever set.
+      return;
+    } else {
+      for (i=0;i<propcnt;i++) {
+	switch (props[i]) {
+	case PTP_OPC_Name:
+	  alb->name = get_string_from_object(device, ob->oid, PTP_OPC_Name);
+	  break;
+	case PTP_OPC_AlbumArtist:
+	  if (alb->artist != NULL)
+	    free(alb->artist);
+	  alb->artist = get_string_from_object(device, ob->oid, PTP_OPC_AlbumArtist);
+	  break;
+	case PTP_OPC_Artist:
+	  if (alb->artist == NULL)
+	    alb->artist = get_string_from_object(device, ob->oid, PTP_OPC_Artist);
+	  break;
+	case PTP_OPC_Composer:
+	  alb->composer = get_string_from_object(device, ob->oid, PTP_OPC_Composer);
+	  break;
+	case PTP_OPC_Genre:
+	  alb->genre = get_string_from_object(device, ob->oid, PTP_OPC_Genre);
+	  break;
+	default:
+	  break;
+	}
+      }
+      free(props);
+    }
+  }
+}
+
+/**
+ * This function returns a list of the albums available on the
+ * device.
+ *
+ * @param device a pointer to the device to get the album listing from.
+ * @return an album list on success, else NULL. If there are no albums
+ *         on the device, NULL will be returned as well.
+ * @see LIBMTP_Get_Album()
+ */
+LIBMTP_album_t *LIBMTP_Get_Album_List(LIBMTP_mtpdevice_t *device)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  LIBMTP_album_t *retalbums = NULL;
+  LIBMTP_album_t *curalbum = NULL;
+  uint32_t i;
+
+  // Get all the handles if we haven't already done that
+  if (params->nrofobjects == 0)
+    flush_handles(device);
+
+  for (i = 0; i < params->nrofobjects; i++) {
+    LIBMTP_album_t *alb;
+    PTPObject *ob;
+    uint16_t ret;
+
+    ob = &params->objects[i];
+
+    // Ignore stuff that isn't an album
+    if ( ob->oi.ObjectFormat != PTP_OFC_MTP_AbstractAudioAlbum )
+      continue;
+
+    // Allocate a new album type
+    alb = LIBMTP_new_album_t();
+    alb->album_id = ob->oid;
+    alb->parent_id = ob->oi.ParentObject;
+    alb->storage_id = ob->oi.StorageID;
+
+    // Fetch supported metadata
+    get_album_metadata(device, alb);
+
+    // Then get the track listing for this album
+    ret = ptp_mtp_getobjectreferences(params, alb->album_id, &alb->tracks, &alb->no_tracks);
+    if (ret != PTP_RC_OK) {
+      add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Album_List(): Could not get object references.");
+      alb->tracks = NULL;
+      alb->no_tracks = 0;
+    }
+
+    // Add album to a list that will be returned afterwards.
+    if (retalbums == NULL) {
+      retalbums = alb;
+      curalbum = alb;
+    } else {
+      curalbum->next = alb;
+      curalbum = alb;
+    }
+
+  }
+  return retalbums;
+}
+
+/**
+ * This function retrieves an individual album from the device.
+ * @param device a pointer to the device to get the album from.
+ * @param albid the unique ID of the album to retrieve.
+ * @return a valid album metadata or NULL on failure.
+ * @see LIBMTP_Get_Album_List()
+ */
+LIBMTP_album_t *LIBMTP_Get_Album(LIBMTP_mtpdevice_t *device, uint32_t const albid)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t ret;
+  PTPObject *ob;
+  LIBMTP_album_t *alb;
+
+  // Get all the handles if we haven't already done that
+  if (params->nrofobjects == 0)
+    flush_handles(device);
+
+  ret = ptp_object_want(params, albid, PTPOBJECT_OBJECTINFO_LOADED, &ob);
+  if (ret != PTP_RC_OK)
+    return NULL;
+
+  // Ignore stuff that isn't an album
+  if (ob->oi.ObjectFormat != PTP_OFC_MTP_AbstractAudioAlbum)
+    return NULL;
+
+  // Allocate a new album type
+  alb = LIBMTP_new_album_t();
+  alb->album_id = ob->oid;
+  alb->parent_id = ob->oi.ParentObject;
+  alb->storage_id = ob->oi.StorageID;
+
+  // Fetch supported metadata
+  get_album_metadata(device, alb);
+
+  // Then get the track listing for this album
+  ret = ptp_mtp_getobjectreferences(params, alb->album_id, &alb->tracks, &alb->no_tracks);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Album: Could not get object references.");
+    alb->tracks = NULL;
+    alb->no_tracks = 0;
+  }
+
+  return alb;
+}
+
+/**
+ * This routine creates a new album based on the metadata
+ * supplied. If the <code>tracks</code> field of the metadata
+ * contains a track listing, these tracks will be added to the
+ * album.
+ * @param device a pointer to the device to create the new album on.
+ * @param metadata the metadata for the new album. If the function
+ *        exits with success, the <code>album_id</code> field of this
+ *        struct will contain the new ID of the album.
+ *        <ul>
+ *        <li><code>metadata-&gt;parent_id</code> should be set to the parent
+ *        (e.g. folder) to store this track in. Since some
+ *        devices are a bit picky about where files
+ *        are placed, a default folder will be chosen if libmtp
+ *        has detected one for the current filetype and this
+ *        parameter is set to 0. If this is 0 and no default folder
+ *        can be found, the file will be stored in the root folder.
+ *        <li><code>metadata-&gt;storage_id</code> should be set to the
+ *        desired storage (e.g. memory card or whatever your device
+ *        presents) to store this track in. Setting this to 0 will store
+ *        the track on the primary storage.
+ *        </ul>
+ * @return 0 on success, any other value means failure.
+ * @see LIBMTP_Update_Album()
+ * @see LIBMTP_Delete_Object()
+ */
+int LIBMTP_Create_New_Album(LIBMTP_mtpdevice_t *device,
+			    LIBMTP_album_t * const metadata)
+{
+  uint32_t localph = metadata->parent_id;
+
+  // Use a default folder if none given
+  if (localph == 0) {
+    if (device->default_album_folder != 0)
+      localph = device->default_album_folder;
+    else
+      localph = device->default_music_folder;
+  }
+  metadata->parent_id = localph;
+
+  // Just create a new abstract album...
+  return create_new_abstract_list(device,
+				  metadata->name,
+				  metadata->artist,
+				  metadata->composer,
+				  metadata->genre,
+				  localph,
+				  metadata->storage_id,
+				  PTP_OFC_MTP_AbstractAudioAlbum,
+				  ".alb",
+				  &metadata->album_id,
+				  metadata->tracks,
+				  metadata->no_tracks);
+}
+
+/**
+ * This creates a new sample data metadata structure and allocates memory
+ * for it. Notice that if you add strings to this structure they
+ * will be freed by the corresponding <code>LIBMTP_destroy_sampledata_t</code>
+ * operation later, so be careful of using strdup() when assigning
+ * strings.
+ *
+ * @return a pointer to the newly allocated metadata structure.
+ * @see LIBMTP_destroy_sampledata_t()
+ */
+LIBMTP_filesampledata_t *LIBMTP_new_filesampledata_t(void)
+{
+  LIBMTP_filesampledata_t *new = (LIBMTP_filesampledata_t *) malloc(sizeof(LIBMTP_filesampledata_t));
+  if (new == NULL) {
+    return NULL;
+  }
+  new->height=0;
+  new->width = 0;
+  new->data = NULL;
+  new->duration = 0;
+  new->size = 0;
+  return new;
+}
+
+/**
+ * This destroys a file sample metadata type.
+ * @param sample the file sample metadata to be destroyed.
+ */
+void LIBMTP_destroy_filesampledata_t(LIBMTP_filesampledata_t * sample)
+{
+  if (sample == NULL) {
+    return;
+  }
+  if (sample->data != NULL) {
+    free(sample->data);
+  }
+  free(sample);
+}
+
+/**
+ * This routine figures out whether a certain filetype supports
+ * representative samples (small thumbnail images) or not. This
+ * typically applies to JPEG files, MP3 files and Album abstract
+ * playlists, but in theory any filetype could support representative
+ * samples.
+ * @param device a pointer to the device which is to be examined.
+ * @param filetype the fileype to examine, and return the representative sample
+ *        properties for.
+ * @param sample this will contain a new sample type with the fields
+ *        filled in with suitable default values. For example, the
+ *        supported sample type will be set, the supported height and
+ *        width will be set to max values if it is an image sample,
+ *        and duration will also be given some suitable default value
+ *        which should not be exceeded on audio samples. If the 
+ *        device does not support samples for this filetype, this
+ *        pointer will be NULL. If it is not NULL, the user must
+ *        destroy this struct with <code>LIBMTP_destroy_filesampledata_t()</code>
+ *        after use.
+ * @return 0 on success, any other value means failure.
+ * @see LIBMTP_Send_Representative_Sample()
+ * @see LIBMTP_Create_New_Album()
+ */
+int LIBMTP_Get_Representative_Sample_Format(LIBMTP_mtpdevice_t *device,
+					    LIBMTP_filetype_t const filetype,
+					    LIBMTP_filesampledata_t ** sample)
+{
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+  uint16_t *props = NULL;
+  uint32_t propcnt = 0;
+  int i;
+  // TODO: Get rid of these when we can properly query the device.
+  int support_data = 0;
+  int support_format = 0;
+  int support_height = 0;
+  int support_width = 0;
+  int support_duration = 0;
+  int support_size = 0;
+
+  PTPObjectPropDesc opd_height;
+  PTPObjectPropDesc opd_width;
+  PTPObjectPropDesc opd_format;
+  PTPObjectPropDesc opd_duration;
+  PTPObjectPropDesc opd_size;
+  
+  // Default to no type supported.
+  *sample = NULL;
+  
+  ret = ptp_mtp_getobjectpropssupported(params, map_libmtp_type_to_ptp_type(filetype), &propcnt, &props);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Representative_Sample_Format(): could not get object properties.");
+    return -1;
+  }
+  /*
+   * TODO: when walking through these object properties, make calls to
+   * a new function in ptp.h/ptp.c that can send the command 
+   * PTP_OC_MTP_GetObjectPropDesc to get max/min values of the properties
+   * supported.
+   */
+  for (i = 0; i < propcnt; i++) {
+    switch(props[i]) {
+    case PTP_OPC_RepresentativeSampleData:
+      support_data = 1;
+      break;
+    case PTP_OPC_RepresentativeSampleFormat:
+      support_format = 1;
+      break;
+    case PTP_OPC_RepresentativeSampleSize:
+      support_size = 1;
+      break;
+    case PTP_OPC_RepresentativeSampleHeight:
+      support_height = 1;
+      break;
+    case PTP_OPC_RepresentativeSampleWidth:
+      support_width = 1;
+      break;
+    case PTP_OPC_RepresentativeSampleDuration:
+      support_duration = 1;
+      break;
+    default:
+      break;
+    }
+  }
+  free(props);
+    
+  if (support_data && support_format && support_height && support_width && !support_duration) {
+    // Something that supports height and width and not duration is likely to be JPEG
+    LIBMTP_filesampledata_t *retsam = LIBMTP_new_filesampledata_t();
+    /* 
+     * Populate the sample format with the first supported format 
+     * 
+     * TODO: figure out how to pass back more than one format if more are
+     * supported by the device.
+     */
+    ptp_mtp_getobjectpropdesc (params, PTP_OPC_RepresentativeSampleFormat, map_libmtp_type_to_ptp_type(filetype), &opd_format);    
+    retsam->filetype = map_ptp_type_to_libmtp_type(opd_format.FORM.Enum.SupportedValue[0].u16);
+    ptp_free_objectpropdesc(&opd_format);
+    /* Populate the maximum image height */
+    ptp_mtp_getobjectpropdesc (params, PTP_OPC_RepresentativeSampleWidth, map_libmtp_type_to_ptp_type(filetype), &opd_width);        
+    retsam->width = opd_width.FORM.Range.MaximumValue.u32;
+    ptp_free_objectpropdesc(&opd_width);
+    /* Populate the maximum image width */
+    ptp_mtp_getobjectpropdesc (params, PTP_OPC_RepresentativeSampleHeight, map_libmtp_type_to_ptp_type(filetype), &opd_height);    						
+    retsam->height = opd_height.FORM.Range.MaximumValue.u32;
+    ptp_free_objectpropdesc(&opd_height);
+    /* Populate the maximum size */
+    if (support_size) {
+      ptp_mtp_getobjectpropdesc (params, PTP_OPC_RepresentativeSampleSize, map_libmtp_type_to_ptp_type(filetype), &opd_size);
+      retsam->size = opd_size.FORM.Range.MaximumValue.u32;
+      ptp_free_objectpropdesc(&opd_size);
+    }
+    *sample = retsam;
+  } else if (support_data && support_format && !support_height && !support_width && support_duration) {
+    // Another qualified guess
+    LIBMTP_filesampledata_t *retsam = LIBMTP_new_filesampledata_t();
+    /* 
+     * Populate the sample format with the first supported format 
+     * 
+     * TODO: figure out how to pass back more than one format if more are
+     * supported by the device.
+     */
+    ptp_mtp_getobjectpropdesc (params, PTP_OPC_RepresentativeSampleFormat, map_libmtp_type_to_ptp_type(filetype), &opd_format);    
+    retsam->filetype = map_ptp_type_to_libmtp_type(opd_format.FORM.Enum.SupportedValue[0].u16);
+    ptp_free_objectpropdesc(&opd_format);
+    /* Populate the maximum duration */
+    ptp_mtp_getobjectpropdesc (params, PTP_OPC_RepresentativeSampleDuration, map_libmtp_type_to_ptp_type(filetype), &opd_duration);    
+    retsam->duration = opd_duration.FORM.Range.MaximumValue.u32;
+    ptp_free_objectpropdesc(&opd_duration);
+    /* Populate the maximum size */
+    if (support_size) {
+      ptp_mtp_getobjectpropdesc (params, PTP_OPC_RepresentativeSampleSize, map_libmtp_type_to_ptp_type(filetype), &opd_size);
+      retsam->size = opd_size.FORM.Range.MaximumValue.u32;
+      ptp_free_objectpropdesc(&opd_size);
+    }
+    *sample = retsam;
+  }
+  return 0;
+}
+
+/**
+ * This routine sends representative sample data for an object.
+ * This uses the RepresentativeSampleData property of the album,
+ * if the device supports it. The data should be of a format acceptable
+ * to the player (for iRiver and Creative, this seems to be JPEG) and
+ * must not be too large. (for a Creative, max seems to be about 20KB.)
+ * Check by calling LIBMTP_Get_Representative_Sample_Format() to get
+ * maximum size, dimensions, etc..
+ * @param device a pointer to the device which the object is on.
+ * @param id unique id of the object to set artwork for.
+ * @param pointer to LIBMTP_filesampledata_t struct containing data
+ * @return 0 on success, any other value means failure.
+ * @see LIBMTP_Get_Representative_Sample()
+ * @see LIBMTP_Get_Representative_Sample_Format()
+ * @see LIBMTP_Create_New_Album()
+ */
+int LIBMTP_Send_Representative_Sample(LIBMTP_mtpdevice_t *device,
+                          uint32_t const id,
+                          LIBMTP_filesampledata_t *sampledata)
+{
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  PTPPropertyValue propval;
+  PTPObject *ob;
+  uint32_t i;
+  uint16_t *props = NULL;
+  uint32_t propcnt = 0;
+  int supported = 0;
+
+  // get the file format for the object we're going to send representative data for
+  ret = ptp_object_want (params, id, PTPOBJECT_OBJECTINFO_LOADED, &ob);
+  if (ret != PTP_RC_OK) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Send_Representative_Sample(): could not get object info.");
+    return -1;
+  }
+
+  // check that we can send representative sample data for this object format
+  ret = ptp_mtp_getobjectpropssupported(params, ob->oi.ObjectFormat, &propcnt, &props);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Send_Representative_Sample(): could not get object properties.");
+    return -1;
+  }
+
+  for (i = 0; i < propcnt; i++) {
+    if (props[i] == PTP_OPC_RepresentativeSampleData) {
+      supported = 1;
+      break;
+    }
+  }
+  if (!supported) {
+    free(props);
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Send_Representative_Sample(): object type doesn't support RepresentativeSampleData.");
+    return -1;
+  }
+  free(props);
+  
+  // Go ahead and send the data
+  propval.a.count = sampledata->size;
+  propval.a.v = malloc(sizeof(PTPPropertyValue) * sampledata->size);
+  for (i = 0; i < sampledata->size; i++) {
+    propval.a.v[i].u8 = sampledata->data[i];
+  }
+  
+  ret = ptp_mtp_setobjectpropvalue(params,id,PTP_OPC_RepresentativeSampleData,
+				   &propval,PTP_DTC_AUINT8);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Send_Representative_Sample(): could not send sample data.");
+    free(propval.a.v);
+    return -1;
+  }
+  free(propval.a.v);
+  
+  /* Set the height and width if the sample is an image, otherwise just
+   * set the duration and size */
+  switch(sampledata->filetype) {
+  case LIBMTP_FILETYPE_JPEG:
+  case LIBMTP_FILETYPE_JFIF:
+  case LIBMTP_FILETYPE_TIFF:
+  case LIBMTP_FILETYPE_BMP:
+  case LIBMTP_FILETYPE_GIF:
+  case LIBMTP_FILETYPE_PICT:
+  case LIBMTP_FILETYPE_PNG:
+    if (!FLAG_BROKEN_SET_SAMPLE_DIMENSIONS(ptp_usb)) {
+      // For images, set the height and width
+      set_object_u32(device, id, PTP_OPC_RepresentativeSampleHeight, sampledata->height);
+      set_object_u32(device, id, PTP_OPC_RepresentativeSampleWidth, sampledata->width);		
+    }
+    break;
+  default:
+    // For anything not an image, set the duration and size
+    set_object_u32(device, id, PTP_OPC_RepresentativeSampleDuration, sampledata->duration);
+    set_object_u32(device, id, PTP_OPC_RepresentativeSampleSize, sampledata->size);
+    break;  		
+  }
+    
+  return 0;
+}
+
+/**
+ * This routine gets representative sample data for an object.
+ * This uses the RepresentativeSampleData property of the album,
+ * if the device supports it.
+ * @param device a pointer to the device which the object is on.
+ * @param id unique id of the object to get data for.
+ * @param pointer to LIBMTP_filesampledata_t struct to receive data
+ * @return 0 on success, any other value means failure.
+ * @see LIBMTP_Send_Representative_Sample()
+ * @see LIBMTP_Get_Representative_Sample_Format()
+ * @see LIBMTP_Create_New_Album()
+ */
+int LIBMTP_Get_Representative_Sample(LIBMTP_mtpdevice_t *device,
+                          uint32_t const id,
+                          LIBMTP_filesampledata_t *sampledata)
+{
+  uint16_t ret;
+  PTPParams *params = (PTPParams *) device->params;
+  PTPPropertyValue propval;
+  PTPObject *ob;
+  uint32_t i;
+  uint16_t *props = NULL;
+  uint32_t propcnt = 0;
+  int supported = 0;
+
+  // get the file format for the object we're going to send representative data for
+  ret = ptp_object_want (params, id, PTPOBJECT_OBJECTINFO_LOADED, &ob);
+  if (ret != PTP_RC_OK) {
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_Representative_Sample(): could not get object info.");
+    return -1;
+  }
+
+  // check that we can store representative sample data for this object format
+  ret = ptp_mtp_getobjectpropssupported(params, ob->oi.ObjectFormat, &propcnt, &props);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Representative_Sample(): could not get object properties.");
+    return -1;
+  }
+
+  for (i = 0; i < propcnt; i++) {
+    if (props[i] == PTP_OPC_RepresentativeSampleData) {
+      supported = 1;
+      break;
+    }
+  }
+  if (!supported) {
+    free(props);
+    add_error_to_errorstack(device, LIBMTP_ERROR_GENERAL, "LIBMTP_Get_Representative_Sample(): object type doesn't support RepresentativeSampleData.");
+    return -1;
+  }
+  free(props);
+  
+  // Get the data
+  ret = ptp_mtp_getobjectpropvalue(params,id,PTP_OPC_RepresentativeSampleData,
+				   &propval,PTP_DTC_AUINT8);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Representative_Sample(): could not get sample data.");
+    return -1;
+  }
+  
+  // Store it
+  sampledata->size = propval.a.count;
+  sampledata->data = malloc(sizeof(PTPPropertyValue) * propval.a.count);
+  for (i = 0; i < propval.a.count; i++) {
+    sampledata->data[i] = propval.a.v[i].u8;
+  }
+  free(propval.a.v);
+
+  // Get the other properties  
+  sampledata->width = get_u32_from_object(device, id, PTP_OPC_RepresentativeSampleWidth, 0);
+  sampledata->height = get_u32_from_object(device, id, PTP_OPC_RepresentativeSampleHeight, 0);
+  sampledata->duration = get_u32_from_object(device, id, PTP_OPC_RepresentativeSampleDuration, 0);
+  sampledata->filetype = map_ptp_type_to_libmtp_type(
+        get_u16_from_object(device, id, PTP_OPC_RepresentativeSampleFormat, LIBMTP_FILETYPE_UNKNOWN));
+    
+  return 0;
+}
+
+/**
+ * This routine updates an album based on the metadata
+ * supplied. If the <code>tracks</code> field of the metadata
+ * contains a track listing, these tracks will be added to the
+ * album in place of those already present, i.e. the
+ * previous track listing will be deleted.
+ * @param device a pointer to the device to create the new album on.
+ * @param metadata the metadata for the album to be updated.
+ *                 notice that the field <code>album_id</code>
+ *                 must contain the apropriate album ID.
+ * @return 0 on success, any other value means failure.
+ * @see LIBMTP_Create_New_Album()
+ * @see LIBMTP_Delete_Object()
+ */
+int LIBMTP_Update_Album(LIBMTP_mtpdevice_t *device,
+			   LIBMTP_album_t const * const metadata)
+{
+  return update_abstract_list(device,
+			      metadata->name,
+			      metadata->artist,
+			      metadata->composer,
+			      metadata->genre,
+			      metadata->album_id,
+			      PTP_OFC_MTP_AbstractAudioAlbum,
+			      metadata->tracks,
+			      metadata->no_tracks);
+}
+
+/**
+ * Dummy function needed to interface to upstream
+ * ptp.c/ptp.h files.
+ */
+void ptp_nikon_getptpipguid (unsigned char* guid) {
+  return;
+}
+
+/**
+ * Add an object to cache.
+ * @param device the device which may have a cache to which the object should be added.
+ * @param object_id the object to add to the cache.
+ */ 
+static void add_object_to_cache(LIBMTP_mtpdevice_t *device, uint32_t object_id)
+{
+  PTPParams *params = (PTPParams *)device->params;
+  uint16_t ret;
+
+  ret = ptp_add_object_to_cache(params, object_id);
+  if (ret != PTP_RC_OK) {
+    add_ptp_error_to_errorstack(device, ret, "add_object_to_cache(): couldn't add object to cache");
+  }
+}
+
+
+/**
+ * Update cache after object has been modified
+ * @param device the device which may have a cache to which the object should be updated.
+ * @param object_id the object to update.
+ */
+static void update_metadata_cache(LIBMTP_mtpdevice_t *device, uint32_t object_id)
+{
+  PTPParams *params = (PTPParams *)device->params;
+
+  ptp_remove_object_from_cache(params, object_id);
+  add_object_to_cache(device, object_id);
+}
diff --git a/src/libmtp.h b/src/libmtp.h
new file mode 100644
index 0000000..7657ad3
--- /dev/null
+++ b/src/libmtp.h
@@ -0,0 +1,940 @@
+/**
+ * \file libmtp.h
+ * Interface to the Media Transfer Protocol library.
+ *
+ * Copyright (C) 2005-2008 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2005-2008 Richard A. Low <richard@wentnet.com>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ * Copyright (C) 2008 Florent Mertens <flomertens@gmail.com>
+ *
+ * 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.
+ *
+ * <code>
+ * #include <libmtp.h>
+ * </code>
+ */
+#ifndef LIBMTP_H_INCLUSION_GUARD
+#define LIBMTP_H_INCLUSION_GUARD
+
+#define LIBMTP_VERSION 1.0.1
+#define LIBMTP_VERSION_STRING "1.0.1"
+
+/* This handles MSVC pecularities */
+#ifdef _MSC_VER
+#include <windows.h>
+#define __WIN32__
+#define snprintf _snprintf
+#define ssize_t SSIZE_T
+/*
+ * Types that do not exist in Windows
+ * sys/types.h, but they exist in mingw32
+ * sys/types.h.
+ */
+typedef char int8_t;
+typedef unsigned char uint8_t;
+typedef __int16 int16_t;
+typedef unsigned __int16 uint16_t;
+typedef __int32 int32_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+#endif
+
+#include <stdio.h>
+#include <usb.h>
+#include <stdint.h>
+
+/**
+ * @defgroup types libmtp global type definitions
+ * @{
+ * The filetypes defined here are the external types used
+ * by the libmtp library interface. The types used internally
+ * as PTP-defined enumerator types is something different.
+ */
+typedef enum {
+  LIBMTP_FILETYPE_FOLDER,
+  LIBMTP_FILETYPE_WAV,
+  LIBMTP_FILETYPE_MP3,
+  LIBMTP_FILETYPE_WMA,
+  LIBMTP_FILETYPE_OGG,
+  LIBMTP_FILETYPE_AUDIBLE,
+  LIBMTP_FILETYPE_MP4,
+  LIBMTP_FILETYPE_UNDEF_AUDIO,
+  LIBMTP_FILETYPE_WMV,
+  LIBMTP_FILETYPE_AVI,
+  LIBMTP_FILETYPE_MPEG,
+  LIBMTP_FILETYPE_ASF,
+  LIBMTP_FILETYPE_QT,
+  LIBMTP_FILETYPE_UNDEF_VIDEO,
+  LIBMTP_FILETYPE_JPEG,
+  LIBMTP_FILETYPE_JFIF,
+  LIBMTP_FILETYPE_TIFF,
+  LIBMTP_FILETYPE_BMP,
+  LIBMTP_FILETYPE_GIF,
+  LIBMTP_FILETYPE_PICT,
+  LIBMTP_FILETYPE_PNG,
+  LIBMTP_FILETYPE_VCALENDAR1,
+  LIBMTP_FILETYPE_VCALENDAR2,
+  LIBMTP_FILETYPE_VCARD2,
+  LIBMTP_FILETYPE_VCARD3,
+  LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT,
+  LIBMTP_FILETYPE_WINEXEC,
+  LIBMTP_FILETYPE_TEXT,
+  LIBMTP_FILETYPE_HTML,
+  LIBMTP_FILETYPE_FIRMWARE,
+  LIBMTP_FILETYPE_AAC,
+  LIBMTP_FILETYPE_MEDIACARD,
+  LIBMTP_FILETYPE_FLAC,
+  LIBMTP_FILETYPE_MP2,
+  LIBMTP_FILETYPE_M4A,
+  LIBMTP_FILETYPE_DOC,
+  LIBMTP_FILETYPE_XML,
+  LIBMTP_FILETYPE_XLS,
+  LIBMTP_FILETYPE_PPT,
+  LIBMTP_FILETYPE_MHT,
+  LIBMTP_FILETYPE_JP2,
+  LIBMTP_FILETYPE_JPX,
+  LIBMTP_FILETYPE_ALBUM,
+  LIBMTP_FILETYPE_PLAYLIST,
+  LIBMTP_FILETYPE_UNKNOWN
+} LIBMTP_filetype_t;
+
+/**
+ * \def LIBMTP_FILETYPE_IS_AUDIO
+ * Audio filetype test.
+ *
+ * For filetypes that can be either audio
+ * or video, use LIBMTP_FILETYPE_IS_AUDIOVIDEO
+ */
+#define LIBMTP_FILETYPE_IS_AUDIO(a)\
+(a == LIBMTP_FILETYPE_WAV ||\
+ a == LIBMTP_FILETYPE_MP3 ||\
+ a == LIBMTP_FILETYPE_MP2 ||\
+ a == LIBMTP_FILETYPE_WMA ||\
+ a == LIBMTP_FILETYPE_OGG ||\
+ a == LIBMTP_FILETYPE_FLAC ||\
+ a == LIBMTP_FILETYPE_AAC ||\
+ a == LIBMTP_FILETYPE_M4A ||\
+ a == LIBMTP_FILETYPE_AUDIBLE ||\
+ a == LIBMTP_FILETYPE_UNDEF_AUDIO)
+
+/**
+ *  \def LIBMTP_FILETYPE_IS_VIDEO
+ *  Video filetype test.
+ *
+ * For filetypes that can be either audio
+ * or video, use LIBMTP_FILETYPE_IS_AUDIOVIDEO
+ */
+#define LIBMTP_FILETYPE_IS_VIDEO(a)\
+(a == LIBMTP_FILETYPE_WMV ||\
+ a == LIBMTP_FILETYPE_AVI ||\
+ a == LIBMTP_FILETYPE_MPEG ||\
+ a == LIBMTP_FILETYPE_UNDEF_VIDEO)
+
+/**
+ *  \def LIBMTP_FILETYPE_IS_AUDIOVIDEO
+ *  Audio and&slash;or video filetype test.
+ */
+#define LIBMTP_FILETYPE_IS_AUDIOVIDEO(a)\
+(a == LIBMTP_FILETYPE_MP4 ||\
+ a == LIBMTP_FILETYPE_ASF ||\
+ a == LIBMTP_FILETYPE_QT)
+
+/**
+ *  \def LIBMTP_FILETYPE_IS_TRACK
+ *  Test if filetype is a track.
+ *  Use this to determine if the File API or Track API
+ *  should be used to upload or download an object.
+ */
+#define LIBMTP_FILETYPE_IS_TRACK(a)\
+(LIBMTP_FILETYPE_IS_AUDIO(a) ||\
+ LIBMTP_FILETYPE_IS_VIDEO(a) ||\
+ LIBMTP_FILETYPE_IS_AUDIOVIDEO(a))
+
+/**
+ *  \def LIBMTP_FILETYPE_IS_IMAGE
+ *  Image filetype test
+ */
+#define LIBMTP_FILETYPE_IS_IMAGE(a)\
+(a == LIBMTP_FILETYPE_JPEG ||\
+a == LIBMTP_FILETYPE_JFIF ||\
+a == LIBMTP_FILETYPE_TIFF ||\
+a == LIBMTP_FILETYPE_BMP ||\
+a == LIBMTP_FILETYPE_GIF ||\
+a == LIBMTP_FILETYPE_PICT ||\
+a == LIBMTP_FILETYPE_PNG ||\
+a == LIBMTP_FILETYPE_JP2 ||\
+a == LIBMTP_FILETYPE_JPX ||\
+a == LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT)
+
+/**
+ *  \def LIBMTP_FILETYPE_IS_ADDRESSBOOK
+ *  Addressbook and Business card filetype test
+ */
+#define LIBMTP_FILETYPE_IS_ADDRESSBOOK(a)\
+(a == LIBMTP_FILETYPE_VCARD2 ||\
+a == LIBMTP_FILETYPE_VCARD2)
+
+/**
+ *  \def LIBMTP_FILETYPE_IS_CALENDAR
+ *  Calendar and Appointment filetype test
+ */
+#define LIBMTP_FILETYPE_IS_CALENDAR(a)\
+(a == LIBMTP_FILETYPE_VCALENDAR1 ||\
+a == LIBMTP_FILETYPE_VCALENDAR2)
+
+/**
+ * The properties defined here are the external types used
+ * by the libmtp library interface.
+ */
+typedef enum {
+  LIBMTP_PROPERTY_StorageID,
+  LIBMTP_PROPERTY_ObjectFormat,
+  LIBMTP_PROPERTY_ProtectionStatus,
+  LIBMTP_PROPERTY_ObjectSize,
+  LIBMTP_PROPERTY_AssociationType,
+  LIBMTP_PROPERTY_AssociationDesc,
+  LIBMTP_PROPERTY_ObjectFileName,
+  LIBMTP_PROPERTY_DateCreated,
+  LIBMTP_PROPERTY_DateModified,
+  LIBMTP_PROPERTY_Keywords,
+  LIBMTP_PROPERTY_ParentObject,
+  LIBMTP_PROPERTY_AllowedFolderContents,
+  LIBMTP_PROPERTY_Hidden,
+  LIBMTP_PROPERTY_SystemObject,
+  LIBMTP_PROPERTY_PersistantUniqueObjectIdentifier,
+  LIBMTP_PROPERTY_SyncID,
+  LIBMTP_PROPERTY_PropertyBag,
+  LIBMTP_PROPERTY_Name,
+  LIBMTP_PROPERTY_CreatedBy,
+  LIBMTP_PROPERTY_Artist,
+  LIBMTP_PROPERTY_DateAuthored,
+  LIBMTP_PROPERTY_Description,
+  LIBMTP_PROPERTY_URLReference,
+  LIBMTP_PROPERTY_LanguageLocale,
+  LIBMTP_PROPERTY_CopyrightInformation,
+  LIBMTP_PROPERTY_Source,
+  LIBMTP_PROPERTY_OriginLocation,
+  LIBMTP_PROPERTY_DateAdded,
+  LIBMTP_PROPERTY_NonConsumable,
+  LIBMTP_PROPERTY_CorruptOrUnplayable,
+  LIBMTP_PROPERTY_ProducerSerialNumber,
+  LIBMTP_PROPERTY_RepresentativeSampleFormat,
+  LIBMTP_PROPERTY_RepresentativeSampleSize,
+  LIBMTP_PROPERTY_RepresentativeSampleHeight,
+  LIBMTP_PROPERTY_RepresentativeSampleWidth,
+  LIBMTP_PROPERTY_RepresentativeSampleDuration,
+  LIBMTP_PROPERTY_RepresentativeSampleData,
+  LIBMTP_PROPERTY_Width,
+  LIBMTP_PROPERTY_Height,
+  LIBMTP_PROPERTY_Duration,
+  LIBMTP_PROPERTY_Rating,
+  LIBMTP_PROPERTY_Track,
+  LIBMTP_PROPERTY_Genre,
+  LIBMTP_PROPERTY_Credits,
+  LIBMTP_PROPERTY_Lyrics,
+  LIBMTP_PROPERTY_SubscriptionContentID,
+  LIBMTP_PROPERTY_ProducedBy,
+  LIBMTP_PROPERTY_UseCount,
+  LIBMTP_PROPERTY_SkipCount,
+  LIBMTP_PROPERTY_LastAccessed,
+  LIBMTP_PROPERTY_ParentalRating,
+  LIBMTP_PROPERTY_MetaGenre,
+  LIBMTP_PROPERTY_Composer,
+  LIBMTP_PROPERTY_EffectiveRating,
+  LIBMTP_PROPERTY_Subtitle,
+  LIBMTP_PROPERTY_OriginalReleaseDate,
+  LIBMTP_PROPERTY_AlbumName,
+  LIBMTP_PROPERTY_AlbumArtist,
+  LIBMTP_PROPERTY_Mood,
+  LIBMTP_PROPERTY_DRMStatus,
+  LIBMTP_PROPERTY_SubDescription,
+  LIBMTP_PROPERTY_IsCropped,
+  LIBMTP_PROPERTY_IsColorCorrected,
+  LIBMTP_PROPERTY_ImageBitDepth,
+  LIBMTP_PROPERTY_Fnumber,
+  LIBMTP_PROPERTY_ExposureTime,
+  LIBMTP_PROPERTY_ExposureIndex,
+  LIBMTP_PROPERTY_DisplayName,
+  LIBMTP_PROPERTY_BodyText,
+  LIBMTP_PROPERTY_Subject,
+  LIBMTP_PROPERTY_Priority,
+  LIBMTP_PROPERTY_GivenName,
+  LIBMTP_PROPERTY_MiddleNames,
+  LIBMTP_PROPERTY_FamilyName,
+  LIBMTP_PROPERTY_Prefix,
+  LIBMTP_PROPERTY_Suffix,
+  LIBMTP_PROPERTY_PhoneticGivenName,
+  LIBMTP_PROPERTY_PhoneticFamilyName,
+  LIBMTP_PROPERTY_EmailPrimary,
+  LIBMTP_PROPERTY_EmailPersonal1,
+  LIBMTP_PROPERTY_EmailPersonal2,
+  LIBMTP_PROPERTY_EmailBusiness1,
+  LIBMTP_PROPERTY_EmailBusiness2,
+  LIBMTP_PROPERTY_EmailOthers,
+  LIBMTP_PROPERTY_PhoneNumberPrimary,
+  LIBMTP_PROPERTY_PhoneNumberPersonal,
+  LIBMTP_PROPERTY_PhoneNumberPersonal2,
+  LIBMTP_PROPERTY_PhoneNumberBusiness,
+  LIBMTP_PROPERTY_PhoneNumberBusiness2,
+  LIBMTP_PROPERTY_PhoneNumberMobile,
+  LIBMTP_PROPERTY_PhoneNumberMobile2,
+  LIBMTP_PROPERTY_FaxNumberPrimary,
+  LIBMTP_PROPERTY_FaxNumberPersonal,
+  LIBMTP_PROPERTY_FaxNumberBusiness,
+  LIBMTP_PROPERTY_PagerNumber,
+  LIBMTP_PROPERTY_PhoneNumberOthers,
+  LIBMTP_PROPERTY_PrimaryWebAddress,
+  LIBMTP_PROPERTY_PersonalWebAddress,
+  LIBMTP_PROPERTY_BusinessWebAddress,
+  LIBMTP_PROPERTY_InstantMessengerAddress,
+  LIBMTP_PROPERTY_InstantMessengerAddress2,
+  LIBMTP_PROPERTY_InstantMessengerAddress3,
+  LIBMTP_PROPERTY_PostalAddressPersonalFull,
+  LIBMTP_PROPERTY_PostalAddressPersonalFullLine1,
+  LIBMTP_PROPERTY_PostalAddressPersonalFullLine2,
+  LIBMTP_PROPERTY_PostalAddressPersonalFullCity,
+  LIBMTP_PROPERTY_PostalAddressPersonalFullRegion,
+  LIBMTP_PROPERTY_PostalAddressPersonalFullPostalCode,
+  LIBMTP_PROPERTY_PostalAddressPersonalFullCountry,
+  LIBMTP_PROPERTY_PostalAddressBusinessFull,
+  LIBMTP_PROPERTY_PostalAddressBusinessLine1,
+  LIBMTP_PROPERTY_PostalAddressBusinessLine2,
+  LIBMTP_PROPERTY_PostalAddressBusinessCity,
+  LIBMTP_PROPERTY_PostalAddressBusinessRegion,
+  LIBMTP_PROPERTY_PostalAddressBusinessPostalCode,
+  LIBMTP_PROPERTY_PostalAddressBusinessCountry,
+  LIBMTP_PROPERTY_PostalAddressOtherFull,
+  LIBMTP_PROPERTY_PostalAddressOtherLine1,
+  LIBMTP_PROPERTY_PostalAddressOtherLine2,
+  LIBMTP_PROPERTY_PostalAddressOtherCity,
+  LIBMTP_PROPERTY_PostalAddressOtherRegion,
+  LIBMTP_PROPERTY_PostalAddressOtherPostalCode,
+  LIBMTP_PROPERTY_PostalAddressOtherCountry,
+  LIBMTP_PROPERTY_OrganizationName,
+  LIBMTP_PROPERTY_PhoneticOrganizationName,
+  LIBMTP_PROPERTY_Role,
+  LIBMTP_PROPERTY_Birthdate,
+  LIBMTP_PROPERTY_MessageTo,
+  LIBMTP_PROPERTY_MessageCC,
+  LIBMTP_PROPERTY_MessageBCC,
+  LIBMTP_PROPERTY_MessageRead,
+  LIBMTP_PROPERTY_MessageReceivedTime,
+  LIBMTP_PROPERTY_MessageSender,
+  LIBMTP_PROPERTY_ActivityBeginTime,
+  LIBMTP_PROPERTY_ActivityEndTime,
+  LIBMTP_PROPERTY_ActivityLocation,
+  LIBMTP_PROPERTY_ActivityRequiredAttendees,
+  LIBMTP_PROPERTY_ActivityOptionalAttendees,
+  LIBMTP_PROPERTY_ActivityResources,
+  LIBMTP_PROPERTY_ActivityAccepted,
+  LIBMTP_PROPERTY_Owner,
+  LIBMTP_PROPERTY_Editor,
+  LIBMTP_PROPERTY_Webmaster,
+  LIBMTP_PROPERTY_URLSource,
+  LIBMTP_PROPERTY_URLDestination,
+  LIBMTP_PROPERTY_TimeBookmark,
+  LIBMTP_PROPERTY_ObjectBookmark,
+  LIBMTP_PROPERTY_ByteBookmark,
+  LIBMTP_PROPERTY_LastBuildDate,
+  LIBMTP_PROPERTY_TimetoLive,
+  LIBMTP_PROPERTY_MediaGUID,
+  LIBMTP_PROPERTY_TotalBitRate,
+  LIBMTP_PROPERTY_BitRateType,
+  LIBMTP_PROPERTY_SampleRate,
+  LIBMTP_PROPERTY_NumberOfChannels,
+  LIBMTP_PROPERTY_AudioBitDepth,
+  LIBMTP_PROPERTY_ScanDepth,
+  LIBMTP_PROPERTY_AudioWAVECodec,
+  LIBMTP_PROPERTY_AudioBitRate,
+  LIBMTP_PROPERTY_VideoFourCCCodec,
+  LIBMTP_PROPERTY_VideoBitRate,
+  LIBMTP_PROPERTY_FramesPerThousandSeconds,
+  LIBMTP_PROPERTY_KeyFrameDistance,
+  LIBMTP_PROPERTY_BufferSize,
+  LIBMTP_PROPERTY_EncodingQuality,
+  LIBMTP_PROPERTY_EncodingProfile,
+  LIBMTP_PROPERTY_BuyFlag,
+  LIBMTP_PROPERTY_UNKNOWN
+} LIBMTP_property_t;
+
+/**
+ * These are the data types
+ */
+typedef enum {
+  LIBMTP_DATATYPE_INT8,
+  LIBMTP_DATATYPE_UINT8,
+  LIBMTP_DATATYPE_INT16,
+  LIBMTP_DATATYPE_UINT16,
+  LIBMTP_DATATYPE_INT32,
+  LIBMTP_DATATYPE_UINT32,
+  LIBMTP_DATATYPE_INT64,
+  LIBMTP_DATATYPE_UINT64,
+} LIBMTP_datatype_t;
+
+/**
+ * These are the numbered error codes. You can also
+ * get string representations for errors.
+ */
+typedef enum {
+  LIBMTP_ERROR_NONE,
+  LIBMTP_ERROR_GENERAL,
+  LIBMTP_ERROR_PTP_LAYER,
+  LIBMTP_ERROR_USB_LAYER,
+  LIBMTP_ERROR_MEMORY_ALLOCATION,
+  LIBMTP_ERROR_NO_DEVICE_ATTACHED,
+  LIBMTP_ERROR_STORAGE_FULL,
+  LIBMTP_ERROR_CONNECTING,
+  LIBMTP_ERROR_CANCELLED
+} LIBMTP_error_number_t;
+typedef struct LIBMTP_device_entry_struct LIBMTP_device_entry_t; /**< @see LIBMTP_device_entry_struct */
+typedef struct LIBMTP_raw_device_struct LIBMTP_raw_device_t; /**< @see LIBMTP_raw_device_struct */
+typedef struct LIBMTP_error_struct LIBMTP_error_t; /**< @see LIBMTP_error_struct */
+typedef struct LIBMTP_allowed_values_struct LIBMTP_allowed_values_t; /**< @see LIBMTP_allowed_values_struct */
+typedef struct LIBMTP_mtpdevice_struct LIBMTP_mtpdevice_t; /**< @see LIBMTP_mtpdevice_struct */
+typedef struct LIBMTP_file_struct LIBMTP_file_t; /**< @see LIBMTP_file_struct */
+typedef struct LIBMTP_track_struct LIBMTP_track_t; /**< @see LIBMTP_track_struct */
+typedef struct LIBMTP_playlist_struct LIBMTP_playlist_t; /**< @see LIBMTP_playlist_struct */
+typedef struct LIBMTP_album_struct LIBMTP_album_t; /**< @see LIBMTP_album_struct */
+typedef struct LIBMTP_folder_struct LIBMTP_folder_t; /**< @see LIBMTP_folder_t */
+typedef struct LIBMTP_object_struct LIBMTP_object_t; /**< @see LIBMTP_object_t */
+typedef struct LIBMTP_filesampledata_struct LIBMTP_filesampledata_t; /**< @see LIBMTP_filesample_t */
+typedef struct LIBMTP_devicestorage_struct LIBMTP_devicestorage_t; /**< @see LIBMTP_devicestorage_t */
+
+/**
+ * The callback type definition. Notice that a progress percentage ratio
+ * is easy to calculate by dividing <code>sent</code> by
+ * <code>total</code>.
+ * @param sent the number of bytes sent so far
+ * @param total the total number of bytes to send
+ * @param data a user-defined dereferencable pointer
+ * @return if anything else than 0 is returned, the current transfer will be
+ *         interrupted / cancelled.
+ */
+typedef int (* LIBMTP_progressfunc_t) (uint64_t const sent, uint64_t const total,
+                		void const * const data);
+
+/**
+ * Callback function for get by handler function
+ * @param params the device parameters
+ * @param priv a user-defined dereferencable pointer
+ * @param wantlen the number of bytes wanted
+ * @param data a buffer to write the data to
+ * @param gotlen pointer to the number of bytes actually written
+ *        to data
+ * @return LIBMTP_HANDLER_RETURN_OK if successful,
+ *         LIBMTP_HANDLER_RETURN_ERROR on error or
+ *         LIBMTP_HANDLER_RETURN_CANCEL to cancel the transfer
+ */
+typedef uint16_t (* MTPDataGetFunc)	(void* params, void* priv,
+					uint32_t wantlen, unsigned char *data, uint32_t *gotlen);
+
+/**
+ * Callback function for put by handler function
+ * @param params the device parameters
+ * @param priv a user-defined dereferencable pointer
+ * @param sendlen the number of bytes available
+ * @param data a buffer to read the data from
+ * @param putlen pointer to the number of bytes actually read
+ *        from data
+ * @return LIBMTP_HANDLER_RETURN_OK if successful,
+ *         LIBMTP_HANDLER_RETURN_ERROR on error or
+ *         LIBMTP_HANDLER_RETURN_CANCEL to cancel the transfer
+ */
+typedef uint16_t (* MTPDataPutFunc)	(void* params, void* priv,
+					uint32_t sendlen, unsigned char *data, uint32_t *putlen);
+
+/**
+ * The return codes for the get/put functions
+ */
+#define LIBMTP_HANDLER_RETURN_OK 0
+#define LIBMTP_HANDLER_RETURN_ERROR 1
+#define LIBMTP_HANDLER_RETURN_CANCEL 2
+
+/**
+ * @}
+ * @defgroup structar libmtp data structures
+ * @{
+ */
+
+/**
+ * A data structure to hold MTP device entries.
+ */
+struct LIBMTP_device_entry_struct {
+  char *vendor; /**< The vendor of this device */
+  uint16_t vendor_id; /**< Vendor ID for this device */
+  char *product; /**< The product name of this device */
+  uint16_t product_id; /**< Product ID for this device */
+  uint32_t device_flags; /**< Bugs, device specifics etc */
+};
+
+/**
+ * A data structure to hold a raw MTP device connected
+ * to the bus.
+ */
+struct LIBMTP_raw_device_struct {
+  LIBMTP_device_entry_t device_entry; /**< The device entry for this raw device */
+  uint32_t bus_location; /**< Location of the bus, if device available */
+  uint8_t devnum; /**< Device number on the bus, if device available */
+};
+
+/**
+ * A data structure to hold errors from the library.
+ */
+struct LIBMTP_error_struct {
+  LIBMTP_error_number_t errornumber;
+  char *error_text;
+  LIBMTP_error_t *next;
+};
+
+/**
+ * A data structure to hold allowed ranges of values
+ */
+struct LIBMTP_allowed_values_struct {
+  uint8_t   u8max;
+  uint8_t   u8min;
+  uint8_t   u8step;
+  uint8_t*  u8vals;
+  int8_t    i8max;
+  int8_t    i8min;
+  int8_t    i8step;
+  int8_t*   i8vals;
+  uint16_t  u16max;
+  uint16_t  u16min;
+  uint16_t  u16step;
+  uint16_t* u16vals;
+  int16_t   i16max;
+  int16_t   i16min;
+  int16_t   i16step;
+  int16_t*  i16vals;
+  uint32_t  u32max;
+  uint32_t  u32min;
+  uint32_t  u32step;
+  uint32_t* u32vals;
+  int32_t   i32max;
+  int32_t   i32min;
+  int32_t   i32step;
+  int32_t*  i32vals;
+  uint64_t  u64max;
+  uint64_t  u64min;
+  uint64_t  u64step;
+  uint64_t* u64vals;
+  int64_t   i64max;
+  int64_t   i64min;
+  int64_t   i64step;
+  int64_t*  i64vals;
+  /**
+   * Number of entries in the vals array
+   */
+  uint16_t  num_entries;
+  /**
+   * The datatype specifying which of the above is used
+  */
+  LIBMTP_datatype_t datatype;
+  /**
+   * Non zero for range, 0 for enum
+  */
+  int is_range;
+};
+
+/**
+ * Main MTP device object struct
+ */
+struct LIBMTP_mtpdevice_struct {
+  /**
+   * Object bitsize, typically 32 or 64.
+   */
+  uint8_t object_bitsize;
+  /**
+   * Parameters for this device, must be cast into
+   * \c (PTPParams*) before internal use.
+   */
+  void *params;
+  /**
+   * USB device for this device, must be cast into
+   * \c (PTP_USB*) before internal use.
+   */
+  void *usbinfo;
+  /** 
+   * The storage for this device, do not use strings in here without 
+   * copying them first, and beware that this list may be rebuilt at
+   * any time.
+   * @see LIBMTP_Get_Storage()
+   */
+  LIBMTP_devicestorage_t *storage;
+  /**
+   * The error stack. This shall be handled using the error getting
+   * and clearing functions, not by dereferencing this list.
+   */
+  LIBMTP_error_t *errorstack;
+  /** The maximum battery level for this device */
+  uint8_t maximum_battery_level;
+  /** Default music folder */
+  uint32_t default_music_folder;
+  /** Default playlist folder */
+  uint32_t default_playlist_folder;
+  /** Default picture folder */
+  uint32_t default_picture_folder;
+  /** Default video folder */
+  uint32_t default_video_folder;
+  /** Default organizer folder */
+  uint32_t default_organizer_folder;
+  /** Default ZENcast folder (only Creative devices...) */
+  uint32_t default_zencast_folder;
+  /** Default Album folder */
+  uint32_t default_album_folder;
+  /** Default Text folder */
+  uint32_t default_text_folder;
+  /** Per device iconv() converters, only used internally */
+  void *cd;
+  
+  /** Pointer to next device in linked list; NULL if this is the last device */
+  LIBMTP_mtpdevice_t *next;
+};
+
+/**
+ * MTP file struct
+ */
+struct LIBMTP_file_struct {
+  uint32_t item_id; /**< Unique item ID */
+  uint32_t parent_id; /**< ID of parent folder */
+  uint32_t storage_id; /**< ID of storage holding this file */
+  char *filename; /**< Filename of this file */
+  uint64_t filesize; /**< Size of file in bytes */
+  time_t modificationdate; /**< Date of last alteration of the file */
+  LIBMTP_filetype_t filetype; /**< Filetype used for the current file */
+  LIBMTP_file_t *next; /**< Next file in list or NULL if last file */
+};
+
+/**
+ * MTP track struct
+ */
+struct LIBMTP_track_struct {
+  uint32_t item_id; /**< Unique item ID */
+  uint32_t parent_id; /**< ID of parent folder */
+  uint32_t storage_id; /**< ID of storage holding this track */
+  char *title; /**< Track title */
+  char *artist; /**< Name of recording artist */
+  char *composer; /**< Name of recording composer */
+  char *genre; /**< Genre name for track */
+  char *album; /**< Album name for track */
+  char *date; /**< Date of original recording as a string */
+  char *filename; /**< Original filename of this track */
+  uint16_t tracknumber; /**< Track number (in sequence on recording) */
+  uint32_t duration; /**< Duration in milliseconds */
+  uint32_t samplerate; /**< Sample rate of original file, min 0x1f80 max 0xbb80 */
+  uint16_t nochannels; /**< Number of channels in this recording 0 = unknown, 1 or 2 */
+  uint32_t wavecodec; /**< FourCC wave codec name */
+  uint32_t bitrate; /**< (Average) bitrate for this file min=1 max=0x16e360 */
+  uint16_t bitratetype; /**< 0 = unused, 1 = constant, 2 = VBR, 3 = free */
+  uint16_t rating; /**< User rating 0-100 (0x00-0x64) */
+  uint32_t usecount; /**< Number of times used/played */
+  uint64_t filesize; /**< Size of track file in bytes */
+  time_t modificationdate; /**< Date of last alteration of the track */
+  LIBMTP_filetype_t filetype; /**< Filetype used for the current track */
+  LIBMTP_track_t *next; /**< Next track in list or NULL if last track */
+};
+
+/**
+ * MTP Playlist structure
+ */
+struct LIBMTP_playlist_struct {
+  uint32_t playlist_id; /**< Unique playlist ID */
+  uint32_t parent_id; /**< ID of parent folder */
+  uint32_t storage_id; /**< ID of storage holding this playlist */
+  char *name; /**< Name of playlist */
+  uint32_t *tracks; /**< The tracks in this playlist */
+  uint32_t no_tracks; /**< The number of tracks in this playlist */
+  LIBMTP_playlist_t *next; /**< Next playlist or NULL if last playlist */
+};
+
+/**
+ * MTP Album structure
+ */
+struct LIBMTP_album_struct {
+  uint32_t album_id; /**< Unique playlist ID */
+  uint32_t parent_id; /**< ID of parent folder */
+  uint32_t storage_id; /**< ID of storage holding this album */
+  char *name; /**< Name of album */
+  char *artist; /**< Name of album artist */
+  char *composer; /**< Name of recording composer */
+  char *genre; /**< Genre of album */
+  uint32_t *tracks; /**< The tracks in this album */
+  uint32_t no_tracks; /**< The number of tracks in this album */
+  LIBMTP_album_t *next; /**< Next album or NULL if last album */
+};
+
+/**
+ * MTP Folder structure
+ */
+struct LIBMTP_folder_struct {
+  uint32_t folder_id; /**< Unique folder ID */
+  uint32_t parent_id; /**< ID of parent folder */
+  uint32_t storage_id; /**< ID of storage holding this folder */
+  char *name; /**< Name of folder */
+  LIBMTP_folder_t *sibling; /**< Next folder at same level or NULL if no more */
+  LIBMTP_folder_t *child; /**< Child folder or NULL if no children */
+};
+
+/**
+ * LIBMTP Object RepresentativeSampleData Structure
+ */
+struct LIBMTP_filesampledata_struct {
+  uint32_t width; /**< Width of sample if it is an image */
+  uint32_t height; /**< Height of sample if it is an image */
+  uint32_t duration; /**< Duration in milliseconds if it is audio */
+  LIBMTP_filetype_t filetype; /**< Filetype used for the sample */
+  uint64_t size; /**< Size of sample data in bytes */
+  char *data; /**< Sample data */
+};
+
+/**
+ * LIBMTP Device Storage structure
+ */
+struct LIBMTP_devicestorage_struct {
+  uint32_t id; /**< Unique ID for this storage */
+  uint16_t StorageType; /**< Storage type */
+  uint16_t FilesystemType; /**< Filesystem type */
+  uint16_t AccessCapability; /**< Access capability */
+  uint64_t MaxCapacity; /**< Maximum capability */
+  uint64_t FreeSpaceInBytes; /**< Free space in bytes */
+  uint64_t FreeSpaceInObjects; /**< Free space in objects */
+  char *StorageDescription; /**< A brief description of this storage */
+  char *VolumeIdentifier; /**< A volume identifier */
+  LIBMTP_devicestorage_t *next; /**< Next storage, follow this link until NULL */
+  LIBMTP_devicestorage_t *prev; /**< Previous storage */
+};
+  
+
+/** @} */
+
+/* Make functions available for C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup internals The libmtp internals API.
+ * @{
+ */
+void LIBMTP_Init(void);
+int LIBMTP_Get_Supported_Devices_List(LIBMTP_device_entry_t ** const, int * const);
+/**
+ * @}
+ * @defgroup basic The basic device management API.
+ * @{
+ */
+LIBMTP_error_number_t LIBMTP_Detect_Raw_Devices(LIBMTP_raw_device_t **, int *);
+LIBMTP_mtpdevice_t *LIBMTP_Open_Raw_Device(LIBMTP_raw_device_t *);
+/* Begin old, legacy interface */
+LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void);
+LIBMTP_error_number_t LIBMTP_Get_Connected_Devices(LIBMTP_mtpdevice_t **);
+uint32_t LIBMTP_Number_Devices_In_List(LIBMTP_mtpdevice_t *);
+void LIBMTP_Release_Device_List(LIBMTP_mtpdevice_t*);
+/* End old, legacy interface */
+void LIBMTP_Release_Device(LIBMTP_mtpdevice_t*);
+void LIBMTP_Dump_Device_Info(LIBMTP_mtpdevice_t*);
+int LIBMTP_Reset_Device(LIBMTP_mtpdevice_t*);
+char *LIBMTP_Get_Manufacturername(LIBMTP_mtpdevice_t*);
+char *LIBMTP_Get_Modelname(LIBMTP_mtpdevice_t*);
+char *LIBMTP_Get_Serialnumber(LIBMTP_mtpdevice_t*);
+char *LIBMTP_Get_Deviceversion(LIBMTP_mtpdevice_t*);
+char *LIBMTP_Get_Friendlyname(LIBMTP_mtpdevice_t*);
+int LIBMTP_Set_Friendlyname(LIBMTP_mtpdevice_t*, char const * const);
+char *LIBMTP_Get_Syncpartner(LIBMTP_mtpdevice_t*);
+int LIBMTP_Set_Syncpartner(LIBMTP_mtpdevice_t*, char const * const);
+int LIBMTP_Get_Batterylevel(LIBMTP_mtpdevice_t *,
+			    uint8_t * const,
+			    uint8_t * const);
+int LIBMTP_Get_Secure_Time(LIBMTP_mtpdevice_t *, char ** const);
+int LIBMTP_Get_Device_Certificate(LIBMTP_mtpdevice_t *, char ** const);
+int LIBMTP_Get_Supported_Filetypes(LIBMTP_mtpdevice_t *, uint16_t ** const, uint16_t * const);
+LIBMTP_error_t *LIBMTP_Get_Errorstack(LIBMTP_mtpdevice_t*);
+void LIBMTP_Clear_Errorstack(LIBMTP_mtpdevice_t*);
+void LIBMTP_Dump_Errorstack(LIBMTP_mtpdevice_t*);
+
+void LIBMTP_Set_Device_Timeout(LIBMTP_mtpdevice_t *device, int milliseconds);
+void LIBMTP_Get_Device_Timeout(LIBMTP_mtpdevice_t *device, int * milliseconds);
+
+#define LIBMTP_STORAGE_SORTBY_NOTSORTED 0
+#define LIBMTP_STORAGE_SORTBY_FREESPACE 1
+#define LIBMTP_STORAGE_SORTBY_MAXSPACE  2
+
+int LIBMTP_Get_Storage(LIBMTP_mtpdevice_t *, int const);
+int LIBMTP_Format_Storage(LIBMTP_mtpdevice_t *, LIBMTP_devicestorage_t *);
+
+/**
+ * Get/set arbitrary properties.  These do not update the cache; should only be used on
+ * properties not stored in structs
+ */
+char *LIBMTP_Get_String_From_Object(LIBMTP_mtpdevice_t *, uint32_t const, LIBMTP_property_t const);
+uint64_t LIBMTP_Get_u64_From_Object(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint64_t const);
+uint32_t LIBMTP_Get_u32_From_Object(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint32_t const);
+uint16_t LIBMTP_Get_u16_From_Object(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint16_t const);
+uint8_t LIBMTP_Get_u8_From_Object(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint8_t const);
+int LIBMTP_Set_Object_String(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, char const * const);
+int LIBMTP_Set_Object_u32(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint32_t const);
+int LIBMTP_Set_Object_u16(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint16_t const);
+int LIBMTP_Set_Object_u8(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint8_t const);
+char const * LIBMTP_Get_Property_Description(LIBMTP_property_t inproperty);
+int LIBMTP_Is_Property_Supported(LIBMTP_mtpdevice_t*, LIBMTP_property_t const,
+            LIBMTP_filetype_t const);
+int LIBMTP_Get_Allowed_Property_Values(LIBMTP_mtpdevice_t*, LIBMTP_property_t const,
+            LIBMTP_filetype_t const, LIBMTP_allowed_values_t*);
+void LIBMTP_destroy_allowed_values_t(LIBMTP_allowed_values_t*);
+
+/**
+ * @}
+ * @defgroup files The file management API.
+ * @{
+ */
+LIBMTP_file_t *LIBMTP_new_file_t(void);
+void LIBMTP_destroy_file_t(LIBMTP_file_t*);
+char const * LIBMTP_Get_Filetype_Description(LIBMTP_filetype_t);
+LIBMTP_file_t *LIBMTP_Get_Filelisting(LIBMTP_mtpdevice_t *);
+LIBMTP_file_t *LIBMTP_Get_Filelisting_With_Callback(LIBMTP_mtpdevice_t *,
+      LIBMTP_progressfunc_t const, void const * const);
+LIBMTP_file_t *LIBMTP_Get_Filemetadata(LIBMTP_mtpdevice_t *, uint32_t const);
+int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const,
+			LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const,
+			LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Get_File_To_Handler(LIBMTP_mtpdevice_t *, uint32_t const, MTPDataPutFunc, void *,
+                   LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Send_File_From_File(LIBMTP_mtpdevice_t *, char const * const,
+	                 LIBMTP_file_t * const, LIBMTP_progressfunc_t const,
+			 void const * const);
+int LIBMTP_Send_File_From_File_Descriptor(LIBMTP_mtpdevice_t *, int const,
+	                LIBMTP_file_t * const, LIBMTP_progressfunc_t const,
+			void const * const);
+int LIBMTP_Send_File_From_Handler(LIBMTP_mtpdevice_t *, MTPDataGetFunc, void *,
+      LIBMTP_file_t * const, LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Set_File_Name(LIBMTP_mtpdevice_t *, LIBMTP_file_t *, const char *);
+LIBMTP_filesampledata_t *LIBMTP_new_filesampledata_t(void);
+void LIBMTP_destroy_filesampledata_t(LIBMTP_filesampledata_t *);
+int LIBMTP_Get_Representative_Sample_Format(LIBMTP_mtpdevice_t *,
+                        LIBMTP_filetype_t const,
+                        LIBMTP_filesampledata_t **);
+int LIBMTP_Send_Representative_Sample(LIBMTP_mtpdevice_t *, uint32_t const,
+                          LIBMTP_filesampledata_t *);
+int LIBMTP_Get_Representative_Sample(LIBMTP_mtpdevice_t *, uint32_t const,
+                          LIBMTP_filesampledata_t *);
+
+
+void LIBMTP_Set_Load_Cache_On_Demand(int flag);
+
+LIBMTP_file_t * LIBMTP_Get_Files_And_Folders(LIBMTP_mtpdevice_t *device,
+      uint32_t storageId, uint32_t parentId);
+
+/**
+ * @}
+ * @defgroup tracks The track management API.
+ * @{
+ */
+LIBMTP_track_t *LIBMTP_new_track_t(void);
+void LIBMTP_destroy_track_t(LIBMTP_track_t*);
+LIBMTP_track_t *LIBMTP_Get_Tracklisting(LIBMTP_mtpdevice_t*);
+LIBMTP_track_t *LIBMTP_Get_Tracklisting_With_Callback(LIBMTP_mtpdevice_t*,
+      LIBMTP_progressfunc_t const, void const * const);
+LIBMTP_track_t *LIBMTP_Get_Trackmetadata(LIBMTP_mtpdevice_t*, uint32_t const);
+int LIBMTP_Get_Track_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const,
+			LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const,
+			LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Get_Track_To_Handler(LIBMTP_mtpdevice_t *, uint32_t const, MTPDataPutFunc,
+      void *, LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Send_Track_From_File(LIBMTP_mtpdevice_t *,
+			 char const * const, LIBMTP_track_t * const,
+                         LIBMTP_progressfunc_t const,
+			 void const * const);
+int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *,
+			 int const, LIBMTP_track_t * const,
+                         LIBMTP_progressfunc_t const,
+			 void const * const);
+int LIBMTP_Send_Track_From_Handler(LIBMTP_mtpdevice_t *,
+			 MTPDataGetFunc, void *, LIBMTP_track_t * const,
+                         LIBMTP_progressfunc_t const,
+			 void const * const);
+int LIBMTP_Update_Track_Metadata(LIBMTP_mtpdevice_t *,
+			LIBMTP_track_t const * const);
+int LIBMTP_Track_Exists(LIBMTP_mtpdevice_t *, uint32_t);
+int LIBMTP_Set_Track_Name(LIBMTP_mtpdevice_t *, LIBMTP_track_t *, const char *);
+/** @} */
+
+/**
+ * @}
+ * @defgroup folders The folder management API.
+ * @{
+ */
+LIBMTP_folder_t *LIBMTP_new_folder_t(void);
+void LIBMTP_destroy_folder_t(LIBMTP_folder_t*);
+LIBMTP_folder_t *LIBMTP_Get_Folder_List(LIBMTP_mtpdevice_t*);
+LIBMTP_folder_t *LIBMTP_Find_Folder(LIBMTP_folder_t*, uint32_t const);
+uint32_t LIBMTP_Create_Folder(LIBMTP_mtpdevice_t*, char *, uint32_t, uint32_t);
+int LIBMTP_Set_Folder_Name(LIBMTP_mtpdevice_t *, LIBMTP_folder_t *, const char *);
+/** @} */
+
+
+/**
+ * @}
+ * @defgroup playlists The audio/video playlist management API.
+ * @{
+ */
+LIBMTP_playlist_t *LIBMTP_new_playlist_t(void);
+void LIBMTP_destroy_playlist_t(LIBMTP_playlist_t *);
+LIBMTP_playlist_t *LIBMTP_Get_Playlist_List(LIBMTP_mtpdevice_t *);
+LIBMTP_playlist_t *LIBMTP_Get_Playlist(LIBMTP_mtpdevice_t *, uint32_t const);
+int LIBMTP_Create_New_Playlist(LIBMTP_mtpdevice_t *, LIBMTP_playlist_t * const);
+int LIBMTP_Update_Playlist(LIBMTP_mtpdevice_t *, LIBMTP_playlist_t * const);
+int LIBMTP_Set_Playlist_Name(LIBMTP_mtpdevice_t *, LIBMTP_playlist_t *, const char *);
+
+/**
+ * @}
+ * @defgroup albums The audio/video album management API.
+ * @{
+ */
+LIBMTP_album_t *LIBMTP_new_album_t(void);
+void LIBMTP_destroy_album_t(LIBMTP_album_t *);
+LIBMTP_album_t *LIBMTP_Get_Album_List(LIBMTP_mtpdevice_t *);
+LIBMTP_album_t *LIBMTP_Get_Album(LIBMTP_mtpdevice_t *, uint32_t const);
+int LIBMTP_Create_New_Album(LIBMTP_mtpdevice_t *, LIBMTP_album_t * const);
+int LIBMTP_Update_Album(LIBMTP_mtpdevice_t *, LIBMTP_album_t const * const);
+int LIBMTP_Set_Album_Name(LIBMTP_mtpdevice_t *, LIBMTP_album_t *, const char *);
+
+/**
+ * @}
+ * @defgroup objects The object management API.
+ * @{
+ */
+int LIBMTP_Delete_Object(LIBMTP_mtpdevice_t *, uint32_t);
+int LIBMTP_Set_Object_Filename(LIBMTP_mtpdevice_t *, uint32_t , char *);
+
+/** @} */
+
+/* End of C++ exports */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LIBMTP_H_INCLUSION_GUARD */
+
diff --git a/src/libmtp.h.in b/src/libmtp.h.in
new file mode 100644
index 0000000..12f657d
--- /dev/null
+++ b/src/libmtp.h.in
@@ -0,0 +1,930 @@
+/**
+ * \file libmtp.h
+ * Interface to the Media Transfer Protocol library.
+ *
+ * Copyright (C) 2005-2008 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2005-2008 Richard A. Low <richard@wentnet.com>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ * Copyright (C) 2008 Florent Mertens <flomertens@gmail.com>
+ *
+ * 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.
+ *
+ * <code>
+ * #include <libmtp.h>
+ * </code>
+ */
+#ifndef LIBMTP_H_INCLUSION_GUARD
+#define LIBMTP_H_INCLUSION_GUARD
+
+#define LIBMTP_VERSION @VERSION@
+#define LIBMTP_VERSION_STRING "@VERSION@"
+
+/* This handles MSVC pecularities */
+#ifdef _MSC_VER
+#include <windows.h>
+#define __WIN32__
+#define snprintf _snprintf
+#define ssize_t SSIZE_T
+/*
+ * Types that do not exist in Windows
+ * sys/types.h, but they exist in mingw32
+ * sys/types.h.
+ */
+typedef char int8_t;
+typedef unsigned char uint8_t;
+typedef __int16 int16_t;
+typedef unsigned __int16 uint16_t;
+typedef __int32 int32_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+#endif
+
+#include <stdio.h>
+#include <usb.h>
+#include <stdint.h>
+
+/**
+ * @defgroup types libmtp global type definitions
+ * @{
+ * The filetypes defined here are the external types used
+ * by the libmtp library interface. The types used internally
+ * as PTP-defined enumerator types is something different.
+ */
+typedef enum {
+  LIBMTP_FILETYPE_WAV,
+  LIBMTP_FILETYPE_MP3,
+  LIBMTP_FILETYPE_WMA,
+  LIBMTP_FILETYPE_OGG,
+  LIBMTP_FILETYPE_AUDIBLE,
+  LIBMTP_FILETYPE_MP4,
+  LIBMTP_FILETYPE_UNDEF_AUDIO,
+  LIBMTP_FILETYPE_WMV,
+  LIBMTP_FILETYPE_AVI,
+  LIBMTP_FILETYPE_MPEG,
+  LIBMTP_FILETYPE_ASF,
+  LIBMTP_FILETYPE_QT,
+  LIBMTP_FILETYPE_UNDEF_VIDEO,
+  LIBMTP_FILETYPE_JPEG,
+  LIBMTP_FILETYPE_JFIF,
+  LIBMTP_FILETYPE_TIFF,
+  LIBMTP_FILETYPE_BMP,
+  LIBMTP_FILETYPE_GIF,
+  LIBMTP_FILETYPE_PICT,
+  LIBMTP_FILETYPE_PNG,
+  LIBMTP_FILETYPE_VCALENDAR1,
+  LIBMTP_FILETYPE_VCALENDAR2,
+  LIBMTP_FILETYPE_VCARD2,
+  LIBMTP_FILETYPE_VCARD3,
+  LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT,
+  LIBMTP_FILETYPE_WINEXEC,
+  LIBMTP_FILETYPE_TEXT,
+  LIBMTP_FILETYPE_HTML,
+  LIBMTP_FILETYPE_FIRMWARE,
+  LIBMTP_FILETYPE_AAC,
+  LIBMTP_FILETYPE_MEDIACARD,
+  LIBMTP_FILETYPE_FLAC,
+  LIBMTP_FILETYPE_MP2,
+  LIBMTP_FILETYPE_M4A,
+  LIBMTP_FILETYPE_DOC,
+  LIBMTP_FILETYPE_XML,
+  LIBMTP_FILETYPE_XLS,
+  LIBMTP_FILETYPE_PPT,
+  LIBMTP_FILETYPE_MHT,
+  LIBMTP_FILETYPE_JP2,
+  LIBMTP_FILETYPE_JPX,
+  LIBMTP_FILETYPE_ALBUM,
+  LIBMTP_FILETYPE_PLAYLIST,
+  LIBMTP_FILETYPE_UNKNOWN
+} LIBMTP_filetype_t;
+
+/**
+ * \def LIBMTP_FILETYPE_IS_AUDIO
+ * Audio filetype test.
+ *
+ * For filetypes that can be either audio
+ * or video, use LIBMTP_FILETYPE_IS_AUDIOVIDEO
+ */
+#define LIBMTP_FILETYPE_IS_AUDIO(a)\
+(a == LIBMTP_FILETYPE_WAV ||\
+ a == LIBMTP_FILETYPE_MP3 ||\
+ a == LIBMTP_FILETYPE_MP2 ||\
+ a == LIBMTP_FILETYPE_WMA ||\
+ a == LIBMTP_FILETYPE_OGG ||\
+ a == LIBMTP_FILETYPE_FLAC ||\
+ a == LIBMTP_FILETYPE_AAC ||\
+ a == LIBMTP_FILETYPE_M4A ||\
+ a == LIBMTP_FILETYPE_AUDIBLE ||\
+ a == LIBMTP_FILETYPE_UNDEF_AUDIO)
+
+/**
+ *  \def LIBMTP_FILETYPE_IS_VIDEO
+ *  Video filetype test.
+ *
+ * For filetypes that can be either audio
+ * or video, use LIBMTP_FILETYPE_IS_AUDIOVIDEO
+ */
+#define LIBMTP_FILETYPE_IS_VIDEO(a)\
+(a == LIBMTP_FILETYPE_WMV ||\
+ a == LIBMTP_FILETYPE_AVI ||\
+ a == LIBMTP_FILETYPE_MPEG ||\
+ a == LIBMTP_FILETYPE_UNDEF_VIDEO)
+
+/**
+ *  \def LIBMTP_FILETYPE_IS_AUDIOVIDEO
+ *  Audio and&slash;or video filetype test.
+ */
+#define LIBMTP_FILETYPE_IS_AUDIOVIDEO(a)\
+(a == LIBMTP_FILETYPE_MP4 ||\
+ a == LIBMTP_FILETYPE_ASF ||\
+ a == LIBMTP_FILETYPE_QT)
+
+/**
+ *  \def LIBMTP_FILETYPE_IS_TRACK
+ *  Test if filetype is a track.
+ *  Use this to determine if the File API or Track API
+ *  should be used to upload or download an object.
+ */
+#define LIBMTP_FILETYPE_IS_TRACK(a)\
+(LIBMTP_FILETYPE_IS_AUDIO(a) ||\
+ LIBMTP_FILETYPE_IS_VIDEO(a) ||\
+ LIBMTP_FILETYPE_IS_AUDIOVIDEO(a))
+
+/**
+ *  \def LIBMTP_FILETYPE_IS_IMAGE
+ *  Image filetype test
+ */
+#define LIBMTP_FILETYPE_IS_IMAGE(a)\
+(a == LIBMTP_FILETYPE_JPEG ||\
+a == LIBMTP_FILETYPE_JFIF ||\
+a == LIBMTP_FILETYPE_TIFF ||\
+a == LIBMTP_FILETYPE_BMP ||\
+a == LIBMTP_FILETYPE_GIF ||\
+a == LIBMTP_FILETYPE_PICT ||\
+a == LIBMTP_FILETYPE_PNG ||\
+a == LIBMTP_FILETYPE_JP2 ||\
+a == LIBMTP_FILETYPE_JPX ||\
+a == LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT)
+
+/**
+ *  \def LIBMTP_FILETYPE_IS_ADDRESSBOOK
+ *  Addressbook and Business card filetype test
+ */
+#define LIBMTP_FILETYPE_IS_ADDRESSBOOK(a)\
+(a == LIBMTP_FILETYPE_VCARD2 ||\
+a == LIBMTP_FILETYPE_VCARD2)
+
+/**
+ *  \def LIBMTP_FILETYPE_IS_CALENDAR
+ *  Calendar and Appointment filetype test
+ */
+#define LIBMTP_FILETYPE_IS_CALENDAR(a)\
+(a == LIBMTP_FILETYPE_VCALENDAR1 ||\
+a == LIBMTP_FILETYPE_VCALENDAR2)
+
+/**
+ * The properties defined here are the external types used
+ * by the libmtp library interface.
+ */
+typedef enum {
+  LIBMTP_PROPERTY_StorageID,
+  LIBMTP_PROPERTY_ObjectFormat,
+  LIBMTP_PROPERTY_ProtectionStatus,
+  LIBMTP_PROPERTY_ObjectSize,
+  LIBMTP_PROPERTY_AssociationType,
+  LIBMTP_PROPERTY_AssociationDesc,
+  LIBMTP_PROPERTY_ObjectFileName,
+  LIBMTP_PROPERTY_DateCreated,
+  LIBMTP_PROPERTY_DateModified,
+  LIBMTP_PROPERTY_Keywords,
+  LIBMTP_PROPERTY_ParentObject,
+  LIBMTP_PROPERTY_AllowedFolderContents,
+  LIBMTP_PROPERTY_Hidden,
+  LIBMTP_PROPERTY_SystemObject,
+  LIBMTP_PROPERTY_PersistantUniqueObjectIdentifier,
+  LIBMTP_PROPERTY_SyncID,
+  LIBMTP_PROPERTY_PropertyBag,
+  LIBMTP_PROPERTY_Name,
+  LIBMTP_PROPERTY_CreatedBy,
+  LIBMTP_PROPERTY_Artist,
+  LIBMTP_PROPERTY_DateAuthored,
+  LIBMTP_PROPERTY_Description,
+  LIBMTP_PROPERTY_URLReference,
+  LIBMTP_PROPERTY_LanguageLocale,
+  LIBMTP_PROPERTY_CopyrightInformation,
+  LIBMTP_PROPERTY_Source,
+  LIBMTP_PROPERTY_OriginLocation,
+  LIBMTP_PROPERTY_DateAdded,
+  LIBMTP_PROPERTY_NonConsumable,
+  LIBMTP_PROPERTY_CorruptOrUnplayable,
+  LIBMTP_PROPERTY_ProducerSerialNumber,
+  LIBMTP_PROPERTY_RepresentativeSampleFormat,
+  LIBMTP_PROPERTY_RepresentativeSampleSize,
+  LIBMTP_PROPERTY_RepresentativeSampleHeight,
+  LIBMTP_PROPERTY_RepresentativeSampleWidth,
+  LIBMTP_PROPERTY_RepresentativeSampleDuration,
+  LIBMTP_PROPERTY_RepresentativeSampleData,
+  LIBMTP_PROPERTY_Width,
+  LIBMTP_PROPERTY_Height,
+  LIBMTP_PROPERTY_Duration,
+  LIBMTP_PROPERTY_Rating,
+  LIBMTP_PROPERTY_Track,
+  LIBMTP_PROPERTY_Genre,
+  LIBMTP_PROPERTY_Credits,
+  LIBMTP_PROPERTY_Lyrics,
+  LIBMTP_PROPERTY_SubscriptionContentID,
+  LIBMTP_PROPERTY_ProducedBy,
+  LIBMTP_PROPERTY_UseCount,
+  LIBMTP_PROPERTY_SkipCount,
+  LIBMTP_PROPERTY_LastAccessed,
+  LIBMTP_PROPERTY_ParentalRating,
+  LIBMTP_PROPERTY_MetaGenre,
+  LIBMTP_PROPERTY_Composer,
+  LIBMTP_PROPERTY_EffectiveRating,
+  LIBMTP_PROPERTY_Subtitle,
+  LIBMTP_PROPERTY_OriginalReleaseDate,
+  LIBMTP_PROPERTY_AlbumName,
+  LIBMTP_PROPERTY_AlbumArtist,
+  LIBMTP_PROPERTY_Mood,
+  LIBMTP_PROPERTY_DRMStatus,
+  LIBMTP_PROPERTY_SubDescription,
+  LIBMTP_PROPERTY_IsCropped,
+  LIBMTP_PROPERTY_IsColorCorrected,
+  LIBMTP_PROPERTY_ImageBitDepth,
+  LIBMTP_PROPERTY_Fnumber,
+  LIBMTP_PROPERTY_ExposureTime,
+  LIBMTP_PROPERTY_ExposureIndex,
+  LIBMTP_PROPERTY_DisplayName,
+  LIBMTP_PROPERTY_BodyText,
+  LIBMTP_PROPERTY_Subject,
+  LIBMTP_PROPERTY_Priority,
+  LIBMTP_PROPERTY_GivenName,
+  LIBMTP_PROPERTY_MiddleNames,
+  LIBMTP_PROPERTY_FamilyName,
+  LIBMTP_PROPERTY_Prefix,
+  LIBMTP_PROPERTY_Suffix,
+  LIBMTP_PROPERTY_PhoneticGivenName,
+  LIBMTP_PROPERTY_PhoneticFamilyName,
+  LIBMTP_PROPERTY_EmailPrimary,
+  LIBMTP_PROPERTY_EmailPersonal1,
+  LIBMTP_PROPERTY_EmailPersonal2,
+  LIBMTP_PROPERTY_EmailBusiness1,
+  LIBMTP_PROPERTY_EmailBusiness2,
+  LIBMTP_PROPERTY_EmailOthers,
+  LIBMTP_PROPERTY_PhoneNumberPrimary,
+  LIBMTP_PROPERTY_PhoneNumberPersonal,
+  LIBMTP_PROPERTY_PhoneNumberPersonal2,
+  LIBMTP_PROPERTY_PhoneNumberBusiness,
+  LIBMTP_PROPERTY_PhoneNumberBusiness2,
+  LIBMTP_PROPERTY_PhoneNumberMobile,
+  LIBMTP_PROPERTY_PhoneNumberMobile2,
+  LIBMTP_PROPERTY_FaxNumberPrimary,
+  LIBMTP_PROPERTY_FaxNumberPersonal,
+  LIBMTP_PROPERTY_FaxNumberBusiness,
+  LIBMTP_PROPERTY_PagerNumber,
+  LIBMTP_PROPERTY_PhoneNumberOthers,
+  LIBMTP_PROPERTY_PrimaryWebAddress,
+  LIBMTP_PROPERTY_PersonalWebAddress,
+  LIBMTP_PROPERTY_BusinessWebAddress,
+  LIBMTP_PROPERTY_InstantMessengerAddress,
+  LIBMTP_PROPERTY_InstantMessengerAddress2,
+  LIBMTP_PROPERTY_InstantMessengerAddress3,
+  LIBMTP_PROPERTY_PostalAddressPersonalFull,
+  LIBMTP_PROPERTY_PostalAddressPersonalFullLine1,
+  LIBMTP_PROPERTY_PostalAddressPersonalFullLine2,
+  LIBMTP_PROPERTY_PostalAddressPersonalFullCity,
+  LIBMTP_PROPERTY_PostalAddressPersonalFullRegion,
+  LIBMTP_PROPERTY_PostalAddressPersonalFullPostalCode,
+  LIBMTP_PROPERTY_PostalAddressPersonalFullCountry,
+  LIBMTP_PROPERTY_PostalAddressBusinessFull,
+  LIBMTP_PROPERTY_PostalAddressBusinessLine1,
+  LIBMTP_PROPERTY_PostalAddressBusinessLine2,
+  LIBMTP_PROPERTY_PostalAddressBusinessCity,
+  LIBMTP_PROPERTY_PostalAddressBusinessRegion,
+  LIBMTP_PROPERTY_PostalAddressBusinessPostalCode,
+  LIBMTP_PROPERTY_PostalAddressBusinessCountry,
+  LIBMTP_PROPERTY_PostalAddressOtherFull,
+  LIBMTP_PROPERTY_PostalAddressOtherLine1,
+  LIBMTP_PROPERTY_PostalAddressOtherLine2,
+  LIBMTP_PROPERTY_PostalAddressOtherCity,
+  LIBMTP_PROPERTY_PostalAddressOtherRegion,
+  LIBMTP_PROPERTY_PostalAddressOtherPostalCode,
+  LIBMTP_PROPERTY_PostalAddressOtherCountry,
+  LIBMTP_PROPERTY_OrganizationName,
+  LIBMTP_PROPERTY_PhoneticOrganizationName,
+  LIBMTP_PROPERTY_Role,
+  LIBMTP_PROPERTY_Birthdate,
+  LIBMTP_PROPERTY_MessageTo,
+  LIBMTP_PROPERTY_MessageCC,
+  LIBMTP_PROPERTY_MessageBCC,
+  LIBMTP_PROPERTY_MessageRead,
+  LIBMTP_PROPERTY_MessageReceivedTime,
+  LIBMTP_PROPERTY_MessageSender,
+  LIBMTP_PROPERTY_ActivityBeginTime,
+  LIBMTP_PROPERTY_ActivityEndTime,
+  LIBMTP_PROPERTY_ActivityLocation,
+  LIBMTP_PROPERTY_ActivityRequiredAttendees,
+  LIBMTP_PROPERTY_ActivityOptionalAttendees,
+  LIBMTP_PROPERTY_ActivityResources,
+  LIBMTP_PROPERTY_ActivityAccepted,
+  LIBMTP_PROPERTY_Owner,
+  LIBMTP_PROPERTY_Editor,
+  LIBMTP_PROPERTY_Webmaster,
+  LIBMTP_PROPERTY_URLSource,
+  LIBMTP_PROPERTY_URLDestination,
+  LIBMTP_PROPERTY_TimeBookmark,
+  LIBMTP_PROPERTY_ObjectBookmark,
+  LIBMTP_PROPERTY_ByteBookmark,
+  LIBMTP_PROPERTY_LastBuildDate,
+  LIBMTP_PROPERTY_TimetoLive,
+  LIBMTP_PROPERTY_MediaGUID,
+  LIBMTP_PROPERTY_TotalBitRate,
+  LIBMTP_PROPERTY_BitRateType,
+  LIBMTP_PROPERTY_SampleRate,
+  LIBMTP_PROPERTY_NumberOfChannels,
+  LIBMTP_PROPERTY_AudioBitDepth,
+  LIBMTP_PROPERTY_ScanDepth,
+  LIBMTP_PROPERTY_AudioWAVECodec,
+  LIBMTP_PROPERTY_AudioBitRate,
+  LIBMTP_PROPERTY_VideoFourCCCodec,
+  LIBMTP_PROPERTY_VideoBitRate,
+  LIBMTP_PROPERTY_FramesPerThousandSeconds,
+  LIBMTP_PROPERTY_KeyFrameDistance,
+  LIBMTP_PROPERTY_BufferSize,
+  LIBMTP_PROPERTY_EncodingQuality,
+  LIBMTP_PROPERTY_EncodingProfile,
+  LIBMTP_PROPERTY_BuyFlag,
+  LIBMTP_PROPERTY_UNKNOWN
+} LIBMTP_property_t;
+
+/**
+ * These are the data types
+ */
+typedef enum {
+  LIBMTP_DATATYPE_INT8,
+  LIBMTP_DATATYPE_UINT8,
+  LIBMTP_DATATYPE_INT16,
+  LIBMTP_DATATYPE_UINT16,
+  LIBMTP_DATATYPE_INT32,
+  LIBMTP_DATATYPE_UINT32,
+  LIBMTP_DATATYPE_INT64,
+  LIBMTP_DATATYPE_UINT64,
+} LIBMTP_datatype_t;
+
+/**
+ * These are the numbered error codes. You can also
+ * get string representations for errors.
+ */
+typedef enum {
+  LIBMTP_ERROR_NONE,
+  LIBMTP_ERROR_GENERAL,
+  LIBMTP_ERROR_PTP_LAYER,
+  LIBMTP_ERROR_USB_LAYER,
+  LIBMTP_ERROR_MEMORY_ALLOCATION,
+  LIBMTP_ERROR_NO_DEVICE_ATTACHED,
+  LIBMTP_ERROR_STORAGE_FULL,
+  LIBMTP_ERROR_CONNECTING,
+  LIBMTP_ERROR_CANCELLED
+} LIBMTP_error_number_t;
+typedef struct LIBMTP_device_entry_struct LIBMTP_device_entry_t; /**< @see LIBMTP_device_entry_struct */
+typedef struct LIBMTP_raw_device_struct LIBMTP_raw_device_t; /**< @see LIBMTP_raw_device_struct */
+typedef struct LIBMTP_error_struct LIBMTP_error_t; /**< @see LIBMTP_error_struct */
+typedef struct LIBMTP_allowed_values_struct LIBMTP_allowed_values_t; /**< @see LIBMTP_allowed_values_struct */
+typedef struct LIBMTP_mtpdevice_struct LIBMTP_mtpdevice_t; /**< @see LIBMTP_mtpdevice_struct */
+typedef struct LIBMTP_file_struct LIBMTP_file_t; /**< @see LIBMTP_file_struct */
+typedef struct LIBMTP_track_struct LIBMTP_track_t; /**< @see LIBMTP_track_struct */
+typedef struct LIBMTP_playlist_struct LIBMTP_playlist_t; /**< @see LIBMTP_playlist_struct */
+typedef struct LIBMTP_album_struct LIBMTP_album_t; /**< @see LIBMTP_album_struct */
+typedef struct LIBMTP_folder_struct LIBMTP_folder_t; /**< @see LIBMTP_folder_t */
+typedef struct LIBMTP_object_struct LIBMTP_object_t; /**< @see LIBMTP_object_t */
+typedef struct LIBMTP_filesampledata_struct LIBMTP_filesampledata_t; /**< @see LIBMTP_filesample_t */
+typedef struct LIBMTP_devicestorage_struct LIBMTP_devicestorage_t; /**< @see LIBMTP_devicestorage_t */
+
+/**
+ * The callback type definition. Notice that a progress percentage ratio
+ * is easy to calculate by dividing <code>sent</code> by
+ * <code>total</code>.
+ * @param sent the number of bytes sent so far
+ * @param total the total number of bytes to send
+ * @param data a user-defined dereferencable pointer
+ * @return if anything else than 0 is returned, the current transfer will be
+ *         interrupted / cancelled.
+ */
+typedef int (* LIBMTP_progressfunc_t) (uint64_t const sent, uint64_t const total,
+                		void const * const data);
+
+/**
+ * Callback function for get by handler function
+ * @param params the device parameters
+ * @param priv a user-defined dereferencable pointer
+ * @param wantlen the number of bytes wanted
+ * @param data a buffer to write the data to
+ * @param gotlen pointer to the number of bytes actually written
+ *        to data
+ * @return LIBMTP_HANDLER_RETURN_OK if successful,
+ *         LIBMTP_HANDLER_RETURN_ERROR on error or
+ *         LIBMTP_HANDLER_RETURN_CANCEL to cancel the transfer
+ */
+typedef uint16_t (* MTPDataGetFunc)	(void* params, void* priv,
+					uint32_t wantlen, unsigned char *data, uint32_t *gotlen);
+
+/**
+ * Callback function for put by handler function
+ * @param params the device parameters
+ * @param priv a user-defined dereferencable pointer
+ * @param sendlen the number of bytes available
+ * @param data a buffer to read the data from
+ * @param putlen pointer to the number of bytes actually read
+ *        from data
+ * @return LIBMTP_HANDLER_RETURN_OK if successful,
+ *         LIBMTP_HANDLER_RETURN_ERROR on error or
+ *         LIBMTP_HANDLER_RETURN_CANCEL to cancel the transfer
+ */
+typedef uint16_t (* MTPDataPutFunc)	(void* params, void* priv,
+					uint32_t sendlen, unsigned char *data, uint32_t *putlen);
+
+/**
+ * The return codes for the get/put functions
+ */
+#define LIBMTP_HANDLER_RETURN_OK 0
+#define LIBMTP_HANDLER_RETURN_ERROR 1
+#define LIBMTP_HANDLER_RETURN_CANCEL 2
+
+/**
+ * @}
+ * @defgroup structar libmtp data structures
+ * @{
+ */
+
+/**
+ * A data structure to hold MTP device entries.
+ */
+struct LIBMTP_device_entry_struct {
+  char *vendor; /**< The vendor of this device */
+  uint16_t vendor_id; /**< Vendor ID for this device */
+  char *product; /**< The product name of this device */
+  uint16_t product_id; /**< Product ID for this device */
+  uint32_t device_flags; /**< Bugs, device specifics etc */
+};
+
+/**
+ * A data structure to hold a raw MTP device connected
+ * to the bus.
+ */
+struct LIBMTP_raw_device_struct {
+  LIBMTP_device_entry_t device_entry; /**< The device entry for this raw device */
+  uint32_t bus_location; /**< Location of the bus, if device available */
+  uint8_t devnum; /**< Device number on the bus, if device available */
+};
+
+/**
+ * A data structure to hold errors from the library.
+ */
+struct LIBMTP_error_struct {
+  LIBMTP_error_number_t errornumber;
+  char *error_text;
+  LIBMTP_error_t *next;
+};
+
+/**
+ * A data structure to hold allowed ranges of values
+ */
+struct LIBMTP_allowed_values_struct {
+  uint8_t   u8max;
+  uint8_t   u8min;
+  uint8_t   u8step;
+  uint8_t*  u8vals;
+  int8_t    i8max;
+  int8_t    i8min;
+  int8_t    i8step;
+  int8_t*   i8vals;
+  uint16_t  u16max;
+  uint16_t  u16min;
+  uint16_t  u16step;
+  uint16_t* u16vals;
+  int16_t   i16max;
+  int16_t   i16min;
+  int16_t   i16step;
+  int16_t*  i16vals;
+  uint32_t  u32max;
+  uint32_t  u32min;
+  uint32_t  u32step;
+  uint32_t* u32vals;
+  int32_t   i32max;
+  int32_t   i32min;
+  int32_t   i32step;
+  int32_t*  i32vals;
+  uint64_t  u64max;
+  uint64_t  u64min;
+  uint64_t  u64step;
+  uint64_t* u64vals;
+  int64_t   i64max;
+  int64_t   i64min;
+  int64_t   i64step;
+  int64_t*  i64vals;
+  /**
+   * Number of entries in the vals array
+   */
+  uint16_t  num_entries;
+  /**
+   * The datatype specifying which of the above is used
+  */
+  LIBMTP_datatype_t datatype;
+  /**
+   * Non zero for range, 0 for enum
+  */
+  int is_range;
+};
+
+/**
+ * Main MTP device object struct
+ */
+struct LIBMTP_mtpdevice_struct {
+  /**
+   * Object bitsize, typically 32 or 64.
+   */
+  uint8_t object_bitsize;
+  /**
+   * Parameters for this device, must be cast into
+   * \c (PTPParams*) before internal use.
+   */
+  void *params;
+  /**
+   * USB device for this device, must be cast into
+   * \c (PTP_USB*) before internal use.
+   */
+  void *usbinfo;
+  /** 
+   * The storage for this device, do not use strings in here without 
+   * copying them first, and beware that this list may be rebuilt at
+   * any time.
+   * @see LIBMTP_Get_Storage()
+   */
+  LIBMTP_devicestorage_t *storage;
+  /**
+   * The error stack. This shall be handled using the error getting
+   * and clearing functions, not by dereferencing this list.
+   */
+  LIBMTP_error_t *errorstack;
+  /** The maximum battery level for this device */
+  uint8_t maximum_battery_level;
+  /** Default music folder */
+  uint32_t default_music_folder;
+  /** Default playlist folder */
+  uint32_t default_playlist_folder;
+  /** Default picture folder */
+  uint32_t default_picture_folder;
+  /** Default video folder */
+  uint32_t default_video_folder;
+  /** Default organizer folder */
+  uint32_t default_organizer_folder;
+  /** Default ZENcast folder (only Creative devices...) */
+  uint32_t default_zencast_folder;
+  /** Default Album folder */
+  uint32_t default_album_folder;
+  /** Default Text folder */
+  uint32_t default_text_folder;
+  /** Per device iconv() converters, only used internally */
+  void *cd;
+  
+  /** Pointer to next device in linked list; NULL if this is the last device */
+  LIBMTP_mtpdevice_t *next;
+};
+
+/**
+ * MTP file struct
+ */
+struct LIBMTP_file_struct {
+  uint32_t item_id; /**< Unique item ID */
+  uint32_t parent_id; /**< ID of parent folder */
+  uint32_t storage_id; /**< ID of storage holding this file */
+  char *filename; /**< Filename of this file */
+  uint64_t filesize; /**< Size of file in bytes */
+  time_t modificationdate; /**< Date of last alteration of the file */
+  LIBMTP_filetype_t filetype; /**< Filetype used for the current file */
+  LIBMTP_file_t *next; /**< Next file in list or NULL if last file */
+};
+
+/**
+ * MTP track struct
+ */
+struct LIBMTP_track_struct {
+  uint32_t item_id; /**< Unique item ID */
+  uint32_t parent_id; /**< ID of parent folder */
+  uint32_t storage_id; /**< ID of storage holding this track */
+  char *title; /**< Track title */
+  char *artist; /**< Name of recording artist */
+  char *composer; /**< Name of recording composer */
+  char *genre; /**< Genre name for track */
+  char *album; /**< Album name for track */
+  char *date; /**< Date of original recording as a string */
+  char *filename; /**< Original filename of this track */
+  uint16_t tracknumber; /**< Track number (in sequence on recording) */
+  uint32_t duration; /**< Duration in milliseconds */
+  uint32_t samplerate; /**< Sample rate of original file, min 0x1f80 max 0xbb80 */
+  uint16_t nochannels; /**< Number of channels in this recording 0 = unknown, 1 or 2 */
+  uint32_t wavecodec; /**< FourCC wave codec name */
+  uint32_t bitrate; /**< (Average) bitrate for this file min=1 max=0x16e360 */
+  uint16_t bitratetype; /**< 0 = unused, 1 = constant, 2 = VBR, 3 = free */
+  uint16_t rating; /**< User rating 0-100 (0x00-0x64) */
+  uint32_t usecount; /**< Number of times used/played */
+  uint64_t filesize; /**< Size of track file in bytes */
+  time_t modificationdate; /**< Date of last alteration of the track */
+  LIBMTP_filetype_t filetype; /**< Filetype used for the current track */
+  LIBMTP_track_t *next; /**< Next track in list or NULL if last track */
+};
+
+/**
+ * MTP Playlist structure
+ */
+struct LIBMTP_playlist_struct {
+  uint32_t playlist_id; /**< Unique playlist ID */
+  uint32_t parent_id; /**< ID of parent folder */
+  uint32_t storage_id; /**< ID of storage holding this playlist */
+  char *name; /**< Name of playlist */
+  uint32_t *tracks; /**< The tracks in this playlist */
+  uint32_t no_tracks; /**< The number of tracks in this playlist */
+  LIBMTP_playlist_t *next; /**< Next playlist or NULL if last playlist */
+};
+
+/**
+ * MTP Album structure
+ */
+struct LIBMTP_album_struct {
+  uint32_t album_id; /**< Unique playlist ID */
+  uint32_t parent_id; /**< ID of parent folder */
+  uint32_t storage_id; /**< ID of storage holding this album */
+  char *name; /**< Name of album */
+  char *artist; /**< Name of album artist */
+  char *composer; /**< Name of recording composer */
+  char *genre; /**< Genre of album */
+  uint32_t *tracks; /**< The tracks in this album */
+  uint32_t no_tracks; /**< The number of tracks in this album */
+  LIBMTP_album_t *next; /**< Next album or NULL if last album */
+};
+
+/**
+ * MTP Folder structure
+ */
+struct LIBMTP_folder_struct {
+  uint32_t folder_id; /**< Unique folder ID */
+  uint32_t parent_id; /**< ID of parent folder */
+  uint32_t storage_id; /**< ID of storage holding this folder */
+  char *name; /**< Name of folder */
+  LIBMTP_folder_t *sibling; /**< Next folder at same level or NULL if no more */
+  LIBMTP_folder_t *child; /**< Child folder or NULL if no children */
+};
+
+/**
+ * LIBMTP Object RepresentativeSampleData Structure
+ */
+struct LIBMTP_filesampledata_struct {
+  uint32_t width; /**< Width of sample if it is an image */
+  uint32_t height; /**< Height of sample if it is an image */
+  uint32_t duration; /**< Duration in milliseconds if it is audio */
+  LIBMTP_filetype_t filetype; /**< Filetype used for the sample */
+  uint64_t size; /**< Size of sample data in bytes */
+  char *data; /**< Sample data */
+};
+
+/**
+ * LIBMTP Device Storage structure
+ */
+struct LIBMTP_devicestorage_struct {
+  uint32_t id; /**< Unique ID for this storage */
+  uint16_t StorageType; /**< Storage type */
+  uint16_t FilesystemType; /**< Filesystem type */
+  uint16_t AccessCapability; /**< Access capability */
+  uint64_t MaxCapacity; /**< Maximum capability */
+  uint64_t FreeSpaceInBytes; /**< Free space in bytes */
+  uint64_t FreeSpaceInObjects; /**< Free space in objects */
+  char *StorageDescription; /**< A brief description of this storage */
+  char *VolumeIdentifier; /**< A volume identifier */
+  LIBMTP_devicestorage_t *next; /**< Next storage, follow this link until NULL */
+  LIBMTP_devicestorage_t *prev; /**< Previous storage */
+};
+  
+
+/** @} */
+
+/* Make functions available for C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup internals The libmtp internals API.
+ * @{
+ */
+void LIBMTP_Init(void);
+int LIBMTP_Get_Supported_Devices_List(LIBMTP_device_entry_t ** const, int * const);
+/**
+ * @}
+ * @defgroup basic The basic device management API.
+ * @{
+ */
+LIBMTP_error_number_t LIBMTP_Detect_Raw_Devices(LIBMTP_raw_device_t **, int *);
+LIBMTP_mtpdevice_t *LIBMTP_Open_Raw_Device(LIBMTP_raw_device_t *);
+/* Begin old, legacy interface */
+LIBMTP_mtpdevice_t *LIBMTP_Get_First_Device(void);
+LIBMTP_error_number_t LIBMTP_Get_Connected_Devices(LIBMTP_mtpdevice_t **);
+uint32_t LIBMTP_Number_Devices_In_List(LIBMTP_mtpdevice_t *);
+void LIBMTP_Release_Device_List(LIBMTP_mtpdevice_t*);
+/* End old, legacy interface */
+void LIBMTP_Release_Device(LIBMTP_mtpdevice_t*);
+void LIBMTP_Dump_Device_Info(LIBMTP_mtpdevice_t*);
+int LIBMTP_Reset_Device(LIBMTP_mtpdevice_t*);
+char *LIBMTP_Get_Manufacturername(LIBMTP_mtpdevice_t*);
+char *LIBMTP_Get_Modelname(LIBMTP_mtpdevice_t*);
+char *LIBMTP_Get_Serialnumber(LIBMTP_mtpdevice_t*);
+char *LIBMTP_Get_Deviceversion(LIBMTP_mtpdevice_t*);
+char *LIBMTP_Get_Friendlyname(LIBMTP_mtpdevice_t*);
+int LIBMTP_Set_Friendlyname(LIBMTP_mtpdevice_t*, char const * const);
+char *LIBMTP_Get_Syncpartner(LIBMTP_mtpdevice_t*);
+int LIBMTP_Set_Syncpartner(LIBMTP_mtpdevice_t*, char const * const);
+int LIBMTP_Get_Batterylevel(LIBMTP_mtpdevice_t *,
+			    uint8_t * const,
+			    uint8_t * const);
+int LIBMTP_Get_Secure_Time(LIBMTP_mtpdevice_t *, char ** const);
+int LIBMTP_Get_Device_Certificate(LIBMTP_mtpdevice_t *, char ** const);
+int LIBMTP_Get_Supported_Filetypes(LIBMTP_mtpdevice_t *, uint16_t ** const, uint16_t * const);
+LIBMTP_error_t *LIBMTP_Get_Errorstack(LIBMTP_mtpdevice_t*);
+void LIBMTP_Clear_Errorstack(LIBMTP_mtpdevice_t*);
+void LIBMTP_Dump_Errorstack(LIBMTP_mtpdevice_t*);
+
+#define LIBMTP_STORAGE_SORTBY_NOTSORTED 0
+#define LIBMTP_STORAGE_SORTBY_FREESPACE 1
+#define LIBMTP_STORAGE_SORTBY_MAXSPACE  2
+
+int LIBMTP_Get_Storage(LIBMTP_mtpdevice_t *, int const);
+int LIBMTP_Format_Storage(LIBMTP_mtpdevice_t *, LIBMTP_devicestorage_t *);
+
+/**
+ * Get/set arbitrary properties.  These do not update the cache; should only be used on
+ * properties not stored in structs
+ */
+char *LIBMTP_Get_String_From_Object(LIBMTP_mtpdevice_t *, uint32_t const, LIBMTP_property_t const);
+uint64_t LIBMTP_Get_u64_From_Object(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint64_t const);
+uint32_t LIBMTP_Get_u32_From_Object(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint32_t const);
+uint16_t LIBMTP_Get_u16_From_Object(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint16_t const);
+uint8_t LIBMTP_Get_u8_From_Object(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint8_t const);
+int LIBMTP_Set_Object_String(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, char const * const);
+int LIBMTP_Set_Object_u32(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint32_t const);
+int LIBMTP_Set_Object_u16(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint16_t const);
+int LIBMTP_Set_Object_u8(LIBMTP_mtpdevice_t *, uint32_t const,
+      LIBMTP_property_t const, uint8_t const);
+char const * LIBMTP_Get_Property_Description(LIBMTP_property_t inproperty);
+int LIBMTP_Is_Property_Supported(LIBMTP_mtpdevice_t*, LIBMTP_property_t const,
+            LIBMTP_filetype_t const);
+int LIBMTP_Get_Allowed_Property_Values(LIBMTP_mtpdevice_t*, LIBMTP_property_t const,
+            LIBMTP_filetype_t const, LIBMTP_allowed_values_t*);
+void LIBMTP_destroy_allowed_values_t(LIBMTP_allowed_values_t*);
+
+/**
+ * @}
+ * @defgroup files The file management API.
+ * @{
+ */
+LIBMTP_file_t *LIBMTP_new_file_t(void);
+void LIBMTP_destroy_file_t(LIBMTP_file_t*);
+char const * LIBMTP_Get_Filetype_Description(LIBMTP_filetype_t);
+LIBMTP_file_t *LIBMTP_Get_Filelisting(LIBMTP_mtpdevice_t *);
+LIBMTP_file_t *LIBMTP_Get_Filelisting_With_Callback(LIBMTP_mtpdevice_t *,
+      LIBMTP_progressfunc_t const, void const * const);
+LIBMTP_file_t *LIBMTP_Get_Filemetadata(LIBMTP_mtpdevice_t *, uint32_t const);
+int LIBMTP_Get_File_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const,
+			LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Get_File_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const,
+			LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Get_File_To_Handler(LIBMTP_mtpdevice_t *, uint32_t const, MTPDataPutFunc, void *,
+                   LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Send_File_From_File(LIBMTP_mtpdevice_t *, char const * const,
+	                 LIBMTP_file_t * const, LIBMTP_progressfunc_t const,
+			 void const * const);
+int LIBMTP_Send_File_From_File_Descriptor(LIBMTP_mtpdevice_t *, int const,
+	                LIBMTP_file_t * const, LIBMTP_progressfunc_t const,
+			void const * const);
+int LIBMTP_Send_File_From_Handler(LIBMTP_mtpdevice_t *, MTPDataGetFunc, void *,
+      LIBMTP_file_t * const, LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Set_File_Name(LIBMTP_mtpdevice_t *, LIBMTP_file_t *, const char *);
+LIBMTP_filesampledata_t *LIBMTP_new_filesampledata_t(void);
+void LIBMTP_destroy_filesampledata_t(LIBMTP_filesampledata_t *);
+int LIBMTP_Get_Representative_Sample_Format(LIBMTP_mtpdevice_t *,
+                        LIBMTP_filetype_t const,
+                        LIBMTP_filesampledata_t **);
+int LIBMTP_Send_Representative_Sample(LIBMTP_mtpdevice_t *, uint32_t const,
+                          LIBMTP_filesampledata_t *);
+int LIBMTP_Get_Representative_Sample(LIBMTP_mtpdevice_t *, uint32_t const,
+                          LIBMTP_filesampledata_t *);
+
+/**
+ * @}
+ * @defgroup tracks The track management API.
+ * @{
+ */
+LIBMTP_track_t *LIBMTP_new_track_t(void);
+void LIBMTP_destroy_track_t(LIBMTP_track_t*);
+LIBMTP_track_t *LIBMTP_Get_Tracklisting(LIBMTP_mtpdevice_t*);
+LIBMTP_track_t *LIBMTP_Get_Tracklisting_With_Callback(LIBMTP_mtpdevice_t*,
+      LIBMTP_progressfunc_t const, void const * const);
+LIBMTP_track_t *LIBMTP_Get_Trackmetadata(LIBMTP_mtpdevice_t*, uint32_t const);
+int LIBMTP_Get_Track_To_File(LIBMTP_mtpdevice_t*, uint32_t, char const * const,
+			LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Get_Track_To_File_Descriptor(LIBMTP_mtpdevice_t*, uint32_t const, int const,
+			LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Get_Track_To_Handler(LIBMTP_mtpdevice_t *, uint32_t const, MTPDataPutFunc,
+      void *, LIBMTP_progressfunc_t const, void const * const);
+int LIBMTP_Send_Track_From_File(LIBMTP_mtpdevice_t *,
+			 char const * const, LIBMTP_track_t * const,
+                         LIBMTP_progressfunc_t const,
+			 void const * const);
+int LIBMTP_Send_Track_From_File_Descriptor(LIBMTP_mtpdevice_t *,
+			 int const, LIBMTP_track_t * const,
+                         LIBMTP_progressfunc_t const,
+			 void const * const);
+int LIBMTP_Send_Track_From_Handler(LIBMTP_mtpdevice_t *,
+			 MTPDataGetFunc, void *, LIBMTP_track_t * const,
+                         LIBMTP_progressfunc_t const,
+			 void const * const);
+int LIBMTP_Update_Track_Metadata(LIBMTP_mtpdevice_t *,
+			LIBMTP_track_t const * const);
+int LIBMTP_Track_Exists(LIBMTP_mtpdevice_t *, uint32_t);
+int LIBMTP_Set_Track_Name(LIBMTP_mtpdevice_t *, LIBMTP_track_t *, const char *);
+/** @} */
+
+/**
+ * @}
+ * @defgroup folders The folder management API.
+ * @{
+ */
+LIBMTP_folder_t *LIBMTP_new_folder_t(void);
+void LIBMTP_destroy_folder_t(LIBMTP_folder_t*);
+LIBMTP_folder_t *LIBMTP_Get_Folder_List(LIBMTP_mtpdevice_t*);
+LIBMTP_folder_t *LIBMTP_Find_Folder(LIBMTP_folder_t*, uint32_t const);
+uint32_t LIBMTP_Create_Folder(LIBMTP_mtpdevice_t*, char *, uint32_t, uint32_t);
+int LIBMTP_Set_Folder_Name(LIBMTP_mtpdevice_t *, LIBMTP_folder_t *, const char *);
+/** @} */
+
+
+/**
+ * @}
+ * @defgroup playlists The audio/video playlist management API.
+ * @{
+ */
+LIBMTP_playlist_t *LIBMTP_new_playlist_t(void);
+void LIBMTP_destroy_playlist_t(LIBMTP_playlist_t *);
+LIBMTP_playlist_t *LIBMTP_Get_Playlist_List(LIBMTP_mtpdevice_t *);
+LIBMTP_playlist_t *LIBMTP_Get_Playlist(LIBMTP_mtpdevice_t *, uint32_t const);
+int LIBMTP_Create_New_Playlist(LIBMTP_mtpdevice_t *, LIBMTP_playlist_t * const);
+int LIBMTP_Update_Playlist(LIBMTP_mtpdevice_t *, LIBMTP_playlist_t * const);
+int LIBMTP_Set_Playlist_Name(LIBMTP_mtpdevice_t *, LIBMTP_playlist_t *, const char *);
+
+/**
+ * @}
+ * @defgroup albums The audio/video album management API.
+ * @{
+ */
+LIBMTP_album_t *LIBMTP_new_album_t(void);
+void LIBMTP_destroy_album_t(LIBMTP_album_t *);
+LIBMTP_album_t *LIBMTP_Get_Album_List(LIBMTP_mtpdevice_t *);
+LIBMTP_album_t *LIBMTP_Get_Album(LIBMTP_mtpdevice_t *, uint32_t const);
+int LIBMTP_Create_New_Album(LIBMTP_mtpdevice_t *, LIBMTP_album_t * const);
+int LIBMTP_Update_Album(LIBMTP_mtpdevice_t *, LIBMTP_album_t const * const);
+int LIBMTP_Set_Album_Name(LIBMTP_mtpdevice_t *, LIBMTP_album_t *, const char *);
+
+/**
+ * @}
+ * @defgroup objects The object management API.
+ * @{
+ */
+int LIBMTP_Delete_Object(LIBMTP_mtpdevice_t *, uint32_t);
+int LIBMTP_Set_Object_Filename(LIBMTP_mtpdevice_t *, uint32_t , char *);
+
+/** @} */
+
+/* End of C++ exports */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LIBMTP_H_INCLUSION_GUARD */
+
diff --git a/src/libmtp.sym b/src/libmtp.sym
new file mode 100644
index 0000000..8a649a8
--- /dev/null
+++ b/src/libmtp.sym
@@ -0,0 +1,78 @@
+LIBMTP_Init
+LIBMTP_Get_Supported_Devices_List
+LIBMTP_Detect_Raw_Devices
+LIBMTP_Open_Raw_Device
+LIBMTP_Get_First_Device
+LIBMTP_Get_Connected_Devices
+LIBMTP_Number_Devices_In_List
+LIBMTP_Release_Device_List
+LIBMTP_Release_Device
+LIBMTP_Dump_Device_Info
+LIBMTP_Reset_Device
+LIBMTP_Get_Manufacturername
+LIBMTP_Get_Modelname
+LIBMTP_Get_Serialnumber
+LIBMTP_Get_Deviceversion
+LIBMTP_Get_Friendlyname
+LIBMTP_Set_Friendlyname
+LIBMTP_Get_Syncpartner
+LIBMTP_Set_Syncpartner
+LIBMTP_Get_Batterylevel
+LIBMTP_Get_Secure_Time
+LIBMTP_Get_Device_Certificate
+LIBMTP_Get_Supported_Filetypes
+LIBMTP_Get_Errorstack
+LIBMTP_Clear_Errorstack
+LIBMTP_Dump_Errorstack
+LIBMTP_Get_Storage
+LIBMTP_Format_Storage
+LIBMTP_new_file_t
+LIBMTP_destroy_file_t
+LIBMTP_Get_Filetype_Description
+LIBMTP_Get_Filelisting
+LIBMTP_Get_Filelisting_With_Callback
+LIBMTP_Get_Filemetadata
+LIBMTP_Get_File_To_File
+LIBMTP_Get_File_To_File_Descriptor
+LIBMTP_Send_File_From_File
+LIBMTP_Send_File_From_File_Descriptor
+LIBMTP_new_filesampledata_t
+LIBMTP_destroy_filesampledata_t
+LIBMTP_Get_Representative_Sample_Format
+LIBMTP_Send_Representative_Sample
+LIBMTP_Get_Representative_Sample
+LIBMTP_new_track_t
+LIBMTP_destroy_track_t
+LIBMTP_Get_Tracklisting
+LIBMTP_Get_Tracklisting_With_Callback
+LIBMTP_Get_Trackmetadata
+LIBMTP_Get_Track_To_File
+LIBMTP_Get_Track_To_File_Descriptor
+LIBMTP_Send_Track_From_File
+LIBMTP_Send_Track_From_File_Descriptor
+LIBMTP_Update_Track_Metadata
+LIBMTP_Track_Exists
+LIBMTP_new_folder_t
+LIBMTP_destroy_folder_t
+LIBMTP_Get_Folder_List
+LIBMTP_Find_Folder
+LIBMTP_Create_Folder
+LIBMTP_new_playlist_t
+LIBMTP_destroy_playlist_t
+LIBMTP_Get_Playlist_List
+LIBMTP_Get_Playlist
+LIBMTP_Create_New_Playlist
+LIBMTP_Update_Playlist
+LIBMTP_new_album_t
+LIBMTP_destroy_album_t
+LIBMTP_Get_Album_List
+LIBMTP_Get_Album
+LIBMTP_Create_New_Album
+LIBMTP_Update_Album
+LIBMTP_Delete_Object
+LIBMTP_Set_File_Name
+LIBMTP_Set_Folder_Name
+LIBMTP_Set_Track_Name
+LIBMTP_Set_Playlist_Name
+LIBMTP_Set_Album_Name
+LIBMTP_Set_Object_Filename
diff --git a/src/libptp-stdint.h b/src/libptp-stdint.h
new file mode 100644
index 0000000..80ecf41
--- /dev/null
+++ b/src/libptp-stdint.h
@@ -0,0 +1,2 @@
+/* This file is generated automatically by configure */
+#include <stdint.h>
diff --git a/src/libusb-glue.c b/src/libusb-glue.c
new file mode 100644
index 0000000..6c0effe
--- /dev/null
+++ b/src/libusb-glue.c
@@ -0,0 +1,1911 @@
+/*
+ * \file libusb-glue.c
+ * Low-level USB interface glue towards libusb.
+ *
+ * Copyright (C) 2005-2007 Richard A. Low <richard@wentnet.com>
+ * Copyright (C) 2005-2008 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006-2007 Marcus Meissner
+ * Copyright (C) 2007 Ted Bullock
+ * Copyright (C) 2008 Chris Bagwell <chris@cnpbagwell.com>
+ *
+ * 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.
+ *
+ * Created by Richard Low on 24/12/2005. (as mtp-utils.c)
+ * Modified by Linus Walleij 2006-03-06
+ *  (Notice that Anglo-Saxons use little-endian dates and Swedes
+ *   use big-endian dates.)
+ *
+ */
+#include "config.h"
+#include "libmtp.h"
+#include "libusb-glue.h"
+#include "device-flags.h"
+#include "util.h"
+#include "ptp.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <usb.h>
+
+#include "ptp-pack.c"
+
+/* Aha, older libusb does not have USB_CLASS_PTP */
+#ifndef USB_CLASS_PTP
+#define USB_CLASS_PTP 6
+#endif
+
+/* To enable debug prints for USB stuff, switch on this */
+//#define ENABLE_USB_BULK_DEBUG
+
+/* Default USB timeout length.  This can be overridden as needed
+ * but should start with a reasonable value so most common 
+ * requests can be completed.  The original value of 4000 was
+ * not long enough for large file transfer.  Also, players can
+ * spend a bit of time collecting data.  Higher values also
+ * make connecting/disconnecting more reliable.
+ */
+#define USB_TIMEOUT_DEFAULT     10000
+
+/* USB control message data phase direction */
+#ifndef USB_DP_HTD
+#define USB_DP_HTD		(0x00 << 7)	/* host to device */
+#endif
+#ifndef USB_DP_DTH
+#define USB_DP_DTH		(0x01 << 7)	/* device to host */
+#endif
+
+/* USB Feature selector HALT */
+#ifndef USB_FEATURE_HALT
+#define USB_FEATURE_HALT	0x00
+#endif
+
+/* Internal data types */
+struct mtpdevice_list_struct {
+  struct usb_device *libusb_device;
+  PTPParams *params;
+  PTP_USB *ptp_usb;
+  uint32_t bus_location;
+  struct mtpdevice_list_struct *next;
+};
+typedef struct mtpdevice_list_struct mtpdevice_list_t;
+
+static const LIBMTP_device_entry_t mtp_device_table[] = {
+/* We include an .h file which is shared between us and libgphoto2 */
+#include "music-players.h"
+};
+static const int mtp_device_table_size = sizeof(mtp_device_table) / sizeof(LIBMTP_device_entry_t);
+
+// Local functions
+static struct usb_bus* init_usb();
+static void close_usb(PTP_USB* ptp_usb);
+static void find_interface_and_endpoints(struct usb_device *dev,
+					 uint8_t *interface,
+					 int* inep, 
+					 int* inep_maxpacket, 
+					 int* outep, 
+					 int* outep_maxpacket, 
+					 int* intep);
+static void clear_stall(PTP_USB* ptp_usb);
+static int init_ptp_usb (PTPParams* params, PTP_USB* ptp_usb, struct usb_device* dev);
+static short ptp_write_func (unsigned long,PTPDataHandler*,void *data,unsigned long*);
+static short ptp_read_func (unsigned long,PTPDataHandler*,void *data,unsigned long*,int);
+static int usb_clear_stall_feature(PTP_USB* ptp_usb, int ep);
+static int usb_get_endpoint_status(PTP_USB* ptp_usb, int ep, uint16_t* status);
+
+/**
+ * Get a list of the supported USB devices.
+ *
+ * The developers depend on users of this library to constantly
+ * add in to the list of supported devices. What we need is the
+ * device name, USB Vendor ID (VID) and USB Product ID (PID).
+ * put this into a bug ticket at the project homepage, please.
+ * The VID/PID is used to let e.g. udev lift the device to
+ * console userspace access when it's plugged in.
+ *
+ * @param devices a pointer to a pointer that will hold a device
+ *        list after the call to this function, if it was
+ *        successful.
+ * @param numdevs a pointer to an integer that will hold the number
+ *        of devices in the device list if the call was successful.
+ * @return 0 if the list was successfull retrieved, any other
+ *        value means failure.
+ */
+int LIBMTP_Get_Supported_Devices_List(LIBMTP_device_entry_t ** const devices, int * const numdevs)
+{
+  *devices = (LIBMTP_device_entry_t *) &mtp_device_table;
+  *numdevs = mtp_device_table_size;
+  return 0;
+}
+
+
+static struct usb_bus* init_usb()
+{
+  usb_init();
+  usb_find_busses();
+  usb_find_devices();
+  return (usb_get_busses());
+}
+
+/**
+ * Small recursive function to append a new usb_device to the linked list of
+ * USB MTP devices
+ * @param devlist dynamic linked list of pointers to usb devices with MTP 
+ *        properties, to be extended with new device.
+ * @param newdevice the new device to add.
+ * @param bus_location bus for this device.
+ * @return an extended array or NULL on failure.
+ */
+static mtpdevice_list_t *append_to_mtpdevice_list(mtpdevice_list_t *devlist,
+						  struct usb_device *newdevice,
+						  uint32_t bus_location)
+{
+  mtpdevice_list_t *new_list_entry;
+  
+  new_list_entry = (mtpdevice_list_t *) malloc(sizeof(mtpdevice_list_t));
+  if (new_list_entry == NULL) {
+    return NULL;
+  }
+  // Fill in USB device, if we *HAVE* to make a copy of the device do it here.
+  new_list_entry->libusb_device = newdevice;
+  new_list_entry->bus_location = bus_location;
+  new_list_entry->next = NULL;
+  
+  if (devlist == NULL) {
+    return new_list_entry;
+  } else {
+    mtpdevice_list_t *tmp = devlist;
+    while (tmp->next != NULL) {
+      tmp = tmp->next;
+    }
+    tmp->next = new_list_entry;
+  }
+  return devlist;
+}
+
+/**
+ * Small recursive function to free dynamic memory allocated to the linked list
+ * of USB MTP devices
+ * @param devlist dynamic linked list of pointers to usb devices with MTP 
+ * properties.
+ * @return nothing
+ */
+static void free_mtpdevice_list(mtpdevice_list_t *devlist)
+{
+  mtpdevice_list_t *tmplist = devlist;
+
+  if (devlist == NULL)
+    return;
+  while (tmplist != NULL) {
+    mtpdevice_list_t *tmp = tmplist;
+    tmplist = tmplist->next;
+    // Do not free() the fields (ptp_usb, params)! These are used elsewhere.
+    free(tmp);
+  }
+  return;
+}
+
+/* Comment out this define to enable the original, more aggressive probing. */
+#define MILD_MTP_PROBING
+
+#ifdef MILD_MTP_PROBING
+/**
+ * This checks if a device has an interface with MTP description.
+ *
+ * @param dev a device struct from libusb.
+ * @param dumpfile set to non-NULL to make the descriptors dump out
+ *        to this file in human-readable hex so we can scruitinze them.
+ * @return 1 if the device is MTP compliant, 0 if not.
+ */
+static int probe_device_descriptor(struct usb_device *dev, FILE *dumpfile)
+{
+  usb_dev_handle *devh;
+  unsigned char buf[1024];
+  int i;
+  int ret;
+
+  /*
+   * Don't examine devices that are not likely to
+   * contain any MTP interface, update this the day
+   * you find some weird combination...
+   */
+  if (!(dev->descriptor.bDeviceClass == USB_CLASS_PER_INTERFACE ||
+	dev->descriptor.bDeviceClass == USB_CLASS_COMM ||
+	dev->descriptor.bDeviceClass == USB_CLASS_PTP ||
+	dev->descriptor.bDeviceClass == USB_CLASS_VENDOR_SPEC)) {
+    return 0;
+  }
+
+  /* Attempt to open Device on this port */
+  devh = usb_open(dev);
+  if (devh == NULL) {
+    /* Could not open this device */
+    return 0;
+  }
+
+  /*
+   * This sometimes crashes on the j for loop below
+   * I think it is because config is NULL yet
+   * dev->descriptor.bNumConfigurations > 0
+   * this check should stop this
+   */
+  if (dev->config) {
+    /*
+     * Loop over the interfaces, and check for string "MTP"
+     * in the descriptions.
+     */
+
+    for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
+      uint8_t j;
+
+      for (j = 0; j < dev->config[i].bNumInterfaces; j++) {
+        int k;
+        for (k = 0; k < dev->config[i].interface[j].num_altsetting; k++) {
+	  /* Current interface descriptor */
+	  struct usb_interface_descriptor *intf =
+	    &dev->config[i].interface[j].altsetting[k];
+
+          buf[0] = '\0';
+          ret = usb_get_string_simple(devh,
+				      dev->config[i].interface[j].altsetting[k].iInterface,
+				      (char *) buf,
+				      1024);
+
+	  if (ret < 3)
+	    continue;
+          if (strcmp((char *) buf, "MTP") == 0) {
+	    if (dumpfile != NULL) {
+              fprintf(dumpfile, "Configuration %d, interface %d, altsetting %d:\n", i, j, k);
+	      fprintf(dumpfile, "   Interface description contains the string \"MTP\"\n");
+	      fprintf(dumpfile, "   Device recognized as MTP, no further probing.\n");
+	    }
+            usb_close(devh);
+            return 1;
+          }
+       }
+      }
+    }
+  }
+
+  return 0;
+}
+
+#else /* MILD_MTP_PROBING */
+/**
+ * This checks if a device has an MTP descriptor. The descriptor was
+ * elaborated about in gPhoto bug 1482084, and some official documentation
+ * with no strings attached was published by Microsoft at
+ * http://www.microsoft.com/whdc/system/bus/USB/USBFAQ_intermed.mspx#E3HAC
+ *
+ * @param dev a device struct from libusb.
+ * @param dumpfile set to non-NULL to make the descriptors dump out
+ *        to this file in human-readable hex so we can scruitinze them.
+ * @return 1 if the device is MTP compliant, 0 if not.
+ */
+static int probe_device_descriptor(struct usb_device *dev, FILE *dumpfile)
+{
+  usb_dev_handle *devh;
+  unsigned char buf[1024], cmd;
+  int i;
+  int ret;
+  
+  /* Don't examine hubs (no point in that) */
+  if (dev->descriptor.bDeviceClass == USB_CLASS_HUB) {
+    return 0;
+  }
+  
+  /* Attempt to open Device on this port */
+  devh = usb_open(dev);
+  if (devh == NULL) {
+    /* Could not open this device */
+    return 0;
+  }
+
+  /*
+   * This sometimes crashes on the j for loop below
+   * I think it is because config is NULL yet
+   * dev->descriptor.bNumConfigurations > 0
+   * this check should stop this
+   */
+  if (dev->config) {
+    /*
+     * Loop over the device configurations and interfaces. Nokia MTP-capable
+     * handsets (possibly others) typically have the string "MTP" in their
+     * MTP interface descriptions, that's how they can be detected, before
+     * we try the more esoteric "OS descriptors" (below).
+     */
+    for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
+      uint8_t j;
+
+      for (j = 0; j < dev->config[i].bNumInterfaces; j++) {
+        int k;
+        for (k = 0; k < dev->config[i].interface[j].num_altsetting; k++) {
+	  /* Current interface descriptor */
+	  struct usb_interface_descriptor *intf =
+	    &dev->config[i].interface[j].altsetting[k];
+
+
+          buf[0] = '\0';
+          ret = usb_get_string_simple(devh,
+				      dev->config[i].interface[j].altsetting[k].iInterface,
+				      (char *) buf,
+				      1024);
+	  if (ret < 3)
+	    continue;
+          if (strcmp((char *) buf, "MTP") == 0) {
+	    if (dumpfile != NULL) {
+              fprintf(dumpfile, "Configuration %d, interface %d, altsetting %d:\n", i, j, k);
+	      fprintf(dumpfile, "   Interface description contains the string \"MTP\"\n");
+	      fprintf(dumpfile, "   Device recognized as MTP, no further probing.\n");
+	    }
+            usb_close(devh);
+            return 1;
+          }
+  #ifdef LIBUSB_HAS_GET_DRIVER_NP
+	  {
+	    /*
+	     * Specifically avoid probing anything else than USB mass storage devices
+	     * and non-associated drivers in Linux.
+	     */
+	    char devname[0x10];
+
+	    devname[0] = '\0';
+	    ret = usb_get_driver_np(devh,
+				    dev->config[i].interface[j].altsetting[k].iInterface,
+				    devname,
+				    sizeof(devname));
+	    if (devname[0] != '\0' && strcmp(devname, "usb-storage")) {
+	      printf("avoid probing device using kernel interface \"%s\"\n", devname);
+	      return 0;
+	    }
+	  }
+  #endif
+        }
+      }
+    }
+  } else {
+    if (dev->descriptor.bNumConfigurations)
+      printf("dev->config is NULL in probe_device_descriptor yet dev->descriptor.bNumConfigurations > 0\n");
+  }
+  
+  /* Read the special descriptor */
+  ret = usb_get_descriptor(devh, 0x03, 0xee, buf, sizeof(buf));
+
+  // Dump it, if requested
+  if (dumpfile != NULL && ret > 0) {
+    fprintf(dumpfile, "Microsoft device descriptor 0xee:\n");
+    data_dump_ascii(dumpfile, buf, ret, 16);
+  }
+  
+  /* Check if descriptor length is at least 10 bytes */
+  if (ret < 10) {
+    usb_close(devh);
+    return 0;
+  }
+      
+  /* Check if this device has a Microsoft Descriptor */
+  if (!((buf[2] == 'M') && (buf[4] == 'S') &&
+	(buf[6] == 'F') && (buf[8] == 'T'))) {
+    usb_close(devh);
+    return 0;
+  }
+      
+  /* Check if device responds to control message 1 or if there is an error */
+  cmd = buf[16];
+  ret = usb_control_msg (devh,
+			 USB_ENDPOINT_IN|USB_RECIP_DEVICE|USB_TYPE_VENDOR,
+			 cmd,
+			 0,
+			 4,
+			 (char *) buf,
+			 sizeof(buf),
+                         USB_TIMEOUT_DEFAULT);
+
+  // Dump it, if requested
+  if (dumpfile != NULL && ret > 0) {
+    fprintf(dumpfile, "Microsoft device response to control message 1, CMD 0x%02x:\n", cmd);
+    data_dump_ascii(dumpfile, buf, ret, 16);
+  }
+  
+  /* If this is true, the device either isn't MTP or there was an error */
+  if (ret <= 0x15) {
+    /* TODO: If there was an error, flag it and let the user know somehow */
+    /* if(ret == -1) {} */
+    usb_close(devh);
+    return 0;
+  }
+  
+  /* Check if device is MTP or if it is something like a USB Mass Storage 
+     device with Janus DRM support */
+  if ((buf[0x12] != 'M') || (buf[0x13] != 'T') || (buf[0x14] != 'P')) {
+    usb_close(devh);
+    return 0;
+  }
+      
+  /* After this point we are probably dealing with an MTP device */
+
+  /* Check if device responds to control message 2 or if there is an error*/
+  ret = usb_control_msg (devh,
+			 USB_ENDPOINT_IN|USB_RECIP_DEVICE|USB_TYPE_VENDOR,
+			 cmd,
+			 0,
+			 5,
+			 (char *) buf,
+			 sizeof(buf),
+                         USB_TIMEOUT_DEFAULT);
+
+  // Dump it, if requested
+  if (dumpfile != NULL && ret > 0) {
+    fprintf(dumpfile, "Microsoft device response to control message 2, CMD 0x%02x:\n", cmd);
+    data_dump_ascii(dumpfile, buf, ret, 16);
+  }
+  
+  /* If this is true, the device errored against control message 2 */
+  if (ret == -1) {
+    /* TODO: Implement callback function to let managing program know there
+       was a problem, along with description of the problem */
+    fprintf(stderr, "Potential MTP Device with VendorID:%04x and "
+	    "ProductID:%04x encountered an error responding to "
+	    "control message 2.\n"
+	    "Problems may arrise but continuing\n",
+	    dev->descriptor.idVendor, dev->descriptor.idProduct);
+  } else if (ret <= 0x15) {
+    /* TODO: Implement callback function to let managing program know there
+       was a problem, along with description of the problem */
+    fprintf(stderr, "Potential MTP Device with VendorID:%04x and "
+	    "ProductID:%04x responded to control message 2 with a "
+	    "response that was too short. Problems may arrise but "
+	    "continuing\n",
+	    dev->descriptor.idVendor, dev->descriptor.idProduct);
+  } else if ((buf[0x12] != 'M') || (buf[0x13] != 'T') || (buf[0x14] != 'P')) {
+    /* TODO: Implement callback function to let managing program know there
+       was a problem, along with description of the problem */
+    fprintf(stderr, "Potential MTP Device with VendorID:%04x and "
+	    "ProductID:%04x encountered an error responding to "
+	    "control message 2\n"
+	    "Problems may arrise but continuing\n",
+	    dev->descriptor.idVendor, dev->descriptor.idProduct);
+  }
+  
+  /* Close the USB device handle */
+  usb_close(devh);
+  return 1;
+}
+#endif /* MILD_MTP_PROBING */
+
+/**
+ * This function scans through the connected usb devices on a machine and
+ * if they match known Vendor and Product identifiers appends them to the
+ * dynamic array mtp_device_list. Be sure to call 
+ * <code>free_mtpdevice_list(mtp_device_list)</code> when you are done 
+ * with it, assuming it is not NULL.
+ * @param mtp_device_list dynamic array of pointers to usb devices with MTP 
+ *        properties (if this list is not empty, new entries will be appended
+ *        to the list).
+ * @return LIBMTP_ERROR_NONE implies that devices have been found, scan the list
+ *        appropriately. LIBMTP_ERROR_NO_DEVICE_ATTACHED implies that no 
+ *        devices have been found.
+ */
+static LIBMTP_error_number_t get_mtp_usb_device_list(mtpdevice_list_t ** mtp_device_list)
+{
+  struct usb_bus *bus = init_usb();
+  for (; bus != NULL; bus = bus->next) {
+    struct usb_device *dev = bus->devices;
+    for (; dev != NULL; dev = dev->next) {
+      if (dev->descriptor.bDeviceClass != USB_CLASS_HUB) {
+	int i;
+        int found = 0;
+
+	// First check if we know about the device already.
+	// Devices well known to us will not have their descriptors
+	// probed, it caused problems with some devices.
+        for(i = 0; i < mtp_device_table_size; i++) {
+          if(dev->descriptor.idVendor == mtp_device_table[i].vendor_id &&
+            dev->descriptor.idProduct == mtp_device_table[i].product_id) {
+            /* Append this usb device to the MTP device list */
+            *mtp_device_list = append_to_mtpdevice_list(*mtp_device_list, 
+							dev, 
+							bus->location);
+            found = 1;
+            break;
+          }
+        }
+	// If we didn't know it, try probing the "OS Descriptor".
+        if (!found) {
+          if (probe_device_descriptor(dev, NULL)) {
+            /* Append this usb device to the MTP USB Device List */
+            *mtp_device_list = append_to_mtpdevice_list(*mtp_device_list, 
+							dev,
+							bus->location);
+          }
+          /*
+	   * By thomas_-_s: Also append devices that are no MTP but PTP devices
+	   * if this is commented out.
+	   */
+	  /*
+	  else {
+	    // Check whether the device is no USB hub but a PTP.
+	    if ( dev->config != NULL &&dev->config->interface->altsetting->bInterfaceClass == USB_CLASS_PTP && dev->descriptor.bDeviceClass != USB_CLASS_HUB ) {
+	      *mtp_device_list = append_to_mtpdevice_list(*mtp_device_list, dev, bus->location);
+	    }
+          }
+	  */
+        }
+      }
+    }
+  }
+  
+  /* If nothing was found we end up here. */
+  if(*mtp_device_list == NULL) {
+    return LIBMTP_ERROR_NO_DEVICE_ATTACHED;
+  }
+  return LIBMTP_ERROR_NONE;
+}
+
+/**
+ * Detect the raw MTP device descriptors and return a list of
+ * of the devices found.
+ * 
+ * @param devices a pointer to a variable that will hold
+ *        the list of raw devices found. This may be NULL
+ *        on return if the number of detected devices is zero.
+ *        The user shall simply <code>free()</code> this
+ *        variable when finished with the raw devices,
+ *        in order to release memory.
+ * @param numdevs a pointer to an integer that will hold 
+ *        the number of devices in the list. This may
+ *        be 0.
+ * @return 0 if successful, any other value means failure.
+ */
+LIBMTP_error_number_t LIBMTP_Detect_Raw_Devices(LIBMTP_raw_device_t ** devices, 
+			      int * numdevs)
+{
+  mtpdevice_list_t *devlist = NULL;
+  mtpdevice_list_t *dev;
+  LIBMTP_error_number_t ret;
+  LIBMTP_raw_device_t *retdevs;
+  int devs = 0;
+  int i, j;
+
+  ret = get_mtp_usb_device_list(&devlist);
+  if (ret == LIBMTP_ERROR_NO_DEVICE_ATTACHED) {
+    *devices = NULL;
+    *numdevs = 0;
+    return ret;
+  } else if (ret != LIBMTP_ERROR_NONE) {
+    fprintf(stderr, "LIBMTP PANIC: get_mtp_usb_device_list() "
+	    "error code: %d on line %d\n", ret, __LINE__);
+    return ret;
+  }
+
+  // Get list size
+  dev = devlist;
+  while (dev != NULL) {
+    devs++;
+    dev = dev->next;
+  }
+  if (devs == 0) {
+    *devices = NULL;
+    *numdevs = 0;
+    return LIBMTP_ERROR_NONE;
+  }
+  // Conjure a device list
+  retdevs = (LIBMTP_raw_device_t *) malloc(sizeof(LIBMTP_raw_device_t) * devs);
+  if (retdevs == NULL) {
+    // Out of memory
+    *devices = NULL;
+    *numdevs = 0;
+    return LIBMTP_ERROR_MEMORY_ALLOCATION;
+  }
+  dev = devlist;
+  i = 0;
+  while (dev != NULL) {
+    int device_known = 0;
+
+    // Assign default device info
+    retdevs[i].device_entry.vendor = NULL;
+    retdevs[i].device_entry.vendor_id = dev->libusb_device->descriptor.idVendor;
+    retdevs[i].device_entry.product = NULL;
+    retdevs[i].device_entry.product_id = dev->libusb_device->descriptor.idProduct;
+    retdevs[i].device_entry.device_flags = 0x00000000U;
+    // See if we can locate some additional vendor info and device flags
+    for(j = 0; j < mtp_device_table_size; j++) {
+      if(dev->libusb_device->descriptor.idVendor == mtp_device_table[j].vendor_id &&
+	 dev->libusb_device->descriptor.idProduct == mtp_device_table[j].product_id) {
+	device_known = 1;
+	retdevs[i].device_entry.vendor = mtp_device_table[j].vendor;
+	retdevs[i].device_entry.product = mtp_device_table[j].product;
+	retdevs[i].device_entry.device_flags = mtp_device_table[j].device_flags;
+
+#ifdef _AFT_BUILD
+    // Disable the following features for all devices.
+	retdevs[i].device_entry.device_flags |= DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST|
+                                            DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST|
+                                            DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST;
+#endif
+
+#ifdef ENABLE_USB_BULK_DEBUG
+	// This device is known to the developers
+	fprintf(stderr, "Device %d (VID=%04x and PID=%04x) is a %s %s.\n", 
+		i,
+		dev->libusb_device->descriptor.idVendor,
+		dev->libusb_device->descriptor.idProduct,
+		mtp_device_table[j].vendor,
+		mtp_device_table[j].product);
+#endif
+	break;
+      }
+    }
+    if (!device_known) {
+      // This device is unknown to the developers
+      fprintf(stderr, "Device %d (VID=%04x and PID=%04x) is UNKNOWN.\n", 
+	      i,
+	      dev->libusb_device->descriptor.idVendor,
+	      dev->libusb_device->descriptor.idProduct);
+      fprintf(stderr, "Please report this VID/PID and the device model to the "
+	      "libmtp development team\n");
+      /*
+       * Trying to get iManufacturer or iProduct from the device at this
+       * point would require opening a device handle, that we don't want
+       * to do right now. (Takes time for no good enough reason.)
+       */
+    }
+    // Save the location on the bus
+    retdevs[i].bus_location = dev->bus_location;
+    retdevs[i].devnum = dev->libusb_device->devnum;
+    i++;
+    dev = dev->next;
+  }  
+  *devices = retdevs;
+  *numdevs = i;
+  free_mtpdevice_list(devlist);
+  return LIBMTP_ERROR_NONE;
+}
+
+/**
+ * This routine just dumps out low-level
+ * USB information about the current device.
+ * @param ptp_usb the USB device to get information from.
+ */
+void dump_usbinfo(PTP_USB *ptp_usb)
+{
+  struct usb_device *dev;
+
+#ifdef LIBUSB_HAS_GET_DRIVER_NP
+  char devname[0x10];
+  int res;
+  
+  devname[0] = '\0';
+  res = usb_get_driver_np(ptp_usb->handle, (int) ptp_usb->interface, devname, sizeof(devname));
+  if (devname[0] != '\0') {
+    printf("   Using kernel interface \"%s\"\n", devname);
+  }
+#endif
+  dev = usb_device(ptp_usb->handle);
+  printf("   bcdUSB: %d\n", dev->descriptor.bcdUSB);
+  printf("   bDeviceClass: %d\n", dev->descriptor.bDeviceClass);
+  printf("   bDeviceSubClass: %d\n", dev->descriptor.bDeviceSubClass);
+  printf("   bDeviceProtocol: %d\n", dev->descriptor.bDeviceProtocol);
+  printf("   idVendor: %04x\n", dev->descriptor.idVendor);
+  printf("   idProduct: %04x\n", dev->descriptor.idProduct);
+  printf("   IN endpoint maxpacket: %d bytes\n", ptp_usb->inep_maxpacket);
+  printf("   OUT endpoint maxpacket: %d bytes\n", ptp_usb->outep_maxpacket);
+  printf("   Raw device info:\n");
+  printf("      Bus location: %d\n", ptp_usb->rawdevice.bus_location);
+  printf("      Device number: %d\n", ptp_usb->rawdevice.devnum);
+  printf("      Device entry info:\n");
+  printf("         Vendor: %s\n", ptp_usb->rawdevice.device_entry.vendor);
+  printf("         Vendor id: 0x%04x\n", ptp_usb->rawdevice.device_entry.vendor_id);
+  printf("         Product: %s\n", ptp_usb->rawdevice.device_entry.product);
+  printf("         Vendor id: 0x%04x\n", ptp_usb->rawdevice.device_entry.product_id);
+  printf("         Device flags: 0x%08x\n", ptp_usb->rawdevice.device_entry.device_flags);
+  (void) probe_device_descriptor(dev, stdout);
+}
+
+/**
+ * Retrieve the apropriate playlist extension for this
+ * device. Rather hacky at the moment. This is probably
+ * desired by the managing software, but when creating
+ * lists on the device itself you notice certain preferences.
+ * @param ptp_usb the USB device to get suggestion for.
+ * @return the suggested playlist extension.
+ */
+const char *get_playlist_extension(PTP_USB *ptp_usb)
+{
+  struct usb_device *dev;
+  static char creative_pl_extension[] = ".zpl";
+  static char default_pl_extension[] = ".pla";
+
+  dev = usb_device(ptp_usb->handle);
+  if (dev->descriptor.idVendor == 0x041e) {
+    return creative_pl_extension;
+  }
+  return default_pl_extension;
+}
+
+static void
+libusb_glue_debug (PTPParams *params, const char *format, ...)
+{  
+        va_list args;
+
+        va_start (args, format);
+        if (params->debug_func!=NULL)
+                params->debug_func (params->data, format, args);
+        else
+	{
+                vfprintf (stderr, format, args);
+		fprintf (stderr,"\n");
+		fflush (stderr);
+	}
+        va_end (args);
+}  
+
+static void
+libusb_glue_error (PTPParams *params, const char *format, ...)
+{  
+        va_list args;
+
+        va_start (args, format);
+        if (params->error_func!=NULL)
+                params->error_func (params->data, format, args);
+        else
+	{
+                vfprintf (stderr, format, args);
+		fprintf (stderr,"\n");
+		fflush (stderr);
+	}
+        va_end (args);
+}
+
+
+/*
+ * ptp_read_func() and ptp_write_func() are
+ * based on same functions usb.c in libgphoto2.
+ * Much reading packet logs and having fun with trials and errors
+ * reveals that WMP / Windows is probably using an algorithm like this
+ * for large transfers:
+ *
+ * 1. Send the command (0x0c bytes) if headers are split, else, send 
+ *    command plus sizeof(endpoint) - 0x0c bytes.
+ * 2. Send first packet, max size to be sizeof(endpoint) but only when using
+ *    split headers. Else goto 3.
+ * 3. REPEAT send 0x10000 byte chunks UNTIL remaining bytes < 0x10000
+ *    We call 0x10000 CONTEXT_BLOCK_SIZE.
+ * 4. Send remaining bytes MOD sizeof(endpoint)
+ * 5. Send remaining bytes. If this happens to be exactly sizeof(endpoint)
+ *    then also send a zero-length package.
+ *
+ * Further there is some special quirks to handle zero reads from the
+ * device, since some devices can't do them at all due to shortcomings
+ * of the USB slave controller in the device.
+ */
+#define CONTEXT_BLOCK_SIZE_1	0x3e00
+#define CONTEXT_BLOCK_SIZE_2  0x200
+#define CONTEXT_BLOCK_SIZE    CONTEXT_BLOCK_SIZE_1+CONTEXT_BLOCK_SIZE_2
+static short
+ptp_read_func (
+	unsigned long size, PTPDataHandler *handler,void *data,
+	unsigned long *readbytes,
+	int readzero
+) {
+  PTP_USB *ptp_usb = (PTP_USB *)data;
+  unsigned long toread = 0;
+  int result = 0;
+  unsigned long curread = 0;
+  unsigned long written;
+  unsigned char *bytes;
+  int expect_terminator_byte = 0;
+
+  // This is the largest block we'll need to read in.
+  bytes = malloc(CONTEXT_BLOCK_SIZE);
+  while (curread < size) {
+    
+#ifdef ENABLE_USB_BULK_DEBUG
+    printf("Remaining size to read: 0x%04lx bytes\n", size - curread);
+#endif
+    // check equal to condition here
+    if (size - curread < CONTEXT_BLOCK_SIZE)
+    {
+      // this is the last packet
+      toread = size - curread;
+      // this is equivalent to zero read for these devices
+      if (readzero && FLAG_NO_ZERO_READS(ptp_usb) && toread % 64 == 0) {
+        toread += 1;
+        expect_terminator_byte = 1;
+      }
+    }
+    else if (curread == 0)
+      // we are first packet, but not last packet
+      toread = CONTEXT_BLOCK_SIZE_1;
+    else if (toread == CONTEXT_BLOCK_SIZE_1)
+      toread = CONTEXT_BLOCK_SIZE_2;
+    else if (toread == CONTEXT_BLOCK_SIZE_2)
+      toread = CONTEXT_BLOCK_SIZE_1;
+    else
+      printf("unexpected toread size 0x%04x, 0x%04x remaining bytes\n", 
+	     (unsigned int) toread, (unsigned int) (size-curread));
+
+#ifdef ENABLE_USB_BULK_DEBUG
+    printf("Reading in 0x%04lx bytes\n", toread);
+#endif
+    result = USB_BULK_READ(ptp_usb->handle, ptp_usb->inep, (char*)bytes, toread, ptp_usb->timeout);
+#ifdef ENABLE_USB_BULK_DEBUG
+    printf("Result of read: 0x%04x\n", result);
+#endif
+        
+    if (result < 0) {
+      return PTP_ERROR_IO;
+    }
+#ifdef ENABLE_USB_BULK_DEBUG
+    printf("<==USB IN\n");
+    if (result == 0)
+      printf("Zero Read\n");
+    else if (result < 0) 
+      fprintf(stderr, "USB_BULK_READ result=%#x\n", result);
+    else 
+      data_dump_ascii (stdout,bytes,result,16);
+#endif
+    
+    // want to discard extra byte
+    if (expect_terminator_byte && result == toread)
+    {
+#ifdef ENABLE_USB_BULK_DEBUG
+      printf("<==USB IN\nDiscarding extra byte\n");
+#endif
+      result--;
+    }
+    
+    int putfunc_ret = handler->putfunc(NULL, handler->priv, result, bytes, &written);
+    if (putfunc_ret != PTP_RC_OK)
+      return putfunc_ret;
+    
+    ptp_usb->current_transfer_complete += result;
+    curread += result;
+
+    // Increase counters, call callback
+    if (ptp_usb->callback_active) {
+      if (ptp_usb->current_transfer_complete >= ptp_usb->current_transfer_total) {
+	// send last update and disable callback.
+	ptp_usb->current_transfer_complete = ptp_usb->current_transfer_total;
+	ptp_usb->callback_active = 0;
+      }
+      if (ptp_usb->current_transfer_callback != NULL) {
+	int ret;
+	ret = ptp_usb->current_transfer_callback(ptp_usb->current_transfer_complete,
+						 ptp_usb->current_transfer_total,
+						 ptp_usb->current_transfer_callback_data);
+	if (ret != 0) {
+	  return PTP_ERROR_CANCEL;
+	}
+      }
+    }  
+
+    if (result < toread) /* short reads are common */
+      break;
+  }
+  if (readbytes) *readbytes = curread;
+  free (bytes);
+  
+  // there might be a zero packet waiting for us...
+  if (readzero && 
+      !FLAG_NO_ZERO_READS(ptp_usb) && 
+      curread % ptp_usb->outep_maxpacket == 0) {
+    char temp;
+    int zeroresult = 0;
+
+#ifdef ENABLE_USB_BULK_DEBUG
+    printf("<==USB IN\n");
+    printf("Zero Read\n");
+#endif
+    zeroresult = USB_BULK_READ(ptp_usb->handle, ptp_usb->inep, &temp, 0, ptp_usb->timeout);
+    if (zeroresult != 0)
+      printf("LIBMTP panic: unable to read in zero packet, response 0x%04x", zeroresult);
+  }
+  
+  return PTP_RC_OK;
+}
+
+static short
+ptp_write_func (
+        unsigned long   size,
+        PTPDataHandler  *handler,
+        void            *data,
+        unsigned long   *written
+) {
+  PTP_USB *ptp_usb = (PTP_USB *)data;
+  unsigned long towrite = 0;
+  int result = 0;
+  unsigned long curwrite = 0;
+  unsigned char *bytes;
+
+  // This is the largest block we'll need to read in.  
+  bytes = malloc(CONTEXT_BLOCK_SIZE);
+  if (!bytes) {
+    return PTP_ERROR_IO;
+  }
+  while (curwrite < size) {
+    unsigned long usbwritten = 0;
+    towrite = size-curwrite;
+    if (towrite > CONTEXT_BLOCK_SIZE) {
+      towrite = CONTEXT_BLOCK_SIZE;
+    } else {
+      // This magic makes packets the same size that WMP send them.
+      if (towrite > ptp_usb->outep_maxpacket && towrite % ptp_usb->outep_maxpacket != 0) {
+        towrite -= towrite % ptp_usb->outep_maxpacket;
+      }
+    }
+    int getfunc_ret = handler->getfunc(NULL, handler->priv,towrite,bytes,&towrite);
+    if (getfunc_ret != PTP_RC_OK)
+      return getfunc_ret;
+    while (usbwritten < towrite) {
+	    result = USB_BULK_WRITE(ptp_usb->handle,ptp_usb->outep,((char*)bytes+usbwritten),towrite-usbwritten,ptp_usb->timeout);
+#ifdef ENABLE_USB_BULK_DEBUG
+	    printf("USB OUT==>\n");
+        if (result > 0) { 
+            data_dump_ascii (stdout,bytes+usbwritten,result,16);
+        } else {
+            fprintf(stderr, "USB_BULK_WRITE: result=%#x\n", result);
+        }
+#endif
+	    if (result < 0) {
+	      return PTP_ERROR_IO;
+	    }
+	    // check for result == 0 perhaps too.
+	    // Increase counters
+	    ptp_usb->current_transfer_complete += result;
+	    curwrite += result;
+	    usbwritten += result;
+    }
+    // call callback
+    if (ptp_usb->callback_active) {
+      if (ptp_usb->current_transfer_complete >= ptp_usb->current_transfer_total) {
+	// send last update and disable callback.
+	ptp_usb->current_transfer_complete = ptp_usb->current_transfer_total;
+	ptp_usb->callback_active = 0;
+      }
+      if (ptp_usb->current_transfer_callback != NULL) {
+	int ret;
+	ret = ptp_usb->current_transfer_callback(ptp_usb->current_transfer_complete,
+						 ptp_usb->current_transfer_total,
+						 ptp_usb->current_transfer_callback_data);
+	if (ret != 0) {
+	  return PTP_ERROR_CANCEL;
+	}
+      }
+    }
+    if (result < towrite) /* short writes happen */
+      break;
+  }
+  free (bytes);
+  if (written) {
+    *written = curwrite;
+  }
+  
+
+  // If this is the last transfer send a zero write if required
+  if (ptp_usb->current_transfer_complete >= ptp_usb->current_transfer_total) {
+    if ((towrite % ptp_usb->outep_maxpacket) == 0) {
+#ifdef ENABLE_USB_BULK_DEBUG
+      printf("USB OUT==>\n");
+      printf("Zero Write\n");
+#endif
+      result=USB_BULK_WRITE(ptp_usb->handle,ptp_usb->outep,(char *)"x",0,ptp_usb->timeout);
+    }
+  }
+    
+  if (result < 0)
+    return PTP_ERROR_IO;
+  return PTP_RC_OK;
+}
+
+/* memory data get/put handler */
+typedef struct {
+	unsigned char	*data;
+	unsigned long	size, curoff;
+} PTPMemHandlerPrivate;
+
+static uint16_t
+memory_getfunc(PTPParams* params, void* private,
+	       unsigned long wantlen, unsigned char *data,
+	       unsigned long *gotlen
+) {
+	PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)private;
+	unsigned long tocopy = wantlen;
+
+	if (priv->curoff + tocopy > priv->size)
+		tocopy = priv->size - priv->curoff;
+	memcpy (data, priv->data + priv->curoff, tocopy);
+	priv->curoff += tocopy;
+	*gotlen = tocopy;
+	return PTP_RC_OK;
+}
+
+static uint16_t
+memory_putfunc(PTPParams* params, void* private,
+	       unsigned long sendlen, unsigned char *data,
+	       unsigned long *putlen
+) {
+	PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)private;
+
+	if (priv->curoff + sendlen > priv->size) {
+		priv->data = realloc (priv->data, priv->curoff+sendlen);
+		priv->size = priv->curoff + sendlen;
+	}
+	memcpy (priv->data + priv->curoff, data, sendlen);
+	priv->curoff += sendlen;
+	*putlen = sendlen;
+	return PTP_RC_OK;
+}
+
+/* init private struct for receiving data. */
+static uint16_t
+ptp_init_recv_memory_handler(PTPDataHandler *handler) {
+	PTPMemHandlerPrivate* priv;
+	priv = malloc (sizeof(PTPMemHandlerPrivate));
+	handler->priv = priv;
+	handler->getfunc = memory_getfunc;
+	handler->putfunc = memory_putfunc;
+	priv->data = NULL;
+	priv->size = 0;
+	priv->curoff = 0;
+	return PTP_RC_OK;
+}
+
+/* init private struct and put data in for sending data.
+ * data is still owned by caller.
+ */
+static uint16_t
+ptp_init_send_memory_handler(PTPDataHandler *handler,
+	unsigned char *data, unsigned long len
+) {
+	PTPMemHandlerPrivate* priv;
+	priv = malloc (sizeof(PTPMemHandlerPrivate));
+	if (!priv)
+		return PTP_RC_GeneralError;
+	handler->priv = priv;
+	handler->getfunc = memory_getfunc;
+	handler->putfunc = memory_putfunc;
+	priv->data = data;
+	priv->size = len;
+	priv->curoff = 0;
+	return PTP_RC_OK;
+}
+
+/* free private struct + data */
+static uint16_t
+ptp_exit_send_memory_handler (PTPDataHandler *handler) {
+	PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)handler->priv;
+	/* data is owned by caller */
+	free (priv);
+	return PTP_RC_OK;
+}
+
+/* hand over our internal data to caller */
+static uint16_t
+ptp_exit_recv_memory_handler (PTPDataHandler *handler,
+	unsigned char **data, unsigned long *size
+) {
+	PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)handler->priv;
+	*data = priv->data;
+	*size = priv->size;
+	free (priv);
+	return PTP_RC_OK;
+}
+
+/* send / receive functions */
+
+uint16_t
+ptp_usb_sendreq (PTPParams* params, PTPContainer* req)
+{
+	uint16_t ret;
+	PTPUSBBulkContainer usbreq;
+	PTPDataHandler	memhandler;
+	unsigned long written = 0;
+	unsigned long towrite;
+#ifdef ENABLE_USB_BULK_DEBUG
+	char txt[256];
+
+	(void) ptp_render_opcode (params, req->Code, sizeof(txt), txt);
+	printf("REQUEST: 0x%04x, %s\n", req->Code, txt);
+#endif
+	/* build appropriate USB container */
+	usbreq.length=htod32(PTP_USB_BULK_REQ_LEN-
+		(sizeof(uint32_t)*(5-req->Nparam)));
+	usbreq.type=htod16(PTP_USB_CONTAINER_COMMAND);
+	usbreq.code=htod16(req->Code);
+	usbreq.trans_id=htod32(req->Transaction_ID);
+	usbreq.payload.params.param1=htod32(req->Param1);
+	usbreq.payload.params.param2=htod32(req->Param2);
+	usbreq.payload.params.param3=htod32(req->Param3);
+	usbreq.payload.params.param4=htod32(req->Param4);
+	usbreq.payload.params.param5=htod32(req->Param5);
+	/* send it to responder */
+	towrite = PTP_USB_BULK_REQ_LEN-(sizeof(uint32_t)*(5-req->Nparam));
+	ptp_init_send_memory_handler (&memhandler, (unsigned char*)&usbreq, towrite);
+	ret=ptp_write_func(
+		towrite,
+		&memhandler,
+		params->data,
+		&written
+	);
+	ptp_exit_send_memory_handler (&memhandler);
+	if (ret!=PTP_RC_OK && ret!=PTP_ERROR_CANCEL) {
+		ret = PTP_ERROR_IO;
+	}
+	if (written != towrite && ret != PTP_ERROR_CANCEL && ret != PTP_ERROR_IO) {
+		libusb_glue_error (params, 
+			"PTP: request code 0x%04x sending req wrote only %ld bytes instead of %d",
+			req->Code, written, towrite
+		);
+		ret = PTP_ERROR_IO;
+	}
+	return ret;
+}
+
+uint16_t
+ptp_usb_senddata (PTPParams* params, PTPContainer* ptp,
+		  unsigned long size, PTPDataHandler *handler
+) {
+	uint16_t ret;
+	int wlen, datawlen;
+	unsigned long written;
+	PTPUSBBulkContainer usbdata;
+	uint32_t bytes_left_to_transfer;
+	PTPDataHandler memhandler;
+
+#ifdef ENABLE_USB_BULK_DEBUG
+	printf("SEND DATA PHASE\n");
+#endif
+	/* build appropriate USB container */
+	usbdata.length	= htod32(PTP_USB_BULK_HDR_LEN+size);
+	usbdata.type	= htod16(PTP_USB_CONTAINER_DATA);
+	usbdata.code	= htod16(ptp->Code);
+	usbdata.trans_id= htod32(ptp->Transaction_ID);
+  
+	((PTP_USB*)params->data)->current_transfer_complete = 0;
+	((PTP_USB*)params->data)->current_transfer_total = size+PTP_USB_BULK_HDR_LEN;
+
+	if (params->split_header_data) {
+		datawlen = 0;
+		wlen = PTP_USB_BULK_HDR_LEN;
+	} else {
+		unsigned long gotlen;
+		/* For all camera devices. */
+		datawlen = (size<PTP_USB_BULK_PAYLOAD_LEN_WRITE)?size:PTP_USB_BULK_PAYLOAD_LEN_WRITE;
+		wlen = PTP_USB_BULK_HDR_LEN + datawlen;
+    
+		ret = handler->getfunc(params, handler->priv, datawlen, usbdata.payload.data, &gotlen);
+		if (ret != PTP_RC_OK)
+			return ret;
+		if (gotlen != datawlen)
+			return PTP_RC_GeneralError;
+	}
+	ptp_init_send_memory_handler (&memhandler, (unsigned char *)&usbdata, wlen);
+	/* send first part of data */
+	ret = ptp_write_func(wlen, &memhandler, params->data, &written);
+	ptp_exit_send_memory_handler (&memhandler);
+	if (ret!=PTP_RC_OK) {
+		return ret;
+	}
+	if (size <= datawlen) return ret;
+	/* if everything OK send the rest */
+	bytes_left_to_transfer = size-datawlen;
+	ret = PTP_RC_OK;
+	while(bytes_left_to_transfer > 0) {
+		ret = ptp_write_func (bytes_left_to_transfer, handler, params->data, &written);
+		if (ret != PTP_RC_OK)
+			break;
+		if (written == 0) {
+			ret = PTP_ERROR_IO;
+			break;
+		}
+		bytes_left_to_transfer -= written;
+	}
+	if (ret!=PTP_RC_OK && ret!=PTP_ERROR_CANCEL)
+		ret = PTP_ERROR_IO;
+	return ret;
+}
+
+static uint16_t ptp_usb_getpacket(PTPParams *params,
+		PTPUSBBulkContainer *packet, unsigned long *rlen)
+{
+	PTPDataHandler	memhandler;
+	uint16_t	ret;
+	unsigned char	*x = NULL;
+
+	/* read the header and potentially the first data */
+	if (params->response_packet_size > 0) {
+		/* If there is a buffered packet, just use it. */
+		memcpy(packet, params->response_packet, params->response_packet_size);
+		*rlen = params->response_packet_size;
+		free(params->response_packet);
+		params->response_packet = NULL;
+		params->response_packet_size = 0;
+		/* Here this signifies a "virtual read" */
+		return PTP_RC_OK;
+	}
+	ptp_init_recv_memory_handler (&memhandler);
+	ret = ptp_read_func(PTP_USB_BULK_HS_MAX_PACKET_LEN_READ, &memhandler, params->data, rlen, 0);
+	ptp_exit_recv_memory_handler (&memhandler, &x, rlen);
+	if (x) {
+		memcpy (packet, x, *rlen);
+		free (x);
+	}
+	return ret;
+}
+
+uint16_t
+ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
+{
+	uint16_t ret;
+	PTPUSBBulkContainer usbdata;
+	unsigned long	written;
+	PTP_USB *ptp_usb = (PTP_USB *) params->data;
+
+#ifdef ENABLE_USB_BULK_DEBUG
+	printf("GET DATA PHASE\n");
+#endif
+	memset(&usbdata,0,sizeof(usbdata));
+	do {
+		unsigned long len, rlen;
+
+		ret = ptp_usb_getpacket(params, &usbdata, &rlen);
+		if (ret!=PTP_RC_OK) {
+			ret = PTP_ERROR_IO;
+			break;
+		}
+		if (dtoh16(usbdata.type)!=PTP_USB_CONTAINER_DATA) {
+			ret = PTP_ERROR_DATA_EXPECTED;
+			break;
+		}
+		if (dtoh16(usbdata.code)!=ptp->Code) {
+			if (FLAG_IGNORE_HEADER_ERRORS(ptp_usb)) {
+				libusb_glue_debug (params, "ptp2/ptp_usb_getdata: detected a broken "
+					   "PTP header, code field insane, expect problems! (But continuing)");
+				// Repair the header, so it won't wreak more havoc, don't just ignore it.
+				// Typically these two fields will be broken.
+				usbdata.code	 = htod16(ptp->Code);
+				usbdata.trans_id = htod32(ptp->Transaction_ID);
+				ret = PTP_RC_OK;
+			} else {
+				ret = dtoh16(usbdata.code);
+				// This filters entirely insane garbage return codes, but still
+				// makes it possible to return error codes in the code field when
+				// getting data. It appears Windows ignores the contents of this 
+				// field entirely.
+				if (ret < PTP_RC_Undefined || ret > PTP_RC_SpecificationOfDestinationUnsupported) {
+					libusb_glue_debug (params, "ptp2/ptp_usb_getdata: detected a broken "
+						   "PTP header, code field insane.");
+					ret = PTP_ERROR_IO;
+				}
+				break;
+			}
+		}
+		if (usbdata.length == 0xffffffffU) {
+			/* Copy first part of data to 'data' */
+      int putfunc_ret = 
+			handler->putfunc(
+				params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, usbdata.payload.data,
+				&written
+			);
+      if (putfunc_ret != PTP_RC_OK)
+        return putfunc_ret;
+			/* stuff data directly to passed data handler */
+			while (1) {
+				unsigned long readdata;
+				uint16_t xret;
+
+				xret = ptp_read_func(
+					PTP_USB_BULK_HS_MAX_PACKET_LEN_READ,
+					handler,
+					params->data,
+					&readdata,
+					0
+				);
+				if (xret != PTP_RC_OK)
+					return xret;
+				if (readdata < PTP_USB_BULK_HS_MAX_PACKET_LEN_READ)
+					break;
+			}
+			return PTP_RC_OK;
+		}
+		if (rlen > dtoh32(usbdata.length)) {
+			/*
+			 * Buffer the surplus response packet if it is >=
+			 * PTP_USB_BULK_HDR_LEN
+			 * (i.e. it is probably an entire package)
+			 * else discard it as erroneous surplus data.
+			 * This will even work if more than 2 packets appear
+			 * in the same transaction, they will just be handled
+			 * iteratively.
+			 *
+			 * Marcus observed stray bytes on iRiver devices;
+			 * these are still discarded.
+			 */
+			unsigned int packlen = dtoh32(usbdata.length);
+			unsigned int surplen = rlen - packlen;
+
+			if (surplen >= PTP_USB_BULK_HDR_LEN) {
+				params->response_packet = malloc(surplen);
+				memcpy(params->response_packet,
+				       (uint8_t *) &usbdata + packlen, surplen);
+				params->response_packet_size = surplen;
+			/* Ignore reading one extra byte if device flags have been set */
+			} else if(!FLAG_NO_ZERO_READS(ptp_usb) &&
+				  (rlen - dtoh32(usbdata.length) == 1)) {
+			  libusb_glue_debug (params, "ptp2/ptp_usb_getdata: read %d bytes "
+				     "too much, expect problems!", 
+				     rlen - dtoh32(usbdata.length));
+			}
+			rlen = packlen;
+		}
+
+		/* For most PTP devices rlen is 512 == sizeof(usbdata)
+		 * here. For MTP devices splitting header and data it might
+		 * be 12.
+		 */
+		/* Evaluate full data length. */
+		len=dtoh32(usbdata.length)-PTP_USB_BULK_HDR_LEN;
+
+		/* autodetect split header/data MTP devices */
+		if (dtoh32(usbdata.length) > 12 && (rlen==12))
+			params->split_header_data = 1;
+
+		/* Copy first part of data to 'data' */
+    int putfunc_ret = 
+		handler->putfunc(
+			params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, usbdata.payload.data,
+			&written
+		);
+    if (putfunc_ret != PTP_RC_OK)
+      return putfunc_ret;
+
+		if (FLAG_NO_ZERO_READS(ptp_usb) &&
+		    len+PTP_USB_BULK_HDR_LEN == PTP_USB_BULK_HS_MAX_PACKET_LEN_READ) {
+#ifdef ENABLE_USB_BULK_DEBUG
+		  printf("Reading in extra terminating byte\n");
+#endif
+		  // need to read in extra byte and discard it
+		  int result = 0;
+		  char byte = 0;
+                  result = USB_BULK_READ(ptp_usb->handle, ptp_usb->inep, &byte, 1, ptp_usb->timeout);
+
+		  if (result != 1)
+		    printf("Could not read in extra byte for PTP_USB_BULK_HS_MAX_PACKET_LEN_READ long file, return value 0x%04x\n", result);
+		} else if (len+PTP_USB_BULK_HDR_LEN == PTP_USB_BULK_HS_MAX_PACKET_LEN_READ && params->split_header_data == 0) {
+		  int zeroresult = 0;
+		  char zerobyte = 0;
+
+#ifdef ENABLE_USB_BULK_DEBUG
+		  printf("Reading in zero packet after header\n");
+#endif
+                  zeroresult = USB_BULK_READ(ptp_usb->handle, ptp_usb->inep, &zerobyte, 0, ptp_usb->timeout);
+		  
+		  if (zeroresult != 0)
+		    printf("LIBMTP panic: unable to read in zero packet, response 0x%04x", zeroresult);
+		}
+		
+		/* Is that all of data? */
+		if (len+PTP_USB_BULK_HDR_LEN<=rlen) {
+		  break;
+		}
+		
+		ret = ptp_read_func(len - (rlen - PTP_USB_BULK_HDR_LEN),
+				    handler,
+				    params->data, &rlen, 1);
+		
+		if (ret!=PTP_RC_OK) {
+		  break;
+		}
+	} while (0);
+	return ret;
+}
+
+uint16_t
+ptp_usb_getresp (PTPParams* params, PTPContainer* resp)
+{
+	uint16_t ret;
+	unsigned long rlen;
+	PTPUSBBulkContainer usbresp;
+	PTP_USB *ptp_usb = (PTP_USB *)(params->data);
+
+#ifdef ENABLE_USB_BULK_DEBUG
+	printf("RESPONSE: ");
+#endif
+	memset(&usbresp,0,sizeof(usbresp));
+	/* read response, it should never be longer than sizeof(usbresp) */
+	ret = ptp_usb_getpacket(params, &usbresp, &rlen);
+
+	// Fix for bevahiour reported by Scott Snyder on Samsung YP-U3. The player
+	// sends a packet containing just zeroes of length 2 (up to 4 has been seen too)
+	// after a NULL packet when it should send the response. This code ignores
+	// such illegal packets.
+	while (ret==PTP_RC_OK && rlen<PTP_USB_BULK_HDR_LEN && usbresp.length==0) {
+	  libusb_glue_debug (params, "ptp_usb_getresp: detected short response "
+		     "of %d bytes, expect problems! (re-reading "
+		     "response), rlen");
+	  ret = ptp_usb_getpacket(params, &usbresp, &rlen);
+	}
+
+	if (ret!=PTP_RC_OK) {
+		ret = PTP_ERROR_IO;
+	} else
+	if (dtoh16(usbresp.type)!=PTP_USB_CONTAINER_RESPONSE) {
+		ret = PTP_ERROR_RESP_EXPECTED;
+	} else
+	if (dtoh16(usbresp.code)!=resp->Code) {
+		ret = dtoh16(usbresp.code);
+	}
+#ifdef ENABLE_USB_BULK_DEBUG
+	printf("%04x\n", ret);
+#endif
+	if (ret!=PTP_RC_OK) {
+/*		libusb_glue_error (params,
+		"PTP: request code 0x%04x getting resp error 0x%04x",
+			resp->Code, ret);*/
+		return ret;
+	}
+	/* build an appropriate PTPContainer */
+	resp->Code=dtoh16(usbresp.code);
+	resp->SessionID=params->session_id;
+	resp->Transaction_ID=dtoh32(usbresp.trans_id);
+	if (FLAG_IGNORE_HEADER_ERRORS(ptp_usb)) {
+		if (resp->Transaction_ID != params->transaction_id-1) {
+			libusb_glue_debug (params, "ptp_usb_getresp: detected a broken "
+				   "PTP header, transaction ID insane, expect "
+				   "problems! (But continuing)");
+			// Repair the header, so it won't wreak more havoc.
+			resp->Transaction_ID = params->transaction_id-1;
+		}
+	}
+	resp->Param1=dtoh32(usbresp.payload.params.param1);
+	resp->Param2=dtoh32(usbresp.payload.params.param2);
+	resp->Param3=dtoh32(usbresp.payload.params.param3);
+	resp->Param4=dtoh32(usbresp.payload.params.param4);
+	resp->Param5=dtoh32(usbresp.payload.params.param5);
+	return ret;
+}
+
+/* Event handling functions */
+
+/* PTP Events wait for or check mode */
+#define PTP_EVENT_CHECK			0x0000	/* waits for */
+#define PTP_EVENT_CHECK_FAST		0x0001	/* checks */
+
+static inline uint16_t
+ptp_usb_event (PTPParams* params, PTPContainer* event, int wait)
+{
+	uint16_t ret;
+	int result;
+	unsigned long rlen;
+	PTPUSBEventContainer usbevent;
+	PTP_USB *ptp_usb = (PTP_USB *)(params->data);
+
+	memset(&usbevent,0,sizeof(usbevent));
+
+	if ((params==NULL) || (event==NULL)) 
+		return PTP_ERROR_BADPARAM;
+	ret = PTP_RC_OK;
+	switch(wait) {
+	case PTP_EVENT_CHECK:
+                result=USB_BULK_READ(ptp_usb->handle, ptp_usb->intep,(char *)&usbevent,sizeof(usbevent),ptp_usb->timeout);
+		if (result==0)
+                        result = USB_BULK_READ(ptp_usb->handle, ptp_usb->intep,(char *) &usbevent, sizeof(usbevent), ptp_usb->timeout);
+		if (result < 0) ret = PTP_ERROR_IO;
+		break;
+	case PTP_EVENT_CHECK_FAST:
+                result=USB_BULK_READ(ptp_usb->handle, ptp_usb->intep,(char *)&usbevent,sizeof(usbevent),ptp_usb->timeout);
+		if (result==0)
+                        result = USB_BULK_READ(ptp_usb->handle, ptp_usb->intep,(char *) &usbevent, sizeof(usbevent), ptp_usb->timeout);
+		if (result < 0) ret = PTP_ERROR_IO;
+		break;
+	default:
+		ret=PTP_ERROR_BADPARAM;
+		break;
+	}
+	if (ret!=PTP_RC_OK) {
+		libusb_glue_error (params,
+			"PTP: reading event an error 0x%04x occurred", ret);
+		return PTP_ERROR_IO;
+	}
+	rlen = result;
+	if (rlen < 8) {
+		libusb_glue_error (params,
+			"PTP: reading event an short read of %ld bytes occurred", rlen);
+		return PTP_ERROR_IO;
+	}
+	/* if we read anything over interrupt endpoint it must be an event */
+	/* build an appropriate PTPContainer */
+	event->Code=dtoh16(usbevent.code);
+	event->SessionID=params->session_id;
+	event->Transaction_ID=dtoh32(usbevent.trans_id);
+	event->Param1=dtoh32(usbevent.param1);
+	event->Param2=dtoh32(usbevent.param2);
+	event->Param3=dtoh32(usbevent.param3);
+	return ret;
+}
+
+uint16_t
+ptp_usb_event_check (PTPParams* params, PTPContainer* event) {
+
+	return ptp_usb_event (params, event, PTP_EVENT_CHECK_FAST);
+}
+
+uint16_t
+ptp_usb_event_wait (PTPParams* params, PTPContainer* event) {
+
+	return ptp_usb_event (params, event, PTP_EVENT_CHECK);
+}
+
+uint16_t
+ptp_usb_control_cancel_request (PTPParams *params, uint32_t transactionid) {
+	PTP_USB *ptp_usb = (PTP_USB *)(params->data);
+	int ret;
+	unsigned char buffer[6];
+
+	htod16a(&buffer[0],PTP_EC_CancelTransaction);
+	htod32a(&buffer[2],transactionid);
+	ret = usb_control_msg(ptp_usb->handle, 
+			      USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+                              0x64, 0x0000, 0x0000, (char *) buffer, sizeof(buffer), ptp_usb->timeout);
+	if (ret < sizeof(buffer))
+		return PTP_ERROR_IO;
+	return PTP_RC_OK;
+}
+
+static int init_ptp_usb (PTPParams* params, PTP_USB* ptp_usb, struct usb_device* dev)
+{
+  usb_dev_handle *device_handle;
+  
+  params->sendreq_func=ptp_usb_sendreq;
+  params->senddata_func=ptp_usb_senddata;
+  params->getresp_func=ptp_usb_getresp;
+  params->getdata_func=ptp_usb_getdata;
+  params->cancelreq_func=ptp_usb_control_cancel_request;
+  params->data=ptp_usb;
+  params->transaction_id=0;
+  /*
+   * This is hardcoded here since we have no devices whatsoever that are BE.
+   * Change this the day we run into our first BE device (if ever).
+   */
+  params->byteorder = PTP_DL_LE;
+  
+  ptp_usb->timeout = USB_TIMEOUT_DEFAULT;
+  
+  device_handle = usb_open(dev);
+  if (!device_handle) {
+    perror("usb_open()");
+    return -1;
+  }
+
+  ptp_usb->handle = device_handle;
+#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
+  /*
+  * If this device is known to be wrongfully claimed by other kernel
+  * drivers (such as mass storage), then try to unload it to make it
+  * accessible from user space.
+  */
+  if (FLAG_UNLOAD_DRIVER(ptp_usb)) {
+    if (usb_detach_kernel_driver_np(device_handle, (int) ptp_usb->interface)) {
+	  // Totally ignore this error!
+	  // perror("usb_detach_kernel_driver_np()");
+    }
+  }
+#endif
+#ifdef __WIN32__
+  // Only needed on Windows, and cause problems on other platforms.
+  if (usb_set_configuration(device_handle, dev->config->bConfigurationValue)) {
+    perror("usb_set_configuration()");
+    return -1;
+  }
+#endif
+  if (usb_claim_interface(device_handle, (int) ptp_usb->interface)) {
+    perror("usb_claim_interface()");
+    return -1;
+  }
+
+  return 0;
+}
+
+static void clear_stall(PTP_USB* ptp_usb)
+{
+  uint16_t status;
+  int ret;
+  
+  /* check the inep status */
+  status = 0;
+  ret = usb_get_endpoint_status(ptp_usb,ptp_usb->inep,&status);
+  if (ret<0) {
+    perror ("inep: usb_get_endpoint_status()");
+  } else if (status) {
+    printf("Clearing stall on IN endpoint\n");
+    ret = usb_clear_stall_feature(ptp_usb,ptp_usb->inep);
+    if (ret<0) {
+      perror ("usb_clear_stall_feature()");
+    }
+  }
+  
+  /* check the outep status */
+  status=0;
+  ret = usb_get_endpoint_status(ptp_usb,ptp_usb->outep,&status);
+  if (ret<0) {
+    perror("outep: usb_get_endpoint_status()");
+  } else if (status) {
+    printf("Clearing stall on OUT endpoint\n");
+    ret = usb_clear_stall_feature(ptp_usb,ptp_usb->outep);
+    if (ret<0) {
+      perror("usb_clear_stall_feature()");
+    }
+  }
+
+  /* TODO: do we need this for INTERRUPT (ptp_usb->intep) too? */
+}
+
+static void clear_halt(PTP_USB* ptp_usb)
+{
+  int ret;
+
+  ret = usb_clear_halt(ptp_usb->handle,ptp_usb->inep);
+  if (ret<0) {
+    perror("usb_clear_halt() on IN endpoint");
+  }
+  ret = usb_clear_halt(ptp_usb->handle,ptp_usb->outep);
+  if (ret<0) {
+    perror("usb_clear_halt() on OUT endpoint");
+  }
+  ret = usb_clear_halt(ptp_usb->handle,ptp_usb->intep);
+  if (ret<0) {
+    perror("usb_clear_halt() on INTERRUPT endpoint");
+  }
+}
+
+static void close_usb(PTP_USB* ptp_usb)
+{
+  // Commented out since it was confusing some
+  // devices to do these things.
+  if (!FLAG_NO_RELEASE_INTERFACE(ptp_usb)) {
+
+    /*
+     * Clear any stalled endpoints
+     * On misbehaving devices designed for Windows/Mac, quote from:
+     * http://www2.one-eyed-alien.net/~mdharm/linux-usb/target_offenses.txt
+     * Device does Bad Things(tm) when it gets a GET_STATUS after CLEAR_HALT
+     * (...) Windows, when clearing a stall, only sends the CLEAR_HALT command, 
+     * and presumes that the stall has cleared.  Some devices actually choke 
+     * if the CLEAR_HALT is followed by a GET_STATUS (used to determine if the 
+     * STALL is persistant or not).
+     */
+    clear_stall(ptp_usb);
+    // Clear halts on any endpoints
+    clear_halt(ptp_usb);
+    // Added to clear some stuff on the OUT endpoint
+    // TODO: is this good on the Mac too?
+    // HINT: some devices may need that you comment these two out too.
+    usb_resetep(ptp_usb->handle, ptp_usb->outep);
+    usb_release_interface(ptp_usb->handle, (int) ptp_usb->interface);
+  }
+
+  usb_close(ptp_usb->handle);
+}
+
+/**
+ * Self-explanatory?
+ */
+static void find_interface_and_endpoints(struct usb_device *dev, 
+					 uint8_t *interface,
+					 int* inep, 
+					 int* inep_maxpacket, 
+					 int* outep, 
+					 int *outep_maxpacket, 
+					 int* intep)
+{
+  int i;
+
+  // Loop over the device configurations
+  for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
+    uint8_t j;
+
+    for (j = 0; j < dev->config[i].bNumInterfaces; j++) {
+      uint8_t k;
+      uint8_t no_ep;
+      struct usb_endpoint_descriptor *ep;
+      
+      if (dev->descriptor.bNumConfigurations > 1 || dev->config[i].bNumInterfaces > 1) {
+	// OK This device has more than one interface, so we have to find out
+	// which one to use! 
+	// FIXME: Probe the interface.
+	// FIXME: Release modules attached to all other interfaces in Linux...?
+      }
+
+      *interface = dev->config[i].interface[j].altsetting->bInterfaceNumber;
+      ep = dev->config[i].interface[j].altsetting->endpoint;
+      no_ep = dev->config[i].interface[j].altsetting->bNumEndpoints;
+      
+      for (k = 0; k < no_ep; k++) {
+	if (ep[k].bmAttributes==USB_ENDPOINT_TYPE_BULK)	{
+	  if ((ep[k].bEndpointAddress&USB_ENDPOINT_DIR_MASK)==
+	      USB_ENDPOINT_DIR_MASK)
+	    {
+	      *inep=ep[k].bEndpointAddress;
+	      *inep_maxpacket=ep[k].wMaxPacketSize;
+	    }
+	  if ((ep[k].bEndpointAddress&USB_ENDPOINT_DIR_MASK)==0)
+	    {
+	      *outep=ep[k].bEndpointAddress;
+	      *outep_maxpacket=ep[k].wMaxPacketSize;
+	    }
+	} else if (ep[k].bmAttributes==USB_ENDPOINT_TYPE_INTERRUPT){
+	  if ((ep[k].bEndpointAddress&USB_ENDPOINT_DIR_MASK)==
+	      USB_ENDPOINT_DIR_MASK)
+	    {
+	      *intep=ep[k].bEndpointAddress;
+	    }
+	}
+      }
+      // We assigned the endpoints so return here.
+      return;
+    }
+  }
+}
+
+/**
+ * This function assigns params and usbinfo given a raw device
+ * as input.
+ * @param device the device to be assigned.
+ * @param usbinfo a pointer to the new usbinfo.
+ * @return an error code.
+ */
+LIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device, 
+					   PTPParams *params,
+					   void **usbinfo)
+{
+  PTP_USB *ptp_usb;
+  struct usb_device *libusb_device;
+  uint16_t ret = 0;
+  struct usb_bus *bus;
+  int found = 0;
+
+  /* See if we can find this raw device again... */
+  bus = init_usb();
+  for (; bus != NULL; bus = bus->next) {
+    if (bus->location == device->bus_location) {
+      struct usb_device *dev = bus->devices;
+
+      for (; dev != NULL; dev = dev->next) {
+	if(dev->devnum == device->devnum &&
+	   dev->descriptor.idVendor == device->device_entry.vendor_id &&
+	   dev->descriptor.idProduct == device->device_entry.product_id ) {
+	  libusb_device = dev;
+	  found = 1;
+	  break;
+	}
+      }
+      if (found)
+	break;
+    }
+  }
+  /* Device has gone since detecting raw devices! */
+  if (!found) {
+    return LIBMTP_ERROR_NO_DEVICE_ATTACHED;
+  }
+
+  /* Allocate structs */
+  ptp_usb = (PTP_USB *) malloc(sizeof(PTP_USB));
+  if (ptp_usb == NULL) {
+    return LIBMTP_ERROR_MEMORY_ALLOCATION;
+  }
+  /* Start with a blank slate (includes setting device_flags to 0) */
+  memset(ptp_usb, 0, sizeof(PTP_USB));
+
+  /* Copy the raw device */
+  memcpy(&ptp_usb->rawdevice, device, sizeof(LIBMTP_raw_device_t));
+
+  /*
+   * Some devices must have their "OS Descriptor" massaged in order
+   * to work.
+   */
+  if (FLAG_ALWAYS_PROBE_DESCRIPTOR(ptp_usb)) {
+    // Massage the device descriptor
+    (void) probe_device_descriptor(libusb_device, NULL);
+  }
+  
+
+  /* Assign endpoints to usbinfo... */
+  find_interface_and_endpoints(libusb_device,
+		   &ptp_usb->interface,
+		   &ptp_usb->inep,
+		   &ptp_usb->inep_maxpacket,
+		   &ptp_usb->outep,
+		   &ptp_usb->outep_maxpacket,
+		   &ptp_usb->intep);
+    
+  /* Attempt to initialize this device */
+  if (init_ptp_usb(params, ptp_usb, libusb_device) < 0) {
+    fprintf(stderr, "LIBMTP PANIC: Unable to initialize device\n");
+    return LIBMTP_ERROR_CONNECTING;
+  }
+  
+  /*
+   * This works in situations where previous bad applications
+   * have not used LIBMTP_Release_Device on exit 
+   */
+  if ((ret = ptp_opensession(params, 1)) == PTP_ERROR_IO) {
+    fprintf(stderr, "PTP_ERROR_IO: Trying again after re-initializing USB interface\n");
+    close_usb(ptp_usb);
+      
+    if(init_ptp_usb(params, ptp_usb, libusb_device) <0) {
+      fprintf(stderr, "LIBMTP PANIC: Could not open session on device\n");
+      return LIBMTP_ERROR_CONNECTING;
+    }
+    
+    /* Device has been reset, try again */
+    ret = ptp_opensession(params, 1);
+  }
+  
+  /* Was the transaction id invalid? Try again */
+  if (ret == PTP_RC_InvalidTransactionID) {
+    fprintf(stderr, "LIBMTP WARNING: Transaction ID was invalid, increment and try again\n");
+    params->transaction_id += 10;
+    ret = ptp_opensession(params, 1);
+  }
+
+  if (ret != PTP_RC_SessionAlreadyOpened && ret != PTP_RC_OK) {
+    fprintf(stderr, "LIBMTP PANIC: Could not open session! "
+	    "(Return code %d)\n  Try to reset the device.\n",
+	    ret);
+    usb_release_interface(ptp_usb->handle,
+			  (int) ptp_usb->interface);
+    return LIBMTP_ERROR_CONNECTING;
+  }
+
+  /* OK configured properly */
+  *usbinfo = (void *) ptp_usb;
+  return LIBMTP_ERROR_NONE;
+}
+
+
+void close_device (PTP_USB *ptp_usb, PTPParams *params)
+{
+  if (ptp_closesession(params)!=PTP_RC_OK)
+    fprintf(stderr,"ERROR: Could not close session!\n");
+  close_usb(ptp_usb);
+}
+
+void set_usb_device_timeout(PTP_USB *ptp_usb, int timeout)
+{
+    ptp_usb->timeout = timeout;
+}
+
+void get_usb_device_timeout(PTP_USB *ptp_usb, int *timeout)
+{
+    *timeout = ptp_usb->timeout;
+}
+
+static int usb_clear_stall_feature(PTP_USB* ptp_usb, int ep)
+{
+  
+  return (usb_control_msg(ptp_usb->handle,
+			  USB_RECIP_ENDPOINT, USB_REQ_CLEAR_FEATURE, USB_FEATURE_HALT,
+                          ep, NULL, 0, ptp_usb->timeout));
+}
+
+static int usb_get_endpoint_status(PTP_USB* ptp_usb, int ep, uint16_t* status)
+{
+  return (usb_control_msg(ptp_usb->handle,
+			  USB_DP_DTH|USB_RECIP_ENDPOINT, USB_REQ_GET_STATUS,
+                          USB_FEATURE_HALT, ep, (char *)status, 2, ptp_usb->timeout));
+}
diff --git a/src/libusb-glue.h b/src/libusb-glue.h
new file mode 100644
index 0000000..c68677e
--- /dev/null
+++ b/src/libusb-glue.h
@@ -0,0 +1,129 @@
+/**
+ * \file libusb-glue.h
+ * Low-level USB interface glue towards libusb.
+ *
+ * Copyright (C) 2005-2007 Richard A. Low <richard@wentnet.com>
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006-2007 Marcus Meissner
+ * Copyright (C) 2007 Ted Bullock
+ * Copyright (C) 2008 Chris Bagwell <chris@cnpbagwell.com>
+ *
+ * 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.
+ *
+ * Created by Richard Low on 24/12/2005.
+ * Modified by Linus Walleij
+ *
+ */
+#ifndef LIBUSB_GLUE_H
+#define LIBUSB_GLUE_H
+
+#include "ptp.h"
+#include <usb.h>
+#include "libmtp.h"
+#include "device-flags.h"
+
+/* Make functions available for C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define USB_BULK_READ usb_bulk_read
+#define USB_BULK_WRITE usb_bulk_write
+
+/**
+ * Internal USB struct.
+ */
+typedef struct _PTP_USB PTP_USB;
+struct _PTP_USB {
+  PTPParams *params;
+  usb_dev_handle* handle;
+  uint8_t interface;
+  int inep;
+  int inep_maxpacket;
+  int outep;
+  int outep_maxpacket;
+  int intep;
+  int timeout;
+  /** File transfer callbacks and counters */
+  int callback_active;
+  uint64_t current_transfer_total;
+  uint64_t current_transfer_complete;
+  LIBMTP_progressfunc_t current_transfer_callback;
+  void const * current_transfer_callback_data;
+  /** Any special device flags, only used internally */
+  LIBMTP_raw_device_t rawdevice;
+};
+
+int open_device (int busn, int devn, short force, PTP_USB *ptp_usb, PTPParams *params, struct usb_device **dev);
+void dump_usbinfo(PTP_USB *ptp_usb);
+const char *get_playlist_extension(PTP_USB *ptp_usb);
+void close_device(PTP_USB *ptp_usb, PTPParams *params);
+LIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device, 
+					   PTPParams *params,
+					   void **usbinfo);
+void set_usb_device_timeout(PTP_USB *ptp_usb, int timeout);
+void get_usb_device_timeout(PTP_USB *ptp_usb, int *timeout);
+
+/* Flag check macros */
+#define FLAG_BROKEN_MTPGETOBJPROPLIST_ALL(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL)
+#define FLAG_UNLOAD_DRIVER(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNLOAD_DRIVER)
+#define FLAG_BROKEN_MTPGETOBJPROPLIST(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST)
+#define FLAG_NO_ZERO_READS(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_ZERO_READS)
+#define FLAG_IRIVER_OGG_ALZHEIMER(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IRIVER_OGG_ALZHEIMER)
+#define FLAG_ONLY_7BIT_FILENAMES(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ONLY_7BIT_FILENAMES)
+#define FLAG_NO_RELEASE_INTERFACE(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_RELEASE_INTERFACE)
+#define FLAG_IGNORE_HEADER_ERRORS(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IGNORE_HEADER_ERRORS)
+#define FLAG_BROKEN_SET_OBJECT_PROPLIST(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST)
+#define FLAG_OGG_IS_UNKNOWN(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_OGG_IS_UNKNOWN)
+#define FLAG_BROKEN_SET_SAMPLE_DIMENSIONS(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_SAMPLE_DIMENSIONS)
+#define FLAG_ALWAYS_PROBE_DESCRIPTOR(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR)
+#define FLAG_PLAYLIST_SPL_V1(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V1)
+#define FLAG_PLAYLIST_SPL_V2(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V2)
+#define FLAG_PLAYLIST_SPL(a) \
+  ((a)->rawdevice.device_entry.device_flags & (DEVICE_FLAG_PLAYLIST_SPL_V1 | DEVICE_FLAG_PLAYLIST_SPL_V2))
+#define FLAG_CANNOT_HANDLE_DATEMODIFIED(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED)
+#define FLAG_BROKEN_SEND_OBJECT_PROPLIST(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST)
+#define FLAG_BROKEN_BATTERY_LEVEL(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_BATTERY_LEVEL)
+#define FLAG_FLAC_IS_UNKNOWN(a) \
+  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FLAC_IS_UNKNOWN)
+
+/* connect_first_device return codes */
+#define PTP_CD_RC_CONNECTED	0
+#define PTP_CD_RC_NO_DEVICES	1
+#define PTP_CD_RC_ERROR_CONNECTING	2
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif //  LIBUSB-GLUE_H
diff --git a/src/music-players.h b/src/music-players.h
new file mode 100644
index 0000000..4e1caab
--- /dev/null
+++ b/src/music-players.h
@@ -0,0 +1,969 @@
+/**
+ * \file music-players.h
+ * List of music players as USB ids.
+ *
+ * Copyright (C) 2005-2007 Richard A. Low <richard@wentnet.com>
+ * Copyright (C) 2005-2009 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006-2007 Marcus Meissner
+ * Copyright (C) 2007 Ted Bullock
+ *
+ * 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.
+ *
+ * This file is supposed to be included within a struct from both libmtp
+ * and libgphoto2.
+ *
+ * Information can be harvested from Windows driver .INF files, see:
+ * http://msdn.microsoft.com/en-us/library/aa973606.aspx
+ */
+/*
+ * MTP device list, trying real bad to get all devices into
+ * this list by stealing from everyone I know.
+ * Some devices taken from the Rockbox device listing:
+ * http://www.rockbox.org/twiki/bin/view/Main/DeviceDetection
+ */
+
+  /*
+   * Creative Technology and ZiiLABS
+   * Initially the Creative devices was all we supported so these are
+   * the most thoroughly tested devices. Presumably only the devices
+   * with older firmware (the ones that have 32bit object size) will
+   * need the DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL flag. This bug
+   * manifest itself when you have a lot of folders on the device,
+   * some of the folders will start to disappear when getting all objects
+   * and properties.
+   */
+  { "Motorola", 0x22b8, "Xoom", 0x70a9, DEVICE_FLAG_NONE },
+  { "Motorola", 0x22b8, "Xoom", 0x70a8 , DEVICE_FLAG_NONE},
+  { "Creative", 0x041e, "ZEN Vision", 0x411f, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  { "Creative", 0x041e, "Portable Media Center", 0x4123, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  { "Creative", 0x041e, "ZEN Xtra (MTP mode)", 0x4128, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  { "Dell", 0x041e, "DJ (2nd generation)", 0x412f, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  { "Creative", 0x041e, "ZEN Micro (MTP mode)", 0x4130, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  { "Creative", 0x041e, "ZEN Touch (MTP mode)", 0x4131, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  { "Dell", 0x041e, "Dell Pocket DJ (MTP mode)", 0x4132, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  { "Creative", 0x041e, "ZEN Sleek (MTP mode)", 0x4137, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  { "Creative", 0x041e, "ZEN MicroPhoto", 0x413c, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  { "Creative", 0x041e, "ZEN Sleek Photo", 0x413d, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  { "Creative", 0x041e, "ZEN Vision:M", 0x413e, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // Reported by marazm@o2.pl
+  { "Creative", 0x041e, "ZEN V", 0x4150, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // Reported by danielw@iinet.net.au
+  // This version of the Vision:M needs the no release interface flag,
+  // unclear whether the other version above need it too or not.
+  { "Creative", 0x041e, "ZEN Vision:M (DVP-HD0004)", 0x4151, 
+      DEVICE_FLAG_NO_RELEASE_INTERFACE |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL},
+  // Reported by Darel on the XNJB forums
+  { "Creative", 0x041e, "ZEN V Plus", 0x4152,
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  { "Creative", 0x041e, "ZEN Vision W", 0x4153,
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // Don't add 0x4155: this is a Zen Stone device which is not MTP
+  // Reported by Paul Kurczaba <paul@kurczaba.com>
+  { "Creative", 0x041e, "ZEN", 0x4157, DEVICE_FLAG_IGNORE_HEADER_ERRORS |
+    DEVICE_FLAG_BROKEN_SET_SAMPLE_DIMENSIONS |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // Reported by Ringofan <mcroman@users.sourceforge.net>
+  { "Creative", 0x041e, "ZEN V 2GB", 0x4158,
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // Reported by j norment <stormzen@gmail.com>
+  { "Creative", 0x041e, "ZEN Mozaic", 0x4161,
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // Reported by Aaron F. Gonzalez <sub_tex@users.sourceforge.net>
+  { "Creative", 0x041e, "ZEN X-Fi", 0x4162,
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // Reported by Todor Gyumyushev <yodor1@users.sourceforge.net>
+  { "ZiiLABS", 0x041e, "Zii EGG", 0x6000,
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+
+  /*
+   * Samsung
+   * We suspect that more of these are dual mode.
+   * We suspect more of these might need DEVICE_FLAG_NO_ZERO_READS
+   * We suspect more of these might need DEVICE_FLAG_PLAYLIST_SPL_V1
+   *  or DEVICE_FLAG_PLAYLIST_SPL_V2 to get playlists working.
+   * YP-NEU, YP-NDU, YP-20, YP-800, YP-MF Series, YP-100, YP-30
+   * YP-700 and YP-90 are NOT MTP, but use a Samsung custom protocol.
+   */
+  // From anonymous SourceForge user, not verified
+  { "Samsung", 0x04e8, "YP-900", 0x0409, DEVICE_FLAG_NONE },
+  // From MItch <dbaker@users.sourceforge.net>
+  { "Samsung", 0x04e8, "I550W Phone", 0x04a4, DEVICE_FLAG_NONE },
+  // From Gabriel Nunes <gabrielkm1@yahoo.com.br>
+  { "Samsung", 0x04e8, "YH-920 (501d)", 0x501d, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From Soren O'Neill
+  { "Samsung", 0x04e8, "YH-920 (5022)", 0x5022, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Contributed by aronvanammers on SourceForge
+  { "Samsung", 0x04e8, "YH-925GS", 0x5024, DEVICE_FLAG_NONE },
+  // From libgphoto2, according to tests by Stephan Fabel it cannot
+  // get all objects with the getobjectproplist command..
+  { "Samsung", 0x04e8, "YH-820", 0x502e, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // Contributed by polux2001@users.sourceforge.net
+  { "Samsung", 0x04e8, "YH-925(-GS)", 0x502f, DEVICE_FLAG_UNLOAD_DRIVER | 
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // Contributed by anonymous person on SourceForge
+  { "Samsung", 0x04e8, "YH-J70J", 0x5033, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From XNJB user
+  // Guessing on .spl flag
+  { "Samsung", 0x04e8, "YP-Z5", 0x503c, DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_PLAYLIST_SPL_V1 },
+  // Don't add 0x5041 as this is YP-Z5 in USB mode
+  // Contributed by anonymous person on SourceForge
+  { "Samsung", 0x04e8, "YP-T7J", 0x5047, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by cstrickler@gmail.com
+  { "Samsung", 0x04e8, "YP-U2J (YP-U2JXB/XAA)", 0x5054, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by Andrew Benson
+  { "Samsung", 0x04e8, "YP-F2J", 0x5057, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by Patrick <skibler@gmail.com>
+  // Just guessing but looks like .spl v1 http://www.anythingbutipod.com/forum/showthread.php?t=14160
+  { "Samsung", 0x04e8, "YP-K5", 0x505a, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_NO_ZERO_READS | DEVICE_FLAG_PLAYLIST_SPL_V1 },
+  // From dev.local@gmail.com - 0x4e8/0x507c is the UMS mode, apparently
+  // do not add that device.
+  // From m.eik michalke
+  // This device does NOT use the special SPL playlist according to sypqgjxu@gmx.de.
+  { "Samsung", 0x04e8, "YP-U3", 0x507d, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by Matthew Wilcox <matthew@wil.cx>
+  // Sergio <sfrdll@tiscali.it> reports this device need the BROKEN ALL flag.
+  // Guessing on .spl flag
+  { "Samsung", 0x04e8, "YP-T9", 0x507f, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL | DEVICE_FLAG_PLAYLIST_SPL_V1 },
+  // From Paul Clinch
+  // Just guessing but looks like .spl v1 http://www.anythingbutipod.com/forum/showthread.php?t=14160
+  // Some versions of the firmware reportedly support OGG, reportedly only the
+  // UMS versions, so MTP+OGG is not possible on this device.
+  { "Samsung", 0x04e8, "YP-K3", 0x5081, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_PLAYLIST_SPL_V1 },
+  // From XNJB user
+  // From Alistair Boyle, .spl v2 required for playlists
+  // According to the device log it properly supports OGG
+  { "Samsung", 0x04e8, "YP-P2", 0x5083, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_NO_ZERO_READS | DEVICE_FLAG_PLAYLIST_SPL_V2 },
+  // From Paul Clinch
+  // Guessing on .spl flag
+  { "Samsung", 0x04e8, "YP-T10", 0x508a, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_OGG_IS_UNKNOWN | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+      DEVICE_FLAG_PLAYLIST_SPL_V1 | DEVICE_FLAG_NO_ZERO_READS },
+  // From Wim Verwimp <wimverwimp@gmail.com>
+  // Not sure about the Ogg and broken proplist flags here. Just guessing.
+  // Guessing on .spl flag
+  { "Samsung", 0x04e8, "YP-S5", 0x508b, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_OGG_IS_UNKNOWN | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+      DEVICE_FLAG_PLAYLIST_SPL_V1 },
+  // From Ludovic Danigo
+  // Guessing on .spl flag
+  { "Samsung", 0x04e8, "YP-S3", 0x5091, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_OGG_IS_UNKNOWN | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+      DEVICE_FLAG_PLAYLIST_SPL_V1 },
+  // From Adrian Levi <adrian.levi@gmail.com>
+  // Guessing on .spl flag
+  // This one supports OGG properly through the correct MTP type.
+  { "Samsung", 0x04e8, "YP-U4", 0x5093, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From Anonymous SourceForge user, NOT VERIFIED TO BE MTP
+  // Guessing on .spl flag
+  { "Samsung", 0x04e8, "YP-Q1", 0x5115, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_OGG_IS_UNKNOWN | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+      DEVICE_FLAG_PLAYLIST_SPL_V1 },
+  // From Anonymous SourceForge user
+  // Guessing on .spl flag
+  { "Samsung", 0x04e8, "YP-P3", 0x511a, DEVICE_FLAG_UNLOAD_DRIVER |
+     DEVICE_FLAG_OGG_IS_UNKNOWN | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+     DEVICE_FLAG_PLAYLIST_SPL_V1 },
+  // From Anonymous SourceForge user
+  // Guessing on .spl flag
+  { "Samsung", 0x04e8, "YP-Q2", 0x511d, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_OGG_IS_UNKNOWN | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+      DEVICE_FLAG_PLAYLIST_SPL_V1 },
+  // From Marco Pizzocaro <mpizzocaro@users.sourceforge.net>
+  // Guessing on .spl flag
+  { "Samsung", 0x04e8, "YP-U5", 0x5121,
+     DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_PLAYLIST_SPL_V1 },
+  // From a rouge .INF file,
+  // this device ID seems to have been recycled for:
+  // the Samsung SGH-A707 Cingular cellphone
+  // the Samsung L760-V cellphone
+  // the Samsung SGH-U900 cellphone
+  { "Samsung", 0x04e8, "YH-999 Portable Media Center/SGH-A707/SGH-L760V/SGH-U900", 0x5a0f, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // From Santi Béjar <sbejar@gmail.com> - not sure this is MTP...
+  // { "Samsung", 0x04e8, "Z170 Mobile Phone", 0x6601, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From Santi Béjar <sbejar@gmail.com> - not sure this is MTP...
+  // { "Samsung", 0x04e8, "E250 Mobile Phone", 0x663e, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From Lionel Bouton
+  { "Samsung", 0x04e8, "X830 Mobile Phone", 0x6702, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From James <jamestech@gmail.com>
+  { "Samsung", 0x04e8, "U600 Mobile Phone", 0x6709, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From Cesar Cardoso <cesar@cesarcardoso.tk>
+  // No confirmation that this is really MTP.
+  { "Samsung", 0x04e8, "F250 Mobile Phone", 0x6727, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From Charlie Todd  2007-10-31
+  { "Samsung", 0x04e8, "Juke (SCH-U470)", 0x6734, DEVICE_FLAG_UNLOAD_DRIVER},
+  // Reported by Tenn
+  { "Samsung", 0x04e8, "GT-B2700", 0x6752, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Added by Greg Fitzgerald <netzdamon@gmail.com>
+  { "Samsung", 0x04e8, "SAMSUNG Trance", 0x6763, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_NO_ZERO_READS | DEVICE_FLAG_PLAYLIST_SPL_V1 },
+  // From anonymous Sourceforge user
+  { "Samsung", 0x04e8, "GT-S5230", 0xe20c, DEVICE_FLAG_NONE },
+
+
+
+  /*
+   * Intel
+   */
+  { "Intel", 0x045e, "Bandon Portable Media Center", 0x00c9, DEVICE_FLAG_NONE },
+  // Reported by Tadimarri Sarath <sarath.tadi@gmail.com>
+  // No idea why this use an Intel PID, perhaps a leftover from
+  // the early PMC development days when Intel and Microsoft were
+  // partnering.
+  { "Microsoft", 0x045e, "Windows MTP Simulator", 0x0622, DEVICE_FLAG_NONE },
+
+  /*
+   * JVC
+   */
+  // From Mark Veinot
+  { "JVC", 0x04f1, "Alneo XA-HD500", 0x6105, DEVICE_FLAG_NONE },
+
+  /*
+   * Philips
+   */
+  { "Philips", 0x0471, "HDD6320/00 or HDD6330/17", 0x014b, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // Anonymous SourceForge user
+  { "Philips", 0x0471, "HDD14XX,HDD1620 or HDD1630/17", 0x014c, DEVICE_FLAG_NONE },
+  // from discussion forum
+  { "Philips", 0x0471, "HDD085/00 or HDD082/17", 0x014d, DEVICE_FLAG_NONE },
+  // from XNJB forum
+  { "Philips", 0x0471, "GoGear SA9200", 0x014f, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // From John Coppens <jcoppens@users.sourceforge.net>
+  { "Philips", 0x0471, "SA1115/55", 0x0164, DEVICE_FLAG_NONE },
+  // From Gerhard Mekenkamp
+  { "Philips", 0x0471, "GoGear Audio", 0x0165, DEVICE_FLAG_NONE },
+  // from David Holm <wormie@alberg.dk>
+  { "Philips", 0x0471, "Shoqbox", 0x0172, DEVICE_FLAG_ONLY_7BIT_FILENAMES },
+  // from npedrosa
+  { "Philips", 0x0471, "PSA610", 0x0181, DEVICE_FLAG_NONE },
+  // From libgphoto2 source
+  { "Philips", 0x0471, "HDD6320", 0x01eb, DEVICE_FLAG_NONE },
+  // From Detlef Meier <dm@emlix.com>
+  { "Philips", 0x0471, "GoGear SA6014/SA6015/SA6024/SA6025/SA6044/SA6045", 0x084e, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From anonymous Sourceforge user SA5145/02
+  { "Philips", 0x0471, "GoGear SA5145", 0x0857, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From a
+  { "Philips", 0x0471, "GoGear SA6125/SA6145/SA6185", 0x2002, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From anonymous Sourceforge user, not verified to be MTP!
+  { "Philips", 0x0471, "GoGear SA3345", 0x2004, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From Roberto Vidmar <rvidmar@libero.it>
+  { "Philips", 0x0471, "SA5285", 0x2022, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From Elie De Brauwer <elie@de-brauwer.be>
+  { "Philips", 0x0471, "GoGear ViBE SA1VBE04", 0x2075,
+    DEVICE_FLAG_UNLOAD_DRIVER },
+  // From Elie De Brauwer <elie@de-brauwer.be>
+  { "Philips", 0x0471, "GoGear ViBE SA1VBE08", 0x207b,
+    DEVICE_FLAG_UNLOAD_DRIVER },
+  // From josmtx <josmtx@users.sourceforge.net>
+  { "Philips", 0x0471, "GoGear Aria", 0x207c,
+    DEVICE_FLAG_UNLOAD_DRIVER },
+  // from XNJB user
+  { "Philips", 0x0471, "PSA235", 0x7e01, DEVICE_FLAG_NONE },
+
+
+  /*
+   * SanDisk
+   * several devices (c150 for sure) are definately dual-mode and must 
+   * have the USB mass storage driver that hooks them unloaded first.
+   * They all have problematic dual-mode making the device unload effect
+   * uncertain on these devices.
+   *
+   * All older devices seem to need DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL.
+   * Old chipsets: e200/c200 use PP5024 from Nvidia (formerly PortalPlayer).
+   * m200 use TCC770 from Telechips.
+   *
+   * The newer Sansa v2 chipset, AD3525 from Austriamicrosystems (AMS) found 
+   * in e280 v2 c200 v2, Clip, Fuze etc require DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST
+   * and DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR to work properly.
+   *
+   * For more info see: http://daniel.haxx.se/sansa/v2.html
+   */
+  // Reported by Brian Robison
+  { "SanDisk", 0x0781, "Sansa m230/m240", 0x7400,
+    DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED },
+  // From Rockbox device listing
+  { "SanDisk", 0x0781, "Sansa m200-tcc (MTP mode)", 0x7401,
+    DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED },
+  // Reported by tangent_@users.sourceforge.net
+  { "SanDisk", 0x0781, "Sansa c150", 0x7410,
+    DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED },
+  // From libgphoto2 source
+  // Reported by <gonkflea@users.sourceforge.net>
+  // Reported by Mike Owen <mikeowen@computerbaseusa.com>
+  { "SanDisk", 0x0781, "Sansa e200/e250/e260/e270/e280", 0x7420,
+    DEVICE_FLAG_UNLOAD_DRIVER |  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED },
+  // Don't add 0x7421 as this is e280 in MSC mode
+  // Reported by XNJB user
+  { "SanDisk", 0x0781, "Sansa e260/e280 v2", 0x7422,
+    DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR |
+    DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED },
+  // Reported by XNJB user
+  { "SanDisk", 0x0781, "Sansa m240/m250", 0x7430,
+    DEVICE_FLAG_UNLOAD_DRIVER |  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED },
+  // Reported by Eugene Brevdo <ebrevdo@princeton.edu>
+  { "SanDisk", 0x0781, "Sansa Clip", 0x7432,
+    DEVICE_FLAG_UNLOAD_DRIVER |  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR |
+    DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED},
+  // Reported by HackAR <hackar@users.sourceforge.net>
+  { "SanDisk", 0x0781, "Sansa Clip v2", 0x7434,
+    DEVICE_FLAG_UNLOAD_DRIVER |  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR |
+    DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED},
+  // Reported by anonymous user at sourceforge.net
+  { "SanDisk", 0x0781, "Sansa c240/c250", 0x7450,
+    DEVICE_FLAG_UNLOAD_DRIVER |  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED },
+  // Reported by anonymous SourceForge user
+  { "SanDisk", 0x0781, "Sansa c250 v2", 0x7452,
+    DEVICE_FLAG_UNLOAD_DRIVER |  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED },
+  // Reported by Troy Curtis Jr.
+  { "SanDisk", 0x0781, "Sansa Express", 0x7460,
+    DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED },
+  // Reported by XNJB user, and Miguel de Icaza <miguel@gnome.org>
+  // This has no dual-mode so no need to unload any driver.
+  // This is a Linux based device!
+  { "SanDisk", 0x0781, "Sansa Connect", 0x7480, DEVICE_FLAG_NONE },
+  // Reported by anonymous SourceForge user
+  { "SanDisk", 0x0781, "Sansa View", 0x74b0,
+    DEVICE_FLAG_UNLOAD_DRIVER |  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED },
+  // Reported by Patrick <skibler@gmail.com>
+  // There are apparently problems with this device.
+  { "SanDisk", 0x0781, "Sansa Fuze", 0x74c0,
+    DEVICE_FLAG_UNLOAD_DRIVER |  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR |
+    DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED },
+  // Harry Phillips <tuxcomputers@users.sourceforge.net>
+  { "SanDisk", 0x0781, "Sansa Fuze v2", 0x74c2,
+    DEVICE_FLAG_UNLOAD_DRIVER |  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE | DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR |
+    DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED },
+
+  /*
+   * iRiver
+   * we assume that PTP_OC_MTP_GetObjPropList is essentially
+   * broken on all iRiver devices, meaning it simply won't return
+   * all properties for a file when asking for metadata 0xffffffff. 
+   * Please test on your device if you believe it isn't broken!
+   */
+  { "iRiver", 0x1006, "H300 Series MTP", 0x3004,
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  { "iRiver", 0x1006, "Portable Media Center", 0x4002,
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  { "iRiver", 0x1006, "Portable Media Center", 0x4003,
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  // From [st]anislav <iamstanislav@gmail.com>
+  { "iRiver", 0x1042, "T7 Volcano", 0x1143, DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  // From an anonymous person at SourceForge, uncertain about this one
+  { "iRiver", 0x4102, "iFP-880", 0x1008, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  // 0x4102, 0x1042 is a USB mass storage mode for E100 v2/Lplayer
+  // From libgphoto2 source
+  { "iRiver", 0x4102, "T10", 0x1113, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  { "iRiver", 0x4102, "T20 FM", 0x1114, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  // This appears at the MTP-UMS site
+  { "iRiver", 0x4102, "T20", 0x1115, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  { "iRiver", 0x4102, "U10", 0x1116, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  { "iRiver", 0x4102, "T10a", 0x1117, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  { "iRiver", 0x4102, "T20", 0x1118, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  { "iRiver", 0x4102, "T30", 0x1119, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  // Reported by David Wolpoff
+  { "iRiver", 0x4102, "T10 2GB", 0x1120, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  // Rough guess this is the MTP device ID...
+  { "iRiver", 0x4102, "N12", 0x1122, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  // Reported by Philip Antoniades <philip@mysql.com>
+  // Newer iriver devices seem to have shaped-up firmware without any
+  // of the annoying bugs.
+  { "iRiver", 0x4102, "Clix2", 0x1126, DEVICE_FLAG_NONE },
+  // Reported by Adam Torgerson
+  { "iRiver", 0x4102, "Clix", 0x112a, 
+    DEVICE_FLAG_NO_ZERO_READS | DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  // Reported by Douglas Roth <dougaus@gmail.com>
+  { "iRiver", 0x4102, "X20", 0x1132, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  // Reported by Robert Ugo <robert_ugo@users.sourceforge.net>
+  { "iRiver", 0x4102, "T60", 0x1134, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_IRIVER_OGG_ALZHEIMER },
+  // Reported by two anonymous SourceForge users
+  // Needs the stronger OGG_IS_UNKNOWN flag to support OGG properly,
+  // be aware of newer players that may be needing this too.
+  { "iRiver", 0x4102, "E100", 0x1141, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_OGG_IS_UNKNOWN },
+  // Reported by anonymous SourceForge user
+  // Need verification of whether this firmware really need all these flags
+  { "iRiver", 0x4102, "E100 v2/Lplayer", 0x1142, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_OGG_IS_UNKNOWN },
+  // Reported by Richard Vennemann <vennemann@users.sourceforge.net>
+  // In USB Mass Storage mode it is 0x4102/0x1047
+  // Seems to use the new shaped-up firmware.
+  { "iRiver", 0x4102, "Spinn", 0x1147, DEVICE_FLAG_NONE },
+  // Reported by Tony Janssen <tonyjanssen@users.sourceforge.net>
+  { "iRiver", 0x4102, "E50", 0x1151,
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_OGG_IS_UNKNOWN },
+  // Reported by Scott Call
+  // Assume this actually supports OGG though it reports it doesn't.
+  { "iRiver", 0x4102, "H10 20GB", 0x2101, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_OGG_IS_UNKNOWN },
+  { "iRiver", 0x4102, "H10 5GB", 0x2102, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_OGG_IS_UNKNOWN },
+  // From Rockbox device listing
+  { "iRiver", 0x4102, "H10 5.6GB", 0x2105, 
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_NO_ZERO_READS | 
+    DEVICE_FLAG_OGG_IS_UNKNOWN },
+
+
+  /*
+   * Dell
+   */
+  { "Dell, Inc", 0x413c, "DJ Itty", 0x4500, DEVICE_FLAG_NONE },
+  
+  /*
+   * Toshiba
+   * Tentatively flagged all Toshiba devices with
+   * DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST after one of them
+   * showed erroneous behaviour.
+   */
+  { "Toshiba", 0x0930, "Gigabeat MEGF-40", 0x0009,
+    DEVICE_FLAG_NO_RELEASE_INTERFACE |  DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST },
+  { "Toshiba", 0x0930, "Gigabeat", 0x000c,
+    DEVICE_FLAG_NO_RELEASE_INTERFACE |  DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST },
+  // Reported by Nicholas Tripp
+  { "Toshiba", 0x0930, "Gigabeat P20", 0x000f,
+    DEVICE_FLAG_NO_RELEASE_INTERFACE |  DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST },
+  // From libgphoto2
+  { "Toshiba", 0x0930, "Gigabeat S", 0x0010, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL |
+      DEVICE_FLAG_NO_RELEASE_INTERFACE |  DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST },
+  // Reported by Rob Brown
+  { "Toshiba", 0x0930, "Gigabeat P10", 0x0011,
+    DEVICE_FLAG_NO_RELEASE_INTERFACE |  DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST },
+  // Reported by solanum@users.sourceforge.net
+  { "Toshiba", 0x0930, "Gigabeat V30", 0x0014,
+    DEVICE_FLAG_NO_RELEASE_INTERFACE |  DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST },
+  // Reported by Michael Davis <slithy@yahoo.com>
+  { "Toshiba", 0x0930, "Gigabeat U", 0x0016,
+    DEVICE_FLAG_NO_RELEASE_INTERFACE |  DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST },
+  // Reported by Devon Jacobs <devo@godevo.com>
+  { "Toshiba", 0x0930, "Gigabeat MEU202", 0x0018,
+    DEVICE_FLAG_NO_RELEASE_INTERFACE |  DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST },
+  // Reported by Rolf <japan (at) dl3lar.de>
+  { "Toshiba", 0x0930, "Gigabeat T", 0x0019,
+    DEVICE_FLAG_NO_RELEASE_INTERFACE |  DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST },
+  // Reported by Phil Ingram <ukpbert@users.sourceforge.net>
+  // Tentatively added - no real reports of this device ID being MTP,
+  // reports as USB Mass Storage currently.
+  { "Toshiba", 0x0930, "Gigabeat MEU201", 0x001a,
+    DEVICE_FLAG_NO_RELEASE_INTERFACE |  DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST },
+  // Reported by anonymous SourceForge user
+  { "Toshiba", 0x0930, "Gigabeat MET401", 0x001d,
+    DEVICE_FLAG_NO_RELEASE_INTERFACE |  DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST },
+
+  
+  /*
+   * Archos
+   * These devices have some dual-mode interfaces which will really
+   * respect the driver unloading, so DEVICE_FLAG_UNLOAD_DRIVER
+   * really work on these devices!
+   */
+  // Reported by Alexander Haertig <AlexanderHaertig@gmx.de>
+  { "Archos", 0x0e79, "Gmini XS100", 0x1207, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Added by Jan Binder
+  { "Archos", 0x0e79, "XS202 (MTP mode)", 0x1208, DEVICE_FLAG_NONE },
+  // Reported by gudul1@users.sourceforge.net
+  { "Archos", 0x0e79, "104 (MTP mode)", 0x120a, DEVICE_FLAG_NONE },
+  // Reported by anonymous Sourceforge user.
+  { "Archos", 0x0e79, "404 (MTP mode)", 0x1301, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by Etienne Chauchot <chauchot.etienne@free.fr>
+  { "Archos", 0x0e79, "504 (MTP mode)", 0x1307, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by Kay McCormick <kaym@modsystems.com>
+  { "Archos", 0x0e79, "704 mobile dvr", 0x130d, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by Joe Rabinoff
+  { "Archos", 0x0e79, "605 (MTP mode)", 0x1313, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by Jim Krehl <jimmuhk@users.sourceforge.net>
+  { "Archos", 0x0e79, "5 (MTP mode)", 0x1331, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by Adrien Guichard <tmor@users.sourceforge.net>
+  { "Archos", 0x0e79, "5 (MTP mode)", 0x1333, DEVICE_FLAG_UNLOAD_DRIVER },
+
+  /*
+   * Dunlop (OEM of EGOMAN ltd?) reported by Nanomad
+   * This unit is falsely detected as USB mass storage in Linux
+   * prior to kernel 2.6.19 (fixed by patch from Alan Stern)
+   * so on older kernels special care is needed to remove the
+   * USB mass storage driver that erroneously binds to the device
+   * interface.
+   */
+  { "Dunlop", 0x10d6, "MP3 player 1GB / EGOMAN MD223AFD", 0x2200, DEVICE_FLAG_UNLOAD_DRIVER},
+  // Reported by Steven Black <stevenblack1956@users.sourceforge.net>
+  // Obviously this company goes by many names.
+  // This device is USB 2.0 only. Broken pipe on closing.
+  { "Memorex", 0x10d6, "MMP 8585/8586", 0x2300, DEVICE_FLAG_UNLOAD_DRIVER | 
+      DEVICE_FLAG_NO_RELEASE_INTERFACE},
+  
+  /*
+   * Microsoft
+   */
+  // Reported by Farooq Zaman (used for all Zunes)
+  { "Microsoft", 0x045e, "Zune", 0x0710, DEVICE_FLAG_NONE }, 
+  
+  /*
+   * Sirius
+   */
+  { "Sirius", 0x18f6, "Stiletto", 0x0102, DEVICE_FLAG_NONE },
+  // Reported by Chris Bagwell <chris@cnpbagwell.com>
+  { "Sirius", 0x18f6, "Stiletto 2", 0x0110, DEVICE_FLAG_NONE },
+
+  /*
+   * Canon
+   * This is actually a camera, but it has a Microsoft device descriptor
+   * and reports itself as supporting the MTP extension.
+   */
+  { "Canon", 0x04a9, "PowerShot A640 (PTP/MTP mode)", 0x3139,
+     DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+
+  /*
+   * Nokia
+   * Please verify the low device IDs here, I suspect these might be for
+   * things like USB storage or modem mode actually, whereas the higher
+   * range (0x04nn) could be for MTP. Some of the devices were gathered
+   * from the Nokia WMP drivers:
+   * http://nds2.nokia.com/files/support/global/phones/software/
+   * Address was gathered from going to:
+   * nseries.com
+   * -> support
+   * -> select supported device
+   *  -> PC software
+   *    -> Music software
+   *      -> Windows Media Player 10 driver
+   */
+  // From: DoomHammer <gaczek@users.sourceforge.net>
+  { "Nokia", 0x0421, "N81 Mobile Phone", 0x000a, DEVICE_FLAG_NONE },
+  // From an anonymous SourceForge user
+  { "Nokia", 0x0421, "6120c Classic Mobile Phone", 0x002e, DEVICE_FLAG_NONE },
+  // From Stefano
+  { "Nokia", 0x0421, "N96 Mobile Phone", 0x0039, DEVICE_FLAG_NONE },
+  // From Martijn van de Streek <martijn@vandestreek.net>
+  { "Nokia", 0x0421, "6500c Classic Mobile Phone", 0x003c, DEVICE_FLAG_NONE },
+  // From: DoomHammer <gaczek@users.sourceforge.net>
+  { "Nokia", 0x0421, "3110c Mobile Phone", 0x005f, DEVICE_FLAG_NONE },
+  // From: Vasily <spc-@users.sourceforge.net>
+  { "Nokia", 0x0421, "3109c Mobile Phone", 0x0065, DEVICE_FLAG_NONE },
+  // From: <rawc@users.sourceforge.net>
+  { "Nokia", 0x0421, "5310 XpressMusic", 0x006c, DEVICE_FLAG_NONE },
+  // From: robin (AT) headbank D0Tco DOTuk
+  { "Nokia", 0x0421, "N95 Mobile Phone 8GB", 0x006e, DEVICE_FLAG_NONE },
+  // From Bastien Nocera <hadess@hadess.net>
+  { "Nokia", 0x0421, "N82 Mobile Phone", 0x0074, DEVICE_FLAG_NONE },
+  // From Martijn van de Streek <martijn@vandestreek.net>
+  { "Nokia", 0x0421, "N78 Mobile Phone", 0x0079, DEVICE_FLAG_NONE },
+  // From William Pettersson <the_enigma@users.sourceforge.net>
+  { "Nokia", 0x0421, "6220 Classic", 0x008d, DEVICE_FLAG_NONE },
+  // From kellerkev@gmail.com
+  { "Nokia", 0x0421, "N85 Mobile Phone", 0x0092, DEVICE_FLAG_NONE },
+  // From: danielw
+  { "Nokia", 0x0421, "E71", 0x00e4, DEVICE_FLAG_NONE },
+  // From: Laurent Bigonville <bigon@users.sourceforge.net>
+  { "Nokia", 0x0421, "E66", 0x00e5, DEVICE_FLAG_NONE },
+  // From: Pier <pierlucalino@users.sourceforge.net>
+  { "Nokia", 0x0421, "5320 XpressMusic", 0x00ea, DEVICE_FLAG_NONE },
+  // From: Gausie <innerdreams@users.sourceforge.net>
+  { "Nokia", 0x0421, "5800 XpressMusic", 0x0154, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // From: Willy Gardiol (web) <willy@gardiol.org>
+  // Spurious errors for getting all objects, lead me to believe this flag atleast is needed
+  { "Nokia", 0x0421, "5800 XpressMusic v2", 0x0155, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // From an anonymous SourceForge user
+  // Not verified to be MTP
+  { "Nokia", 0x0421, "E63", 0x0179, DEVICE_FLAG_NONE },
+  // From: FunkyPenguin <awafaa@users.sourceforge.net>
+  { "Nokia", 0x0421, "N97", 0x01f5, DEVICE_FLAG_NONE },
+  // From: Alexander Kojevnikov <alex-kay@users.sourceforge.net>
+  { "Nokia", 0x0421, "6600i", 0x0297, DEVICE_FLAG_NONE },
+  // https://sourceforge.net/tracker/index.php?func=detail&aid=2692473&group_id=8874&atid=358874
+  { "Nokia", 0x0421, "5200", 0x0421, DEVICE_FLAG_NONE },
+  // From: http://nds2.nokia.com/files/support/global/phones/software/Nokia_3250_WMP10_driver.inf
+  { "Nokia", 0x0421, "3250 Mobile Phone", 0x0462, DEVICE_FLAG_NONE },
+  // From http://nds2.nokia.com/files/support/global/phones/software/Nokia_N93_WMP10_Driver.inf
+  { "Nokia", 0x0421, "N93 Mobile Phone", 0x0478, DEVICE_FLAG_NONE },
+  // From: http://nds2.nokia.com/files/support/global/phones/software/Nokia_5500_Sport_WMP10_driver.inf
+  { "Nokia", 0x0421, "5500 Sport Mobile Phone", 0x047e, DEVICE_FLAG_NONE },
+  // From http://nds2.nokia.com/files/support/global/phones/software/Nokia_N91_WMP10_Driver.inf
+  { "Nokia", 0x0421, "N91 Mobile Phone", 0x0485, DEVICE_FLAG_NONE },
+  // From: Christian Rusa <kristous@users.sourceforge.net>
+  { "Nokia", 0x0421, "5700 XpressMusic Mobile Phone", 0x04b4, DEVICE_FLAG_NONE },
+  // From: Mitchell Hicks <mitchix@yahoo.com>
+  { "Nokia", 0x0421, "5300 Mobile Phone", 0x04ba, DEVICE_FLAG_NONE },
+  // From Christian Arnold <webmaster@arctic-media.de>
+  { "Nokia", 0x0421, "N73 Mobile Phone", 0x04d1, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From Swapan <swapan@yahoo.com>
+  { "Nokia", 0x0421, "N75 Mobile Phone", 0x04e1, DEVICE_FLAG_NONE },
+  // From: http://nds2.nokia.com/files/support/global/phones/software/Nokia_N93i_WMP10_driver.inf
+  { "Nokia", 0x0421, "N93i Mobile Phone", 0x04e5, DEVICE_FLAG_NONE },
+  // From Anonymous Sourceforge User
+  { "Nokia", 0x0421, "N95 Mobile Phone", 0x04ef, DEVICE_FLAG_NONE },
+  // From: Pat Nicholls <pat@patandannie.co.uk>
+  { "Nokia", 0x0421, "N80 Internet Edition (Media Player)", 0x04f1, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by Richard Wall <richard@the-moon.net>
+  { "Nokia", 0x05c6, "5530 Xpressmusic", 0x0229, DEVICE_FLAG_NONE },
+  // Reported by anonymous SourceForge user
+  // One thing stated by reporter (Nokia model) another by the detect log...
+  { "Nokia/Verizon", 0x05c6, "6205 Balboa/Verizon Music Phone", 0x3196, DEVICE_FLAG_NONE },
+
+
+  /*
+   * LOGIK
+   * Sold in the UK, seem to be manufactured by CCTech in China.
+   */
+  { "Logik", 0x13d1, "LOG DAX MP3 and DAB Player", 0x7002, DEVICE_FLAG_UNLOAD_DRIVER },
+
+  /*
+   * RCA / Thomson
+   */
+  // From kiki <omkiki@users.sourceforge.net>
+  { "Thomson", 0x069b, "EM28 Series", 0x0774, DEVICE_FLAG_NONE },
+  { "Thomson / RCA", 0x069b, "Opal / Lyra MC4002", 0x0777, DEVICE_FLAG_NONE },
+  { "Thomson", 0x069b, "Lyra MC5104B (M51 Series)", 0x077c, DEVICE_FLAG_NONE },
+  { "Thomson", 0x069b, "RCA H106", 0x301a, DEVICE_FLAG_UNLOAD_DRIVER },
+  // From Svenna <svenna@svenna.de>
+  // Not confirmed to be MTP.
+  { "Thomson", 0x069b, "scenium E308", 0x3028, DEVICE_FLAG_NONE },
+  // From XNJB user
+  { "Thomson / RCA", 0x069b, "Lyra HC308A", 0x3035, DEVICE_FLAG_NONE },
+  
+  /*
+   * NTT DoCoMo
+   */
+  { "FOMA", 0x04c5, "F903iX HIGH-SPEED", 0x1140, DEVICE_FLAG_NONE },
+
+  /*
+   * Palm device userland program named Pocket Tunes
+   * Reported by Peter Gyongyosi <gyp@impulzus.com>
+   */
+  { "NormSoft, Inc.", 0x1703, "Pocket Tunes", 0x0001, DEVICE_FLAG_NONE },
+  // Reported by anonymous submission
+  { "NormSoft, Inc.", 0x1703, "Pocket Tunes 4", 0x0002, DEVICE_FLAG_NONE },
+
+  /*
+   * TrekStor, Medion and Maxfield devices
+   * Their datasheet claims their devices are dualmode so probably needs to
+   * unload the attached drivers here.
+   */
+  // Reported by Stefan Voss <svoss@web.de>
+  // This is a Sigmatel SoC with a hard disk.
+  { "TrekStor", 0x066f, "Vibez 8/12GB", 0x842a,
+    DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by anonymous SourceForge user.
+  // This one done for Medion, whatever that is. Error reported so assume
+  // the same bug flag as its ancestor above.
+  { "Medion", 0x066f, "MD8333", 0x8550,
+    DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by anonymous SourceForge user
+  { "Medion", 0x066f, "MD8333", 0x8588,
+    DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by anonymous SourceForge user
+  { "Maxfield", 0x066f, "G-Flash NG 1GB", 0x846c,
+    DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Cristi Magherusan <majeru@gentoo.ro>
+  { "TrekStor", 0x0402, "i.Beat Sweez FM", 0x0611,
+    DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by Fox-ino <fox-ino@users.sourceforge.net>
+  { "ALi Corp.", 0x0402, "MPMAN 2GB", 0x5668,
+    DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by Anonymous SourceForge user
+  {"TrekStor", 0x1e68, "i.Beat Organix 2.0", 0x0002,
+    DEVICE_FLAG_UNLOAD_DRIVER },
+
+  /*
+   * Disney/Tevion/MyMusix
+   */
+  // Reported by XNJB user
+  { "Disney", 0x0aa6, "MixMax", 0x6021, DEVICE_FLAG_NONE },
+  // Reported by anonymous Sourceforge user 
+  { "Tevion", 0x0aa6, "MD 81488", 0x3011, DEVICE_FLAG_NONE },
+  // Reported by Peter Hedlund <peter@peterandlinda.com>
+  { "MyMusix", 0x0aa6, "PD-6070", 0x9601, DEVICE_FLAG_UNLOAD_DRIVER |
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+    DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST |
+    DEVICE_FLAG_NO_RELEASE_INTERFACE },
+
+  /*
+   * Cowon Systems, Inc.
+   * The iAudio audiophile devices don't encourage the use of MTP.
+   */
+  // Reported by Patrik Johansson <Patrik.Johansson@qivalue.com>
+  { "Cowon", 0x0e21, "iAudio U3 (MTP mode)", 0x0701,
+   DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Kevin Michael Smith <hai-etlik@users.sourceforge.net>
+  { "Cowon", 0x0e21, "iAudio 6 (MTP mode)", 0x0711,
+   DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Roberth Karman
+  { "Cowon", 0x0e21, "iAudio 7 (MTP mode)", 0x0751,
+   DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by an anonymous SourceForge user
+  { "Cowon", 0x0e21, "iAudio U5 (MTP mode)", 0x0761,
+   DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by TJ Something <tjbk_tjb@users.sourceforge.net>
+  { "Cowon", 0x0e21, "iAudio D2 (MTP mode)", 0x0801,
+   DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by anonymous Sourceforge user
+  { "Cowon", 0x0e21, "iAudio D2+ FW 2.x (MTP mode)", 0x0861,
+   DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // From Rockbox device listing
+  { "Cowon", 0x0e21, "iAudio D2+ DAB FW 4.x (MTP mode)", 0x0871,
+   DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // From Rockbox device listing
+  { "Cowon", 0x0e21, "iAudio D2+ FW 3.x (MTP mode)", 0x0881,
+   DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // From Rockbox device listing
+  { "Cowon", 0x0e21, "iAudio D2+ DMB FW 1.x (MTP mode)", 0x0891,
+   DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by <twkonefal@users.sourceforge.net>
+  { "Cowon", 0x0e21, "iAudio S9 (MTP mode)", 0x0901,
+   DEVICE_FLAG_UNLOAD_DRIVER | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+   DEVICE_FLAG_OGG_IS_UNKNOWN | DEVICE_FLAG_FLAC_IS_UNKNOWN },
+
+  /*
+   * Insignia, dual-mode.
+   */
+  { "Insignia", 0x19ff, "NS-DV45", 0x0303, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by Rajan Bella <rajanbella@yahoo.com>
+  { "Insignia", 0x19ff, "Sport Player", 0x0307, DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by "brad" (anonymous, sourceforge)
+  { "Insignia", 0x19ff, "Pilot 4GB", 0x0309, DEVICE_FLAG_UNLOAD_DRIVER },
+
+  /*
+   * LG Electronics
+   */
+  // Not verified - anonymous submission
+  { "LG Electronics Inc.", 0x043e, "UP3", 0x70b1, DEVICE_FLAG_NONE },
+  // Reported by Joseph Nahmias <joe@nahimas.net>
+  { "LG Electronics Inc.", 0x1004, "VX8550 V CAST Mobile Phone", 0x6010,
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST | DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR },
+  // Reported by Cyrille Potereau <cyrille.potereau@wanadoo.fr>
+  { "LG Electronics Inc.", 0x1004, "KC910 Renoir Mobile Phone", 0x608f,
+      DEVICE_FLAG_UNLOAD_DRIVER },
+  // Reported by anonymous sourceforge user
+  { "LG Electronics Inc.", 0x1004, "KM900", 0x6132,
+      DEVICE_FLAG_UNLOAD_DRIVER },
+
+  /*
+   * Sony
+   * It could be that these PIDs are one-per hundred series, so
+   * NWZ-A8xx is 0325, NWZ-S5xx is 0x326 etc. We need more devices
+   * reported to see a pattern here.
+   */
+  // Reported by Alessandro Radaelli <alessandro.radaelli@aruba.it>
+  { "Sony", 0x054c, "Walkman NWZ-A815/NWZ-A818", 0x0325,
+      DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by anonymous Sourceforge user.
+  { "Sony", 0x054c, "Walkman NWZ-S516", 0x0326, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Endre Oma <endre.88.oma@gmail.com>
+  { "Sony", 0x054c, "Walkman NWZ-S615F/NWZ-S616F/NWZ-S618F", 0x0327,
+      DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Jean-Marc Bourguet <jm@bourguet.org>
+  { "Sony", 0x054c, "Walkman NWZ-S716F", 0x035a, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Anon SF User / Anthon van der Neut <avanderneut@avid.com>
+  { "Sony", 0x054c, "Walkman NWZ-A826/NWZ-A828/NWZ-A829", 0x035b,
+      DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Niek Klaverstijn <niekez@users.sourceforge.net>
+  { "Sony", 0x054c, "Walkman NWZ-A726/NWZ-A728/NWZ-A768", 0x035c,
+      DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Mehdi AMINI <mehdi.amini - at - ulp.u-strasbg.fr>
+  { "Sony", 0x054c, "Walkman NWZ-B135", 0x036e, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by <tiagoboldt@users.sourceforge.net>
+  { "Sony", 0x054c, "Walkman NWZ-E436F", 0x0385, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Michael Wilkinson
+  { "Sony", 0x054c, "Walkman NWZ-W202", 0x0388, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Ondrej Sury <ondrej@sury.org>
+  { "Sony", 0x054c, "Walkman NWZ-S739F", 0x038c, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Marco Filipe Nunes Soares Abrantes Pereira <marcopereira@ua.pt>
+  { "Sony", 0x054c, "Walkman NWZ-S638F", 0x038e, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Elliot <orwells@users.sourceforge.net>
+  { "Sony", 0x054c, "Walkman NWZ-X1050B/NWZ-X1060B",
+    0x0397, DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Silvio J. Gutierrez <silviogutierrez@users.sourceforge.net>
+  { "Sony", 0x054c, "Walkman NWZ-X1051/NWZ-X1061", 0x0398,
+      DEVICE_FLAG_UNLOAD_DRIVER |
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+
+
+  /*
+   * SonyEricsson
+   * These initially seemed to support GetObjPropList but later revisions
+   * of the firmware seem to have broken it, so all are flagged as broken
+   * for now.
+   */
+  // Reported by Thomas Schweitzer <thomas_-_s@users.sourceforge.net>
+  { "SonyEricsson", 0x0fce, "K550i", 0xe000, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Øyvind Stegard <stegaro@users.sourceforge.net>
+  { "SonyEricsson", 0x0fce, "K850i", 0x0075, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Michael Eriksson
+  { "SonyEricsson", 0x0fce, "W910", 0x0076, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Zack <zackdvd@users.sourceforge.net>
+  { "SonyEricsson", 0x0fce, "W890i", 0x00b3, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by robert dot ahlskog at gmail
+  { "SonyEricsson", 0x0fce, "W760i", 0x00c6, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Linus Åkesson <linusakesson@users.sourceforge.net>
+  { "SonyEricsson", 0x0fce, "C902", 0x00d4, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by an anonymous SourceForge user
+  { "SonyEricsson", 0x0fce, "C702", 0x00d9, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Christian Zuckschwerdt <christian@zuckschwerdt.org>
+  { "SonyEricsson", 0x0fce, "W980", 0x00da, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by David Taylor <davidt-libmtp@yadt.co.uk>
+  { "SonyEricsson", 0x0fce, "C905", 0x00ef, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by David House <dmhouse@users.sourceforge.net>
+  { "SonyEricsson", 0x0fce, "W595", 0x00f3,
+      DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL | DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST },
+  // Reported by Mattias Evensson <mevensson@users.sourceforge.net>
+  { "SonyEricsson", 0x0fce, "W902", 0x00f5, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Sarunas <sarunas@users.sourceforge.net>
+  // Doesn't need any flags according to reporter
+  { "SonyEricsson", 0x0fce, "T700", 0x00fb, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // Reported by Stéphane Pontier <shadow_walker@users.sourceforge.net>
+  { "SonyEricsson", 0x0fce, "W705/W715", 0x0105, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+  // Reported by Håkan Kvist
+  { "SonyEricsson", 0x0fce, "W995", 0x0112, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+
+
+  /*
+   * Motorola
+   * Assume DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST on all of these.
+   */
+  // Reported by David Boyd <tiggrdave@users.sourceforge.net>
+  { "Motorola", 0x22b8, "V3m/V750 verizon", 0x2a65, DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST |
+    DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL },
+  // Reported by Marcus Meissner to libptp2
+  { "Motorola", 0x22b8, "K1", 0x4811, DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST },
+  // Reported by Hans-Joachim Baader <hjb@pro-linux.de> to libptp2
+  { "Motorola", 0x22b8, "A1200", 0x60ca, DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST },
+  // http://mark.cdmaforums.com/Files/Motdmmtp.inf
+  { "Motorola", 0x22b8, "MTP Test Command Interface", 0x6413, DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST },
+  // Reported by anonymous user
+  { "Motorola", 0x22b8, "RAZR2 V8/U9/Z6", 0x6415, DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST },
+  
+
+  /*
+   * Media Keg
+   */
+  // Reported by Rajan Bella <rajanbella@yahoo.com>
+  { "Kenwood", 0x0b28, "Media Keg HD10GB7 Sport Player", 0x100c, DEVICE_FLAG_UNLOAD_DRIVER},
+
+  /*
+   * Micro-Star International (MSI)
+   */
+  // Reported by anonymous sourceforge user.
+  { "Micro-Star International", 0x0db0, "P610/Model MS-5557", 0x5572, DEVICE_FLAG_NONE },
+
+  /*
+   * FOMA
+   */
+  { "FOMA", 0x06d3, "D905i", 0x21ba, DEVICE_FLAG_NONE },
+
+  /*
+   * Haier
+   */
+  // Both reported by an anonymous SourceForge user
+  // This is the 30 GiB model
+  { "Haier", 0x1302, "Ibiza Rhapsody", 0x1016, DEVICE_FLAG_NONE },
+  // This is the 4/8 GiB model
+  { "Haier", 0x1302, "Ibiza Rhapsody", 0x1017, DEVICE_FLAG_NONE },
+  
+  /*
+   * Panasonic
+   */
+  // Reported by dmizer
+  { "Panasonic", 0x04da, "P905i", 0x2145, DEVICE_FLAG_NONE },
+
+  /*
+   * Polaroid
+   */
+  { "Polaroid", 0x0546, "Freescape/MPU-433158", 0x2035, DEVICE_FLAG_NONE },
+
+  /*
+   * Pioneer
+   */
+  // Reported by Dan Allen <dan.j.allen@gmail.com>
+  { "Pioneer", 0x08e4, "XMP3", 0x0148, DEVICE_FLAG_NONE },
+
+  /*
+   * Slacker Inc.
+   * Put in all evilness flags because it looks fragile.
+   */
+  // Reported by Pug Fantus <pugfantus@users.sourceforge.net>
+  { "Slacker Inc.", 0x1bdc, "Slacker Portable Media Player", 0xfabf,
+    DEVICE_FLAG_BROKEN_BATTERY_LEVEL | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST |
+    DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST | DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST },
+
+  // Reported by Demadridsur <demadridsur@gmail.com>
+  { "O2 Sistemas", 0x1e53, "ZoltarTV", 0x0006, DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST },
+
+  // Reported by Sense Hofstede <qense@users.sourceforge.net>
+  { "Perception Digital, Ltd", 0x0aa6, "Gigaware GX400", 0x9702, DEVICE_FLAG_NONE },
+  /*
+   * Other strange stuff.
+   */
+  { "Isabella", 0x0b20, "Her Prototype", 0xddee, DEVICE_FLAG_NONE }
diff --git a/src/playlist-spl.c b/src/playlist-spl.c
new file mode 100644
index 0000000..95844d0
--- /dev/null
+++ b/src/playlist-spl.c
@@ -0,0 +1,854 @@
+/**
+ * \File playlist-spl.c
+ *
+ * Playlist_t to Samsung (.spl) and back conversion functions.
+ *
+ * Copyright (C) 2008 Alistair Boyle <alistair.js.boyle@gmail.com>
+ *
+ * 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 <config.h>
+
+#include <stdio.h>
+#include <stdlib.h> // mkstmp()
+#include <unistd.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_UIO_H
+#include <sys/uio.h>
+#endif
+#include <fcntl.h>
+
+#include <string.h>
+
+#include "libmtp.h"
+#include "libusb-glue.h"
+#include "ptp.h"
+#include "unicode.h"
+
+#include "playlist-spl.h"
+
+// set this to 1 to add lots of messy debug output to the playlist code
+#define DEBUG_ENABLED 0
+
+// debug macro
+// d = indenting depth
+#define IF_DEBUG() if(DEBUG_ENABLED) {\
+                     printf("%s:%u:%s(): ", __FILE__, __LINE__, __func__); \
+                   } \
+                   if(DEBUG_ENABLED)
+
+// Internal singly linked list of strings
+// used to hold .spl playlist in memory
+typedef struct text_struct {
+  char* text; // String
+  struct text_struct *next; // Link to next line, NULL if end of list
+} text_t;
+
+
+/**
+ * Forward declarations of local (static) functions.
+ */
+static text_t* read_into_spl_text_t(LIBMTP_mtpdevice_t *device, const int fd);
+static void write_from_spl_text_t(LIBMTP_mtpdevice_t *device, const int fd, text_t* p);
+static void free_spl_text_t(text_t* p);
+static void print_spl_text_t(text_t* p);
+static uint32_t trackno_spl_text_t(text_t* p);
+static void tracks_from_spl_text_t(text_t* p, uint32_t* tracks, LIBMTP_folder_t* folders, LIBMTP_file_t* files);
+static void spl_text_t_from_tracks(text_t** p, uint32_t* tracks, const uint32_t trackno, const uint32_t ver_major, const uint32_t ver_minor, char* dnse, LIBMTP_folder_t* folders, LIBMTP_file_t* files);
+
+static uint32_t discover_id_from_filepath(const char* s, LIBMTP_folder_t* folders, LIBMTP_file_t* files); // TODO add file/dir cached args
+static void discover_filepath_from_id(char** p, uint32_t track, LIBMTP_folder_t* folders, LIBMTP_file_t* files);
+static void find_folder_name(LIBMTP_folder_t* folders, uint32_t* id, char** name);
+static uint32_t find_folder_id(LIBMTP_folder_t* folders, uint32_t parent, char* name);
+
+static void append_text_t(text_t** t, char* s);
+
+
+
+
+/**
+ * Decides if the indicated object index is an .spl playlist.
+ *
+ * @param oi object we are deciding on
+ * @return 1 if this is a Samsung .spl object, 0 otherwise
+ */
+int is_spl_playlist(PTPObjectInfo *oi)
+{
+  return (oi->ObjectFormat == PTP_OFC_Undefined) &&
+         (strlen(oi->Filename) > 4) &&
+         (strcmp((oi->Filename + strlen(oi->Filename) -4), ".spl") == 0);
+}
+
+#ifndef HAVE_MKSTEMP
+# ifdef __WIN32__
+#  include <fcntl.h>
+#  define mkstemp(_pattern) _open(_mktemp(_pattern), _O_CREAT | _O_SHORT_LIVED | _O_EXCL)
+# else
+#  error Missing mkstemp() function.
+# endif
+#endif
+
+/**
+ * Take an object ID, a .spl playlist on the MTP device,
+ * and convert it to a playlist_t object.
+ *
+ * @param device mtp device pointer
+ * @param oi object we are reading
+ * @param id .spl playlist id on MTP device
+ * @param pl the LIBMTP_playlist_t pointer to be filled with info from id
+ */
+
+void spl_to_playlist_t(LIBMTP_mtpdevice_t* device, PTPObjectInfo *oi,
+                       const uint32_t id, LIBMTP_playlist_t * const pl)
+{
+  // Fill in playlist metadata
+  // Use the Filename as the playlist name, dropping the ".spl" extension
+  pl->name = malloc(sizeof(char)*(strlen(oi->Filename) -4 +1));
+  memcpy(pl->name, oi->Filename, strlen(oi->Filename) -4);
+  // Set terminating character
+  pl->name[strlen(oi->Filename) - 4] = 0;
+  pl->playlist_id = id;
+  pl->parent_id = oi->ParentObject;
+  pl->storage_id = oi->StorageID;
+  pl->tracks = NULL;
+  pl->no_tracks = 0;
+
+  IF_DEBUG() printf("pl->name='%s'\n",pl->name);
+
+  // open a temporary file
+  char tmpname[] = "/tmp/mtp-spl2pl-XXXXXX";
+  int fd = mkstemp(tmpname);
+  if(fd < 0) {
+    printf("failed to make temp file for %s.spl -> %s, errno=%s\n", pl->name, tmpname, strerror(errno));
+    return;
+  }
+  // make sure the file will be deleted afterwards
+  if(unlink(tmpname) < 0)
+    printf("failed to delete temp file for %s.spl -> %s, errno=%s\n", pl->name, tmpname, strerror(errno));
+  int ret = LIBMTP_Get_File_To_File_Descriptor(device, pl->playlist_id, fd, NULL, NULL);
+  if( ret < 0 ) {
+    // FIXME     add_ptp_error_to_errorstack(device, ret, "LIBMTP_Get_Playlist: Could not get .spl playlist file.");
+    close(fd);
+    printf("FIXME closed\n");
+  }
+
+  text_t* p = read_into_spl_text_t(device, fd);
+  close(fd);
+
+  // FIXME cache these somewhere else so we don't keep calling this!
+  LIBMTP_folder_t *folders;
+  LIBMTP_file_t *files;
+  folders = LIBMTP_Get_Folder_List(device);
+  files = LIBMTP_Get_Filelisting_With_Callback(device, NULL, NULL);
+
+  // convert the playlist listing to track ids
+  pl->no_tracks = trackno_spl_text_t(p);
+  IF_DEBUG() printf("%u track%s found\n", pl->no_tracks, pl->no_tracks==1?"":"s");
+  pl->tracks = malloc(sizeof(uint32_t)*(pl->no_tracks));
+  tracks_from_spl_text_t(p, pl->tracks, folders, files);
+
+  free_spl_text_t(p);
+
+  // debug: add a break since this is the top level function call
+  IF_DEBUG() printf("------------\n\n");
+}
+
+
+/**
+ * Push a playlist_t onto the device after converting it to a .spl format
+ *
+ * @param device mtp device pointer
+ * @param pl the LIBMTP_playlist_t to convert (pl->playlist_id will be updated
+ *           with the newly created object's id)
+ * @return 0 on success, any other value means failure.
+ */
+int playlist_t_to_spl(LIBMTP_mtpdevice_t *device,
+                      LIBMTP_playlist_t * const pl)
+{
+  text_t* t;
+  LIBMTP_folder_t *folders;
+  LIBMTP_file_t *files;
+  folders = LIBMTP_Get_Folder_List(device);
+  files = LIBMTP_Get_Filelisting_With_Callback(device, NULL, NULL);
+
+  char tmpname[] = "/tmp/mtp-spl2pl-XXXXXX"; // must be a var since mkstemp modifies it
+
+  IF_DEBUG() printf("pl->name='%s'\n",pl->name);
+
+  // open a file descriptor
+  int fd = mkstemp(tmpname);
+  if(fd < 0) {
+    printf("failed to make temp file for %s.spl -> %s, errno=%s\n", pl->name, tmpname, strerror(errno));
+    return -1;
+  }
+  // make sure the file will be deleted afterwards
+  if(unlink(tmpname) < 0)
+    printf("failed to delete temp file for %s.spl -> %s, errno=%s\n", pl->name, tmpname, strerror(errno));
+
+  // decide on which version of the .spl format to use
+  uint32_t ver_major;
+  uint32_t ver_minor = 0;
+  PTP_USB *ptp_usb = (PTP_USB*) device->usbinfo;
+  if(FLAG_PLAYLIST_SPL_V2(ptp_usb)) ver_major = 2;
+  else ver_major = 1; // FLAG_PLAYLIST_SPL_V1()
+
+  IF_DEBUG() printf("%u track%s\n", pl->no_tracks, pl->no_tracks==1?"":"s");
+  IF_DEBUG() printf(".spl version %d.%02d\n", ver_major, ver_minor);
+
+  // create the text for the playlist
+  spl_text_t_from_tracks(&t, pl->tracks, pl->no_tracks, ver_major, ver_minor, NULL, folders, files);
+  write_from_spl_text_t(device, fd, t);
+  free_spl_text_t(t); // done with the text
+
+  // create the file object for storing
+  LIBMTP_file_t* f = malloc(sizeof(LIBMTP_file_t));
+  f->item_id = 0;
+  f->parent_id = pl->parent_id;
+  f->storage_id = pl->storage_id;
+  f->filename = malloc(sizeof(char)*(strlen(pl->name)+5));
+  strcpy(f->filename, pl->name);
+  strcat(f->filename, ".spl"); // append suffix
+  f->filesize = lseek(fd, 0, SEEK_CUR); // file desc is currently at end of file
+  f->filetype = LIBMTP_FILETYPE_UNKNOWN;
+  f->next = NULL;
+
+  IF_DEBUG() printf("%s is %dB\n", f->filename, (int)f->filesize);
+
+  // push the playlist to the device
+  lseek(fd, 0, SEEK_SET); // reset file desc. to start of file
+  int ret = LIBMTP_Send_File_From_File_Descriptor(device, fd, f, NULL, NULL);
+  pl->playlist_id = f->item_id;
+  free(f->filename);
+  free(f);
+
+  // release the memory when we're done with it
+  close(fd);
+  // debug: add a break since this is the top level function call
+  IF_DEBUG() printf("------------\n\n");
+
+  return ret;
+}
+
+
+
+/**
+ * Update a playlist on the device. If only the playlist's name is being
+ * changed the pl->playlist_id will likely remain the same. An updated track
+ * list will result in the old playlist being replaced (ie: new playlist_id).
+ * NOTE: Other playlist metadata aside from playlist name and tracks are
+ * ignored.
+ *
+ * @param device mtp device pointer
+ * @param new the LIBMTP_playlist_t to convert (pl->playlist_id will be updated
+ *           with the newly created object's id)
+ * @return 0 on success, any other value means failure.
+ */
+int update_spl_playlist(LIBMTP_mtpdevice_t *device,
+			  LIBMTP_playlist_t * const newlist)
+{
+  IF_DEBUG() printf("pl->name='%s'\n",newlist->name);
+
+  // read in the playlist of interest
+  LIBMTP_playlist_t * old = LIBMTP_Get_Playlist(device, newlist->playlist_id);
+  
+  // check to see if we found it
+  if (!old)
+    return -1;
+
+  // check if the playlists match
+  int delta = 0;
+  int i;
+  if(old->no_tracks != newlist->no_tracks)
+    delta++;
+  for(i=0;i<newlist->no_tracks && delta==0;i++) {
+    if(old->tracks[i] != newlist->tracks[i])
+      delta++;
+  }
+
+  // if not, kill the playlist and replace it
+  if(delta) {
+    IF_DEBUG() printf("new tracks detected:\n");
+    IF_DEBUG() printf("delete old playlist and build a new one\n");
+    IF_DEBUG() printf(" NOTE: new playlist_id will result!\n");
+    if(LIBMTP_Delete_Object(device, old->playlist_id) != 0)
+      return -1;
+
+    IF_DEBUG() {
+      if(strcmp(old->name,newlist->name) == 0)
+        printf("name unchanged\n");
+      else
+        printf("name is changing too -> %s\n",newlist->name);
+    }
+
+    return LIBMTP_Create_New_Playlist(device, newlist);
+  }
+
+
+  // update the name only
+  if(strcmp(old->name,newlist->name) != 0) {
+    IF_DEBUG() printf("ONLY name is changing -> %s\n",newlist->name);
+    IF_DEBUG() printf("playlist_id will remain unchanged\n");
+    char* s = malloc(sizeof(char)*(strlen(newlist->name)+5));
+    strcpy(s, newlist->name);
+    strcat(s,".spl"); // FIXME check for success
+    int ret = LIBMTP_Set_Playlist_Name(device, newlist, s);
+    free(s);
+    return ret;
+  }
+
+  IF_DEBUG() printf("no change\n");
+  return 0; // nothing to be done, success
+}
+
+
+/**
+ * Load a file descriptor into a string.
+ *
+ * @param device a pointer to the current device.
+ *               (needed for ucs2->utf8 charset conversion)
+ * @param fd the file descriptor to load
+ * @return text_t* a linked list of lines of text, id is left blank, NULL if nothing read in
+ */
+static text_t* read_into_spl_text_t(LIBMTP_mtpdevice_t *device, const int fd)
+{
+  // set MAXREAD to match STRING_BUFFER_LENGTH in unicode.h conversion function
+  const size_t MAXREAD = 1024*2;
+  char t[MAXREAD];
+  // upto 3 bytes per utf8 character, 2 bytes per ucs2 character,
+  // +1 for '\0' at end of string
+  const size_t WSIZE = MAXREAD/2*3+1;
+  char w[WSIZE];
+  char* it = t; // iterator on t
+  char* iw = w;
+  ssize_t rdcnt;
+  off_t offcnt;
+  text_t* head = NULL;
+  text_t* tail = NULL;
+  int eof = 0;
+
+  // reset file descriptor (fd) to start of file
+  offcnt = lseek(fd, 0, SEEK_SET);
+
+  while(!eof) {
+    // find the current offset in the file
+    // to allow us to determine how many bytes we read if we hit the EOF
+    // where returned rdcnt=0 from read()
+    offcnt = lseek(fd, 0, SEEK_CUR);
+    // read to refill buffer
+    // (there might be data left from an incomplete last string in t,
+    // hence start filling at it)
+    it = t; // set ptr to start of buffer
+    rdcnt = read(fd, it, sizeof(char)*MAXREAD);
+    if(rdcnt < 0)
+      printf("load_spl_fd read err %s\n", strerror(errno));
+    else if(rdcnt == 0) { // for EOF, fix rdcnt
+      if(it-t == MAXREAD)
+        printf("error -- buffer too small to read in .spl playlist entry\n");
+
+      rdcnt = lseek(fd, 0, SEEK_CUR) - offcnt;
+      eof = 1;
+    }
+
+    IF_DEBUG() printf("read buff= {%dB new, %dB old/left-over}%s\n",(int)rdcnt, (int)(iw-w), eof?", EOF":"");
+
+    // while more input bytes
+    char* it_end = t + rdcnt;
+    while(it < it_end) {
+      // copy byte, unless EOL (then replace with end-of-string \0)
+      if(*it == '\r' || *it == '\n')
+        *iw = '\0';
+      else
+        *iw = *it;
+
+      it++;
+      iw++;
+
+      // EOL -- store it
+      if( (iw-w) >= 2 && // we must have at least two bytes
+          *(iw-1) == '\0' && *(iw-2) == '\0' && // 0x0000 is end-of-string
+          // but it must be aligned such that we have an {odd,even} set of
+          // bytes since we are expecting to consume bytes two-at-a-time
+          !((iw-w)%2) ) {
+
+        // drop empty lines
+        //  ... cast as a string of 2 byte characters
+        if(ucs2_strlen((uint16_t*)w) == 0) {
+          iw = w;
+          continue;
+        }
+
+        // create a new node in the list
+        if(head == NULL) {
+          head = malloc(sizeof(text_t));
+          tail = head;
+        }
+        else {
+          tail->next = malloc(sizeof(text_t));
+          tail = tail->next;
+        }
+        // fill in the data for the node
+        //  ... cast as a string of 2 byte characters
+        tail->text = utf16_to_utf8(device, (uint16_t*) w);
+        iw = w; // start again
+
+        IF_DEBUG() printf("line: %s\n", tail->text);
+      }
+
+      // prevent buffer overflow
+      if(iw >= w + WSIZE) {
+        // if we ever see this error its BAD:
+        //   we are dropping all the processed bytes for this line and
+        //   proceeding on as if everything is okay, probably losing a track
+        //   from the playlist
+        printf("ERROR %s:%u:%s(): buffer overflow! .spl line too long @ %zuB\n",
+               __FILE__, __LINE__, __func__, WSIZE);
+        iw = w; // reset buffer
+      }
+    }
+
+    // if the last thing we did was save our line, then we finished working
+    // on the input buffer and we can start fresh
+    // otherwise we need to save our partial work, if we're not quiting (eof).
+    // there is nothing special we need to do, to achieve this since the
+    // partially completed string will sit in 'w' until we return to complete
+    // the line
+
+  }
+
+  // set the next pointer at the end
+  // if there is any list
+  if(head != NULL)
+    tail->next = NULL;
+
+  // return the head of the list (NULL if no list)
+  return head;
+}
+
+
+/**
+ * Write a .spl text file to a file in preparation for pushing it
+ * to the device.
+ *
+ * @param fd file descriptor to write to
+ * @param p the text to output one line per string in the linked list
+ * @see playlist_t_to_spl()
+ */
+static void write_from_spl_text_t(LIBMTP_mtpdevice_t *device,
+                                  const int fd,
+                                  text_t* p) {
+  ssize_t ret;
+  // write out BOM for utf16/ucs2 (byte order mark)
+  ret = write(fd,"\xff\xfe",2);
+  while(p != NULL) {
+    char *const t = (char*) utf8_to_utf16(device, p->text);
+    // note: 2 bytes per ucs2 character
+    const size_t len = ucs2_strlen((uint16_t*)t)*sizeof(uint16_t);
+    int i;
+
+    IF_DEBUG() {
+      printf("\nutf8=%s ",p->text);
+      for(i=0;i<strlen(p->text);i++)
+        printf("%02x ", p->text[i] & 0xff);
+      printf("\n");
+      printf("ucs2=");
+      for(i=0;i<ucs2_strlen((uint16_t*)t)*sizeof(uint16_t);i++)
+        printf("%02x ", t[i] & 0xff);
+      printf("\n");
+    }
+
+    // write: utf8 -> utf16
+    ret += write(fd, t, len);
+
+    // release the converted string
+    free(t);
+
+    // check for failures
+    if(ret < 0)
+      printf("write spl file failed: %s\n", strerror(errno));
+    else if(ret != len +2)
+      printf("write spl file wrong number of bytes ret=%d len=%d '%s'\n", (int)ret, (int)len, p->text);
+
+    // write carriage return, line feed in ucs2
+    ret = write(fd, "\r\0\n\0", 4);
+    if(ret < 0)
+      printf("write spl file failed: %s\n", strerror(errno));
+    else if(ret != 4)
+      printf("failed to write the correct number of bytes '\\n'!\n");
+
+    // fake out count (first time through has two extra bytes from BOM)
+    ret = 2;
+
+    // advance to the next line
+    p = p->next;
+  }
+}
+
+/**
+ * Destroy a linked-list of strings.
+ *
+ * @param p the list to destroy
+ * @see spl_to_playlist_t()
+ * @see playlist_t_to_spl()
+ */
+static void free_spl_text_t(text_t* p)
+{
+  text_t* d;
+  while(p != NULL) {
+    d = p;
+    free(p->text);
+    p = p->next;
+    free(d);
+  }
+}
+
+/**
+ * Print a linked-list of strings to stdout.
+ *
+ * @param p the list to print
+ */
+static void print_spl_text_t(text_t* p)
+{
+  while(p != NULL) {
+    printf("%s\n",p->text);
+    p = p->next;
+  }
+}
+
+/**
+ * Count the number of tracks in this playlist. A track will be counted as
+ * such if the line starts with a leading slash.
+ *
+ * @param p the text to search
+ * @return number of tracks in the playlist
+ * @see spl_to_playlist_t()
+ */
+static uint32_t trackno_spl_text_t(text_t* p) {
+  uint32_t c = 0;
+  while(p != NULL) {
+    if(p->text[0] == '\\' ) c++;
+    p = p->next;
+  }
+
+  return c;
+}
+
+/**
+ * Find the track ids for this playlist's files.
+ * (ie: \Music\song.mp3 -> 12345)
+ *
+ * @param p the text to search
+ * @param tracks returned list of track id's for the playlist_t, must be large
+ *               enough to accomodate all the tracks as reported by
+ *               trackno_spl_text_t()
+ * @param folders the folders list for the device
+ * @param fiels the files list for the device
+ * @see spl_to_playlist_t()
+ */
+static void tracks_from_spl_text_t(text_t* p,
+                                   uint32_t* tracks,
+                                   LIBMTP_folder_t* folders,
+                                   LIBMTP_file_t* files)
+{
+  uint32_t c = 0;
+  while(p != NULL) {
+    if(p->text[0] == '\\' ) {
+      tracks[c] = discover_id_from_filepath(p->text, folders, files);
+      IF_DEBUG()
+        printf("track %d = %s (%u)\n", c+1, p->text, tracks[c]);
+      c++;
+    }
+    p = p->next;
+  }
+}
+
+
+/**
+ * Find the track names (including path) for this playlist's track ids.
+ * (ie: 12345 -> \Music\song.mp3)
+ *
+ * @param p the text to search
+ * @param tracks list of track id's to look up
+ * @param folders the folders list for the device
+ * @param fiels the files list for the device
+ * @see playlist_t_to_spl()
+ */
+static void spl_text_t_from_tracks(text_t** p,
+                                   uint32_t* tracks,
+                                   const uint32_t trackno,
+                                   const uint32_t ver_major,
+                                   const uint32_t ver_minor,
+                                   char* dnse,
+                                   LIBMTP_folder_t* folders,
+                                   LIBMTP_file_t* files)
+{
+
+  // HEADER
+  text_t* c = NULL;
+  append_text_t(&c, "SPL PLAYLIST");
+  *p = c; // save the top of the list!
+
+  char vs[14]; // "VERSION 2.00\0"
+  sprintf(vs,"VERSION %d.%02d",ver_major,ver_minor);
+
+  append_text_t(&c, vs);
+  append_text_t(&c, "");
+
+  // TRACKS
+  int i;
+  char* f;
+  for(i=0;i<trackno;i++) {
+    discover_filepath_from_id(&f, tracks[i], folders, files);
+
+    if(f != NULL) {
+      append_text_t(&c, f);
+      IF_DEBUG()
+        printf("track %d = %s (%u)\n", i+1, f, tracks[i]);
+    }
+    else
+      printf("failed to find filepath for track=%d\n", tracks[i]);
+  }
+
+  // FOOTER
+  append_text_t(&c, "");
+  append_text_t(&c, "END PLAYLIST");
+  if(ver_major == 2) {
+    append_text_t(&c, "");
+    append_text_t(&c, "myDNSe DATA");
+    if(dnse != NULL) {
+      append_text_t(&c, dnse);
+    }
+    else {
+      append_text_t(&c, "");
+      append_text_t(&c, "");
+    }
+    append_text_t(&c, "END myDNSe");
+  }
+
+  c->next = NULL;
+
+  // debug
+  IF_DEBUG() {
+    printf(".spl playlist:\n");
+    print_spl_text_t(*p);
+  }
+}
+
+
+/**
+ * Find the track names (including path) given a fileid
+ * (ie: 12345 -> \Music\song.mp3)
+ *
+ * @param p returns the file path (ie: \Music\song.mp3),
+ *          (*p) == NULL if the look up fails
+ * @param track track id to look up
+ * @param folders the folders list for the device
+ * @param files the files list for the device
+ * @see spl_text_t_from_tracks()
+ */
+
+// returns p = NULL on failure, else the filepath to the track including track name, allocated as a correct length string
+static void discover_filepath_from_id(char** p,
+                                      uint32_t track,
+                                      LIBMTP_folder_t* folders,
+                                      LIBMTP_file_t* files)
+{
+  // fill in a string from the right side since we don't know the root till the end
+  const int M = 1024;
+  char w[M];
+  char* iw = w + M; // iterator on w
+
+  // in case of failure return NULL string
+  *p = NULL;
+
+
+  // find the right file
+  while(files != NULL && files->item_id != track) {
+    files = files->next;
+  }
+  // if we didn't find a matching file, abort
+  if(files == NULL)
+    return;
+
+  // stuff the filename into our string
+  // FIXME: check for string overflow before it occurs
+  iw = iw - (strlen(files->filename) +1); // leave room for '\0' at the end
+  strcpy(iw,files->filename);
+
+  // next follow the directories to the root
+  // prepending folders to the path as we go
+  uint32_t id = files->parent_id;
+  char* f = NULL;
+  while(id != 0) {
+    find_folder_name(folders, &id, &f);
+    if(f == NULL) return; // fail if the next part of the path couldn't be found
+    iw = iw - (strlen(f) +1);
+    // FIXME: check for string overflow before it occurs
+    strcpy(iw, f);
+    iw[strlen(f)] = '\\';
+    free(f);
+  }
+
+  // prepend a slash
+  iw--;
+  iw[0] = '\\';
+
+  // now allocate a string of the right length to be returned
+  *p = strdup(iw);
+}
+
+
+/**
+ * Find the track id given a track's name (including path)
+ * (ie: \Music\song.mp3 -> 12345)
+ *
+ * @param s file path to look up (ie: \Music\song.mp3),
+ *          (*p) == NULL if the look up fails
+ * @param folders the folders list for the device
+ * @param files the files list for the device
+ * @return track id, 0 means failure
+ * @see tracks_from_spl_text_t()
+ */
+static uint32_t discover_id_from_filepath(const char* s, LIBMTP_folder_t* folders, LIBMTP_file_t* files)
+{
+  // abort if this isn't a path
+  if(s[0] != '\\')
+    return 0;
+
+  int i;
+  uint32_t id = 0;
+  char* sc = strdup(s);
+  char* sci = sc +1; // iterator
+  // skip leading slash in path
+
+  // convert all \ to \0
+  size_t len = strlen(s);
+  for(i=0;i<len;i++) {
+    if(sc[i] == '\\') {
+      sc[i] = '\0';
+    }
+  }
+
+  // now for each part of the string, find the id
+  while(sci != sc + len +1) {
+    // if its the last part of the string, its the filename
+    if(sci + strlen(sci) == sc + len) {
+
+      while(files != NULL) {
+        // check parent matches id and name matches sci
+        if( (files->parent_id == id) &&
+            (strcmp(files->filename, sci) == 0) ) { // found it!
+          id = files->item_id;
+          break;
+        }
+        files = files->next;
+      }
+    }
+    else { // otherwise its part of the directory path
+      id = find_folder_id(folders, id, sci);
+    }
+
+    // move to next folder/file
+    sci += strlen(sci) +1;
+  }
+
+  // release our copied string
+  free(sc);
+
+  // FIXME check that we actually have a file
+
+  return id;
+}
+
+
+
+/**
+ * Find the folder name given the folder's id.
+ *
+ * @param folders the folders list for the device
+ * @param id the folder_id to look up, returns the folder's parent folder_id
+ * @param name returns the name of the folder or NULL on failure
+ * @see discover_filepath_from_id()
+ */
+static void find_folder_name(LIBMTP_folder_t* folders, uint32_t* id, char** name)
+{
+
+  // FIXME this function is exactly LIBMTP_Find_Folder
+
+  LIBMTP_folder_t* f = LIBMTP_Find_Folder(folders, *id);
+  if(f == NULL) {
+    *name = NULL;
+  }
+  else { // found it!
+    *name = strdup(f->name);
+    *id = f->parent_id;
+  }
+}
+
+
+/**
+ * Find the folder id given the folder's name and parent id.
+ *
+ * @param folders the folders list for the device
+ * @param parent the folder's parent's id
+ * @param name the name of the folder
+ * @return the folder_id or 0 on failure
+ * @see discover_filepath_from_id()
+ */
+static uint32_t find_folder_id(LIBMTP_folder_t* folders, uint32_t parent, char* name) {
+
+  if(folders == NULL)
+    return 0;
+
+  // found it!
+  else if( (folders->parent_id == parent) &&
+           (strcmp(folders->name, name) == 0) )
+    return folders->folder_id;
+
+  // no luck so far, search both siblings and children
+  else {
+    uint32_t id = 0;
+
+    if(folders->sibling != NULL)
+      id = find_folder_id(folders->sibling, parent, name);
+    if( (id == 0) && (folders->child != NULL) )
+      id = find_folder_id(folders->child, parent, name);
+
+    return id;
+  }
+}
+
+
+/**
+ * Append a string to a linked-list of strings.
+ *
+ * @param t the list-of-strings, returns with the added string
+ * @param s the string to append
+ * @see spl_text_t_from_tracks()
+ */
+static void append_text_t(text_t** t, char* s)
+{
+  if(*t == NULL) {
+    *t = malloc(sizeof(text_t));
+  }
+  else {
+    (*t)->next = malloc(sizeof(text_t));
+    (*t) = (*t)->next;
+  }
+  (*t)->text = strdup(s);
+}
diff --git a/src/playlist-spl.h b/src/playlist-spl.h
new file mode 100644
index 0000000..ee00d35
--- /dev/null
+++ b/src/playlist-spl.h
@@ -0,0 +1,35 @@
+/*
+ * \file playlist-spl.h
+ * Playlist to .spl conversion functions.
+ *
+ * Copyright (C) 2008 Alistair Boyle <alistair.js.boyle@gmail.com>
+ *
+ * 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.
+ */
+
+#ifndef __MTP__PLAYLIST_SPL__H
+#define __MTP__PLAYLIST_SPL__H
+
+int is_spl_playlist(PTPObjectInfo *oi);
+
+void spl_to_playlist_t(LIBMTP_mtpdevice_t* device, PTPObjectInfo *oi,
+                       const uint32_t id, LIBMTP_playlist_t * const pl);
+int playlist_t_to_spl(LIBMTP_mtpdevice_t *device,
+                      LIBMTP_playlist_t * const metadata);
+int update_spl_playlist(LIBMTP_mtpdevice_t *device,
+			  LIBMTP_playlist_t * const newlist);
+
+#endif //__MTP__PLAYLIST_SPL__H
diff --git a/src/ptp-pack.c b/src/ptp-pack.c
new file mode 100644
index 0000000..c6a090c
--- /dev/null
+++ b/src/ptp-pack.c
@@ -0,0 +1,1877 @@
+/* currently this file is included into ptp.c */
+
+#ifdef HAVE_ICONV
+#include <iconv.h>
+#endif
+
+extern void
+ptp_debug (PTPParams *params, const char *format, ...);
+
+static inline uint16_t
+htod16p (PTPParams *params, uint16_t var)
+{
+	return ((params->byteorder==PTP_DL_LE)?htole16(var):htobe16(var));
+}
+
+static inline uint32_t
+htod32p (PTPParams *params, uint32_t var)
+{
+	return ((params->byteorder==PTP_DL_LE)?htole32(var):htobe32(var));
+}
+
+static inline void
+htod16ap (PTPParams *params, unsigned char *a, uint16_t val)
+{
+	if (params->byteorder==PTP_DL_LE)
+		htole16a(a,val);
+	else 
+		htobe16a(a,val);
+}
+
+static inline void
+htod32ap (PTPParams *params, unsigned char *a, uint32_t val)
+{
+	if (params->byteorder==PTP_DL_LE)
+		htole32a(a,val);
+	else 
+		htobe32a(a,val);
+}
+
+static inline void
+htod64ap (PTPParams *params, unsigned char *a, uint64_t val)
+{
+	if (params->byteorder==PTP_DL_LE)
+		htole64a(a,val);
+	else 
+		htobe64a(a,val);
+}
+
+static inline uint16_t
+dtoh16p (PTPParams *params, uint16_t var)
+{
+	return ((params->byteorder==PTP_DL_LE)?le16toh(var):be16toh(var));
+}
+
+static inline uint32_t
+dtoh32p (PTPParams *params, uint32_t var)
+{
+	return ((params->byteorder==PTP_DL_LE)?le32toh(var):be32toh(var));
+}
+
+static inline uint64_t
+dtoh64p (PTPParams *params, uint64_t var)
+{
+	return ((params->byteorder==PTP_DL_LE)?le64toh(var):be64toh(var));
+}
+
+static inline uint16_t
+dtoh16ap (PTPParams *params, const unsigned char *a)
+{
+	return ((params->byteorder==PTP_DL_LE)?le16atoh(a):be16atoh(a));
+}
+
+static inline uint32_t
+dtoh32ap (PTPParams *params, const unsigned char *a)
+{
+	return ((params->byteorder==PTP_DL_LE)?le32atoh(a):be32atoh(a));
+}
+
+static inline uint64_t
+dtoh64ap (PTPParams *params, const unsigned char *a)
+{
+	return ((params->byteorder==PTP_DL_LE)?le64atoh(a):be64atoh(a));
+}
+
+#define htod8a(a,x)	*(uint8_t*)(a) = x
+#define htod16a(a,x)	htod16ap(params,a,x)
+#define htod32a(a,x)	htod32ap(params,a,x)
+#define htod64a(a,x)	htod64ap(params,a,x)
+#define htod16(x)	htod16p(params,x)
+#define htod32(x)	htod32p(params,x)
+#define htod64(x)	htod64p(params,x)
+
+#define dtoh8a(x)	(*(uint8_t*)(x))
+#define dtoh16a(a)	dtoh16ap(params,a)
+#define dtoh32a(a)	dtoh32ap(params,a)
+#define dtoh64a(a)	dtoh64ap(params,a)
+#define dtoh16(x)	dtoh16p(params,x)
+#define dtoh32(x)	dtoh32p(params,x)
+#define dtoh64(x)	dtoh64p(params,x)
+
+
+static inline char*
+ptp_unpack_string(PTPParams *params, unsigned char* data, uint16_t offset, uint8_t *len)
+{
+	uint8_t length;
+	uint16_t string[PTP_MAXSTRLEN+1];
+	/* allow for UTF-8: max of 3 bytes per UCS-2 char, plus final null */
+	char loclstr[PTP_MAXSTRLEN*3+1]; 
+	size_t nconv, srclen, destlen;
+	char *src, *dest;
+
+	length = dtoh8a(&data[offset]);	/* PTP_MAXSTRLEN == 255, 8 bit len */
+	*len = length;
+	if (length == 0)		/* nothing to do? */
+		return(NULL);
+
+	/* copy to string[] to ensure correct alignment for iconv(3) */
+	memcpy(string, &data[offset+1], length * sizeof(string[0]));
+	string[length] = 0x0000U;   /* be paranoid!  add a terminator. */
+	loclstr[0] = '\0';
+    
+	/* convert from camera UCS-2 to our locale */
+	src = (char *)string;
+	srclen = length * sizeof(string[0]);
+	dest = loclstr;
+	destlen = sizeof(loclstr)-1;
+	nconv = (size_t)-1;
+#ifdef HAVE_ICONV
+	nconv = iconv(params->cd_ucs2_to_locale, &src, &srclen, 
+			&dest, &destlen);
+#endif
+	if (nconv == (size_t) -1) { /* do it the hard way */
+		int i;
+		/* try the old way, in case iconv is broken */
+		for (i=0;i<length;i++) {
+			if (dtoh16a(&data[offset+1+2*i])>127)
+				loclstr[i] = '?';
+			else
+				loclstr[i] = dtoh16a(&data[offset+1+2*i]);
+		}
+		dest = loclstr+length;
+	}
+	*dest = '\0';
+	loclstr[sizeof(loclstr)-1] = '\0';   /* be safe? */
+	return(strdup(loclstr));
+}
+
+static inline int
+ucs2strlen(uint16_t const * const unicstr)
+{
+	int length;
+	
+	/* Unicode strings are terminated with 2 * 0x00 */
+	for(length = 0; unicstr[length] != 0x0000U; length ++);
+	return length;
+}
+
+
+static inline void
+ptp_pack_string(PTPParams *params, char *string, unsigned char* data, uint16_t offset, uint8_t *len)
+{
+	int packedlen;
+	uint16_t ucs2str[PTP_MAXSTRLEN+1];
+	char *ucs2strp = (char *) ucs2str;
+	size_t convlen = strlen(string);
+
+	/* Cannot exceed 255 (PTP_MAXSTRLEN) since it is a single byte, duh ... */
+	memset(ucs2strp, 0, sizeof(ucs2str));  /* XXX: necessary? */
+#ifdef HAVE_ICONV
+	{ 
+		size_t nconv;
+		size_t convmax = PTP_MAXSTRLEN * 2; /* Includes the terminator */
+		char *stringp = string;
+
+		nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen,
+			&ucs2strp, &convmax);
+		if (nconv == (size_t) -1)
+			ucs2str[0] = 0x0000U;
+	}
+#else
+	{
+		int i;
+		for (i=0;i<convlen;i++) {
+			ucs2str[i] = string[i];
+		}
+		ucs2str[convlen] = 0;
+	}
+#endif
+	/*
+	 * XXX: isn't packedlen just ( (uint16_t *)ucs2strp - ucs2str )?
+	 *      why do we need ucs2strlen()?
+	 */
+	packedlen = ucs2strlen(ucs2str);
+	if (packedlen > PTP_MAXSTRLEN-1) {
+		*len=0;
+		return;
+	}
+	
+	/* number of characters including terminating 0 (PTP standard confirmed) */
+	htod8a(&data[offset],packedlen+1);
+	memcpy(&data[offset+1], &ucs2str[0], packedlen * sizeof(ucs2str[0]));
+	htod16a(&data[offset+packedlen*2+1], 0x0000);  /* terminate 0 */
+
+	/* The returned length is in number of characters */
+	*len = (uint8_t) packedlen+1;
+}
+
+static inline unsigned char *
+ptp_get_packed_stringcopy(PTPParams *params, char *string, uint32_t *packed_size)
+{
+	uint8_t packed[PTP_MAXSTRLEN*2+3], len;
+	size_t plen;
+	unsigned char *retcopy = NULL;
+  
+	if (string == NULL)
+	  ptp_pack_string(params, "", (unsigned char*) packed, 0, &len);
+	else
+	  ptp_pack_string(params, string, (unsigned char*) packed, 0, &len);
+  
+	/* returned length is in characters, then one byte for string length */
+	plen = len*2 + 1;
+	
+	retcopy = malloc(plen);
+	if (!retcopy) {
+		*packed_size = 0;
+		return NULL;
+	}
+	memcpy(retcopy, packed, plen);
+	*packed_size = plen;
+	return (retcopy);
+}
+
+static inline uint32_t
+ptp_unpack_uint32_t_array(PTPParams *params, unsigned char* data, uint16_t offset, uint32_t **array)
+{
+	uint32_t n, i=0;
+
+	n=dtoh32a(&data[offset]);
+	*array = malloc (n*sizeof(uint32_t));
+	while (n>i) {
+		(*array)[i]=dtoh32a(&data[offset+(sizeof(uint32_t)*(i+1))]);
+		i++;
+	}
+	return n;
+}
+
+static inline uint32_t
+ptp_pack_uint32_t_array(PTPParams *params, uint32_t *array, uint32_t arraylen, unsigned char **data )
+{
+	uint32_t i=0;
+
+	*data = malloc ((arraylen+1)*sizeof(uint32_t));
+	htod32a(&(*data)[0],arraylen);
+	for (i=0;i<arraylen;i++)
+		htod32a(&(*data)[sizeof(uint32_t)*(i+1)], array[i]);
+	return (arraylen+1)*sizeof(uint32_t);
+}
+
+static inline uint32_t
+ptp_unpack_uint16_t_array(PTPParams *params, unsigned char* data, uint16_t offset, uint16_t **array)
+{
+	uint32_t n, i=0;
+
+	n=dtoh32a(&data[offset]);
+	*array = malloc (n*sizeof(uint16_t));
+	while (n>i) {
+		(*array)[i]=dtoh16a(&data[offset+(sizeof(uint16_t)*(i+2))]);
+		i++;
+	}
+	return n;
+}
+
+/* DeviceInfo pack/unpack */
+
+#define PTP_di_StandardVersion		 0
+#define PTP_di_VendorExtensionID	 2
+#define PTP_di_VendorExtensionVersion	 6
+#define PTP_di_VendorExtensionDesc	 8
+#define PTP_di_FunctionalMode		 8
+#define PTP_di_OperationsSupported	10
+
+static inline void
+ptp_unpack_DI (PTPParams *params, unsigned char* data, PTPDeviceInfo *di, unsigned int datalen)
+{
+	uint8_t len;
+	unsigned int totallen;
+
+	if (!data) return;
+	if (datalen < 12) return;
+	di->StandardVersion = dtoh16a(&data[PTP_di_StandardVersion]);
+	di->VendorExtensionID =
+		dtoh32a(&data[PTP_di_VendorExtensionID]);
+	di->VendorExtensionVersion =
+		dtoh16a(&data[PTP_di_VendorExtensionVersion]);
+	di->VendorExtensionDesc = 
+		ptp_unpack_string(params, data,
+		PTP_di_VendorExtensionDesc, &len); 
+	totallen=len*2+1;
+	di->FunctionalMode = 
+		dtoh16a(&data[PTP_di_FunctionalMode+totallen]);
+	di->OperationsSupported_len = ptp_unpack_uint16_t_array(params, data,
+		PTP_di_OperationsSupported+totallen,
+		&di->OperationsSupported);
+	totallen=totallen+di->OperationsSupported_len*sizeof(uint16_t)+sizeof(uint32_t);
+	di->EventsSupported_len = ptp_unpack_uint16_t_array(params, data,
+		PTP_di_OperationsSupported+totallen,
+		&di->EventsSupported);
+	totallen=totallen+di->EventsSupported_len*sizeof(uint16_t)+sizeof(uint32_t);
+	di->DevicePropertiesSupported_len =
+		ptp_unpack_uint16_t_array(params, data,
+		PTP_di_OperationsSupported+totallen,
+		&di->DevicePropertiesSupported);
+	totallen=totallen+di->DevicePropertiesSupported_len*sizeof(uint16_t)+sizeof(uint32_t);
+	di->CaptureFormats_len = ptp_unpack_uint16_t_array(params, data,
+		PTP_di_OperationsSupported+totallen,
+		&di->CaptureFormats);
+	totallen=totallen+di->CaptureFormats_len*sizeof(uint16_t)+sizeof(uint32_t);
+	di->ImageFormats_len = ptp_unpack_uint16_t_array(params, data,
+		PTP_di_OperationsSupported+totallen,
+		&di->ImageFormats);
+	totallen=totallen+di->ImageFormats_len*sizeof(uint16_t)+sizeof(uint32_t);
+	di->Manufacturer = ptp_unpack_string(params, data,
+		PTP_di_OperationsSupported+totallen,
+		&len);
+	totallen+=len*2+1;
+	di->Model = ptp_unpack_string(params, data,
+		PTP_di_OperationsSupported+totallen,
+		&len);
+	totallen+=len*2+1;
+	di->DeviceVersion = ptp_unpack_string(params, data,
+		PTP_di_OperationsSupported+totallen,
+		&len);
+	totallen+=len*2+1;
+	di->SerialNumber = ptp_unpack_string(params, data,
+		PTP_di_OperationsSupported+totallen,
+		&len);
+}
+
+static void
+ptp_free_DI (PTPDeviceInfo *di) {
+	if (di->SerialNumber) free (di->SerialNumber);
+	if (di->DeviceVersion) free (di->DeviceVersion);
+	if (di->Model) free (di->Model);
+	if (di->Manufacturer) free (di->Manufacturer);
+	if (di->ImageFormats) free (di->ImageFormats);
+	if (di->CaptureFormats) free (di->CaptureFormats);
+	if (di->VendorExtensionDesc) free (di->VendorExtensionDesc);
+	if (di->OperationsSupported) free (di->OperationsSupported);
+	if (di->EventsSupported) free (di->EventsSupported);
+	if (di->DevicePropertiesSupported) free (di->DevicePropertiesSupported);
+}
+
+/* EOS Device Info unpack */
+static inline void
+ptp_unpack_EOS_DI (PTPParams *params, unsigned char* data, PTPCanonEOSDeviceInfo *di, unsigned int datalen)
+{
+	int totallen = 4;
+	if (datalen < 8) return;
+
+	/* uint32_t struct len - ignore */
+	di->EventsSupported_len = ptp_unpack_uint32_t_array(params, data,
+		totallen, &di->EventsSupported);
+	if (!di->EventsSupported) return;
+	totallen += di->EventsSupported_len*sizeof(uint32_t)+4;
+	if (totallen >= datalen) return;
+
+	di->DevicePropertiesSupported_len = ptp_unpack_uint32_t_array(params, data,
+		totallen, &di->DevicePropertiesSupported);
+	if (!di->DevicePropertiesSupported) return;
+	totallen += di->DevicePropertiesSupported_len*sizeof(uint32_t)+4;
+	if (totallen >= datalen) return;
+
+	di->unk_len = ptp_unpack_uint32_t_array(params, data,
+		totallen, &di->unk);
+	if (!di->unk) return;
+	totallen += di->unk_len*sizeof(uint32_t)+4;
+	return;
+}
+	
+/* ObjectHandles array pack/unpack */
+
+#define PTP_oh				 0
+
+static inline void
+ptp_unpack_OH (PTPParams *params, unsigned char* data, PTPObjectHandles *oh, unsigned int len)
+{
+	if (len) {
+		oh->n = ptp_unpack_uint32_t_array(params, data, PTP_oh, &oh->Handler);
+	} else {
+		oh->n = 0;
+		oh->Handler = NULL;
+	} 
+}
+
+/* StoreIDs array pack/unpack */
+
+#define PTP_sids			 0
+
+static inline void
+ptp_unpack_SIDs (PTPParams *params, unsigned char* data, PTPStorageIDs *sids, unsigned int len)
+{
+	sids->n = ptp_unpack_uint32_t_array(params, data, PTP_sids,
+	&sids->Storage);
+}
+
+/* StorageInfo pack/unpack */
+
+#define PTP_si_StorageType		 0
+#define PTP_si_FilesystemType		 2
+#define PTP_si_AccessCapability		 4
+#define PTP_si_MaxCapability		 6
+#define PTP_si_FreeSpaceInBytes		14
+#define PTP_si_FreeSpaceInImages	22
+#define PTP_si_StorageDescription	26
+
+static inline void
+ptp_unpack_SI (PTPParams *params, unsigned char* data, PTPStorageInfo *si, unsigned int len)
+{
+	uint8_t storagedescriptionlen;
+
+	si->StorageType=dtoh16a(&data[PTP_si_StorageType]);
+	si->FilesystemType=dtoh16a(&data[PTP_si_FilesystemType]);
+	si->AccessCapability=dtoh16a(&data[PTP_si_AccessCapability]);
+	si->MaxCapability=dtoh64a(&data[PTP_si_MaxCapability]);
+	si->FreeSpaceInBytes=dtoh64a(&data[PTP_si_FreeSpaceInBytes]);
+	si->FreeSpaceInImages=dtoh32a(&data[PTP_si_FreeSpaceInImages]);
+	si->StorageDescription=ptp_unpack_string(params, data,
+		PTP_si_StorageDescription, &storagedescriptionlen);
+	si->VolumeLabel=ptp_unpack_string(params, data,
+		PTP_si_StorageDescription+storagedescriptionlen*2+1,
+		&storagedescriptionlen);
+}
+
+/* ObjectInfo pack/unpack */
+
+#define PTP_oi_StorageID		 0
+#define PTP_oi_ObjectFormat		 4
+#define PTP_oi_ProtectionStatus		 6
+#define PTP_oi_ObjectCompressedSize	 8
+#define PTP_oi_ThumbFormat		12
+#define PTP_oi_ThumbCompressedSize	14
+#define PTP_oi_ThumbPixWidth		18
+#define PTP_oi_ThumbPixHeight		22
+#define PTP_oi_ImagePixWidth		26
+#define PTP_oi_ImagePixHeight		30
+#define PTP_oi_ImageBitDepth		34
+#define PTP_oi_ParentObject		38
+#define PTP_oi_AssociationType		42
+#define PTP_oi_AssociationDesc		44
+#define PTP_oi_SequenceNumber		48
+#define PTP_oi_filenamelen		52
+#define PTP_oi_Filename			53
+
+/* the max length assuming zero length dates. We have need 3 */
+/* bytes for these. */
+#define PTP_oi_MaxLen PTP_oi_Filename+(PTP_MAXSTRLEN+1)*2+3
+
+static inline uint32_t
+ptp_pack_OI (PTPParams *params, PTPObjectInfo *oi, unsigned char** oidataptr)
+{
+	unsigned char* oidata;
+	uint8_t filenamelen;
+	uint8_t capturedatelen=0;
+	/* let's allocate some memory first; correct assuming zero length dates */
+	oidata=malloc(PTP_oi_MaxLen);
+	/* the caller should free it after use! */
+#if 0
+	char *capture_date="20020101T010101"; /* XXX Fake date */
+#endif
+	memset (oidata, 0, PTP_oi_MaxLen);
+	htod32a(&oidata[PTP_oi_StorageID],oi->StorageID);
+	htod16a(&oidata[PTP_oi_ObjectFormat],oi->ObjectFormat);
+	htod16a(&oidata[PTP_oi_ProtectionStatus],oi->ProtectionStatus);
+	htod32a(&oidata[PTP_oi_ObjectCompressedSize],oi->ObjectCompressedSize);
+	htod16a(&oidata[PTP_oi_ThumbFormat],oi->ThumbFormat);
+	htod32a(&oidata[PTP_oi_ThumbCompressedSize],oi->ThumbCompressedSize);
+	htod32a(&oidata[PTP_oi_ThumbPixWidth],oi->ThumbPixWidth);
+	htod32a(&oidata[PTP_oi_ThumbPixHeight],oi->ThumbPixHeight);
+	htod32a(&oidata[PTP_oi_ImagePixWidth],oi->ImagePixWidth);
+	htod32a(&oidata[PTP_oi_ImagePixHeight],oi->ImagePixHeight);
+	htod32a(&oidata[PTP_oi_ImageBitDepth],oi->ImageBitDepth);
+	htod32a(&oidata[PTP_oi_ParentObject],oi->ParentObject);
+	htod16a(&oidata[PTP_oi_AssociationType],oi->AssociationType);
+	htod32a(&oidata[PTP_oi_AssociationDesc],oi->AssociationDesc);
+	htod32a(&oidata[PTP_oi_SequenceNumber],oi->SequenceNumber);
+	
+	ptp_pack_string(params, oi->Filename, oidata, PTP_oi_filenamelen, &filenamelen);
+/*
+	filenamelen=(uint8_t)strlen(oi->Filename);
+	htod8a(&req->data[PTP_oi_filenamelen],filenamelen+1);
+	for (i=0;i<filenamelen && i< PTP_MAXSTRLEN; i++) {
+		req->data[PTP_oi_Filename+i*2]=oi->Filename[i];
+	}
+*/
+	/*
+	 *XXX Fake date.
+	 * for example Kodak sets Capture date on the basis of EXIF data.
+	 * Spec says that this field is from perspective of Initiator.
+	 */
+#if 0	/* seems now we don't need any data packed in OI dataset... for now ;)*/
+	capturedatelen=strlen(capture_date);
+	htod8a(&data[PTP_oi_Filename+(filenamelen+1)*2],
+		capturedatelen+1);
+	for (i=0;i<capturedatelen && i< PTP_MAXSTRLEN; i++) {
+		data[PTP_oi_Filename+(i+filenamelen+1)*2+1]=capture_date[i];
+	}
+	htod8a(&data[PTP_oi_Filename+(filenamelen+capturedatelen+2)*2+1],
+		capturedatelen+1);
+	for (i=0;i<capturedatelen && i< PTP_MAXSTRLEN; i++) {
+		data[PTP_oi_Filename+(i+filenamelen+capturedatelen+2)*2+2]=
+		  capture_date[i];
+	}
+#endif
+	/* XXX this function should return dataset length */
+	
+	*oidataptr=oidata;
+	return (PTP_oi_Filename+filenamelen*2+(capturedatelen+1)*3);
+}
+
+static time_t
+ptp_unpack_PTPTIME (const char *str) {
+	char ptpdate[40];
+	char tmp[5];
+	int  ptpdatelen;
+	struct tm tm;
+
+	if (!str)
+		return 0;
+	ptpdatelen = strlen(str);
+	if (ptpdatelen >= sizeof (ptpdate)) {
+		/*ptp_debug (params ,"datelen is larger then size of buffer", ptpdatelen, (int)sizeof(ptpdate));*/
+		return 0;
+	}
+	strcpy (ptpdate, str);
+	if (ptpdatelen<15) {
+		/*ptp_debug (params ,"datelen is less than 15 (%d)", ptpdatelen);*/
+		return 0;
+	}
+
+	memset(&tm,0,sizeof(tm));
+	strncpy (tmp, ptpdate, 4);
+	tmp[4] = 0;
+	tm.tm_year=atoi (tmp) - 1900;
+	strncpy (tmp, ptpdate + 4, 2);
+	tmp[2] = 0;
+	tm.tm_mon = atoi (tmp) - 1;
+	strncpy (tmp, ptpdate + 6, 2);
+	tmp[2] = 0;
+	tm.tm_mday = atoi (tmp);
+	strncpy (tmp, ptpdate + 9, 2);
+	tmp[2] = 0;
+	tm.tm_hour = atoi (tmp);
+	strncpy (tmp, ptpdate + 11, 2);
+	tmp[2] = 0;
+	tm.tm_min = atoi (tmp);
+	strncpy (tmp, ptpdate + 13, 2);
+	tmp[2] = 0;
+	tm.tm_sec = atoi (tmp);
+
+	tm.tm_isdst = -1;
+
+	return mktime (&tm);
+}
+
+static inline void
+ptp_unpack_OI (PTPParams *params, unsigned char* data, PTPObjectInfo *oi, unsigned int len)
+{
+	uint8_t filenamelen;
+	uint8_t capturedatelen;
+	char *capture_date;
+
+	oi->StorageID=dtoh32a(&data[PTP_oi_StorageID]);
+	oi->ObjectFormat=dtoh16a(&data[PTP_oi_ObjectFormat]);
+	oi->ProtectionStatus=dtoh16a(&data[PTP_oi_ProtectionStatus]);
+	oi->ObjectCompressedSize=dtoh32a(&data[PTP_oi_ObjectCompressedSize]);
+	oi->ThumbFormat=dtoh16a(&data[PTP_oi_ThumbFormat]);
+	oi->ThumbCompressedSize=dtoh32a(&data[PTP_oi_ThumbCompressedSize]);
+	oi->ThumbPixWidth=dtoh32a(&data[PTP_oi_ThumbPixWidth]);
+	oi->ThumbPixHeight=dtoh32a(&data[PTP_oi_ThumbPixHeight]);
+	oi->ImagePixWidth=dtoh32a(&data[PTP_oi_ImagePixWidth]);
+	oi->ImagePixHeight=dtoh32a(&data[PTP_oi_ImagePixHeight]);
+	oi->ImageBitDepth=dtoh32a(&data[PTP_oi_ImageBitDepth]);
+	oi->ParentObject=dtoh32a(&data[PTP_oi_ParentObject]);
+	oi->AssociationType=dtoh16a(&data[PTP_oi_AssociationType]);
+	oi->AssociationDesc=dtoh32a(&data[PTP_oi_AssociationDesc]);
+	oi->SequenceNumber=dtoh32a(&data[PTP_oi_SequenceNumber]);
+	oi->Filename= ptp_unpack_string(params, data, PTP_oi_filenamelen, &filenamelen);
+
+	capture_date = ptp_unpack_string(params, data,
+		PTP_oi_filenamelen+filenamelen*2+1, &capturedatelen);
+	/* subset of ISO 8601, without '.s' tenths of second and 
+	 * time zone
+	 */
+	oi->CaptureDate = ptp_unpack_PTPTIME(capture_date);
+	free(capture_date);
+
+	/* now the modification date ... */
+	capture_date = ptp_unpack_string(params, data,
+		PTP_oi_filenamelen+filenamelen*2
+		+capturedatelen*2+2,&capturedatelen);
+	oi->ModificationDate = ptp_unpack_PTPTIME(capture_date);
+	free(capture_date);
+}
+
+/* Custom Type Value Assignement (without Length) macro frequently used below */
+#define CTVAL(target,func) {			\
+	if (total - *offset < sizeof(target))	\
+		return 0;			\
+	target = func(&data[*offset]);		\
+	*offset += sizeof(target);		\
+}
+
+#define RARR(val,member,func)	{			\
+	int n,j;					\
+	if (total - *offset < sizeof(uint32_t))		\
+		return 0;				\
+	n = dtoh32a (&data[*offset]);			\
+	*offset += sizeof(uint32_t);			\
+							\
+	val->a.count = n;				\
+	val->a.v = malloc(sizeof(val->a.v[0])*n);	\
+	if (!val->a.v) return 0;			\
+	for (j=0;j<n;j++)				\
+		CTVAL(val->a.v[j].member, func);	\
+}
+
+static inline int
+ptp_unpack_DPV (
+	PTPParams *params, unsigned char* data, int *offset, int total,
+	PTPPropertyValue* value, uint16_t datatype
+) {
+	switch (datatype) {
+	case PTP_DTC_INT8:
+		CTVAL(value->i8,dtoh8a);
+		break;
+	case PTP_DTC_UINT8:
+		CTVAL(value->u8,dtoh8a);
+		break;
+	case PTP_DTC_INT16:
+		CTVAL(value->i16,dtoh16a);
+		break;
+	case PTP_DTC_UINT16:
+		CTVAL(value->u16,dtoh16a);
+		break;
+	case PTP_DTC_INT32:
+		CTVAL(value->i32,dtoh32a);
+		break;
+	case PTP_DTC_UINT32:
+		CTVAL(value->u32,dtoh32a);
+		break;
+	case PTP_DTC_INT64:
+		CTVAL(value->i64,dtoh64a);
+		break;
+	case PTP_DTC_UINT64:
+		CTVAL(value->u64,dtoh64a);
+		break;
+
+	case PTP_DTC_UINT128:
+		*offset += 16;
+		/*fprintf(stderr,"unhandled unpack of uint128n");*/
+		break;
+	case PTP_DTC_INT128:
+		*offset += 16;
+		/*fprintf(stderr,"unhandled unpack of int128n");*/
+		break;
+
+
+
+	case PTP_DTC_AINT8:
+		RARR(value,i8,dtoh8a);
+		break;
+	case PTP_DTC_AUINT8:
+		RARR(value,u8,dtoh8a);
+		break;
+	case PTP_DTC_AUINT16:
+		RARR(value,u16,dtoh16a);
+		break;
+	case PTP_DTC_AINT16:
+		RARR(value,i16,dtoh16a);
+		break;
+	case PTP_DTC_AUINT32:
+		RARR(value,u32,dtoh32a);
+		break;
+	case PTP_DTC_AINT32:
+		RARR(value,i32,dtoh32a);
+		break;
+	case PTP_DTC_AUINT64:
+		RARR(value,u64,dtoh64a);
+		break;
+	case PTP_DTC_AINT64:
+		RARR(value,i64,dtoh64a);
+		break;
+	/* XXX: other int types are unimplemented */
+	/* XXX: other int arrays are unimplemented also */
+	case PTP_DTC_STR: {
+		uint8_t len;
+		/* XXX: max size */
+		value->str = ptp_unpack_string(params,data,*offset,&len);
+		*offset += len*2+1;
+		if (!value->str)
+			return 1;
+		break;
+	}
+	default:
+		return 0;
+	}
+	return 1;
+}
+
+/* Device Property pack/unpack */
+
+#define PTP_dpd_DevicePropertyCode	0
+#define PTP_dpd_DataType		2
+#define PTP_dpd_GetSet			4
+#define PTP_dpd_FactoryDefaultValue	5
+
+static inline int
+ptp_unpack_DPD (PTPParams *params, unsigned char* data, PTPDevicePropDesc *dpd, unsigned int dpdlen)
+{
+	int offset=0, ret;
+
+	memset (dpd, 0, sizeof(*dpd));
+	dpd->DevicePropertyCode=dtoh16a(&data[PTP_dpd_DevicePropertyCode]);
+	dpd->DataType=dtoh16a(&data[PTP_dpd_DataType]);
+	dpd->GetSet=dtoh8a(&data[PTP_dpd_GetSet]);
+	dpd->FormFlag=PTP_DPFF_None;
+
+	offset = PTP_dpd_FactoryDefaultValue;
+	ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FactoryDefaultValue, dpd->DataType);
+	if (!ret) goto outofmemory;
+	if ((dpd->DataType == PTP_DTC_STR) && (offset == dpdlen))
+		return 1;
+	ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->CurrentValue, dpd->DataType);
+	if (!ret) goto outofmemory;
+
+	/* if offset==0 then Data Type format is not supported by this
+	   code or the Data Type is a string (with two empty strings as
+	   values). In both cases Form Flag should be set to 0x00 and FORM is
+	   not present. */
+
+	if (offset==PTP_dpd_FactoryDefaultValue)
+		return 1;
+
+	dpd->FormFlag=dtoh8a(&data[offset]);
+	offset+=sizeof(uint8_t);
+
+	switch (dpd->FormFlag) {
+	case PTP_DPFF_Range:
+		ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FORM.Range.MinimumValue, dpd->DataType);
+		if (!ret) goto outofmemory;
+		ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FORM.Range.MaximumValue, dpd->DataType);
+		if (!ret) goto outofmemory;
+		ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FORM.Range.StepSize, dpd->DataType);
+		if (!ret) goto outofmemory;
+		break;
+	case PTP_DPFF_Enumeration: {
+		int i;
+#define N	dpd->FORM.Enum.NumberOfValues
+		N = dtoh16a(&data[offset]);
+		offset+=sizeof(uint16_t);
+		dpd->FORM.Enum.SupportedValue = malloc(N*sizeof(dpd->FORM.Enum.SupportedValue[0]));
+		if (!dpd->FORM.Enum.SupportedValue)
+			goto outofmemory;
+
+		memset (dpd->FORM.Enum.SupportedValue,0 , N*sizeof(dpd->FORM.Enum.SupportedValue[0]));
+		for (i=0;i<N;i++) {
+			ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FORM.Enum.SupportedValue[i], dpd->DataType);
+
+			/* Slightly different handling here. The HP PhotoSmart 120
+			 * specifies an enumeration with N in wrong endian
+			 * 00 01 instead of 01 00, so we count the enum just until the
+			 * the end of the packet.
+			 */
+			if (!ret) {
+				if (!i)
+					goto outofmemory;
+				dpd->FORM.Enum.NumberOfValues = i;
+				break;
+			}
+		}
+		}
+	}
+#undef N
+	return 1;
+outofmemory:
+	ptp_free_devicepropdesc(dpd);
+	return 0;
+}
+
+/* (MTP) Object Property pack/unpack */
+#define PTP_opd_ObjectPropertyCode	0
+#define PTP_opd_DataType		2
+#define PTP_opd_GetSet			4
+#define PTP_opd_FactoryDefaultValue	5
+
+static inline int
+ptp_unpack_OPD (PTPParams *params, unsigned char* data, PTPObjectPropDesc *opd, unsigned int opdlen)
+{
+	int offset=0, ret;
+
+	memset (opd, 0, sizeof(*opd));
+	opd->ObjectPropertyCode=dtoh16a(&data[PTP_opd_ObjectPropertyCode]);
+	opd->DataType=dtoh16a(&data[PTP_opd_DataType]);
+	opd->GetSet=dtoh8a(&data[PTP_opd_GetSet]);
+
+	offset = PTP_opd_FactoryDefaultValue;
+	ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FactoryDefaultValue, opd->DataType);
+	if (!ret) goto outofmemory;
+
+	opd->GroupCode=dtoh32a(&data[offset]);
+	offset+=sizeof(uint32_t);
+
+	opd->FormFlag=dtoh8a(&data[offset]);
+	offset+=sizeof(uint8_t);
+
+	switch (opd->FormFlag) {
+	case PTP_OPFF_Range:
+		ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.Range.MinimumValue, opd->DataType);
+		if (!ret) goto outofmemory;
+		ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.Range.MaximumValue, opd->DataType);
+		if (!ret) goto outofmemory;
+		ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.Range.StepSize, opd->DataType);
+		if (!ret) goto outofmemory;
+		break;
+	case PTP_OPFF_Enumeration: {
+		int i;
+#define N	opd->FORM.Enum.NumberOfValues
+		N = dtoh16a(&data[offset]);
+		offset+=sizeof(uint16_t);
+		opd->FORM.Enum.SupportedValue = malloc(N*sizeof(opd->FORM.Enum.SupportedValue[0]));
+		if (!opd->FORM.Enum.SupportedValue)
+			goto outofmemory;
+
+		memset (opd->FORM.Enum.SupportedValue,0 , N*sizeof(opd->FORM.Enum.SupportedValue[0]));
+		for (i=0;i<N;i++) {
+			ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.Enum.SupportedValue[i], opd->DataType);
+
+			/* Slightly different handling here. The HP PhotoSmart 120
+			 * specifies an enumeration with N in wrong endian
+			 * 00 01 instead of 01 00, so we count the enum just until the
+			 * the end of the packet.
+			 */
+			if (!ret) {
+				if (!i)
+					goto outofmemory;
+				opd->FORM.Enum.NumberOfValues = i;
+				break;
+			}
+		}
+#undef N
+		}
+	}
+	return 1;
+outofmemory:
+	ptp_free_objectpropdesc(opd);
+	return 0;
+}
+
+
+static inline uint32_t
+ptp_pack_DPV (PTPParams *params, PTPPropertyValue* value, unsigned char** dpvptr, uint16_t datatype)
+{
+	unsigned char* dpv=NULL;
+	uint32_t size=0;
+	int	i;
+
+	switch (datatype) {
+	case PTP_DTC_INT8:
+		size=sizeof(int8_t);
+		dpv=malloc(size);
+		htod8a(dpv,value->i8);
+		break;
+	case PTP_DTC_UINT8:
+		size=sizeof(uint8_t);
+		dpv=malloc(size);
+		htod8a(dpv,value->u8);
+		break;
+	case PTP_DTC_INT16:
+		size=sizeof(int16_t);
+		dpv=malloc(size);
+		htod16a(dpv,value->i16);
+		break;
+	case PTP_DTC_UINT16:
+		size=sizeof(uint16_t);
+		dpv=malloc(size);
+		htod16a(dpv,value->u16);
+		break;
+	case PTP_DTC_INT32:
+		size=sizeof(int32_t);
+		dpv=malloc(size);
+		htod32a(dpv,value->i32);
+		break;
+	case PTP_DTC_UINT32:
+		size=sizeof(uint32_t);
+		dpv=malloc(size);
+		htod32a(dpv,value->u32);
+		break;
+	case PTP_DTC_INT64:
+		size=sizeof(int64_t);
+		dpv=malloc(size);
+		htod64a(dpv,value->i64);
+		break;
+	case PTP_DTC_UINT64:
+		size=sizeof(uint64_t);
+		dpv=malloc(size);
+		htod64a(dpv,value->u64);
+		break;
+	case PTP_DTC_AUINT8:
+		size=sizeof(uint32_t)+value->a.count*sizeof(uint8_t);
+		dpv=malloc(size);
+		htod32a(dpv,value->a.count);
+		for (i=0;i<value->a.count;i++)
+			htod8a(&dpv[sizeof(uint32_t)+i*sizeof(uint8_t)],value->a.v[i].u8);
+		break;
+	case PTP_DTC_AINT8:
+		size=sizeof(uint32_t)+value->a.count*sizeof(int8_t);
+		dpv=malloc(size);
+		htod32a(dpv,value->a.count);
+		for (i=0;i<value->a.count;i++)
+			htod8a(&dpv[sizeof(uint32_t)+i*sizeof(int8_t)],value->a.v[i].i8);
+		break;
+	case PTP_DTC_AUINT16:
+		size=sizeof(uint32_t)+value->a.count*sizeof(uint16_t);
+		dpv=malloc(size);
+		htod32a(dpv,value->a.count);
+		for (i=0;i<value->a.count;i++)
+			htod16a(&dpv[sizeof(uint32_t)+i*sizeof(uint16_t)],value->a.v[i].u16);
+		break;
+	case PTP_DTC_AINT16:
+		size=sizeof(uint32_t)+value->a.count*sizeof(int16_t);
+		dpv=malloc(size);
+		htod32a(dpv,value->a.count);
+		for (i=0;i<value->a.count;i++)
+			htod16a(&dpv[sizeof(uint32_t)+i*sizeof(int16_t)],value->a.v[i].i16);
+		break;
+	case PTP_DTC_AUINT32:
+		size=sizeof(uint32_t)+value->a.count*sizeof(uint32_t);
+		dpv=malloc(size);
+		htod32a(dpv,value->a.count);
+		for (i=0;i<value->a.count;i++)
+			htod32a(&dpv[sizeof(uint32_t)+i*sizeof(uint32_t)],value->a.v[i].u32);
+		break;
+	case PTP_DTC_AINT32:
+		size=sizeof(uint32_t)+value->a.count*sizeof(int32_t);
+		dpv=malloc(size);
+		htod32a(dpv,value->a.count);
+		for (i=0;i<value->a.count;i++)
+			htod32a(&dpv[sizeof(uint32_t)+i*sizeof(int32_t)],value->a.v[i].i32);
+		break;
+	case PTP_DTC_AUINT64:
+		size=sizeof(uint32_t)+value->a.count*sizeof(uint64_t);
+		dpv=malloc(size);
+		htod32a(dpv,value->a.count);
+		for (i=0;i<value->a.count;i++)
+			htod64a(&dpv[sizeof(uint32_t)+i*sizeof(uint64_t)],value->a.v[i].u64);
+		break;
+	case PTP_DTC_AINT64:
+		size=sizeof(uint32_t)+value->a.count*sizeof(int64_t);
+		dpv=malloc(size);
+		htod32a(dpv,value->a.count);
+		for (i=0;i<value->a.count;i++)
+			htod64a(&dpv[sizeof(uint32_t)+i*sizeof(int64_t)],value->a.v[i].i64);
+		break;
+	/* XXX: other int types are unimplemented */
+	case PTP_DTC_STR: {
+		dpv=ptp_get_packed_stringcopy(params, value->str, &size);
+		break;
+	}
+	}
+	*dpvptr=dpv;
+	return size;
+}
+
+#define MAX_MTP_PROPS 127
+static inline uint32_t
+ptp_pack_OPL (PTPParams *params, MTPProperties *props, int nrofprops, unsigned char** opldataptr)
+{
+	unsigned char* opldata;
+	MTPProperties *propitr;
+	unsigned char *packedprops[MAX_MTP_PROPS];
+	uint32_t packedpropslens[MAX_MTP_PROPS];
+	uint32_t packedobjecthandles[MAX_MTP_PROPS];
+	uint16_t packedpropsids[MAX_MTP_PROPS];
+	uint16_t packedpropstypes[MAX_MTP_PROPS];
+	uint32_t totalsize = 0;
+	uint32_t bufp = 0;
+	uint32_t noitems = 0;
+	uint32_t i;
+
+	totalsize = sizeof(uint32_t); /* 4 bytes to store the number of elements */
+	propitr = props;
+	while (nrofprops-- && noitems < MAX_MTP_PROPS) {
+		/* Object Handle */
+		packedobjecthandles[noitems]=propitr->ObjectHandle;
+		totalsize += sizeof(uint32_t); /* Object ID */
+		/* Metadata type */
+		packedpropsids[noitems]=propitr->property;
+		totalsize += sizeof(uint16_t);
+		/* Data type */
+		packedpropstypes[noitems]= propitr->datatype;
+		totalsize += sizeof(uint16_t);
+		/* Add each property to be sent. */
+	        packedpropslens[noitems] = ptp_pack_DPV (params, &propitr->propval, &packedprops[noitems], propitr->datatype);
+		totalsize += packedpropslens[noitems];
+		noitems ++;
+		propitr ++;
+	}
+
+	/* Allocate memory for the packed property list */
+	opldata = malloc(totalsize);
+
+	htod32a(&opldata[bufp],noitems);
+	bufp += 4;
+
+	/* Copy into a nice packed list */
+	for (i = 0; i < noitems; i++) {
+		/* Object ID */
+		htod32a(&opldata[bufp],packedobjecthandles[i]);
+		bufp += sizeof(uint32_t);
+		htod16a(&opldata[bufp],packedpropsids[i]);
+		bufp += sizeof(uint16_t);
+		htod16a(&opldata[bufp],packedpropstypes[i]);
+		bufp += sizeof(uint16_t);
+		/* The copy the actual property */
+		memcpy(&opldata[bufp], packedprops[i], packedpropslens[i]);
+		bufp += packedpropslens[i];
+		free(packedprops[i]);
+	}
+	*opldataptr = opldata;
+	return totalsize;
+}
+
+static int
+_compare_func(const void* x, const void *y) {
+	const MTPProperties *px = x;
+	const MTPProperties *py = y;
+
+	return px->ObjectHandle - py->ObjectHandle;
+}
+
+static inline int
+ptp_unpack_OPL (PTPParams *params, unsigned char* data, MTPProperties **pprops, unsigned int len)
+{ 
+	uint32_t prop_count = dtoh32a(data);
+	MTPProperties *props = NULL;
+	int offset = 0, i;
+
+	if (prop_count == 0) {
+		*pprops = NULL;
+		return 0;
+	}
+	ptp_debug (params ,"Unpacking MTP OPL, size %d (prop_count %d)", len, prop_count);
+	data += sizeof(uint32_t);
+	len -= sizeof(uint32_t);
+	props = malloc(prop_count * sizeof(MTPProperties));
+	if (!props) return 0;
+	for (i = 0; i < prop_count; i++) {
+		if (len <= 0) {
+			ptp_debug (params ,"short MTP Object Property List at property %d (of %d)", i, prop_count);
+			ptp_debug (params ,"device probably needs DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL", i);
+			ptp_debug (params ,"or even DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST", i);
+			qsort (props, i, sizeof(MTPProperties),_compare_func);
+			*pprops = props;
+			return i;
+		}
+		props[i].ObjectHandle = dtoh32a(data);
+		data += sizeof(uint32_t);
+		len -= sizeof(uint32_t);
+
+		props[i].property = dtoh16a(data);
+		data += sizeof(uint16_t);
+		len -= sizeof(uint16_t);
+
+		props[i].datatype = dtoh16a(data);
+		data += sizeof(uint16_t);
+		len -= sizeof(uint16_t);
+
+		offset = 0;
+		ptp_unpack_DPV(params, data, &offset, len, &props[i].propval, props[i].datatype);
+		data += offset;
+		len -= offset;
+	}
+	qsort (props, prop_count, sizeof(MTPProperties),_compare_func);
+	*pprops = props;
+	return prop_count;
+}
+
+/*
+    PTP USB Event container unpack
+    Copyright (c) 2003 Nikolai Kopanygin
+*/
+
+#define PTP_ec_Length		0
+#define PTP_ec_Type		4
+#define PTP_ec_Code		6
+#define PTP_ec_TransId		8
+#define PTP_ec_Param1		12
+#define PTP_ec_Param2		16
+#define PTP_ec_Param3		20
+
+static inline void
+ptp_unpack_EC (PTPParams *params, unsigned char* data, PTPContainer *ec, unsigned int len)
+{
+	int	length;
+	int	type;
+
+	if (data==NULL)
+		return;
+	memset(ec,0,sizeof(*ec));
+	length=dtoh32a(&data[PTP_ec_Length]);
+	type = dtoh16a(&data[PTP_ec_Type]);
+
+	ec->Code=dtoh16a(&data[PTP_ec_Code]);
+	ec->Transaction_ID=dtoh32a(&data[PTP_ec_TransId]);
+
+	if (type!=PTP_USB_CONTAINER_EVENT) {
+		ptp_debug (params, "Unknown canon event type %d (code=%x,tid=%x), please report!",type,ec->Code,ec->Transaction_ID);
+		return;
+	}
+	if (length>=(PTP_ec_Param1+4)) {
+		ec->Param1=dtoh32a(&data[PTP_ec_Param1]);
+		ec->Nparam=1;
+	}
+	if (length>=(PTP_ec_Param2+4)) {
+		ec->Param2=dtoh32a(&data[PTP_ec_Param2]);
+		ec->Nparam=2;
+	}
+	if (length>=(PTP_ec_Param3+4)) {
+		ec->Param3=dtoh32a(&data[PTP_ec_Param3]);
+		ec->Nparam=3;
+	}
+}
+
+/*
+    PTP Canon Folder Entry unpack
+    Copyright (c) 2003 Nikolai Kopanygin
+*/
+#define PTP_cfe_ObjectHandle		0
+#define PTP_cfe_ObjectFormatCode	4
+#define PTP_cfe_Flags			6
+#define PTP_cfe_ObjectSize		7
+#define PTP_cfe_Time			11
+#define PTP_cfe_Filename		15
+
+static inline void
+ptp_unpack_Canon_FE (PTPParams *params, unsigned char* data, PTPCANONFolderEntry *fe)
+{
+	int i;
+	if (data==NULL)
+		return;
+	fe->ObjectHandle=dtoh32a(&data[PTP_cfe_ObjectHandle]);
+	fe->ObjectFormatCode=dtoh16a(&data[PTP_cfe_ObjectFormatCode]);
+	fe->Flags=dtoh8a(&data[PTP_cfe_Flags]);
+	fe->ObjectSize=dtoh32a((unsigned char*)&data[PTP_cfe_ObjectSize]);
+	fe->Time=(time_t)dtoh32a(&data[PTP_cfe_Time]);
+	for (i=0; i<PTP_CANON_FilenameBufferLen; i++)
+		fe->Filename[i]=(char)dtoh8a(&data[PTP_cfe_Filename+i]);
+}
+
+static inline uint16_t
+ptp_unpack_EOS_ImageFormat (PTPParams* params, unsigned char** data )
+{
+	/*
+	  EOS ImageFormat entries (of at least the 5DMII and the 400D ) look like this:
+		uint32: number of entries / generated files (1 or 2)
+		uint32: size of this entry in bytes (most likely allways 0x10)
+		uint32: image type (1 == JPG, 6 == RAW)
+		uint32: image size (0 == Large, 1 == Medium, 2 == Small)
+		uint32: image compression (2 == Standard/JPG, 3 == Fine/JPG, 4 == Lossles/RAW)
+	  If number of entries is 2 the last uint32 repeat.
+
+	  example:
+		0: 0x       1
+		1: 0x      10
+		2: 0x       6
+		3: 0x       1
+		4: 0x       4
+
+	  The idea is to simply 'condense' these values to just one uint16 to be able to conveniontly
+	  use the available enumeration facilities (look-up table). The image size and compression
+	  values fully describe the image format. Hence we generate a uint16 with the four nibles set
+	  as follows: entry 1 size | entry 1 compression | entry 2 size | entry 2 compression.
+	  The above example would result in the value 0x1400.
+	  */
+
+	const unsigned char* d = *data;
+	uint32_t n = dtoh32a( d );
+	uint32_t l, s1, c1, s2 = 0, c2 = 0;
+
+	if (n != 1 && n !=2) {
+		ptp_debug (params, "parsing EOS ImageFormat property failed (n != 1 && n != 2: %d)", n);
+		return 0;
+	}
+
+	l = dtoh32a( d+=4 );
+	if (l != 0x10) {
+		ptp_debug (params, "parsing EOS ImageFormat property failed (l != 0x10: 0x%x)", l);
+		return 0;
+	}
+
+	d+=4; /* skip type */
+	s1 = dtoh32a( d+=4 );
+	c1 = dtoh32a( d+=4 );
+
+	if (n == 2) {
+		l = dtoh32a( d+=4 );
+		if (l != 0x10) {
+			ptp_debug (params, "parsing EOS ImageFormat property failed (l != 0x10: 0x%x)", l);
+			return 0;
+		}
+		d+=4; /* skip type */
+		s2 = dtoh32a( d+=4 );
+		c2 = dtoh32a( d+=4 );
+	}
+
+	*data = (unsigned char*) d+4;
+
+	return ((s1 & 0xF) << 12) | ((c1 & 0xF) << 8) | ((s2 & 0xF) << 4) | ((c2 & 0xF) << 0);
+}
+
+static inline uint32_t
+ptp_pack_EOS_ImageFormat (PTPParams* params, unsigned char* data, uint16_t value)
+{
+	uint32_t n = (value & 0xFF) ? 2 : 1;
+	uint32_t s = 4 + 0x10 * n;
+
+	if( !data )
+		return s;
+
+	htod32a(data+=0, n);
+	htod32a(data+=4, 0x10);
+	htod32a(data+=4, ((value >> 8) & 0xF) == 4 ? 6 : 1);
+	htod32a(data+=4, (value >> 12) & 0xF);
+	htod32a(data+=4, (value >> 8) & 0xF);
+
+	if (n==2) {
+		htod32a(data+=4, 0x10);
+		htod32a(data+=4, ((value >> 0) & 0xF) == 4 ? 6 : 1);
+		htod32a(data+=4, (value >> 4) & 0xF);
+		htod32a(data+=4, (value >> 0) & 0xF);
+	}
+
+	return s;
+}
+
+/*
+    PTP EOS Changes Entry unpack
+*/
+#define PTP_ece_Size		0
+#define PTP_ece_Type		4
+
+#define PTP_ece_Prop_Subtype	8	/* only for properties */
+#define PTP_ece_Prop_Val_Data	0xc	/* only for properties */
+#define PTP_ece_Prop_Desc_Type	0xc	/* only for property descs */
+#define PTP_ece_Prop_Desc_Count	0x10	/* only for property descs */
+#define PTP_ece_Prop_Desc_Data	0x14	/* only for property descs */
+
+/* for PTP_EC_CANON_EOS_RequestObjectTransfer */
+#define PTP_ece_OI_ObjectID	8
+#define PTP_ece_OI_OFC		0x0c
+#define PTP_ece_OI_Size		0x14
+#define PTP_ece_OI_Name		0x1c
+
+/* for PTP_EC_CANON_EOS_ObjectAddedEx */
+#define PTP_ece_OA_ObjectID	8
+#define PTP_ece_OA_StorageID	0x0c
+#define PTP_ece_OA_OFC		0x10
+#define PTP_ece_OA_Size		0x1c
+#define PTP_ece_OA_Parent	0x20
+#define PTP_ece_OA_Name		0x28
+
+static inline int
+ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize, PTPCanon_changes_entry **ce)
+{
+	int	i = 0, entries = 0;
+	unsigned char	*curdata = data;
+
+	if (data==NULL)
+		return 0;
+	while (curdata - data < datasize) {
+		uint32_t	size = dtoh32a(&curdata[PTP_ece_Size]);
+		uint32_t	type = dtoh32a(&curdata[PTP_ece_Type]);
+
+		curdata += size;
+		if ((size == 8) && (type == 0))
+			break;
+		entries++;
+	}
+	*ce = malloc (sizeof(PTPCanon_changes_entry)*(entries+1));
+	if (!*ce) return 0;
+
+	curdata = data;
+	while (curdata - data < datasize) {
+		uint32_t	size = dtoh32a(&curdata[PTP_ece_Size]);
+		uint32_t	type = dtoh32a(&curdata[PTP_ece_Type]);
+
+		(*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
+		switch (type) {
+		case  PTP_EC_CANON_EOS_ObjectAddedEx:
+			(*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO;
+			(*ce)[i].u.object.oid    		= dtoh32a(&curdata[PTP_ece_OA_ObjectID]);
+			(*ce)[i].u.object.oi.StorageID 		= dtoh32a(&curdata[PTP_ece_OA_StorageID]);
+			(*ce)[i].u.object.oi.ParentObject	= dtoh32a(&curdata[PTP_ece_OA_Parent]);
+			(*ce)[i].u.object.oi.ObjectFormat 	= dtoh16a(&curdata[PTP_ece_OA_OFC]);
+			(*ce)[i].u.object.oi.ObjectCompressedSize= dtoh32a(&curdata[PTP_ece_OA_Size]);
+			(*ce)[i].u.object.oi.Filename 		= strdup(((char*)&curdata[PTP_ece_OA_Name]));
+			ptp_debug (params, "event %d: objectinfo added oid %08lx, parent %08lx, ofc %04x, size %d, filename %s", i, (*ce)[i].u.object.oid, (*ce)[i].u.object.oi.ParentObject, (*ce)[i].u.object.oi.ObjectFormat, (*ce)[i].u.object.oi.ObjectCompressedSize, (*ce)[i].u.object.oi.Filename);
+			break;
+		case  PTP_EC_CANON_EOS_RequestObjectTransfer:
+			(*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTTRANSFER;
+			(*ce)[i].u.object.oid    		= dtoh32a(&curdata[PTP_ece_OI_ObjectID]);
+			(*ce)[i].u.object.oi.StorageID 		= 0; /* use as marker */
+			(*ce)[i].u.object.oi.ObjectFormat 	= dtoh16a(&curdata[PTP_ece_OI_OFC]);
+			(*ce)[i].u.object.oi.ParentObject	= 0; /* check, but use as marker */
+			(*ce)[i].u.object.oi.ObjectCompressedSize = dtoh32a(&curdata[PTP_ece_OI_Size]);
+			(*ce)[i].u.object.oi.Filename 		= strdup(((char*)&curdata[PTP_ece_OI_Name]));
+
+			ptp_debug (params, "event %d: request object transfer oid %08lx, ofc %04x, size %d, filename %s", i, (*ce)[i].u.object.oid, (*ce)[i].u.object.oi.ObjectFormat, (*ce)[i].u.object.oi.ObjectCompressedSize, (*ce)[i].u.object.oi.Filename);
+			break;
+		case  PTP_EC_CANON_EOS_AvailListChanged: {	/* property desc */
+			uint32_t	proptype = dtoh32a(&curdata[PTP_ece_Prop_Subtype]);
+			uint32_t	propxtype = dtoh32a(&curdata[PTP_ece_Prop_Desc_Type]);
+			uint32_t	propxcnt = dtoh32a(&curdata[PTP_ece_Prop_Desc_Count]);
+			unsigned char	*data = &curdata[PTP_ece_Prop_Desc_Data];
+			int		j;
+			PTPDevicePropDesc	*dpd;
+
+			ptp_debug (params, "event %d: EOS prop %04x desc record, datasize %d, propxtype %d", i, proptype, size-PTP_ece_Prop_Desc_Data, propxtype);
+			for (j=0;j<params->nrofcanon_props;j++)
+				if (params->canon_props[j].proptype == proptype)
+					break;
+			if (j==params->nrofcanon_props) {
+				ptp_debug (params, "event %d: propdesc %x, default value not found.", i, proptype);
+				break;
+			}
+			dpd = &params->canon_props[j].dpd;
+			/* 1 - uint16 ? 
+			 * 3 - uint16
+			 * 7 - string?
+			 */
+			if (propxtype != 3) {
+				ptp_debug (params, "event %d: propxtype is %x for %04x, unhandled.", i, propxtype, proptype);
+				for (j=0;j<size-PTP_ece_Prop_Desc_Data;j++)
+					ptp_debug (params, "    %d: %02x", j, data[j]);
+				break;
+			}
+			if (! propxcnt)
+				break;
+
+			ptp_debug (params, "event %d: propxtype is %x, prop is 0x%04x, data type is 0x%04x, propxcnt is %d.",
+				   i, propxtype, proptype, dpd->DataType, propxcnt);
+			dpd->FormFlag = PTP_DPFF_Enumeration;
+			dpd->FORM.Enum.NumberOfValues = propxcnt;
+			dpd->FORM.Enum.SupportedValue = malloc (sizeof (PTPPropertyValue)*propxcnt);
+
+			switch (proptype) {
+			case PTP_DPC_CANON_EOS_ImageFormat:
+			case PTP_DPC_CANON_EOS_ImageFormatCF:
+			case PTP_DPC_CANON_EOS_ImageFormatSD:
+			case PTP_DPC_CANON_EOS_ImageFormatExtHD:
+				/* special handling of ImageFormat properties */
+				for (j=0;j<propxcnt;j++) {
+					dpd->FORM.Enum.SupportedValue[j].u16 =
+							dtoh16( ptp_unpack_EOS_ImageFormat( params, &data ) );
+					ptp_debug (params, "event %d: suppval[%d] of %x is 0x%x.", i, j, proptype, dpd->FORM.Enum.SupportedValue[j].u16);
+				}
+				break;
+			default:
+				/* 'normal' enumerated types */
+				switch (dpd->DataType) {
+#define XX( TYPE, CONV )\
+					for (j=0;j<propxcnt;j++) { \
+						dpd->FORM.Enum.SupportedValue[j].TYPE = CONV(data); \
+						ptp_debug (params, "event %d: suppval[%d] of %x is 0x%x.", i, j, proptype, CONV(data)); \
+						data += 4; /* might only be for propxtype 3 */ \
+					} \
+					break;
+
+				case PTP_DTC_INT16:	XX( i16, dtoh16a );
+				case PTP_DTC_UINT32:	XX( u32, dtoh32a );
+				case PTP_DTC_UINT16:	XX( u16, dtoh16a );
+				case PTP_DTC_UINT8:	XX( u8,  dtoh8a );
+#undef XX
+				default:
+					ptp_debug (params ,"event %d: data type 0x%04x of %x unhandled, raw values:", i, dpd->DataType, proptype, dtoh32a(data));
+					for (j=0;j<(size-PTP_ece_Prop_Desc_Data)/4;j++, data+=4) /* 4 is good for propxtype 3 */
+						ptp_debug (params, "    %3d: 0x%8x", j, dtoh32a(data));
+					break;
+				}
+			}
+			break;
+		}
+		case PTP_EC_CANON_EOS_PropValueChanged:
+			if (size >= 0xc) {	/* property info */
+				int j;
+				uint32_t	proptype = dtoh32a(&curdata[PTP_ece_Prop_Subtype]);
+				unsigned char	*data = &curdata[PTP_ece_Prop_Val_Data];
+				PTPDevicePropDesc	*dpd;
+
+				ptp_debug (params, "event %d: EOS prop %04x info record, datasize is %d", i, proptype, size-PTP_ece_Prop_Val_Data);
+				for (j=0;j<params->nrofcanon_props;j++)
+					if (params->canon_props[j].proptype == proptype)
+						break;
+				if (j<params->nrofcanon_props) {
+					if (	(params->canon_props[j].size != size) ||
+						(memcmp(params->canon_props[j].data,data,size-PTP_ece_Prop_Val_Data))) {
+						params->canon_props[j].data = realloc(params->canon_props[j].data,size-PTP_ece_Prop_Val_Data);
+						memcpy (params->canon_props[j].data,data,size-PTP_ece_Prop_Val_Data);
+					}
+				} else {
+					if (j)
+						params->canon_props = realloc(params->canon_props, sizeof(params->canon_props[0])*(j+1));
+					else
+						params->canon_props = malloc(sizeof(params->canon_props[0]));
+					params->canon_props[j].type = type;
+					params->canon_props[j].proptype = proptype;
+					params->canon_props[j].size = size;
+					params->canon_props[j].data = malloc(size-PTP_ece_Prop_Val_Data);
+					memcpy(params->canon_props[j].data, data, size-PTP_ece_Prop_Val_Data);
+					memset (&params->canon_props[j].dpd,0,sizeof(params->canon_props[j].dpd));
+					params->canon_props[j].dpd.GetSet = 1;
+					params->canon_props[j].dpd.FormFlag = PTP_DPFF_None;
+					params->nrofcanon_props = j+1;
+				}
+				dpd = &params->canon_props[j].dpd;
+
+				/* fix GetSet value */
+				switch (proptype) {
+#define XX(x) case PTP_DPC_CANON_##x:
+					XX(EOS_FocusMode)
+					XX(EOS_BatteryPower)
+					XX(EOS_BatterySelect)
+					XX(EOS_ModelID)
+					XX(EOS_PTPExtensionVersion)
+					XX(EOS_DPOFVersion)
+					XX(EOS_AvailableShots)
+					XX(EOS_CurrentStorage)
+					XX(EOS_CurrentFolder)
+					XX(EOS_MyMenu)
+					XX(EOS_MyMenuList)
+					XX(EOS_HDDirectoryStructure)
+					XX(EOS_BatteryInfo)
+					XX(EOS_AdapterInfo)
+					XX(EOS_LensStatus)
+					XX(EOS_CardExtension)
+					XX(EOS_TempStatus)
+					XX(EOS_ShutterCounter)
+					XX(EOS_SerialNumber)
+					XX(EOS_DepthOfFieldPreview)
+					XX(EOS_EVFRecordStatus)
+					XX(EOS_LvAfSystem)
+					XX(EOS_FocusInfoEx)
+					XX(EOS_DepthOfField)
+					XX(EOS_Brightness)
+					XX(EOS_EFComp)
+					XX(EOS_LensName)
+					XX(EOS_LensID)
+#undef XX
+						dpd->GetSet = PTP_DPGS_Get;
+						break;
+				}
+
+				/* set DataType */
+				switch (proptype) {
+				case PTP_DPC_CANON_EOS_CameraTime:
+				case PTP_DPC_CANON_EOS_EVFOutputDevice:
+				case PTP_DPC_CANON_EOS_AvailableShots:
+				case PTP_DPC_CANON_EOS_CaptureDestination:
+				case PTP_DPC_CANON_EOS_WhiteBalanceXA:
+				case PTP_DPC_CANON_EOS_WhiteBalanceXB:
+				case PTP_DPC_CANON_EOS_QuickReviewTime:
+				case PTP_DPC_CANON_EOS_CurrentStorage:
+				case PTP_DPC_CANON_EOS_CurrentFolder:
+				case PTP_DPC_CANON_EOS_ShutterCounter:
+				case PTP_DPC_CANON_EOS_ModelID:
+				case PTP_DPC_CANON_EOS_LensID:
+				case PTP_DPC_CANON_EOS_StroboFiring:
+					dpd->DataType = PTP_DTC_UINT32;
+					break;
+				case PTP_DPC_CANON_EOS_Aperture:
+				case PTP_DPC_CANON_EOS_ShutterSpeed:
+				case PTP_DPC_CANON_EOS_ISOSpeed:
+				case PTP_DPC_CANON_EOS_FocusMode:
+				case PTP_DPC_CANON_EOS_AutoExposureMode:
+				case PTP_DPC_CANON_EOS_ColorSpace:
+				case PTP_DPC_CANON_EOS_BatteryPower:
+				case PTP_DPC_CANON_EOS_PTPExtensionVersion:
+				case PTP_DPC_CANON_EOS_DriveMode:
+				case PTP_DPC_CANON_EOS_AEB:
+					dpd->DataType = PTP_DTC_UINT16;
+					break;
+				case PTP_DPC_CANON_EOS_PictureStyle:
+				case PTP_DPC_CANON_EOS_WhiteBalance:
+				case PTP_DPC_CANON_EOS_MeteringMode:
+				case PTP_DPC_CANON_EOS_ExpCompensation: /* actually int8 if you calculate */
+					dpd->DataType = PTP_DTC_UINT8;
+					break;
+				case PTP_DPC_CANON_EOS_Owner:
+				case PTP_DPC_CANON_EOS_Artist:
+				case PTP_DPC_CANON_EOS_Copyright:
+				case PTP_DPC_CANON_EOS_SerialNumber:
+				case PTP_DPC_CANON_EOS_LensName:
+					dpd->DataType = PTP_DTC_STR;
+					break;
+				case PTP_DPC_CANON_EOS_WhiteBalanceAdjustA:
+				case PTP_DPC_CANON_EOS_WhiteBalanceAdjustB:
+					dpd->DataType = PTP_DTC_INT16;
+					break;
+				/* unknown props, listed from dump.... all 16 bit, but vals might be smaller */
+				case PTP_DPC_CANON_EOS_BatterySelect:
+				case 0xd114:
+				case PTP_DPC_CANON_EOS_DPOFVersion:
+				case PTP_DPC_CANON_EOS_BracketMode:
+					dpd->DataType = PTP_DTC_UINT16;
+					ptp_debug (params, "event %d: Unknown EOS property %04x, datasize is %d, using uint16", i ,proptype, size-PTP_ece_Prop_Val_Data);
+					for (j=0;j<size-PTP_ece_Prop_Val_Data;j++)
+						ptp_debug (params, "    %d: %02x", j, data[j]);
+					break;
+				case PTP_DPC_CANON_EOS_CustomFunc1:
+				case PTP_DPC_CANON_EOS_CustomFunc2:
+				case PTP_DPC_CANON_EOS_CustomFunc3:
+				case PTP_DPC_CANON_EOS_CustomFunc4:
+				case PTP_DPC_CANON_EOS_CustomFunc5:
+				case PTP_DPC_CANON_EOS_CustomFunc6:
+				case PTP_DPC_CANON_EOS_CustomFunc7:
+				case PTP_DPC_CANON_EOS_CustomFunc8:
+				case PTP_DPC_CANON_EOS_CustomFunc9:
+				case PTP_DPC_CANON_EOS_CustomFunc10:
+				case PTP_DPC_CANON_EOS_CustomFunc11:
+					dpd->DataType = PTP_DTC_UINT8;
+					ptp_debug (params, "event %d: Unknown EOS property %04x, datasize is %d, using uint8", i ,proptype, size-PTP_ece_Prop_Val_Data);
+					for (j=0;j<size-PTP_ece_Prop_Val_Data;j++)
+						ptp_debug (params, "    %d: %02x", j, data[j]);
+					/* custom func entries look like this on the 400D: '5 0 0 0 ?' = 4 bytes size + 1 byte data */
+					data += 4;
+					break;
+				/* yet unknown 32bit props */
+				case PTP_DPC_CANON_EOS_ColorTemperature:
+				case PTP_DPC_CANON_EOS_WftStatus:
+				case PTP_DPC_CANON_EOS_LensStatus:
+				case PTP_DPC_CANON_EOS_CardExtension:
+				case PTP_DPC_CANON_EOS_TempStatus:
+				case PTP_DPC_CANON_EOS_PhotoStudioMode:
+				case PTP_DPC_CANON_EOS_EVFMode:
+				case PTP_DPC_CANON_EOS_DepthOfFieldPreview:
+				case PTP_DPC_CANON_EOS_EVFSharpness:
+				case PTP_DPC_CANON_EOS_EVFWBMode:
+				case PTP_DPC_CANON_EOS_EVFClickWBCoeffs:
+				case PTP_DPC_CANON_EOS_EVFColorTemp:
+				case PTP_DPC_CANON_EOS_EVFRecordStatus:
+				case PTP_DPC_CANON_EOS_ExposureSimMode:
+				case PTP_DPC_CANON_EOS_LvAfSystem:
+				case PTP_DPC_CANON_EOS_MovSize:
+				case PTP_DPC_CANON_EOS_DepthOfField:
+				case PTP_DPC_CANON_EOS_LvViewTypeSelect:
+				case PTP_DPC_CANON_EOS_ImageFormat:
+				case PTP_DPC_CANON_EOS_ImageFormatCF:
+				case PTP_DPC_CANON_EOS_ImageFormatSD:
+				case PTP_DPC_CANON_EOS_ImageFormatExtHD:
+				case PTP_DPC_CANON_EOS_CustomFuncEx:
+//					dpd->DataType = PTP_DTC_UINT32;
+					ptp_debug (params, "event %d: Unknown EOS property %04x, datasize is %d, using uint32", i ,proptype, size-PTP_ece_Prop_Val_Data);
+					if ((size-PTP_ece_Prop_Val_Data) % sizeof(uint32_t) != 0)
+						ptp_debug (params, "event %d: Warning: datasize modulo sizeof(uint32) is not 0: ", i, (size-PTP_ece_Prop_Val_Data) % sizeof(uint32_t) );
+					for (j=0;j<(size-PTP_ece_Prop_Val_Data)/sizeof(uint32_t);j++)
+						ptp_debug (params, "    %d: 0x%8x", j, ((uint32_t*)data)[j]);
+					break;
+				default:
+					ptp_debug (params, "event %d: Unknown EOS property %04x, datasize is %d", i ,proptype, size-PTP_ece_Prop_Val_Data);
+					for (j=0;j<size-PTP_ece_Prop_Val_Data;j++)
+						ptp_debug (params, "    %d: %02x", j, data[j]);
+					break;
+				}
+				switch (dpd->DataType) {
+				case PTP_DTC_UINT32:
+					dpd->FactoryDefaultValue.u32	= dtoh32a(data);
+					dpd->CurrentValue.u32		= dtoh32a(data);
+					ptp_debug (params ,"event %d: currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u32);
+					break;
+				case PTP_DTC_UINT16:
+					dpd->FactoryDefaultValue.u16	= dtoh16a(data);
+					dpd->CurrentValue.u16		= dtoh16a(data);
+					ptp_debug (params,"event %d: currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u16);
+					break;
+				case PTP_DTC_UINT8:
+					dpd->FactoryDefaultValue.u8	= dtoh8a(data);
+					dpd->CurrentValue.u8		= dtoh8a(data);
+					ptp_debug (params,"event %d: currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u8);
+					break;
+				case PTP_DTC_STR: {
+#if 0 /* 5D MII and 400D aktually store plain ASCII in their string properties */
+					uint8_t len = 0;
+					dpd->FactoryDefaultValue.str	= ptp_unpack_string(params, data, 0, &len);
+					dpd->CurrentValue.str		= ptp_unpack_string(params, data, 0, &len);
+#else
+					dpd->FactoryDefaultValue.str	= strdup( (char*)data );
+					dpd->CurrentValue.str		= strdup( (char*)data );
+#endif
+					ptp_debug (params,"event %d: currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str);
+					break;
+				}
+				default:
+					/* debug is printed in switch above this one */
+					break;
+				}
+
+				/* ImageFormat special handling */
+				switch (proptype) {
+				case PTP_DPC_CANON_EOS_ImageFormat:
+				case PTP_DPC_CANON_EOS_ImageFormatCF:
+				case PTP_DPC_CANON_EOS_ImageFormatSD:
+				case PTP_DPC_CANON_EOS_ImageFormatExtHD:
+					dpd->DataType = PTP_DTC_UINT16;
+					dpd->FactoryDefaultValue.u16	= ptp_unpack_EOS_ImageFormat( params, &data );
+					dpd->CurrentValue.u16		= dpd->FactoryDefaultValue.u16;
+					ptp_debug (params,"event %d: currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u8);
+					break;
+				}
+
+				break;
+		}
+		case 0: /* end marker */
+			if (size == 8) /* no output */
+				break;
+			ptp_debug (params, "event %d: EOS event 0, but size %d", i, size);
+			break;
+		default:
+			switch (type) {
+#define XX(x)		case PTP_EC_CANON_EOS_##x: ptp_debug (params, "event %d: unhandled EOS event "#x" (size %d)", i, size);break;
+			XX(RequestGetEvent)
+			XX(ObjectRemoved)
+			XX(RequestGetObjectInfoEx)
+			XX(StorageStatusChanged)
+			XX(StorageInfoChanged)
+			XX(ObjectInfoChangedEx)
+			XX(ObjectContentChanged)
+			XX(CameraStatusChanged)
+			XX(WillSoonShutdown)
+			XX(ShutdownTimerUpdated)
+			XX(RequestCancelTransfer)
+			XX(RequestObjectTransferDT)
+			XX(RequestCancelTransferDT)
+			XX(StoreAdded)
+			XX(StoreRemoved)
+			XX(BulbExposureTime)
+			XX(RecordingTime)
+			XX(RequestObjectTransferTS)
+			XX(AfResult)
+#undef XX
+			default:
+				ptp_debug (params, "event %d: unknown EOS event %04x", i, type);
+				break;
+			}
+			if (size >= 0x8) {	/* event info */
+				int j;
+				for (j=8;j<size;j++)
+					ptp_debug (params, "    %d: %02x", j, curdata[j]);
+			}
+			(*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
+			break;
+		}
+		curdata += size;
+		i++;
+		if ((size == 8) && (type == 0))
+			break;
+	}
+
+	return entries;
+}
+
+/*
+    PTP USB Event container unpack for Nikon events.
+*/
+#define PTP_nikon_ec_Length		0
+#define PTP_nikon_ec_Code		2
+#define PTP_nikon_ec_Param1		4
+#define PTP_nikon_ec_Size		6
+static inline void
+ptp_unpack_Nikon_EC (PTPParams *params, unsigned char* data, unsigned int len, PTPContainer **ec, int *cnt)
+{
+	int i;
+
+	*ec = NULL;
+	if (data == NULL)
+		return;
+	if (len < PTP_nikon_ec_Code)
+		return;
+	*cnt = dtoh16a(&data[PTP_nikon_ec_Length]);
+	if (*cnt > (len-PTP_nikon_ec_Code)/PTP_nikon_ec_Size) /* broken cnt? */
+		return;
+	*ec = malloc(sizeof(PTPContainer)*(*cnt));
+	
+	for (i=0;i<*cnt;i++) {
+		memset(&(*ec)[i],0,sizeof(PTPContainer));
+		(*ec)[i].Code	= dtoh16a(&data[PTP_nikon_ec_Code+PTP_nikon_ec_Size*i]);
+		(*ec)[i].Param1	= dtoh32a(&data[PTP_nikon_ec_Param1+PTP_nikon_ec_Size*i]);
+		(*ec)[i].Nparam	= 1;
+	}
+}
+
+
+static inline uint32_t
+ptp_pack_EK_text(PTPParams *params, PTPEKTextParams *text, unsigned char **data) {
+	int i, len = 0;
+	uint8_t	retlen;
+	unsigned char *curdata;
+
+	len =	2*(strlen(text->title)+1)+1+
+		2*(strlen(text->line[0])+1)+1+
+		2*(strlen(text->line[1])+1)+1+
+		2*(strlen(text->line[2])+1)+1+
+		2*(strlen(text->line[3])+1)+1+
+		2*(strlen(text->line[4])+1)+1+
+		4*2+2*4+2+4+2+5*4*2;
+	*data = malloc(len);
+	if (!*data) return 0;
+
+	curdata = *data;
+	htod16a(curdata,100);curdata+=2;
+	htod16a(curdata,1);curdata+=2;
+	htod16a(curdata,0);curdata+=2;
+	htod16a(curdata,1000);curdata+=2;
+
+	htod32a(curdata,0);curdata+=4;
+	htod32a(curdata,0);curdata+=4;
+
+	htod16a(curdata,6);curdata+=2;
+	htod32a(curdata,0);curdata+=4;
+
+	ptp_pack_string(params, text->title, curdata, 0, &retlen); curdata+=2*retlen+1;htod16a(curdata,0);curdata+=2;
+	htod16a(curdata,0x10);curdata+=2;
+	
+	for (i=0;i<5;i++) {
+		ptp_pack_string(params, text->line[i], curdata, 0, &retlen); curdata+=2*retlen+1;htod16a(curdata,0);curdata+=2;
+		htod16a(curdata,0x10);curdata+=2;
+		htod16a(curdata,0x01);curdata+=2;
+		htod16a(curdata,0x02);curdata+=2;
+		htod16a(curdata,0x06);curdata+=2;
+	}
+	return len;
+}
+
+#define ptp_canon_dir_version	0x00
+#define ptp_canon_dir_ofc	0x02
+#define ptp_canon_dir_unk1	0x04
+#define ptp_canon_dir_objectid	0x08
+#define ptp_canon_dir_parentid	0x0c
+#define ptp_canon_dir_previd	0x10	/* in same dir */
+#define ptp_canon_dir_nextid	0x14	/* in same dir */
+#define ptp_canon_dir_nextchild	0x18	/* down one dir */
+#define ptp_canon_dir_storageid	0x1c	/* only in storage entry */
+#define ptp_canon_dir_name	0x20
+#define ptp_canon_dir_flags	0x2c
+#define ptp_canon_dir_size	0x30
+#define ptp_canon_dir_unixtime	0x34
+#define ptp_canon_dir_year	0x38
+#define ptp_canon_dir_month	0x39
+#define ptp_canon_dir_mday	0x3a
+#define ptp_canon_dir_hour	0x3b
+#define ptp_canon_dir_minute	0x3c
+#define ptp_canon_dir_second	0x3d
+#define ptp_canon_dir_unk2	0x3e
+#define ptp_canon_dir_thumbsize	0x40
+#define ptp_canon_dir_width	0x44
+#define ptp_canon_dir_height	0x48
+
+static inline uint16_t
+ptp_unpack_canon_directory (
+	PTPParams		*params,
+	unsigned char		*dir,
+	uint32_t		cnt,
+	PTPObjectHandles	*handles,
+	PTPObjectInfo		**oinfos,	/* size(handles->n) */
+	uint32_t		**flags		/* size(handles->n) */
+) {
+	unsigned int	i, j, nrofobs = 0, curob = 0;
+
+#define ISOBJECT(ptr) (dtoh32a((ptr)+ptp_canon_dir_storageid) == 0xffffffff)
+	for (i=0;i<cnt;i++)
+		if (ISOBJECT(dir+i*0x4c)) nrofobs++;
+	handles->n = nrofobs;
+	handles->Handler = calloc(sizeof(handles->Handler[0]),nrofobs);
+	if (!handles->Handler) return PTP_RC_GeneralError;
+	*oinfos = calloc(sizeof((*oinfos)[0]),nrofobs);
+	if (!*oinfos) return PTP_RC_GeneralError;
+	*flags  = calloc(sizeof((*flags)[0]),nrofobs);
+	if (!*flags) return PTP_RC_GeneralError;
+
+	/* Migrate data into objects ids, handles into
+	 * the object handler array.
+	 */
+	curob = 0;
+	for (i=0;i<cnt;i++) {
+		unsigned char	*cur = dir+i*0x4c;
+		PTPObjectInfo	*oi = (*oinfos)+curob;
+
+		if (!ISOBJECT(cur))
+			continue;
+
+		handles->Handler[curob] = dtoh32a(cur + ptp_canon_dir_objectid);
+		oi->StorageID		= 0xffffffff;
+		oi->ObjectFormat	= dtoh16a(cur + ptp_canon_dir_ofc);
+		oi->ParentObject	= dtoh32a(cur + ptp_canon_dir_parentid);
+		oi->Filename		= strdup((char*)(cur + ptp_canon_dir_name));
+		oi->ObjectCompressedSize= dtoh32a(cur + ptp_canon_dir_size);
+		oi->ThumbCompressedSize	= dtoh32a(cur + ptp_canon_dir_thumbsize);
+		oi->ImagePixWidth	= dtoh32a(cur + ptp_canon_dir_width);
+		oi->ImagePixHeight	= dtoh32a(cur + ptp_canon_dir_height);
+		oi->CaptureDate		= oi->ModificationDate = dtoh32a(cur + ptp_canon_dir_unixtime);
+		(*flags)[curob]		= dtoh32a(cur + ptp_canon_dir_flags);
+		curob++;
+	}
+	/* Walk over Storage ID entries and distribute the IDs to
+	 * the parent objects. */
+	for (i=0;i<cnt;i++) {
+		unsigned char	*cur = dir+i*0x4c;
+		uint32_t	nextchild = dtoh32a(cur + ptp_canon_dir_nextchild);
+
+		if (ISOBJECT(cur))
+			continue;
+		for (j=0;j<handles->n;j++) if (nextchild == handles->Handler[j]) break;
+		if (j == handles->n) continue;
+		(*oinfos)[j].StorageID = dtoh32a(cur + ptp_canon_dir_storageid);
+	}
+	/* Walk over all objects and distribute the storage ids */
+	while (1) {
+		int changed = 0;
+		for (i=0;i<cnt;i++) {
+			unsigned char	*cur = dir+i*0x4c;
+			uint32_t	oid = dtoh32a(cur + ptp_canon_dir_objectid);
+			uint32_t	nextoid = dtoh32a(cur + ptp_canon_dir_nextid);
+			uint32_t	nextchild = dtoh32a(cur + ptp_canon_dir_nextchild);
+			uint32_t	storageid;
+
+			if (!ISOBJECT(cur))
+				continue;
+			for (j=0;j<handles->n;j++) if (oid == handles->Handler[j]) break;
+			if (j == handles->n) {
+				/*fprintf(stderr,"did not find oid in lookup pass for current oid\n");*/
+				continue;
+			}
+	 		storageid = (*oinfos)[j].StorageID;
+			if (storageid == 0xffffffff) continue;
+			if (nextoid != 0xffffffff) {
+				for (j=0;j<handles->n;j++) if (nextoid == handles->Handler[j]) break;
+				if (j == handles->n) {
+					/*fprintf(stderr,"did not find oid in lookup pass for next oid\n");*/
+					continue;
+				}
+				if ((*oinfos)[j].StorageID == 0xffffffff) {
+					(*oinfos)[j].StorageID = storageid;
+					changed++;
+				}
+			}
+			if (nextchild != 0xffffffff) {
+				for (j=0;j<handles->n;j++) if (nextchild == handles->Handler[j]) break;
+				if (j == handles->n) {
+					/*fprintf(stderr,"did not find oid in lookup pass for next child\n");*/
+					continue;
+				}
+				if ((*oinfos)[j].StorageID == 0xffffffff) {
+					(*oinfos)[j].StorageID = storageid;
+					changed++;
+				}
+			}
+		}
+		/* Check if we:
+		 * - changed no entry (nothing more to do)
+		 * - changed all of them at once (usually happens)
+		 * break if we do.
+		 */
+		if (!changed || (changed==nrofobs-1))
+			break;
+	}
+#undef ISOBJECT
+	return PTP_RC_OK;
+}
diff --git a/src/ptp.c b/src/ptp.c
new file mode 100644
index 0000000..a8c265b
--- /dev/null
+++ b/src/ptp.c
@@ -0,0 +1,4974 @@
+/* ptp.c
+ *
+ * Copyright (C) 2001-2004 Mariusz Woloszyn <emsi@ipartners.pl>
+ * Copyright (C) 2003-2009 Marcus Meissner <marcus@jet.franken.de>
+ * Copyright (C) 2006-2008 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2007 Tero Saarni <tero.saarni@gmail.com>
+ *
+ * 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.
+ */
+
+#define _BSD_SOURCE
+#include "config.h"
+#include "ptp.h"
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifdef ENABLE_NLS
+#  include <libintl.h>
+#  undef _
+#  define _(String) dgettext (PACKAGE, String)
+#  ifdef gettext_noop
+#    define N_(String) gettext_noop (String)
+#  else
+#    define N_(String) (String)
+#  endif
+#else
+#  define textdomain(String) (String)
+#  define gettext(String) (String)
+#  define dgettext(Domain,Message) (Message)
+#  define dcgettext(Domain,Message,Type) (Message)
+#  define bindtextdomain(Domain,Directory) (Domain)
+#  define _(String) (String)
+#  define N_(String) (String)
+#endif
+
+#define CHECK_PTP_RC(result)	{uint16_t r=(result); if (r!=PTP_RC_OK) return r;}
+
+#define PTP_CNT_INIT(cnt) {memset(&cnt,0,sizeof(cnt));}
+
+static uint16_t ptp_exit_recv_memory_handler (PTPDataHandler*,unsigned char**,unsigned long*);
+static uint16_t ptp_init_recv_memory_handler(PTPDataHandler*);
+static uint16_t ptp_init_send_memory_handler(PTPDataHandler*,unsigned char*,unsigned long len);
+static uint16_t ptp_exit_send_memory_handler (PTPDataHandler *handler);
+
+static void
+ptp_debug (PTPParams *params, const char *format, ...)
+{  
+        va_list args;
+
+        va_start (args, format);
+        if (params->debug_func!=NULL)
+                params->debug_func (params->data, format, args);
+        else
+	{
+                vfprintf (stderr, format, args);
+		fprintf (stderr,"\n");
+		fflush (stderr);
+	}
+        va_end (args);
+}  
+
+static void
+ptp_error (PTPParams *params, const char *format, ...)
+{  
+        va_list args;
+
+        va_start (args, format);
+        if (params->error_func!=NULL)
+                params->error_func (params->data, format, args);
+        else
+	{
+                vfprintf (stderr, format, args);
+		fprintf (stderr,"\n");
+		fflush (stderr);
+	}
+        va_end (args);
+}
+
+/* Pack / unpack functions */
+
+#include "ptp-pack.c"
+
+/* major PTP functions */
+
+/* Transaction data phase description */
+#define PTP_DP_NODATA		0x0000	/* no data phase */
+#define PTP_DP_SENDDATA		0x0001	/* sending data */
+#define PTP_DP_GETDATA		0x0002	/* receiving data */
+#define PTP_DP_DATA_MASK	0x00ff	/* data phase mask */
+
+/**
+ * ptp_transaction:
+ * params:	PTPParams*
+ * 		PTPContainer* ptp	- general ptp container
+ * 		uint16_t flags		- lower 8 bits - data phase description
+ * 		unsigned int sendlen	- senddata phase data length
+ * 		char** data		- send or receive data buffer pointer
+ * 		int* recvlen		- receive data length
+ *
+ * Performs PTP transaction. ptp is a PTPContainer with appropriate fields
+ * filled in (i.e. operation code and parameters). It's up to caller to do
+ * so.
+ * The flags decide thether the transaction has a data phase and what is its
+ * direction (send or receive). 
+ * If transaction is sending data the sendlen should contain its length in
+ * bytes, otherwise it's ignored.
+ * The data should contain an address of a pointer to data going to be sent
+ * or is filled with such a pointer address if data are received depending
+ * od dataphase direction (send or received) or is beeing ignored (no
+ * dataphase).
+ * The memory for a pointer should be preserved by the caller, if data are
+ * beeing retreived the appropriate amount of memory is beeing allocated
+ * (the caller should handle that!).
+ *
+ * Return values: Some PTP_RC_* code.
+ * Upon success PTPContainer* ptp contains PTP Response Phase container with
+ * all fields filled in.
+ **/
+static uint16_t
+ptp_transaction_new (PTPParams* params, PTPContainer* ptp, 
+		uint16_t flags, unsigned int sendlen,
+		PTPDataHandler *handler
+) {
+	int tries;
+
+	if ((params==NULL) || (ptp==NULL)) 
+		return PTP_ERROR_BADPARAM;
+
+	ptp->Transaction_ID=params->transaction_id++;
+	ptp->SessionID=params->session_id;
+	/* send request */
+	CHECK_PTP_RC(params->sendreq_func (params, ptp));
+	/* is there a dataphase? */
+	switch (flags&PTP_DP_DATA_MASK) {
+	case PTP_DP_SENDDATA:
+		{
+			uint16_t ret;
+			ret = params->senddata_func(params, ptp,
+						    sendlen, handler);
+			if (ret == PTP_ERROR_CANCEL) {
+				ret = params->cancelreq_func(params, 
+							     params->transaction_id-1);
+				if (ret == PTP_RC_OK)
+					ret = PTP_ERROR_CANCEL;
+			}
+			if (ret != PTP_RC_OK)
+				return ret;
+		}
+		break;
+	case PTP_DP_GETDATA:
+		{
+			uint16_t ret;
+			ret = params->getdata_func(params, ptp, handler);
+			if (ret == PTP_ERROR_CANCEL) {
+				ret = params->cancelreq_func(params, 
+							     params->transaction_id-1);
+				if (ret == PTP_RC_OK)
+					ret = PTP_ERROR_CANCEL;
+			}
+			if (ret != PTP_RC_OK)
+				return ret;
+		}
+		break;
+	case PTP_DP_NODATA:
+		break;
+	default:
+		return PTP_ERROR_BADPARAM;
+	}
+	tries = 3;
+	while (1) {
+		/* get response */
+		CHECK_PTP_RC(params->getresp_func(params, ptp));
+		if (ptp->Transaction_ID != params->transaction_id-1) {
+			/* try to clean up potential left overs from previous session */
+			if ((ptp->Code == PTP_OC_OpenSession) && tries--)
+				continue;
+			ptp_error (params,
+				"PTP: Sequence number mismatch %d vs expected %d.",
+				ptp->Transaction_ID, params->transaction_id-1
+			);
+			return PTP_ERROR_BADPARAM;
+		}
+		break;
+	}
+	return ptp->Code;
+}
+
+/* memory data get/put handler */
+typedef struct {
+	unsigned char	*data;
+	unsigned long	size, curoff;
+} PTPMemHandlerPrivate;
+
+static uint16_t
+memory_getfunc(PTPParams* params, void* private,
+	       unsigned long wantlen, unsigned char *data,
+	       unsigned long *gotlen
+) {
+	PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)private;
+	unsigned long tocopy = wantlen;
+
+	if (priv->curoff + tocopy > priv->size)
+		tocopy = priv->size - priv->curoff;
+	memcpy (data, priv->data + priv->curoff, tocopy);
+	priv->curoff += tocopy;
+	*gotlen = tocopy;
+	return PTP_RC_OK;
+}
+
+static uint16_t
+memory_putfunc(PTPParams* params, void* private,
+	       unsigned long sendlen, unsigned char *data,
+	       unsigned long *putlen
+) {
+	PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)private;
+
+	if (priv->curoff + sendlen > priv->size) {
+		priv->data = realloc (priv->data, priv->curoff+sendlen);
+		priv->size = priv->curoff + sendlen;
+	}
+	memcpy (priv->data + priv->curoff, data, sendlen);
+	priv->curoff += sendlen;
+	*putlen = sendlen;
+	return PTP_RC_OK;
+}
+
+/* init private struct for receiving data. */
+static uint16_t
+ptp_init_recv_memory_handler(PTPDataHandler *handler) {
+	PTPMemHandlerPrivate* priv;
+	priv = malloc (sizeof(PTPMemHandlerPrivate));
+	handler->priv = priv;
+	handler->getfunc = memory_getfunc;
+	handler->putfunc = memory_putfunc;
+	priv->data = NULL;
+	priv->size = 0;
+	priv->curoff = 0;
+	return PTP_RC_OK;
+}
+
+/* init private struct and put data in for sending data.
+ * data is still owned by caller.
+ */
+static uint16_t
+ptp_init_send_memory_handler(PTPDataHandler *handler,
+	unsigned char *data, unsigned long len
+) {
+	PTPMemHandlerPrivate* priv;
+	priv = malloc (sizeof(PTPMemHandlerPrivate));
+	if (!priv)
+		return PTP_RC_GeneralError;
+	handler->priv = priv;
+	handler->getfunc = memory_getfunc;
+	handler->putfunc = memory_putfunc;
+	priv->data = data;
+	priv->size = len;
+	priv->curoff = 0;
+	return PTP_RC_OK;
+}
+
+/* free private struct + data */
+static uint16_t
+ptp_exit_send_memory_handler (PTPDataHandler *handler) {
+	PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)handler->priv;
+	/* data is owned by caller */
+	free (priv);
+	return PTP_RC_OK;
+}
+
+/* hand over our internal data to caller */
+static uint16_t
+ptp_exit_recv_memory_handler (PTPDataHandler *handler,
+	unsigned char **data, unsigned long *size
+) {
+	PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)handler->priv;
+	*data = priv->data;
+	*size = priv->size;
+	free (priv);
+	return PTP_RC_OK;
+}
+
+/* fd data get/put handler */
+typedef struct {
+	int fd;
+} PTPFDHandlerPrivate;
+
+static uint16_t
+fd_getfunc(PTPParams* params, void* private,
+	       unsigned long wantlen, unsigned char *data,
+	       unsigned long *gotlen
+) {
+	PTPFDHandlerPrivate* priv = (PTPFDHandlerPrivate*)private;
+	int		got;
+
+	got = read (priv->fd, data, wantlen);
+	if (got != -1)
+		*gotlen = got;
+	else
+		return PTP_RC_GeneralError;
+	return PTP_RC_OK;
+}
+
+static uint16_t
+fd_putfunc(PTPParams* params, void* private,
+	       unsigned long sendlen, unsigned char *data,
+	       unsigned long *putlen
+) {
+	int		written;
+	PTPFDHandlerPrivate* priv = (PTPFDHandlerPrivate*)private;
+
+	written = write (priv->fd, data, sendlen);
+	if (written != -1)
+		*putlen = written;
+	else
+		return PTP_RC_GeneralError;
+	return PTP_RC_OK;
+}
+
+static uint16_t
+ptp_init_fd_handler(PTPDataHandler *handler, int fd) {
+	PTPFDHandlerPrivate* priv;
+	priv = malloc (sizeof(PTPFDHandlerPrivate));
+	handler->priv = priv;
+	handler->getfunc = fd_getfunc;
+	handler->putfunc = fd_putfunc;
+	priv->fd = fd;
+	return PTP_RC_OK;
+}
+
+static uint16_t
+ptp_exit_fd_handler (PTPDataHandler *handler) {
+	PTPFDHandlerPrivate* priv = (PTPFDHandlerPrivate*)handler->priv;
+	free (priv);
+	return PTP_RC_OK;
+}
+
+/* Old style transaction, based on memory */
+static uint16_t
+ptp_transaction (PTPParams* params, PTPContainer* ptp, 
+		uint16_t flags, unsigned int sendlen,
+		unsigned char **data, unsigned int *recvlen
+) {
+	PTPDataHandler	handler;
+	uint16_t	ret;
+
+	switch (flags & PTP_DP_DATA_MASK) {
+	case PTP_DP_SENDDATA:
+		ptp_init_send_memory_handler (&handler, *data, sendlen);
+		break;
+	case PTP_DP_GETDATA:
+		ptp_init_recv_memory_handler (&handler);
+		break;
+	default:break;
+	}
+	ret = ptp_transaction_new (params, ptp, flags, sendlen, &handler);
+	switch (flags & PTP_DP_DATA_MASK) {
+	case PTP_DP_SENDDATA:
+		ptp_exit_send_memory_handler (&handler);
+		break;
+	case PTP_DP_GETDATA: {
+		unsigned long len;
+		ptp_exit_recv_memory_handler (&handler, data, &len);
+		if (recvlen)
+			*recvlen = len;
+		break;
+	}
+	default:break;
+	}
+	return ret;
+}
+
+
+/**
+ * PTP operation functions
+ *
+ * all ptp_ functions should take integer parameters
+ * in host byte order!
+ **/
+
+
+/**
+ * ptp_getdeviceinfo:
+ * params:	PTPParams*
+ *
+ * Gets device info dataset and fills deviceinfo structure.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_getdeviceinfo (PTPParams* params, PTPDeviceInfo* deviceinfo)
+{
+	uint16_t 	ret;
+	unsigned long	len;
+	PTPContainer	ptp;
+	unsigned char*	di=NULL;
+	PTPDataHandler	handler;
+
+	ptp_init_recv_memory_handler (&handler);
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetDeviceInfo;
+	ptp.Nparam=0;
+	len=0;
+	ret=ptp_transaction_new(params, &ptp, PTP_DP_GETDATA, 0, &handler);
+	ptp_exit_recv_memory_handler (&handler, &di, &len);
+	if (!di) ret = PTP_RC_GeneralError;
+	if (ret == PTP_RC_OK) ptp_unpack_DI(params, di, deviceinfo, len);
+	free(di);
+	return ret;
+}
+
+uint16_t
+ptp_canon_eos_getdeviceinfo (PTPParams* params, PTPCanonEOSDeviceInfo*di)
+{
+	uint16_t 	ret;
+	PTPContainer	ptp;
+	PTPDataHandler	handler;
+	unsigned long	len;
+	unsigned char	*data;
+
+	ptp_init_recv_memory_handler (&handler);
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_CANON_EOS_GetDeviceInfoEx;
+	ptp.Nparam=0;
+	len=0;
+	data=NULL;
+	ret=ptp_transaction_new(params, &ptp, PTP_DP_GETDATA, 0, &handler);
+	ptp_exit_recv_memory_handler (&handler, &data, &len);
+	if (ret == PTP_RC_OK) ptp_unpack_EOS_DI(params, data, di, len);
+	free (data);
+	return ret;
+}
+
+/**
+ * ptp_generic_no_data:
+ * params:	PTPParams*
+ * 		code	PTP OP Code
+ * 		n_param	count of parameters
+ *		... variable argument list ...
+ *
+ * Emits a generic PTP command without any data transfer.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_generic_no_data (PTPParams* params, uint16_t code, unsigned int n_param, ...)
+{
+	PTPContainer ptp;
+	va_list args;
+	int i;
+
+	if( n_param > 5 )
+		return PTP_RC_InvalidParameter;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=code;
+	ptp.Nparam=n_param;
+
+	va_start(args, n_param);
+	for( i=0; i<n_param; ++i )
+		(&ptp.Param1)[i] = va_arg(args, uint32_t);
+	va_end(args);
+
+	return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
+}
+
+/**
+ * ptp_opensession:
+ * params:	PTPParams*
+ * 		session			- session number 
+ *
+ * Establishes a new session.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_opensession (PTPParams* params, uint32_t session)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+
+	ptp_debug(params,"PTP: Opening session");
+
+	/* SessonID field of the operation dataset should always
+	   be set to 0 for OpenSession request! */
+	params->session_id=0x00000000;
+	/* TransactionID should be set to 0 also! */
+	params->transaction_id=0x0000000;
+	/* zero out response packet buffer */
+	params->response_packet = NULL;
+	params->response_packet_size = 0;
+	/* no split headers */
+	params->split_header_data = 0;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_OpenSession;
+	ptp.Param1=session;
+	ptp.Nparam=1;
+	ret=ptp_transaction_new(params, &ptp, PTP_DP_NODATA, 0, NULL);
+	/* now set the global session id to current session number */
+	params->session_id=session;
+	return ret;
+}
+
+/**
+ * ptp_free_params:
+ * params:	PTPParams*
+ *
+ * Frees all data within the PTPParams struct.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+void
+ptp_free_params (PTPParams *params) {
+	int i;
+
+	if (params->cameraname) free (params->cameraname);
+	if (params->wifi_profiles) free (params->wifi_profiles);
+	for (i=0;i<params->nrofobjects;i++)
+		ptp_free_object (&params->objects[i]);
+	free (params->objects);
+	ptp_free_DI (&params->deviceinfo);
+}
+
+/**
+ * ptp_getststorageids:
+ * params:	PTPParams*
+ *
+ * Gets array of StorageIDs and fills the storageids structure.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_getstorageids (PTPParams* params, PTPStorageIDs* storageids)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned int len;
+	unsigned char* sids=NULL;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetStorageIDs;
+	ptp.Nparam=0;
+	len=0;
+	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &sids, &len);
+	if (ret == PTP_RC_OK) ptp_unpack_SIDs(params, sids, storageids, len);
+	free(sids);
+	return ret;
+}
+
+/**
+ * ptp_getststorageinfo:
+ * params:	PTPParams*
+ *		storageid		- StorageID
+ *
+ * Gets StorageInfo dataset of desired storage and fills storageinfo
+ * structure.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_getstorageinfo (PTPParams* params, uint32_t storageid,
+			PTPStorageInfo* storageinfo)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char* si=NULL;
+	unsigned int len;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetStorageInfo;
+	ptp.Param1=storageid;
+	ptp.Nparam=1;
+	len=0;
+	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &si, &len);
+	if (ret == PTP_RC_OK) ptp_unpack_SI(params, si, storageinfo, len);
+	free(si);
+	return ret;
+}
+
+/**
+ * ptp_getobjecthandles:
+ * params:	PTPParams*
+ *		storage			- StorageID
+ *		objectformatcode	- ObjectFormatCode (optional)
+ *		associationOH		- ObjectHandle of Association for
+ *					  wich a list of children is desired
+ *					  (optional)
+ *		objecthandles		- pointer to structute
+ *
+ * Fills objecthandles with structure returned by device.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_getobjecthandles (PTPParams* params, uint32_t storage,
+			uint32_t objectformatcode, uint32_t associationOH,
+			PTPObjectHandles* objecthandles)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char* oh=NULL;
+	unsigned int len;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetObjectHandles;
+	ptp.Param1=storage;
+	ptp.Param2=objectformatcode;
+	ptp.Param3=associationOH;
+	ptp.Nparam=3;
+	len=0;
+	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &oh, &len);
+	if (ret == PTP_RC_OK) {
+		ptp_unpack_OH(params, oh, objecthandles, len);
+	} else {
+		if (	(storage == 0xffffffff) &&
+			(objectformatcode == 0) &&
+			(associationOH == 0)
+		) {
+			/* When we query all object handles on all stores and
+			 * get an error -> just handle it as "0 handles".
+			 */
+			objecthandles->Handler = NULL;
+			objecthandles->n = 0;
+			ret = PTP_RC_OK;
+		}
+	}
+	free(oh);
+	return ret;
+}
+
+/**
+ * ptp_getnumobjects:
+ * params:	PTPParams*
+ *		storage			- StorageID
+ *		objectformatcode	- ObjectFormatCode (optional)
+ *		associationOH		- ObjectHandle of Association for
+ *					  wich a list of children is desired
+ *					  (optional)
+ *		numobs			- pointer to uint32_t that takes number of objects
+ *
+ * Fills numobs with number of objects on device.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_getnumobjects (PTPParams* params, uint32_t storage,
+			uint32_t objectformatcode, uint32_t associationOH,
+			uint32_t* numobs)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	int len;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetNumObjects;
+	ptp.Param1=storage;
+	ptp.Param2=objectformatcode;
+	ptp.Param3=associationOH;
+	ptp.Nparam=3;
+	len=0;
+	ret=ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
+	if (ret == PTP_RC_OK) {
+		if (ptp.Nparam >= 1)
+			*numobs = ptp.Param1;
+		else
+			ret = PTP_RC_GeneralError;
+	}
+	return ret;
+}
+
+/**
+ * ptp_getobjectinfo:
+ * params:	PTPParams*
+ *		handle			- Object handle
+ *		objectinfo		- pointer to objectinfo that is returned
+ *
+ * Get objectinfo structure for handle from device.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_getobjectinfo (PTPParams* params, uint32_t handle,
+			PTPObjectInfo* objectinfo)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char* oi=NULL;
+	unsigned int len;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetObjectInfo;
+	ptp.Param1=handle;
+	ptp.Nparam=1;
+	len=0;
+	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &oi, &len);
+	if (ret == PTP_RC_OK) ptp_unpack_OI(params, oi, objectinfo, len);
+	free(oi);
+	return ret;
+}
+
+/**
+ * ptp_getobject:
+ * params:	PTPParams*
+ *		handle			- Object handle
+ *		object			- pointer to data area
+ *
+ * Get object 'handle' from device and store the data in newly
+ * allocated 'object'.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_getobject (PTPParams* params, uint32_t handle, unsigned char** object)
+{
+	PTPContainer ptp;
+	unsigned int len;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetObject;
+	ptp.Param1=handle;
+	ptp.Nparam=1;
+	len=0;
+	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object, &len);
+}
+
+/**
+ * ptp_getobject_to_handler:
+ * params:	PTPParams*
+ *		handle			- Object handle
+ *		PTPDataHandler*		- pointer datahandler
+ *
+ * Get object 'handle' from device and store the data in newly
+ * allocated 'object'.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_getobject_to_handler (PTPParams* params, uint32_t handle, PTPDataHandler *handler)
+{
+	PTPContainer ptp;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetObject;
+	ptp.Param1=handle;
+	ptp.Nparam=1;
+	return ptp_transaction_new(params, &ptp, PTP_DP_GETDATA, 0, handler);
+}
+
+/**
+ * ptp_getobject_tofd:
+ * params:	PTPParams*
+ *		handle			- Object handle
+ *		fd                      - File descriptor to write() to
+ *
+ * Get object 'handle' from device and write the data to the 
+ * given file descriptor.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_getobject_tofd (PTPParams* params, uint32_t handle, int fd)
+{
+	PTPContainer	ptp;
+	PTPDataHandler	handler;
+	uint16_t	ret;
+
+	ptp_init_fd_handler (&handler, fd);
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetObject;
+	ptp.Param1=handle;
+	ptp.Nparam=1;
+	ret = ptp_transaction_new(params, &ptp, PTP_DP_GETDATA, 0, &handler);
+	ptp_exit_fd_handler (&handler);
+	return ret;
+}
+
+/**
+ * ptp_getpartialobject:
+ * params:	PTPParams*
+ *		handle			- Object handle
+ *		offset			- Offset into object
+ *		maxbytes		- Maximum of bytes to read
+ *		object			- pointer to data area
+ *
+ * Get object 'handle' from device and store the data in newly
+ * allocated 'object'. Start from offset and read at most maxbytes.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_getpartialobject (PTPParams* params, uint32_t handle, uint32_t offset,
+			uint32_t maxbytes, unsigned char** object)
+{
+	PTPContainer ptp;
+	unsigned int len;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetPartialObject;
+	ptp.Param1=handle;
+	ptp.Param2=offset;
+	ptp.Param3=maxbytes;
+	ptp.Nparam=3;
+	len=0;
+	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object, &len);
+}
+
+/**
+ * ptp_getthumb:
+ * params:	PTPParams*
+ *		handle			- Object handle
+ *		object			- pointer to data area
+ *
+ * Get thumb for object 'handle' from device and store the data in newly
+ * allocated 'object'.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_getthumb (PTPParams* params, uint32_t handle, unsigned char** object)
+{
+	PTPContainer ptp;
+	unsigned int len;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetThumb;
+	ptp.Param1=handle;
+	ptp.Nparam=1;
+	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object, &len);
+}
+
+/**
+ * ptp_deleteobject:
+ * params:	PTPParams*
+ *		handle			- object handle
+ *		ofc			- object format code (optional)
+ * 
+ * Deletes desired objects.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_deleteobject (PTPParams* params, uint32_t handle, uint32_t ofc)
+{
+	PTPContainer ptp;
+	uint16_t ret;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_DeleteObject;
+	ptp.Param1=handle;
+	ptp.Param2=ofc;
+	ptp.Nparam=2;
+	ret = ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
+	if (ret != PTP_RC_OK) {
+		return ret;
+	}
+	/* If the object is cached and could be removed, cleanse cache. */
+	ptp_remove_object_from_cache(params, handle);
+	return PTP_RC_OK;
+}
+
+/**
+ * ptp_sendobjectinfo:
+ * params:	PTPParams*
+ *		uint32_t* store		- destination StorageID on Responder
+ *		uint32_t* parenthandle 	- Parent ObjectHandle on responder
+ * 		uint32_t* handle	- see Return values
+ *		PTPObjectInfo* objectinfo- ObjectInfo that is to be sent
+ * 
+ * Sends ObjectInfo of file that is to be sent via SendFileObject.
+ *
+ * Return values: Some PTP_RC_* code.
+ * Upon success : uint32_t* store	- Responder StorageID in which
+ *					  object will be stored
+ *		  uint32_t* parenthandle- Responder Parent ObjectHandle
+ *					  in which the object will be stored
+ *		  uint32_t* handle	- Responder's reserved ObjectHandle
+ *					  for the incoming object
+ **/
+uint16_t
+ptp_sendobjectinfo (PTPParams* params, uint32_t* store, 
+			uint32_t* parenthandle, uint32_t* handle,
+			PTPObjectInfo* objectinfo)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char* oidata=NULL;
+	uint32_t size;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_SendObjectInfo;
+	ptp.Param1=*store;
+	ptp.Param2=*parenthandle;
+	ptp.Nparam=2;
+	
+	size=ptp_pack_OI(params, objectinfo, &oidata);
+	ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &oidata, NULL); 
+	free(oidata);
+	*store=ptp.Param1;
+	*parenthandle=ptp.Param2;
+	*handle=ptp.Param3; 
+	return ret;
+}
+
+/**
+ * ptp_sendobject:
+ * params:	PTPParams*
+ *		char*	object		- contains the object that is to be sent
+ *		uint32_t size		- object size
+ *		
+ * Sends object to Responder.
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ */
+uint16_t
+ptp_sendobject (PTPParams* params, unsigned char* object, uint32_t size)
+{
+	PTPContainer ptp;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_SendObject;
+	ptp.Nparam=0;
+
+	return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &object, NULL);
+}
+
+/**
+ * ptp_sendobject_from_handler:
+ * params:	PTPParams*
+ *		PTPDataHandler*         - File descriptor to read() object from
+ *              uint32_t size           - File/object size
+ *
+ * Sends object from file descriptor by consecutive reads from this
+ * descriptor.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_sendobject_from_handler (PTPParams* params, PTPDataHandler *handler, uint32_t size)
+{
+	PTPContainer	ptp;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_SendObject;
+	ptp.Nparam=0;
+	return ptp_transaction_new(params, &ptp, PTP_DP_SENDDATA, size, handler);
+}
+
+
+/**
+ * ptp_sendobject_fromfd:
+ * params:	PTPParams*
+ *		fd                      - File descriptor to read() object from
+ *              uint32_t size           - File/object size
+ *
+ * Sends object from file descriptor by consecutive reads from this
+ * descriptor.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_sendobject_fromfd (PTPParams* params, int fd, uint32_t size)
+{
+	PTPContainer	ptp;
+	PTPDataHandler	handler;
+	uint16_t	ret;
+
+	ptp_init_fd_handler (&handler, fd);
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_SendObject;
+	ptp.Nparam=0;
+	ret = ptp_transaction_new(params, &ptp, PTP_DP_SENDDATA, size, &handler);
+	ptp_exit_fd_handler (&handler);
+	return ret;
+}
+
+
+uint16_t
+ptp_getdevicepropdesc (PTPParams* params, uint16_t propcode, 
+			PTPDevicePropDesc* devicepropertydesc)
+{
+	PTPContainer ptp;
+	uint16_t ret;
+	unsigned int len;
+	unsigned char* dpd=NULL;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetDevicePropDesc;
+	ptp.Param1=propcode;
+	ptp.Nparam=1;
+	len=0;
+	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpd, &len);
+	if (ret == PTP_RC_OK) ptp_unpack_DPD(params, dpd, devicepropertydesc, len);
+	free(dpd);
+	return ret;
+}
+
+
+uint16_t
+ptp_getdevicepropvalue (PTPParams* params, uint16_t propcode,
+			PTPPropertyValue* value, uint16_t datatype)
+{
+	PTPContainer ptp;
+	uint16_t ret;
+	unsigned int len;
+	int offset;
+	unsigned char* dpv=NULL;
+
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_GetDevicePropValue;
+	ptp.Param1=propcode;
+	ptp.Nparam=1;
+	len=offset=0;
+	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpv, &len);
+	if (ret == PTP_RC_OK) ptp_unpack_DPV(params, dpv, &offset, len, value, datatype);
+	free(dpv);
+	return ret;
+}
+
+uint16_t
+ptp_setdevicepropvalue (PTPParams* params, uint16_t propcode,
+			PTPPropertyValue *value, uint16_t datatype)
+{
+	PTPContainer ptp;
+	uint16_t ret;
+	uint32_t size;
+	unsigned char* dpv=NULL;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_SetDevicePropValue;
+	ptp.Param1=propcode;
+	ptp.Nparam=1;
+	size=ptp_pack_DPV(params, value, &dpv, datatype);
+	ret=ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &dpv, NULL);
+	free(dpv);
+	return ret;
+}
+
+/**
+ * ptp_ek_sendfileobjectinfo:
+ * params:	PTPParams*
+ *		uint32_t* store		- destination StorageID on Responder
+ *		uint32_t* parenthandle 	- Parent ObjectHandle on responder
+ * 		uint32_t* handle	- see Return values
+ *		PTPObjectInfo* objectinfo- ObjectInfo that is to be sent
+ * 
+ * Sends ObjectInfo of file that is to be sent via SendFileObject.
+ *
+ * Return values: Some PTP_RC_* code.
+ * Upon success : uint32_t* store	- Responder StorageID in which
+ *					  object will be stored
+ *		  uint32_t* parenthandle- Responder Parent ObjectHandle
+ *					  in which the object will be stored
+ *		  uint32_t* handle	- Responder's reserved ObjectHandle
+ *					  for the incoming object
+ **/
+uint16_t
+ptp_ek_sendfileobjectinfo (PTPParams* params, uint32_t* store, 
+			uint32_t* parenthandle, uint32_t* handle,
+			PTPObjectInfo* objectinfo)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char* oidata=NULL;
+	uint32_t size;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_EK_SendFileObjectInfo;
+	ptp.Param1=*store;
+	ptp.Param2=*parenthandle;
+	ptp.Nparam=2;
+	
+	size=ptp_pack_OI(params, objectinfo, &oidata);
+	ret=ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &oidata, NULL); 
+	free(oidata);
+	*store=ptp.Param1;
+	*parenthandle=ptp.Param2;
+	*handle=ptp.Param3; 
+	return ret;
+}
+
+/**
+ * ptp_ek_getserial:
+ * params:	PTPParams*
+ *		char**	serial		- contains the serial number of the camera
+ *		uint32_t* size		- contains the string length
+ *		
+ * Gets the serial number from the device. (ptp serial)
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ */
+uint16_t
+ptp_ek_getserial (PTPParams* params, unsigned char **data, unsigned int *size)
+{
+	PTPContainer ptp;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code   = PTP_OC_EK_GetSerial;
+	ptp.Nparam = 0;
+	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); 
+}
+
+/**
+ * ptp_ek_setserial:
+ * params:	PTPParams*
+ *		char*	serial		- contains the new serial number
+ *		uint32_t size		- string length
+ *		
+ * Sets the serial number of the device. (ptp serial)
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ */
+uint16_t
+ptp_ek_setserial (PTPParams* params, unsigned char *data, unsigned int size)
+{
+	PTPContainer ptp;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code   = PTP_OC_EK_SetSerial;
+	ptp.Nparam = 0;
+	return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL); 
+}
+
+/* unclear what it does yet */
+uint16_t
+ptp_ek_9007 (PTPParams* params, unsigned char **data, unsigned int *size)
+{
+	PTPContainer ptp;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code   = 0x9007;
+	ptp.Nparam = 0;
+	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); 
+}
+
+/* unclear what it does yet */
+uint16_t
+ptp_ek_9009 (PTPParams* params, uint32_t *p1, uint32_t *p2)
+{
+	PTPContainer	ptp;
+	uint16_t	ret;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code   = 0x9009;
+	ptp.Nparam = 0;
+	ret = ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); 
+	*p1 = ptp.Param1;
+	*p2 = ptp.Param2;
+	return ret;
+}
+
+/* unclear yet, but I guess it returns the info from 9008 */
+uint16_t
+ptp_ek_900c (PTPParams* params, unsigned char **data, unsigned int *size)
+{
+	PTPContainer ptp;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code   = 0x900c;
+	ptp.Nparam = 0;
+	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); 
+	/* returned data is 16bit,16bit,32bit,32bit */
+}
+
+/**
+ * ptp_ek_settext:
+ * params:	PTPParams*
+ *		PTPEKTextParams*	- contains the texts to display.
+ *		
+ * Displays the specified texts on the TFT of the camera.
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ */
+uint16_t
+ptp_ek_settext (PTPParams* params, PTPEKTextParams *text)
+{
+	PTPContainer ptp;
+	uint16_t ret;
+	unsigned int size;
+	unsigned char *data;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code   = PTP_OC_EK_SetText;
+	ptp.Nparam = 0;
+	if (0 == (size = ptp_pack_EK_text(params, text, &data)))
+		return PTP_ERROR_BADPARAM;
+	ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL); 
+	free(data);
+	return ret;
+}
+
+/**
+ * ptp_ek_sendfileobject:
+ * params:	PTPParams*
+ *		char*	object		- contains the object that is to be sent
+ *		uint32_t size		- object size
+ *		
+ * Sends object to Responder.
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ */
+uint16_t
+ptp_ek_sendfileobject (PTPParams* params, unsigned char* object, uint32_t size)
+{
+	PTPContainer ptp;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_EK_SendFileObject;
+	ptp.Nparam=0;
+
+	return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &object, NULL);
+}
+
+/**
+ * ptp_ek_sendfileobject_from_handler:
+ * params:	PTPParams*
+ *		PTPDataHandler*	handler	- contains the handler of the object that is to be sent
+ *		uint32_t size		- object size
+ *		
+ * Sends object to Responder.
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ */
+uint16_t
+ptp_ek_sendfileobject_from_handler (PTPParams* params, PTPDataHandler*handler, uint32_t size)
+{
+	PTPContainer ptp;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_EK_SendFileObject;
+	ptp.Nparam=0;
+	return ptp_transaction_new(params, &ptp, PTP_DP_SENDDATA, size, handler);
+}
+
+/*************************************************************************
+ *
+ * Canon PTP extensions support
+ *
+ * (C) Nikolai Kopanygin 2003
+ *
+ *************************************************************************/
+
+
+/**
+ * ptp_canon_getpartialobjectinfo:
+ * params:	PTPParams*
+ *		uint32_t handle		- ObjectHandle
+ *		uint32_t p2 		- Not fully understood parameter
+ *					  0 - returns full size
+ *					  1 - returns thumbnail size (or EXIF?)
+ * 
+ * Gets form the responder the size of the specified object.
+ *
+ * Return values: Some PTP_RC_* code.
+ * Upon success : uint32_t* size	- The object size
+ *		  uint32_t* rp2		- Still unknown return parameter
+ *                                        (perhaps upper 32bit of size)
+ *
+ *
+ **/
+uint16_t
+ptp_canon_getpartialobjectinfo (PTPParams* params, uint32_t handle, uint32_t p2, 
+			uint32_t* size, uint32_t* rp2) 
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_CANON_GetPartialObjectInfo;
+	ptp.Param1=handle;
+	ptp.Param2=p2;
+	ptp.Nparam=2;
+	ret=ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
+	*size=ptp.Param1;
+	*rp2=ptp.Param2;
+	return ret;
+}
+
+/**
+ * ptp_canon_get_mac_address:
+ * params:	PTPParams*
+ *					  value 0 works.
+ * Gets the MAC address of the wireless transmitter.
+ *
+ * Return values: Some PTP_RC_* code.
+ * Upon success : unsigned char* mac	- The MAC address
+ *
+ **/
+uint16_t
+ptp_canon_get_mac_address (PTPParams* params, unsigned char **mac)
+{
+	PTPContainer ptp;
+	unsigned int size = 0;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_CANON_GetMACAddress;
+	ptp.Nparam=0;
+	*mac = NULL;
+	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, mac, &size);
+}
+
+/**
+ * ptp_canon_get_directory:
+ * params:	PTPParams*
+
+ * Gets the full directory of the camera.
+ *
+ * Return values: Some PTP_RC_* code.
+ * Upon success : PTPObjectHandles        *handles	- filled out with handles
+ * 		  PTPObjectInfo           **oinfos	- allocated array of PTP Object Infos
+ * 		  uint32_t                **flags	- allocated array of CANON Flags
+ *
+ **/
+uint16_t
+ptp_canon_get_directory (PTPParams* params,
+	PTPObjectHandles	*handles,
+	PTPObjectInfo		**oinfos,	/* size(handles->n) */
+	uint32_t		**flags		/* size(handles->n) */
+) {
+	PTPContainer	ptp;
+	unsigned char	*dir = NULL;
+	unsigned int	size = 0;
+	uint16_t	ret;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_CANON_GetDirectory;
+	ptp.Nparam=0;
+	ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dir, &size);
+	if (ret != PTP_RC_OK)
+		return ret;
+	ret = ptp_unpack_canon_directory(params, dir, ptp.Param1, handles, oinfos, flags);
+	free (dir);
+	return ret;
+}
+
+/**
+ * ptp_canon_gettreeinfo:
+ * params:	PTPParams*
+ *              uint32_t *out
+ * 
+ * Switches the camera display to on and lets the user
+ * select what to transfer. Sends a 0xc011 event when started 
+ * and 0xc013 if direct transfer aborted.
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_canon_gettreeinfo (PTPParams* params, uint32_t *out)
+{
+	PTPContainer ptp;
+	uint16_t ret;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code   = PTP_OC_CANON_GetTreeInfo;
+	ptp.Nparam = 1;
+	ptp.Param1 = 0xf;
+	ret = ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
+	if ((ret == PTP_RC_OK) && (ptp.Nparam>0))
+		*out = ptp.Param1;
+	return ret;
+}
+
+/**
+ * ptp_canon_getpairinginfo:
+ * params:	PTPParams*
+ *              int nr
+ * 
+ * Get the pairing information.
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_canon_getpairinginfo (PTPParams* params, uint32_t nr, unsigned char **data, unsigned int *size)
+{
+	PTPContainer ptp;
+	uint16_t ret;
+	
+	PTP_CNT_INIT(ptp);
+	ptp.Code   = PTP_OC_CANON_GetPairingInfo;
+	ptp.Nparam = 1;
+	ptp.Param1 = nr;
+	*data = NULL;
+	*size = 0;
+	ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size);
+	if (ret != PTP_RC_OK)
+		return ret;
+	return PTP_RC_OK;
+}
+
+/**
+ * ptp_canon_get_target_handles:
+ * params:	PTPParams*
+ *              PTPCanon_directtransfer_entry **out
+ *              unsigned int *outsize
+ * 
+ * Retrieves direct transfer entries specifying the images to transfer
+ * from the camera (to be retrieved after 0xc011 event).
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_canon_gettreesize (PTPParams* params,
+	PTPCanon_directtransfer_entry **entries, unsigned int *cnt)
+{
+	PTPContainer ptp;
+	uint16_t ret;
+	unsigned char *out = NULL, *cur;
+	int i;
+	unsigned int size;
+	
+	PTP_CNT_INIT(ptp);
+	ptp.Code   = PTP_OC_CANON_GetTreeSize;
+	ptp.Nparam = 0;
+	ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &out, &size);
+	if (ret != PTP_RC_OK)
+		return ret;
+	*cnt = dtoh32a(out);
+	*entries = malloc(sizeof(PTPCanon_directtransfer_entry)*(*cnt));
+	cur = out+4;
+	for (i=0;i<*cnt;i++) {
+		unsigned char len;
+		(*entries)[i].oid = dtoh32a(cur);
+		(*entries)[i].str = ptp_unpack_string(params, cur, 4, &len);
+		cur += 4+(cur[4]*2+1);
+	}
+	free (out);
+	return PTP_RC_OK;
+}
+
+/**
+ * ptp_canon_checkevent:
+ * params:	PTPParams*
+ * 
+ * The camera has a FIFO stack, in which it accumulates events.
+ * Partially these events are communicated also via the USB interrupt pipe
+ * according to the PTP USB specification, partially not.
+ * This operation returns from the device a block of data, empty,
+ * if the event stack is empty, or filled with an event's data otherwise.
+ * The event is removed from the stack in the latter case.
+ * The Remote Capture app sends this command to the camera all the time
+ * of connection, filling with it the gaps between other operations. 
+ *
+ * Return values: Some PTP_RC_* code.
+ * Upon success : PTPUSBEventContainer* event	- is filled with the event data
+ *						  if any
+ *                int *isevent			- returns 1 in case of event
+ *						  or 0 otherwise
+ **/
+uint16_t
+ptp_canon_checkevent (PTPParams* params, PTPContainer* event, int* isevent)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char *evdata = NULL;
+	unsigned int len;
+	
+	*isevent=0;
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_CANON_CheckEvent;
+	ptp.Nparam=0;
+	len=0;
+	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &evdata, &len);
+	if (evdata!=NULL) {
+		if (ret == PTP_RC_OK) {
+        		ptp_unpack_EC(params, evdata, event, len);
+    			*isevent=1;
+        	}
+		free(evdata);
+	}
+	return ret;
+}
+
+uint16_t
+ptp_check_event (PTPParams *params) {
+	PTPContainer		event;
+	uint16_t		ret;
+
+	if (	(params->deviceinfo.VendorExtensionID == PTP_VENDOR_NIKON) &&
+		ptp_operation_issupported(params, PTP_OC_NIKON_CheckEvent)
+	) {
+		int evtcnt;
+		PTPContainer	*xevent = NULL;
+
+		ret = ptp_nikon_check_event(params, &xevent, &evtcnt);
+		if (ret != PTP_RC_OK)
+			return ret;
+
+		if (evtcnt) {
+			if (params->nrofevents)
+				params->events = realloc(params->events, sizeof(PTPContainer)*(evtcnt+params->nrofevents));
+			else
+				params->events = malloc(sizeof(PTPContainer)*evtcnt);
+			memcpy (&params->events[params->nrofevents],xevent,evtcnt*sizeof(PTPContainer));
+			params->nrofevents += evtcnt;
+			free (xevent);
+		}
+		return PTP_RC_OK;
+	}
+	if (	(params->deviceinfo.VendorExtensionID == PTP_VENDOR_CANON) &&
+		ptp_operation_issupported(params, PTP_OC_CANON_CheckEvent)
+	) {
+		int isevent;
+
+		ret = ptp_canon_checkevent (params,&event,&isevent);
+		if (ret!=PTP_RC_OK)
+			return ret;
+		if (isevent)
+			goto store_event;
+		/* FIXME: fallthrough or return? */
+	}
+	ret = params->event_check(params,&event);
+
+store_event:
+	if (ret == PTP_RC_OK) {
+		ptp_debug (params, "event: nparams=0x%X, code=0x%X, trans_id=0x%X, p1=0x%X, p2=0x%X, p3=0x%X", event.Nparam,event.Code,event.Transaction_ID, event.Param1, event.Param2, event.Param3);
+		if (params->nrofevents)
+			params->events = realloc(params->events, sizeof(PTPContainer)*(params->nrofevents+1));
+		else
+			params->events = malloc(sizeof(PTPContainer)*1);
+		memcpy (&params->events[params->nrofevents],&event,1*sizeof(PTPContainer));
+		params->nrofevents += 1;
+	}
+	if (ret == PTP_ERROR_TIMEOUT) /* ok, just new events */
+		ret = PTP_RC_OK;
+	return ret;
+}
+
+int
+ptp_get_one_event(PTPParams *params, PTPContainer *event) {
+	if (!params->nrofevents)
+		return 0;
+	memcpy (event, params->events, sizeof(PTPContainer));
+	memmove (params->events, params->events+1, sizeof(PTPContainer)*(params->nrofevents-1));
+	/* do not realloc on shrink. */
+	params->nrofevents--;
+	return 1;
+}
+
+/**
+ * ptp_canon_eos_getevent:
+ * 
+ * This retrieves configuration status/updates/changes
+ * on EOS cameras. It reads a datablock which has a list of variable
+ * sized structures.
+ *
+ * params:	PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_canon_eos_getevent (PTPParams* params, PTPCanon_changes_entry **entries, int *nrofentries)
+{
+	PTPContainer ptp;
+	uint16_t	ret;
+	unsigned int 	size = 0;
+	unsigned char	*data = NULL;
+
+	*nrofentries = 0;
+	*entries = NULL;
+	PTP_CNT_INIT(ptp);
+	ptp.Code = PTP_OC_CANON_EOS_GetEvent;
+	ptp.Nparam = 0;
+	ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size);
+	if (ret != PTP_RC_OK) return ret;
+        *nrofentries = ptp_unpack_CANON_changes(params,data,size,entries);
+	return PTP_RC_OK;
+}
+
+uint16_t
+ptp_canon_eos_getdevicepropdesc (PTPParams* params, uint16_t propcode,
+	PTPDevicePropDesc *dpd)
+{
+	int i;
+
+	for (i=0;i<params->nrofcanon_props;i++)
+		if (params->canon_props[i].proptype == propcode)
+			break;
+	if (params->nrofcanon_props == i)
+		return PTP_RC_Undefined;
+	memcpy (dpd, &params->canon_props[i].dpd, sizeof (*dpd));
+	if (dpd->FormFlag == PTP_DPFF_Enumeration) {
+		/* need to duplicate the Enumeration alloc */
+		dpd->FORM.Enum.SupportedValue = malloc (sizeof (PTPPropertyValue)*dpd->FORM.Enum.NumberOfValues);
+		memcpy (dpd->FORM.Enum.SupportedValue,
+			params->canon_props[i].dpd.FORM.Enum.SupportedValue,
+			sizeof (PTPPropertyValue)*dpd->FORM.Enum.NumberOfValues
+		);
+	}
+	if (dpd->DataType == PTP_DTC_STR) {
+		dpd->FactoryDefaultValue.str = strdup( params->canon_props[i].dpd.FactoryDefaultValue.str );
+		dpd->CurrentValue.str = strdup( params->canon_props[i].dpd.CurrentValue.str );
+	}
+
+	return PTP_RC_OK;
+}
+
+
+uint16_t
+ptp_canon_eos_getstorageids (PTPParams* params, PTPStorageIDs* storageids)
+{
+	PTPContainer	ptp;
+	unsigned int	len = 0;
+	uint16_t	ret;
+	unsigned char*	sids=NULL;
+	
+	PTP_CNT_INIT(ptp);
+	ptp.Code 	= PTP_OC_CANON_EOS_GetStorageIDs;
+	ptp.Nparam	= 0;
+	ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &sids, &len);
+	if (ret == PTP_RC_OK) ptp_unpack_SIDs(params, sids, storageids, len);
+	free(sids);
+	return ret;
+}
+
+uint16_t
+ptp_canon_eos_getstorageinfo (PTPParams* params, uint32_t p1)
+{
+	PTPContainer ptp;
+	unsigned char	*data = NULL;
+	unsigned int	size = 0;
+	uint16_t	ret;
+	
+	PTP_CNT_INIT(ptp);
+	ptp.Code 	= PTP_OC_CANON_EOS_GetStorageInfo;
+	ptp.Nparam	= 1;
+	ptp.Param1	= p1;
+	ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size);
+	/* FIXME: do stuff with data */
+	return ret;
+}
+
+/**
+ * ptp_canon_eos_getpartialobject:
+ * 
+ * This retrieves a part of an PTP object which you specify as object id.
+ * The id originates from 0x9116 call.
+ * After finishing it, we seem to need to call ptp_canon_eos_enddirecttransfer.
+ *
+ * params:	PTPParams*
+ * 		oid		Object ID
+ * 		offset		The offset where to start the data transfer 
+ *		xsize		Size in bytes of the transfer to do
+ *		data		Pointer that receives the malloc()ed memory of the transfer.
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ */
+uint16_t
+ptp_canon_eos_getpartialobject (PTPParams* params, uint32_t oid, uint32_t offset, uint32_t xsize, unsigned char**data)
+{
+	PTPContainer	ptp;
+	unsigned int	size = 0;
+
+	*data = NULL;
+	PTP_CNT_INIT(ptp);
+	ptp.Code 	= PTP_OC_CANON_EOS_GetPartialObject;
+	ptp.Nparam	= 3;
+	ptp.Param1	= oid;
+	ptp.Param2	= offset;
+	ptp.Param3	= xsize;
+	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, &size);
+}
+
+uint16_t
+ptp_canon_eos_setdevicepropvalueex (PTPParams* params, unsigned char* data, unsigned int size)
+{
+	PTPContainer	ptp;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code 	= PTP_OC_CANON_EOS_SetDevicePropValueEx;
+	ptp.Nparam	= 0;
+	return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL);
+}
+
+uint16_t
+ptp_canon_eos_setdevicepropvalue (PTPParams* params,
+	uint16_t propcode, PTPPropertyValue *value, uint16_t datatype
+) {
+	PTPContainer	ptp;
+	uint16_t	ret;
+	int 		i;
+	unsigned char	*data;
+	unsigned int	size;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code 	= PTP_OC_CANON_EOS_SetDevicePropValueEx;
+	ptp.Nparam	= 0;
+	for (i=0;i<params->nrofcanon_props;i++)
+		if (params->canon_props[i].proptype == propcode)
+			break;
+	if (params->nrofcanon_props == i)
+		return PTP_RC_Undefined;
+
+	switch (propcode) {
+	case PTP_DPC_CANON_EOS_ImageFormat:
+	case PTP_DPC_CANON_EOS_ImageFormatCF:
+	case PTP_DPC_CANON_EOS_ImageFormatSD:
+	case PTP_DPC_CANON_EOS_ImageFormatExtHD:
+		/* special handling of ImageFormat properties */
+		size = 8 + ptp_pack_EOS_ImageFormat( params, NULL, value->u16 );
+		data = malloc( size );
+		params->canon_props[i].dpd.CurrentValue.u16 = value->u16;
+		ptp_pack_EOS_ImageFormat( params, data + 8, value->u16 );
+		break;
+	default:
+		if (datatype != PTP_DTC_STR) {
+			data = calloc(sizeof(uint32_t),3);
+			size = sizeof(uint32_t)*3;
+		} else {
+			size = strlen(value->str) + 1 + 8;
+			data = calloc(sizeof(char),size);
+		}
+		switch (datatype) {
+		case PTP_DTC_UINT8:
+			/*fprintf (stderr, "%x -> %d\n", propcode, value->u8);*/
+			htod8a(&data[8], value->u8);
+			params->canon_props[i].dpd.CurrentValue.u8 = value->u8;
+			break;
+		case PTP_DTC_UINT16:
+			/*fprintf (stderr, "%x -> %d\n", propcode, value->u16);*/
+			htod16a(&data[8], value->u16);
+			params->canon_props[i].dpd.CurrentValue.u16 = value->u16;
+			break;
+		case PTP_DTC_UINT32:
+			/*fprintf (stderr, "%x -> %d\n", propcode, value->u32);*/
+			htod32a(&data[8], value->u32);
+			params->canon_props[i].dpd.CurrentValue.u32 = value->u32;
+			break;
+		case PTP_DTC_STR:
+			strcpy((char*)data + 8, value->str);
+			free (params->canon_props[i].dpd.CurrentValue.str);
+			params->canon_props[i].dpd.CurrentValue.str = strdup(value->str);
+			break;
+		}
+	}
+
+	htod32a(&data[0], size);
+	htod32a(&data[4], propcode);
+
+	ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL);
+	free (data);
+	return ret;
+}
+
+/**
+ * ptp_canon_getpartialobject:
+ *
+ * This operation is used to read from the device a data 
+ * block of an object from a specified offset.
+ *
+ * params:	PTPParams*
+ *      uint32_t handle - the handle of the requested object
+ *      uint32_t offset - the offset in bytes from the beginning of the object
+ *      uint32_t size - the requested size of data block to read
+ *      uint32_t pos - 1 for the first block, 2 - for a block in the middle,
+ *                  3 - for the last block
+ *
+ * Return values: Some PTP_RC_* code.
+ *      char **block - the pointer to the block of data read
+ *      uint32_t* readnum - the number of bytes read
+ *
+ **/
+uint16_t
+ptp_canon_getpartialobject (PTPParams* params, uint32_t handle, 
+				uint32_t offset, uint32_t size,
+				uint32_t pos, unsigned char** block, 
+				uint32_t* readnum)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char *data=NULL;
+	unsigned int len;
+	
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_CANON_GetPartialObjectEx;
+	ptp.Param1=handle;
+	ptp.Param2=offset;
+	ptp.Param3=size;
+	ptp.Param4=pos;
+	ptp.Nparam=4;
+	len=0;
+	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len);
+	if (ret==PTP_RC_OK) {
+		*block=data;
+		*readnum=ptp.Param1;
+	}
+	return ret;
+}
+
+/**
+ * ptp_canon_getviewfinderimage:
+ *
+ * This operation can be used to read the image which is currently
+ * in the camera's viewfinder. The image size is 320x240, format is JPEG.
+ * Of course, prior to calling this operation, one must turn the viewfinder
+ * on with the CANON_ViewfinderOn command.
+ * Invoking this operation many times, one can get live video from the camera!
+ * 
+ * params:	PTPParams*
+ * 
+ * Return values: Some PTP_RC_* code.
+ *      char **image - the pointer to the read image
+ *      unit32_t *size - the size of the image in bytes
+ *
+ **/
+uint16_t
+ptp_canon_getviewfinderimage (PTPParams* params, unsigned char** image, uint32_t* size)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned int len;
+	
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_CANON_GetViewfinderImage;
+	ptp.Nparam=0;
+	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, image, &len);
+	if (ret==PTP_RC_OK) *size=ptp.Param1;
+	return ret;
+}
+
+/**
+ * ptp_canon_getchanges:
+ *
+ * This is an interesting operation, about the effect of which I am not sure.
+ * This command is called every time when a device property has been changed 
+ * with the SetDevicePropValue operation, and after some other operations.
+ * This operation reads the array of Device Properties which have been changed
+ * by the previous operation.
+ * Probably, this operation is even required to make those changes work.
+ *
+ * params:	PTPParams*
+ * 
+ * Return values: Some PTP_RC_* code.
+ *      uint16_t** props - the pointer to the array of changed properties
+ *      uint32_t* propnum - the number of elements in the *props array
+ *
+ **/
+uint16_t
+ptp_canon_getchanges (PTPParams* params, uint16_t** props, uint32_t* propnum)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char* data=NULL;
+	unsigned int len;
+	
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_CANON_GetChanges;
+	ptp.Nparam=0;
+	len=0;
+	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len);
+	if (ret == PTP_RC_OK)
+        	*propnum=ptp_unpack_uint16_t_array(params,data,0,props);
+	free(data);
+	return ret;
+}
+
+/**
+ * ptp_canon_getobjectinfo:
+ *
+ * This command reads a specified object's record in a device's filesystem,
+ * or the records of all objects belonging to a specified folder (association).
+ *  
+ * params:	PTPParams*
+ *      uint32_t store - StorageID,
+ *      uint32_t p2 - Yet unknown (0 value works OK)
+ *      uint32_t parent - Parent Object Handle
+ *                      # If Parent Object Handle is 0xffffffff, 
+ *                      # the Parent Object is the top level folder.
+ *      uint32_t handle - Object Handle
+ *                      # If Object Handle is 0, the records of all objects 
+ *                      # belonging to the Parent Object are read.
+ *                      # If Object Handle is not 0, only the record of this 
+ *                      # Object is read.
+ *
+ * Return values: Some PTP_RC_* code.
+ *      PTPCANONFolderEntry** entries - the pointer to the folder entry array
+ *      uint32_t* entnum - the number of elements of the array
+ *
+ **/
+uint16_t
+ptp_canon_getobjectinfo (PTPParams* params, uint32_t store, uint32_t p2, 
+			    uint32_t parent, uint32_t handle, 
+			    PTPCANONFolderEntry** entries, uint32_t* entnum)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char *data = NULL;
+	unsigned int len;
+	
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_CANON_GetObjectInfoEx;
+	ptp.Param1=store;
+	ptp.Param2=p2;
+	ptp.Param3=parent;
+	ptp.Param4=handle;
+	ptp.Nparam=4;
+	len=0;
+	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len);
+	if (ret == PTP_RC_OK) {
+		int i;
+		*entnum=ptp.Param1;
+		*entries=calloc(*entnum, sizeof(PTPCANONFolderEntry));
+		if (*entries!=NULL) {
+			for(i=0; i<(*entnum); i++)
+				ptp_unpack_Canon_FE(params,
+					data+i*PTP_CANON_FolderEntryLen,
+					&((*entries)[i]) );
+		} else {
+			ret=PTP_ERROR_IO; /* Cannot allocate memory */
+		}
+	}
+	free(data);
+	return ret;
+}
+
+/**
+ * ptp_canon_get_objecthandle_by_name:
+ *
+ * This command looks up the specified object on the camera.
+ *
+ * Format is "A:\\PATH".
+ *
+ * The 'A' is the VolumeLabel from GetStorageInfo,
+ * my IXUS has "A" for the card and "V" for internal memory.
+ *  
+ * params:	PTPParams*
+ *      char* name - path name
+ *
+ * Return values: Some PTP_RC_* code.
+ *      uint32_t *oid - PTP object id.
+ *
+ **/
+uint16_t
+ptp_canon_get_objecthandle_by_name (PTPParams* params, char* name, uint32_t* objectid)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char *data = NULL;
+	uint8_t len;
+
+	PTP_CNT_INIT (ptp);
+	ptp.Code=PTP_OC_CANON_GetObjectHandleByName;
+	ptp.Nparam=0;
+	len=0;
+	data = malloc (2*(strlen(name)+1)+2);
+	memset (data, 0, 2*(strlen(name)+1)+2);
+	ptp_pack_string (params, name, data, 0, &len);
+	ret=ptp_transaction (params, &ptp, PTP_DP_SENDDATA, (len+1)*2+1, &data, NULL);
+	free (data);
+	*objectid = ptp.Param1;
+	return ret;
+}
+
+/**
+ * ptp_canon_get_customize_data:
+ *
+ * This command downloads the specified theme slot, including jpegs
+ * and wav files.
+ *  
+ * params:	PTPParams*
+ *      uint32_t themenr - nr of theme
+ *
+ * Return values: Some PTP_RC_* code.
+ *      unsigned char **data - pointer to data pointer
+ *      unsigned int  *size - size of data returned
+ *
+ **/
+uint16_t
+ptp_canon_get_customize_data (PTPParams* params, uint32_t themenr,
+		unsigned char **data, unsigned int *size)
+{
+	PTPContainer ptp;
+
+	*data = NULL;
+	*size = 0;
+	PTP_CNT_INIT(ptp);
+	ptp.Code	= PTP_OC_CANON_GetCustomizeData;
+	ptp.Param1	= themenr;
+	ptp.Nparam	= 1;
+	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); 
+}
+
+
+uint16_t
+ptp_nikon_curve_download (PTPParams* params, unsigned char **data, unsigned int *size) {
+	PTPContainer ptp;
+	*data = NULL;
+	*size = 0;
+	PTP_CNT_INIT(ptp);
+	ptp.Code	= PTP_OC_NIKON_CurveDownload;
+	ptp.Nparam	= 0;
+	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); 
+}
+
+/**
+ * ptp_canon_get_vendorpropcodes:
+ *
+ * This command downloads the vendor specific property codes.
+ *  
+ * params:	PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *      unsigned char **data - pointer to data pointer
+ *      unsigned int  *size - size of data returned
+ *
+ **/
+uint16_t
+ptp_nikon_get_vendorpropcodes (PTPParams* params, uint16_t **props, unsigned int *size) {
+	PTPContainer	ptp;
+	uint16_t	ret;
+	unsigned char	*xdata;
+	unsigned int 	xsize;
+
+	*props = NULL;
+	*size = 0;
+	PTP_CNT_INIT(ptp);
+	ptp.Code	= PTP_OC_NIKON_GetVendorPropCodes;
+	ptp.Nparam	= 0;
+	ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &xdata, &xsize); 
+	if (ret == PTP_RC_OK)
+        	*size = ptp_unpack_uint16_t_array(params,xdata,0,props);
+	return ret;
+}
+
+uint16_t
+ptp_nikon_getfileinfoinblock ( PTPParams* params,
+	uint32_t p1, uint32_t p2, uint32_t p3,
+	unsigned char **data, unsigned int *size
+) {
+	PTPContainer ptp;
+	*data = NULL;
+	*size = 0;
+	PTP_CNT_INIT(ptp);
+	ptp.Code	= PTP_OC_NIKON_GetFileInfoInBlock;
+	ptp.Nparam	= 3;
+	ptp.Param1	= p1;
+	ptp.Param2	= p2;
+	ptp.Param3	= p3;
+	return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); 
+}
+
+/**
+ * ptp_nikon_get_liveview_image:
+ *
+ * This command gets a LiveView image from newer Nikons DSLRs.
+ *  
+ * params:	PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_nikon_get_liveview_image (PTPParams* params, unsigned char **data, unsigned int *size)
+{
+        PTPContainer ptp;
+        
+        PTP_CNT_INIT(ptp);
+        ptp.Code=PTP_OC_NIKON_GetLiveViewImg;
+        ptp.Nparam=0;
+        return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size);
+}
+
+/**
+ * ptp_nikon_get_preview_image:
+ *
+ * This command gets a Preview image from newer Nikons DSLRs.
+ *  
+ * params:	PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_nikon_get_preview_image (PTPParams* params, unsigned char **xdata, unsigned int *xsize,
+	uint32_t *handle)
+{
+        PTPContainer	ptp;
+	uint16_t	ret;
+        
+        PTP_CNT_INIT(ptp);
+        ptp.Code=PTP_OC_NIKON_GetPreviewImg;
+        ptp.Nparam=0;
+        ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, xdata, xsize);
+	if (ret == PTP_RC_OK) {
+		if (ptp.Nparam > 0)
+			*handle = ptp.Param1;
+	}
+	return ret;
+}
+
+/**
+ * ptp_canon_eos_get_viewfinder_image:
+ *
+ * This command gets a Viewfinder image from newer Nikons DSLRs.
+ *  
+ * params:	PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_canon_eos_get_viewfinder_image (PTPParams* params, unsigned char **data, unsigned int *size)
+{
+        PTPContainer ptp;
+        
+        PTP_CNT_INIT(ptp);
+        ptp.Code=PTP_OC_CANON_EOS_GetViewFinderData;
+        ptp.Nparam=1;
+        ptp.Param1=0x00100000; /* from trace */
+        return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size);
+}
+
+/**
+ * ptp_nikon_check_event:
+ *
+ * This command checks the event queue on the Nikon.
+ *  
+ * params:	PTPParams*
+ *      PTPUSBEventContainer **event - list of usb events.
+ *	int *evtcnt - number of usb events in event structure.
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_nikon_check_event (PTPParams* params, PTPContainer** event, int* evtcnt)
+{
+        PTPContainer ptp;
+	uint16_t ret;
+	unsigned char *data = NULL;
+	unsigned int size = 0;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_NIKON_CheckEvent;
+	ptp.Nparam=0;
+	*evtcnt = 0;
+	ret = ptp_transaction (params, &ptp, PTP_DP_GETDATA, 0, &data, &size);
+	if (ret == PTP_RC_OK) {
+		ptp_unpack_Nikon_EC (params, data, size, event, evtcnt);
+		free (data);
+	}
+	return ret;
+}
+
+/**
+ * ptp_nikon_getptpipinfo:
+ *
+ * This command gets the ptpip info data.
+ *  
+ * params:	PTPParams*
+ *	unsigned char *data	- data
+ *	unsigned int size	- size of returned data
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_nikon_getptpipinfo (PTPParams* params, unsigned char **data, unsigned int *size)
+{
+        PTPContainer ptp;
+        
+        PTP_CNT_INIT(ptp);
+        ptp.Code=PTP_OC_NIKON_GetDevicePTPIPInfo;
+        ptp.Nparam=0;
+        return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size);
+}
+
+/**
+ * ptp_nikon_getwifiprofilelist:
+ *
+ * This command gets the wifi profile list.
+ *  
+ * params:	PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_nikon_getwifiprofilelist (PTPParams* params)
+{
+        PTPContainer ptp;
+	unsigned char* data;
+	unsigned int size;
+	unsigned int pos;
+	unsigned int profn;
+	unsigned int n;
+	char* buffer;
+	uint8_t len;
+	
+        PTP_CNT_INIT(ptp);
+        ptp.Code=PTP_OC_NIKON_GetProfileAllData;
+        ptp.Nparam=0;
+	size = 0;
+	data = NULL;
+	CHECK_PTP_RC(ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size));
+
+	if (size < 2) return PTP_RC_Undefined; /* FIXME: Add more precise error code */
+
+	params->wifi_profiles_version = data[0];
+	params->wifi_profiles_number = data[1];
+	if (params->wifi_profiles)
+		free(params->wifi_profiles);
+	
+	params->wifi_profiles = malloc(params->wifi_profiles_number*sizeof(PTPNIKONWifiProfile));
+	memset(params->wifi_profiles, 0, params->wifi_profiles_number*sizeof(PTPNIKONWifiProfile));
+
+	pos = 2;
+	profn = 0;
+	while (profn < params->wifi_profiles_number && pos < size) {
+		if (pos+6 >= size) return PTP_RC_Undefined;
+		params->wifi_profiles[profn].id = data[pos++];
+		params->wifi_profiles[profn].valid = data[pos++];
+
+		n = dtoh32a(&data[pos]);
+		pos += 4;
+		if (pos+n+4 >= size) return PTP_RC_Undefined;
+		strncpy(params->wifi_profiles[profn].profile_name, (char*)&data[pos], n);
+		params->wifi_profiles[profn].profile_name[16] = '\0';
+		pos += n;
+
+		params->wifi_profiles[profn].display_order = data[pos++];
+		params->wifi_profiles[profn].device_type = data[pos++];
+		params->wifi_profiles[profn].icon_type = data[pos++];
+
+		buffer = ptp_unpack_string(params, data, pos, &len);
+		strncpy(params->wifi_profiles[profn].creation_date, buffer, sizeof(params->wifi_profiles[profn].creation_date));
+		free (buffer);
+		pos += (len*2+1);
+		if (pos+1 >= size) return PTP_RC_Undefined;
+		/* FIXME: check if it is really last usage date */
+		buffer = ptp_unpack_string(params, data, pos, &len);
+		strncpy(params->wifi_profiles[profn].lastusage_date, buffer, sizeof(params->wifi_profiles[profn].lastusage_date));
+		free (buffer);
+		pos += (len*2+1);
+		if (pos+5 >= size) return PTP_RC_Undefined;
+		
+		n = dtoh32a(&data[pos]);
+		pos += 4;
+		if (pos+n >= size) return PTP_RC_Undefined;
+		strncpy(params->wifi_profiles[profn].essid, (char*)&data[pos], n);
+		params->wifi_profiles[profn].essid[32] = '\0';
+		pos += n;
+		pos += 1;
+		profn++;
+	}
+
+#if 0
+	PTPNIKONWifiProfile test;
+	memset(&test, 0, sizeof(PTPNIKONWifiProfile));
+	strcpy(test.profile_name, "MyTest");
+	test.icon_type = 1;
+	strcpy(test.essid, "nikon");
+	test.ip_address = 10 + 11 << 16 + 11 << 24;
+	test.subnet_mask = 24;
+	test.access_mode = 1;
+	test.wifi_channel = 1;
+	test.key_nr = 1;
+
+	ptp_nikon_writewifiprofile(params, &test);
+#endif
+
+	return PTP_RC_OK;
+}
+
+/**
+ * ptp_nikon_writewifiprofile:
+ *
+ * This command gets the ptpip info data.
+ *  
+ * params:	PTPParams*
+ *	unsigned int profilenr	- profile number
+ *	unsigned char *data	- data
+ *	unsigned int size	- size of returned data
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_nikon_writewifiprofile (PTPParams* params, PTPNIKONWifiProfile* profile)
+{
+	unsigned char guid[16];
+	
+	PTPContainer ptp;
+	unsigned char buffer[1024];
+	unsigned char* data = buffer;
+	int size = 0;
+	int i;
+	uint8_t len;
+	int profilenr = -1;
+	
+	ptp_nikon_getptpipguid(guid);
+
+	if (!params->wifi_profiles)
+		CHECK_PTP_RC(ptp_nikon_getwifiprofilelist(params));
+	
+	for (i = 0; i < params->wifi_profiles_number; i++) {
+		if (!params->wifi_profiles[i].valid) {
+			profilenr = params->wifi_profiles[i].id;
+			break;
+		}
+	}
+	
+	if (profilenr == -1) {
+		/* No free profile! */
+		return PTP_RC_StoreFull;
+	}
+	
+	memset(buffer, 0, 1024);
+	
+	buffer[0x00] = 0x64; /* Version */
+	
+	/* Profile name */
+	htod32a(&buffer[0x01], 17);
+	/* 16 as third parameter, so there will always be a null-byte in the end */
+	strncpy((char*)&buffer[0x05], profile->profile_name, 16);
+	
+	buffer[0x16] = 0x00; /* Display order */
+	buffer[0x17] = profile->device_type;
+	buffer[0x18] = profile->icon_type;
+	
+	/* FIXME: Creation date: put a real date here */
+	ptp_pack_string(params, "19990909T090909", data, 0x19, &len);
+	
+	/* IP parameters */
+	*((unsigned int*)&buffer[0x3A]) = profile->ip_address; /* Do not reverse bytes */
+	buffer[0x3E] = profile->subnet_mask;
+	*((unsigned int*)&buffer[0x3F]) = profile->gateway_address; /* Do not reverse bytes */
+	buffer[0x43] = profile->address_mode;
+	
+	/* Wifi parameters */
+	buffer[0x44] = profile->access_mode;
+	buffer[0x45] = profile->wifi_channel;
+	
+	htod32a(&buffer[0x46], 33); /* essid */
+	 /* 32 as third parameter, so there will always be a null-byte in the end */
+	strncpy((char*)&buffer[0x4A], profile->essid, 32);
+	
+	buffer[0x6B] = profile->authentification;
+	buffer[0x6C] = profile->encryption;
+	htod32a(&buffer[0x6D], 64);
+	for (i = 0; i < 64; i++) {
+		buffer[0x71+i] = profile->key[i];
+	}
+	buffer[0xB1] = profile->key_nr;
+	memcpy(&buffer[0xB2], guid, 16);
+	
+	switch(profile->encryption) {
+	case 1: /* WEP 64bit */
+		htod16a(&buffer[0xC2], 5); /* (64-24)/8 = 5 */
+		break;
+	case 2: /* WEP 128bit */
+		htod16a(&buffer[0xC2], 13); /* (128-24)/8 = 13 */
+		break;
+	default:
+		htod16a(&buffer[0xC2], 0);
+	}
+	size = 0xC4;
+	       
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_NIKON_SendProfileData;
+	ptp.Nparam=1;
+	ptp.Param1=profilenr;
+	return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL);
+}
+
+/**
+ * ptp_mtp_getobjectpropssupported:
+ *
+ * This command gets the object properties possible from the device.
+ *  
+ * params:	PTPParams*
+ *	uint ofc		- object format code
+ *	unsigned int *propnum	- number of elements in returned array
+ *	uint16_t *props		- array of supported properties
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_mtp_getobjectpropssupported (PTPParams* params, uint16_t ofc,
+		 uint32_t *propnum, uint16_t **props
+) {
+        PTPContainer ptp;
+	uint16_t ret;
+	unsigned char *data = NULL;
+	unsigned int size = 0;
+        
+        PTP_CNT_INIT(ptp);
+        ptp.Code=PTP_OC_MTP_GetObjectPropsSupported;
+        ptp.Nparam = 1;
+        ptp.Param1 = ofc;
+        ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size);
+	if (ret == PTP_RC_OK)
+        	*propnum=ptp_unpack_uint16_t_array(params,data,0,props);
+	free(data);
+	return ret;
+}
+
+/**
+ * ptp_mtp_getobjectpropdesc:
+ *
+ * This command gets the object property description.
+ *  
+ * params:	PTPParams*
+ *	uint16_t opc	- object property code
+ *	uint16_t ofc	- object format code
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_mtp_getobjectpropdesc (
+	PTPParams* params, uint16_t opc, uint16_t ofc, PTPObjectPropDesc *opd
+) {
+        PTPContainer ptp;
+	uint16_t ret;
+	unsigned char *data = NULL;
+	unsigned int size = 0;
+        
+        PTP_CNT_INIT(ptp);
+        ptp.Code=PTP_OC_MTP_GetObjectPropDesc;
+        ptp.Nparam = 2;
+        ptp.Param1 = opc;
+        ptp.Param2 = ofc;
+        ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size);
+	if (ret == PTP_RC_OK)
+		ptp_unpack_OPD (params, data, opd, size);
+	free(data);
+	return ret;
+}
+
+/**
+ * ptp_mtp_getobjectpropvalue:
+ *
+ * This command gets the object properties of an object handle.
+ *  
+ * params:	PTPParams*
+ *	uint32_t objectid	- object format code
+ *	uint16_t opc		- object prop code
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_mtp_getobjectpropvalue (
+	PTPParams* params, uint32_t oid, uint16_t opc,
+	PTPPropertyValue *value, uint16_t datatype
+) {
+        PTPContainer ptp;
+	uint16_t ret;
+	unsigned char *data = NULL;
+	unsigned int size = 0;
+	int offset = 0;
+        
+        PTP_CNT_INIT(ptp);
+        ptp.Code=PTP_OC_MTP_GetObjectPropValue;
+        ptp.Nparam = 2;
+        ptp.Param1 = oid;
+        ptp.Param2 = opc;
+        ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size);
+	if (ret == PTP_RC_OK)
+		ptp_unpack_DPV(params, data, &offset, size, value, datatype);
+	free(data);
+	return ret;
+}
+
+/**
+ * ptp_mtp_setobjectpropvalue:
+ *
+ * This command gets the object properties of an object handle.
+ *  
+ * params:	PTPParams*
+ *	uint32_t objectid	- object format code
+ *	uint16_t opc		- object prop code
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+uint16_t
+ptp_mtp_setobjectpropvalue (
+	PTPParams* params, uint32_t oid, uint16_t opc,
+	PTPPropertyValue *value, uint16_t datatype
+) {
+        PTPContainer ptp;
+	uint16_t ret;
+	unsigned char *data = NULL;
+	unsigned int size ;
+        
+        PTP_CNT_INIT(ptp);
+        ptp.Code=PTP_OC_MTP_SetObjectPropValue;
+        ptp.Nparam = 2;
+        ptp.Param1 = oid;
+        ptp.Param2 = opc;
+	size = ptp_pack_DPV(params, value, &data, datatype);
+        ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL);
+	free(data);
+	return ret;
+}
+
+uint16_t
+ptp_mtp_getobjectreferences (PTPParams* params, uint32_t handle, uint32_t** ohArray, uint32_t* arraylen)
+{
+	PTPContainer ptp;
+	uint16_t ret;
+	unsigned char* dpv=NULL;
+	unsigned int dpvlen = 0;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code=PTP_OC_MTP_GetObjectReferences;
+	ptp.Param1=handle;
+	ptp.Nparam=1;
+	ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpv, &dpvlen);
+	if (ret == PTP_RC_OK) {
+		/* Sandisk Sansa skips the DATA phase, but returns OK as response.
+		 * this will gives us a NULL here. Handle it. -Marcus */
+		if ((dpv == NULL) || (dpvlen == 0)) {
+			*arraylen = 0;
+			*ohArray = NULL;
+		} else {
+			*arraylen = ptp_unpack_uint32_t_array(params, dpv, 0, ohArray);
+		}
+	}
+	free(dpv);
+	return ret;
+}
+
+uint16_t
+ptp_mtp_setobjectreferences (PTPParams* params, uint32_t handle, uint32_t* ohArray, uint32_t arraylen)
+{
+	PTPContainer ptp;
+	uint16_t ret;
+	uint32_t size;
+	unsigned char* dpv=NULL;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code   = PTP_OC_MTP_SetObjectReferences;
+	ptp.Param1 = handle;
+	ptp.Nparam = 1;
+	size = ptp_pack_uint32_t_array(params, ohArray, arraylen, &dpv);
+	ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, (unsigned char **)&dpv, NULL);
+	free(dpv);
+	return ret;
+}
+
+uint16_t
+ptp_mtp_getobjectproplist (PTPParams* params, uint32_t handle, MTPProperties **props, int *nrofprops)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char* opldata = NULL;
+	unsigned int oplsize;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code = PTP_OC_MTP_GetObjPropList;
+	ptp.Param1 = handle;
+	ptp.Param2 = 0x00000000U;  /* 0x00000000U should be "all formats" */
+	ptp.Param3 = 0xFFFFFFFFU;  /* 0xFFFFFFFFU should be "all properties" */
+	ptp.Param4 = 0x00000000U;
+	ptp.Param5 = 0x00000000U;
+	ptp.Nparam = 5;
+	ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &opldata, &oplsize);  
+	if (ret == PTP_RC_OK) *nrofprops = ptp_unpack_OPL(params, opldata, props, oplsize);
+	if (opldata != NULL)
+		free(opldata);
+	return ret;
+}
+
+uint16_t
+ptp_mtp_sendobjectproplist (PTPParams* params, uint32_t* store, uint32_t* parenthandle, uint32_t* handle,
+			    uint16_t objecttype, uint64_t objectsize, MTPProperties *props, int nrofprops)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char* opldata=NULL;
+	uint32_t oplsize;
+
+	PTP_CNT_INIT(ptp);
+	ptp.Code = PTP_OC_MTP_SendObjectPropList;
+	ptp.Param1 = *store;
+	ptp.Param2 = *parenthandle;
+	ptp.Param3 = (uint32_t) objecttype;
+	ptp.Param4 = (uint32_t) (objectsize >> 32);
+	ptp.Param5 = (uint32_t) (objectsize & 0xffffffffU);
+	ptp.Nparam = 5;
+
+	/* Set object handle to 0 for a new object */
+	oplsize = ptp_pack_OPL(params,props,nrofprops,&opldata);
+	ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, oplsize, &opldata, NULL); 
+	free(opldata);
+	*store = ptp.Param1;
+	*parenthandle = ptp.Param2;
+	*handle = ptp.Param3; 
+
+	return ret;
+}
+
+uint16_t
+ptp_mtp_setobjectproplist (PTPParams* params, MTPProperties *props, int nrofprops)
+{
+	uint16_t ret;
+	PTPContainer ptp;
+	unsigned char* opldata=NULL;
+	uint32_t oplsize;
+  
+	PTP_CNT_INIT(ptp);
+	ptp.Code = PTP_OC_MTP_SetObjPropList;
+	ptp.Nparam = 0;
+  
+	oplsize = ptp_pack_OPL(params,props,nrofprops,&opldata);
+	ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, oplsize, &opldata, NULL); 
+	free(opldata);
+
+	return ret;
+}
+
+/* Non PTP protocol functions */
+/* devinfo testing functions */
+
+int
+ptp_operation_issupported(PTPParams* params, uint16_t operation)
+{
+	int i=0;
+
+	for (;i<params->deviceinfo.OperationsSupported_len;i++) {
+		if (params->deviceinfo.OperationsSupported[i]==operation)
+			return 1;
+	}
+	return 0;
+}
+
+
+int
+ptp_event_issupported(PTPParams* params, uint16_t event)
+{
+	int i=0;
+
+	for (;i<params->deviceinfo.EventsSupported_len;i++) {
+		if (params->deviceinfo.EventsSupported[i]==event)
+			return 1;
+	}
+	return 0;
+}
+
+
+int
+ptp_property_issupported(PTPParams* params, uint16_t property)
+{
+	int i;
+
+	for (i=0;i<params->deviceinfo.DevicePropertiesSupported_len;i++)
+		if (params->deviceinfo.DevicePropertiesSupported[i]==property)
+			return 1;
+	return 0;
+}
+
+/* ptp structures freeing functions */
+void
+ptp_free_devicepropvalue(uint16_t dt, PTPPropertyValue* dpd) {
+	switch (dt) {
+	case PTP_DTC_INT8:	case PTP_DTC_UINT8:
+	case PTP_DTC_UINT16:	case PTP_DTC_INT16:
+	case PTP_DTC_UINT32:	case PTP_DTC_INT32:
+	case PTP_DTC_UINT64:	case PTP_DTC_INT64:
+	case PTP_DTC_UINT128:	case PTP_DTC_INT128:
+		/* Nothing to free */
+		break;
+	case PTP_DTC_AINT8:	case PTP_DTC_AUINT8:
+	case PTP_DTC_AUINT16:	case PTP_DTC_AINT16:
+	case PTP_DTC_AUINT32:	case PTP_DTC_AINT32:
+	case PTP_DTC_AUINT64:	case PTP_DTC_AINT64:
+	case PTP_DTC_AUINT128:	case PTP_DTC_AINT128:
+		if (dpd->a.v)
+			free(dpd->a.v);
+		break;
+	case PTP_DTC_STR:
+		if (dpd->str)
+			free(dpd->str);
+		break;
+	}
+}
+
+void
+ptp_free_devicepropdesc(PTPDevicePropDesc* dpd)
+{
+	uint16_t i;
+
+	ptp_free_devicepropvalue (dpd->DataType, &dpd->FactoryDefaultValue);
+	ptp_free_devicepropvalue (dpd->DataType, &dpd->CurrentValue);
+	switch (dpd->FormFlag) {
+	case PTP_DPFF_Range:
+		ptp_free_devicepropvalue (dpd->DataType, &dpd->FORM.Range.MinimumValue);
+		ptp_free_devicepropvalue (dpd->DataType, &dpd->FORM.Range.MaximumValue);
+		ptp_free_devicepropvalue (dpd->DataType, &dpd->FORM.Range.StepSize);
+		break;
+	case PTP_DPFF_Enumeration:
+		if (dpd->FORM.Enum.SupportedValue) {
+			for (i=0;i<dpd->FORM.Enum.NumberOfValues;i++)
+				ptp_free_devicepropvalue (dpd->DataType, dpd->FORM.Enum.SupportedValue+i);
+			free (dpd->FORM.Enum.SupportedValue);
+		}
+	}
+}
+
+void
+ptp_free_objectpropdesc(PTPObjectPropDesc* opd)
+{
+	uint16_t i;
+
+	ptp_free_devicepropvalue (opd->DataType, &opd->FactoryDefaultValue);
+	switch (opd->FormFlag) {
+	case PTP_OPFF_None:
+		break;
+	case PTP_OPFF_Range:
+		ptp_free_devicepropvalue (opd->DataType, &opd->FORM.Range.MinimumValue);
+		ptp_free_devicepropvalue (opd->DataType, &opd->FORM.Range.MaximumValue);
+		ptp_free_devicepropvalue (opd->DataType, &opd->FORM.Range.StepSize);
+		break;
+	case PTP_OPFF_Enumeration:
+		if (opd->FORM.Enum.SupportedValue) {
+			for (i=0;i<opd->FORM.Enum.NumberOfValues;i++)
+				ptp_free_devicepropvalue (opd->DataType, opd->FORM.Enum.SupportedValue+i);
+			free (opd->FORM.Enum.SupportedValue);
+		}
+		break;
+	case PTP_OPFF_DateTime:
+	case PTP_OPFF_FixedLengthArray:
+	case PTP_OPFF_RegularExpression:
+	case PTP_OPFF_ByteArray:
+	case PTP_OPFF_LongString:
+		/* Ignore these presently, we cannot unpack them, so there is nothing to be freed. */
+		break;
+	default:
+		fprintf (stderr, "Unknown OPFF type %d\n", opd->FormFlag);
+		break;
+	}
+}
+
+void
+ptp_free_objectinfo (PTPObjectInfo *oi)
+{
+	if (!oi) return;
+        free (oi->Filename); oi->Filename = NULL;
+        free (oi->Keywords); oi->Keywords = NULL;
+}
+
+void
+ptp_free_object (PTPObject *ob)
+{
+	int i;
+	if (!ob) return;
+
+	ptp_free_objectinfo (&ob->oi);
+	for (i=0;i<ob->nrofmtpprops;i++)
+		ptp_destroy_object_prop(&ob->mtpprops[i]);
+	ob->flags = 0;
+}
+
+void 
+ptp_perror(PTPParams* params, uint16_t error) {
+
+	int i;
+	/* PTP error descriptions */
+	static struct {
+		short n;
+		const char *txt;
+	} ptp_errors[] = {
+	{PTP_RC_Undefined, 		N_("PTP: Undefined Error")},
+	{PTP_RC_OK, 			N_("PTP: OK!")},
+	{PTP_RC_GeneralError, 		N_("PTP: General Error")},
+	{PTP_RC_SessionNotOpen, 	N_("PTP: Session Not Open")},
+	{PTP_RC_InvalidTransactionID, 	N_("PTP: Invalid Transaction ID")},
+	{PTP_RC_OperationNotSupported, 	N_("PTP: Operation Not Supported")},
+	{PTP_RC_ParameterNotSupported, 	N_("PTP: Parameter Not Supported")},
+	{PTP_RC_IncompleteTransfer, 	N_("PTP: Incomplete Transfer")},
+	{PTP_RC_InvalidStorageId, 	N_("PTP: Invalid Storage ID")},
+	{PTP_RC_InvalidObjectHandle, 	N_("PTP: Invalid Object Handle")},
+	{PTP_RC_DevicePropNotSupported, N_("PTP: Device Prop Not Supported")},
+	{PTP_RC_InvalidObjectFormatCode, N_("PTP: Invalid Object Format Code")},
+	{PTP_RC_StoreFull, 		N_("PTP: Store Full")},
+	{PTP_RC_ObjectWriteProtected, 	N_("PTP: Object Write Protected")},
+	{PTP_RC_StoreReadOnly, 		N_("PTP: Store Read Only")},
+	{PTP_RC_AccessDenied,		N_("PTP: Access Denied")},
+	{PTP_RC_NoThumbnailPresent, 	N_("PTP: No Thumbnail Present")},
+	{PTP_RC_SelfTestFailed, 	N_("PTP: Self Test Failed")},
+	{PTP_RC_PartialDeletion, 	N_("PTP: Partial Deletion")},
+	{PTP_RC_StoreNotAvailable, 	N_("PTP: Store Not Available")},
+	{PTP_RC_SpecificationByFormatUnsupported,
+				N_("PTP: Specification By Format Unsupported")},
+	{PTP_RC_NoValidObjectInfo, 	N_("PTP: No Valid Object Info")},
+	{PTP_RC_InvalidCodeFormat, 	N_("PTP: Invalid Code Format")},
+	{PTP_RC_UnknownVendorCode, 	N_("PTP: Unknown Vendor Code")},
+	{PTP_RC_CaptureAlreadyTerminated,
+					N_("PTP: Capture Already Terminated")},
+	{PTP_RC_DeviceBusy, 		N_("PTP: Device Busy")},
+	{PTP_RC_InvalidParentObject, 	N_("PTP: Invalid Parent Object")},
+	{PTP_RC_InvalidDevicePropFormat, N_("PTP: Invalid Device Prop Format")},
+	{PTP_RC_InvalidDevicePropValue, N_("PTP: Invalid Device Prop Value")},
+	{PTP_RC_InvalidParameter, 	N_("PTP: Invalid Parameter")},
+	{PTP_RC_SessionAlreadyOpened, 	N_("PTP: Session Already Opened")},
+	{PTP_RC_TransactionCanceled, 	N_("PTP: Transaction Canceled")},
+	{PTP_RC_SpecificationOfDestinationUnsupported,
+			N_("PTP: Specification Of Destination Unsupported")},
+	{PTP_RC_EK_FilenameRequired,	N_("PTP: EK Filename Required")},
+	{PTP_RC_EK_FilenameConflicts,	N_("PTP: EK Filename Conflicts")},
+	{PTP_RC_EK_FilenameInvalid,	N_("PTP: EK Filename Invalid")},
+
+	{PTP_ERROR_IO,		  N_("PTP: I/O error")},
+	{PTP_ERROR_BADPARAM,	  N_("PTP: Error: bad parameter")},
+	{PTP_ERROR_DATA_EXPECTED, N_("PTP: Protocol error, data expected")},
+	{PTP_ERROR_RESP_EXPECTED, N_("PTP: Protocol error, response expected")},
+	{0, NULL}
+};
+
+	for (i=0; ptp_errors[i].txt!=NULL; i++)
+		if (ptp_errors[i].n == error)
+			ptp_error(params, ptp_errors[i].txt);
+}
+
+const char*
+ptp_get_property_description(PTPParams* params, uint16_t dpc)
+{
+	int i;
+	/* Device Property descriptions */
+	struct {
+		uint16_t dpc;
+		const char *txt;
+	} ptp_device_properties[] = {
+		{PTP_DPC_Undefined,		N_("Undefined PTP Property")},
+		{PTP_DPC_BatteryLevel,		N_("Battery Level")},
+		{PTP_DPC_FunctionalMode,	N_("Functional Mode")},
+		{PTP_DPC_ImageSize,		N_("Image Size")},
+		{PTP_DPC_CompressionSetting,	N_("Compression Setting")},
+		{PTP_DPC_WhiteBalance,		N_("White Balance")},
+		{PTP_DPC_RGBGain,		N_("RGB Gain")},
+		{PTP_DPC_FNumber,		N_("F-Number")},
+		{PTP_DPC_FocalLength,		N_("Focal Length")},
+		{PTP_DPC_FocusDistance,		N_("Focus Distance")},
+		{PTP_DPC_FocusMode,		N_("Focus Mode")},
+		{PTP_DPC_ExposureMeteringMode,	N_("Exposure Metering Mode")},
+		{PTP_DPC_FlashMode,		N_("Flash Mode")},
+		{PTP_DPC_ExposureTime,		N_("Exposure Time")},
+		{PTP_DPC_ExposureProgramMode,	N_("Exposure Program Mode")},
+		{PTP_DPC_ExposureIndex,
+					N_("Exposure Index (film speed ISO)")},
+		{PTP_DPC_ExposureBiasCompensation,
+					N_("Exposure Bias Compensation")},
+		{PTP_DPC_DateTime,		N_("Date & Time")},
+		{PTP_DPC_CaptureDelay,		N_("Pre-Capture Delay")},
+		{PTP_DPC_StillCaptureMode,	N_("Still Capture Mode")},
+		{PTP_DPC_Contrast,		N_("Contrast")},
+		{PTP_DPC_Sharpness,		N_("Sharpness")},
+		{PTP_DPC_DigitalZoom,		N_("Digital Zoom")},
+		{PTP_DPC_EffectMode,		N_("Effect Mode")},
+		{PTP_DPC_BurstNumber,		N_("Burst Number")},
+		{PTP_DPC_BurstInterval,		N_("Burst Interval")},
+		{PTP_DPC_TimelapseNumber,	N_("Timelapse Number")},
+		{PTP_DPC_TimelapseInterval,	N_("Timelapse Interval")},
+		{PTP_DPC_FocusMeteringMode,	N_("Focus Metering Mode")},
+		{PTP_DPC_UploadURL,		N_("Upload URL")},
+		{PTP_DPC_Artist,		N_("Artist")},
+		{PTP_DPC_CopyrightInfo,		N_("Copyright Info")},
+		{0,NULL}
+	};
+	struct {
+		uint16_t dpc;
+		const char *txt;
+	} ptp_device_properties_EK[] = {
+		{PTP_DPC_EK_ColorTemperature,	N_("Color Temperature")},
+		{PTP_DPC_EK_DateTimeStampFormat,
+					N_("Date Time Stamp Format")},
+		{PTP_DPC_EK_BeepMode,		N_("Beep Mode")},
+		{PTP_DPC_EK_VideoOut,		N_("Video Out")},
+		{PTP_DPC_EK_PowerSaving,	N_("Power Saving")},
+		{PTP_DPC_EK_UI_Language,	N_("UI Language")},
+		{0,NULL}
+	};
+
+	struct {
+		uint16_t dpc;
+		const char *txt;
+	} ptp_device_properties_Canon[] = {
+		{PTP_DPC_CANON_BeepMode,	N_("Beep Mode")},
+		{PTP_DPC_CANON_BatteryKind,	N_("Battery Type")},
+		{PTP_DPC_CANON_BatteryStatus,	N_("Battery Mode")},
+		{PTP_DPC_CANON_UILockType,	N_("UILockType")},
+		{PTP_DPC_CANON_CameraMode,	N_("Camera Mode")},
+		{PTP_DPC_CANON_ImageQuality,	N_("Image Quality")},
+		{PTP_DPC_CANON_FullViewFileFormat,	N_("Full View File Format")},
+		{PTP_DPC_CANON_ImageSize,	N_("Image Size")},
+		{PTP_DPC_CANON_SelfTime,	N_("Self Time")},
+		{PTP_DPC_CANON_FlashMode,	N_("Flash Mode")},
+		{PTP_DPC_CANON_Beep,		N_("Beep")},
+		{PTP_DPC_CANON_ShootingMode,	N_("Shooting Mode")},
+		{PTP_DPC_CANON_ImageMode,	N_("Image Mode")},
+		{PTP_DPC_CANON_DriveMode,	N_("Drive Mode")},
+		{PTP_DPC_CANON_EZoom,		N_("Zoom")},
+		{PTP_DPC_CANON_MeteringMode,	N_("Metering Mode")},
+		{PTP_DPC_CANON_AFDistance,	N_("AF Distance")},
+		{PTP_DPC_CANON_FocusingPoint,	N_("Focusing Point")},
+		{PTP_DPC_CANON_WhiteBalance,	N_("White Balance")},
+		{PTP_DPC_CANON_SlowShutterSetting,	N_("Slow Shutter Setting")},
+		{PTP_DPC_CANON_AFMode,		N_("AF Mode")},
+		{PTP_DPC_CANON_ImageStabilization,		N_("Image Stabilization")},
+		{PTP_DPC_CANON_Contrast,	N_("Contrast")},
+		{PTP_DPC_CANON_ColorGain,	N_("Color Gain")},
+		{PTP_DPC_CANON_Sharpness,	N_("Sharpness")},
+		{PTP_DPC_CANON_Sensitivity,	N_("Sensitivity")},
+		{PTP_DPC_CANON_ParameterSet,	N_("Parameter Set")},
+		{PTP_DPC_CANON_ISOSpeed,	N_("ISO Speed")},
+		{PTP_DPC_CANON_Aperture,	N_("Aperture")},
+		{PTP_DPC_CANON_ShutterSpeed,	N_("Shutter Speed")},
+		{PTP_DPC_CANON_ExpCompensation,	N_("Exposure Compensation")},
+		{PTP_DPC_CANON_FlashCompensation,	N_("Flash Compensation")},
+		{PTP_DPC_CANON_AEBExposureCompensation,	N_("AEB Exposure Compensation")},
+		{PTP_DPC_CANON_AvOpen,		N_("Av Open")},
+		{PTP_DPC_CANON_AvMax,		N_("Av Max")},
+		{PTP_DPC_CANON_FocalLength,	N_("Focal Length")},
+		{PTP_DPC_CANON_FocalLengthTele,	N_("Focal Length Tele")},
+		{PTP_DPC_CANON_FocalLengthWide,	N_("Focal Length Wide")},
+		{PTP_DPC_CANON_FocalLengthDenominator,	N_("Focal Length Denominator")},
+		{PTP_DPC_CANON_CaptureTransferMode,	N_("Capture Transfer Mode")},
+		{PTP_DPC_CANON_Zoom,		N_("Zoom")},
+		{PTP_DPC_CANON_NamePrefix,	N_("Name Prefix")},
+		{PTP_DPC_CANON_SizeQualityMode,	N_("Size Quality Mode")},
+		{PTP_DPC_CANON_SupportedThumbSize,	N_("Supported Thumb Size")},
+		{PTP_DPC_CANON_SizeOfOutputDataFromCamera,	N_("Size of Output Data from Camera")},
+		{PTP_DPC_CANON_SizeOfInputDataToCamera,		N_("Size of Input Data to Camera")},
+		{PTP_DPC_CANON_RemoteAPIVersion,N_("Remote API Version")},
+		{PTP_DPC_CANON_FirmwareVersion,	N_("Firmware Version")},
+		{PTP_DPC_CANON_CameraModel,	N_("Camera Model")},
+		{PTP_DPC_CANON_CameraOwner,	N_("Camera Owner")},
+		{PTP_DPC_CANON_UnixTime,	N_("UNIX Time")},
+		{PTP_DPC_CANON_CameraBodyID,	N_("Camera Body ID")},
+		{PTP_DPC_CANON_CameraOutput,	N_("Camera Output")},
+		{PTP_DPC_CANON_DispAv,		N_("Disp Av")},
+		{PTP_DPC_CANON_AvOpenApex,	N_("Av Open Apex")},
+		{PTP_DPC_CANON_DZoomMagnification,	N_("Digital Zoom Magnification")},
+		{PTP_DPC_CANON_MlSpotPos,	N_("Ml Spot Position")},
+		{PTP_DPC_CANON_DispAvMax,	N_("Disp Av Max")},
+		{PTP_DPC_CANON_AvMaxApex,	N_("Av Max Apex")},
+		{PTP_DPC_CANON_EZoomStartPosition,	N_("EZoom Start Position")},
+		{PTP_DPC_CANON_FocalLengthOfTele,	N_("Focal Length Tele")},
+		{PTP_DPC_CANON_EZoomSizeOfTele,	N_("EZoom Size of Tele")},
+		{PTP_DPC_CANON_PhotoEffect,	N_("Photo Effect")},
+		{PTP_DPC_CANON_AssistLight,	N_("Assist Light")},
+		{PTP_DPC_CANON_FlashQuantityCount,	N_("Flash Quantity Count")},
+		{PTP_DPC_CANON_RotationAngle,	N_("Rotation Angle")},
+		{PTP_DPC_CANON_RotationScene,	N_("Rotation Scene")},
+		{PTP_DPC_CANON_EventEmulateMode,N_("Event Emulate Mode")},
+		{PTP_DPC_CANON_DPOFVersion,	N_("DPOF Version")},
+		{PTP_DPC_CANON_TypeOfSupportedSlideShow,	N_("Type of Slideshow")},
+		{PTP_DPC_CANON_AverageFilesizes,N_("Average Filesizes")},
+		{PTP_DPC_CANON_ModelID,		N_("Model ID")},
+		{0,NULL}
+	};
+
+	struct {
+		uint16_t dpc;
+		const char *txt;
+	} ptp_device_properties_Nikon[] = {
+		{PTP_DPC_NIKON_ShootingBank, 			/* 0xD010 */
+		 N_("Shooting Bank")},
+		{PTP_DPC_NIKON_ShootingBankNameA,		/* 0xD011 */
+		 N_("Shooting Bank Name A")},
+		{PTP_DPC_NIKON_ShootingBankNameB,		/* 0xD012 */
+		 N_("Shooting Bank Name B")},
+		{PTP_DPC_NIKON_ShootingBankNameC,		/* 0xD013 */
+		 N_("Shooting Bank Name C")},
+		{PTP_DPC_NIKON_ShootingBankNameD,		/* 0xD014 */
+		 N_("Shooting Bank Name D")},
+		{PTP_DPC_NIKON_ResetBank0,			/* 0xD015 */
+		 N_("Reset Bank 0")},
+		{PTP_DPC_NIKON_RawCompression,			/* 0xD016 */
+		 N_("Raw Compression")},
+		{PTP_DPC_NIKON_WhiteBalanceAutoBias,		/* 0xD017 */
+		 N_("Auto White Balance Bias")},
+		{PTP_DPC_NIKON_WhiteBalanceTungstenBias,	/* 0xD018 */
+		 N_("Tungsten White Balance Bias")},
+		{PTP_DPC_NIKON_WhiteBalanceFluorescentBias,	/* 0xD019 */
+		 N_("Fluorescent White Balance Bias")},
+		{PTP_DPC_NIKON_WhiteBalanceDaylightBias,	/* 0xD01a */
+		 N_("Daylight White Balance Bias")},
+		{PTP_DPC_NIKON_WhiteBalanceFlashBias,		/* 0xD01b */
+		 N_("Flash White Balance Bias")},
+		{PTP_DPC_NIKON_WhiteBalanceCloudyBias,		/* 0xD01c */
+		 N_("Cloudy White Balance Bias")},
+		{PTP_DPC_NIKON_WhiteBalanceShadeBias,		/* 0xD01d */
+		 N_("Shady White Balance Bias")},
+		{PTP_DPC_NIKON_WhiteBalanceColorTemperature,	/* 0xD01e */
+		 N_("White Balance Colour Temperature")},
+		{PTP_DPC_NIKON_WhiteBalancePresetNo,		/* 0xD01f */
+		 N_("White Balance Preset Number")},
+		{PTP_DPC_NIKON_WhiteBalancePresetName0,		/* 0xD020 */
+		 N_("White Balance Preset Name 0")},
+		{PTP_DPC_NIKON_WhiteBalancePresetName1,		/* 0xD021 */
+		 N_("White Balance Preset Name 1")},
+		{PTP_DPC_NIKON_WhiteBalancePresetName2,		/* 0xD022 */
+		 N_("White Balance Preset Name 2")},
+		{PTP_DPC_NIKON_WhiteBalancePresetName3,		/* 0xD023 */
+		 N_("White Balance Preset Name 3")},
+		{PTP_DPC_NIKON_WhiteBalancePresetName4,		/* 0xD024 */
+		 N_("White Balance Preset Name 4")},
+		{PTP_DPC_NIKON_WhiteBalancePresetVal0,		/* 0xD025 */
+		 N_("White Balance Preset Value 0")},
+		{PTP_DPC_NIKON_WhiteBalancePresetVal1,		/* 0xD026 */
+		 N_("White Balance Preset Value 1")},
+		{PTP_DPC_NIKON_WhiteBalancePresetVal2,		/* 0xD027 */
+		 N_("White Balance Preset Value 2")},
+		{PTP_DPC_NIKON_WhiteBalancePresetVal3,		/* 0xD028 */
+		 N_("White Balance Preset Value 3")},
+		{PTP_DPC_NIKON_WhiteBalancePresetVal4,		/* 0xD029 */
+		 N_("White Balance Preset Value 4")},
+		{PTP_DPC_NIKON_ImageSharpening,			/* 0xD02a */
+		 N_("Sharpening")},
+		{PTP_DPC_NIKON_ToneCompensation,		/* 0xD02b */
+		 N_("Tone Compensation")},
+		{PTP_DPC_NIKON_ColorModel,			/* 0xD02c */
+		 N_("Color Model")},
+		{PTP_DPC_NIKON_HueAdjustment,			/* 0xD02d */
+		 N_("Hue Adjustment")},
+		{PTP_DPC_NIKON_NonCPULensDataFocalLength,	/* 0xD02e */
+		 N_("Lens Focal Length (Non CPU)")},
+		{PTP_DPC_NIKON_NonCPULensDataMaximumAperture,	/* 0xD02f */
+		 N_("Lens Maximum Aperture (Non CPU)")},
+		{PTP_DPC_NIKON_ShootingMode,			/* 0xD030 */
+		 N_("Shooting Mode")},
+		{PTP_DPC_NIKON_JPEG_Compression_Policy,		/* 0xD031 */
+		 N_("JPEG Compression Policy")},
+		{PTP_DPC_NIKON_ColorSpace,			/* 0xD032 */
+		 N_("Color Space")},
+		{PTP_DPC_NIKON_AutoDXCrop,			/* 0xD033 */
+		 N_("Auto DX Crop")},
+		{PTP_DPC_NIKON_CSMMenuBankSelect,		/* 0xD040 */
+		 "PTP_DPC_NIKON_CSMMenuBankSelect"},
+		{PTP_DPC_NIKON_MenuBankNameA,			/* 0xD041 */
+		 N_("Menu Bank Name A")},
+		{PTP_DPC_NIKON_MenuBankNameB,			/* 0xD042 */
+		 N_("Menu Bank Name B")},
+		{PTP_DPC_NIKON_MenuBankNameC,			/* 0xD043 */
+		 N_("Menu Bank Name C")},
+		{PTP_DPC_NIKON_MenuBankNameD,			/* 0xD044 */
+		 N_("Menu Bank Name D")},
+		{PTP_DPC_NIKON_ResetBank,			/* 0xD045 */
+		 N_("Reset Menu Bank")},
+		{PTP_DPC_NIKON_A1AFCModePriority,		/* 0xD048 */
+		 "PTP_DPC_NIKON_A1AFCModePriority"},
+		{PTP_DPC_NIKON_A2AFSModePriority,		/* 0xD049 */
+		 "PTP_DPC_NIKON_A2AFSModePriority"},
+		{PTP_DPC_NIKON_A3GroupDynamicAF,		/* 0xD04a */
+		 "PTP_DPC_NIKON_A3GroupDynamicAF"},
+		{PTP_DPC_NIKON_A4AFActivation,			/* 0xD04b */
+		 "PTP_DPC_NIKON_A4AFActivation"},
+		{PTP_DPC_NIKON_FocusAreaIllumManualFocus,	/* 0xD04c */
+		 "PTP_DPC_NIKON_FocusAreaIllumManualFocus"},
+		{PTP_DPC_NIKON_FocusAreaIllumContinuous,	/* 0xD04d */
+		 "PTP_DPC_NIKON_FocusAreaIllumContinuous"},
+		{PTP_DPC_NIKON_FocusAreaIllumWhenSelected,	/* 0xD04e */
+		 "PTP_DPC_NIKON_FocusAreaIllumWhenSelected"},
+		{PTP_DPC_NIKON_FocusAreaWrap,			/* 0xD04f */
+		 N_("Focus Area Wrap")},
+		{PTP_DPC_NIKON_VerticalAFON,			/* 0xD050 */
+		 N_("Vertical AF On")},
+		{PTP_DPC_NIKON_AFLockOn,			/* 0xD051 */
+		 N_("AF Lock On")},
+		{PTP_DPC_NIKON_FocusAreaZone,			/* 0xD052 */
+		 N_("Focus Area Zone")},
+		{PTP_DPC_NIKON_EnableCopyright,			/* 0xD053 */
+		 N_("Enable Copyright")},
+		{PTP_DPC_NIKON_ISOAuto,				/* 0xD054 */
+		 N_("Auto ISO")},
+		{PTP_DPC_NIKON_EVISOStep,			/* 0xD055 */
+		 N_("Exposure ISO Step")},
+		{PTP_DPC_NIKON_EVStep,				/* 0xD056 */
+		 N_("Exposure Step")},
+		{PTP_DPC_NIKON_EVStepExposureComp,		/* 0xD057 */
+		 N_("Exposure Compensation (EV)")},
+		{PTP_DPC_NIKON_ExposureCompensation,		/* 0xD058 */
+		 N_("Exposure Compensation")},
+		{PTP_DPC_NIKON_CenterWeightArea,		/* 0xD059 */
+		 N_("Centre Weight Area")},
+		{PTP_DPC_NIKON_ExposureBaseMatrix,		/* 0xD05A */
+		 N_("Exposure Base Matrix")},
+		{PTP_DPC_NIKON_ExposureBaseCenter,		/* 0xD05B */
+		 N_("Exposure Base Center")},
+		{PTP_DPC_NIKON_ExposureBaseSpot,		/* 0xD05C */
+		 N_("Exposure Base Spot")},
+		{PTP_DPC_NIKON_LiveViewAF,			/* 0xD05D */
+		 N_("Live View AF")},
+		{PTP_DPC_NIKON_AELockMode,			/* 0xD05E */
+		 N_("Exposure Lock")},
+		{PTP_DPC_NIKON_AELAFLMode,			/* 0xD05F */
+		 N_("Focus Lock")},
+		{PTP_DPC_NIKON_MeterOff,			/* 0xD062 */
+		 N_("Auto Meter Off Time")},
+		{PTP_DPC_NIKON_SelfTimer,			/* 0xD063 */
+		 N_("Self Timer Delay")},
+		{PTP_DPC_NIKON_MonitorOff,			/* 0xD064 */
+		 N_("LCD Off Time")},
+		{PTP_DPC_NIKON_ImgConfTime,			/* 0xD065 */
+		 N_("Img Conf Time")},
+		{PTP_DPC_NIKON_AngleLevel,			/* 0xD067 */
+		 N_("Angle Level")},
+		{PTP_DPC_NIKON_D1ShootingSpeed,			/* 0xD068 */
+		 N_("Shooting Speed")},
+		{PTP_DPC_NIKON_D2MaximumShots,			/* 0xD069 */
+		 N_("Maximum Shots")},
+		{PTP_DPC_NIKON_D3ExpDelayMode,			/* 0xD06A */
+		 N_("Exposure delay mode")},
+		{PTP_DPC_NIKON_LongExposureNoiseReduction,	/* 0xD06B */
+		 N_("Long Exposure Noise Reduction")},
+		{PTP_DPC_NIKON_FileNumberSequence,		/* 0xD06C */
+		 N_("File Number Sequencing")},
+		{PTP_DPC_NIKON_ControlPanelFinderRearControl,	/* 0xD06D */
+		 "PTP_DPC_NIKON_ControlPanelFinderRearControl"},
+		{PTP_DPC_NIKON_ControlPanelFinderViewfinder,	/* 0xD06E */
+		 "PTP_DPC_NIKON_ControlPanelFinderViewfinder"},
+		{PTP_DPC_NIKON_D7Illumination,			/* 0xD06F */
+		 N_("LCD Illumination")},
+		{PTP_DPC_NIKON_NrHighISO,			/* 0xD070 */
+		 N_("High ISO noise reduction")},
+		{PTP_DPC_NIKON_SHSET_CH_GUID_DISP,		/* 0xD071 */
+		 N_("On screen tips")},
+		{PTP_DPC_NIKON_ArtistName,			/* 0xD072 */
+		 N_("Artist Name")},
+		{PTP_DPC_NIKON_CopyrightInfo,			/* 0xD073 */
+		 N_("Copyright Information")},
+		{PTP_DPC_NIKON_FlashSyncSpeed,			/* 0xD074 */
+		 N_("Flash Sync. Speed")},
+		{PTP_DPC_NIKON_FlashShutterSpeed,		/* 0xD075 */
+		 N_("Flash Shutter Speed")},
+		{PTP_DPC_NIKON_E3AAFlashMode,			/* 0xD076 */
+		 N_("Flash Mode")},
+		{PTP_DPC_NIKON_E4ModelingFlash,			/* 0xD077 */
+		 N_("Modeling Flash")},
+		{PTP_DPC_NIKON_BracketSet,			/* 0xD078 */
+		 N_("Bracket Set")},
+		{PTP_DPC_NIKON_E6ManualModeBracketing,		/* 0xD079 */
+		 N_("Manual Mode Bracketing")},
+		{PTP_DPC_NIKON_BracketOrder,			/* 0xD07A */
+		 N_("Bracket Order")},
+		{PTP_DPC_NIKON_E8AutoBracketSelection,		/* 0xD07B */
+		 N_("Auto Bracket Selection")},
+		{PTP_DPC_NIKON_BracketingSet, N_("NIKON Auto Bracketing Set")},	/* 0xD07C */
+		{PTP_DPC_NIKON_F1CenterButtonShootingMode,	/* 0xD080 */
+		 N_("Center Button Shooting Mode")},
+		{PTP_DPC_NIKON_CenterButtonPlaybackMode,	/* 0xD081 */
+		 N_("Center Button Playback Mode")},
+		{PTP_DPC_NIKON_F2Multiselector,			/* 0xD082 */
+		 N_("Multiselector")},
+		{PTP_DPC_NIKON_F3PhotoInfoPlayback,		/* 0xD083 */
+		 N_("Photo Info. Playback")},
+		{PTP_DPC_NIKON_F4AssignFuncButton,		/* 0xD084 */
+		 N_("Assign Func. Button")},
+		{PTP_DPC_NIKON_F5CustomizeCommDials,		/* 0xD085 */
+		 N_("Customise Command Dials")},
+		{PTP_DPC_NIKON_ReverseCommandDial,		/* 0xD086 */
+		 N_("Reverse Command Dial")},
+		{PTP_DPC_NIKON_ApertureSetting,			/* 0xD087 */
+		 N_("Aperture Setting")},
+		{PTP_DPC_NIKON_MenusAndPlayback,		/* 0xD088 */
+		 N_("Menus and Playback")},
+		{PTP_DPC_NIKON_F6ButtonsAndDials,		/* 0xD089 */
+		 N_("Buttons and Dials")},
+		{PTP_DPC_NIKON_NoCFCard,			/* 0xD08A */
+		 N_("No CF Card Release")},
+		{PTP_DPC_NIKON_CenterButtonZoomRatio,		/* 0xD08B */
+		 N_("Center Button Zoom Ratio")},
+		{PTP_DPC_NIKON_FunctionButton2,			/* 0xD08C */
+		 N_("Function Button 2")},
+		{PTP_DPC_NIKON_AFAreaPoint,			/* 0xD08D */
+		 N_("AF Area Point")},
+		{PTP_DPC_NIKON_NormalAFOn,			/* 0xD08E */
+		 N_("Normal AF On")},
+		{PTP_DPC_NIKON_ImageCommentString,		/* 0xD090 */
+		 N_("Image Comment String")},
+		{PTP_DPC_NIKON_ImageCommentEnable,		/* 0xD091 */
+		 N_("Image Comment Enable")},
+		{PTP_DPC_NIKON_ImageRotation,			/* 0xD092 */
+		 N_("Image Rotation")},
+		{PTP_DPC_NIKON_ManualSetLensNo,			/* 0xD093 */
+		 N_("Manual Set Lens Number")},
+		{PTP_DPC_NIKON_MovScreenSize,			/* 0xD0A0 */
+		 N_("Movie Screen Size")},
+		{PTP_DPC_NIKON_MovVoice,			/* 0xD0A1 */
+		 N_("Movie Voice")},
+		{PTP_DPC_NIKON_Bracketing,			/* 0xD0C0 */
+		 N_("Bracketing Enable")},
+		{PTP_DPC_NIKON_AutoExposureBracketStep,		/* 0xD0C1 */
+		 N_("Exposure Bracketing Step")},
+		{PTP_DPC_NIKON_AutoExposureBracketProgram,	/* 0xD0C2 */
+		 N_("Exposure Bracketing Program")},
+		{PTP_DPC_NIKON_AutoExposureBracketCount,	/* 0xD0C3 */
+		 N_("Auto Exposure Bracket Count")},
+		{PTP_DPC_NIKON_WhiteBalanceBracketStep, N_("White Balance Bracket Step")}, /* 0xD0C4 */
+		{PTP_DPC_NIKON_WhiteBalanceBracketProgram, N_("White Balance Bracket Program")}, /* 0xD0C5 */
+		{PTP_DPC_NIKON_LensID,				/* 0xD0E0 */
+		 N_("Lens ID")},
+		{PTP_DPC_NIKON_LensSort,			/* 0xD0E1 */
+		 N_("Lens Sort")},
+		{PTP_DPC_NIKON_LensType,			/* 0xD0E2 */
+		 N_("Lens Type")},
+		{PTP_DPC_NIKON_FocalLengthMin,			/* 0xD0E3 */
+		 N_("Min. Focal Length")},
+		{PTP_DPC_NIKON_FocalLengthMax,			/* 0xD0E4 */
+		 N_("Max. Focal Length")},
+		{PTP_DPC_NIKON_MaxApAtMinFocalLength,		/* 0xD0E5 */
+		 N_("Max. Aperture at Min. Focal Length")},
+		{PTP_DPC_NIKON_MaxApAtMaxFocalLength,		/* 0xD0E6 */
+		 N_("Max. Aperture at Max. Focal Length")},
+		{PTP_DPC_NIKON_FinderISODisp,			/* 0xD0F0 */
+		 N_("Finder ISO Display")},
+		{PTP_DPC_NIKON_AutoOffPhoto,			/* 0xD0F2 */
+		 N_("Auto Off Photo")},
+		{PTP_DPC_NIKON_AutoOffMenu,			/* 0xD0F3 */
+		 N_("Auto Off Menu")},
+		{PTP_DPC_NIKON_AutoOffInfo,			/* 0xD0F4 */
+		 N_("Auto Off Info")},
+		{PTP_DPC_NIKON_SelfTimerShootNum,		/* 0xD0F5 */
+		 N_("Self Timer Shot Number")},
+		{PTP_DPC_NIKON_VignetteCtrl,			/* 0xD0F7 */
+		 N_("Vignette Control")},
+		{PTP_DPC_NIKON_ExposureTime,			/* 0xD100 */
+		 N_("Nikon Exposure Time")},
+		{PTP_DPC_NIKON_ACPower, N_("AC Power")},	/* 0xD101 */
+		{PTP_DPC_NIKON_WarningStatus, N_("Warning Status")},/* 0xD102 */
+		{PTP_DPC_NIKON_MaximumShots,			/* 0xD103 */
+		 N_("Maximum Shots")},
+		{PTP_DPC_NIKON_AFLockStatus, N_("AF Locked")},/* 0xD104 */
+		{PTP_DPC_NIKON_AELockStatus, N_("AE Locked")},/* 0xD105 */
+		{PTP_DPC_NIKON_FVLockStatus, N_("FV Locked")},/* 0xD106 */
+		{PTP_DPC_NIKON_AutofocusLCDTopMode2,		/* 0xD107 */
+		 N_("AF LCD Top Mode 2")},
+		{PTP_DPC_NIKON_AutofocusArea,			/* 0xD108 */
+		 N_("Active AF Sensor")},
+		{PTP_DPC_NIKON_FlexibleProgram,			/* 0xD109 */
+		 N_("Flexible Program")},
+		{PTP_DPC_NIKON_LightMeter,			/* 0xD10A */
+		 N_("Exposure Meter")},
+		{PTP_DPC_NIKON_RecordingMedia,			/* 0xD10B */
+		 N_("Recording Media")},
+		{PTP_DPC_NIKON_USBSpeed,			/* 0xD10C */
+		 N_("USB Speed")},
+		{PTP_DPC_NIKON_CCDNumber,			/* 0xD10D */
+		 N_("CCD Serial Number")},
+		{PTP_DPC_NIKON_CameraOrientation,		/* 0xD10E */
+		 N_("Camera Orientation")},
+		{PTP_DPC_NIKON_GroupPtnType,			/* 0xD10F */
+		 N_("Group PTN Type")},
+		{PTP_DPC_NIKON_FNumberLock,			/* 0xD110 */
+		 N_("FNumber Lock")},
+		{PTP_DPC_NIKON_ExposureApertureLock,		/* 0xD111 */
+		 N_("Exposure Aperture Lock")},
+		{PTP_DPC_NIKON_TVLockSetting,			/* 0xD112 */
+		 N_("TV Lock Setting")},
+		{PTP_DPC_NIKON_AVLockSetting,			/* 0xD113 */
+		 N_("AV Lock Setting")},
+		{PTP_DPC_NIKON_IllumSetting,			/* 0xD114 */
+		 N_("Illum Setting")},
+		{PTP_DPC_NIKON_FocusPointBright,		/* 0xD115 */
+		 N_("Focus Point Bright")},
+		{PTP_DPC_NIKON_ExternalFlashAttached,		/* 0xD120 */
+		 N_("External Flash Attached")},
+		{PTP_DPC_NIKON_ExternalFlashStatus,		/* 0xD121 */
+		 N_("External Flash Status")},
+		{PTP_DPC_NIKON_ExternalFlashSort,		/* 0xD122 */
+		 N_("External Flash Sort")},
+		{PTP_DPC_NIKON_ExternalFlashMode,		/* 0xD123 */
+		 N_("External Flash Mode")},
+		{PTP_DPC_NIKON_ExternalFlashCompensation,	/* 0xD124 */
+		 N_("External Flash Compensation")},
+		{PTP_DPC_NIKON_NewExternalFlashMode,		/* 0xD125 */
+		 N_("External Flash Mode")},
+		{PTP_DPC_NIKON_FlashExposureCompensation,	/* 0xD126 */
+		 N_("Flash Exposure Compensation")},
+		{PTP_DPC_NIKON_OptimizeImage,			/* 0xD140 */
+		 N_("Optimize Image")},
+		{PTP_DPC_NIKON_Saturation,			/* 0xD142 */
+		 N_("Saturation")},
+		{PTP_DPC_NIKON_BW_FillerEffect,			/* 0xD143 */
+		 N_("BW Filler Effect")},
+		{PTP_DPC_NIKON_BW_Sharpness,			/* 0xD144 */
+		 N_("BW Sharpness")},
+		{PTP_DPC_NIKON_BW_Contrast,			/* 0xD145 */
+		 N_("BW Contrast")},
+		{PTP_DPC_NIKON_BW_Setting_Type,			/* 0xD146 */
+		 N_("BW Setting Type")},
+		{PTP_DPC_NIKON_Slot2SaveMode,			/* 0xD148 */
+		 N_("Slot 2 Save Mode")},
+		{PTP_DPC_NIKON_RawBitMode,			/* 0xD149 */
+		 N_("Raw Bit Mode")},
+		{PTP_DPC_NIKON_ISOAutoTime,			/* 0xD14E */
+		 N_("ISO Auto Time")},
+		{PTP_DPC_NIKON_FlourescentType,			/* 0xD14F */
+		 N_("Flourescent Type")},
+		{PTP_DPC_NIKON_TuneColourTemperature,		/* 0xD150 */
+		 N_("Tune Colour Temperature")},
+		{PTP_DPC_NIKON_TunePreset0,			/* 0xD151 */
+		 N_("Tune Preset 0")},
+		{PTP_DPC_NIKON_TunePreset1,			/* 0xD152 */
+		 N_("Tune Preset 1")},
+		{PTP_DPC_NIKON_TunePreset2,			/* 0xD153 */
+		 N_("Tune Preset 2")},
+		{PTP_DPC_NIKON_TunePreset3,			/* 0xD154 */
+		 N_("Tune Preset 3")},
+		{PTP_DPC_NIKON_TunePreset4,			/* 0xD155 */
+		 N_("Tune Preset 4")},
+		{PTP_DPC_NIKON_BeepOff,				/* 0xD160 */
+		 N_("AF Beep Mode")},
+		{PTP_DPC_NIKON_AutofocusMode,			/* 0xD161 */
+		 N_("Autofocus Mode")},
+		{PTP_DPC_NIKON_AFAssist,			/* 0xD163 */
+		 N_("AF Assist Lamp")},
+		{PTP_DPC_NIKON_PADVPMode,			/* 0xD164 */
+		 N_("Auto ISO P/A/DVP Setting")},
+		{PTP_DPC_NIKON_ImageReview,			/* 0xD165 */
+		 N_("Image Review")},
+		{PTP_DPC_NIKON_AFAreaIllumination,		/* 0xD166 */
+		 N_("AF Area Illumination")},
+		{PTP_DPC_NIKON_FlashMode,			/* 0xD167 */
+		 N_("Flash Mode")},
+		{PTP_DPC_NIKON_FlashCommanderMode,	 	/* 0xD168 */
+		 N_("Flash Commander Mode")},
+		{PTP_DPC_NIKON_FlashSign,			/* 0xD169 */
+		 N_("Flash Sign")},
+		{PTP_DPC_NIKON_ISOAuto,				/* 0xD16A */
+		 N_("ISO Auto")},
+		{PTP_DPC_NIKON_RemoteTimeout,			/* 0xD16B */
+		 N_("Remote Timeout")},
+		{PTP_DPC_NIKON_GridDisplay,			/* 0xD16C */
+		 N_("Viewfinder Grid Display")},
+		{PTP_DPC_NIKON_FlashModeManualPower,		/* 0xD16D */
+		 N_("Flash Mode Manual Power")},
+		{PTP_DPC_NIKON_FlashModeCommanderPower,		/* 0xD16E */
+		 N_("Flash Mode Commander Power")},
+		{PTP_DPC_NIKON_AutoFP,				/* 0xD16F */
+		 N_("Auto FP")},
+		{PTP_DPC_NIKON_CSMMenu,				/* 0xD180 */
+		 N_("CSM Menu")},
+		{PTP_DPC_NIKON_WarningDisplay,			/* 0xD181 */
+		 N_("Warning Display")},
+		{PTP_DPC_NIKON_BatteryCellKind,			/* 0xD182 */
+		 N_("Battery Cell Kind")},
+		{PTP_DPC_NIKON_ISOAutoHiLimit,			/* 0xD183 */
+		 N_("ISO Auto High Limit")},
+		{PTP_DPC_NIKON_DynamicAFArea,			/* 0xD184 */
+		 N_("Dynamic AF Area")},
+		{PTP_DPC_NIKON_ContinuousSpeedHigh,		/* 0xD186 */
+		 N_("Continuous Speed High")},
+		{PTP_DPC_NIKON_InfoDispSetting,			/* 0xD187 */
+		 N_("Info Disp Setting")},
+		{PTP_DPC_NIKON_PreviewButton,			/* 0xD189 */
+		 N_("Preview Button")},
+		{PTP_DPC_NIKON_PreviewButton2,			/* 0xD18A */
+		 N_("Preview Button 2")},
+		{PTP_DPC_NIKON_AEAFLockButton2,			/* 0xD18B */
+		 N_("AEAF Lock Button 2")},
+		{PTP_DPC_NIKON_IndicatorDisp,			/* 0xD18D */
+		 N_("Indicator Display")},
+		{PTP_DPC_NIKON_CellKindPriority,		/* 0xD18E */
+		 N_("Cell Kind Priority")},
+		{PTP_DPC_NIKON_BracketingFramesAndSteps,	/* 0xD190 */
+		 N_("Bracketing Frames and Steps")},
+		{PTP_DPC_NIKON_LiveViewMode,			/* 0xD1A0 */
+		 N_("Live View Mode")},
+		{PTP_DPC_NIKON_LiveViewDriveMode,		/* 0xD1A1 */
+		 N_("Live View Drive Mode")},
+		{PTP_DPC_NIKON_LiveViewStatus,			/* 0xD1A2 */
+		 N_("Live View Status")},
+		{PTP_DPC_NIKON_LiveViewImageZoomRatio,		/* 0xD1A3 */
+		 N_("Live View Image Zoom Ratio")},
+		{PTP_DPC_NIKON_LiveViewProhibitCondition,	/* 0xD1A4 */
+		 N_("Live View Prohibit Condition")},
+		{PTP_DPC_NIKON_ExposureDisplayStatus,		/* 0xD1B0 */
+		 N_("Exposure Display Status")},
+		{PTP_DPC_NIKON_ExposureIndicateStatus,		/* 0xD1B1 */
+		 N_("Exposure Indicate Status")},
+		{PTP_DPC_NIKON_ExposureIndicateLightup,		/* 0xD1B2 */
+		 N_("Exposure Indicate Lightup")},
+		{PTP_DPC_NIKON_FlashOpen,			/* 0xD1C0 */
+		 N_("Flash Open")},
+		{PTP_DPC_NIKON_FlashCharged,			/* 0xD1C1 */
+		 N_("Flash Charged")},
+		{PTP_DPC_NIKON_FlashMRepeatValue,		/* 0xD1D0 */
+		 N_("Flash MRepeat Value")},
+		{PTP_DPC_NIKON_FlashMRepeatCount,		/* 0xD1D1 */
+		 N_("Flash MRepeat Count")},
+		{PTP_DPC_NIKON_FlashMRepeatInterval,		/* 0xD1D2 */
+		 N_("Flash MRepeat Interval")},
+		{PTP_DPC_NIKON_FlashCommandChannel,		/* 0xD1D3 */
+		 N_("Flash Command Channel")},
+		{PTP_DPC_NIKON_FlashCommandSelfMode,		/* 0xD1D4 */
+		 N_("Flash Command Self Mode")},
+		{PTP_DPC_NIKON_FlashCommandSelfCompensation,	/* 0xD1D5 */
+		 N_("Flash Command Self Compensation")},
+		{PTP_DPC_NIKON_FlashCommandSelfValue,		/* 0xD1D6 */
+		 N_("Flash Command Self Value")},
+		{PTP_DPC_NIKON_FlashCommandAMode,		/* 0xD1D7 */
+		 N_("Flash Command A Mode")},
+		{PTP_DPC_NIKON_FlashCommandACompensation,	/* 0xD1D8 */
+		 N_("Flash Command A Compensation")},
+		{PTP_DPC_NIKON_FlashCommandAValue,		/* 0xD1D9 */
+		 N_("Flash Command A Value")},
+		{PTP_DPC_NIKON_FlashCommandBMode,		/* 0xD1DA */
+		 N_("Flash Command B Mode")},
+		{PTP_DPC_NIKON_FlashCommandBCompensation,	/* 0xD1DB */
+		 N_("Flash Command B Compensation")},
+		{PTP_DPC_NIKON_FlashCommandBValue,		/* 0xD1DC */
+		 N_("Flash Command B Value")},
+		{PTP_DPC_NIKON_ActivePicCtrlItem,		/* 0xD200 */
+		 N_("Active Pic Ctrl Item")},
+		{PTP_DPC_NIKON_ChangePicCtrlItem,		/* 0xD201 */
+		 N_("Change Pic Ctrl Item")},
+		{0,NULL}
+	};
+        struct {
+		uint16_t dpc;
+		const char *txt;
+        } ptp_device_properties_MTP[] = {
+		{PTP_DPC_MTP_SecureTime,        N_("Secure Time")},		/* D101 */
+		{PTP_DPC_MTP_DeviceCertificate, N_("Device Certificate")},	/* D102 */
+		{PTP_DPC_MTP_RevocationInfo,    N_("Revocation Info")},		/* D103 */
+		{PTP_DPC_MTP_SynchronizationPartner,				/* D401 */
+		 N_("Synchronization Partner")},
+		{PTP_DPC_MTP_DeviceFriendlyName,				/* D402 */
+		 N_("Friendly Device Name")},
+		{PTP_DPC_MTP_VolumeLevel,       N_("Volume Level")},		/* D403 */
+		{PTP_DPC_MTP_DeviceIcon,        N_("Device Icon")},		/* D405 */
+		{PTP_DPC_MTP_SessionInitiatorInfo,	N_("Session Initiator Info")},/* D406 */
+		{PTP_DPC_MTP_PerceivedDeviceType,	N_("Perceived Device Type")},/* D407 */
+		{PTP_DPC_MTP_PlaybackRate,      N_("Playback Rate")},		/* D410 */
+		{PTP_DPC_MTP_PlaybackObject,    N_("Playback Object")},		/* D411 */
+		{PTP_DPC_MTP_PlaybackContainerIndex,				/* D412 */
+		 N_("Playback Container Index")},
+		{PTP_DPC_MTP_PlaybackPosition,  N_("Playback Position")},	/* D413 */
+		{PTP_DPC_MTP_PlaysForSureID,    N_("PlaysForSure ID")},		/* D131 (?) */
+		{0,NULL}
+        };
+
+	for (i=0; ptp_device_properties[i].txt!=NULL; i++)
+		if (ptp_device_properties[i].dpc==dpc)
+			return (ptp_device_properties[i].txt);
+
+	if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_MICROSOFT
+	    || params->deviceinfo.VendorExtensionID==PTP_VENDOR_MTP)
+		for (i=0; ptp_device_properties_MTP[i].txt!=NULL; i++)
+			if (ptp_device_properties_MTP[i].dpc==dpc)
+				return (ptp_device_properties_MTP[i].txt);
+
+	if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_EASTMAN_KODAK)
+		for (i=0; ptp_device_properties_EK[i].txt!=NULL; i++)
+			if (ptp_device_properties_EK[i].dpc==dpc)
+				return (ptp_device_properties_EK[i].txt);
+
+	if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_CANON)
+		for (i=0; ptp_device_properties_Canon[i].txt!=NULL; i++)
+			if (ptp_device_properties_Canon[i].dpc==dpc)
+				return (ptp_device_properties_Canon[i].txt);
+
+	if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_NIKON)
+		for (i=0; ptp_device_properties_Nikon[i].txt!=NULL; i++)
+			if (ptp_device_properties_Nikon[i].dpc==dpc)
+				return (ptp_device_properties_Nikon[i].txt);
+
+	return NULL;
+}
+
+static int64_t
+_value_to_num(PTPPropertyValue *data, uint16_t dt) {
+	if (dt == PTP_DTC_STR) {
+		if (!data->str)
+			return 0;
+		return atol(data->str);
+	}
+	if (dt & PTP_DTC_ARRAY_MASK) {
+		return 0;
+	} else {
+		switch (dt) {
+		case PTP_DTC_UNDEF: 
+			return 0;
+		case PTP_DTC_INT8:
+			return data->i8;
+		case PTP_DTC_UINT8:
+			return data->u8;
+		case PTP_DTC_INT16:
+			return data->i16;
+		case PTP_DTC_UINT16:
+			return data->u16;
+		case PTP_DTC_INT32:
+			return data->i32;
+		case PTP_DTC_UINT32:
+			return data->u32;
+	/*
+		PTP_DTC_INT64           
+		PTP_DTC_UINT64         
+		PTP_DTC_INT128        
+		PTP_DTC_UINT128      
+	*/
+		default:
+			return 0;
+		}
+	}
+
+	return 0;
+}
+
+#define PTP_VAL_BOOL(dpc) {dpc, 0, N_("Off")}, {dpc, 1, N_("On")}
+#define PTP_VENDOR_VAL_BOOL(dpc,vendor) {dpc, vendor, 0, N_("Off")}, {dpc, vendor, 1, N_("On")}
+#define PTP_VENDOR_VAL_RBOOL(dpc,vendor) {dpc, vendor, 0, N_("On")}, {dpc, vendor, 1, N_("Off")}
+#define PTP_VENDOR_VAL_YN(dpc,vendor) {dpc, vendor, 0, N_("No")}, {dpc, vendor, 1, N_("Yes")}
+
+int
+ptp_render_property_value(PTPParams* params, uint16_t dpc,
+			  PTPDevicePropDesc *dpd, int length, char *out)
+{
+	int i;
+	int64_t	kval;
+
+	struct {
+		uint16_t dpc;
+		uint16_t vendor;
+		double coef;
+		double bias;
+		const char *format;
+	} ptp_value_trans[] = {
+		{PTP_DPC_BatteryLevel, 0, 1.0, 0.0, "%.0f%%"},		/* 5001 */
+		{PTP_DPC_FNumber, 0, 0.01, 0.0, "f/%.2g"},		/* 5007 */
+		{PTP_DPC_FocalLength, 0, 0.01, 0.0, "%.0f mm"},		/* 5008 */
+		{PTP_DPC_FocusDistance, 0, 0.01, 0.0, "%.0f mm"},	/* 5009 */
+		{PTP_DPC_ExposureTime, 0, 0.00001, 0.0, "%.2g sec"},	/* 500D */
+		{PTP_DPC_ExposureIndex, 0, 1.0, 0.0, "ISO %.0f"},	/* 500F */
+		{PTP_DPC_ExposureBiasCompensation, 0, 0.001, 0.0, N_("%.1f stops")},/* 5010 */
+		{PTP_DPC_DigitalZoom, 0, 0.1, 0.0, "%.1f"},		/* 5016 */
+
+		/* Nikon device properties */
+		{PTP_DPC_NIKON_LightMeter, PTP_VENDOR_NIKON, 0.08333, 0.0, N_("%.1f stops")},/* D10A */
+		{PTP_DPC_NIKON_FlashExposureCompensation, PTP_VENDOR_NIKON, 0.16666, 0.0, N_("%.1f stops")}, /* D126 */
+		{PTP_DPC_NIKON_CenterWeightArea, PTP_VENDOR_NIKON, 2.0, 6.0, N_("%.0f mm")},/* D059 */
+		{PTP_DPC_NIKON_FocalLengthMin, PTP_VENDOR_NIKON, 0.01, 0.0, "%.0f mm"}, /* D0E3 */
+		{PTP_DPC_NIKON_FocalLengthMax, PTP_VENDOR_NIKON, 0.01, 0.0, "%.0f mm"}, /* D0E4 */
+		{PTP_DPC_NIKON_MaxApAtMinFocalLength, PTP_VENDOR_NIKON, 0.01, 0.0, "f/%.2g"}, /* D0E5 */
+		{PTP_DPC_NIKON_MaxApAtMaxFocalLength, PTP_VENDOR_NIKON, 0.01, 0.0, "f/%.2g"}, /* D0E6 */
+		{PTP_DPC_NIKON_ExternalFlashCompensation, PTP_VENDOR_NIKON, 1.0/6.0, 0.0,"%.0f"}, /* D124 */
+		{PTP_DPC_NIKON_ExposureIndicateStatus, PTP_VENDOR_NIKON, 0.08333, 0.0, N_("%.1f stops")},/* D1B1 - FIXME: check if correct. */
+		{0, 0, 0.0, 0.0, NULL}
+	};
+
+	struct {
+		uint16_t dpc;
+		uint16_t vendor;
+		int64_t key;
+		char *value;
+	} ptp_value_list[] = {
+		{PTP_DPC_CompressionSetting, 0, 0, N_("JPEG Basic")},	/* 5004 */
+		{PTP_DPC_CompressionSetting, 0, 1, N_("JPEG Norm")},
+		{PTP_DPC_CompressionSetting, 0, 2, N_("JPEG Fine")},
+		{PTP_DPC_CompressionSetting, 0, 4, N_("RAW")},
+		{PTP_DPC_CompressionSetting, 0, 5, N_("RAW + JPEG Basic")},
+		{PTP_DPC_WhiteBalance, 0, 1, N_("Manual")},
+		{PTP_DPC_WhiteBalance, 0, 2, N_("Automatic")},		/* 5005 */
+		{PTP_DPC_WhiteBalance, 0, 3, N_("One-push Automatic")},
+		{PTP_DPC_WhiteBalance, 0, 4, N_("Daylight")},
+		{PTP_DPC_WhiteBalance, 0, 5, N_("Fluorescent")},
+		{PTP_DPC_WhiteBalance, 0, 6, N_("Incandescent")},
+		{PTP_DPC_WhiteBalance, 0, 7, N_("Flash")},
+		{PTP_DPC_WhiteBalance, PTP_VENDOR_NIKON, 32784, N_("Cloudy")},
+		{PTP_DPC_WhiteBalance, PTP_VENDOR_NIKON, 32785, N_("Shade")},
+		{PTP_DPC_WhiteBalance, PTP_VENDOR_NIKON, 32786, N_("Color Temperature")},
+		{PTP_DPC_WhiteBalance, PTP_VENDOR_NIKON, 32787, N_("Preset")},
+		{PTP_DPC_FocusMode, 0, 1, N_("Manual Focus")},		/* 500A */
+		{PTP_DPC_FocusMode, 0, 2, N_("Automatic")},
+		{PTP_DPC_FocusMode, 0, 3, N_("Automatic Macro (close-up)")},
+		{PTP_DPC_FocusMode, PTP_VENDOR_NIKON, 32784, "AF-S"},
+		{PTP_DPC_FocusMode, PTP_VENDOR_NIKON, 32785, "AF-C"},
+		{PTP_DPC_FocusMode, PTP_VENDOR_NIKON, 32786, "AF-A"},
+		{PTP_DPC_ExposureMeteringMode, 0, 1, N_("Average")},	/* 500B */
+		{PTP_DPC_ExposureMeteringMode, 0, 2, N_("Center Weighted Average")},
+		{PTP_DPC_ExposureMeteringMode, 0, 3, N_("Multi-spot")},
+		{PTP_DPC_ExposureMeteringMode, 0, 4, N_("Center-spot")},
+		{PTP_DPC_FlashMode, 0, 0, N_("Undefined")},		/* 500C */
+		{PTP_DPC_FlashMode, 0, 1, N_("Automatic flash")},
+		{PTP_DPC_FlashMode, 0, 2, N_("Flash off")},
+		{PTP_DPC_FlashMode, 0, 3, N_("Fill flash")},
+		{PTP_DPC_FlashMode, 0, 4, N_("Automatic Red-eye Reduction")},
+		{PTP_DPC_FlashMode, 0, 5, N_("Red-eye fill flash")},
+		{PTP_DPC_FlashMode, 0, 6, N_("External sync")},
+		{PTP_DPC_FlashMode, PTP_VENDOR_NIKON, 32784, N_("Default")},
+		{PTP_DPC_FlashMode, PTP_VENDOR_NIKON, 32785, N_("Slow Sync")},
+		{PTP_DPC_FlashMode, PTP_VENDOR_NIKON, 32786, N_("Rear Curtain Sync + Slow Sync")},
+		{PTP_DPC_FlashMode, PTP_VENDOR_NIKON, 32787, N_("Red-eye Reduction + Slow Sync")},
+		{PTP_DPC_ExposureProgramMode, 0, 1, "M"},		/* 500E */
+		{PTP_DPC_ExposureProgramMode, 0, 3, "A"},
+		{PTP_DPC_ExposureProgramMode, 0, 4, "S"},
+		{PTP_DPC_ExposureProgramMode, 0, 2, "P"},
+		{PTP_DPC_ExposureProgramMode, PTP_VENDOR_NIKON, 32784, N_("Auto")},
+		{PTP_DPC_ExposureProgramMode, PTP_VENDOR_NIKON, 32785, N_("Portrait")},
+		{PTP_DPC_ExposureProgramMode, PTP_VENDOR_NIKON, 32786, N_("Landscape")},
+		{PTP_DPC_ExposureProgramMode, PTP_VENDOR_NIKON, 32787, N_("Macro")},
+		{PTP_DPC_ExposureProgramMode, PTP_VENDOR_NIKON, 32788, N_("Sports")},
+		{PTP_DPC_ExposureProgramMode, PTP_VENDOR_NIKON, 32790, N_("Night Landscape")},
+		{PTP_DPC_ExposureProgramMode, PTP_VENDOR_NIKON, 32789, N_("Night Portrait")},
+		{PTP_DPC_StillCaptureMode, 0, 1, N_("Single Shot")},	/* 5013 */
+		{PTP_DPC_StillCaptureMode, 0, 2, N_("Power Wind")},
+		{PTP_DPC_StillCaptureMode, 0, 3, N_("Timelapse")},
+		{PTP_DPC_StillCaptureMode, PTP_VENDOR_NIKON, 32784, N_("Continuous Low Speed")},
+		{PTP_DPC_StillCaptureMode, PTP_VENDOR_NIKON, 32785, N_("Timer")},
+		{PTP_DPC_StillCaptureMode, PTP_VENDOR_NIKON, 32787, N_("Remote")},
+		{PTP_DPC_StillCaptureMode, PTP_VENDOR_NIKON, 32787, N_("Mirror Up")},
+		{PTP_DPC_StillCaptureMode, PTP_VENDOR_NIKON, 32788, N_("Timer + Remote")},
+		{PTP_DPC_FocusMeteringMode, 0, 1, N_("Centre-spot")},	/* 501C */
+		{PTP_DPC_FocusMeteringMode, 0, 2, N_("Multi-spot")},
+		{PTP_DPC_FocusMeteringMode, PTP_VENDOR_NIKON, 32784, N_("Single Area")},
+		{PTP_DPC_FocusMeteringMode, PTP_VENDOR_NIKON, 32785, N_("Closest Subject")},
+		{PTP_DPC_FocusMeteringMode, PTP_VENDOR_NIKON, 32786, N_("Group Dynamic")},
+
+
+		/* Nikon specific device properties */
+		{PTP_DPC_NIKON_ImageSharpening, PTP_VENDOR_NIKON, 0, N_("Auto")},	/* D02A */
+		{PTP_DPC_NIKON_ImageSharpening, PTP_VENDOR_NIKON, 1, N_("Normal")},
+		{PTP_DPC_NIKON_ImageSharpening, PTP_VENDOR_NIKON, 2, N_("Low")},
+		{PTP_DPC_NIKON_ImageSharpening, PTP_VENDOR_NIKON, 3, N_("Medium Low")},
+		{PTP_DPC_NIKON_ImageSharpening, PTP_VENDOR_NIKON, 4, N_("Medium high")},
+		{PTP_DPC_NIKON_ImageSharpening, PTP_VENDOR_NIKON, 5, N_("High")},
+		{PTP_DPC_NIKON_ImageSharpening, PTP_VENDOR_NIKON, 6, N_("None")},
+
+		{PTP_DPC_NIKON_ToneCompensation, PTP_VENDOR_NIKON, 0, N_("Auto")},	/* D02B */
+		{PTP_DPC_NIKON_ToneCompensation, PTP_VENDOR_NIKON, 1, N_("Normal")},
+		{PTP_DPC_NIKON_ToneCompensation, PTP_VENDOR_NIKON, 2, N_("Low contrast")},
+		{PTP_DPC_NIKON_ToneCompensation, PTP_VENDOR_NIKON, 3, N_("Medium Low")},
+		{PTP_DPC_NIKON_ToneCompensation, PTP_VENDOR_NIKON, 4, N_("Medium High")},
+		{PTP_DPC_NIKON_ToneCompensation, PTP_VENDOR_NIKON, 5, N_("High control")},
+		{PTP_DPC_NIKON_ToneCompensation, PTP_VENDOR_NIKON, 6, N_("Custom")},
+
+		{PTP_DPC_NIKON_ColorModel, PTP_VENDOR_NIKON, 0, "sRGB"},		/* D02C */
+		{PTP_DPC_NIKON_ColorModel, PTP_VENDOR_NIKON, 1, "AdobeRGB"},
+		{PTP_DPC_NIKON_ColorModel, PTP_VENDOR_NIKON, 2, "sRGB"},
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_AutoDXCrop,PTP_VENDOR_NIKON),	   	/* D033 */
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_FocusAreaWrap,PTP_VENDOR_NIKON),   	/* D04F */
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_EnableCopyright,PTP_VENDOR_NIKON),   	/* D053 */
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_ISOAuto,PTP_VENDOR_NIKON),	   	/* D054 */
+
+		/* FIXME! this is not ISO Auto (which is a bool) Perhaps ISO Auto Time?*/
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 0, "1/125"},			/* D054 */
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 1, "1/60"},
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 2, "1/30"},
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 3, "1/15"},
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 4, "1/8"},
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 5, "1/4"},
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 6, "1/2"},
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 7, "1"},
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 8, "2"},
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 9, "4"},
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 10, "8"},
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 11, "15"},
+		{PTP_DPC_NIKON_ISOAuto,	PTP_VENDOR_NIKON, 12, "30"},
+
+		{PTP_DPC_NIKON_EVStep, PTP_VENDOR_NIKON, 0, "1/3"},			/* D056 */
+		{PTP_DPC_NIKON_EVStep, PTP_VENDOR_NIKON, 1, "1/2"},
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_ExposureCompensation,PTP_VENDOR_NIKON),/*D058 */
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_AELockMode,PTP_VENDOR_NIKON),    	/* D05E */
+
+		{PTP_DPC_NIKON_AELAFLMode, PTP_VENDOR_NIKON, 0, N_("AE/AF Lock")},	/* D05F */
+		{PTP_DPC_NIKON_AELAFLMode, PTP_VENDOR_NIKON, 1, N_("AF Lock only")},
+		{PTP_DPC_NIKON_AELAFLMode, PTP_VENDOR_NIKON, 2, N_("AE Lock only")},
+		{PTP_DPC_NIKON_AELAFLMode, PTP_VENDOR_NIKON, 3, N_("AF Lock Hold")},
+		{PTP_DPC_NIKON_AELAFLMode, PTP_VENDOR_NIKON, 4, N_("AF On")},
+		{PTP_DPC_NIKON_AELAFLMode, PTP_VENDOR_NIKON, 5, N_("Flash Lock")},
+
+		{PTP_DPC_NIKON_MeterOff, PTP_VENDOR_NIKON, 0, N_("4 seconds")},		/* D062 */
+		{PTP_DPC_NIKON_MeterOff, PTP_VENDOR_NIKON, 1, N_("6 seconds")},
+		{PTP_DPC_NIKON_MeterOff, PTP_VENDOR_NIKON, 2, N_("8 seconds")},
+		{PTP_DPC_NIKON_MeterOff, PTP_VENDOR_NIKON, 3, N_("16 seconds")},
+		{PTP_DPC_NIKON_MeterOff, PTP_VENDOR_NIKON, 4, N_("30 minutes")},
+		{PTP_DPC_NIKON_MeterOff, PTP_VENDOR_NIKON, 5, N_("30 seconds")},
+
+		{PTP_DPC_NIKON_SelfTimer, PTP_VENDOR_NIKON, 0, N_("2 seconds")},	/* D063 */
+		{PTP_DPC_NIKON_SelfTimer, PTP_VENDOR_NIKON, 1, N_("5 seconds")},
+		{PTP_DPC_NIKON_SelfTimer, PTP_VENDOR_NIKON, 2, N_("10 seconds")},
+		{PTP_DPC_NIKON_SelfTimer, PTP_VENDOR_NIKON, 3, N_("20 seconds")},
+
+		{PTP_DPC_NIKON_MonitorOff, PTP_VENDOR_NIKON, 0, N_("10 seconds")},	/* D064 */
+		{PTP_DPC_NIKON_MonitorOff, PTP_VENDOR_NIKON, 1, N_("20 seconds")},
+		{PTP_DPC_NIKON_MonitorOff, PTP_VENDOR_NIKON, 2, N_("1 minute")},
+		{PTP_DPC_NIKON_MonitorOff, PTP_VENDOR_NIKON, 3, N_("5 minutes")},
+		{PTP_DPC_NIKON_MonitorOff, PTP_VENDOR_NIKON, 4, N_("10 minutes")},
+		{PTP_DPC_NIKON_MonitorOff, PTP_VENDOR_NIKON, 5, N_("5 seconds")}, /* d80 observed */
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_D3ExpDelayMode,PTP_VENDOR_NIKON),	/* D06A */
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_LongExposureNoiseReduction,PTP_VENDOR_NIKON),	/* D06B */
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_FileNumberSequence,PTP_VENDOR_NIKON),	/* D06C */
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_D7Illumination,PTP_VENDOR_NIKON),	/* D06F */
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_SHSET_CH_GUID_DISP,PTP_VENDOR_NIKON),	/* D071 */
+
+		{PTP_DPC_NIKON_FlashShutterSpeed, PTP_VENDOR_NIKON, 0, "1/60s"},		/* D075 */
+		{PTP_DPC_NIKON_FlashShutterSpeed, PTP_VENDOR_NIKON, 1, "1/30s"},
+		{PTP_DPC_NIKON_FlashShutterSpeed, PTP_VENDOR_NIKON, 2, "1/15s"},
+		{PTP_DPC_NIKON_FlashShutterSpeed, PTP_VENDOR_NIKON, 3, "1/8s"},
+		{PTP_DPC_NIKON_FlashShutterSpeed, PTP_VENDOR_NIKON, 4, "1/4s"},
+		{PTP_DPC_NIKON_FlashShutterSpeed, PTP_VENDOR_NIKON, 5, "1/2s"},
+		{PTP_DPC_NIKON_FlashShutterSpeed, PTP_VENDOR_NIKON, 6, "1s"},
+		{PTP_DPC_NIKON_FlashShutterSpeed, PTP_VENDOR_NIKON, 7, "2s"},
+		{PTP_DPC_NIKON_FlashShutterSpeed, PTP_VENDOR_NIKON, 8, "4s"},
+		{PTP_DPC_NIKON_FlashShutterSpeed, PTP_VENDOR_NIKON, 9, "8s"},
+		{PTP_DPC_NIKON_FlashShutterSpeed, PTP_VENDOR_NIKON, 10, "15s"},
+		{PTP_DPC_NIKON_FlashShutterSpeed, PTP_VENDOR_NIKON, 11, "30s"},
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_E4ModelingFlash,PTP_VENDOR_NIKON),	/* D077 */
+
+		{PTP_DPC_NIKON_BracketSet, PTP_VENDOR_NIKON, 0, N_("AE & Flash")},	/* D078 */
+		{PTP_DPC_NIKON_BracketSet, PTP_VENDOR_NIKON, 1, N_("AE only")},
+		{PTP_DPC_NIKON_BracketSet, PTP_VENDOR_NIKON, 2, N_("Flash only")},
+		{PTP_DPC_NIKON_BracketSet, PTP_VENDOR_NIKON, 3, N_("WB bracketing")},
+
+		{PTP_DPC_NIKON_BracketOrder, PTP_VENDOR_NIKON, 0, N_("MTR > Under")},	/* D07A */
+		{PTP_DPC_NIKON_BracketOrder, PTP_VENDOR_NIKON, 1, N_("Under > MTR")},
+
+		{PTP_DPC_NIKON_F1CenterButtonShootingMode, PTP_VENDOR_NIKON, 0, N_("Reset focus point to center")}, /* D080 */
+		{PTP_DPC_NIKON_F1CenterButtonShootingMode, PTP_VENDOR_NIKON, 1, N_("Highlight active focus point")},
+		{PTP_DPC_NIKON_F1CenterButtonShootingMode, PTP_VENDOR_NIKON, 2, N_("Unused")},
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_F3PhotoInfoPlayback,PTP_VENDOR_NIKON),/* D083 */
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_F5CustomizeCommDials,PTP_VENDOR_NIKON),/* D085 */
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_ReverseCommandDial,PTP_VENDOR_NIKON),	/* D086 */
+		PTP_VENDOR_VAL_RBOOL(PTP_DPC_NIKON_F6ButtonsAndDials,PTP_VENDOR_NIKON),	/* D089 */
+		PTP_VENDOR_VAL_RBOOL(PTP_DPC_NIKON_NoCFCard,PTP_VENDOR_NIKON),		/* D08A */
+		PTP_VENDOR_VAL_RBOOL(PTP_DPC_NIKON_AFAreaPoint,PTP_VENDOR_NIKON),	/* D08D */
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_ImageCommentEnable,PTP_VENDOR_NIKON),	/* D091 */
+		PTP_VENDOR_VAL_RBOOL(PTP_DPC_NIKON_ImageRotation,PTP_VENDOR_NIKON),	/* D092 */
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_MovVoice,PTP_VENDOR_NIKON),		/* D0A1 */
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_Bracketing,PTP_VENDOR_NIKON),		/* D0C0 */
+
+		{PTP_DPC_NIKON_LensID, PTP_VENDOR_NIKON, 0, N_("Unknown")},		/* D0E0 */
+		{PTP_DPC_NIKON_LensID, PTP_VENDOR_NIKON, 38, "Sigma 70-300mm 1:4-5.6 D APO Macro"},
+		{PTP_DPC_NIKON_LensID, PTP_VENDOR_NIKON, 83, "AF Nikkor 80-200mm 1:2.8 D ED"},
+		{PTP_DPC_NIKON_LensID, PTP_VENDOR_NIKON, 118, "AF Nikkor 50mm 1:1.8 D"},
+		{PTP_DPC_NIKON_LensID, PTP_VENDOR_NIKON, 127, "AF-S Nikkor 18-70mm 1:3.5-4.5G ED DX"},
+		{PTP_DPC_NIKON_LensID, PTP_VENDOR_NIKON, 139, "AF-S Nikkor 18-200mm 1:3.5-5.6 GED DX VR"},
+		{PTP_DPC_NIKON_LensID, PTP_VENDOR_NIKON, 147, "AF-S Nikkor 24-70mm 1:2.8G ED DX"},
+		{PTP_DPC_NIKON_LensID, PTP_VENDOR_NIKON, 154, "AF-S Nikkor 18-55mm 1:3.5-F5.6G DX VR"},
+		{PTP_DPC_NIKON_FinderISODisp, PTP_VENDOR_NIKON, 0, "Show ISO sensitivity"},/* 0xD0F0 */
+		{PTP_DPC_NIKON_FinderISODisp, PTP_VENDOR_NIKON, 1, "Show ISO/Easy ISO"},
+		{PTP_DPC_NIKON_FinderISODisp, PTP_VENDOR_NIKON, 2, "Show frame count"},
+
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_ACPower,PTP_VENDOR_NIKON),		/* D101 */
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_AFLockStatus,PTP_VENDOR_NIKON),		/* D104 */
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_AELockStatus,PTP_VENDOR_NIKON),		/* D105 */
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_FVLockStatus,PTP_VENDOR_NIKON),		/* D106 */
+
+		{PTP_DPC_NIKON_AutofocusArea, PTP_VENDOR_NIKON, 0, N_("Centre")},	/* D108 */
+		{PTP_DPC_NIKON_AutofocusArea, PTP_VENDOR_NIKON, 1, N_("Top")},
+		{PTP_DPC_NIKON_AutofocusArea, PTP_VENDOR_NIKON, 2, N_("Bottom")},
+		{PTP_DPC_NIKON_AutofocusArea, PTP_VENDOR_NIKON, 3, N_("Left")},
+		{PTP_DPC_NIKON_AutofocusArea, PTP_VENDOR_NIKON, 4, N_("Right")},
+
+		{PTP_DPC_NIKON_RecordingMedia, PTP_VENDOR_NIKON, 0, N_("Card")},	/* D10B */
+		{PTP_DPC_NIKON_RecordingMedia, PTP_VENDOR_NIKON, 1, N_("SDRam")},
+
+		{PTP_DPC_NIKON_USBSpeed, PTP_VENDOR_NIKON, 0, N_("USB 1.1")},		/* D10C */
+		{PTP_DPC_NIKON_USBSpeed, PTP_VENDOR_NIKON, 1, N_("USB 2.0")},
+
+		{PTP_DPC_NIKON_CameraOrientation, PTP_VENDOR_NIKON, 0, "0'"},		/* D10E */
+		{PTP_DPC_NIKON_CameraOrientation, PTP_VENDOR_NIKON, 1, "270'"},
+		{PTP_DPC_NIKON_CameraOrientation, PTP_VENDOR_NIKON, 2, "90'"},
+		{PTP_DPC_NIKON_CameraOrientation, PTP_VENDOR_NIKON, 3, "180'"},
+
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_FNumberLock,PTP_VENDOR_NIKON),		/* D110 */
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_ExposureApertureLock,PTP_VENDOR_NIKON),	/* D111 */
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_TVLockSetting,PTP_VENDOR_NIKON),	/* D112 */
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_AVLockSetting,PTP_VENDOR_NIKON),	/* D113 */
+
+		{PTP_DPC_NIKON_IllumSetting,PTP_VENDOR_NIKON,0,N_("LCD Backlight")},	/* D114 */
+		{PTP_DPC_NIKON_IllumSetting,PTP_VENDOR_NIKON,1,N_("LCD Backlight and Info Display")},
+
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_ExternalFlashAttached,PTP_VENDOR_NIKON),/* D120 */
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_ExternalFlashStatus,PTP_VENDOR_NIKON),	/* D121 */
+
+		{PTP_DPC_NIKON_OptimizeImage, PTP_VENDOR_NIKON, 0, N_("Normal")},	/* D140 */
+		{PTP_DPC_NIKON_OptimizeImage, PTP_VENDOR_NIKON, 1, N_("Vivid")},
+		{PTP_DPC_NIKON_OptimizeImage, PTP_VENDOR_NIKON, 2, N_("Sharper")},
+		{PTP_DPC_NIKON_OptimizeImage, PTP_VENDOR_NIKON, 3, N_("Softer")},
+		{PTP_DPC_NIKON_OptimizeImage, PTP_VENDOR_NIKON, 4, N_("Direct Print")},
+		{PTP_DPC_NIKON_OptimizeImage, PTP_VENDOR_NIKON, 5, N_("Portrait")},
+		{PTP_DPC_NIKON_OptimizeImage, PTP_VENDOR_NIKON, 6, N_("Landscape")},
+		{PTP_DPC_NIKON_OptimizeImage, PTP_VENDOR_NIKON, 7, N_("Custom")},
+
+		{PTP_DPC_NIKON_Saturation, PTP_VENDOR_NIKON, 0, N_("Normal")},		/* D142 */
+		{PTP_DPC_NIKON_Saturation, PTP_VENDOR_NIKON, 1, N_("Moderate")},
+		{PTP_DPC_NIKON_Saturation, PTP_VENDOR_NIKON, 2, N_("Enhanced")},
+
+		PTP_VENDOR_VAL_RBOOL(PTP_DPC_NIKON_BeepOff,PTP_VENDOR_NIKON),		/* D160 */
+
+		{PTP_DPC_NIKON_AutofocusMode, PTP_VENDOR_NIKON, 0, N_("AF-S")},	 	/* D161 */
+		{PTP_DPC_NIKON_AutofocusMode, PTP_VENDOR_NIKON, 1, N_("AF-C")},
+		{PTP_DPC_NIKON_AutofocusMode, PTP_VENDOR_NIKON, 2, N_("AF-A")},
+		{PTP_DPC_NIKON_AutofocusMode, PTP_VENDOR_NIKON, 3, N_("MF (fixed)")},
+		{PTP_DPC_NIKON_AutofocusMode, PTP_VENDOR_NIKON, 4, N_("MF (selection)")},
+
+		PTP_VENDOR_VAL_RBOOL(PTP_DPC_NIKON_AFAssist,PTP_VENDOR_NIKON),   	/* D163 */
+
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 0,  "1/125"},		/* D164 */
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 1,  "1/60"},
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 2,  "1/30"},
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 3,  "1/15"},
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 4,  "1/8"},
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 5,  "1/4"},
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 6,  "1/2"},
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 7,  "1"},
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 8,  "2"},
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 9,  "4"},
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 10, "8"},
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 11, "15"},
+		{PTP_DPC_NIKON_PADVPMode, PTP_VENDOR_NIKON, 12, "30"},
+
+		PTP_VENDOR_VAL_RBOOL(PTP_DPC_NIKON_ImageReview,PTP_VENDOR_NIKON),	/* D165 */
+
+		{PTP_DPC_NIKON_AFAreaIllumination, PTP_VENDOR_NIKON, 0, N_("Auto")},	/* D166 */
+		{PTP_DPC_NIKON_AFAreaIllumination, PTP_VENDOR_NIKON, 1, N_("Off")},
+		{PTP_DPC_NIKON_AFAreaIllumination, PTP_VENDOR_NIKON, 2, N_("On")},
+
+		{PTP_DPC_NIKON_FlashMode, PTP_VENDOR_NIKON, 0, "iTTL"},			/* D167 */
+		{PTP_DPC_NIKON_FlashMode, PTP_VENDOR_NIKON, 1, N_("Manual")},
+		{PTP_DPC_NIKON_FlashMode, PTP_VENDOR_NIKON, 2, N_("Commander")},
+
+		{PTP_DPC_NIKON_FlashCommanderMode, PTP_VENDOR_NIKON, 0, N_("TTL")},	/* D168 */
+		{PTP_DPC_NIKON_FlashCommanderMode, PTP_VENDOR_NIKON, 1, N_("Auto Aperture")},
+		{PTP_DPC_NIKON_FlashCommanderMode, PTP_VENDOR_NIKON, 2, N_("Full Manual")},
+
+		PTP_VENDOR_VAL_RBOOL(PTP_DPC_NIKON_FlashSign,PTP_VENDOR_NIKON),		/* D169 */
+
+		{PTP_DPC_NIKON_RemoteTimeout, PTP_VENDOR_NIKON, 0, N_("1 min")},	/* D16B */
+		{PTP_DPC_NIKON_RemoteTimeout, PTP_VENDOR_NIKON, 1, N_("5 mins")},
+		{PTP_DPC_NIKON_RemoteTimeout, PTP_VENDOR_NIKON, 2, N_("10 mins")},
+		{PTP_DPC_NIKON_RemoteTimeout, PTP_VENDOR_NIKON, 3, N_("15 mins")},
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_NIKON_GridDisplay,PTP_VENDOR_NIKON),	/* D16C */
+
+		{PTP_DPC_NIKON_FlashModeManualPower, PTP_VENDOR_NIKON, 0, N_("Full")},	/* D16D */
+		{PTP_DPC_NIKON_FlashModeManualPower, PTP_VENDOR_NIKON, 1, "1/2"},
+		{PTP_DPC_NIKON_FlashModeManualPower, PTP_VENDOR_NIKON, 2, "1/4"},
+		{PTP_DPC_NIKON_FlashModeManualPower, PTP_VENDOR_NIKON, 3, "1/8"},
+		{PTP_DPC_NIKON_FlashModeManualPower, PTP_VENDOR_NIKON, 4, "1/16"},
+
+		{PTP_DPC_NIKON_FlashModeCommanderPower, PTP_VENDOR_NIKON, 0, N_("Full")},/* D16E */
+		{PTP_DPC_NIKON_FlashModeCommanderPower, PTP_VENDOR_NIKON, 1, "1/2"},
+		{PTP_DPC_NIKON_FlashModeCommanderPower, PTP_VENDOR_NIKON, 2, "1/4"},
+		{PTP_DPC_NIKON_FlashModeCommanderPower, PTP_VENDOR_NIKON, 3, "1/8"},
+		{PTP_DPC_NIKON_FlashModeCommanderPower, PTP_VENDOR_NIKON, 4, "1/16"},
+		{PTP_DPC_NIKON_FlashModeCommanderPower, PTP_VENDOR_NIKON, 5, "1/32"},
+		{PTP_DPC_NIKON_FlashModeCommanderPower, PTP_VENDOR_NIKON, 6, "1/64"},
+		{PTP_DPC_NIKON_FlashModeCommanderPower, PTP_VENDOR_NIKON, 7, "1/128"},
+
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_CSMMenu,PTP_VENDOR_NIKON),		/* D180 */
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_WarningDisplay,PTP_VENDOR_NIKON),	/* D181 */
+
+		{PTP_DPC_NIKON_BatteryCellKind, PTP_VENDOR_NIKON, 0, "LR6 (AA alkaline)"},/* D182 */
+		{PTP_DPC_NIKON_BatteryCellKind, PTP_VENDOR_NIKON, 1, "HR6 (AA Ni-Mh)"},
+		{PTP_DPC_NIKON_BatteryCellKind, PTP_VENDOR_NIKON, 2, "FR6 (AA Lithium)"},
+		{PTP_DPC_NIKON_BatteryCellKind, PTP_VENDOR_NIKON, 3, "ZR6 (AA Ni-Mn)"},
+
+		{PTP_DPC_NIKON_ISOAutoHiLimit, PTP_VENDOR_NIKON, 0, "400"},		/* D183 */
+		{PTP_DPC_NIKON_ISOAutoHiLimit, PTP_VENDOR_NIKON, 1, "800"},
+		{PTP_DPC_NIKON_ISOAutoHiLimit, PTP_VENDOR_NIKON, 2, "1600"},
+		{PTP_DPC_NIKON_ISOAutoHiLimit, PTP_VENDOR_NIKON, 3, "3200"},
+		{PTP_DPC_NIKON_ISOAutoHiLimit, PTP_VENDOR_NIKON, 4, "Hi 1"},
+
+		{PTP_DPC_NIKON_InfoDispSetting, PTP_VENDOR_NIKON, 0, N_("Auto")},	/* 0xD187 */
+		{PTP_DPC_NIKON_InfoDispSetting, PTP_VENDOR_NIKON, 1, N_("Dark on light")},
+		{PTP_DPC_NIKON_InfoDispSetting, PTP_VENDOR_NIKON, 2, N_("Light on dark")},
+
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_IndicatorDisp,PTP_VENDOR_NIKON),	/* D18D */
+
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_LiveViewStatus,PTP_VENDOR_NIKON),	/* D1A2 */
+
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_ExposureDisplayStatus,PTP_VENDOR_NIKON),/* D1B0 */
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_InfoDispErrStatus,PTP_VENDOR_NIKON),	/* D1B2 */
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_ExposureIndicateLightup,PTP_VENDOR_NIKON),/* D1B3 */
+
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_FlashOpen,PTP_VENDOR_NIKON),		/* D1C0 */
+		PTP_VENDOR_VAL_YN(PTP_DPC_NIKON_FlashCharged,PTP_VENDOR_NIKON),		/* D1C1 */
+
+		/* Canon stuff */
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_CANON_AssistLight,PTP_VENDOR_CANON),
+		PTP_VENDOR_VAL_RBOOL(PTP_DPC_CANON_RotationScene,PTP_VENDOR_CANON),
+		PTP_VENDOR_VAL_RBOOL(PTP_DPC_CANON_BeepMode,PTP_VENDOR_CANON),
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_CANON_Beep,PTP_VENDOR_CANON),
+
+		{PTP_DPC_CANON_RotationAngle, PTP_VENDOR_CANON, 0, "0'"},
+		{PTP_DPC_CANON_RotationAngle, PTP_VENDOR_CANON, 3, "270'"},
+		{PTP_DPC_CANON_RotationAngle, PTP_VENDOR_CANON, 1, "90'"},
+
+		{PTP_DPC_CANON_BatteryKind, PTP_VENDOR_CANON, 0, N_("Unknown")},
+		{PTP_DPC_CANON_BatteryKind, PTP_VENDOR_CANON, 1, N_("AC")},
+		{PTP_DPC_CANON_BatteryKind, PTP_VENDOR_CANON, 2, N_("Lithium Ion")},
+		{PTP_DPC_CANON_BatteryKind, PTP_VENDOR_CANON, 3, N_("Nickel hydride")},
+		{PTP_DPC_CANON_BatteryKind, PTP_VENDOR_CANON, 4, N_("Nickel cadmium")},
+		{PTP_DPC_CANON_BatteryKind, PTP_VENDOR_CANON, 5, N_("Alkalium manganese")},
+
+		{PTP_DPC_CANON_BatteryStatus, PTP_VENDOR_CANON, 0, N_("Undefined")},
+		{PTP_DPC_CANON_BatteryStatus, PTP_VENDOR_CANON, 1, N_("Normal")},
+		{PTP_DPC_CANON_BatteryStatus, PTP_VENDOR_CANON, 2, N_("Warning Level 1")},
+		{PTP_DPC_CANON_BatteryStatus, PTP_VENDOR_CANON, 3, N_("Emergency")},
+		{PTP_DPC_CANON_BatteryStatus, PTP_VENDOR_CANON, 4, N_("Warning Level 0")},
+
+		{PTP_DPC_CANON_ImageQuality, PTP_VENDOR_CANON, 0, N_("Undefined")},
+		{PTP_DPC_CANON_ImageQuality, PTP_VENDOR_CANON, 1, N_("Economy")},
+		{PTP_DPC_CANON_ImageQuality, PTP_VENDOR_CANON, 2, N_("Normal")},
+		{PTP_DPC_CANON_ImageQuality, PTP_VENDOR_CANON, 3, N_("Fine")},
+		{PTP_DPC_CANON_ImageQuality, PTP_VENDOR_CANON, 4, N_("Lossless")},
+		{PTP_DPC_CANON_ImageQuality, PTP_VENDOR_CANON, 5, N_("SuperFine")},
+
+		{PTP_DPC_CANON_FullViewFileFormat, PTP_VENDOR_CANON, 0, N_("Undefined")},
+		{PTP_DPC_CANON_FullViewFileFormat, PTP_VENDOR_CANON, 1, N_("JPEG")},
+		{PTP_DPC_CANON_FullViewFileFormat, PTP_VENDOR_CANON, 2, N_("CRW")},
+
+		{PTP_DPC_CANON_ImageSize, PTP_VENDOR_CANON, 0, N_("Large")},
+		{PTP_DPC_CANON_ImageSize, PTP_VENDOR_CANON, 1, N_("Medium 1")},
+		{PTP_DPC_CANON_ImageSize, PTP_VENDOR_CANON, 2, N_("Small")},
+		{PTP_DPC_CANON_ImageSize, PTP_VENDOR_CANON, 3, N_("Medium 2")},
+		{PTP_DPC_CANON_ImageSize, PTP_VENDOR_CANON, 7, N_("Medium 3")},
+
+		{PTP_DPC_CANON_SelfTime, PTP_VENDOR_CANON, 0,   N_("Not used")},
+		{PTP_DPC_CANON_SelfTime, PTP_VENDOR_CANON, 100, N_("10 seconds")},
+		{PTP_DPC_CANON_SelfTime, PTP_VENDOR_CANON, 20,  N_("2 seconds")},
+
+		{PTP_DPC_CANON_FlashMode, PTP_VENDOR_CANON, 0,  N_("Off")},
+		{PTP_DPC_CANON_FlashMode, PTP_VENDOR_CANON, 1,  N_("Auto")},
+		{PTP_DPC_CANON_FlashMode, PTP_VENDOR_CANON, 2,  N_("On")},
+		{PTP_DPC_CANON_FlashMode, PTP_VENDOR_CANON, 3,  N_("Red Eye Suppression")},
+		{PTP_DPC_CANON_FlashMode, PTP_VENDOR_CANON, 4,  N_("Low Speed Synchronization")},
+		{PTP_DPC_CANON_FlashMode, PTP_VENDOR_CANON, 5,  N_("Auto + Red Eye Suppression")},
+		{PTP_DPC_CANON_FlashMode, PTP_VENDOR_CANON, 6,  N_("On + Red Eye Suppression")},
+
+		{PTP_DPC_CANON_ShootingMode, PTP_VENDOR_CANON, 0,  N_("Auto")},
+		{PTP_DPC_CANON_ShootingMode, PTP_VENDOR_CANON, 1,  N_("P")},
+		{PTP_DPC_CANON_ShootingMode, PTP_VENDOR_CANON, 2,  N_("Tv")},
+		{PTP_DPC_CANON_ShootingMode, PTP_VENDOR_CANON, 3,  N_("Av")},
+		{PTP_DPC_CANON_ShootingMode, PTP_VENDOR_CANON, 4,  N_("M")},
+		{PTP_DPC_CANON_ShootingMode, PTP_VENDOR_CANON, 5,  N_("A_DEP")},
+		{PTP_DPC_CANON_ShootingMode, PTP_VENDOR_CANON, 6,  N_("M_DEP")},
+		{PTP_DPC_CANON_ShootingMode, PTP_VENDOR_CANON, 7,  N_("Bulb")},
+		/* more actually */
+
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 0,  N_("Auto")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 1,  N_("Manual")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 2,  N_("Distant View")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 3,  N_("High-Speed Shutter")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 4,  N_("Low-Speed Shutter")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 5,  N_("Night View")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 6,  N_("Grayscale")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 7,  N_("Sepia")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 8,  N_("Portrait")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 9,  N_("Sports")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 10,  N_("Macro")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 11,  N_("Monochrome")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 12,  N_("Pan Focus")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 13,  N_("Neutral")},
+		{PTP_DPC_CANON_ImageMode, PTP_VENDOR_CANON, 14,  N_("Soft")},
+
+		{PTP_DPC_CANON_DriveMode, PTP_VENDOR_CANON, 0,  N_("Single-Frame Shooting")},
+		{PTP_DPC_CANON_DriveMode, PTP_VENDOR_CANON, 1,  N_("Continuous Shooting")},
+		{PTP_DPC_CANON_DriveMode, PTP_VENDOR_CANON, 2,  N_("Timer (Single) Shooting")},
+		{PTP_DPC_CANON_DriveMode, PTP_VENDOR_CANON, 4,  N_("Continuous Low-speed Shooting")},
+		{PTP_DPC_CANON_DriveMode, PTP_VENDOR_CANON, 5,  N_("Continuous High-speed Shooting")},
+
+		{PTP_DPC_CANON_EZoom, PTP_VENDOR_CANON, 0,  N_("Off")},
+		{PTP_DPC_CANON_EZoom, PTP_VENDOR_CANON, 1,  N_("2x")},
+		{PTP_DPC_CANON_EZoom, PTP_VENDOR_CANON, 2,  N_("4x")},
+		{PTP_DPC_CANON_EZoom, PTP_VENDOR_CANON, 3,  N_("Smooth")},
+
+		{PTP_DPC_CANON_MeteringMode, PTP_VENDOR_CANON, 0,  N_("Center-weighted Metering")},
+		{PTP_DPC_CANON_MeteringMode, PTP_VENDOR_CANON, 1,  N_("Spot Metering")},
+		{PTP_DPC_CANON_MeteringMode, PTP_VENDOR_CANON, 2,  N_("Average Metering")},
+		{PTP_DPC_CANON_MeteringMode, PTP_VENDOR_CANON, 3,  N_("Evaluative Metering")},
+		{PTP_DPC_CANON_MeteringMode, PTP_VENDOR_CANON, 4,  N_("Partial Metering")},
+		{PTP_DPC_CANON_MeteringMode, PTP_VENDOR_CANON, 5,  N_("Center-weighted Average Metering")},
+		{PTP_DPC_CANON_MeteringMode, PTP_VENDOR_CANON, 6,  N_("Spot Metering Interlocked with AF Frame")},
+		{PTP_DPC_CANON_MeteringMode, PTP_VENDOR_CANON, 7,  N_("Multi-Spot Metering")},
+
+		{PTP_DPC_CANON_AFDistance, PTP_VENDOR_CANON, 0,  N_("Manual")},
+		{PTP_DPC_CANON_AFDistance, PTP_VENDOR_CANON, 1,  N_("Auto")},
+		{PTP_DPC_CANON_AFDistance, PTP_VENDOR_CANON, 2,  N_("Unknown")},
+		{PTP_DPC_CANON_AFDistance, PTP_VENDOR_CANON, 3,  N_("Zone Focus (Close-up)")},
+		{PTP_DPC_CANON_AFDistance, PTP_VENDOR_CANON, 4,  N_("Zone Focus (Very Close)")},
+		{PTP_DPC_CANON_AFDistance, PTP_VENDOR_CANON, 5,  N_("Zone Focus (Close)")},
+		{PTP_DPC_CANON_AFDistance, PTP_VENDOR_CANON, 6,  N_("Zone Focus (Medium)")},
+		{PTP_DPC_CANON_AFDistance, PTP_VENDOR_CANON, 7,  N_("Zone Focus (Far)")},
+
+		{PTP_DPC_CANON_FocusingPoint, PTP_VENDOR_CANON, 0,  N_("Invalid")},
+		{PTP_DPC_CANON_FocusingPoint, PTP_VENDOR_CANON, 0x1000,  N_("Focusing Point on Center Only, Manual")},
+		{PTP_DPC_CANON_FocusingPoint, PTP_VENDOR_CANON, 0x1001,  N_("Focusing Point on Center Only, Auto")},
+		{PTP_DPC_CANON_FocusingPoint, PTP_VENDOR_CANON, 0x3000,  N_("Multiple Focusing Points (No Specification), Manual")},
+		{PTP_DPC_CANON_FocusingPoint, PTP_VENDOR_CANON, 0x3001,  N_("Multiple Focusing Points, Auto")},
+		{PTP_DPC_CANON_FocusingPoint, PTP_VENDOR_CANON, 0x3002,  N_("Multiple Focusing Points (Right)")},
+		{PTP_DPC_CANON_FocusingPoint, PTP_VENDOR_CANON, 0x3003,  N_("Multiple Focusing Points (Center)")},
+		{PTP_DPC_CANON_FocusingPoint, PTP_VENDOR_CANON, 0x3004,  N_("Multiple Focusing Points (Left)")},
+
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 0,  N_("Auto")},
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 1,  N_("Daylight")},
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 2,  N_("Cloudy")},
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 3,  N_("Tungsten")},
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 4,  N_("Fluorescent")},
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 6,  N_("Preset")},
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 7,  N_("Fluorescent H")},
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 9,  N_("Color Temperature")},
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 10,  N_("Custom Whitebalance PC-1")},
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 11,  N_("Custom Whitebalance PC-2")},
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 12,  N_("Custom Whitebalance PC-3")},
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 13,  N_("Missing Number")},
+		{PTP_DPC_CANON_WhiteBalance, PTP_VENDOR_CANON, 14,  N_("Fluorescent H")}, /* dup? */
+
+		{PTP_DPC_CANON_SlowShutterSetting, PTP_VENDOR_CANON, 0,  N_("Off")},
+		{PTP_DPC_CANON_SlowShutterSetting, PTP_VENDOR_CANON, 1,  N_("Night View")},
+		{PTP_DPC_CANON_SlowShutterSetting, PTP_VENDOR_CANON, 2,  N_("On")},
+		{PTP_DPC_CANON_SlowShutterSetting, PTP_VENDOR_CANON, 3,  N_("Low-speed shutter function not available")},
+
+		{PTP_DPC_CANON_AFMode, PTP_VENDOR_CANON, 0,  N_("Single Shot")},
+		{PTP_DPC_CANON_AFMode, PTP_VENDOR_CANON, 1,  N_("AI Servo")},
+		{PTP_DPC_CANON_AFMode, PTP_VENDOR_CANON, 2,  N_("AI Focus")},
+		{PTP_DPC_CANON_AFMode, PTP_VENDOR_CANON, 3,  N_("Manual")},
+		{PTP_DPC_CANON_AFMode, PTP_VENDOR_CANON, 4,  N_("Continuous")},
+
+		PTP_VENDOR_VAL_BOOL(PTP_DPC_CANON_ImageStabilization,PTP_VENDOR_CANON),
+
+		{PTP_DPC_CANON_Contrast, PTP_VENDOR_CANON, -2,  N_("Low 2")},
+		{PTP_DPC_CANON_Contrast, PTP_VENDOR_CANON, -1,  N_("Low")},
+		{PTP_DPC_CANON_Contrast, PTP_VENDOR_CANON, 0,  N_("Standard")},
+		{PTP_DPC_CANON_Contrast, PTP_VENDOR_CANON, 1,  N_("High")},
+		{PTP_DPC_CANON_Contrast, PTP_VENDOR_CANON, 2,  N_("High 2")},
+
+		{PTP_DPC_CANON_ColorGain, PTP_VENDOR_CANON, -2,  N_("Low 2")},
+		{PTP_DPC_CANON_ColorGain, PTP_VENDOR_CANON, -1,  N_("Low")},
+		{PTP_DPC_CANON_ColorGain, PTP_VENDOR_CANON, 0,  N_("Standard")},
+		{PTP_DPC_CANON_ColorGain, PTP_VENDOR_CANON, 1,  N_("High")},
+		{PTP_DPC_CANON_ColorGain, PTP_VENDOR_CANON, 2,  N_("High 2")},
+
+		{PTP_DPC_CANON_Sharpness, PTP_VENDOR_CANON, -2,  N_("Low 2")},
+		{PTP_DPC_CANON_Sharpness, PTP_VENDOR_CANON, -1,  N_("Low")},
+		{PTP_DPC_CANON_Sharpness, PTP_VENDOR_CANON, 0,  N_("Standard")},
+		{PTP_DPC_CANON_Sharpness, PTP_VENDOR_CANON, 1,  N_("High")},
+		{PTP_DPC_CANON_Sharpness, PTP_VENDOR_CANON, 2,  N_("High 2")},
+
+		{PTP_DPC_CANON_Sensitivity, PTP_VENDOR_CANON, 0,  N_("Standard")},
+		{PTP_DPC_CANON_Sensitivity, PTP_VENDOR_CANON, 1,  N_("Upper 1")},
+		{PTP_DPC_CANON_Sensitivity, PTP_VENDOR_CANON, 2,  N_("Upper 2")},
+
+		{PTP_DPC_CANON_ParameterSet, PTP_VENDOR_CANON, 0x08,  N_("Standard Development Parameters")},
+		{PTP_DPC_CANON_ParameterSet, PTP_VENDOR_CANON, 0x10,  N_("Development Parameters 1")},
+		{PTP_DPC_CANON_ParameterSet, PTP_VENDOR_CANON, 0x20,  N_("Development Parameters 2")},
+		{PTP_DPC_CANON_ParameterSet, PTP_VENDOR_CANON, 0x40,  N_("Development Parameters 3")},
+
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x00,  N_("Auto")},
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x28,  "6"},
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x30,  "12"},
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x38,  "25"},
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x40,  "50"},
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x43,  "64"},
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x48,  "100"},
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x50,  "200"},
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x58,  "400"},
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x60,  "800"},
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x68,  "1600"},
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x70,  "3200"},
+		{PTP_DPC_CANON_ISOSpeed, PTP_VENDOR_CANON, 0x78,  "6400"},
+
+		/* 0xd01d - PTP_DPC_CANON_Aperture */
+		/* 0xd01e - PTP_DPC_CANON_ShutterSpeed */
+		/* 0xd01f - PTP_DPC_CANON_ExpCompensation */
+		/* 0xd020 - PTP_DPC_CANON_FlashCompensation */
+		/* 0xd021 - PTP_DPC_CANON_AEBExposureCompensation */
+		/* 0xd023 - PTP_DPC_CANON_AvOpen */
+		/* 0xd024 - PTP_DPC_CANON_AvMax */
+
+		{PTP_DPC_CANON_CameraOutput, PTP_VENDOR_CANON, 0,  N_("Undefined")},
+		{PTP_DPC_CANON_CameraOutput, PTP_VENDOR_CANON, 1,  N_("LCD")},
+		{PTP_DPC_CANON_CameraOutput, PTP_VENDOR_CANON, 2,  N_("Video OUT")},
+		{PTP_DPC_CANON_CameraOutput, PTP_VENDOR_CANON, 3,  N_("Off")},
+
+		{PTP_DPC_CANON_MlSpotPos, PTP_VENDOR_CANON, 0, N_("MlSpotPosCenter")},
+		{PTP_DPC_CANON_MlSpotPos, PTP_VENDOR_CANON, 1, N_("MlSpotPosAfLink")},
+
+		{PTP_DPC_CANON_PhotoEffect, PTP_VENDOR_CANON, 0, N_("Off")},
+		{PTP_DPC_CANON_PhotoEffect, PTP_VENDOR_CANON, 1, N_("Vivid")},
+		{PTP_DPC_CANON_PhotoEffect, PTP_VENDOR_CANON, 2, N_("Neutral")},
+		{PTP_DPC_CANON_PhotoEffect, PTP_VENDOR_CANON, 3, N_("Soft")},
+		{PTP_DPC_CANON_PhotoEffect, PTP_VENDOR_CANON, 4, N_("Sepia")},
+		{PTP_DPC_CANON_PhotoEffect, PTP_VENDOR_CANON, 5, N_("Monochrome")},
+
+		{0, 0, 0, NULL}
+	};
+	for (i=0; ptp_value_trans[i].dpc!=0; i++) {
+		if ((ptp_value_trans[i].dpc == dpc) && 
+			(((ptp_value_trans[i].dpc & 0xf000) == 0x5000) ||
+		         (ptp_value_trans[i].vendor == params->deviceinfo.VendorExtensionID))
+		) {
+			double value = _value_to_num(&(dpd->CurrentValue), dpd->DataType);
+
+			return snprintf(out, length, 
+				_(ptp_value_trans[i].format),
+				value * ptp_value_trans[i].coef +
+				ptp_value_trans[i].bias);
+		}
+	}
+
+	kval = _value_to_num(&(dpd->CurrentValue), dpd->DataType);
+	for (i=0; ptp_value_list[i].dpc!=0; i++) {
+		if ((ptp_value_list[i].dpc == dpc) && 
+			(((ptp_value_list[i].dpc & 0xf000) == 0x5000) ||
+		          (ptp_value_list[i].vendor == params->deviceinfo.VendorExtensionID)) &&
+		    (ptp_value_list[i].key==kval)
+		) {
+			return snprintf(out, length, "%s", _(ptp_value_list[i].value));
+		}
+	}
+	if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_MICROSOFT
+	    || params->deviceinfo.VendorExtensionID==PTP_VENDOR_MTP) {
+		switch (dpc) {
+		case PTP_DPC_MTP_SynchronizationPartner:
+		case PTP_DPC_MTP_DeviceFriendlyName:
+			return snprintf(out, length, "%s", dpd->CurrentValue.str);
+		case PTP_DPC_MTP_SecureTime:
+		case PTP_DPC_MTP_DeviceCertificate: {
+			/* FIXME: Convert to use unicode demux functions */
+			for (i=0;(i<dpd->CurrentValue.a.count) && (i<length);i++)
+				out[i] = dpd->CurrentValue.a.v[i].u16;
+			if (	dpd->CurrentValue.a.count &&
+				(dpd->CurrentValue.a.count < length)) {
+				out[dpd->CurrentValue.a.count-1] = 0;
+				return dpd->CurrentValue.a.count-1;
+			} else {
+				out[length-1] = 0;
+				return length;
+			}
+			break;
+		}
+		default:
+			break;
+		}
+	}
+
+	return 0;
+}
+
+struct {
+	uint16_t ofc;
+	const char *format;
+} ptp_ofc_trans[] = {
+	{PTP_OFC_Undefined,"Undefined Type"},
+	{PTP_OFC_Defined,"Defined Type"},
+	{PTP_OFC_Association,"Association/Directory"},
+	{PTP_OFC_Script,"Script"},
+	{PTP_OFC_Executable,"Executable"},
+	{PTP_OFC_Text,"Text"},
+	{PTP_OFC_HTML,"HTML"},
+	{PTP_OFC_DPOF,"DPOF"},
+	{PTP_OFC_AIFF,"AIFF"},
+	{PTP_OFC_WAV,"MS Wave"},
+	{PTP_OFC_MP3,"MP3"},
+	{PTP_OFC_AVI,"MS AVI"},
+	{PTP_OFC_MPEG,"MPEG"},
+	{PTP_OFC_ASF,"ASF"},
+	{PTP_OFC_QT,"Apple Quicktime"},
+	{PTP_OFC_EXIF_JPEG,"JPEG"},
+	{PTP_OFC_TIFF_EP,"TIFF EP"},
+	{PTP_OFC_FlashPix,"FlashPix"},
+	{PTP_OFC_BMP,"BMP"},
+	{PTP_OFC_CIFF,"CIFF"},
+	{PTP_OFC_GIF,"GIF"},
+	{PTP_OFC_JFIF,"JFIF"},
+	{PTP_OFC_PCD,"PCD"},
+	{PTP_OFC_PICT,"PICT"},
+	{PTP_OFC_PNG,"PNG"},
+	{PTP_OFC_TIFF,"TIFF"},
+	{PTP_OFC_TIFF_IT,"TIFF_IT"},
+	{PTP_OFC_JP2,"JP2"},
+	{PTP_OFC_JPX,"JPX"},
+	{PTP_OFC_DNG,"DNG"},
+};
+
+struct {
+	uint16_t ofc;
+	const char *format;
+} ptp_ofc_mtp_trans[] = {
+	{PTP_OFC_MTP_MediaCard,N_("Media Card")},
+	{PTP_OFC_MTP_MediaCardGroup,N_("Media Card Group")},
+	{PTP_OFC_MTP_Encounter,N_("Encounter")},
+	{PTP_OFC_MTP_EncounterBox,N_("Encounter Box")},
+	{PTP_OFC_MTP_M4A,N_("M4A")},
+	{PTP_OFC_MTP_Firmware,N_("Firmware")},
+	{PTP_OFC_MTP_WindowsImageFormat,N_("Windows Image Format")},
+	{PTP_OFC_MTP_UndefinedAudio,N_("Undefined Audio")},
+	{PTP_OFC_MTP_WMA,"WMA"},
+	{PTP_OFC_MTP_OGG,"OGG"},
+	{PTP_OFC_MTP_AAC,"AAC"},
+	{PTP_OFC_MTP_AudibleCodec,N_("Audible.com Codec")},
+	{PTP_OFC_MTP_FLAC,"FLAC"},
+	{PTP_OFC_MTP_UndefinedVideo,N_("Undefined Video")},
+	{PTP_OFC_MTP_WMV,"WMV"},
+	{PTP_OFC_MTP_MP4,"MP4"},
+	{PTP_OFC_MTP_MP2,"MP2"},
+	{PTP_OFC_MTP_3GP,"3GP"},
+	{PTP_OFC_MTP_UndefinedCollection,N_("Undefined Collection")},
+	{PTP_OFC_MTP_AbstractMultimediaAlbum,N_("Abstract Multimedia Album")},
+	{PTP_OFC_MTP_AbstractImageAlbum,N_("Abstract Image Album")},
+	{PTP_OFC_MTP_AbstractAudioAlbum,N_("Abstract Audio Album")},
+	{PTP_OFC_MTP_AbstractVideoAlbum,N_("Abstract Video Album")},
+	{PTP_OFC_MTP_AbstractAudioVideoPlaylist,N_("Abstract Audio Video Playlist")},
+	{PTP_OFC_MTP_AbstractContactGroup,N_("Abstract Contact Group")},
+	{PTP_OFC_MTP_AbstractMessageFolder,N_("Abstract Message Folder")},
+	{PTP_OFC_MTP_AbstractChapteredProduction,N_("Abstract Chaptered Production")},
+	{PTP_OFC_MTP_AbstractAudioPlaylist,N_("Abstract Audio Playlist")},
+	{PTP_OFC_MTP_AbstractVideoPlaylist,N_("Abstract Video Playlist")},
+	{PTP_OFC_MTP_AbstractMediacast,N_("Abstract Mediacast")},
+	{PTP_OFC_MTP_WPLPlaylist,N_("WPL Playlist")},
+	{PTP_OFC_MTP_M3UPlaylist,N_("M3U Playlist")},
+	{PTP_OFC_MTP_MPLPlaylist,N_("MPL Playlist")},
+	{PTP_OFC_MTP_ASXPlaylist,N_("ASX Playlist")},
+	{PTP_OFC_MTP_PLSPlaylist,N_("PLS Playlist")},
+	{PTP_OFC_MTP_UndefinedDocument,N_("Undefined Document")},
+	{PTP_OFC_MTP_AbstractDocument,N_("Abstract Document")},
+	{PTP_OFC_MTP_XMLDocument,N_("XMLDocument")},
+	{PTP_OFC_MTP_MSWordDocument,N_("Microsoft Word Document")},
+	{PTP_OFC_MTP_MHTCompiledHTMLDocument,N_("MHT Compiled HTML Document")},
+	{PTP_OFC_MTP_MSExcelSpreadsheetXLS,N_("Microsoft Excel Spreadsheet (.xls)")},
+	{PTP_OFC_MTP_MSPowerpointPresentationPPT,N_("Microsoft Powerpoint (.ppt)")},
+	{PTP_OFC_MTP_UndefinedMessage,N_("Undefined Message")},
+	{PTP_OFC_MTP_AbstractMessage,N_("Abstract Message")},
+	{PTP_OFC_MTP_UndefinedContact,N_("Undefined Contact")},
+	{PTP_OFC_MTP_AbstractContact,N_("Abstract Contact")},
+	{PTP_OFC_MTP_vCard2,N_("vCard2")},
+	{PTP_OFC_MTP_vCard3,N_("vCard3")},
+	{PTP_OFC_MTP_UndefinedCalendarItem,N_("Undefined Calendar Item")},
+	{PTP_OFC_MTP_AbstractCalendarItem,N_("Abstract Calendar Item")},
+	{PTP_OFC_MTP_vCalendar1,N_("vCalendar1")},
+	{PTP_OFC_MTP_vCalendar2,N_("vCalendar2")},
+	{PTP_OFC_MTP_UndefinedWindowsExecutable,N_("Undefined Windows Executable")},
+	{PTP_OFC_MTP_MediaCast,N_("Media Cast")},
+	{PTP_OFC_MTP_Section,N_("Section")},
+};
+
+int
+ptp_render_ofc(PTPParams* params, uint16_t ofc, int spaceleft, char *txt)
+{
+	int i;
+	
+	if (!(ofc & 0x8000)) {
+		for (i=0;i<sizeof(ptp_ofc_trans)/sizeof(ptp_ofc_trans[0]);i++)
+			if (ofc == ptp_ofc_trans[i].ofc)
+				return snprintf(txt, spaceleft, "%s", _(ptp_ofc_trans[i].format));
+	} else {
+		switch (params->deviceinfo.VendorExtensionID) {
+		case PTP_VENDOR_EASTMAN_KODAK:
+			switch (ofc) {
+			case PTP_OFC_EK_M3U:
+				return snprintf (txt, spaceleft,"M3U");
+			default:
+				break;
+			}
+			break;
+		case PTP_VENDOR_CANON:
+			switch (ofc) {
+			case PTP_OFC_CANON_CRW:
+				return snprintf (txt, spaceleft,"CRW");
+			default:
+				break;
+			}
+			break;
+		case PTP_VENDOR_MICROSOFT:
+		case PTP_VENDOR_MTP:		  
+			for (i=0;i<sizeof(ptp_ofc_mtp_trans)/sizeof(ptp_ofc_mtp_trans[0]);i++)
+				if (ofc == ptp_ofc_mtp_trans[i].ofc)
+					return snprintf(txt, spaceleft, "%s", _(ptp_ofc_mtp_trans[i].format));
+			break;
+		default:break;
+		}
+	}
+	return snprintf (txt, spaceleft,_("Unknown(%04x)"), ofc);
+}
+
+struct {
+	uint16_t opcode;
+	const char *name;
+} ptp_opcode_trans[] = {
+	{PTP_OC_Undefined,N_("Undefined")},
+	{PTP_OC_GetDeviceInfo,N_("get device info")},
+	{PTP_OC_OpenSession,N_("Open session")},
+	{PTP_OC_CloseSession,N_("Close session")},
+	{PTP_OC_GetStorageIDs,N_("Get storage IDs")},
+	{PTP_OC_GetStorageInfo,N_("Get storage info")},
+	{PTP_OC_GetNumObjects,N_("Get number of objects")},
+	{PTP_OC_GetObjectHandles,N_("Get object handles")},
+	{PTP_OC_GetObjectInfo,N_("Get object info")},
+	{PTP_OC_GetObject,N_("Get object")},
+	{PTP_OC_GetThumb,N_("Get thumbnail")},
+	{PTP_OC_DeleteObject,N_("Delete object")},
+	{PTP_OC_SendObjectInfo,N_("Send object info")},
+	{PTP_OC_SendObject,N_("Send object")},
+	{PTP_OC_InitiateCapture,N_("Initiate capture")},
+	{PTP_OC_FormatStore,N_("Format storage")},
+	{PTP_OC_ResetDevice,N_("Reset device")},
+	{PTP_OC_SelfTest,N_("Self test device")},
+	{PTP_OC_SetObjectProtection,N_("Set object protection")},
+	{PTP_OC_PowerDown,N_("Power down device")},
+	{PTP_OC_GetDevicePropDesc,N_("Get device property description")},
+	{PTP_OC_GetDevicePropValue,N_("Get device property value")},
+	{PTP_OC_SetDevicePropValue,N_("Set device property value")},
+	{PTP_OC_ResetDevicePropValue,N_("Reset device property value")},
+	{PTP_OC_TerminateOpenCapture,N_("Terminate open capture")},
+	{PTP_OC_MoveObject,N_("Move object")},
+	{PTP_OC_CopyObject,N_("Copy object")},
+	{PTP_OC_GetPartialObject,N_("Get partial object")},
+	{PTP_OC_InitiateOpenCapture,N_("Initiate open capture")}
+};
+
+struct {
+	uint16_t opcode;
+	const char *name;
+} ptp_opcode_mtp_trans[] = {
+	{PTP_OC_MTP_GetObjectPropsSupported,N_("Get object properties supported")},
+	{PTP_OC_MTP_GetObjectPropDesc,N_("Get object property description")},
+	{PTP_OC_MTP_GetObjectPropValue,N_("Get object property value")},
+	{PTP_OC_MTP_SetObjectPropValue,N_("Set object property value")},
+	{PTP_OC_MTP_GetObjPropList,N_("Get object property list")},
+	{PTP_OC_MTP_SetObjPropList,N_("Set object property list")},
+	{PTP_OC_MTP_GetInterdependendPropdesc,N_("Get interdependent property description")},
+	{PTP_OC_MTP_SendObjectPropList,N_("Send object property list")},
+	{PTP_OC_MTP_GetObjectReferences,N_("Get object references")},
+	{PTP_OC_MTP_SetObjectReferences,N_("Set object references")},
+	{PTP_OC_MTP_UpdateDeviceFirmware,N_("Update device firmware")},
+	{PTP_OC_MTP_Skip,N_("Skip to next position in playlist")},
+
+	/* WMDRMPD Extensions */
+	{PTP_OC_MTP_WMDRMPD_GetSecureTimeChallenge,N_("Get secure time challenge")},
+	{PTP_OC_MTP_WMDRMPD_GetSecureTimeResponse,N_("Get secure time response")},
+	{PTP_OC_MTP_WMDRMPD_SetLicenseResponse,N_("Set license response")},
+	{PTP_OC_MTP_WMDRMPD_GetSyncList,N_("Get sync list")},
+	{PTP_OC_MTP_WMDRMPD_SendMeterChallengeQuery,N_("Send meter challenge query")},
+	{PTP_OC_MTP_WMDRMPD_GetMeterChallenge,N_("Get meter challenge")},
+	{PTP_OC_MTP_WMDRMPD_SetMeterResponse,N_("Get meter response")},
+	{PTP_OC_MTP_WMDRMPD_CleanDataStore,N_("Clean data store")},
+	{PTP_OC_MTP_WMDRMPD_GetLicenseState,N_("Get license state")},
+	{PTP_OC_MTP_WMDRMPD_SendWMDRMPDCommand,N_("Send WMDRM-PD Command")},
+	{PTP_OC_MTP_WMDRMPD_SendWMDRMPDRequest,N_("Send WMDRM-PD Request")},
+
+	/* WMPPD Extensions */
+	{PTP_OC_MTP_WMPPD_ReportAddedDeletedItems,N_("Report Added/Deleted Items")},
+	{PTP_OC_MTP_WMPPD_ReportAcquiredItems,N_("Report Acquired Items")},
+	{PTP_OC_MTP_WMPPD_PlaylistObjectPref,N_("Get transferable playlist types")},
+
+	/* WMDRMPD Extensions... these have no identifiers associated with them */
+	{PTP_OC_MTP_WMDRMPD_SendWMDRMPDAppRequest,N_("Send WMDRM-PD Application Request")},
+	{PTP_OC_MTP_WMDRMPD_GetWMDRMPDAppResponse,N_("Get WMDRM-PD Application Response")},
+	{PTP_OC_MTP_WMDRMPD_EnableTrustedFilesOperations,N_("Enable trusted file operations")},
+	{PTP_OC_MTP_WMDRMPD_DisableTrustedFilesOperations,N_("Disable trusted file operations")},
+	{PTP_OC_MTP_WMDRMPD_EndTrustedAppSession,N_("End trusted application session")},
+
+	/* AAVT Extensions */
+	{PTP_OC_MTP_AAVT_OpenMediaSession,N_("Open Media Session")},
+	{PTP_OC_MTP_AAVT_CloseMediaSession,N_("Close Media Session")},
+	{PTP_OC_MTP_AAVT_GetNextDataBlock,N_("Get Next Data Block")},
+	{PTP_OC_MTP_AAVT_SetCurrentTimePosition,N_("Set Current Time Position")},
+
+	/* WMDRMND Extensions */
+	{PTP_OC_MTP_WMDRMND_SendRegistrationRequest,N_("Send Registration Request")},
+	{PTP_OC_MTP_WMDRMND_GetRegistrationResponse,N_("Get Registration Response")},
+	{PTP_OC_MTP_WMDRMND_GetProximityChallenge,N_("Get Proximity Challenge")},
+	{PTP_OC_MTP_WMDRMND_SendProximityResponse,N_("Send Proximity Response")},
+	{PTP_OC_MTP_WMDRMND_SendWMDRMNDLicenseRequest,N_("Send WMDRM-ND License Request")},
+	{PTP_OC_MTP_WMDRMND_GetWMDRMNDLicenseResponse,N_("Get WMDRM-ND License Response")},
+
+	/* WiFi Provisioning MTP Extension Codes (microsoft.com/WPDWCN: 1.0) */
+	{PTP_OC_MTP_WPDWCN_ProcessWFCObject,N_("Process WFC Object")}
+};
+
+int
+ptp_render_opcode(PTPParams* params, uint16_t opcode, int spaceleft, char *txt)
+{
+	int i;
+
+	if (!(opcode & 0x8000)) {
+		for (i=0;i<sizeof(ptp_opcode_trans)/sizeof(ptp_opcode_trans[0]);i++)
+			if (opcode == ptp_opcode_trans[i].opcode)
+				return snprintf(txt, spaceleft, "%s", _(ptp_opcode_trans[i].name));
+	} else {
+		switch (params->deviceinfo.VendorExtensionID) {
+		case PTP_VENDOR_MICROSOFT:
+		case PTP_VENDOR_MTP:
+			for (i=0;i<sizeof(ptp_opcode_mtp_trans)/sizeof(ptp_opcode_mtp_trans[0]);i++)
+				if (opcode == ptp_opcode_mtp_trans[i].opcode)
+					return snprintf(txt, spaceleft, "%s", _(ptp_opcode_mtp_trans[i].name));
+			break;
+		default:break;
+		}
+	}
+	return snprintf (txt, spaceleft,_("Unknown (%04x)"), opcode);
+}
+
+
+struct {
+	uint16_t id;
+	const char *name;
+} ptp_opc_trans[] = {
+	{PTP_OPC_StorageID,"StorageID"},
+	{PTP_OPC_ObjectFormat,"ObjectFormat"},
+	{PTP_OPC_ProtectionStatus,"ProtectionStatus"},
+	{PTP_OPC_ObjectSize,"ObjectSize"},
+	{PTP_OPC_AssociationType,"AssociationType"},
+	{PTP_OPC_AssociationDesc,"AssociationDesc"},
+	{PTP_OPC_ObjectFileName,"ObjectFileName"},
+	{PTP_OPC_DateCreated,"DateCreated"},
+	{PTP_OPC_DateModified,"DateModified"},
+	{PTP_OPC_Keywords,"Keywords"},
+	{PTP_OPC_ParentObject,"ParentObject"},
+	{PTP_OPC_AllowedFolderContents,"AllowedFolderContents"},
+	{PTP_OPC_Hidden,"Hidden"},
+	{PTP_OPC_SystemObject,"SystemObject"},
+	{PTP_OPC_PersistantUniqueObjectIdentifier,"PersistantUniqueObjectIdentifier"},
+	{PTP_OPC_SyncID,"SyncID"},
+	{PTP_OPC_PropertyBag,"PropertyBag"},
+	{PTP_OPC_Name,"Name"},
+	{PTP_OPC_CreatedBy,"CreatedBy"},
+	{PTP_OPC_Artist,"Artist"},
+	{PTP_OPC_DateAuthored,"DateAuthored"},
+	{PTP_OPC_Description,"Description"},
+	{PTP_OPC_URLReference,"URLReference"},
+	{PTP_OPC_LanguageLocale,"LanguageLocale"},
+	{PTP_OPC_CopyrightInformation,"CopyrightInformation"},
+	{PTP_OPC_Source,"Source"},
+	{PTP_OPC_OriginLocation,"OriginLocation"},
+	{PTP_OPC_DateAdded,"DateAdded"},
+	{PTP_OPC_NonConsumable,"NonConsumable"},
+	{PTP_OPC_CorruptOrUnplayable,"CorruptOrUnplayable"},
+	{PTP_OPC_ProducerSerialNumber,"ProducerSerialNumber"},
+	{PTP_OPC_RepresentativeSampleFormat,"RepresentativeSampleFormat"},
+	{PTP_OPC_RepresentativeSampleSize,"RepresentativeSampleSize"},
+	{PTP_OPC_RepresentativeSampleHeight,"RepresentativeSampleHeight"},
+	{PTP_OPC_RepresentativeSampleWidth,"RepresentativeSampleWidth"},
+	{PTP_OPC_RepresentativeSampleDuration,"RepresentativeSampleDuration"},
+	{PTP_OPC_RepresentativeSampleData,"RepresentativeSampleData"},
+	{PTP_OPC_Width,"Width"},
+	{PTP_OPC_Height,"Height"},
+	{PTP_OPC_Duration,"Duration"},
+	{PTP_OPC_Rating,"Rating"},
+	{PTP_OPC_Track,"Track"},
+	{PTP_OPC_Genre,"Genre"},
+	{PTP_OPC_Credits,"Credits"},
+	{PTP_OPC_Lyrics,"Lyrics"},
+	{PTP_OPC_SubscriptionContentID,"SubscriptionContentID"},
+	{PTP_OPC_ProducedBy,"ProducedBy"},
+	{PTP_OPC_UseCount,"UseCount"},
+	{PTP_OPC_SkipCount,"SkipCount"},
+	{PTP_OPC_LastAccessed,"LastAccessed"},
+	{PTP_OPC_ParentalRating,"ParentalRating"},
+	{PTP_OPC_MetaGenre,"MetaGenre"},
+	{PTP_OPC_Composer,"Composer"},
+	{PTP_OPC_EffectiveRating,"EffectiveRating"},
+	{PTP_OPC_Subtitle,"Subtitle"},
+	{PTP_OPC_OriginalReleaseDate,"OriginalReleaseDate"},
+	{PTP_OPC_AlbumName,"AlbumName"},
+	{PTP_OPC_AlbumArtist,"AlbumArtist"},
+	{PTP_OPC_Mood,"Mood"},
+	{PTP_OPC_DRMStatus,"DRMStatus"},
+	{PTP_OPC_SubDescription,"SubDescription"},
+	{PTP_OPC_IsCropped,"IsCropped"},
+	{PTP_OPC_IsColorCorrected,"IsColorCorrected"},
+	{PTP_OPC_ImageBitDepth,"ImageBitDepth"},
+	{PTP_OPC_Fnumber,"Fnumber"},
+	{PTP_OPC_ExposureTime,"ExposureTime"},
+	{PTP_OPC_ExposureIndex,"ExposureIndex"},
+	{PTP_OPC_DisplayName,"DisplayName"},
+	{PTP_OPC_BodyText,"BodyText"},
+	{PTP_OPC_Subject,"Subject"},
+	{PTP_OPC_Priority,"Priority"},
+	{PTP_OPC_GivenName,"GivenName"},
+	{PTP_OPC_MiddleNames,"MiddleNames"},
+	{PTP_OPC_FamilyName,"FamilyName"},
+
+	{PTP_OPC_Prefix,"Prefix"},
+	{PTP_OPC_Suffix,"Suffix"},
+	{PTP_OPC_PhoneticGivenName,"PhoneticGivenName"},
+	{PTP_OPC_PhoneticFamilyName,"PhoneticFamilyName"},
+	{PTP_OPC_EmailPrimary,"EmailPrimary"},
+	{PTP_OPC_EmailPersonal1,"EmailPersonal1"},
+	{PTP_OPC_EmailPersonal2,"EmailPersonal2"},
+	{PTP_OPC_EmailBusiness1,"EmailBusiness1"},
+	{PTP_OPC_EmailBusiness2,"EmailBusiness2"},
+	{PTP_OPC_EmailOthers,"EmailOthers"},
+	{PTP_OPC_PhoneNumberPrimary,"PhoneNumberPrimary"},
+	{PTP_OPC_PhoneNumberPersonal,"PhoneNumberPersonal"},
+	{PTP_OPC_PhoneNumberPersonal2,"PhoneNumberPersonal2"},
+	{PTP_OPC_PhoneNumberBusiness,"PhoneNumberBusiness"},
+	{PTP_OPC_PhoneNumberBusiness2,"PhoneNumberBusiness2"},
+	{PTP_OPC_PhoneNumberMobile,"PhoneNumberMobile"},
+	{PTP_OPC_PhoneNumberMobile2,"PhoneNumberMobile2"},
+	{PTP_OPC_FaxNumberPrimary,"FaxNumberPrimary"},
+	{PTP_OPC_FaxNumberPersonal,"FaxNumberPersonal"},
+	{PTP_OPC_FaxNumberBusiness,"FaxNumberBusiness"},
+	{PTP_OPC_PagerNumber,"PagerNumber"},
+	{PTP_OPC_PhoneNumberOthers,"PhoneNumberOthers"},
+	{PTP_OPC_PrimaryWebAddress,"PrimaryWebAddress"},
+	{PTP_OPC_PersonalWebAddress,"PersonalWebAddress"},
+	{PTP_OPC_BusinessWebAddress,"BusinessWebAddress"},
+	{PTP_OPC_InstantMessengerAddress,"InstantMessengerAddress"},
+	{PTP_OPC_InstantMessengerAddress2,"InstantMessengerAddress2"},
+	{PTP_OPC_InstantMessengerAddress3,"InstantMessengerAddress3"},
+	{PTP_OPC_PostalAddressPersonalFull,"PostalAddressPersonalFull"},
+	{PTP_OPC_PostalAddressPersonalFullLine1,"PostalAddressPersonalFullLine1"},
+	{PTP_OPC_PostalAddressPersonalFullLine2,"PostalAddressPersonalFullLine2"},
+	{PTP_OPC_PostalAddressPersonalFullCity,"PostalAddressPersonalFullCity"},
+	{PTP_OPC_PostalAddressPersonalFullRegion,"PostalAddressPersonalFullRegion"},
+	{PTP_OPC_PostalAddressPersonalFullPostalCode,"PostalAddressPersonalFullPostalCode"},
+	{PTP_OPC_PostalAddressPersonalFullCountry,"PostalAddressPersonalFullCountry"},
+	{PTP_OPC_PostalAddressBusinessFull,"PostalAddressBusinessFull"},
+	{PTP_OPC_PostalAddressBusinessLine1,"PostalAddressBusinessLine1"},
+	{PTP_OPC_PostalAddressBusinessLine2,"PostalAddressBusinessLine2"},
+	{PTP_OPC_PostalAddressBusinessCity,"PostalAddressBusinessCity"},
+	{PTP_OPC_PostalAddressBusinessRegion,"PostalAddressBusinessRegion"},
+	{PTP_OPC_PostalAddressBusinessPostalCode,"PostalAddressBusinessPostalCode"},
+	{PTP_OPC_PostalAddressBusinessCountry,"PostalAddressBusinessCountry"},
+	{PTP_OPC_PostalAddressOtherFull,"PostalAddressOtherFull"},
+	{PTP_OPC_PostalAddressOtherLine1,"PostalAddressOtherLine1"},
+	{PTP_OPC_PostalAddressOtherLine2,"PostalAddressOtherLine2"},
+	{PTP_OPC_PostalAddressOtherCity,"PostalAddressOtherCity"},
+	{PTP_OPC_PostalAddressOtherRegion,"PostalAddressOtherRegion"},
+	{PTP_OPC_PostalAddressOtherPostalCode,"PostalAddressOtherPostalCode"},
+	{PTP_OPC_PostalAddressOtherCountry,"PostalAddressOtherCountry"},
+	{PTP_OPC_OrganizationName,"OrganizationName"},
+	{PTP_OPC_PhoneticOrganizationName,"PhoneticOrganizationName"},
+	{PTP_OPC_Role,"Role"},
+	{PTP_OPC_Birthdate,"Birthdate"},
+	{PTP_OPC_MessageTo,"MessageTo"},
+	{PTP_OPC_MessageCC,"MessageCC"},
+	{PTP_OPC_MessageBCC,"MessageBCC"},
+	{PTP_OPC_MessageRead,"MessageRead"},
+	{PTP_OPC_MessageReceivedTime,"MessageReceivedTime"},
+	{PTP_OPC_MessageSender,"MessageSender"},
+	{PTP_OPC_ActivityBeginTime,"ActivityBeginTime"},
+	{PTP_OPC_ActivityEndTime,"ActivityEndTime"},
+	{PTP_OPC_ActivityLocation,"ActivityLocation"},
+	{PTP_OPC_ActivityRequiredAttendees,"ActivityRequiredAttendees"},
+	{PTP_OPC_ActivityOptionalAttendees,"ActivityOptionalAttendees"},
+	{PTP_OPC_ActivityResources,"ActivityResources"},
+	{PTP_OPC_ActivityAccepted,"ActivityAccepted"},
+	{PTP_OPC_Owner,"Owner"},
+	{PTP_OPC_Editor,"Editor"},
+	{PTP_OPC_Webmaster,"Webmaster"},
+	{PTP_OPC_URLSource,"URLSource"},
+	{PTP_OPC_URLDestination,"URLDestination"},
+	{PTP_OPC_TimeBookmark,"TimeBookmark"},
+	{PTP_OPC_ObjectBookmark,"ObjectBookmark"},
+	{PTP_OPC_ByteBookmark,"ByteBookmark"},
+	{PTP_OPC_LastBuildDate,"LastBuildDate"},
+	{PTP_OPC_TimetoLive,"TimetoLive"},
+	{PTP_OPC_MediaGUID,"MediaGUID"},
+	{PTP_OPC_TotalBitRate,"TotalBitRate"},
+	{PTP_OPC_BitRateType,"BitRateType"},
+	{PTP_OPC_SampleRate,"SampleRate"},
+	{PTP_OPC_NumberOfChannels,"NumberOfChannels"},
+	{PTP_OPC_AudioBitDepth,"AudioBitDepth"},
+	{PTP_OPC_ScanDepth,"ScanDepth"},
+	{PTP_OPC_AudioWAVECodec,"AudioWAVECodec"},
+	{PTP_OPC_AudioBitRate,"AudioBitRate"},
+	{PTP_OPC_VideoFourCCCodec,"VideoFourCCCodec"},
+	{PTP_OPC_VideoBitRate,"VideoBitRate"},
+	{PTP_OPC_FramesPerThousandSeconds,"FramesPerThousandSeconds"},
+	{PTP_OPC_KeyFrameDistance,"KeyFrameDistance"},
+	{PTP_OPC_BufferSize,"BufferSize"},
+	{PTP_OPC_EncodingQuality,"EncodingQuality"},
+	{PTP_OPC_EncodingProfile,"EncodingProfile"},
+	{PTP_OPC_BuyFlag,"BuyFlag"},
+};
+
+int
+ptp_render_mtp_propname(uint16_t propid, int spaceleft, char *txt) {
+	int i;
+	for (i=0;i<sizeof(ptp_opc_trans)/sizeof(ptp_opc_trans[0]);i++)
+		if (propid == ptp_opc_trans[i].id)
+			return snprintf(txt, spaceleft, "%s", ptp_opc_trans[i].name);
+	return snprintf (txt, spaceleft,"unknown(%04x)", propid);
+}
+
+/*
+ * Allocate and default-initialize a few object properties.
+ */
+MTPProperties *
+ptp_get_new_object_prop_entry(MTPProperties **props, int *nrofprops) {
+	MTPProperties *newprops;
+	MTPProperties *prop;
+
+	if (*props == NULL) {
+		newprops = malloc(sizeof(MTPProperties)*(*nrofprops+1));
+	} else {
+		newprops = realloc(*props,sizeof(MTPProperties)*(*nrofprops+1));
+	}
+	if (newprops == NULL)
+		return NULL;
+	prop = &newprops[*nrofprops];
+	prop->property = PTP_OPC_StorageID; /* Should be "unknown" */
+	prop->datatype = PTP_DTC_UNDEF;
+	prop->ObjectHandle = 0x00000000U;
+	prop->propval.str = NULL;
+	
+	(*props) = newprops;
+	(*nrofprops)++;
+	return prop;
+}
+
+void 
+ptp_destroy_object_prop(MTPProperties *prop)
+{
+  if (!prop)
+    return;
+  
+  if (prop->datatype == PTP_DTC_STR && prop->propval.str != NULL)
+    free(prop->propval.str);
+  else if ((prop->datatype == PTP_DTC_AINT8 || prop->datatype == PTP_DTC_AINT16 ||
+            prop->datatype == PTP_DTC_AINT32 || prop->datatype == PTP_DTC_AINT64 || prop->datatype == PTP_DTC_AINT128 ||
+            prop->datatype == PTP_DTC_AUINT8 || prop->datatype == PTP_DTC_AUINT16 ||
+            prop->datatype == PTP_DTC_AUINT32 || prop->datatype == PTP_DTC_AUINT64 || prop->datatype ==  PTP_DTC_AUINT128)
+            && prop->propval.a.v != NULL)
+    free(prop->propval.a.v);
+}
+
+void 
+ptp_destroy_object_prop_list(MTPProperties *props, int nrofprops)
+{
+  int i;
+  MTPProperties *prop = props;
+
+  for (i=0;i<nrofprops;i++,prop++)
+    ptp_destroy_object_prop(prop);
+  free(props);
+}
+
+/*
+ * Find a certain object property in the cache, i.e. a certain metadata
+ * item for a certain object handle.
+ */
+MTPProperties *
+ptp_find_object_prop_in_cache(PTPParams *params, uint32_t const handle, uint32_t const attribute_id)
+{
+	int	i;
+	MTPProperties	*prop;
+	PTPObject	*ob;
+	uint16_t	ret;
+
+	ret = ptp_object_find (params, handle, &ob);
+	if (ret != PTP_RC_OK)
+		return NULL;
+	prop = ob->mtpprops;
+	for (i=0;i<ob->nrofmtpprops;i++) {
+		if (attribute_id == prop->property)
+			return prop;
+		prop++;
+	}
+	return NULL;
+}
+
+void
+ptp_remove_object_from_cache(PTPParams *params, uint32_t handle)
+{
+	int i;
+	PTPObject	*ob;
+	uint16_t	ret;
+
+	ret = ptp_object_find (params, handle, &ob);
+	if (ret != PTP_RC_OK)
+		return;
+	i = ob-params->objects;
+	/* remove object from object info cache */
+	ptp_free_object (ob);
+
+	if (i < params->nrofobjects-1)
+		memmove (ob,ob+1,(params->nrofobjects-1-i)*sizeof(PTPObject));
+	params->nrofobjects--;
+	/* We use less memory than before so this shouldn't fail */
+	params->objects = realloc(params->objects, sizeof(PTPObject)*params->nrofobjects);
+}
+
+static int _cmp_ob (const void *a, const void *b) {
+	PTPObject *oa = (PTPObject*)a;
+	PTPObject *ob = (PTPObject*)b;
+
+	return oa->oid - ob->oid;
+}
+	
+void
+ptp_objects_sort (PTPParams *params) {
+	qsort (params->objects, params->nrofobjects, sizeof(PTPObject), _cmp_ob);
+}
+
+/* Binary search in objects. Needs "objects" to be a sorted by objectid list!  */
+uint16_t
+ptp_object_find (PTPParams *params, uint32_t handle, PTPObject **retob) {
+	PTPObject	tmpob;
+
+	tmpob.oid = handle;
+	*retob = bsearch (&tmpob, params->objects, params->nrofobjects, sizeof(tmpob), _cmp_ob);
+	if (!*retob)
+		return PTP_RC_GeneralError;
+	return PTP_RC_OK;
+}
+
+/* Binary search in objects + insert of not found. Needs "objects" to be a sorted by objectid list!  */
+uint16_t
+ptp_object_find_or_insert (PTPParams *params, uint32_t handle, PTPObject **retob) {
+	int 		begin, end, cursor;
+	int		insertat;
+	PTPObject	*newobs;
+
+	if (!handle) return PTP_RC_GeneralError;
+	*retob = NULL;
+	if (!params->nrofobjects) {
+		params->objects = calloc(1,sizeof(PTPObject));
+		params->nrofobjects = 1;
+		params->objects[0].oid = handle;
+		*retob = &params->objects[0];
+		return PTP_RC_OK;
+	}
+	begin = 0;
+	end = params->nrofobjects-1;
+	/*ptp_debug (params, "searching %08x, total=%d", handle, params->nrofobjects);*/
+	while (1) {
+		cursor = (end-begin)/2+begin;
+		/*ptp_debug (params, "ob %d: %08x [%d-%d]", cursor, params->objects[cursor].oid, begin, end);*/
+		if (params->objects[cursor].oid == handle) {
+			*retob = &params->objects[cursor];
+			return PTP_RC_OK;
+		}
+		if (params->objects[cursor].oid < handle)
+			begin = cursor;
+		else
+			end = cursor;
+		if ((end - begin) <= 1)
+			break;
+	}
+	if (params->objects[begin].oid == handle) {
+		*retob = &params->objects[begin];
+		return PTP_RC_OK;
+	}
+	if (params->objects[end].oid == handle) {
+		*retob = &params->objects[end];
+		return PTP_RC_OK;
+	}
+	if ((begin == 0) && (handle < params->objects[0].oid)) {
+		insertat=begin;
+	} else {
+		if ((end == params->nrofobjects-1) && (handle > params->objects[end].oid))
+			insertat=end+1;
+		else
+			insertat=begin+1;
+	}
+	/*ptp_debug (params, "inserting oid %x at [%x,%x], begin=%d, end=%d, insertat=%d\n", handle, params->objects[begin].oid, params->objects[end].oid, begin, end, insertat);*/
+	newobs = realloc (params->objects, sizeof(PTPObject)*(params->nrofobjects+1));
+	if (!newobs) return PTP_RC_GeneralError;
+	params->objects = newobs;
+	if (insertat<=params->nrofobjects)
+		memmove (&params->objects[insertat+1],&params->objects[insertat],(params->nrofobjects-insertat)*sizeof(PTPObject));
+	memset(&params->objects[insertat],0,sizeof(PTPObject));
+	params->objects[insertat].oid = handle;
+	*retob = &params->objects[insertat];
+	params->nrofobjects++;
+	return PTP_RC_OK;
+}
+
+uint16_t
+ptp_object_want (PTPParams *params, uint32_t handle, int want, PTPObject **retob) {
+	uint16_t	ret;
+	PTPObject	*ob;
+	//Camera 		*camera = ((PTPData *)params->data)->camera;
+
+	*retob = NULL;
+	if (!handle) {
+		ptp_debug (params, "ptp_object_want: querying handle 0?\n");
+		return PTP_RC_GeneralError;
+	}
+	ret = ptp_object_find_or_insert (params, handle, &ob);
+	if (ret != PTP_RC_OK)
+		return PTP_RC_GeneralError;
+	*retob = ob;
+	/* Do we have all of it already? */
+	if ((ob->flags & want) == want)
+		return PTP_RC_OK;
+
+#define X (PTPOBJECT_OBJECTINFO_LOADED|PTPOBJECT_STORAGEID_LOADED|PTPOBJECT_PARENTOBJECT_LOADED)
+	if ((want & X) && ((ob->flags & X) != X)) {
+		uint32_t	saveparent = 0;
+		
+		/* One EOS issue, where getobjecthandles(root) returns obs without root flag. */
+		if (ob->flags & PTPOBJECT_PARENTOBJECT_LOADED)
+			saveparent = ob->oi.ParentObject;
+
+		ret = ptp_getobjectinfo (params, handle, &ob->oi);
+		if (ret != PTP_RC_OK)
+			return ret;
+		if (!ob->oi.Filename) ob->oi.Filename=strdup("<none>");
+		if (ob->flags & PTPOBJECT_PARENTOBJECT_LOADED)
+			ob->oi.ParentObject = saveparent;
+
+		/* Second EOS issue, 0x20000000 has 0x20000000 as parent */
+		if (ob->oi.ParentObject == handle)
+			ob->oi.ParentObject = 0;
+		ob->flags |= X;
+
+		/* EOS bug, DCIM links back to itself. */
+	}
+#undef X
+	if (	(want & PTPOBJECT_MTPPROPLIST_LOADED) &&
+		(!(ob->flags & PTPOBJECT_MTPPROPLIST_LOADED))
+	) {
+		int		nrofprops = 0;
+		MTPProperties 	*props = NULL;
+
+		if (params->device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST) {
+			want &= ~PTPOBJECT_MTPPROPLIST_LOADED;
+			goto fallback;
+		}
+
+		/* Microsoft/MTP has fast directory retrieval. */
+		if (!ptp_operation_issupported(params,PTP_OC_MTP_GetObjPropList)) {
+			want &= ~PTPOBJECT_MTPPROPLIST_LOADED;
+			goto fallback;
+		}
+
+		ptp_debug (params, "ptp2/mtpfast: reading mtp proplist of %08x", handle);
+		ret = ptp_mtp_getobjectproplist (params, handle, &props, &nrofprops);
+		if (ret != PTP_RC_OK)
+			goto fallback;
+		ob->mtpprops = props;
+		ob->nrofmtpprops = nrofprops;
+
+#if 0
+		MTPProperties 	*xpl;
+		int j;
+		PTPObjectInfo	oinfo;	
+
+		memset (&oinfo,0,sizeof(oinfo));
+		/* hmm, not necessary ... only if we would use it */
+		for (j=0;j<nrofprops;j++) {
+			xpl = &props[j];
+			switch (xpl->property) {
+			case PTP_OPC_ParentObject:
+				if (xpl->datatype != PTP_DTC_UINT32) {
+					ptp_debug (params, "ptp2/mtpfast: parentobject has type 0x%x???", xpl->datatype);
+					break;
+				}
+				oinfo.ParentObject = xpl->propval.u32;
+				ptp_debug (params, "ptp2/mtpfast: parent 0x%x", xpl->propval.u32);
+				break;
+			case PTP_OPC_ObjectFormat:
+				if (xpl->datatype != PTP_DTC_UINT16) {
+					ptp_debug (params, "ptp2/mtpfast: objectformat has type 0x%x???", xpl->datatype);
+					break;
+				}
+				oinfo.ObjectFormat = xpl->propval.u16;
+				ptp_debug (params, "ptp2/mtpfast: ofc 0x%x", xpl->propval.u16);
+				break;
+			case PTP_OPC_ObjectSize:
+				switch (xpl->datatype) {
+				case PTP_DTC_UINT32:
+					oinfo.ObjectCompressedSize = xpl->propval.u32;
+					break;
+				case PTP_DTC_UINT64:
+					oinfo.ObjectCompressedSize = xpl->propval.u64;
+					break;
+				default:
+					ptp_debug (params, "ptp2/mtpfast: objectsize has type 0x%x???", xpl->datatype);
+					break;
+				}
+				ptp_debug (params, "ptp2/mtpfast: objectsize %u", xpl->propval.u32);
+				break;
+			case PTP_OPC_StorageID:
+				if (xpl->datatype != PTP_DTC_UINT32) {
+					ptp_debug (params, "ptp2/mtpfast: storageid has type 0x%x???", xpl->datatype);
+					break;
+				}
+				oinfo.StorageID = xpl->propval.u32;
+				ptp_debug (params, "ptp2/mtpfast: storageid 0x%x", xpl->propval.u32);
+				break;
+			case PTP_OPC_ProtectionStatus:/*UINT16*/
+				if (xpl->datatype != PTP_DTC_UINT16) {
+					ptp_debug (params, "ptp2/mtpfast: protectionstatus has type 0x%x???", xpl->datatype);
+					break;
+				}
+				oinfo.ProtectionStatus = xpl->propval.u16;
+				ptp_debug (params, "ptp2/mtpfast: protection 0x%x", xpl->propval.u16);
+				break;
+			case PTP_OPC_ObjectFileName:
+				if (xpl->datatype != PTP_DTC_STR) {
+					ptp_debug (params, "ptp2/mtpfast: filename has type 0x%x???", xpl->datatype);
+					break;
+				}
+				if (xpl->propval.str) {
+					ptp_debug (params, "ptp2/mtpfast: filename %s", xpl->propval.str);
+					oinfo.Filename = strdup(xpl->propval.str);
+				} else {
+					oinfo.Filename = NULL;
+				}
+				break;
+			case PTP_OPC_DateCreated:
+				if (xpl->datatype != PTP_DTC_STR) {
+					ptp_debug (params, "ptp2/mtpfast: datecreated has type 0x%x???", xpl->datatype);
+					break;
+				}
+				ptp_debug (params, "ptp2/mtpfast: capturedate %s", xpl->propval.str);
+				oinfo.CaptureDate = ptp_unpack_PTPTIME (xpl->propval.str);
+				break;
+			case PTP_OPC_DateModified:
+				if (xpl->datatype != PTP_DTC_STR) {
+					ptp_debug (params, "ptp2/mtpfast: datemodified has type 0x%x???", xpl->datatype);
+					break;
+				}
+				ptp_debug (params, "ptp2/mtpfast: moddate %s", xpl->propval.str);
+				oinfo.ModificationDate = ptp_unpack_PTPTIME (xpl->propval.str);
+				break;
+			default:
+				if ((xpl->property & 0xfff0) == 0xdc00)
+					ptp_debug (params, "ptp2/mtpfast:case %x type %x unhandled", xpl->property, xpl->datatype);
+				break;
+			}
+		}
+		if (!oinfo.Filename)
+			/* i have one such file on my Creative */
+			oinfo.Filename = strdup("<null>");
+#endif
+		ob->flags |= PTPOBJECT_MTPPROPLIST_LOADED;
+fallback:	;
+	}
+	if ((ob->flags & want) == want)
+		return PTP_RC_OK;
+	ptp_debug (params, "ptp_object_want: oid 0x%08x, want flags %x, have only %x?", handle, want, ob->flags);
+	return PTP_RC_GeneralError;
+}
+
+
+uint16_t
+ptp_add_object_to_cache(PTPParams *params, uint32_t handle)
+{
+	PTPObject *ob;
+	return ptp_object_want (params, handle, PTPOBJECT_OBJECTINFO_LOADED|PTPOBJECT_MTPPROPLIST_LOADED, &ob);
+}
diff --git a/src/ptp.h b/src/ptp.h
new file mode 100644
index 0000000..a558ff5
--- /dev/null
+++ b/src/ptp.h
@@ -0,0 +1,2572 @@
+/* ptp.h
+ *
+ * Copyright (C) 2001 Mariusz Woloszyn <emsi@ipartners.pl>
+ * Copyright (C) 2003-2009 Marcus Meissner <marcus@jet.franken.de>
+ * Copyright (C) 2006-2008 Linus Walleij <triad@df.lth.se>
+ *
+ * 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.
+ */
+
+#ifndef __PTP_H__
+#define __PTP_H__
+
+#include <stdarg.h>
+#include <time.h>
+#ifdef HAVE_ICONV
+#include <iconv.h>
+#endif
+#include "gphoto2-endian.h"
+#include "device-flags.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* PTP datalayer byteorder */
+
+#define PTP_DL_BE			0xF0
+#define	PTP_DL_LE			0x0F
+
+/* USB interface class */
+#ifndef USB_CLASS_PTP
+#define USB_CLASS_PTP			6
+#endif
+
+/* PTP request/response/event general PTP container (transport independent) */
+
+struct _PTPContainer {
+	uint16_t Code;
+	uint32_t SessionID;
+	uint32_t Transaction_ID;
+	/* params  may be of any type of size less or equal to uint32_t */
+	uint32_t Param1;
+	uint32_t Param2;
+	uint32_t Param3;
+	/* events can only have three parameters */
+	uint32_t Param4;
+	uint32_t Param5;
+	/* the number of meaningfull parameters */
+	uint8_t	 Nparam;
+};
+typedef struct _PTPContainer PTPContainer;
+
+/* PTP USB Bulk-Pipe container */
+/* USB bulk max packet length for high speed endpoints */
+/* The max packet is set to 512 bytes. The spec says
+ * "end of data transfers are signaled by short packets or NULL
+ * packets". It never says anything about 512, but current
+ * implementations seem to have chosen this value, which also
+ * happens to be the size of an USB 2.0 HS endpoint, even though
+ * this is not necessary.
+ *
+ * Previously we had this as 4096 for MTP devices. We have found
+ * and fixed the bugs that made this necessary and it can be 512 again.
+ */
+#define PTP_USB_BULK_HS_MAX_PACKET_LEN_WRITE	512
+#define PTP_USB_BULK_HS_MAX_PACKET_LEN_READ   512
+#define PTP_USB_BULK_HDR_LEN		(2*sizeof(uint32_t)+2*sizeof(uint16_t))
+#define PTP_USB_BULK_PAYLOAD_LEN_WRITE	(PTP_USB_BULK_HS_MAX_PACKET_LEN_WRITE-PTP_USB_BULK_HDR_LEN)
+#define PTP_USB_BULK_PAYLOAD_LEN_READ	(PTP_USB_BULK_HS_MAX_PACKET_LEN_READ-PTP_USB_BULK_HDR_LEN)
+#define PTP_USB_BULK_REQ_LEN	(PTP_USB_BULK_HDR_LEN+5*sizeof(uint32_t))
+
+struct _PTPUSBBulkContainer {
+	uint32_t length;
+	uint16_t type;
+	uint16_t code;
+	uint32_t trans_id;
+	union {
+		struct {
+			uint32_t param1;
+			uint32_t param2;
+			uint32_t param3;
+			uint32_t param4;
+			uint32_t param5;
+		} params;
+       /* this must be set to the maximum of PTP_USB_BULK_PAYLOAD_LEN_WRITE 
+        * and PTP_USB_BULK_PAYLOAD_LEN_READ */
+		unsigned char data[PTP_USB_BULK_PAYLOAD_LEN_READ];
+	} payload;
+};
+typedef struct _PTPUSBBulkContainer PTPUSBBulkContainer;
+
+/* PTP USB Asynchronous Event Interrupt Data Format */
+struct _PTPUSBEventContainer {
+	uint32_t length;
+	uint16_t type;
+	uint16_t code;
+	uint32_t trans_id;
+	uint32_t param1;
+	uint32_t param2;
+	uint32_t param3;
+};
+typedef struct _PTPUSBEventContainer PTPUSBEventContainer;
+
+struct _PTPCanon_directtransfer_entry {
+	uint32_t	oid;
+	char		*str;
+};
+typedef struct _PTPCanon_directtransfer_entry PTPCanon_directtransfer_entry;
+
+/* USB container types */
+
+#define PTP_USB_CONTAINER_UNDEFINED		0x0000
+#define PTP_USB_CONTAINER_COMMAND		0x0001
+#define PTP_USB_CONTAINER_DATA			0x0002
+#define PTP_USB_CONTAINER_RESPONSE		0x0003
+#define PTP_USB_CONTAINER_EVENT			0x0004
+
+/* PTP/IP definitions */
+#define PTPIP_INIT_COMMAND_REQUEST	1
+#define PTPIP_INIT_COMMAND_ACK		2
+#define PTPIP_INIT_EVENT_REQUEST	3
+#define PTPIP_INIT_EVENT_ACK		4
+#define PTPIP_INIT_FAIL			5
+#define PTPIP_CMD_REQUEST		6
+#define PTPIP_CMD_RESPONSE		7
+#define PTPIP_EVENT			8
+#define PTPIP_START_DATA_PACKET		9
+#define PTPIP_DATA_PACKET		10
+#define PTPIP_CANCEL_TRANSACTION	11
+#define PTPIP_END_DATA_PACKET		12
+#define PTPIP_PING			13
+#define PTPIP_PONG			14
+
+struct _PTPIPHeader {
+	uint32_t	length;
+	uint32_t	type;
+};
+typedef struct _PTPIPHeader PTPIPHeader;
+
+/* Vendor IDs */
+#define PTP_VENDOR_EASTMAN_KODAK	0x00000001
+#define PTP_VENDOR_SEIKO_EPSON		0x00000002
+#define PTP_VENDOR_AGILENT		0x00000003
+#define PTP_VENDOR_POLAROID		0x00000004
+#define PTP_VENDOR_AGFA_GEVAERT		0x00000005
+#define PTP_VENDOR_MICROSOFT		0x00000006
+#define PTP_VENDOR_EQUINOX		0x00000007
+#define PTP_VENDOR_VIEWQUEST		0x00000008
+#define PTP_VENDOR_STMICROELECTRONICS	0x00000009
+#define PTP_VENDOR_NIKON		0x0000000A
+#define PTP_VENDOR_CANON		0x0000000B
+  
+/* Vendor extension ID used for MTP */
+#define PTP_VENDOR_MTP			0xffffffff  
+
+/* Operation Codes */
+
+/* PTP v1.0 operation codes */
+#define PTP_OC_Undefined                0x1000
+#define PTP_OC_GetDeviceInfo            0x1001
+#define PTP_OC_OpenSession              0x1002
+#define PTP_OC_CloseSession             0x1003
+#define PTP_OC_GetStorageIDs            0x1004
+#define PTP_OC_GetStorageInfo           0x1005
+#define PTP_OC_GetNumObjects            0x1006
+#define PTP_OC_GetObjectHandles         0x1007
+#define PTP_OC_GetObjectInfo            0x1008
+#define PTP_OC_GetObject                0x1009
+#define PTP_OC_GetThumb                 0x100A
+#define PTP_OC_DeleteObject             0x100B
+#define PTP_OC_SendObjectInfo           0x100C
+#define PTP_OC_SendObject               0x100D
+#define PTP_OC_InitiateCapture          0x100E
+#define PTP_OC_FormatStore              0x100F
+#define PTP_OC_ResetDevice              0x1010
+#define PTP_OC_SelfTest                 0x1011
+#define PTP_OC_SetObjectProtection      0x1012
+#define PTP_OC_PowerDown                0x1013
+#define PTP_OC_GetDevicePropDesc        0x1014
+#define PTP_OC_GetDevicePropValue       0x1015
+#define PTP_OC_SetDevicePropValue       0x1016
+#define PTP_OC_ResetDevicePropValue     0x1017
+#define PTP_OC_TerminateOpenCapture     0x1018
+#define PTP_OC_MoveObject               0x1019
+#define PTP_OC_CopyObject               0x101A
+#define PTP_OC_GetPartialObject         0x101B
+#define PTP_OC_InitiateOpenCapture      0x101C
+/* PTP v1.1 operation codes */
+#define PTP_OC_StartEnumHandles		0x101D
+#define PTP_OC_EnumHandles		0x101E
+#define PTP_OC_StopEnumHandles		0x101F
+#define PTP_OC_GetVendorExtensionMaps	0x1020
+#define PTP_OC_GetVendorDeviceInfo	0x1021
+#define PTP_OC_GetResizedImageObject	0x1022
+#define PTP_OC_GetFilesystemManifest	0x1023
+#define PTP_OC_GetStreamInfo		0x1024
+#define PTP_OC_GetStream		0x1025
+
+/* Eastman Kodak extension Operation Codes */
+#define PTP_OC_EK_GetSerial		0x9003
+#define PTP_OC_EK_SetSerial		0x9004
+#define PTP_OC_EK_SendFileObjectInfo	0x9005
+#define PTP_OC_EK_SendFileObject	0x9006
+#define PTP_OC_EK_SetText		0x9008
+
+/* Canon extension Operation Codes */
+#define PTP_OC_CANON_GetPartialObjectInfo	0x9001
+/* 9002 - sends 2 uint32, nothing back  */
+#define PTP_OC_CANON_SetObjectArchive		0x9002
+#define PTP_OC_CANON_KeepDeviceOn		0x9003
+#define PTP_OC_CANON_LockDeviceUI		0x9004
+#define PTP_OC_CANON_UnlockDeviceUI		0x9005
+#define PTP_OC_CANON_GetObjectHandleByName	0x9006
+/* no 9007 observed yet */
+#define PTP_OC_CANON_InitiateReleaseControl	0x9008
+#define PTP_OC_CANON_TerminateReleaseControl	0x9009
+#define PTP_OC_CANON_TerminatePlaybackMode	0x900A
+#define PTP_OC_CANON_ViewfinderOn		0x900B
+#define PTP_OC_CANON_ViewfinderOff		0x900C
+#define PTP_OC_CANON_DoAeAfAwb			0x900D
+
+/* 900e - send nothing, gets 5 uint16t in 32bit entities back in 20byte datablob */
+#define PTP_OC_CANON_GetCustomizeSpec		0x900E
+#define PTP_OC_CANON_GetCustomizeItemInfo	0x900F
+#define PTP_OC_CANON_GetCustomizeData		0x9010
+#define PTP_OC_CANON_SetCustomizeData		0x9011
+#define PTP_OC_CANON_GetCaptureStatus		0x9012
+#define PTP_OC_CANON_CheckEvent			0x9013
+#define PTP_OC_CANON_FocusLock			0x9014
+#define PTP_OC_CANON_FocusUnlock		0x9015
+#define PTP_OC_CANON_GetLocalReleaseParam	0x9016
+#define PTP_OC_CANON_SetLocalReleaseParam	0x9017
+#define PTP_OC_CANON_AskAboutPcEvf		0x9018
+#define PTP_OC_CANON_SendPartialObject		0x9019
+#define PTP_OC_CANON_InitiateCaptureInMemory	0x901A
+#define PTP_OC_CANON_GetPartialObjectEx		0x901B
+#define PTP_OC_CANON_SetObjectTime		0x901C
+#define PTP_OC_CANON_GetViewfinderImage		0x901D
+#define PTP_OC_CANON_GetObjectAttributes	0x901E
+#define PTP_OC_CANON_ChangeUSBProtocol		0x901F
+#define PTP_OC_CANON_GetChanges			0x9020
+#define PTP_OC_CANON_GetObjectInfoEx		0x9021
+#define PTP_OC_CANON_InitiateDirectTransfer	0x9022
+#define PTP_OC_CANON_TerminateDirectTransfer 	0x9023
+#define PTP_OC_CANON_SendObjectInfoByPath 	0x9024
+#define PTP_OC_CANON_SendObjectByPath 		0x9025
+#define PTP_OC_CANON_InitiateDirectTansferEx	0x9026
+#define PTP_OC_CANON_GetAncillaryObjectHandles	0x9027
+#define PTP_OC_CANON_GetTreeInfo 		0x9028
+#define PTP_OC_CANON_GetTreeSize 		0x9029
+#define PTP_OC_CANON_NotifyProgress 		0x902A
+#define PTP_OC_CANON_NotifyCancelAccepted	0x902B
+/* 902c: no parms, read 3 uint32 in data, no response parms */
+#define PTP_OC_CANON_902C			0x902C
+#define PTP_OC_CANON_GetDirectory		0x902D
+
+#define PTP_OC_CANON_SetPairingInfo		0x9030
+#define PTP_OC_CANON_GetPairingInfo		0x9031
+#define PTP_OC_CANON_DeletePairingInfo		0x9032
+#define PTP_OC_CANON_GetMACAddress		0x9033
+/* 9034: 1 param, no parms returned */
+#define PTP_OC_CANON_SetDisplayMonitor		0x9034
+#define PTP_OC_CANON_PairingComplete		0x9035
+#define PTP_OC_CANON_GetWirelessMAXChannel	0x9036
+
+/* 9101: no args, 8 byte data (01 00 00 00 00 00 00 00), no resp data. */
+#define PTP_OC_CANON_EOS_GetStorageIDs		0x9101
+/* 9102: 1 arg (0)
+ * 0x28 bytes of data:
+    00000000: 34 00 00 00 02 00 02 91 0a 00 00 00 04 00 03 00
+    00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+    00000020: 00 00 ff ff ff ff 03 43 00 46 00 00 00 03 41 00
+    00000030: 3a 00 00 00
+ * no resp args
+ */
+#define PTP_OC_CANON_EOS_GetStorageInfo		0x9102
+#define PTP_OC_CANON_EOS_GetObjectInfo		0x9103
+#define PTP_OC_CANON_EOS_GetObject		0x9104
+#define PTP_OC_CANON_EOS_DeleteObject		0x9105
+#define PTP_OC_CANON_EOS_FormatStore		0x9106
+#define PTP_OC_CANON_EOS_GetPartialObject	0x9107
+#define PTP_OC_CANON_EOS_GetDeviceInfoEx	0x9108
+
+/* sample1:
+ * 3 cmdargs: 1,0xffffffff,00 00 10 00;
+ * data:
+    00000000: 48 00 00 00 02 00 09 91 12 00 00 00 01 00 00 00
+    00000010: 38 00 00 00 00 00 00 30 01 00 00 00 01 30 00 00
+    00000020: 01 00 00 00 10 00 00 00 00 00 00 00 00 00 00 20
+    00000030: 00 00 00 30 44 43 49 4d 00 00 00 00 00 00 00 00	DCIM
+    00000040: 00 00 00 00 cc c3 01 46
+ * 2 respargs: 0x0, 0x3c
+ * 
+ * sample2:
+ *
+    00000000: 18 00 00 00 01 00 09 91 15 00 00 00 01 00 00 00
+    00000010: 00 00 00 30 00 00 10 00
+
+    00000000: 48 00 00 00 02 00 09 91 15 00 00 00 01 00 00 00
+    00000010: 38 00 00 00 00 00 9c 33 01 00 00 00 01 30 00 00
+    00000020: 01 00 00 00 10 00 00 00 00 00 00 00 00 00 00 30
+    00000030: 00 00 9c 33 32 33 31 43 41 4e 4f 4e 00 00 00 00	 231CANON
+    00000040: 00 00 00 00 cc c3 01 46
+
+ */
+#define PTP_OC_CANON_EOS_GetObjectInfoEx	0x9109
+#define PTP_OC_CANON_EOS_GetThumbEx		0x910A
+#define PTP_OC_CANON_EOS_SendPartialObject	0x910B
+#define PTP_OC_CANON_EOS_SetObjectAttributes	0x910C
+#define PTP_OC_CANON_EOS_GetObjectTime		0x910D
+#define PTP_OC_CANON_EOS_SetObjectTime		0x910E
+
+/* 910f: no args, no data, 1 response arg (0). */
+#define PTP_OC_CANON_EOS_RemoteRelease		0x910F
+/* Marcus: looks more like "Set DeviceProperty" in the trace. 
+ *
+ * no cmd args
+ * data phase (0xc, 0xd11c, 0x1)
+ * no resp args 
+ */
+#define PTP_OC_CANON_EOS_SetDevicePropValueEx	0x9110
+#define PTP_OC_CANON_EOS_GetRemoteMode		0x9113
+/* 9114: 1 arg (0x1), no data, no resp data. */
+#define PTP_OC_CANON_EOS_SetRemoteMode		0x9114
+/* 9115: 1 arg (0x1), no data, no resp data. */
+#define PTP_OC_CANON_EOS_SetEventMode		0x9115
+/* 9116: no args, data phase, no resp data. */
+#define PTP_OC_CANON_EOS_GetEvent		0x9116
+#define PTP_OC_CANON_EOS_TransferComplete	0x9117
+#define PTP_OC_CANON_EOS_CancelTransfer		0x9118
+#define PTP_OC_CANON_EOS_ResetTransfer		0x9119
+
+/* 911a: 3 args (0xfffffff7, 0x00001000, 0x00000001), no data, no resp data. */
+/* 911a: 3 args (0x001dfc60, 0x00001000, 0x00000001), no data, no resp data. */
+#define PTP_OC_CANON_EOS_PCHDDCapacity		0x911A
+
+/* 911b: no cmd args, no data, no resp args */
+#define PTP_OC_CANON_EOS_SetUILock		0x911B
+/* 911c: no cmd args, no data, no resp args */
+#define PTP_OC_CANON_EOS_ResetUILock		0x911C
+#define PTP_OC_CANON_EOS_KeepDeviceOn		0x911D
+#define PTP_OC_CANON_EOS_SetNullPacketMode	0x911E
+#define PTP_OC_CANON_EOS_UpdateFirmware		0x911F
+#define PTP_OC_CANON_EOS_TransferCompleteDT	0x9120
+#define PTP_OC_CANON_EOS_CancelTransferDT	0x9121
+#define PTP_OC_CANON_EOS_SetWftProfile		0x9122
+#define PTP_OC_CANON_EOS_GetWftProfile		0x9122
+#define PTP_OC_CANON_EOS_SetProfileToWft	0x9124
+#define PTP_OC_CANON_EOS_BulbStart		0x9125
+#define PTP_OC_CANON_EOS_BulbEnd		0x9126
+#define PTP_OC_CANON_EOS_RequestDevicePropValue	0x9127
+
+/* 0x9128 args (0x1/0x2, 0x0), no data, no resp args */
+#define PTP_OC_CANON_EOS_RemoteReleaseOn	0x9128
+/* 0x9129 args (0x1/0x2), no data, no resp args */
+#define PTP_OC_CANON_EOS_RemoteReleaseOff	0x9129
+
+#define PTP_OC_CANON_EOS_InitiateViewfinder	0x9151
+#define PTP_OC_CANON_EOS_TerminateViewfinder	0x9152
+#define PTP_OC_CANON_EOS_GetViewFinderData	0x9153
+#define PTP_OC_CANON_EOS_DoAf			0x9154
+#define PTP_OC_CANON_EOS_DriveLens		0x9155
+#define PTP_OC_CANON_EOS_DepthOfFieldPreview	0x9156
+#define PTP_OC_CANON_EOS_ClickWB		0x9157
+#define PTP_OC_CANON_EOS_Zoom			0x9158
+#define PTP_OC_CANON_EOS_ZoomPosition		0x9159
+#define PTP_OC_CANON_EOS_SetLiveAfFrame		0x915a
+#define PTP_OC_CANON_EOS_AfCancel		0x9160
+#define PTP_OC_CANON_EOS_FAPIMessageTX		0x91FE
+#define PTP_OC_CANON_EOS_FAPIMessageRX		0x91FF
+
+/* Nikon extension Operation Codes */
+#define PTP_OC_NIKON_GetProfileAllData	0x9006
+#define PTP_OC_NIKON_SendProfileData	0x9007
+#define PTP_OC_NIKON_DeleteProfile	0x9008
+#define PTP_OC_NIKON_SetProfileData	0x9009
+#define PTP_OC_NIKON_AdvancedTransfer	0x9010
+#define PTP_OC_NIKON_GetFileInfoInBlock	0x9011
+#define PTP_OC_NIKON_Capture		0x90C0	/* 1 param,   no data */
+#define PTP_OC_NIKON_AfDrive		0x90C1	/* no params, no data */
+#define PTP_OC_NIKON_SetControlMode	0x90C2	/* 1 param,   no data */
+#define PTP_OC_NIKON_DelImageSDRAM	0x90C3	/* no params, no data */
+#define PTP_OC_NIKON_GetLargeThumb	0x90C4
+#define PTP_OC_NIKON_CurveDownload	0x90C5	/* 1 param,   data in */
+#define PTP_OC_NIKON_CurveUpload	0x90C6	/* 1 param,   data out */
+#define PTP_OC_NIKON_CheckEvent		0x90C7	/* no params, data in */
+#define PTP_OC_NIKON_DeviceReady	0x90C8	/* no params, no data */
+#define PTP_OC_NIKON_SetPreWBData	0x90C9	/* 3 params,  data out */
+#define PTP_OC_NIKON_GetVendorPropCodes	0x90CA	/* 0 params, data in */
+#define PTP_OC_NIKON_AfCaptureSDRAM	0x90CB	/* no params, no data */
+#define PTP_OC_NIKON_GetPictCtrlData	0x90CC
+#define PTP_OC_NIKON_SetPictCtrlData	0x90CD
+#define PTP_OC_NIKON_DelCstPicCtrl	0x90CE
+#define PTP_OC_NIKON_GetPicCtrlCapability	0x90CF
+
+/* Nikon Liveview stuff */
+#define PTP_OC_NIKON_GetPreviewImg	0x9200
+#define PTP_OC_NIKON_StartLiveView	0x9201
+#define PTP_OC_NIKON_EndLiveView	0x9202
+#define PTP_OC_NIKON_GetLiveViewImg	0x9203
+#define PTP_OC_NIKON_MfDrive		0x9204
+#define PTP_OC_NIKON_ChangeAfArea	0x9205
+#define PTP_OC_NIKON_AfDriveCancel	0x9206
+
+#define PTP_OC_NIKON_GetDevicePTPIPInfo	0x90E0
+
+/* Microsoft / MTP extension codes */
+
+#define PTP_OC_MTP_GetObjectPropsSupported	0x9801
+#define PTP_OC_MTP_GetObjectPropDesc		0x9802
+#define PTP_OC_MTP_GetObjectPropValue		0x9803
+#define PTP_OC_MTP_SetObjectPropValue		0x9804
+#define PTP_OC_MTP_GetObjPropList		0x9805
+#define PTP_OC_MTP_SetObjPropList		0x9806
+#define PTP_OC_MTP_GetInterdependendPropdesc	0x9807
+#define PTP_OC_MTP_SendObjectPropList		0x9808
+#define PTP_OC_MTP_GetObjectReferences		0x9810
+#define PTP_OC_MTP_SetObjectReferences		0x9811
+#define PTP_OC_MTP_UpdateDeviceFirmware		0x9812
+#define PTP_OC_MTP_Skip				0x9820
+
+/*
+ * Windows Media Digital Rights Management for Portable Devices 
+ * Extension Codes (microsoft.com/WMDRMPD: 10.1)
+ */
+#define PTP_OC_MTP_WMDRMPD_GetSecureTimeChallenge	0x9101
+#define PTP_OC_MTP_WMDRMPD_GetSecureTimeResponse	0x9102
+#define PTP_OC_MTP_WMDRMPD_SetLicenseResponse	0x9103
+#define PTP_OC_MTP_WMDRMPD_GetSyncList		0x9104
+#define PTP_OC_MTP_WMDRMPD_SendMeterChallengeQuery	0x9105
+#define PTP_OC_MTP_WMDRMPD_GetMeterChallenge	0x9106
+#define PTP_OC_MTP_WMDRMPD_SetMeterResponse		0x9107
+#define PTP_OC_MTP_WMDRMPD_CleanDataStore		0x9108
+#define PTP_OC_MTP_WMDRMPD_GetLicenseState		0x9109
+#define PTP_OC_MTP_WMDRMPD_SendWMDRMPDCommand	0x910A
+#define PTP_OC_MTP_WMDRMPD_SendWMDRMPDRequest	0x910B
+
+/* 
+ * Windows Media Digital Rights Management for Portable Devices 
+ * Extension Codes (microsoft.com/WMDRMPD: 10.1)
+ * Below are operations that have no public documented identifier 
+ * associated with them "Vendor-defined Command Code"
+ */
+#define PTP_OC_MTP_WMDRMPD_SendWMDRMPDAppRequest	0x9212
+#define PTP_OC_MTP_WMDRMPD_GetWMDRMPDAppResponse	0x9213
+#define PTP_OC_MTP_WMDRMPD_EnableTrustedFilesOperations	0x9214
+#define PTP_OC_MTP_WMDRMPD_DisableTrustedFilesOperations 0x9215
+#define PTP_OC_MTP_WMDRMPD_EndTrustedAppSession		0x9216
+/* ^^^ guess ^^^ */
+
+/*
+ * Microsoft Advanced Audio/Video Transfer 
+ * Extensions (microsoft.com/AAVT: 1.0)
+ */
+#define PTP_OC_MTP_AAVT_OpenMediaSession		0x9170
+#define PTP_OC_MTP_AAVT_CloseMediaSession		0x9171
+#define PTP_OC_MTP_AAVT_GetNextDataBlock		0x9172
+#define PTP_OC_MTP_AAVT_SetCurrentTimePosition		0x9173
+
+/*
+ * Windows Media Digital Rights Management for Network Devices 
+ * Extensions (microsoft.com/WMDRMND: 1.0) MTP/IP?
+ */
+#define PTP_OC_MTP_WMDRMND_SendRegistrationRequest	0x9180
+#define PTP_OC_MTP_WMDRMND_GetRegistrationResponse	0x9181
+#define PTP_OC_MTP_WMDRMND_GetProximityChallenge	0x9182
+#define PTP_OC_MTP_WMDRMND_SendProximityResponse	0x9183
+#define PTP_OC_MTP_WMDRMND_SendWMDRMNDLicenseRequest	0x9184
+#define PTP_OC_MTP_WMDRMND_GetWMDRMNDLicenseResponse	0x9185
+
+/* 
+ * Windows Media Player Portiable Devices 
+ * Extension Codes (microsoft.com/WMPPD: 11.1)
+ */
+#define PTP_OC_MTP_WMPPD_ReportAddedDeletedItems	0x9201
+#define PTP_OC_MTP_WMPPD_ReportAcquiredItems 	        0x9202
+#define PTP_OC_MTP_WMPPD_PlaylistObjectPref		0x9203
+
+/*
+ * Undocumented Zune Operation Codes 
+ * maybe related to WMPPD extension set?
+ */
+#define PTP_OC_MTP_ZUNE_GETUNDEFINED001		        0x9204
+
+/* WiFi Provisioning MTP Extension Codes (microsoft.com/WPDWCN: 1.0) */
+#define PTP_OC_MTP_WPDWCN_ProcessWFCObject		0x9122
+
+/* Proprietary vendor extension operations mask */
+#define PTP_OC_EXTENSION_MASK           0xF000
+#define PTP_OC_EXTENSION                0x9000
+
+/* Response Codes */
+
+/* PTP v1.0 response codes */
+#define PTP_RC_Undefined                0x2000
+#define PTP_RC_OK                       0x2001
+#define PTP_RC_GeneralError             0x2002
+#define PTP_RC_SessionNotOpen           0x2003
+#define PTP_RC_InvalidTransactionID	0x2004
+#define PTP_RC_OperationNotSupported    0x2005
+#define PTP_RC_ParameterNotSupported    0x2006
+#define PTP_RC_IncompleteTransfer       0x2007
+#define PTP_RC_InvalidStorageId         0x2008
+#define PTP_RC_InvalidObjectHandle      0x2009
+#define PTP_RC_DevicePropNotSupported   0x200A
+#define PTP_RC_InvalidObjectFormatCode  0x200B
+#define PTP_RC_StoreFull                0x200C
+#define PTP_RC_ObjectWriteProtected     0x200D
+#define PTP_RC_StoreReadOnly            0x200E
+#define PTP_RC_AccessDenied             0x200F
+#define PTP_RC_NoThumbnailPresent       0x2010
+#define PTP_RC_SelfTestFailed           0x2011
+#define PTP_RC_PartialDeletion          0x2012
+#define PTP_RC_StoreNotAvailable        0x2013
+#define PTP_RC_SpecificationByFormatUnsupported         0x2014
+#define PTP_RC_NoValidObjectInfo        0x2015
+#define PTP_RC_InvalidCodeFormat        0x2016
+#define PTP_RC_UnknownVendorCode        0x2017
+#define PTP_RC_CaptureAlreadyTerminated 0x2018
+#define PTP_RC_DeviceBusy               0x2019
+#define PTP_RC_InvalidParentObject      0x201A
+#define PTP_RC_InvalidDevicePropFormat  0x201B
+#define PTP_RC_InvalidDevicePropValue   0x201C
+#define PTP_RC_InvalidParameter         0x201D
+#define PTP_RC_SessionAlreadyOpened     0x201E
+#define PTP_RC_TransactionCanceled      0x201F
+#define PTP_RC_SpecificationOfDestinationUnsupported            0x2020
+/* PTP v1.1 response codes */
+#define PTP_RC_InvalidEnumHandle	0x2021
+#define PTP_RC_NoStreamEnabled		0x2022
+#define PTP_RC_InvalidDataSet		0x2023
+
+/* Eastman Kodak extension Response Codes */
+#define PTP_RC_EK_FilenameRequired	0xA001
+#define PTP_RC_EK_FilenameConflicts	0xA002
+#define PTP_RC_EK_FilenameInvalid	0xA003
+
+/* Nikon specific response codes */
+#define PTP_RC_NIKON_HardwareError		0xA001
+#define PTP_RC_NIKON_OutOfFocus			0xA002
+#define PTP_RC_NIKON_ChangeCameraModeFailed	0xA003
+#define PTP_RC_NIKON_InvalidStatus		0xA004
+#define PTP_RC_NIKON_SetPropertyNotSupported	0xA005
+#define PTP_RC_NIKON_WbResetError		0xA006
+#define PTP_RC_NIKON_DustReferenceError		0xA007
+#define PTP_RC_NIKON_ShutterSpeedBulb		0xA008
+#define PTP_RC_NIKON_MirrorUpSequence		0xA009
+#define PTP_RC_NIKON_CameraModeNotAdjustFNumber	0xA00A
+#define PTP_RC_NIKON_NotLiveView		0xA00B
+#define PTP_RC_NIKON_MfDriveStepEnd		0xA00C
+#define PTP_RC_NIKON_MfDriveStepInsufficiency	0xA00E
+#define PTP_RC_NIKON_AdvancedTransferCancel	0xA022
+
+/* Canon specific response codes */
+#define PTP_RC_CANON_A009		0xA009
+
+/* Microsoft/MTP specific codes */
+#define PTP_RC_MTP_Undefined			0xA800
+#define PTP_RC_MTP_Invalid_ObjectPropCode	0xA801
+#define PTP_RC_MTP_Invalid_ObjectProp_Format	0xA802
+#define PTP_RC_MTP_Invalid_ObjectProp_Value	0xA803
+#define PTP_RC_MTP_Invalid_ObjectReference	0xA804
+#define PTP_RC_MTP_Invalid_Dataset		0xA806
+#define PTP_RC_MTP_Specification_By_Group_Unsupported		0xA807
+#define PTP_RC_MTP_Specification_By_Depth_Unsupported		0xA808
+#define PTP_RC_MTP_Object_Too_Large		0xA809
+#define PTP_RC_MTP_ObjectProp_Not_Supported	0xA80A
+
+/* Microsoft Advanced Audio/Video Transfer response codes 
+(microsoft.com/AAVT 1.0) */
+#define PTP_RC_MTP_Invalid_Media_Session_ID	0xA170	
+#define PTP_RC_MTP_Media_Session_Limit_Reached	0xA171
+#define PTP_RC_MTP_No_More_Data			0xA172
+
+/* WiFi Provisioning MTP Extension Error Codes (microsoft.com/WPDWCN: 1.0) */
+#define PTP_RC_MTP_Invalid_WFC_Syntax		0xA121
+#define PTP_RC_MTP_WFC_Version_Not_Supported	0xA122
+
+/* libptp2 extended ERROR codes */
+#define PTP_ERROR_IO			0x02FF
+#define PTP_ERROR_DATA_EXPECTED		0x02FE
+#define PTP_ERROR_RESP_EXPECTED		0x02FD
+#define PTP_ERROR_BADPARAM		0x02FC
+#define PTP_ERROR_CANCEL		0x02FB
+#define PTP_ERROR_TIMEOUT		0x02FA
+
+/* PTP Event Codes */
+
+#define PTP_EC_Undefined		0x4000
+#define PTP_EC_CancelTransaction	0x4001
+#define PTP_EC_ObjectAdded		0x4002
+#define PTP_EC_ObjectRemoved		0x4003
+#define PTP_EC_StoreAdded		0x4004
+#define PTP_EC_StoreRemoved		0x4005
+#define PTP_EC_DevicePropChanged	0x4006
+#define PTP_EC_ObjectInfoChanged	0x4007
+#define PTP_EC_DeviceInfoChanged	0x4008
+#define PTP_EC_RequestObjectTransfer	0x4009
+#define PTP_EC_StoreFull		0x400A
+#define PTP_EC_DeviceReset		0x400B
+#define PTP_EC_StorageInfoChanged	0x400C
+#define PTP_EC_CaptureComplete		0x400D
+#define PTP_EC_UnreportedStatus		0x400E
+
+/* Canon extension Event Codes */
+#define PTP_EC_CANON_ExtendedErrorcode		0xC005	/* ? */
+#define PTP_EC_CANON_ObjectInfoChanged		0xC008
+#define PTP_EC_CANON_RequestObjectTransfer	0xC009
+#define PTP_EC_CANON_CameraModeChanged		0xC00C
+#define PTP_EC_CANON_ShutterButtonPressed	0xC00E
+
+#define PTP_EC_CANON_StartDirectTransfer	0xC011
+#define PTP_EC_CANON_StopDirectTransfer		0xC013
+
+/* Canon EOS events */
+#define PTP_EC_CANON_EOS_RequestGetEvent	0xc101
+#define PTP_EC_CANON_EOS_ObjectAddedEx		0xc181
+#define PTP_EC_CANON_EOS_ObjectRemoved		0xc182
+#define PTP_EC_CANON_EOS_RequestGetObjectInfoEx	0xc183
+#define PTP_EC_CANON_EOS_StorageStatusChanged	0xc184
+#define PTP_EC_CANON_EOS_StorageInfoChanged	0xc185
+#define PTP_EC_CANON_EOS_RequestObjectTransfer	0xc186
+#define PTP_EC_CANON_EOS_ObjectInfoChangedEx	0xc187
+#define PTP_EC_CANON_EOS_ObjectContentChanged	0xc188
+#define PTP_EC_CANON_EOS_PropValueChanged	0xc189
+#define PTP_EC_CANON_EOS_AvailListChanged	0xc18a
+#define PTP_EC_CANON_EOS_CameraStatusChanged	0xc18b
+#define PTP_EC_CANON_EOS_WillSoonShutdown	0xc18d
+#define PTP_EC_CANON_EOS_ShutdownTimerUpdated	0xc18e
+#define PTP_EC_CANON_EOS_RequestCancelTransfer	0xc18f
+#define PTP_EC_CANON_EOS_RequestObjectTransferDT	0xc190
+#define PTP_EC_CANON_EOS_RequestCancelTransferDT	0xc191
+#define PTP_EC_CANON_EOS_StoreAdded		0xc192
+#define PTP_EC_CANON_EOS_StoreRemoved		0xc193
+#define PTP_EC_CANON_EOS_BulbExposureTime	0xc194
+#define PTP_EC_CANON_EOS_RecordingTime		0xc195
+#define PTP_EC_CANON_EOS_RequestObjectTransferTS		0xC1a2
+#define PTP_EC_CANON_EOS_AfResult		0xc1a3
+
+/* Nikon extension Event Codes */
+
+/* Nikon extension Event Codes */
+#define PTP_EC_Nikon_ObjectAddedInSDRAM		0xC101
+#define PTP_EC_Nikon_CaptureCompleteRecInSdram	0xC102
+/* Gets 1 parameter, objectid pointing to DPOF object */
+#define PTP_EC_Nikon_AdvancedTransfer		0xC103
+#define PTP_EC_Nikon_PreviewImageAdded		0xC104
+
+/* MTP Event codes */
+#define PTP_EC_MTP_ObjectPropChanged		0xC801
+#define PTP_EC_MTP_ObjectPropDescChanged	0xC802
+#define PTP_EC_MTP_ObjectReferencesChanged	0xC803
+
+/* constants for GetObjectHandles */
+#define PTP_GOH_ALL_STORAGE 0xffffffff
+#define PTP_GOH_ALL_FORMATS 0x00000000
+#define PTP_GOH_ALL_ASSOCS  0x00000000
+#define PTP_GOH_ROOT_PARENT 0xffffffff
+
+/* PTP device info structure (returned by GetDevInfo) */
+
+struct _PTPDeviceInfo {
+	uint16_t StandardVersion;
+	uint32_t VendorExtensionID;
+	uint16_t VendorExtensionVersion;
+	char	*VendorExtensionDesc;
+	uint16_t FunctionalMode;
+	uint32_t OperationsSupported_len;
+	uint16_t *OperationsSupported;
+	uint32_t EventsSupported_len;
+	uint16_t *EventsSupported;
+	uint32_t DevicePropertiesSupported_len;
+	uint16_t *DevicePropertiesSupported;
+	uint32_t CaptureFormats_len;
+	uint16_t *CaptureFormats;
+	uint32_t ImageFormats_len;
+	uint16_t *ImageFormats;
+	char	*Manufacturer;
+	char	*Model;
+	char	*DeviceVersion;
+	char	*SerialNumber;
+};
+typedef struct _PTPDeviceInfo PTPDeviceInfo;
+
+/* PTP storageIDs structute (returned by GetStorageIDs) */
+
+struct _PTPStorageIDs {
+	uint32_t n;
+	uint32_t *Storage;
+};
+typedef struct _PTPStorageIDs PTPStorageIDs;
+
+/* PTP StorageInfo structure (returned by GetStorageInfo) */
+struct _PTPStorageInfo {
+	uint16_t StorageType;
+	uint16_t FilesystemType;
+	uint16_t AccessCapability;
+	uint64_t MaxCapability;
+	uint64_t FreeSpaceInBytes;
+	uint32_t FreeSpaceInImages;
+	char 	*StorageDescription;
+	char	*VolumeLabel;
+};
+typedef struct _PTPStorageInfo PTPStorageInfo;
+
+/* PTP objecthandles structure (returned by GetObjectHandles) */
+
+struct _PTPObjectHandles {
+	uint32_t n;
+	uint32_t *Handler;
+};
+typedef struct _PTPObjectHandles PTPObjectHandles;
+
+#define PTP_HANDLER_SPECIAL	0xffffffff
+#define PTP_HANDLER_ROOT	0x00000000
+
+
+/* PTP objectinfo structure (returned by GetObjectInfo) */
+
+struct _PTPObjectInfo {
+	uint32_t StorageID;
+	uint16_t ObjectFormat;
+	uint16_t ProtectionStatus;
+	uint32_t ObjectCompressedSize;
+	uint16_t ThumbFormat;
+	uint32_t ThumbCompressedSize;
+	uint32_t ThumbPixWidth;
+	uint32_t ThumbPixHeight;
+	uint32_t ImagePixWidth;
+	uint32_t ImagePixHeight;
+	uint32_t ImageBitDepth;
+	uint32_t ParentObject;
+	uint16_t AssociationType;
+	uint32_t AssociationDesc;
+	uint32_t SequenceNumber;
+	char 	*Filename;
+	time_t	CaptureDate;
+	time_t	ModificationDate;
+	char	*Keywords;
+};
+typedef struct _PTPObjectInfo PTPObjectInfo;
+
+/* max ptp string length INCLUDING terminating null character */
+
+#define PTP_MAXSTRLEN				255
+
+/* PTP Object Format Codes */
+
+/* ancillary formats */
+#define PTP_OFC_Undefined			0x3000
+#define PTP_OFC_Defined				0x3800
+#define PTP_OFC_Association			0x3001
+#define PTP_OFC_Script				0x3002
+#define PTP_OFC_Executable			0x3003
+#define PTP_OFC_Text				0x3004
+#define PTP_OFC_HTML				0x3005
+#define PTP_OFC_DPOF				0x3006
+#define PTP_OFC_AIFF	 			0x3007
+#define PTP_OFC_WAV				0x3008
+#define PTP_OFC_MP3				0x3009
+#define PTP_OFC_AVI				0x300A
+#define PTP_OFC_MPEG				0x300B
+#define PTP_OFC_ASF				0x300C
+#define PTP_OFC_QT				0x300D /* guessing */
+/* image formats */
+#define PTP_OFC_EXIF_JPEG			0x3801
+#define PTP_OFC_TIFF_EP				0x3802
+#define PTP_OFC_FlashPix			0x3803
+#define PTP_OFC_BMP				0x3804
+#define PTP_OFC_CIFF				0x3805
+#define PTP_OFC_Undefined_0x3806		0x3806
+#define PTP_OFC_GIF				0x3807
+#define PTP_OFC_JFIF				0x3808
+#define PTP_OFC_PCD				0x3809
+#define PTP_OFC_PICT				0x380A
+#define PTP_OFC_PNG				0x380B
+#define PTP_OFC_Undefined_0x380C		0x380C
+#define PTP_OFC_TIFF				0x380D
+#define PTP_OFC_TIFF_IT				0x380E
+#define PTP_OFC_JP2				0x380F
+#define PTP_OFC_JPX				0x3810
+/* ptp v1.1 has only DNG new */
+#define PTP_OFC_DNG				0x3811
+/* Eastman Kodak extension ancillary format */
+#define PTP_OFC_EK_M3U				0xb002
+/* Canon extension */
+#define PTP_OFC_CANON_CRW			0xb101
+#define PTP_OFC_CANON_CRW3			0xb103
+#define PTP_OFC_CANON_MOV			0xb104
+/* MTP extensions */
+#define PTP_OFC_MTP_MediaCard			0xb211
+#define PTP_OFC_MTP_MediaCardGroup		0xb212
+#define PTP_OFC_MTP_Encounter			0xb213
+#define PTP_OFC_MTP_EncounterBox		0xb214
+#define PTP_OFC_MTP_M4A				0xb215
+#define PTP_OFC_MTP_ZUNEUNDEFINED		0xb217 /* Unknown file type */
+#define PTP_OFC_MTP_Firmware			0xb802
+#define PTP_OFC_MTP_WindowsImageFormat		0xb881
+#define PTP_OFC_MTP_UndefinedAudio		0xb900
+#define PTP_OFC_MTP_WMA				0xb901
+#define PTP_OFC_MTP_OGG				0xb902
+#define PTP_OFC_MTP_AAC				0xb903
+#define PTP_OFC_MTP_AudibleCodec		0xb904
+#define PTP_OFC_MTP_FLAC			0xb906
+#define PTP_OFC_MTP_UndefinedVideo		0xb980
+#define PTP_OFC_MTP_WMV				0xb981
+#define PTP_OFC_MTP_MP4				0xb982
+#define PTP_OFC_MTP_MP2				0xb983
+#define PTP_OFC_MTP_3GP				0xb984
+#define PTP_OFC_MTP_UndefinedCollection		0xba00
+#define PTP_OFC_MTP_AbstractMultimediaAlbum	0xba01
+#define PTP_OFC_MTP_AbstractImageAlbum		0xba02
+#define PTP_OFC_MTP_AbstractAudioAlbum		0xba03
+#define PTP_OFC_MTP_AbstractVideoAlbum		0xba04
+#define PTP_OFC_MTP_AbstractAudioVideoPlaylist	0xba05
+#define PTP_OFC_MTP_AbstractContactGroup	0xba06
+#define PTP_OFC_MTP_AbstractMessageFolder	0xba07
+#define PTP_OFC_MTP_AbstractChapteredProduction	0xba08
+#define PTP_OFC_MTP_AbstractAudioPlaylist	0xba09
+#define PTP_OFC_MTP_AbstractVideoPlaylist	0xba0a
+#define PTP_OFC_MTP_AbstractMediacast		0xba0b
+#define PTP_OFC_MTP_WPLPlaylist			0xba10
+#define PTP_OFC_MTP_M3UPlaylist			0xba11
+#define PTP_OFC_MTP_MPLPlaylist			0xba12
+#define PTP_OFC_MTP_ASXPlaylist			0xba13
+#define PTP_OFC_MTP_PLSPlaylist			0xba14
+#define PTP_OFC_MTP_UndefinedDocument		0xba80
+#define PTP_OFC_MTP_AbstractDocument		0xba81
+#define PTP_OFC_MTP_XMLDocument			0xba82
+#define PTP_OFC_MTP_MSWordDocument		0xba83
+#define PTP_OFC_MTP_MHTCompiledHTMLDocument	0xba84
+#define PTP_OFC_MTP_MSExcelSpreadsheetXLS	0xba85
+#define PTP_OFC_MTP_MSPowerpointPresentationPPT	0xba86
+#define PTP_OFC_MTP_UndefinedMessage		0xbb00
+#define PTP_OFC_MTP_AbstractMessage		0xbb01
+#define PTP_OFC_MTP_UndefinedContact		0xbb80
+#define PTP_OFC_MTP_AbstractContact		0xbb81
+#define PTP_OFC_MTP_vCard2			0xbb82
+#define PTP_OFC_MTP_vCard3			0xbb83
+#define PTP_OFC_MTP_UndefinedCalendarItem	0xbe00
+#define PTP_OFC_MTP_AbstractCalendarItem	0xbe01
+#define PTP_OFC_MTP_vCalendar1			0xbe02
+#define PTP_OFC_MTP_vCalendar2			0xbe03
+#define PTP_OFC_MTP_UndefinedWindowsExecutable	0xbe80
+#define PTP_OFC_MTP_MediaCast			0xbe81
+#define PTP_OFC_MTP_Section			0xbe82
+
+/* PTP Association Types */
+#define PTP_AT_Undefined			0x0000
+#define PTP_AT_GenericFolder			0x0001
+#define PTP_AT_Album				0x0002
+#define PTP_AT_TimeSequence			0x0003
+#define PTP_AT_HorizontalPanoramic		0x0004
+#define PTP_AT_VerticalPanoramic		0x0005
+#define PTP_AT_2DPanoramic			0x0006
+#define PTP_AT_AncillaryData			0x0007
+
+/* PTP Protection Status */
+
+#define PTP_PS_NoProtection			0x0000
+#define PTP_PS_ReadOnly				0x0001
+#define PTP_PS_MTP_ReadOnlyData			0x8002
+#define PTP_PS_MTP_NonTransferableData		0x8003
+
+/* PTP Storage Types */
+
+#define PTP_ST_Undefined			0x0000
+#define PTP_ST_FixedROM				0x0001
+#define PTP_ST_RemovableROM			0x0002
+#define PTP_ST_FixedRAM				0x0003
+#define PTP_ST_RemovableRAM			0x0004
+
+/* PTP FilesystemType Values */
+
+#define PTP_FST_Undefined			0x0000
+#define PTP_FST_GenericFlat			0x0001
+#define PTP_FST_GenericHierarchical		0x0002
+#define PTP_FST_DCF				0x0003
+
+/* PTP StorageInfo AccessCapability Values */
+
+#define PTP_AC_ReadWrite			0x0000
+#define PTP_AC_ReadOnly				0x0001
+#define PTP_AC_ReadOnly_with_Object_Deletion	0x0002
+
+/* Property Describing Dataset, Range Form */
+
+union _PTPPropertyValue {
+	char		*str;	/* common string, malloced */
+	uint8_t		u8;
+	int8_t		i8;
+	uint16_t	u16;
+	int16_t		i16;
+	uint32_t	u32;
+	int32_t		i32;
+	uint64_t	u64;
+	int64_t		i64;
+	/* XXXX: 128 bit signed and unsigned missing */
+	struct array {
+		uint32_t	count;
+		union _PTPPropertyValue	*v;	/* malloced, count elements */
+	} a;
+};
+
+typedef union _PTPPropertyValue PTPPropertyValue;
+
+/* Metadata lists for MTP operations */
+struct _MTPProperties {
+	uint16_t 	 	property;
+	uint16_t 	 	datatype;
+	uint32_t 	 	ObjectHandle;
+	PTPPropertyValue 	propval;
+};
+typedef struct _MTPProperties MTPProperties;
+
+struct _PTPPropDescRangeForm {
+	PTPPropertyValue 	MinimumValue;
+	PTPPropertyValue 	MaximumValue;
+	PTPPropertyValue 	StepSize;
+};
+typedef struct _PTPPropDescRangeForm PTPPropDescRangeForm;
+
+/* Property Describing Dataset, Enum Form */
+
+struct _PTPPropDescEnumForm {
+	uint16_t		NumberOfValues;
+	PTPPropertyValue	*SupportedValue;	/* malloced */
+};
+typedef struct _PTPPropDescEnumForm PTPPropDescEnumForm;
+
+/* Device Property Describing Dataset (DevicePropDesc) */
+
+struct _PTPDevicePropDesc {
+	uint16_t		DevicePropertyCode;
+	uint16_t		DataType;
+	uint8_t			GetSet;
+	PTPPropertyValue	FactoryDefaultValue;
+	PTPPropertyValue	CurrentValue;
+	uint8_t			FormFlag;
+	union	{
+		PTPPropDescEnumForm	Enum;
+		PTPPropDescRangeForm	Range;
+	} FORM;
+};
+typedef struct _PTPDevicePropDesc PTPDevicePropDesc;
+
+/* Object Property Describing Dataset (DevicePropDesc) */
+
+struct _PTPObjectPropDesc {
+	uint16_t		ObjectPropertyCode;
+	uint16_t		DataType;
+	uint8_t			GetSet;
+	PTPPropertyValue	FactoryDefaultValue;
+	uint32_t		GroupCode;
+	uint8_t			FormFlag;
+	union	{
+		PTPPropDescEnumForm	Enum;
+		PTPPropDescRangeForm	Range;
+	} FORM;
+};
+typedef struct _PTPObjectPropDesc PTPObjectPropDesc;
+
+/* Canon filesystem's folder entry Dataset */
+
+#define PTP_CANON_FilenameBufferLen	13
+#define PTP_CANON_FolderEntryLen	28
+
+struct _PTPCANONFolderEntry {
+	uint32_t	ObjectHandle;
+	uint16_t	ObjectFormatCode;
+	uint8_t		Flags;
+	uint32_t	ObjectSize;
+	time_t		Time;
+	char		Filename[PTP_CANON_FilenameBufferLen];
+};
+typedef struct _PTPCANONFolderEntry PTPCANONFolderEntry;
+
+/* Nikon Tone Curve Data */
+
+#define PTP_NIKON_MaxCurvePoints 19
+
+struct _PTPNIKONCoordinatePair {
+	uint8_t		X;
+	uint8_t		Y;
+};
+
+typedef struct _PTPNIKONCoordinatePair PTPNIKONCoordinatePair;
+
+struct _PTPNTCCoordinatePair {
+	uint8_t		X;
+	uint8_t		Y;
+};
+
+typedef struct _PTPNTCCoordinatePair PTPNTCCoordinatePair;
+
+struct _PTPNIKONCurveData {
+	char 			static_preamble[6];
+	uint8_t			XAxisStartPoint;
+	uint8_t			XAxisEndPoint;
+	uint8_t			YAxisStartPoint;
+	uint8_t			YAxisEndPoint;
+	uint8_t			MidPointIntegerPart;
+	uint8_t			MidPointDecimalPart;
+	uint8_t			NCoordinates;
+	PTPNIKONCoordinatePair	CurveCoordinates[PTP_NIKON_MaxCurvePoints];
+};
+
+typedef struct _PTPNIKONCurveData PTPNIKONCurveData;
+
+struct _PTPEKTextParams {
+	char	*title;
+	char	*line[5];
+};
+typedef struct _PTPEKTextParams PTPEKTextParams;
+
+/* Nikon Wifi profiles */
+
+struct _PTPNIKONWifiProfile {
+	/* Values valid both when reading and writing profiles */
+	char      profile_name[17];
+	uint8_t   device_type;
+	uint8_t   icon_type;
+	char      essid[33];
+
+	/* Values only valid when reading. Some of these are in the write packet,
+	 * but are set automatically, like id, display_order and creation_date. */
+	uint8_t   id;
+	uint8_t   valid;
+	uint8_t   display_order;
+	char      creation_date[16];
+	char      lastusage_date[16];
+	
+	/* Values only valid when writing */
+	uint32_t  ip_address;
+	uint8_t   subnet_mask; /* first zero bit position, e.g. 24 for 255.255.255.0 */
+	uint32_t  gateway_address;
+	uint8_t   address_mode; /* 0 - Manual, 2-3 -  DHCP ad-hoc/managed*/
+	uint8_t   access_mode; /* 0 - Managed, 1 - Adhoc */
+	uint8_t   wifi_channel; /* 1-11 */
+	uint8_t   authentification; /* 0 - Open, 1 - Shared, 2 - WPA-PSK */
+	uint8_t   encryption; /* 0 - None, 1 - WEP 64bit, 2 - WEP 128bit (not supported: 3 - TKIP) */
+	uint8_t   key[64];
+	uint8_t   key_nr;
+//	char      guid[16];
+};
+
+typedef struct _PTPNIKONWifiProfile PTPNIKONWifiProfile;
+
+#define PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN		0
+#define PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO		1
+#define PTP_CANON_EOS_CHANGES_TYPE_OBJECTTRANSFER	2
+
+struct _PTPCanon_New_Object {
+	uint32_t		oid;
+	PTPObjectInfo	oi;
+};
+
+struct _PTPCanon_changes_entry {
+	int	type;
+	union {
+		struct _PTPCanon_New_Object	object;	/* TYPE_OBJECTINFO */
+	} u;
+};
+typedef struct _PTPCanon_changes_entry PTPCanon_changes_entry;
+
+typedef struct _PTPCanon_Property {
+	uint32_t		size;
+	uint32_t		type;
+	uint32_t		proptype;
+	unsigned char		*data;
+
+	/* fill out for queries */
+	PTPDevicePropDesc	dpd;
+} PTPCanon_Property;
+
+typedef struct _PTPCanonEOSDeviceInfo {
+	/* length */
+	uint32_t EventsSupported_len;
+	uint32_t *EventsSupported;
+
+	uint32_t DevicePropertiesSupported_len;
+	uint32_t *DevicePropertiesSupported;
+
+	uint32_t unk_len;
+	uint32_t *unk;
+} PTPCanonEOSDeviceInfo;
+
+/* DataType Codes */
+
+#define PTP_DTC_UNDEF		0x0000
+#define PTP_DTC_INT8		0x0001
+#define PTP_DTC_UINT8		0x0002
+#define PTP_DTC_INT16		0x0003
+#define PTP_DTC_UINT16		0x0004
+#define PTP_DTC_INT32		0x0005
+#define PTP_DTC_UINT32		0x0006
+#define PTP_DTC_INT64		0x0007
+#define PTP_DTC_UINT64		0x0008
+#define PTP_DTC_INT128		0x0009
+#define PTP_DTC_UINT128		0x000A
+
+#define PTP_DTC_ARRAY_MASK	0x4000
+
+#define PTP_DTC_AINT8		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT8)
+#define PTP_DTC_AUINT8		(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT8)
+#define PTP_DTC_AINT16		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT16)
+#define PTP_DTC_AUINT16		(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT16)
+#define PTP_DTC_AINT32		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT32)
+#define PTP_DTC_AUINT32		(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT32)
+#define PTP_DTC_AINT64		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT64)
+#define PTP_DTC_AUINT64		(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT64)
+#define PTP_DTC_AINT128		(PTP_DTC_ARRAY_MASK | PTP_DTC_INT128)
+#define PTP_DTC_AUINT128	(PTP_DTC_ARRAY_MASK | PTP_DTC_UINT128)
+
+#define PTP_DTC_STR		0xFFFF
+
+/* Device Properties Codes */
+
+/* PTP v1.0 property codes */
+#define PTP_DPC_Undefined		0x5000
+#define PTP_DPC_BatteryLevel		0x5001
+#define PTP_DPC_FunctionalMode		0x5002
+#define PTP_DPC_ImageSize		0x5003
+#define PTP_DPC_CompressionSetting	0x5004
+#define PTP_DPC_WhiteBalance		0x5005
+#define PTP_DPC_RGBGain			0x5006
+#define PTP_DPC_FNumber			0x5007
+#define PTP_DPC_FocalLength		0x5008
+#define PTP_DPC_FocusDistance		0x5009
+#define PTP_DPC_FocusMode		0x500A
+#define PTP_DPC_ExposureMeteringMode	0x500B
+#define PTP_DPC_FlashMode		0x500C
+#define PTP_DPC_ExposureTime		0x500D
+#define PTP_DPC_ExposureProgramMode	0x500E
+#define PTP_DPC_ExposureIndex		0x500F
+#define PTP_DPC_ExposureBiasCompensation	0x5010
+#define PTP_DPC_DateTime		0x5011
+#define PTP_DPC_CaptureDelay		0x5012
+#define PTP_DPC_StillCaptureMode	0x5013
+#define PTP_DPC_Contrast		0x5014
+#define PTP_DPC_Sharpness		0x5015
+#define PTP_DPC_DigitalZoom		0x5016
+#define PTP_DPC_EffectMode		0x5017
+#define PTP_DPC_BurstNumber		0x5018
+#define PTP_DPC_BurstInterval		0x5019
+#define PTP_DPC_TimelapseNumber		0x501A
+#define PTP_DPC_TimelapseInterval	0x501B
+#define PTP_DPC_FocusMeteringMode	0x501C
+#define PTP_DPC_UploadURL		0x501D
+#define PTP_DPC_Artist			0x501E
+#define PTP_DPC_CopyrightInfo		0x501F
+/* PTP v1.1 property codes */
+#define PTP_DPC_SupportedStreams	0x5020
+#define PTP_DPC_EnabledStreams		0x5021
+#define PTP_DPC_VideoFormat		0x5022
+#define PTP_DPC_VideoResolution		0x5023
+#define PTP_DPC_VideoQuality		0x5024
+#define PTP_DPC_VideoFrameRate		0x5025
+#define PTP_DPC_VideoContrast		0x5026
+#define PTP_DPC_VideoBrightness		0x5027
+#define PTP_DPC_AudioFormat		0x5028
+#define PTP_DPC_AudioBitrate		0x5029
+#define PTP_DPC_AudioSamplingRate	0x502A
+#define PTP_DPC_AudioBitPerSample	0x502B
+#define PTP_DPC_AudioVolume		0x502C
+
+/* Proprietary vendor extension device property mask */
+#define PTP_DPC_EXTENSION_MASK		0xF000
+#define PTP_DPC_EXTENSION		0xD000
+
+/* Zune extension device property codes */
+#define PTP_DPC_MTP_ZUNE_UNKNOWN1	0xD181
+#define PTP_DPC_MTP_ZUNE_UNKNOWN2	0xD132
+#define PTP_DPC_MTP_ZUNE_UNKNOWN3	0xD215
+#define PTP_DPC_MTP_ZUNE_UNKNOWN4	0xD216
+
+/* Eastman Kodak extension device property codes */
+#define PTP_DPC_EK_ColorTemperature	0xD001
+#define PTP_DPC_EK_DateTimeStampFormat	0xD002
+#define PTP_DPC_EK_BeepMode		0xD003
+#define PTP_DPC_EK_VideoOut		0xD004
+#define PTP_DPC_EK_PowerSaving		0xD005
+#define PTP_DPC_EK_UI_Language		0xD006
+
+/* Canon extension device property codes */
+#define PTP_DPC_CANON_BeepMode		0xD001
+#define PTP_DPC_CANON_BatteryKind	0xD002
+#define PTP_DPC_CANON_BatteryStatus	0xD003
+#define PTP_DPC_CANON_UILockType	0xD004
+#define PTP_DPC_CANON_CameraMode	0xD005
+#define PTP_DPC_CANON_ImageQuality	0xD006
+#define PTP_DPC_CANON_FullViewFileFormat 0xD007
+#define PTP_DPC_CANON_ImageSize		0xD008
+#define PTP_DPC_CANON_SelfTime		0xD009
+#define PTP_DPC_CANON_FlashMode		0xD00A
+#define PTP_DPC_CANON_Beep		0xD00B
+#define PTP_DPC_CANON_ShootingMode	0xD00C
+#define PTP_DPC_CANON_ImageMode		0xD00D
+#define PTP_DPC_CANON_DriveMode		0xD00E
+#define PTP_DPC_CANON_EZoom		0xD00F
+#define PTP_DPC_CANON_MeteringMode	0xD010
+#define PTP_DPC_CANON_AFDistance	0xD011
+#define PTP_DPC_CANON_FocusingPoint	0xD012
+#define PTP_DPC_CANON_WhiteBalance	0xD013
+#define PTP_DPC_CANON_SlowShutterSetting	0xD014
+#define PTP_DPC_CANON_AFMode		0xD015
+#define PTP_DPC_CANON_ImageStabilization	0xD016
+#define PTP_DPC_CANON_Contrast		0xD017
+#define PTP_DPC_CANON_ColorGain		0xD018
+#define PTP_DPC_CANON_Sharpness		0xD019
+#define PTP_DPC_CANON_Sensitivity	0xD01A
+#define PTP_DPC_CANON_ParameterSet	0xD01B
+#define PTP_DPC_CANON_ISOSpeed		0xD01C
+#define PTP_DPC_CANON_Aperture		0xD01D
+#define PTP_DPC_CANON_ShutterSpeed	0xD01E
+#define PTP_DPC_CANON_ExpCompensation	0xD01F
+#define PTP_DPC_CANON_FlashCompensation	0xD020
+#define PTP_DPC_CANON_AEBExposureCompensation	0xD021
+#define PTP_DPC_CANON_AvOpen		0xD023
+#define PTP_DPC_CANON_AvMax		0xD024
+#define PTP_DPC_CANON_FocalLength	0xD025
+#define PTP_DPC_CANON_FocalLengthTele	0xD026
+#define PTP_DPC_CANON_FocalLengthWide	0xD027
+#define PTP_DPC_CANON_FocalLengthDenominator	0xD028
+#define PTP_DPC_CANON_CaptureTransferMode	0xD029
+#define CANON_TRANSFER_ENTIRE_IMAGE_TO_PC	0x0002
+#define CANON_TRANSFER_SAVE_THUMBNAIL_TO_DEVICE	0x0004
+#define CANON_TRANSFER_SAVE_IMAGE_TO_DEVICE	0x0008
+/* we use those values: */
+#define CANON_TRANSFER_MEMORY		(2|1)
+#define CANON_TRANSFER_CARD		(8|4|1)
+
+#define PTP_DPC_CANON_Zoom		0xD02A
+#define PTP_DPC_CANON_NamePrefix	0xD02B
+#define PTP_DPC_CANON_SizeQualityMode	0xD02C
+#define PTP_DPC_CANON_SupportedThumbSize	0xD02D
+#define PTP_DPC_CANON_SizeOfOutputDataFromCamera	0xD02E
+#define PTP_DPC_CANON_SizeOfInputDataToCamera		0xD02F
+#define PTP_DPC_CANON_RemoteAPIVersion	0xD030
+#define PTP_DPC_CANON_FirmwareVersion	0xD031
+#define PTP_DPC_CANON_CameraModel	0xD032
+#define PTP_DPC_CANON_CameraOwner	0xD033
+#define PTP_DPC_CANON_UnixTime		0xD034
+#define PTP_DPC_CANON_CameraBodyID	0xD035
+#define PTP_DPC_CANON_CameraOutput	0xD036
+#define PTP_DPC_CANON_DispAv		0xD037
+#define PTP_DPC_CANON_AvOpenApex	0xD038
+#define PTP_DPC_CANON_DZoomMagnification	0xD039
+#define PTP_DPC_CANON_MlSpotPos		0xD03A
+#define PTP_DPC_CANON_DispAvMax		0xD03B
+#define PTP_DPC_CANON_AvMaxApex		0xD03C
+#define PTP_DPC_CANON_EZoomStartPosition		0xD03D
+#define PTP_DPC_CANON_FocalLengthOfTele	0xD03E
+#define PTP_DPC_CANON_EZoomSizeOfTele	0xD03F
+#define PTP_DPC_CANON_PhotoEffect	0xD040
+#define PTP_DPC_CANON_AssistLight	0xD041
+#define PTP_DPC_CANON_FlashQuantityCount	0xD042
+#define PTP_DPC_CANON_RotationAngle	0xD043
+#define PTP_DPC_CANON_RotationScene	0xD044
+#define PTP_DPC_CANON_EventEmulateMode	0xD045
+#define PTP_DPC_CANON_DPOFVersion	0xD046
+#define PTP_DPC_CANON_TypeOfSupportedSlideShow	0xD047
+#define PTP_DPC_CANON_AverageFilesizes	0xD048
+#define PTP_DPC_CANON_ModelID		0xD049
+
+/* From EOS 400D trace. */
+#define PTP_DPC_CANON_EOS_Aperture		0xD101
+#define PTP_DPC_CANON_EOS_ShutterSpeed		0xD102
+#define PTP_DPC_CANON_EOS_ISOSpeed		0xD103
+#define PTP_DPC_CANON_EOS_ExpCompensation	0xD104
+#define PTP_DPC_CANON_EOS_AutoExposureMode	0xD105
+#define PTP_DPC_CANON_EOS_DriveMode		0xD106
+#define PTP_DPC_CANON_EOS_MeteringMode		0xD107 
+#define PTP_DPC_CANON_EOS_FocusMode		0xD108
+#define PTP_DPC_CANON_EOS_WhiteBalance		0xD109
+#define PTP_DPC_CANON_EOS_ColorTemperature	0xD10A
+#define PTP_DPC_CANON_EOS_WhiteBalanceAdjustA	0xD10B
+#define PTP_DPC_CANON_EOS_WhiteBalanceAdjustB	0xD10C
+#define PTP_DPC_CANON_EOS_WhiteBalanceXA	0xD10D
+#define PTP_DPC_CANON_EOS_WhiteBalanceXB	0xD10E
+#define PTP_DPC_CANON_EOS_ColorSpace		0xD10F
+#define PTP_DPC_CANON_EOS_PictureStyle		0xD110
+#define PTP_DPC_CANON_EOS_BatteryPower		0xD111
+#define PTP_DPC_CANON_EOS_BatterySelect		0xD112
+#define PTP_DPC_CANON_EOS_CameraTime		0xD113
+#define PTP_DPC_CANON_EOS_Owner			0xD115
+#define PTP_DPC_CANON_EOS_ModelID		0xD116
+#define PTP_DPC_CANON_EOS_PTPExtensionVersion	0xD119
+#define PTP_DPC_CANON_EOS_DPOFVersion		0xD11A
+#define PTP_DPC_CANON_EOS_AvailableShots	0xD11B
+#define PTP_DPC_CANON_EOS_CaptureDestination	0xD11C
+#define PTP_DPC_CANON_EOS_BracketMode		0xD11D
+#define PTP_DPC_CANON_EOS_CurrentStorage	0xD11E
+#define PTP_DPC_CANON_EOS_CurrentFolder		0xD11F
+#define PTP_DPC_CANON_EOS_ImageFormat		0xD120	/* file setting */
+#define PTP_DPC_CANON_EOS_ImageFormatCF		0xD121	/* file setting CF */
+#define PTP_DPC_CANON_EOS_ImageFormatSD		0xD122	/* file setting SD */
+#define PTP_DPC_CANON_EOS_ImageFormatExtHD	0xD123	/* file setting exthd */
+#define PTP_DPC_CANON_EOS_CompressionS		0xD130
+#define PTP_DPC_CANON_EOS_CompressionM1		0xD131
+#define PTP_DPC_CANON_EOS_CompressionM2		0xD132
+#define PTP_DPC_CANON_EOS_CompressionL		0xD133
+#define PTP_DPC_CANON_EOS_PCWhiteBalance1	0xD140
+#define PTP_DPC_CANON_EOS_PCWhiteBalance2	0xD141
+#define PTP_DPC_CANON_EOS_PCWhiteBalance3	0xD142
+#define PTP_DPC_CANON_EOS_PCWhiteBalance4	0xD143
+#define PTP_DPC_CANON_EOS_PCWhiteBalance5	0xD144
+#define PTP_DPC_CANON_EOS_MWhiteBalance		0xD145
+#define PTP_DPC_CANON_EOS_PictureStyleStandard	0xD150
+#define PTP_DPC_CANON_EOS_PictureStylePortrait	0xD151
+#define PTP_DPC_CANON_EOS_PictureStyleLandscape	0xD152
+#define PTP_DPC_CANON_EOS_PictureStyleNeutral	0xD153
+#define PTP_DPC_CANON_EOS_PictureStyleFaithful	0xD154
+#define PTP_DPC_CANON_EOS_PictureStyleBlackWhite	0xD155
+#define PTP_DPC_CANON_EOS_PictureStyleUserSet1	0xD160
+#define PTP_DPC_CANON_EOS_PictureStyleUserSet2	0xD161
+#define PTP_DPC_CANON_EOS_PictureStyleUserSet3	0xD162
+#define PTP_DPC_CANON_EOS_PictureStyleParam1	0xD170
+#define PTP_DPC_CANON_EOS_PictureStyleParam2	0xD171
+#define PTP_DPC_CANON_EOS_PictureStyleParam3	0xD172
+#define PTP_DPC_CANON_EOS_FlavorLUTParams	0xD17f
+#define PTP_DPC_CANON_EOS_CustomFunc1		0xD180
+#define PTP_DPC_CANON_EOS_CustomFunc2		0xD181
+#define PTP_DPC_CANON_EOS_CustomFunc3		0xD182
+#define PTP_DPC_CANON_EOS_CustomFunc4		0xD183
+#define PTP_DPC_CANON_EOS_CustomFunc5		0xD184
+#define PTP_DPC_CANON_EOS_CustomFunc6		0xD185
+#define PTP_DPC_CANON_EOS_CustomFunc7		0xD186
+#define PTP_DPC_CANON_EOS_CustomFunc8		0xD187
+#define PTP_DPC_CANON_EOS_CustomFunc9		0xD188
+#define PTP_DPC_CANON_EOS_CustomFunc10		0xD189
+#define PTP_DPC_CANON_EOS_CustomFunc11		0xD18a
+#define PTP_DPC_CANON_EOS_CustomFunc12		0xD18b
+#define PTP_DPC_CANON_EOS_CustomFunc13		0xD18c
+#define PTP_DPC_CANON_EOS_CustomFunc14		0xD18d
+#define PTP_DPC_CANON_EOS_CustomFunc15		0xD18e
+#define PTP_DPC_CANON_EOS_CustomFunc16		0xD18f
+#define PTP_DPC_CANON_EOS_CustomFunc17		0xD190
+#define PTP_DPC_CANON_EOS_CustomFunc18		0xD191
+#define PTP_DPC_CANON_EOS_CustomFunc19		0xD192
+#define PTP_DPC_CANON_EOS_CustomFunc19		0xD192
+#define PTP_DPC_CANON_EOS_CustomFuncEx		0xD1a0
+#define PTP_DPC_CANON_EOS_MyMenu		0xD1a1
+#define PTP_DPC_CANON_EOS_MyMenuList		0xD1a2
+#define PTP_DPC_CANON_EOS_WftStatus		0xD1a3
+#define PTP_DPC_CANON_EOS_WftInputTransmission	0xD1a4
+#define PTP_DPC_CANON_EOS_HDDirectoryStructure	0xD1a5
+#define PTP_DPC_CANON_EOS_BatteryInfo		0xD1a6
+#define PTP_DPC_CANON_EOS_AdapterInfo		0xD1a7
+#define PTP_DPC_CANON_EOS_LensStatus		0xD1a8
+#define PTP_DPC_CANON_EOS_QuickReviewTime	0xD1a9
+#define PTP_DPC_CANON_EOS_CardExtension		0xD1aa
+#define PTP_DPC_CANON_EOS_TempStatus		0xD1ab
+#define PTP_DPC_CANON_EOS_ShutterCounter	0xD1ac
+#define PTP_DPC_CANON_EOS_SpecialOption		0xD1ad
+#define PTP_DPC_CANON_EOS_PhotoStudioMode	0xD1ae
+#define PTP_DPC_CANON_EOS_SerialNumber		0xD1af
+#define PTP_DPC_CANON_EOS_EVFOutputDevice	0xD1b0
+#define PTP_DPC_CANON_EOS_EVFMode		0xD1b1
+#define PTP_DPC_CANON_EOS_DepthOfFieldPreview	0xD1b2
+#define PTP_DPC_CANON_EOS_EVFSharpness		0xD1b3
+#define PTP_DPC_CANON_EOS_EVFWBMode		0xD1b4
+#define PTP_DPC_CANON_EOS_EVFClickWBCoeffs	0xD1b5
+#define PTP_DPC_CANON_EOS_EVFColorTemp		0xD1b6
+#define PTP_DPC_CANON_EOS_ExposureSimMode	0xD1b7
+#define PTP_DPC_CANON_EOS_EVFRecordStatus	0xD1b8
+#define PTP_DPC_CANON_EOS_LvAfSystem		0xD1ba
+#define PTP_DPC_CANON_EOS_MovSize		0xD1bb
+#define PTP_DPC_CANON_EOS_LvViewTypeSelect	0xD1bc
+#define PTP_DPC_CANON_EOS_Artist		0xD1d0
+#define PTP_DPC_CANON_EOS_Copyright		0xD1d1
+#define PTP_DPC_CANON_EOS_BracketValue		0xD1d2
+#define PTP_DPC_CANON_EOS_FocusInfoEx		0xD1d3
+#define PTP_DPC_CANON_EOS_DepthOfField		0xD1d4
+#define PTP_DPC_CANON_EOS_Brightness		0xD1d5
+#define PTP_DPC_CANON_EOS_LensAdjustParams	0xD1d6
+#define PTP_DPC_CANON_EOS_EFComp		0xD1d7
+#define PTP_DPC_CANON_EOS_LensName		0xD1d8
+#define PTP_DPC_CANON_EOS_AEB			0xD1d9
+#define PTP_DPC_CANON_EOS_StroboSetting		0xD1da
+#define PTP_DPC_CANON_EOS_StroboWirelessSetting	0xD1db
+#define PTP_DPC_CANON_EOS_StroboFiring		0xD1dc
+#define PTP_DPC_CANON_EOS_LensID		0xD1dd
+
+/* Nikon extension device property codes */
+#define PTP_DPC_NIKON_ShootingBank			0xD010
+#define PTP_DPC_NIKON_ShootingBankNameA 		0xD011
+#define PTP_DPC_NIKON_ShootingBankNameB			0xD012
+#define PTP_DPC_NIKON_ShootingBankNameC			0xD013
+#define PTP_DPC_NIKON_ShootingBankNameD			0xD014
+#define PTP_DPC_NIKON_ResetBank0			0xD015
+#define PTP_DPC_NIKON_RawCompression			0xD016
+#define PTP_DPC_NIKON_WhiteBalanceAutoBias		0xD017
+#define PTP_DPC_NIKON_WhiteBalanceTungstenBias		0xD018
+#define PTP_DPC_NIKON_WhiteBalanceFluorescentBias	0xD019
+#define PTP_DPC_NIKON_WhiteBalanceDaylightBias		0xD01A
+#define PTP_DPC_NIKON_WhiteBalanceFlashBias		0xD01B
+#define PTP_DPC_NIKON_WhiteBalanceCloudyBias		0xD01C
+#define PTP_DPC_NIKON_WhiteBalanceShadeBias		0xD01D
+#define PTP_DPC_NIKON_WhiteBalanceColorTemperature	0xD01E
+#define PTP_DPC_NIKON_WhiteBalancePresetNo		0xD01F
+#define PTP_DPC_NIKON_WhiteBalancePresetName0		0xD020
+#define PTP_DPC_NIKON_WhiteBalancePresetName1		0xD021
+#define PTP_DPC_NIKON_WhiteBalancePresetName2		0xD022
+#define PTP_DPC_NIKON_WhiteBalancePresetName3		0xD023
+#define PTP_DPC_NIKON_WhiteBalancePresetName4		0xD024
+#define PTP_DPC_NIKON_WhiteBalancePresetVal0		0xD025
+#define PTP_DPC_NIKON_WhiteBalancePresetVal1		0xD026
+#define PTP_DPC_NIKON_WhiteBalancePresetVal2		0xD027
+#define PTP_DPC_NIKON_WhiteBalancePresetVal3		0xD028
+#define PTP_DPC_NIKON_WhiteBalancePresetVal4		0xD029
+#define PTP_DPC_NIKON_ImageSharpening			0xD02A
+#define PTP_DPC_NIKON_ToneCompensation			0xD02B
+#define PTP_DPC_NIKON_ColorModel			0xD02C
+#define PTP_DPC_NIKON_HueAdjustment			0xD02D
+#define PTP_DPC_NIKON_NonCPULensDataFocalLength		0xD02E	/* Set FMM Manual */
+#define PTP_DPC_NIKON_NonCPULensDataMaximumAperture	0xD02F	/* Set F0 Manual */
+#define PTP_DPC_NIKON_ShootingMode			0xD030
+#define PTP_DPC_NIKON_JPEG_Compression_Policy		0xD031
+#define PTP_DPC_NIKON_ColorSpace			0xD032
+#define PTP_DPC_NIKON_AutoDXCrop			0xD033
+#define PTP_DPC_NIKON_CSMMenuBankSelect			0xD040
+#define PTP_DPC_NIKON_MenuBankNameA			0xD041
+#define PTP_DPC_NIKON_MenuBankNameB			0xD042
+#define PTP_DPC_NIKON_MenuBankNameC			0xD043
+#define PTP_DPC_NIKON_MenuBankNameD			0xD044
+#define PTP_DPC_NIKON_ResetBank				0xD045
+#define PTP_DPC_NIKON_A1AFCModePriority			0xD048
+#define PTP_DPC_NIKON_A2AFSModePriority			0xD049
+#define PTP_DPC_NIKON_A3GroupDynamicAF			0xD04A
+#define PTP_DPC_NIKON_A4AFActivation			0xD04B
+#define PTP_DPC_NIKON_FocusAreaIllumManualFocus		0xD04C
+#define PTP_DPC_NIKON_FocusAreaIllumContinuous		0xD04D
+#define PTP_DPC_NIKON_FocusAreaIllumWhenSelected 	0xD04E
+#define PTP_DPC_NIKON_FocusAreaWrap			0xD04F /* area sel */
+#define PTP_DPC_NIKON_VerticalAFON			0xD050
+#define PTP_DPC_NIKON_AFLockOn				0xD051
+#define PTP_DPC_NIKON_FocusAreaZone			0xD052
+#define PTP_DPC_NIKON_EnableCopyright			0xD053
+#define PTP_DPC_NIKON_ISOAuto				0xD054
+#define PTP_DPC_NIKON_EVISOStep				0xD055
+#define PTP_DPC_NIKON_EVStep				0xD056 /* EV Step SS FN */
+#define PTP_DPC_NIKON_EVStepExposureComp		0xD057
+#define PTP_DPC_NIKON_ExposureCompensation		0xD058
+#define PTP_DPC_NIKON_CenterWeightArea			0xD059
+#define PTP_DPC_NIKON_ExposureBaseMatrix		0xD05A
+#define PTP_DPC_NIKON_ExposureBaseCenter		0xD05B
+#define PTP_DPC_NIKON_ExposureBaseSpot			0xD05C
+#define PTP_DPC_NIKON_LiveViewAF			0xD05D
+#define PTP_DPC_NIKON_AELockMode			0xD05E
+#define PTP_DPC_NIKON_AELAFLMode			0xD05F
+#define PTP_DPC_NIKON_MeterOff				0xD062
+#define PTP_DPC_NIKON_SelfTimer				0xD063
+#define PTP_DPC_NIKON_MonitorOff			0xD064
+#define PTP_DPC_NIKON_ImgConfTime			0xD065
+#define PTP_DPC_NIKON_AngleLevel			0xD067
+#define PTP_DPC_NIKON_D1ShootingSpeed			0xD068 /* continous speed low */
+#define PTP_DPC_NIKON_D2MaximumShots			0xD069
+#define PTP_DPC_NIKON_D3ExpDelayMode			0xD06A
+#define PTP_DPC_NIKON_LongExposureNoiseReduction	0xD06B
+#define PTP_DPC_NIKON_FileNumberSequence		0xD06C
+#define PTP_DPC_NIKON_ControlPanelFinderRearControl	0xD06D
+#define PTP_DPC_NIKON_ControlPanelFinderViewfinder	0xD06E
+#define PTP_DPC_NIKON_D7Illumination			0xD06F
+#define PTP_DPC_NIKON_NrHighISO				0xD070
+#define PTP_DPC_NIKON_SHSET_CH_GUID_DISP		0xD071
+#define PTP_DPC_NIKON_ArtistName			0xD072
+#define PTP_DPC_NIKON_CopyrightInfo			0xD073
+#define PTP_DPC_NIKON_FlashSyncSpeed			0xD074
+#define PTP_DPC_NIKON_FlashShutterSpeed			0xD075	/* SB Low Limit */
+#define PTP_DPC_NIKON_E3AAFlashMode			0xD076
+#define PTP_DPC_NIKON_E4ModelingFlash			0xD077
+#define PTP_DPC_NIKON_BracketSet			0xD078	/* Bracket Type? */
+#define PTP_DPC_NIKON_E6ManualModeBracketing		0xD079	/* Bracket Factor? */
+#define PTP_DPC_NIKON_BracketOrder			0xD07A
+#define PTP_DPC_NIKON_E8AutoBracketSelection		0xD07B	/* Bracket Method? */
+#define PTP_DPC_NIKON_BracketingSet			0xD07C
+#define PTP_DPC_NIKON_F1CenterButtonShootingMode	0xD080
+#define PTP_DPC_NIKON_CenterButtonPlaybackMode		0xD081
+#define PTP_DPC_NIKON_F2Multiselector			0xD082
+#define PTP_DPC_NIKON_F3PhotoInfoPlayback		0xD083	/* MultiSelector Dir */
+#define PTP_DPC_NIKON_F4AssignFuncButton		0xD084  /* CMD Dial Rotate */
+#define PTP_DPC_NIKON_F5CustomizeCommDials		0xD085  /* CMD Dial Change */
+#define PTP_DPC_NIKON_ReverseCommandDial		0xD086  /* CMD Dial FN Set */
+#define PTP_DPC_NIKON_ApertureSetting			0xD087  /* CMD Dial Active */
+#define PTP_DPC_NIKON_MenusAndPlayback			0xD088  /* CMD Dial Active */
+#define PTP_DPC_NIKON_F6ButtonsAndDials			0xD089  /* Universal Mode? */
+#define PTP_DPC_NIKON_NoCFCard				0xD08A	/* Enable Shutter? */
+#define PTP_DPC_NIKON_CenterButtonZoomRatio		0xD08B
+#define PTP_DPC_NIKON_FunctionButton2			0xD08C
+#define PTP_DPC_NIKON_AFAreaPoint			0xD08D
+#define PTP_DPC_NIKON_NormalAFOn			0xD08E
+#define PTP_DPC_NIKON_ImageCommentString		0xD090
+#define PTP_DPC_NIKON_ImageCommentEnable		0xD091
+#define PTP_DPC_NIKON_ImageRotation			0xD092
+#define PTP_DPC_NIKON_ManualSetLensNo			0xD093
+#define PTP_DPC_NIKON_MovScreenSize			0xD0A0
+#define PTP_DPC_NIKON_MovVoice				0xD0A1
+#define PTP_DPC_NIKON_Bracketing			0xD0C0
+#define PTP_DPC_NIKON_AutoExposureBracketStep		0xD0C1
+#define PTP_DPC_NIKON_AutoExposureBracketProgram	0xD0C2
+#define PTP_DPC_NIKON_AutoExposureBracketCount		0xD0C3
+#define PTP_DPC_NIKON_WhiteBalanceBracketStep		0xD0C4
+#define PTP_DPC_NIKON_WhiteBalanceBracketProgram	0xD0C5
+#define PTP_DPC_NIKON_LensID				0xD0E0
+#define PTP_DPC_NIKON_LensSort				0xD0E1
+#define PTP_DPC_NIKON_LensType				0xD0E2
+#define PTP_DPC_NIKON_FocalLengthMin			0xD0E3
+#define PTP_DPC_NIKON_FocalLengthMax			0xD0E4
+#define PTP_DPC_NIKON_MaxApAtMinFocalLength		0xD0E5
+#define PTP_DPC_NIKON_MaxApAtMaxFocalLength		0xD0E6
+#define PTP_DPC_NIKON_FinderISODisp			0xD0F0
+#define PTP_DPC_NIKON_AutoOffPhoto			0xD0F2
+#define PTP_DPC_NIKON_AutoOffMenu			0xD0F3
+#define PTP_DPC_NIKON_AutoOffInfo			0xD0F4
+#define PTP_DPC_NIKON_SelfTimerShootNum			0xD0F5
+#define PTP_DPC_NIKON_VignetteCtrl			0xD0F7
+#define PTP_DPC_NIKON_ExposureTime			0xD100	/* Shutter Speed */
+#define PTP_DPC_NIKON_ACPower				0xD101
+#define PTP_DPC_NIKON_WarningStatus			0xD102
+#define PTP_DPC_NIKON_MaximumShots			0xD103 /* remain shots (in RAM buffer?) */
+#define PTP_DPC_NIKON_AFLockStatus			0xD104
+#define PTP_DPC_NIKON_AELockStatus			0xD105
+#define PTP_DPC_NIKON_FVLockStatus			0xD106
+#define PTP_DPC_NIKON_AutofocusLCDTopMode2		0xD107
+#define PTP_DPC_NIKON_AutofocusArea			0xD108
+#define PTP_DPC_NIKON_FlexibleProgram			0xD109
+#define PTP_DPC_NIKON_LightMeter			0xD10A	/* Exposure Status */
+#define PTP_DPC_NIKON_RecordingMedia			0xD10B	/* Card or SDRAM */
+#define PTP_DPC_NIKON_USBSpeed				0xD10C
+#define PTP_DPC_NIKON_CCDNumber				0xD10D
+#define PTP_DPC_NIKON_CameraOrientation			0xD10E
+#define PTP_DPC_NIKON_GroupPtnType			0xD10F
+#define PTP_DPC_NIKON_FNumberLock			0xD110
+#define PTP_DPC_NIKON_ExposureApertureLock		0xD111	/* shutterspeed lock*/
+#define PTP_DPC_NIKON_TVLockSetting			0xD112
+#define PTP_DPC_NIKON_AVLockSetting			0xD113
+#define PTP_DPC_NIKON_IllumSetting			0xD114
+#define PTP_DPC_NIKON_FocusPointBright			0xD115
+#define PTP_DPC_NIKON_ExternalFlashAttached		0xD120
+#define PTP_DPC_NIKON_ExternalFlashStatus		0xD121
+#define PTP_DPC_NIKON_ExternalFlashSort			0xD122
+#define PTP_DPC_NIKON_ExternalFlashMode			0xD123
+#define PTP_DPC_NIKON_ExternalFlashCompensation		0xD124
+#define PTP_DPC_NIKON_NewExternalFlashMode		0xD125
+#define PTP_DPC_NIKON_FlashExposureCompensation		0xD126
+#define PTP_DPC_NIKON_OptimizeImage			0xD140
+#define PTP_DPC_NIKON_Saturation			0xD142
+#define PTP_DPC_NIKON_BW_FillerEffect			0xD143
+#define PTP_DPC_NIKON_BW_Sharpness			0xD144
+#define PTP_DPC_NIKON_BW_Contrast			0xD145
+#define PTP_DPC_NIKON_BW_Setting_Type			0xD146
+#define PTP_DPC_NIKON_Slot2SaveMode			0xD148
+#define PTP_DPC_NIKON_RawBitMode			0xD149
+#define PTP_DPC_NIKON_ISOAutoTime			0xD14E
+#define PTP_DPC_NIKON_FlourescentType			0xD14F
+#define PTP_DPC_NIKON_TuneColourTemperature		0xD150
+#define PTP_DPC_NIKON_TunePreset0			0xD151
+#define PTP_DPC_NIKON_TunePreset1			0xD152
+#define PTP_DPC_NIKON_TunePreset2			0xD153
+#define PTP_DPC_NIKON_TunePreset3			0xD154
+#define PTP_DPC_NIKON_TunePreset4			0xD155
+#define PTP_DPC_NIKON_BeepOff				0xD160
+#define PTP_DPC_NIKON_AutofocusMode			0xD161
+#define PTP_DPC_NIKON_AFAssist				0xD163
+#define PTP_DPC_NIKON_PADVPMode				0xD164	/* iso auto time */
+#define PTP_DPC_NIKON_ImageReview			0xD165
+#define PTP_DPC_NIKON_AFAreaIllumination		0xD166
+#define PTP_DPC_NIKON_FlashMode				0xD167
+#define PTP_DPC_NIKON_FlashCommanderMode		0xD168
+#define PTP_DPC_NIKON_FlashSign				0xD169
+#define PTP_DPC_NIKON_ISO_Auto				0xD16A
+#define PTP_DPC_NIKON_RemoteTimeout			0xD16B
+#define PTP_DPC_NIKON_GridDisplay			0xD16C
+#define PTP_DPC_NIKON_FlashModeManualPower		0xD16D
+#define PTP_DPC_NIKON_FlashModeCommanderPower		0xD16E
+#define PTP_DPC_NIKON_AutoFP				0xD16F
+#define PTP_DPC_NIKON_CSMMenu				0xD180
+#define PTP_DPC_NIKON_WarningDisplay			0xD181
+#define PTP_DPC_NIKON_BatteryCellKind			0xD182
+#define PTP_DPC_NIKON_ISOAutoHiLimit			0xD183
+#define PTP_DPC_NIKON_DynamicAFArea			0xD184
+#define PTP_DPC_NIKON_ContinuousSpeedHigh		0xD186
+#define PTP_DPC_NIKON_InfoDispSetting			0xD187
+#define PTP_DPC_NIKON_PreviewButton			0xD189
+#define PTP_DPC_NIKON_PreviewButton2			0xD18A
+#define PTP_DPC_NIKON_AEAFLockButton2			0xD18B
+#define PTP_DPC_NIKON_IndicatorDisp			0xD18D
+#define PTP_DPC_NIKON_CellKindPriority			0xD18E
+#define PTP_DPC_NIKON_BracketingFramesAndSteps		0xD190
+#define PTP_DPC_NIKON_LiveViewMode			0xD1A0
+#define PTP_DPC_NIKON_LiveViewDriveMode			0xD1A1
+#define PTP_DPC_NIKON_LiveViewStatus			0xD1A2
+#define PTP_DPC_NIKON_LiveViewImageZoomRatio		0xD1A3
+#define PTP_DPC_NIKON_LiveViewProhibitCondition		0xD1A4
+#define PTP_DPC_NIKON_ExposureDisplayStatus		0xD1B0
+#define PTP_DPC_NIKON_ExposureIndicateStatus		0xD1B1
+#define PTP_DPC_NIKON_InfoDispErrStatus			0xD1B2
+#define PTP_DPC_NIKON_ExposureIndicateLightup		0xD1B3
+#define PTP_DPC_NIKON_FlashOpen				0xD1C0
+#define PTP_DPC_NIKON_FlashCharged			0xD1C1
+#define PTP_DPC_NIKON_FlashMRepeatValue			0xD1D0
+#define PTP_DPC_NIKON_FlashMRepeatCount			0xD1D1
+#define PTP_DPC_NIKON_FlashMRepeatInterval		0xD1D2
+#define PTP_DPC_NIKON_FlashCommandChannel		0xD1D3
+#define PTP_DPC_NIKON_FlashCommandSelfMode		0xD1D4
+#define PTP_DPC_NIKON_FlashCommandSelfCompensation	0xD1D5
+#define PTP_DPC_NIKON_FlashCommandSelfValue		0xD1D6
+#define PTP_DPC_NIKON_FlashCommandAMode			0xD1D7
+#define PTP_DPC_NIKON_FlashCommandACompensation		0xD1D8
+#define PTP_DPC_NIKON_FlashCommandAValue		0xD1D9
+#define PTP_DPC_NIKON_FlashCommandBMode			0xD1DA
+#define PTP_DPC_NIKON_FlashCommandBCompensation		0xD1DB
+#define PTP_DPC_NIKON_FlashCommandBValue		0xD1DC
+#define PTP_DPC_NIKON_ActivePicCtrlItem			0xD200
+#define PTP_DPC_NIKON_ChangePicCtrlItem			0xD201
+
+/* Microsoft/MTP specific */
+#define PTP_DPC_MTP_SecureTime				0xD101
+#define PTP_DPC_MTP_DeviceCertificate			0xD102
+#define PTP_DPC_MTP_RevocationInfo			0xD103
+#define PTP_DPC_MTP_SynchronizationPartner		0xD401
+#define PTP_DPC_MTP_DeviceFriendlyName			0xD402
+#define PTP_DPC_MTP_VolumeLevel				0xD403
+#define PTP_DPC_MTP_DeviceIcon				0xD405
+#define PTP_DPC_MTP_SessionInitiatorInfo		0xD406
+#define PTP_DPC_MTP_PerceivedDeviceType			0xD407
+#define PTP_DPC_MTP_PlaybackRate                        0xD410
+#define PTP_DPC_MTP_PlaybackObject                      0xD411
+#define PTP_DPC_MTP_PlaybackContainerIndex              0xD412
+#define PTP_DPC_MTP_PlaybackPosition                    0xD413
+#define PTP_DPC_MTP_PlaysForSureID                      0xD131
+
+/* Zune specific property codes */
+#define PTP_DPC_MTP_Zune_UnknownVersion			0xD181
+
+/* MTP specific Object Properties */
+#define PTP_OPC_StorageID				0xDC01
+#define PTP_OPC_ObjectFormat				0xDC02
+#define PTP_OPC_ProtectionStatus			0xDC03
+#define PTP_OPC_ObjectSize				0xDC04
+#define PTP_OPC_AssociationType				0xDC05
+#define PTP_OPC_AssociationDesc				0xDC06
+#define PTP_OPC_ObjectFileName				0xDC07
+#define PTP_OPC_DateCreated				0xDC08
+#define PTP_OPC_DateModified				0xDC09
+#define PTP_OPC_Keywords				0xDC0A
+#define PTP_OPC_ParentObject				0xDC0B
+#define PTP_OPC_AllowedFolderContents			0xDC0C
+#define PTP_OPC_Hidden					0xDC0D
+#define PTP_OPC_SystemObject				0xDC0E
+#define PTP_OPC_PersistantUniqueObjectIdentifier	0xDC41
+#define PTP_OPC_SyncID					0xDC42
+#define PTP_OPC_PropertyBag				0xDC43
+#define PTP_OPC_Name					0xDC44
+#define PTP_OPC_CreatedBy				0xDC45
+#define PTP_OPC_Artist					0xDC46
+#define PTP_OPC_DateAuthored				0xDC47
+#define PTP_OPC_Description				0xDC48
+#define PTP_OPC_URLReference				0xDC49
+#define PTP_OPC_LanguageLocale				0xDC4A
+#define PTP_OPC_CopyrightInformation			0xDC4B
+#define PTP_OPC_Source					0xDC4C
+#define PTP_OPC_OriginLocation				0xDC4D
+#define PTP_OPC_DateAdded				0xDC4E
+#define PTP_OPC_NonConsumable				0xDC4F
+#define PTP_OPC_CorruptOrUnplayable			0xDC50
+#define PTP_OPC_ProducerSerialNumber			0xDC51
+#define PTP_OPC_RepresentativeSampleFormat		0xDC81
+#define PTP_OPC_RepresentativeSampleSize		0xDC82
+#define PTP_OPC_RepresentativeSampleHeight		0xDC83
+#define PTP_OPC_RepresentativeSampleWidth		0xDC84
+#define PTP_OPC_RepresentativeSampleDuration		0xDC85
+#define PTP_OPC_RepresentativeSampleData		0xDC86
+#define PTP_OPC_Width					0xDC87
+#define PTP_OPC_Height					0xDC88
+#define PTP_OPC_Duration				0xDC89
+#define PTP_OPC_Rating					0xDC8A
+#define PTP_OPC_Track					0xDC8B
+#define PTP_OPC_Genre					0xDC8C
+#define PTP_OPC_Credits					0xDC8D
+#define PTP_OPC_Lyrics					0xDC8E
+#define PTP_OPC_SubscriptionContentID			0xDC8F
+#define PTP_OPC_ProducedBy				0xDC90
+#define PTP_OPC_UseCount				0xDC91
+#define PTP_OPC_SkipCount				0xDC92
+#define PTP_OPC_LastAccessed				0xDC93
+#define PTP_OPC_ParentalRating				0xDC94
+#define PTP_OPC_MetaGenre				0xDC95
+#define PTP_OPC_Composer				0xDC96
+#define PTP_OPC_EffectiveRating				0xDC97
+#define PTP_OPC_Subtitle				0xDC98
+#define PTP_OPC_OriginalReleaseDate			0xDC99
+#define PTP_OPC_AlbumName				0xDC9A
+#define PTP_OPC_AlbumArtist				0xDC9B
+#define PTP_OPC_Mood					0xDC9C
+#define PTP_OPC_DRMStatus				0xDC9D
+#define PTP_OPC_SubDescription				0xDC9E
+#define PTP_OPC_IsCropped				0xDCD1
+#define PTP_OPC_IsColorCorrected			0xDCD2
+#define PTP_OPC_ImageBitDepth				0xDCD3
+#define PTP_OPC_Fnumber					0xDCD4
+#define PTP_OPC_ExposureTime				0xDCD5
+#define PTP_OPC_ExposureIndex				0xDCD6
+#define PTP_OPC_DisplayName				0xDCE0
+#define PTP_OPC_BodyText				0xDCE1
+#define PTP_OPC_Subject					0xDCE2
+#define PTP_OPC_Priority				0xDCE3
+#define PTP_OPC_GivenName				0xDD00
+#define PTP_OPC_MiddleNames				0xDD01
+#define PTP_OPC_FamilyName				0xDD02
+#define PTP_OPC_Prefix					0xDD03
+#define PTP_OPC_Suffix					0xDD04
+#define PTP_OPC_PhoneticGivenName			0xDD05
+#define PTP_OPC_PhoneticFamilyName			0xDD06
+#define PTP_OPC_EmailPrimary				0xDD07
+#define PTP_OPC_EmailPersonal1				0xDD08
+#define PTP_OPC_EmailPersonal2				0xDD09
+#define PTP_OPC_EmailBusiness1				0xDD0A
+#define PTP_OPC_EmailBusiness2				0xDD0B
+#define PTP_OPC_EmailOthers				0xDD0C
+#define PTP_OPC_PhoneNumberPrimary			0xDD0D
+#define PTP_OPC_PhoneNumberPersonal			0xDD0E
+#define PTP_OPC_PhoneNumberPersonal2			0xDD0F
+#define PTP_OPC_PhoneNumberBusiness			0xDD10
+#define PTP_OPC_PhoneNumberBusiness2			0xDD11
+#define PTP_OPC_PhoneNumberMobile			0xDD12
+#define PTP_OPC_PhoneNumberMobile2			0xDD13
+#define PTP_OPC_FaxNumberPrimary			0xDD14
+#define PTP_OPC_FaxNumberPersonal			0xDD15
+#define PTP_OPC_FaxNumberBusiness			0xDD16
+#define PTP_OPC_PagerNumber				0xDD17
+#define PTP_OPC_PhoneNumberOthers			0xDD18
+#define PTP_OPC_PrimaryWebAddress			0xDD19
+#define PTP_OPC_PersonalWebAddress			0xDD1A
+#define PTP_OPC_BusinessWebAddress			0xDD1B
+#define PTP_OPC_InstantMessengerAddress			0xDD1C
+#define PTP_OPC_InstantMessengerAddress2		0xDD1D
+#define PTP_OPC_InstantMessengerAddress3		0xDD1E
+#define PTP_OPC_PostalAddressPersonalFull		0xDD1F
+#define PTP_OPC_PostalAddressPersonalFullLine1		0xDD20
+#define PTP_OPC_PostalAddressPersonalFullLine2		0xDD21
+#define PTP_OPC_PostalAddressPersonalFullCity		0xDD22
+#define PTP_OPC_PostalAddressPersonalFullRegion		0xDD23
+#define PTP_OPC_PostalAddressPersonalFullPostalCode	0xDD24
+#define PTP_OPC_PostalAddressPersonalFullCountry	0xDD25
+#define PTP_OPC_PostalAddressBusinessFull		0xDD26
+#define PTP_OPC_PostalAddressBusinessLine1		0xDD27
+#define PTP_OPC_PostalAddressBusinessLine2		0xDD28
+#define PTP_OPC_PostalAddressBusinessCity		0xDD29
+#define PTP_OPC_PostalAddressBusinessRegion		0xDD2A
+#define PTP_OPC_PostalAddressBusinessPostalCode		0xDD2B
+#define PTP_OPC_PostalAddressBusinessCountry		0xDD2C
+#define PTP_OPC_PostalAddressOtherFull			0xDD2D
+#define PTP_OPC_PostalAddressOtherLine1			0xDD2E
+#define PTP_OPC_PostalAddressOtherLine2			0xDD2F
+#define PTP_OPC_PostalAddressOtherCity			0xDD30
+#define PTP_OPC_PostalAddressOtherRegion		0xDD31
+#define PTP_OPC_PostalAddressOtherPostalCode		0xDD32
+#define PTP_OPC_PostalAddressOtherCountry		0xDD33
+#define PTP_OPC_OrganizationName			0xDD34
+#define PTP_OPC_PhoneticOrganizationName		0xDD35
+#define PTP_OPC_Role					0xDD36
+#define PTP_OPC_Birthdate				0xDD37
+#define PTP_OPC_MessageTo				0xDD40
+#define PTP_OPC_MessageCC				0xDD41
+#define PTP_OPC_MessageBCC				0xDD42
+#define PTP_OPC_MessageRead				0xDD43
+#define PTP_OPC_MessageReceivedTime			0xDD44
+#define PTP_OPC_MessageSender				0xDD45
+#define PTP_OPC_ActivityBeginTime			0xDD50
+#define PTP_OPC_ActivityEndTime				0xDD51
+#define PTP_OPC_ActivityLocation			0xDD52
+#define PTP_OPC_ActivityRequiredAttendees		0xDD54
+#define PTP_OPC_ActivityOptionalAttendees		0xDD55
+#define PTP_OPC_ActivityResources			0xDD56
+#define PTP_OPC_ActivityAccepted			0xDD57
+#define PTP_OPC_Owner					0xDD5D
+#define PTP_OPC_Editor					0xDD5E
+#define PTP_OPC_Webmaster				0xDD5F
+#define PTP_OPC_URLSource				0xDD60
+#define PTP_OPC_URLDestination				0xDD61
+#define PTP_OPC_TimeBookmark				0xDD62
+#define PTP_OPC_ObjectBookmark				0xDD63
+#define PTP_OPC_ByteBookmark				0xDD64
+#define PTP_OPC_LastBuildDate				0xDD70
+#define PTP_OPC_TimetoLive				0xDD71
+#define PTP_OPC_MediaGUID				0xDD72
+#define PTP_OPC_TotalBitRate				0xDE91
+#define PTP_OPC_BitRateType				0xDE92
+#define PTP_OPC_SampleRate				0xDE93
+#define PTP_OPC_NumberOfChannels			0xDE94
+#define PTP_OPC_AudioBitDepth				0xDE95
+#define PTP_OPC_ScanDepth				0xDE97
+#define PTP_OPC_AudioWAVECodec				0xDE99
+#define PTP_OPC_AudioBitRate				0xDE9A
+#define PTP_OPC_VideoFourCCCodec			0xDE9B
+#define PTP_OPC_VideoBitRate				0xDE9C
+#define PTP_OPC_FramesPerThousandSeconds		0xDE9D
+#define PTP_OPC_KeyFrameDistance			0xDE9E
+#define PTP_OPC_BufferSize				0xDE9F
+#define PTP_OPC_EncodingQuality				0xDEA0
+#define PTP_OPC_EncodingProfile				0xDEA1
+#define PTP_OPC_BuyFlag					0xD901
+
+/* WiFi Provisioning MTP Extension property codes */
+#define PTP_OPC_WirelessConfigurationFile		0xB104
+
+/* Device Property Form Flag */
+
+#define PTP_DPFF_None			0x00
+#define PTP_DPFF_Range			0x01
+#define PTP_DPFF_Enumeration		0x02
+
+/* Object Property Codes used by MTP (first 3 are same as DPFF codes) */
+#define PTP_OPFF_None			0x00
+#define PTP_OPFF_Range			0x01
+#define PTP_OPFF_Enumeration		0x02
+#define PTP_OPFF_DateTime		0x03
+#define PTP_OPFF_FixedLengthArray	0x04
+#define PTP_OPFF_RegularExpression	0x05
+#define PTP_OPFF_ByteArray		0x06
+#define PTP_OPFF_LongString		0xFF
+
+/* Device Property GetSet type */
+#define PTP_DPGS_Get			0x00
+#define PTP_DPGS_GetSet			0x01
+
+/* Glue stuff starts here */
+
+typedef struct _PTPParams PTPParams;
+
+
+typedef uint16_t (* PTPDataGetFunc)	(PTPParams* params, void*priv,
+					unsigned long wantlen,
+	                                unsigned char *data, unsigned long *gotlen);
+
+typedef uint16_t (* PTPDataPutFunc)	(PTPParams* params, void*priv,
+					unsigned long sendlen,
+	                                unsigned char *data, unsigned long *putlen);
+typedef struct _PTPDataHandler {
+	PTPDataGetFunc		getfunc;
+	PTPDataPutFunc		putfunc;
+	void			*priv;
+} PTPDataHandler;
+
+/*
+ * This functions take PTP oriented arguments and send them over an
+ * appropriate data layer doing byteorder conversion accordingly.
+ */
+typedef uint16_t (* PTPIOSendReq)	(PTPParams* params, PTPContainer* req);
+typedef uint16_t (* PTPIOSendData)	(PTPParams* params, PTPContainer* ptp,
+					 unsigned long size, PTPDataHandler*getter);
+
+typedef uint16_t (* PTPIOGetResp)	(PTPParams* params, PTPContainer* resp);
+typedef uint16_t (* PTPIOGetData)	(PTPParams* params, PTPContainer* ptp,
+	                                 PTPDataHandler *putter);
+typedef uint16_t (* PTPIOCancelReq)	(PTPParams* params, uint32_t transaction_id);
+
+/* debug functions */
+typedef void (* PTPErrorFunc) (void *data, const char *format, va_list args)
+#if (__GNUC__ >= 3)
+	__attribute__((__format__(printf,2,0)))
+#endif
+;
+typedef void (* PTPDebugFunc) (void *data, const char *format, va_list args)
+#if (__GNUC__ >= 3)
+	__attribute__((__format__(printf,2,0)))
+#endif
+;
+
+struct _PTPObject {
+	uint32_t	oid;
+	unsigned int	flags;
+#define PTPOBJECT_OBJECTINFO_LOADED	(1<<0)
+#define PTPOBJECT_CANONFLAGS_LOADED	(1<<1)
+#define PTPOBJECT_MTPPROPLIST_LOADED	(1<<2)
+#define PTPOBJECT_DIRECTORY_LOADED	(1<<3)
+#define PTPOBJECT_PARENTOBJECT_LOADED	(1<<4)
+#define PTPOBJECT_STORAGEID_LOADED	(1<<5)
+
+	PTPObjectInfo	oi;
+	uint32_t	canon_flags;
+	MTPProperties	*mtpprops;
+	int		nrofmtpprops;
+};
+typedef struct _PTPObject PTPObject;
+
+struct _PTPParams {
+	/* device flags */
+	uint32_t	device_flags;
+
+	/* data layer byteorder */
+	uint8_t		byteorder;
+	uint16_t	maxpacketsize;
+
+	/* PTP IO: Custom IO functions */
+	PTPIOSendReq	sendreq_func;
+	PTPIOSendData	senddata_func;
+	PTPIOGetResp	getresp_func;
+	PTPIOGetData	getdata_func;
+	PTPIOGetResp	event_check;
+	PTPIOGetResp	event_wait;
+	PTPIOCancelReq	cancelreq_func;
+
+	/* Custom error and debug function */
+	PTPErrorFunc	error_func;
+	PTPDebugFunc	debug_func;
+
+	/* Data passed to above functions */
+	void		*data;
+
+	/* ptp transaction ID */
+	uint32_t	transaction_id;
+	/* ptp session ID */
+	uint32_t	session_id;
+
+	/* PTP IO: if we have MTP style split header/data transfers */
+	int		split_header_data;
+
+	/* PTP: internal structures used by ptp driver */
+	PTPObject	*objects;
+	int		nrofobjects;
+
+	PTPDeviceInfo	deviceinfo;
+
+	/* PTP: the current event queue */
+	PTPContainer	*events;
+	int		nrofevents;
+
+	/* PTP: Canon specific flags list */
+	PTPCanon_Property	*canon_props;
+	int			nrofcanon_props;
+	int			canon_viewfinder_on;
+
+	/* PTP: Canon EOS event queue */
+	PTPCanon_changes_entry	*backlogentries;
+	int			nrofbacklogentries;
+	int			eos_captureenabled;
+
+	/* PTP: Wifi profiles */
+	uint8_t 	wifi_profiles_version;
+	uint8_t		wifi_profiles_number;
+	PTPNIKONWifiProfile *wifi_profiles;
+
+	/* IO: PTP/IP related data */
+	int		cmdfd, evtfd;
+	uint8_t		cameraguid[16];
+	uint32_t	eventpipeid;
+	char		*cameraname;
+
+#ifdef HAVE_ICONV
+	/* PTP: iconv converters */
+	iconv_t	cd_locale_to_ucs2;
+	iconv_t cd_ucs2_to_locale;
+#endif
+
+	/* IO: Sometimes the response packet get send in the dataphase
+	 * too. This only happens for a Samsung player now.
+	 */
+	uint8_t		*response_packet;
+	uint16_t	response_packet_size;
+};
+
+/* last, but not least - ptp functions */
+uint16_t ptp_usb_sendreq	(PTPParams* params, PTPContainer* req);
+uint16_t ptp_usb_senddata	(PTPParams* params, PTPContainer* ptp,
+				 unsigned long size, PTPDataHandler *handler);
+uint16_t ptp_usb_getresp	(PTPParams* params, PTPContainer* resp);
+uint16_t ptp_usb_getdata	(PTPParams* params, PTPContainer* ptp, 
+	                         PTPDataHandler *handler);
+uint16_t ptp_usb_event_check	(PTPParams* params, PTPContainer* event);
+uint16_t ptp_usb_event_wait	(PTPParams* params, PTPContainer* event);
+
+uint16_t ptp_usb_control_get_extended_event_data (PTPParams *params, char *buffer, int *size);
+uint16_t ptp_usb_control_device_reset_request (PTPParams *params);
+uint16_t ptp_usb_control_get_device_status (PTPParams *params, char *buffer, int *size);
+uint16_t ptp_usb_control_cancel_request (PTPParams *params, uint32_t transid);
+
+
+int      ptp_ptpip_connect	(PTPParams* params, const char *port);
+uint16_t ptp_ptpip_sendreq	(PTPParams* params, PTPContainer* req);
+uint16_t ptp_ptpip_senddata	(PTPParams* params, PTPContainer* ptp,
+				unsigned long size, PTPDataHandler *handler);
+uint16_t ptp_ptpip_getresp	(PTPParams* params, PTPContainer* resp);
+uint16_t ptp_ptpip_getdata	(PTPParams* params, PTPContainer* ptp, 
+	                         PTPDataHandler *handler);
+uint16_t ptp_ptpip_event_wait	(PTPParams* params, PTPContainer* event);
+uint16_t ptp_ptpip_event_check	(PTPParams* params, PTPContainer* event);
+
+uint16_t ptp_getdeviceinfo	(PTPParams* params, PTPDeviceInfo* deviceinfo);
+
+uint16_t ptp_generic_no_data	(PTPParams* params, uint16_t opcode, unsigned int cnt, ...);
+
+uint16_t ptp_opensession	(PTPParams *params, uint32_t session);
+
+/**
+ * ptp_closesession:
+ * params:      PTPParams*
+ *
+ * Closes session.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+#define ptp_closesession(params) ptp_generic_no_data(params,PTP_OC_CloseSession,0)
+/**
+ * ptp_resetdevice:
+ * params:      PTPParams*
+ *              
+ * Uses the built-in function to reset the device
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ */
+#define ptp_resetdevice(params) ptp_generic_no_data(params,PTP_OC_ResetDevice,0)
+
+uint16_t ptp_getstorageids	(PTPParams* params, PTPStorageIDs* storageids);
+uint16_t ptp_getstorageinfo 	(PTPParams* params, uint32_t storageid,
+				PTPStorageInfo* storageinfo);
+/**
+ * ptp_formatstore:
+ * params:      PTPParams*
+ *              storageid               - StorageID
+ *
+ * Formats the storage on the device.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+#define ptp_formatstore(params,storageid) ptp_generic_no_data(params,PTP_OC_FormatStore,1,storageid)
+
+uint16_t ptp_getobjecthandles 	(PTPParams* params, uint32_t storage,
+				uint32_t objectformatcode,
+				uint32_t associationOH,
+				PTPObjectHandles* objecthandles);
+
+uint16_t ptp_getnumobjects 	(PTPParams* params, uint32_t storage,
+				uint32_t objectformatcode,
+				uint32_t associationOH,
+				uint32_t* numobs);
+
+uint16_t ptp_getobjectinfo	(PTPParams *params, uint32_t handle,
+				PTPObjectInfo* objectinfo);
+
+uint16_t ptp_getobject		(PTPParams *params, uint32_t handle,
+				unsigned char** object);
+uint16_t ptp_getobject_tofd     (PTPParams* params, uint32_t handle, int fd);
+uint16_t ptp_getobject_to_handler (PTPParams* params, uint32_t handle, PTPDataHandler*);
+uint16_t ptp_getpartialobject	(PTPParams* params, uint32_t handle, uint32_t offset,
+				uint32_t maxbytes, unsigned char** object);
+uint16_t ptp_getthumb		(PTPParams *params, uint32_t handle,
+				unsigned char** object);
+
+uint16_t ptp_deleteobject	(PTPParams* params, uint32_t handle,
+				uint32_t ofc);
+
+uint16_t ptp_sendobjectinfo	(PTPParams* params, uint32_t* store,
+				uint32_t* parenthandle, uint32_t* handle,
+				PTPObjectInfo* objectinfo);
+/**
+ * ptp_setobjectprotection:
+ * params:      PTPParams*
+ *              uint16_t newprot        - object protection flag
+ *              
+ * Set protection of object.
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ */
+#define ptp_setobjectprotection(params,oid,newprot) ptp_generic_no_data(params,PTP_OC_SetObjectProtection,2,oid,newprot)
+uint16_t ptp_sendobject		(PTPParams* params, unsigned char* object,
+				 uint32_t size);
+uint16_t ptp_sendobject_fromfd  (PTPParams* params, int fd, uint32_t size);
+uint16_t ptp_sendobject_from_handler  (PTPParams* params, PTPDataHandler*, uint32_t size);
+/**
+ * ptp_initiatecapture:
+ * params:      PTPParams*
+ *              storageid               - destination StorageID on Responder
+ *              ofc                     - object format code
+ * 
+ * Causes device to initiate the capture of one or more new data objects
+ * according to its current device properties, storing the data into store
+ * indicated by storageid. If storageid is 0x00000000, the object(s) will
+ * be stored in a store that is determined by the capturing device.
+ * The capturing of new data objects is an asynchronous operation.
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+#define ptp_initiatecapture(params,storageid,ofc) ptp_generic_no_data(params,PTP_OC_InitiateCapture,2,storageid,ofc)
+
+uint16_t ptp_getdevicepropdesc	(PTPParams* params, uint16_t propcode,
+				PTPDevicePropDesc *devicepropertydesc);
+uint16_t ptp_getdevicepropvalue	(PTPParams* params, uint16_t propcode,
+				PTPPropertyValue* value, uint16_t datatype);
+uint16_t ptp_setdevicepropvalue (PTPParams* params, uint16_t propcode,
+                        	PTPPropertyValue* value, uint16_t datatype);
+
+
+uint16_t ptp_check_event (PTPParams *params);
+int ptp_get_one_event (PTPParams *params, PTPContainer *evt);
+
+/* Microsoft MTP extensions */
+uint16_t ptp_mtp_getobjectpropdesc (PTPParams* params, uint16_t opc, uint16_t ofc,
+				PTPObjectPropDesc *objectpropertydesc);
+uint16_t ptp_mtp_getobjectpropvalue (PTPParams* params, uint32_t oid, uint16_t opc, 
+				PTPPropertyValue *value, uint16_t datatype);
+uint16_t ptp_mtp_setobjectpropvalue (PTPParams* params, uint32_t oid, uint16_t opc,
+				PTPPropertyValue *value, uint16_t datatype);
+uint16_t ptp_mtp_getobjectreferences (PTPParams* params, uint32_t handle, uint32_t** ohArray, uint32_t* arraylen);
+uint16_t ptp_mtp_setobjectreferences (PTPParams* params, uint32_t handle, uint32_t* ohArray, uint32_t arraylen);
+uint16_t ptp_mtp_getobjectproplist (PTPParams* params, uint32_t handle, MTPProperties **props, int *nrofprops);
+uint16_t ptp_mtp_sendobjectproplist (PTPParams* params, uint32_t* store, uint32_t* parenthandle, uint32_t* handle,
+				     uint16_t objecttype, uint64_t objectsize, MTPProperties *props, int nrofprops);
+uint16_t ptp_mtp_setobjectproplist (PTPParams* params, MTPProperties *props, int nrofprops);
+
+/* Eastman Kodak extensions */
+uint16_t ptp_ek_9007 (PTPParams* params, unsigned char **serial, unsigned int *size);
+uint16_t ptp_ek_9009 (PTPParams* params, uint32_t*, uint32_t*);
+uint16_t ptp_ek_900c (PTPParams* params, unsigned char **serial, unsigned int *size);
+uint16_t ptp_ek_getserial (PTPParams* params, unsigned char **serial, unsigned int *size);
+uint16_t ptp_ek_setserial (PTPParams* params, unsigned char *serial, unsigned int size);
+uint16_t ptp_ek_settext (PTPParams* params, PTPEKTextParams *text);
+uint16_t ptp_ek_sendfileobjectinfo (PTPParams* params, uint32_t* store,
+				uint32_t* parenthandle, uint32_t* handle,
+				PTPObjectInfo* objectinfo);
+uint16_t ptp_ek_sendfileobject	(PTPParams* params, unsigned char* object,
+				uint32_t size);
+uint16_t ptp_ek_sendfileobject_from_handler	(PTPParams* params, PTPDataHandler*,
+				uint32_t size);
+
+/* Canon PTP extensions */
+#define ptp_canon_9012(params) ptp_generic_no_data(params,0x9012,0)
+uint16_t ptp_canon_gettreeinfo (PTPParams* params, uint32_t* out);
+uint16_t ptp_canon_gettreesize (PTPParams* params, PTPCanon_directtransfer_entry**, unsigned int*cnt);
+uint16_t ptp_canon_getpartialobjectinfo (PTPParams* params, uint32_t handle,
+				uint32_t p2, uint32_t* size, uint32_t* rp2);
+
+uint16_t ptp_canon_get_mac_address (PTPParams* params, unsigned char **mac);
+/**
+ * ptp_canon_startshootingmode:
+ * params:      PTPParams*
+ * 
+ * Starts shooting session. It emits a StorageInfoChanged
+ * event via the interrupt pipe and pushes the StorageInfoChanged
+ * and CANON_CameraModeChange events onto the event stack
+ * (see operation PTP_OC_CANON_CheckEvent).
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_startshootingmode(params) ptp_generic_no_data(params,PTP_OC_CANON_InitiateReleaseControl,0)
+/**
+ * ptp_canon_endshootingmode:
+ * params:      PTPParams*
+ * 
+ * This operation is observed after pressing the Disconnect 
+ * button on the Remote Capture app. It emits a StorageInfoChanged 
+ * event via the interrupt pipe and pushes the StorageInfoChanged
+ * and CANON_CameraModeChange events onto the event stack
+ * (see operation PTP_OC_CANON_CheckEvent).
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_endshootingmode(params) ptp_generic_no_data(params,PTP_OC_CANON_TerminateReleaseControl,0)
+/**
+ * ptp_canon_viewfinderon:
+ * params:      PTPParams*
+ * 
+ * Prior to start reading viewfinder images, one  must call this operation.
+ * Supposedly, this operation affects the value of the CANON_ViewfinderMode
+ * property.
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_viewfinderon(params) ptp_generic_no_data(params,PTP_OC_CANON_ViewfinderOn,0)
+/**
+ * ptp_canon_viewfinderoff:
+ * params:      PTPParams*
+ * 
+ * Before changing the shooting mode, or when one doesn't need to read
+ * viewfinder images any more, one must call this operation.
+ * Supposedly, this operation affects the value of the CANON_ViewfinderMode
+ * property.
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_viewfinderoff(params) ptp_generic_no_data(params,PTP_OC_CANON_ViewfinderOff,0)
+/**
+ * ptp_canon_reset_aeafawb:
+ * params:      PTPParams*
+ *              uint32_t flags  - what shall be reset.
+ *                      1 - autoexposure
+ *                      2 - autofocus
+ *                      4 - autowhitebalance
+ * 
+ * Called "Reset AeAfAwb" (auto exposure, focus, white balance)
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+#define PTP_CANON_RESET_AE	0x1
+#define PTP_CANON_RESET_AF	0x2
+#define PTP_CANON_RESET_AWB	0x4
+#define ptp_canon_reset_aeafawb(params,flags) ptp_generic_no_data(params,PTP_OC_CANON_DoAeAfAwb,1,flags)
+uint16_t ptp_canon_checkevent (PTPParams* params, 
+				PTPContainer* event, int* isevent);
+/**
+ * ptp_canon_focuslock:
+ *
+ * This operation locks the focus. It is followed by the CANON_GetChanges(?)
+ * operation in the log. 
+ * It affects the CANON_MacroMode property. 
+ *
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_focuslock(params) ptp_generic_no_data(params,PTP_OC_CANON_FocusLock,0)
+/**
+ * ptp_canon_focusunlock:
+ *
+ * This operation unlocks the focus. It is followed by the CANON_GetChanges(?)
+ * operation in the log. 
+ * It sets the CANON_MacroMode property value to 1 (where it occurs in the log).
+ * 
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_focusunlock(params) ptp_generic_no_data(params,PTP_OC_CANON_FocusUnlock,0)
+/**
+ * ptp_canon_keepdeviceon:
+ *
+ * This operation sends a "ping" style message to the camera.
+ * 
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_keepdeviceon(params) ptp_generic_no_data(params,PTP_OC_CANON_KeepDeviceOn,0)
+/**
+ * ptp_canon_eos_keepdeviceon:
+ *
+ * This operation sends a "ping" style message to the camera.
+ * 
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_eos_keepdeviceon(params) ptp_generic_no_data(params,PTP_OC_CANON_EOS_KeepDeviceOn,0)
+/**
+ * ptp_canon_initiatecaptureinmemory:
+ * 
+ * This operation starts the image capture according to the current camera
+ * settings. When the capture has happened, the camera emits a CaptureComplete
+ * event via the interrupt pipe and pushes the CANON_RequestObjectTransfer,
+ * CANON_DeviceInfoChanged and CaptureComplete events onto the event stack
+ * (see operation CANON_CheckEvent). From the CANON_RequestObjectTransfer
+ * event's parameter one can learn the just captured image's ObjectHandle.
+ * The image is stored in the camera's own RAM.
+ * On the next capture the image will be overwritten!
+ *
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_initiatecaptureinmemory(params) ptp_generic_no_data(params,PTP_OC_CANON_InitiateCaptureInMemory,0)
+/**
+ * ptp_canon_eos_requestdevicepropvalue:
+ *
+ * This operation sends a "ping" style message to the camera.
+ * 
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_eos_requestdevicepropvalue(params,prop) ptp_generic_no_data(params,PTP_OC_CANON_EOS_RequestDevicePropValue,1,prop)
+/**
+ * ptp_canon_eos_capture:
+ * 
+ * This starts a EOS400D style capture. You have to use the
+ * 0x9116 command to poll for its completion.
+ * The image is saved on the CF Card currently.
+ *
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_eos_capture(params) ptp_generic_no_data(params,PTP_OC_CANON_EOS_RemoteRelease,0)
+uint16_t ptp_canon_eos_getevent (PTPParams* params, PTPCanon_changes_entry **entries, int *nrofentries);
+uint16_t ptp_canon_getpartialobject (PTPParams* params, uint32_t handle, 
+				uint32_t offset, uint32_t size,
+				uint32_t pos, unsigned char** block, 
+				uint32_t* readnum);
+uint16_t ptp_canon_getviewfinderimage (PTPParams* params, unsigned char** image,
+				uint32_t* size);
+uint16_t ptp_canon_getchanges (PTPParams* params, uint16_t** props,
+				uint32_t* propnum); 
+uint16_t ptp_canon_getobjectinfo (PTPParams* params, uint32_t store,
+				uint32_t p2, uint32_t parenthandle,
+				uint32_t handle, 
+				PTPCANONFolderEntry** entries,
+				uint32_t* entnum);
+uint16_t ptp_canon_eos_getdeviceinfo (PTPParams* params, PTPCanonEOSDeviceInfo*di);
+/**
+ * ptp_canon_eos_setuilock:
+ *
+ * This command sets UI lock
+ *  
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_eos_setuilock(params) ptp_generic_no_data(params,PTP_OC_CANON_EOS_SetUILock,0)
+/**
+ * ptp_canon_eos_resetuilock:
+ *
+ * This command sets UI lock
+ *  
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_eos_resetuilock(params) ptp_generic_no_data(params,PTP_OC_CANON_EOS_ResetUILock,0)
+/**
+ * ptp_canon_eos_start_viewfinder:
+ *
+ * This command starts Viewfinder mode of newer Canon DSLRs.
+ *  
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_eos_start_viewfinder(params) ptp_generic_no_data(params,PTP_OC_CANON_EOS_InitiateViewfinder,0)
+/**
+ * ptp_canon_eos_end_viewfinder:
+ *
+ * This command ends Viewfinder mode of newer Canon DSLRs.
+ *  
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_eos_end_viewfinder(params) ptp_generic_no_data(params,PTP_OC_CANON_EOS_TerminateViewfinder,0)
+uint16_t ptp_canon_eos_get_viewfinder_image (PTPParams* params, unsigned char **data, unsigned int *size);
+uint16_t ptp_canon_get_objecthandle_by_name (PTPParams* params, char* name, uint32_t* objectid);
+uint16_t ptp_canon_get_directory (PTPParams* params, PTPObjectHandles *handles, PTPObjectInfo **oinfos, uint32_t **flags);
+/**
+ * ptp_canon_setobjectarchive:
+ *
+ * params:      PTPParams*
+ *              uint32_t        objectid
+ *              uint32_t        flags
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_setobjectarchive(params,oid,flags) ptp_generic_no_data(params,PTP_OC_CANON_SetObjectArchive,2,oid,flags)
+uint16_t ptp_canon_get_customize_data (PTPParams* params, uint32_t themenr,
+				unsigned char **data, unsigned int *size);
+uint16_t ptp_canon_getpairinginfo (PTPParams* params, uint32_t nr, unsigned char**, unsigned int*);
+
+uint16_t ptp_canon_eos_getstorageids (PTPParams* params, PTPStorageIDs* storageids);
+uint16_t ptp_canon_eos_getstorageinfo (PTPParams* params, uint32_t p1);
+uint16_t ptp_canon_eos_getpartialobject (PTPParams* params, uint32_t oid, uint32_t off, uint32_t xsize, unsigned char**data);
+uint16_t ptp_canon_eos_setdevicepropvalueex (PTPParams* params, unsigned char* data, unsigned int size);
+#define ptp_canon_eos_setremotemode(params,p1) ptp_generic_no_data(params,PTP_OC_CANON_EOS_SetRemoteMode,1,p1)
+#define ptp_canon_eos_seteventmode(params,p1) ptp_generic_no_data(params,PTP_OC_CANON_EOS_SetEventMode,1,p1)
+/**
+ * ptp_canon_eos_transfercomplete:
+ * 
+ * This ends a direct object transfer from an EOS camera.
+ *
+ * params:      PTPParams*
+ *              oid             Object ID
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ */
+#define ptp_canon_eos_transfercomplete(params,oid) ptp_generic_no_data(params,PTP_OC_CANON_EOS_TransferComplete,1,oid)
+/* inHDD = %d, inLength =%d, inReset = %d */
+#define ptp_canon_eos_pchddcapacity(params,p1,p2,p3) ptp_generic_no_data(params,PTP_OC_CANON_EOS_PCHDDCapacity,3,p1,p2,p3)
+#define ptp_canon_eos_bulbstart(params) ptp_generic_no_data(params,PTP_OC_CANON_EOS_BulbStart,1)
+#define ptp_canon_eos_bulbend(params) ptp_generic_no_data(params,PTP_OC_CANON_EOS_BulbEnd,1)
+uint16_t ptp_canon_eos_getdevicepropdesc (PTPParams* params, uint16_t propcode,
+				PTPDevicePropDesc *devicepropertydesc);
+uint16_t ptp_canon_eos_setdevicepropvalue (PTPParams* params, uint16_t propcode,
+                        	PTPPropertyValue* value, uint16_t datatype);
+uint16_t ptp_nikon_get_vendorpropcodes (PTPParams* params, uint16_t **props, unsigned int *size);
+uint16_t ptp_nikon_curve_download (PTPParams* params, 
+				unsigned char **data, unsigned int *size);
+uint16_t ptp_nikon_getptpipinfo (PTPParams* params, unsigned char **data, unsigned int *size);
+uint16_t ptp_nikon_getwifiprofilelist (PTPParams* params);
+uint16_t ptp_nikon_writewifiprofile (PTPParams* params, PTPNIKONWifiProfile* profile);
+/**
+ * ptp_nikon_deletewifiprofile:
+ *
+ * This command deletes a wifi profile.
+ *  
+ * params:      PTPParams*
+ *      unsigned int profilenr  - profile number
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_nikon_deletewifiprofile(params,profilenr) ptp_generic_no_data(params,PTP_OC_NIKON_DeleteProfile,1,profilenr)
+/**
+ * ptp_nikon_setcontrolmode:
+ *
+ * This command can switch the camera to full PC control mode.
+ *  
+ * params:      PTPParams*
+ *      uint32_t mode - mode
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_nikon_setcontrolmode(params,mode) ptp_generic_no_data(params,PTP_OC_NIKON_SetControlMode,1,mode)
+/**
+ * ptp_nikon_afdrive:
+ *
+ * This command runs (drives) the lens autofocus.
+ *  
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_nikon_afdrive(params) ptp_generic_no_data(params,PTP_OC_NIKON_AfDrive,0)
+/**
+ * ptp_nikon_mfdrive:
+ *
+ * This command runs (drives) the lens autofocus.
+ *  
+ * params:      PTPParams*
+ * flag:        0x1 for (no limit - closest), 0x2 for (closest - no limit)
+ * amount:      amount of steps
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_nikon_mfdrive(params,flag,amount) ptp_generic_no_data(params,PTP_OC_NIKON_MfDrive,2,flag,amount)
+/**
+ * ptp_nikon_capture:
+ *
+ * This command captures a picture on the Nikon.
+ *  
+ * params:      PTPParams*
+ *      uint32_t x - unknown parameter. seen to be -1.
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_nikon_capture(params,x) ptp_generic_no_data(params,PTP_OC_NIKON_Capture,1,x)
+/**
+ * ptp_nikon_capture_sdram:
+ *
+ * This command captures a picture on the Nikon.
+ *  
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_nikon_capture_sdram(params) ptp_generic_no_data(params,PTP_OC_NIKON_AfCaptureSDRAM,0)
+/**
+ * ptp_nikon_start_liveview:
+ *
+ * This command starts LiveView mode of newer Nikons DSLRs.
+ *  
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_nikon_start_liveview(params) ptp_generic_no_data(params,PTP_OC_NIKON_StartLiveView,0)
+uint16_t ptp_nikon_get_liveview_image (PTPParams* params, unsigned char**,unsigned int*);
+uint16_t ptp_nikon_get_preview_image (PTPParams* params, unsigned char**, unsigned int*, uint32_t*);
+/**
+ * ptp_nikon_end_liveview:
+ *
+ * This command ends LiveView mode of newer Nikons DSLRs.
+ *  
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_nikon_end_liveview(params) ptp_generic_no_data(params,PTP_OC_NIKON_EndLiveView,0)
+uint16_t ptp_nikon_check_event (PTPParams* params, PTPContainer **evt, int *evtcnt);
+uint16_t ptp_nikon_getfileinfoinblock (PTPParams* params, uint32_t p1, uint32_t p2, uint32_t p3,
+					unsigned char **data, unsigned int *size);
+/**
+ * ptp_nikon_device_ready:
+ *
+ * This command checks if the device is ready. Used after
+ * a capture.
+ *  
+ * params:      PTPParams*
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_nikon_device_ready(params) ptp_generic_no_data (params, PTP_OC_NIKON_DeviceReady, 0)
+uint16_t ptp_mtp_getobjectpropssupported (PTPParams* params, uint16_t ofc, uint32_t *propnum, uint16_t **props);
+
+/* Non PTP protocol functions */
+int ptp_operation_issupported	(PTPParams* params, uint16_t operation);
+int ptp_event_issupported	(PTPParams* params, uint16_t event);
+int ptp_property_issupported	(PTPParams* params, uint16_t property);
+
+void ptp_free_devicepropdesc	(PTPDevicePropDesc* dpd);
+void ptp_free_devicepropvalue	(uint16_t dt, PTPPropertyValue* dpd);
+void ptp_free_objectpropdesc	(PTPObjectPropDesc* dpd);
+void ptp_free_params		(PTPParams *params);
+void ptp_free_objectinfo	(PTPObjectInfo *oi);
+void ptp_free_object		(PTPObject *oi);
+
+void ptp_perror			(PTPParams* params, uint16_t error);
+
+const char*
+ptp_get_property_description(PTPParams* params, uint16_t dpc);
+
+int
+ptp_render_property_value(PTPParams* params, uint16_t dpc,
+                          PTPDevicePropDesc *dpd, int length, char *out);
+int ptp_render_ofc(PTPParams* params, uint16_t ofc, int spaceleft, char *txt);
+int ptp_render_opcode(PTPParams* params, uint16_t opcode, int spaceleft, char *txt);
+int ptp_render_mtp_propname(uint16_t propid, int spaceleft, char *txt);
+MTPProperties *ptp_get_new_object_prop_entry(MTPProperties **props, int *nrofprops);
+void ptp_destroy_object_prop(MTPProperties *prop);
+void ptp_destroy_object_prop_list(MTPProperties *props, int nrofprops);
+MTPProperties *ptp_find_object_prop_in_cache(PTPParams *params, uint32_t const handle, uint32_t const attribute_id);
+void ptp_remove_object_from_cache(PTPParams *params, uint32_t handle);
+uint16_t ptp_add_object_to_cache(PTPParams *params, uint32_t handle);
+uint16_t ptp_object_want (PTPParams *, uint32_t handle, int want, PTPObject**retob);
+void ptp_objects_sort (PTPParams *);
+uint16_t ptp_object_find (PTPParams *params, uint32_t handle, PTPObject **retob);
+uint16_t ptp_object_find_or_insert (PTPParams *params, uint32_t handle, PTPObject **retob);
+/* ptpip.c */
+void ptp_nikon_getptpipguid (unsigned char* guid);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __PTP_H__ */
diff --git a/src/unicode.c b/src/unicode.c
new file mode 100644
index 0000000..9b17c2b
--- /dev/null
+++ b/src/unicode.c
@@ -0,0 +1,173 @@
+/**
+ * \file unicode.c
+ *
+ * This file contains general Unicode string manipulation functions.
+ * It mainly consist of functions for converting between UCS-2 (used on
+ * the devices) and UTF-8 (used by several applications).
+ *
+ * For a deeper understanding of Unicode encoding formats see the
+ * Wikipedia entries for
+ * <a href="http://en.wikipedia.org/wiki/UTF-16/UCS-2">UTF-16/UCS-2</a>
+ * and <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a>.
+ *
+ * Copyright (C) 2005-2009 Linus Walleij <triad@df.lth.se>
+ *
+ * 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 <config.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_ICONV
+#include "iconv.h"
+#else
+#error "libmtp unicode.c needs fixing to work without iconv()!"
+#endif
+#include "libmtp.h"
+#include "unicode.h"
+#include "util.h"
+#include "ptp.h"
+
+/**
+ * The size of the buffer (in characters) used for creating string copies.
+ */
+#define STRING_BUFFER_LENGTH 1024
+
+/**
+ * Gets the length (in characters, not bytes) of a unicode
+ * UCS-2 string, eg a string which physically is 0x00 0x41 0x00 0x00
+ * will return a value of 1.
+ *
+ * @param unicstr a UCS-2 Unicode string
+ * @return the length of the string, in number of characters. If you
+ *         want to know the length in bytes, multiply this by two and
+ *         add two (for zero terminator).
+ */
+int ucs2_strlen(uint16_t const * const unicstr)
+{
+  int length;
+
+  /* Unicode strings are terminated with 2 * 0x00 */
+  for(length = 0; unicstr[length] != 0x0000U; length ++);
+  return length;
+}
+
+/**
+ * Converts a big-endian UTF-16 2-byte string
+ * to a UTF-8 string. Actually just a UCS-2 internal conversion
+ * routine that strips off the BOM if there is one.
+ *
+ * @param device a pointer to the current device.
+ * @param unicstr the UTF-16 unicode string to convert
+ * @return a UTF-8 string.
+ */
+char *utf16_to_utf8(LIBMTP_mtpdevice_t *device, const uint16_t *unicstr)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  char *stringp = (char *) unicstr;
+  char loclstr[STRING_BUFFER_LENGTH*3+1]; // UTF-8 encoding is max 3 bytes per UCS2 char.
+  char *locp = loclstr;
+  size_t nconv;
+  size_t convlen = (ucs2_strlen(unicstr)+1) * sizeof(uint16_t); // UCS-2 is 16 bit wide, include terminator
+  size_t convmax = STRING_BUFFER_LENGTH*3;
+
+  loclstr[0]='\0';
+  /* Do the conversion.  */
+  nconv = iconv(params->cd_ucs2_to_locale, &stringp, &convlen, &locp, &convmax);
+  if (nconv == (size_t) -1) {
+    // Return partial string anyway.
+    *locp = '\0';
+  }
+  loclstr[STRING_BUFFER_LENGTH*3] = '\0';
+  // Strip off any BOM, it's totally useless...
+  if ((uint8_t) loclstr[0] == 0xEFU && (uint8_t) loclstr[1] == 0xBBU && (uint8_t) loclstr[2] == 0xBFU) {
+    return strdup(loclstr+3);
+  }
+  return strdup(loclstr);
+}
+
+/**
+ * Converts a UTF-8 string to a big-endian UTF-16 2-byte string
+ * Actually just a UCS-2 internal conversion.
+ *
+ * @param device a pointer to the current device.
+ * @param localstr the UTF-8 unicode string to convert
+ * @return a UTF-16 string.
+ */
+uint16_t *utf8_to_utf16(LIBMTP_mtpdevice_t *device, const char *localstr)
+{
+  PTPParams *params = (PTPParams *) device->params;
+  char *stringp = (char *) localstr; // cast away "const"
+  char unicstr[(STRING_BUFFER_LENGTH+1)*2]; // UCS2 encoding is 2 bytes per UTF-8 char.
+  char *unip = unicstr;
+  size_t nconv = 0;
+  size_t convlen = strlen(localstr)+1; // utf8 bytes, include terminator
+  size_t convmax = STRING_BUFFER_LENGTH*2;
+
+  unicstr[0]='\0';
+  unicstr[1]='\0';
+
+  /* Do the conversion.  */
+  nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen, &unip, &convmax);
+
+  if (nconv == (size_t) -1) {
+    // Return partial string anyway.
+    unip[0] = '\0';
+    unip[1] = '\0';
+  }
+  // make sure the string is null terminated
+  unicstr[STRING_BUFFER_LENGTH*2] = '\0';
+  unicstr[STRING_BUFFER_LENGTH*2+1] = '\0';
+
+  // allocate the string to be returned
+  // Note: can't use strdup since every other byte is a null byte
+  int ret_len = ucs2_strlen((uint16_t*)unicstr)*sizeof(uint16_t)+2;
+  uint16_t* ret = malloc(ret_len);
+  memcpy(ret,unicstr,(size_t)ret_len);
+  return ret;
+}
+
+/**
+ * This helper function simply removes any consecutive chars
+ * > 0x7F and replace then with an underscore. In UTF-8
+ * consequtive chars > 0x7F represent one single character so
+ * it has to be done like this (and it's elegant). It will only
+ * shrink the string in size so no copying is needed.
+ */
+void strip_7bit_from_utf8(char *str)
+{
+  int i,j,k;
+  i = 0;
+  j = 0;
+  k = strlen(str);
+  while (i < k) {
+    if ((uint8_t) str[i] > 0x7FU) {
+      str[j] = '_';
+      i++;
+      // Skip over any consequtive > 0x7F chars.
+      while((uint8_t) str[i] > 0x7FU) {
+	i++;
+      }
+    } else {
+      str[j] = str[i];
+      i++;
+    }
+    j++;
+  }
+  // Terminate stripped string...
+  str[j] = '\0';
+}
diff --git a/src/unicode.h b/src/unicode.h
new file mode 100644
index 0000000..f612c32
--- /dev/null
+++ b/src/unicode.h
@@ -0,0 +1,40 @@
+/**
+ * \file unicode.h
+ *
+ * This file contains general Unicode string manipulation functions.
+ * It mainly consist of functions for converting between UCS-2 (used on
+ * the devices) and UTF-8 (used by several applications).
+ *
+ * For a deeper understanding of Unicode encoding formats see the
+ * Wikipedia entries for
+ * <a href="http://en.wikipedia.org/wiki/UTF-16/UCS-2">UTF-16/UCS-2</a>
+ * and <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a>.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ *
+ * 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.
+ *
+ */
+
+#ifndef __MTP__UNICODE__H
+#define __MTP__UNICODE__H
+
+int ucs2_strlen(uint16_t const * const);
+char *utf16_to_utf8(LIBMTP_mtpdevice_t*,const uint16_t*);
+uint16_t *utf8_to_utf16(LIBMTP_mtpdevice_t*, const char*);
+void strip_7bit_from_utf8(char *str);
+
+#endif /* __MTP__UNICODE__H */
diff --git a/src/util.c b/src/util.c
new file mode 100644
index 0000000..79ad79c
--- /dev/null
+++ b/src/util.c
@@ -0,0 +1,107 @@
+/**
+ * \file util.c
+ *
+ * This file contains generic utility functions such as can be
+ * used for debugging for example.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ *
+ * 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.
+ */
+
+/* MSVC does not have these */
+#ifndef _MSC_VER
+#include <sys/time.h>
+#include <unistd.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include "libmtp.h"
+#include "util.h"
+
+/**
+ * This dumps out a number of bytes to a textual, hexadecimal
+ * dump.
+ *
+ * @param f the file to dump to (e.g. stdout or stderr)
+ * @param buf a pointer to the buffer containing the bytes to
+ *            be dumped out in hex
+ * @param n the number of bytes to dump from this buffer
+ */
+void data_dump (FILE *f, void *buf, uint32_t n)
+{
+  unsigned char *bp = (unsigned char *) buf;
+  uint32_t i;
+  
+  for (i = 0; i < n; i++) {
+    fprintf(f, "%02x ", *bp);
+    bp++;
+  }
+  fprintf(f, "\n");
+}
+
+/**
+ * This dumps out a number of bytes to a textual, hexadecimal
+ * dump, and also prints out the string ASCII representation
+ * for each line of bytes. It will also print the memory address
+ * offset from a certain boundry.
+ *
+ * @param f the file to dump to (e.g. stdout or stderr)
+ * @param buf a pointer to the buffer containing the bytes to
+ *            be dumped out in hex
+ * @param n the number of bytes to dump from this buffer
+ * @param dump_boundry the address offset to start at (usually 0)
+ */
+void data_dump_ascii (FILE *f, void *buf, uint32_t n, uint32_t dump_boundry)
+{
+  uint32_t remain = n;
+  uint32_t ln, lc;
+  int i;
+  unsigned char *bp = (unsigned char *) buf;
+  
+  lc = 0;
+  while (remain) {
+    fprintf(f, "\t%04x:", dump_boundry-0x10);
+    
+    ln = ( remain > 16 ) ? 16 : remain;
+    
+    for (i = 0; i < ln; i++) {
+      if ( ! (i%2) ) fprintf(f, " ");
+      fprintf(f, "%02x", bp[16*lc+i]);
+    }
+    
+    if ( ln < 16 ) {
+      int width = ((16-ln)/2)*5 + (2*(ln%2));
+      fprintf(f, "%*.*s", width, width, "");
+    }
+    
+    fprintf(f, "\t");
+    for (i = 0; i < ln; i++) {
+      unsigned char ch= bp[16*lc+i];
+      fprintf(f, "%c", ( ch >= 0x20 && ch <= 0x7e ) ? 
+	      ch : '.');
+    }
+    fprintf(f, "\n");
+    
+    lc++;
+    remain -= ln;
+    dump_boundry += ln;
+  }
+}
diff --git a/src/util.h b/src/util.h
new file mode 100644
index 0000000..8066a60
--- /dev/null
+++ b/src/util.h
@@ -0,0 +1,29 @@
+/*
+ * \file util.h
+ * Utilityfunctions.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ *
+ * 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.
+ */
+
+#ifndef __MTP__UTIL__H
+#define __MTP__UTIL__H
+
+void data_dump(FILE *f, void *buf, uint32_t nbytes);
+void data_dump_ascii (FILE *f, void *buf, uint32_t n, uint32_t dump_boundry);
+
+#endif //__MTP__UTIL__H