Permalink
Browse files

Initial import of my local 4.x development code

--HG--
branch : Trunk
extra : convert_revision : svn%3A644ed5ae-bb15-0410-aa60-99f397bbb77a/Trunk%40292
  • Loading branch information...
0 parents commit 9a4d3e19b2825e97ee6230d4b31dcce8d6469cb8 starkos committed Apr 6, 2008
Showing with 28,060 additions and 0 deletions.
  1. +290 −0 CHANGES.txt
  2. +340 −0 LICENSE.txt
  3. +31 −0 README.txt
  4. +258 −0 doxyfile
  5. +130 −0 premake.lua
  6. +11 −0 premake4.lua
  7. +18 −0 src/action/action.c
  8. +18 −0 src/action/action.h
  9. +37 −0 src/action/make/gmake.c
  10. +56 −0 src/action/make/make.c
  11. +13 −0 src/action/make/make.h
  12. +34 −0 src/action/make/make_solution.c
  13. +13 −0 src/action/make/make_solution.h
  14. +58 −0 src/action/make/tests/make_tests.cpp
  15. +37 −0 src/action/vs200x/vs2002.c
  16. +37 −0 src/action/vs200x/vs2003.c
  17. +37 −0 src/action/vs200x/vs2005.c
  18. +34 −0 src/action/vs200x/vs200x_solution.c
  19. +13 −0 src/action/vs200x/vs200x_solution.h
  20. +111 −0 src/base/array.c
  21. +19 −0 src/base/array.h
  22. +7 −0 src/base/base.h
  23. +85 −0 src/base/buffers.c
  24. +14 −0 src/base/buffers.h
  25. +47 −0 src/base/cstr.c
  26. +12 −0 src/base/cstr.h
  27. +106 −0 src/base/dir.c
  28. +14 −0 src/base/dir.h
  29. +51 −0 src/base/error.c
  30. +13 −0 src/base/error.h
  31. +206 −0 src/base/path.c
  32. +16 −0 src/base/path.h
  33. +190 −0 src/base/stream.c
  34. +21 −0 src/base/stream.h
  35. +67 −0 src/base/string.c
  36. +15 −0 src/base/string.h
  37. +97 −0 src/base/strings.c
  38. +20 −0 src/base/strings.h
  39. +23 −0 src/base/tests/base_tests.cpp
  40. +68 −0 src/base/tests/cstr_tests.cpp
  41. +27 −0 src/base/tests/dir_tests.cpp
  42. +137 −0 src/base/tests/path_tests.cpp
  43. +64 −0 src/base/tests/stream_tests.cpp
  44. +46 −0 src/base/tests/string_tests.cpp
  45. +162 −0 src/engine/engine.c
  46. +11 −0 src/engine/engine.h
  47. +70 −0 src/engine/fn_dofile.c
  48. +18 −0 src/engine/fn_error.c
  49. +16 −0 src/engine/fn_getcwd.c
  50. +26 −0 src/engine/fn_include.c
  51. +55 −0 src/engine/fn_solution.c
  52. +68 −0 src/engine/internals.h
  53. +34 −0 src/engine/lua-5.1.2/COPYRIGHT
  54. +183 −0 src/engine/lua-5.1.2/HISTORY
  55. +99 −0 src/engine/lua-5.1.2/INSTALL
  56. +126 −0 src/engine/lua-5.1.2/Makefile
  57. +2 −0 src/engine/lua-5.1.2/PREMAKE_CHANGES.txt
  58. +37 −0 src/engine/lua-5.1.2/README
  59. BIN src/engine/lua-5.1.2/doc/amazon.gif
  60. +456 −0 src/engine/lua-5.1.2/doc/contents.html
  61. BIN src/engine/lua-5.1.2/doc/cover.png
  62. BIN src/engine/lua-5.1.2/doc/logo.gif
  63. +163 −0 src/engine/lua-5.1.2/doc/lua.1
  64. +41 −0 src/engine/lua-5.1.2/doc/lua.css
  65. +172 −0 src/engine/lua-5.1.2/doc/lua.html
  66. +136 −0 src/engine/lua-5.1.2/doc/luac.1
  67. +145 −0 src/engine/lua-5.1.2/doc/luac.html
  68. +7 −0 src/engine/lua-5.1.2/doc/manual.css
  69. +8,521 −0 src/engine/lua-5.1.2/doc/manual.html
  70. +40 −0 src/engine/lua-5.1.2/doc/readme.html
  71. +44 −0 src/engine/lua-5.1.2/etc/Makefile
  72. +37 −0 src/engine/lua-5.1.2/etc/README
  73. +38 −0 src/engine/lua-5.1.2/etc/all.c
  74. +9 −0 src/engine/lua-5.1.2/etc/lua.hpp
  75. BIN src/engine/lua-5.1.2/etc/lua.ico
  76. +31 −0 src/engine/lua-5.1.2/etc/lua.pc
  77. +15 −0 src/engine/lua-5.1.2/etc/luavs.bat
  78. +39 −0 src/engine/lua-5.1.2/etc/min.c
  79. +50 −0 src/engine/lua-5.1.2/etc/noparser.c
  80. +39 −0 src/engine/lua-5.1.2/etc/strict.lua
  81. +183 −0 src/engine/lua-5.1.2/src/Makefile
  82. +1,080 −0 src/engine/lua-5.1.2/src/lapi.c
  83. +16 −0 src/engine/lua-5.1.2/src/lapi.h
  84. +653 −0 src/engine/lua-5.1.2/src/lauxlib.c
  85. +174 −0 src/engine/lua-5.1.2/src/lauxlib.h
  86. +643 −0 src/engine/lua-5.1.2/src/lbaselib.c
  87. +839 −0 src/engine/lua-5.1.2/src/lcode.c
  88. +76 −0 src/engine/lua-5.1.2/src/lcode.h
  89. +397 −0 src/engine/lua-5.1.2/src/ldblib.c
  90. +622 −0 src/engine/lua-5.1.2/src/ldebug.c
  91. +33 −0 src/engine/lua-5.1.2/src/ldebug.h
  92. +516 −0 src/engine/lua-5.1.2/src/ldo.c
  93. +57 −0 src/engine/lua-5.1.2/src/ldo.h
  94. +164 −0 src/engine/lua-5.1.2/src/ldump.c
  95. +174 −0 src/engine/lua-5.1.2/src/lfunc.c
  96. +34 −0 src/engine/lua-5.1.2/src/lfunc.h
  97. +711 −0 src/engine/lua-5.1.2/src/lgc.c
  98. +110 −0 src/engine/lua-5.1.2/src/lgc.h
  99. +38 −0 src/engine/lua-5.1.2/src/linit.c
  100. +532 −0 src/engine/lua-5.1.2/src/liolib.c
  101. +461 −0 src/engine/lua-5.1.2/src/llex.c
  102. +81 −0 src/engine/lua-5.1.2/src/llex.h
  103. +128 −0 src/engine/lua-5.1.2/src/llimits.h
  104. +263 −0 src/engine/lua-5.1.2/src/lmathlib.c
  105. +86 −0 src/engine/lua-5.1.2/src/lmem.c
  106. +49 −0 src/engine/lua-5.1.2/src/lmem.h
  107. +664 −0 src/engine/lua-5.1.2/src/loadlib.c
  108. +214 −0 src/engine/lua-5.1.2/src/lobject.c
  109. +381 −0 src/engine/lua-5.1.2/src/lobject.h
  110. +102 −0 src/engine/lua-5.1.2/src/lopcodes.c
  111. +268 −0 src/engine/lua-5.1.2/src/lopcodes.h
  112. +244 −0 src/engine/lua-5.1.2/src/loslib.c
  113. +1,337 −0 src/engine/lua-5.1.2/src/lparser.c
  114. +82 −0 src/engine/lua-5.1.2/src/lparser.h
  115. +214 −0 src/engine/lua-5.1.2/src/lstate.c
  116. +168 −0 src/engine/lua-5.1.2/src/lstate.h
  117. +111 −0 src/engine/lua-5.1.2/src/lstring.c
  118. +31 −0 src/engine/lua-5.1.2/src/lstring.h
  119. +868 −0 src/engine/lua-5.1.2/src/lstrlib.c
  120. +588 −0 src/engine/lua-5.1.2/src/ltable.c
  121. +40 −0 src/engine/lua-5.1.2/src/ltable.h
  122. +278 −0 src/engine/lua-5.1.2/src/ltablib.c
  123. +75 −0 src/engine/lua-5.1.2/src/ltm.c
  124. +54 −0 src/engine/lua-5.1.2/src/ltm.h
  125. +390 −0 src/engine/lua-5.1.2/src/lua.c
Sorry, we could not display the entire diff because it was too big.
290 CHANGES.txt
@@ -0,0 +1,290 @@
+--------------------
+ 4.0 (in progress)
+--------------------
+This version is a complete rewrite of Premake.
+
+* New, more readable syntax for project information
+* Better validation of command-line arguments
+* Standardized path handling across all project settings
+* Upgraded to Lua 5.1.2
+
+--------------------
+ 3.5
+--------------------
+
+* Prevent creation of import libraries on OS X
+* Improved handling of dylibs on OS X
+* Patch 1771977: Ability to compile C source as C++ in Code::Blocks (Ryan Pusztai)
+* Patch 1771168: luaL_getn speed optimization (Richard O'Grady)
+* Bug 1804810: out-implib not present in linux gnu compler toolchain
+* Bug 1806949: .Net reference paths are broken when bindir is specified
+* Bug 1806960: Make clean does not remove .mdb files
+* Bug 1831389: Makefiles stored in subdirs contain no targets on first run
+
+--------------------
+ 3.4
+--------------------
+
+* Added `no-pch` flag to suppress precompiled headers
+* Added App.config support to GNU makefiles
+* Add os.mkdir() to script environment
+* Makefile now creates target directory before copying .NET references
+* Feature 1520182: Enhanced file-handling functions
+* Bug 531878: Problems with relative paths
+* Bug 1723867: Config-specific post-build on GNU target (Benoit Miller)
+* Bug 1596826: XML targets doesn't escape xml entities
+* Bug 1600155: Core dump due to newpackage() and matchfiles()
+* Bug 1608895: resgen command shown
+* Bug 1639730: Output filename is not set
+* Bug 1729227: non-portable executable with relative library path
+* Bug 1559951: default clean rule removes package dir
+* Patch 1733674: PCH support for Code::Block targets (Ryan Pusztai)
+* Patch 1746563: Ability to specify GUID for VS targets (Ryan Pusztai)
+* Patch 1754867: Creating import lib of different name (Ryan Pusztai)
+
+--------------------
+ 3.3
+--------------------
+
+* Added support for prebuild, prelink, and postbuild commands
+* Added `target` global variable to script environment
+* Added build flag `no-edit-and-continue`
+* Added build flags `native-wchar` and `no-native-wchar`
+* Added build flag `no-manifest`
+* Added build flag `seh-exceptions` (VS2005 only)
+* Added `resdefines`, `respaths`, and `resoptions`
+* Added `prebuildcommands`, `prelinkcommands`, and `postbuildcommands`
+* Added `pchheader` and `pchsource` (Visual Studio only)
+* Feature 1337547: Package-level bindir and libdir
+* Bug 1565755: Generated makefiles do not work with MSYS
+* Bug 1587955: Target path ignored for libs
+* Bug 1574725: Static library extension for "gnu" target
+* Bug 1522861: Fixed by using "ar -rcs" instead of "ar -cr && ranlib"
+* Bug 1656816: Mkdir set wrong directory rights
+* Bug 1655595: Compile/build problem on FreeBSD
+* Bug: "gnu" clean rule doesn't work in cmd.exe
+* Improved behavior of Linux findlib()
+* Updated Code::Blocks support to latest project version (major="1" minor="6")
+* Patch 1681666: GNU targets always show the console if kind = 'winexe'
+
+--------------------
+ 3.2
+--------------------
+
+* Added support for Code::Blocks
+* Updated MonoDevelop support
+* Upgraded Lua to 5.0.3
+* Added new matchdirs() to Lua script environment
+* Expose list of packages as _PACKAGES global in Lua
+* Turn off edit-and-continue in release builds with symbols
+* Bug 1559873: libpaths inserts extra space after -L
+
+--------------------
+ 3.1
+--------------------
+
+* Added support for Visual Studio 2005
+* Added support for Windows resources to GNU make target
+* Added path handling functions to Lua environment
+* Added matchrecursive() for recursive file searches
+* Added os.fileexists() function to Lua environment
+* Added os.appendfile() function to Lua environment
+* Changed `monoresgen` to `resgen` to keep up with Mono project
+* Added `mono2` .NET compiler set for Mono .NET 2.0 support
+* Feature 1096677: exclude files from matchfiles (package.excludes)
+* Bug 1439463: VS2003 RTTI problem
+* Bug 1439446: GNU Makefile problem under Mingw32
+* Bug 1422068: package.path="." causes bad makefiles
+* Bug 1431530: makefile target fails when project path specified
+
+--------------------
+ 3.0
+--------------------
+
+* Upgraded Lua interpreter to version 5.0.1
+* The options table now stores simple values, rather than tables
+* Completed MonoDevelop support
+* Improved .NET resource handling for GNU generator
+* Added unit test suite
+* Merged Scott Graham unicode build flag patch
+* Removed package.warninglevel in favor of extra-warnings flag
+* Added package.targetprefix
+* Overhauled structure of generated GNU makefiles
+* Added --os command line option
+* Fixed bug 1268588: Use gcc to link C packages
+* Fixed bug 1363306: GNU C# should copy referenced DLLs
+
+--------------------
+ 2.4
+--------------------
+
+* Added chdir() to Lua script environment
+* Merged Thomas Harning's patch for .NET resources on GNU
+* Fixed bug 1194702: Can't put multiple packages in same directory
+* Fixed bug in GNU shared library builds (doh!)
+* Added target 'vs2002' to replace 'vs7'
+
+--------------------
+ 2.3
+--------------------
+
+* Added 'project.config[]' with 'bindir' and 'libdir'
+* Merged Scott Graham's "warninglevel" patch.
+* Fixed bug 1153484: Import lib in wrong directory.
+* Fixed bug 1013352: Stack overflow with large projects.
+* Fixed bug 945406: package.files, bad value = crash
+
+--------------------
+ 2.2
+--------------------
+
+* Worked around VS.NET bug for .NET assemblies > 64K.
+* Added --very-verbose flag to GNU generator.
+* GNU generator now supports assembly sources.
+
+--------------------
+ 2.1
+--------------------
+
+* File extension of generated binaries can now be set
+ with config.targetextension.
+* Windows targets now handle .def files for DLLs.
+
+--------------------
+ 2.0
+--------------------
+
+* Can now specify build actions per file
+* Include paths are now passed to VC7 resource compiler
+* Removed _WIN32 define from Cygwin makefiles
+* Added package.objdir to set intermediates directory
+* Added rmdir() to Lua script environment
+* A big bag of bug fixes
+
+--------------------
+ 1.9
+--------------------
+
+* Made verbose mode even more verbose.
+* posix.c now builds properly as C.
+* Fixed package dependency generation for GNU and VS2003.
+* Display Lua version number in usage text.
+* Fixed VS link between *.aspx and *.aspx.cs files.
+* Fixed VS link between *.resx and *.cs files.
+* Fixed *.d file generation for gcc 2.9x.
+* Unified various help options under '--help'.
+* Bin and Lib paths can now be arbitrarily long.
+* linkoptions are now applied in VC6 and VC7 projects.
+
+--------------------
+ 1.8
+--------------------
+
+* Added support for ASP.NET projects.
+* Fixed a bug in VC6 support for static libraries.
+* matchfiles() now uses package path instead of script path.
+* Added --verbose option.
+* No longer apply no-rtti and no-exceptions to *.c files.
+
+--------------------
+ 1.7
+--------------------
+
+* Location of generated project files can now be specified with
+ the project.path variable.
+* Inter-package dependencies are fixed for GNU makefiles.
+* No longer need to execute in same directory as project script.
+* Added "c" language specifier.
+* Added support for .resx and .config files to C# projects.
+* Added support for full assembly names in .NET references.
+* Fixed handling of paths in package.target variable.
+* Improved support for SharpDevelop.
+* Started support for OS X.
+* Added support for Digital Mars compiler.
+
+--------------------
+ 1.6
+--------------------
+
+* VS7 generator crashed if a package was built before one of its
+ dependencies. Now immediately assigns UUID before processing.
+* Added support for Visual Studio 2003 and SharpDevelop.
+* Added binaries directory as a reference path for VS7.
+
+--------------------
+ 1.5
+--------------------
+
+* Added initial support for building static libraries.
+* Added "no-main" flag, prevents overriding WinMain() on
+ Windows builds.
+* Added "--no-rtti" and "no-exceptions" build flags to
+ disable those C++ features.
+* Display error message when project has no packages.
+* Moved VC7 *.pdb files into intermediates directory.
+
+--------------------
+ 1.4
+--------------------
+
+* Bug fixes to the path manipulation routines.
+* GNU makefiles are regenerated when premake scripts change.
+
+--------------------
+ 1.3
+--------------------
+
+* Added support for the Cygwin environment.
+* Added "static-runtime" build flag to statically link against C/C++
+ standard runtime libraries.
+* Bug fixes to Visual Studio 6 and 7 generators and path reversing
+ algorithm.
+
+--------------------
+ 1.2
+--------------------
+
+* Standardized format of command-line options.
+* Can now handle custom command-line options in script.
+* Added new function findlib().
+* Added new C++ build flag "managed" for writing C++ .NET code.
+* Can now use open-source C# compilers in VS6 generator.
+* Several bug fixes to the VS7 generator.
+
+--------------------
+ 1.1
+--------------------
+
+* Added support for custom build configurations. Added "optimize",
+ "optimize-size", "optimize-speed", and "no-symbols" flags to control
+ build settings.
+* Added matchfiles() to select files using wildcards.
+* Added "unsafe" flag for C# projects.
+* Added newpackage() function for creating new package objects inline,
+ instead of creating separate scripts.
+* Changed include() to dopackage() and option() to addoption(). The old
+ versions have been kept for compatibility, but will be deprecated
+ eventually.
+* Major cleanup of the source code.
+
+--------------------
+ 1.0
+--------------------
+
+* Fixed a bug related to the reference paths in VS7 C# projects.
+* Display a warning message if a reference path can't be found.
+* Automatically create bin and lib directories if they do not exist.
+* GNU C# projects will now properly use the configured library paths.
+* Added --with-mono and --with-pnet options.
+* VS7 C# projects will now properly use the configured library paths.
+* Switched to Lua (http://www.lua.org/) for project script parsing.
+* Add support for custom project options.
+* Changed 'type' to 'kind' to avoid conflict with Lua function of the same name.
+* Changed 'conexe' to 'exe' because I liked it better.
+* Changed 'library' to 'dll' for C# projects to keep things consistent.
+
+--------------------
+ 0.9
+--------------------
+
+* Initial public release.
340 LICENSE.txt
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 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.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, 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 or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+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 give any other recipients of the Program a copy of this License
+along with the Program.
+
+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 Program or any portion
+of it, thus forming a work based on the Program, 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) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+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 Program, 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 Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) 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; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, 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 executable. However, as a
+special exception, the source code 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.
+
+If distribution of executable or 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 counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program 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.
+
+ 5. 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 Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program 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 to
+this License.
+
+ 7. 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 Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program 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 Program.
+
+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.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program 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.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the 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 Program
+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 Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, 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
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "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 PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. 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 PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), 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 Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. 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 program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
31 README.txt
@@ -0,0 +1,31 @@
+PREMAKE
+A build configuration tool
+
+ Copyright (C) 2002-2008 by Jason Perkins
+ Distributed under the GNU General Public License, see LICENSE.txt
+
+ The Lua language and runtime library is (C) TeCGraf, PUC-Rio.
+ See their website at http://www.lua.org/
+
+
+BUILDING PREMAKE
+
+ Until an official release is made you will need to use an existing
+ Premake 3.x executable to generate the project files. Grab a binary
+ or executable package from the project site at:
+
+ http://premake.sourceforge.net/
+
+ Then use it to create the project files for your particular toolset.
+
+ $ cd premake-4.0
+ $ premake --target vs2005 # For Visual Studio 2005 files
+
+ Run `premake --help` for a complete list of supported toolsets.
+
+
+
+SUPPORT
+
+ For questions, comments, or more information, visit the project
+ website at http://industriousone.com/premake
258 doxyfile
@@ -0,0 +1,258 @@
+# Doxyfile 1.5.1-p1
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+PROJECT_NAME = "Premake Internals"
+PROJECT_NUMBER =
+OUTPUT_DIRECTORY = doc
+CREATE_SUBDIRS = NO
+OUTPUT_LANGUAGE = English
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF = "The $name class" \
+ "The $name widget" \
+ "The $name file" \
+ is \
+ provides \
+ specifies \
+ contains \
+ represents \
+ a \
+ an \
+ the
+ALWAYS_DETAILED_SEC = YES
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = NO
+STRIP_FROM_PATH = ""
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = NO
+MULTILINE_CPP_IS_BRIEF = NO
+DETAILS_AT_TOP = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 4
+ALIASES =
+OPTIMIZE_OUTPUT_FOR_C = YES
+OPTIMIZE_OUTPUT_JAVA = NO
+BUILTIN_STL_SUPPORT = NO
+DISTRIBUTE_GROUP_DOC = NO
+SUBGROUPING = YES
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = NO
+EXTRACT_PRIVATE = NO
+EXTRACT_STATIC = NO
+EXTRACT_LOCAL_CLASSES = YES
+EXTRACT_LOCAL_METHODS = NO
+HIDE_UNDOC_MEMBERS = YES
+HIDE_UNDOC_CLASSES = YES
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = NO
+HIDE_SCOPE_NAMES = NO
+SHOW_INCLUDE_FILES = YES
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_BY_SCOPE_NAME = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+GENERATE_DEPRECATEDLIST= YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_DIRECTORIES = NO
+FILE_VERSION_FILTER =
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = YES
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT = src
+FILE_PATTERNS = *.c \
+ *.cc \
+ *.cxx \
+ *.cpp \
+ *.c++ \
+ *.d \
+ *.java \
+ *.ii \
+ *.ixx \
+ *.ipp \
+ *.i++ \
+ *.inl \
+ *.h \
+ *.hh \
+ *.hxx \
+ *.hpp \
+ *.h++ \
+ *.idl \
+ *.odl \
+ *.cs \
+ *.php \
+ *.php3 \
+ *.inc \
+ *.m \
+ *.mm \
+ *.dox \
+ *.py
+RECURSIVE = YES
+EXCLUDE =
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS = */UnitTest++/* */lua-5.1.1/*
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS = *
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = NO
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = NO
+REFERENCES_RELATION = NO
+REFERENCES_LINK_SOURCE = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = NO
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = NO
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_ALIGN_MEMBERS = YES
+GENERATE_HTMLHELP = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+BINARY_TOC = NO
+TOC_EXPAND = NO
+DISABLE_INDEX = NO
+ENUM_VALUES_PER_LINE = 4
+GENERATE_TREEVIEW = NO
+TREEVIEW_WIDTH = 250
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4wide
+EXTRA_PACKAGES =
+LATEX_HEADER =
+PDF_HYPERLINKS = NO
+USE_PDFLATEX = NO
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_SCHEMA =
+XML_DTD =
+XML_PROGRAMLISTING = YES
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = NO
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED =
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = NO
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = NO
+CLASS_GRAPH = YES
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = NO
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = NO
+CALLER_GRAPH = NO
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+DOT_PATH =
+DOTFILE_DIRS =
+MAX_DOT_GRAPH_DEPTH = 1000
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to the search engine
+#---------------------------------------------------------------------------
+SEARCHENGINE = NO
130 premake.lua
@@ -0,0 +1,130 @@
+project.name = "Premake4"
+
+-- Project options
+
+ addoption("no-tests", "Build without automated tests")
+
+
+-- Output directories
+
+ project.config["Debug"].bindir = "bin/debug"
+ project.config["Release"].bindir = "bin/release"
+
+
+-- Packages
+
+ dopackage("src")
+
+
+-- Cleanup code
+
+ function doclean(cmd, arg)
+ docommand(cmd, arg)
+ os.rmdir("bin")
+ os.rmdir("doc")
+ end
+
+
+-- Release code
+
+ REPOS = "file://.psf/.Mac/Users/jason/Svn/Premake"
+ TRUNK = "/trunk"
+ BRANCHES = "/branches/4.0-alpha/"
+
+ function userinput(prompt)
+ if (prompt) then print(prompt) end
+ io.stdout:write("> ")
+ local value = io.stdin:read("*l")
+ print("")
+ return value
+ end
+
+ function dobuildrelease(cmd, arg)
+ os.mkdir("releases")
+ os.chdir("releases")
+
+ -------------------------------------------------------------------
+ -- TODO: get the version from the command line instead
+ -------------------------------------------------------------------
+ local version = userinput("What is the version number for this release?")
+
+ local folder = "premake-"..version
+ local trunk = REPOS..TRUNK
+ local branch = REPOS..BRANCHES..version
+
+ -------------------------------------------------------------------
+ -- Make sure everything is good before I start
+ -------------------------------------------------------------------
+ print("")
+ print("PRE-FLIGHT CHECKLIST")
+ print(" * is README up-to-date?")
+ print(" * is CHANGELOG up-to-date?")
+ print(" * did you test build with GCC?")
+ print(" * did you test run Doxygen?")
+ print(" * TODO: automate test for 'svn' (all), '7z', MinGW (Windows)")
+ userinput()
+
+ -------------------------------------------------------------------
+ -- Look for a release branch in SVN, and create one from trunk if necessary
+ -------------------------------------------------------------------
+ print("Checking for release branch...")
+ result = os.execute(string.format("svn ls %s >release.log 2>&1", branch))
+ if (result ~= 0) then
+ print("Creating release branch...")
+ result = os.execute(string.format('svn copy %s %s -m "Creating release branch for %s" >release.log', trunk, branch, version))
+ if (result ~= 0) then
+ error("Failed to create release branch at "..branch)
+ end
+ end
+
+ -------------------------------------------------------------------
+ -- Checkout a local copy of the release branch
+ -------------------------------------------------------------------
+ print("Getting source code from release branch...")
+ os.execute(string.format("svn co %s %s >release.log", branch, folder))
+ if (not os.fileexists(folder.."/README.txt")) then
+ error("Unable to checkout from repository at "..branch)
+ end
+
+ -------------------------------------------------------------------
+ -- Build and run all automated tests
+ -------------------------------------------------------------------
+ print("Building test version...")
+ os.chdir(folder)
+ os.execute("premake --target gnu > ../release.log")
+ result = os.execute("make CONFIG=Release >../release.log")
+ if (result ~= 0) then
+ error("Test build failed; see release.log for details")
+ end
+
+ -------------------------------------------------------------------
+ -- Embed version numbers into the files
+ -------------------------------------------------------------------
+ print("TODO - set version number in premake")
+
+ -------------------------------------------------------------------
+ -- Build the release binary for this platform
+ -------------------------------------------------------------------
+ print("Building release version...")
+ os.execute("premake --clean --no-tests --target gnu >../release.log")
+ os.execute("make CONFIG=Release >../release.log")
+
+ if (windows) then
+ result = os.execute(string.format("7z a -tzip ..\\premake-win32-%s.zip bin\\release\\premake4.exe >../release.log", version))
+ elseif (macosx) then
+ error("OSX not done yet")
+ else
+ error("Linux not done yet")
+ end
+
+ if (result ~= 0) then
+ error("Failed to build binary package; see release.log for details")
+ end
+
+ print("Cleaning up...")
+ os.chdir("..")
+ os.rmdir(folder)
+ os.remove("release.log")
+
+ end
+
11 premake4.lua
@@ -0,0 +1,11 @@
+---------------------------------------------------------------------------
+-- Premake4 solution script for Premake4
+-- Copyright (c) 2002-2008 Jason Perkins and the Premake project
+---------------------------------------------------------------------------
+
+solution "Premake4"
+
+include "src"
+
+
+
18 src/action/action.c
@@ -0,0 +1,18 @@
+/**
+ * \file action.c
+ * \brief Built-in engine actions.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+
+#include "premake.h"
+#include "action/action.h"
+
+
+SessionAction Actions[] =
+{
+ { "gmake", "GNU Makefiles for POSIX, MinGW, and Cygwin", gmake_action },
+ { "vs2002", "Microsoft Visual Studio 2002", vs2002_action },
+ { "vs2003", "Microsoft Visual Studio 2003", vs2003_action },
+ { "vs2005", "Microsoft Visual Studio 2005 (includes Express editions)", vs2005_action },
+ { 0, 0, 0 }
+};
18 src/action/action.h
@@ -0,0 +1,18 @@
+/**
+ * \file action.h
+ * \brief Built-in engine actions.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+#if !defined(PREMAKE_ACTION_H)
+#define PREMAKE_ACTION_H
+
+#include "engine/session.h"
+
+extern SessionAction Actions[];
+
+int gmake_action(Session sess);
+int vs2002_action(Session sess);
+int vs2003_action(Session sess);
+int vs2005_action(Session sess);
+
+#endif
37 src/action/make/gmake.c
@@ -0,0 +1,37 @@
+/**
+ * \file gmake.c
+ * \brief GNU makefile generation action.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+
+#include <stdlib.h>
+#include "premake.h"
+#include "action/action.h"
+#include "make_solution.h"
+
+
+/** The GNU make solution writing process, for session_enumerate_objects() */
+static SessionSolutionCallback GmakeSolutionCallbacks[] =
+{
+ make_solution_create,
+ NULL
+};
+
+/** The GNU make project writing process, for session_enumerate_objects() */
+static SessionProjectCallback GmakeProjectCallbacks[] =
+{
+ NULL
+};
+
+
+/**
+ * The GNU make action handler.
+ * \param sess The active session object.
+ * \returns OKAY if successful.
+ */
+int gmake_action(Session sess)
+{
+ stream_writeline(Console, "Generating project files for GNU make...");
+ return session_enumerate_objects(sess, GmakeSolutionCallbacks, GmakeProjectCallbacks);
+}
+
56 src/action/make/make.c
@@ -0,0 +1,56 @@
+/**
+ * \file make.c
+ * \brief Support functions for the makefile action.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include "premake.h"
+#include "action/make/make.h"
+#include "base/cstr.h"
+
+
+/**
+ * Get the name of the solution makefile for a particular solution.
+ * \param sess The current execution session context.
+ * \param sln The solution being requested.
+ * \returns If this solution is the only object which will generate output to
+ * its target location, then this function will return "Makefile".
+ * If another solution shares this output location, it will return
+ * "{Solution name}.make" instead, so that both solution makefiles
+ * may live in the same directory.
+ */
+const char* make_get_solution_makefile(Session sess, Solution sln)
+{
+ const char* my_path;
+ const char* their_path;
+ int i;
+
+ assert(sess);
+ assert(sln);
+
+ /* get the full makefile path for this solution */
+ my_path = solution_get_filename(sln, "Makefile", NULL);
+
+ /* see if any other solution wants to use this same path */
+ for (i = 0; i < session_num_solutions(sess); ++i)
+ {
+ Solution them = session_get_solution(sess, i);
+ if (them != sln)
+ {
+ their_path = solution_get_filename(them, "Makefile", NULL);
+ if (cstr_eq(my_path, their_path))
+ {
+ /* conflict; use the alternate name */
+ my_path = solution_get_filename(sln, NULL, ".make");
+ return my_path;
+ }
+ }
+ }
+
+ /* all good */
+ return my_path;
+}
+
+
13 src/action/make/make.h
@@ -0,0 +1,13 @@
+/**
+ * \file make.h
+ * \brief Support functions for the makefile action.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+#if !defined(PREMAKE_MAKE_H)
+#define PREMAKE_MAKE_H
+
+#include "engine/session.h"
+
+const char* make_get_solution_makefile(Session sess, Solution sln);
+
+#endif
34 src/action/make/make_solution.c
@@ -0,0 +1,34 @@
+/**
+ * \file make_solution.c
+ * \brief Makefile solution generation functions.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+
+#include "premake.h"
+#include "action/make/make.h"
+#include "action/make/make_solution.h"
+#include "base/error.h"
+
+
+/**
+ * Create a new output stream for a solution, and make it active for subsequent writes.
+ * \param sess The execution session context.
+ * \param sln The current solution.
+ * \param strm The currently active stream; set with session_set_active_stream().
+ * \returns OKAY if successful.
+ */
+int make_solution_create(Session sess, Solution sln, Stream strm)
+{
+ /* create the makefile */
+ const char* filename = make_get_solution_makefile(sess, sln);
+ strm = stream_create_file(filename);
+ if (!strm)
+ {
+ return !OKAY;
+ }
+
+ /* make the stream active for the functions that come after */
+ session_set_active_stream(sess, strm);
+ return OKAY;
+}
+
13 src/action/make/make_solution.h
@@ -0,0 +1,13 @@
+/**
+ * \file make_solution.h
+ * \brief Makefile solution generation functions.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+#if !defined(PREMAKE_MAKE_SOLUTION_H)
+#define PREMAKE_MAKE_SOLUTION_H
+
+#include "engine/session.h"
+
+int make_solution_create(Session sess, Solution sln, Stream strm);
+
+#endif
58 src/action/make/tests/make_tests.cpp
@@ -0,0 +1,58 @@
+/**
+ * \file make_tests.cpp
+ * \brief Automated tests for the makefile generator support functions.
+ * \author Copyright (c) 2008 Jason Perkins and the Premake project
+ */
+
+#include "premake.h"
+#include "testing/testing.h"
+extern "C" {
+#include "engine/engine.h"
+#include "action/make/make.h"
+}
+
+
+struct FxMake
+{
+ Session sess;
+ Solution sln1;
+ Solution sln2;
+
+ FxMake()
+ {
+ sess = session_create();
+ sln1 = AddSolution("MySolution1");
+ sln2 = AddSolution("MySolution2");
+ }
+
+ ~FxMake()
+ {
+ session_destroy(sess);
+ }
+
+ Solution AddSolution(const char* name)
+ {
+ Solution sln = solution_create();
+ session_add_solution(sess, sln);
+ solution_set_name(sln, name);
+ solution_set_base_dir(sln, ".");
+ return sln;
+ }
+};
+
+
+SUITE(action)
+{
+ TEST_FIXTURE(FxMake, GetSolutionMakefile_ReturnsMakefile_OnUniqueLocation)
+ {
+ solution_set_location(sln1, "MySolution");
+ const char* result = make_get_solution_makefile(sess, sln1);
+ CHECK_EQUAL("./MySolution/Makefile", result);
+ }
+
+ TEST_FIXTURE(FxMake, GetSolutionMakefile_ReturnsDotMake_OnSharedLocation)
+ {
+ const char* result = make_get_solution_makefile(sess, sln1);
+ CHECK_EQUAL("./MySolution1.make", result);
+ }
+}
37 src/action/vs200x/vs2002.c
@@ -0,0 +1,37 @@
+/**
+ * \file vs2002.c
+ * \brief Visual Studio 2002 project file generation action.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+
+#include <stdlib.h>
+#include "premake.h"
+#include "action/action.h"
+#include "vs200x_solution.h"
+
+
+/** The VS2002 solution writing process, for session_enumerate_objects() */
+static SessionSolutionCallback Vs2002SolutionCallbacks[] =
+{
+ vs200x_solution_create,
+ NULL
+};
+
+/** The VS2002 project writing process, for session_enumerate_objects() */
+static SessionProjectCallback Vs2002ProjectCallbacks[] =
+{
+ NULL
+};
+
+
+/**
+ * The Visual Studio 2002 action handler.
+ * \param sess The active session object.
+ * \returns OKAY if successful.
+ */
+int vs2002_action(Session sess)
+{
+ stream_writeline(Console, "Generating project files for Visual Studio 2002...");
+ return session_enumerate_objects(sess, Vs2002SolutionCallbacks, Vs2002ProjectCallbacks);
+}
+
37 src/action/vs200x/vs2003.c
@@ -0,0 +1,37 @@
+/**
+ * \file vs2003.c
+ * \brief Visual Studio 2003 project file generation action.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+
+#include <stdlib.h>
+#include "premake.h"
+#include "action/action.h"
+#include "vs200x_solution.h"
+
+
+/** The VS2003 solution writing process, for session_enumerate_objects() */
+static SessionSolutionCallback Vs2003SolutionCallbacks[] =
+{
+ vs200x_solution_create,
+ NULL
+};
+
+/** The VS2003 project writing process, for session_enumerate_objects() */
+static SessionProjectCallback Vs2003ProjectCallbacks[] =
+{
+ NULL
+};
+
+
+/**
+ * The Visual Studio 2003 action handler.
+ * \param sess The active session object.
+ * \returns OKAY if successful.
+ */
+int vs2003_action(Session sess)
+{
+ stream_writeline(Console, "Generating project files for Visual Studio 2003...");
+ return session_enumerate_objects(sess, Vs2003SolutionCallbacks, Vs2003ProjectCallbacks);
+}
+
37 src/action/vs200x/vs2005.c
@@ -0,0 +1,37 @@
+/**
+ * \file vs2005.c
+ * \brief Visual Studio 2005 project file generation action.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+
+#include <stdlib.h>
+#include "premake.h"
+#include "action/action.h"
+#include "vs200x_solution.h"
+
+
+/** The VS2005 solution writing process, for session_enumerate_objects() */
+static SessionSolutionCallback Vs2005SolutionCallbacks[] =
+{
+ vs200x_solution_create,
+ NULL
+};
+
+/** The VS2005 project writing process, for session_enumerate_objects() */
+static SessionProjectCallback Vs2005ProjectCallbacks[] =
+{
+ NULL
+};
+
+
+/**
+ * The Visual Studio 2005 action handler.
+ * \param sess The active session object.
+ * \returns OKAY if successful.
+ */
+int vs2005_action(Session sess)
+{
+ stream_writeline(Console, "Generating project files for Visual Studio 2005...");
+ return session_enumerate_objects(sess, Vs2005SolutionCallbacks, Vs2005ProjectCallbacks);
+}
+
34 src/action/vs200x/vs200x_solution.c
@@ -0,0 +1,34 @@
+/**
+ * \file vs200x_solution.c
+ * \brief Visual Studio 200x solution generation functions.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+
+#include <stdlib.h>
+#include "premake.h"
+#include "base/error.h"
+#include "action/vs200x/vs200x_solution.h"
+
+
+/**
+ * Create a new output stream for a solution, and make it active for subsequent writes.
+ * \param sess The execution session context.
+ * \param sln The current solution.
+ * \param strm The currently active stream; set with session_set_active_stream().
+ * \returns OKAY if successful.
+ */
+int vs200x_solution_create(Session sess, Solution sln, Stream strm)
+{
+ /* create the solution file */
+ const char* filename = solution_get_filename(sln, NULL, ".sln");
+ strm = stream_create_file(filename);
+ if (!strm)
+ {
+ return !OKAY;
+ }
+
+ /* make the stream active for the functions that come after */
+ session_set_active_stream(sess, strm);
+ return OKAY;
+}
+
13 src/action/vs200x/vs200x_solution.h
@@ -0,0 +1,13 @@
+/**
+ * \file vs200x_solution.h
+ * \brief Visual Studio 200x solution generation functions.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+#if !defined(PREMAKE_VS200X_SOLUTION_H)
+#define PREMAKE_VS200X_SOLUTION_H
+
+#include "engine/session.h"
+
+int vs200x_solution_create(Session sess, Solution sln, Stream strm);
+
+#endif
111 src/base/array.c
@@ -0,0 +1,111 @@
+/**
+ * \file array.c
+ * \brief Dynamic array object.
+ * \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
+ */
+
+#include <stdlib.h>
+#include "premake.h"
+#include "base/array.h"
+
+#define INITIAL_SIZE 16
+
+DEFINE_CLASS(Array)
+{
+ void** contents;
+ int size;
+ int capacity;
+};
+
+
+/**
+ * Create a new, empty array object.
+ * \returns A new array object.
+ */
+Array array_create()
+{
+ Array arr = ALLOC_CLASS(Array);
+ arr->contents = (void**)malloc(sizeof(void*) * INITIAL_SIZE);
+ arr->size = 0;
+ arr->capacity = INITIAL_SIZE;
+ return arr;
+}
+
+
+/**
+ * Destroy an array object and release the associated memory.
+ * \param arr The array to destroy.
+ */
+void array_destroy(Array arr)
+{
+ free(arr->contents);
+ free(arr);
+}
+
+
+/**
+ * Get the number of item in the array.
+ * \param arr The array to query.
+ * \returns The number elements currently in the array.
+ */
+int array_size(Array arr)
+{
+ return arr->size;
+}
+
+
+/**
+ * Add a new item to the end of the array, growing the array if necessary.
+ * \param arr The array object.
+ * \param item The item to add.
+ */
+void array_add(Array arr, void* item)
+{
+ if (arr->size == arr->capacity)
+ {
+ arr->capacity *= 2;
+ arr->contents = (void**)realloc(arr->contents, arr->capacity);
+ }
+
+ arr->contents[arr->size] = item;
+ arr->size++;
+}
+
+
+/**
+ * Retrieve the item at the specified index in the array.
+ * \param arr The array to query.
+ * \param index The index of the item to retrieve.
+ * \returns A pointer to the item.
+ */
+void* array_item(Array arr, int index)
+{
+ return arr->contents[index];
+}
+
+
+/**
+ * Store an item at a particular index in the array, overwriting any existing value.
+ * \param arr The array.
+ * \param index The index at which to store the item
+ * \param item The new item.
+ */
+void array_set(Array arr, int index, void* item)
+{
+ arr->contents[index] = item;
+}
+
+
+/**
+ * Append the contents of one array to another.
+ * \param dest The destination array.
+ * \param src The source array.
+ */
+void array_append(Array dest, Array src)
+{
+ int i;
+ for (i = 0; i < src->size; ++i)
+ {
+ array_add(dest, src->contents[i]);
+ }
+}
19 src/base/array.h
@@ -0,0 +1,19 @@
+/**
+ * \file array.h
+ * \brief Dynamic array object.
+ * \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
+ */
+#if !defined(PREMAKE_ARRAY_H)
+#define PREMAKE_ARRAY_H
+
+DECLARE_CLASS(Array);
+
+Array array_create(void);
+void array_destroy(Array arr);
+int array_size(Array arr);
+void array_add(Array arr, void* item);
+void* array_item(Array arr, int index);
+void array_set(Array arr, int index, void* item);
+void array_append(Array dest, Array src);
+
+#endif
7 src/base/base.h
@@ -0,0 +1,7 @@
+/**
+ * \file base.h
+ * \brief Premake base library API.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+
+int base_tests();
85 src/base/buffers.c
@@ -0,0 +1,85 @@
+/**
+ * \file buffers.c
+ * \brief Shared working buffer system.
+ * \author Copyright (c) 2007-2007 Jason Perkins and the Premake project
+ *
+ * \note I need to do a lot of string building operations in Premake. Rather than
+ * constantly creating, resizing, and releasing (and forgetting to release)
+ * dynamic string buffers, I use this shared buffer pool instead. Each request
+ * to buffer_next() returns the next buffer in the list. Pointers to the buffers
+ * can be safely passed around, and I don't need to remember to release anything
+ * when I'm done. The buffers should only be used for transient values, obviously.
+ * If you need to keep a value around for any length of time copy it to a string.
+ *
+ * \note The size and number of the buffers is arbitrary; I just picked some numbers
+ * that seemed big enough.
+ */
+
+#include <stdlib.h>
+#include "premake.h"
+#include "base/buffers.h"
+
+/** The size of an individual buffer, in bytes. */
+const int BUFFER_SIZE = 0x4000;
+
+/** The number of buffers stored in the pool */
+static const int NUM_BUFFERS = 64;
+
+/** The pool of buffers */
+static char** buffers = NULL;
+
+/** The index of the next available buffer */
+static int next = 0;
+
+
+/**
+ * Clean up after the buffer system. Called by atexit().
+ */
+static void buffers_destroy(void)
+{
+ if (buffers != NULL)
+ {
+ int i;
+ for (i = 0; i < NUM_BUFFERS; ++i)
+ {
+ free(buffers[i]);
+ }
+ free(buffers);
+ }
+}
+
+
+/**
+ * Initialize the buffer system.
+ */
+static void buffers_create(void)
+{
+ int i;
+ buffers = (char**)malloc(sizeof(char*) * NUM_BUFFERS);
+ for (i = 0; i < NUM_BUFFERS; ++i)
+ {
+ buffers[i] = (char*)malloc(BUFFER_SIZE);
+ }
+ next = 0;
+ atexit(buffers_destroy);
+}
+
+
+/**
+ * Get a clean buffer.
+ * \returns An empty buffer.
+ */
+char * buffers_next()
+{
+ /* if this is the first call, initialize the buffer system */
+ if (buffers == NULL)
+ buffers_create();
+
+ next++;
+ if (next == NUM_BUFFERS)
+ next = 0;
+
+ /* initialize new buffers to empty string */
+ buffers[next][0] = '\0';
+ return buffers[next];
+}
14 src/base/buffers.h
@@ -0,0 +1,14 @@
+/**
+ * \file buffers.h
+ * \brief Shared working buffer system.
+ * \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
+ */
+#if !defined(PREMAKE_BUFFER_H)
+#define PREMAKE_BUFFER_H
+
+extern const int BUFFER_SIZE;
+
+char* buffers_next(void);
+
+#endif
+
47 src/base/cstr.c
@@ -0,0 +1,47 @@
+/**
+ * \file cstr.c
+ * \brief C string handling.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+
+#include <string.h>
+#include "premake.h"
+#include "base/cstr.h"
+
+
+/**
+ * Determines if the string ends with a particular sequence.
+ * \param str The string to test.
+ * \param expected The sequence for which to look.
+ * \returns True if the string ends with the sequence, false otherwise.
+ */
+int cstr_ends_with(const char* str, const char* expected)
+{
+ if (str != NULL && expected != NULL)
+ {
+ int str_len = strlen(str);
+ int exp_len = strlen(expected);
+ if (str_len >= exp_len)
+ {
+ const char* start = str + str_len - exp_len;
+ return (strcmp(start, expected) == 0);
+ }
+ }
+ return 0;
+}
+
+
+/**
+ * Compares two C strings for equality.
+ * \param str The string to compare.
+ * \param expected The value to compare against.
+ * \returns Nonzero if the strings match, zero otherwise.
+ */
+int cstr_eq(const char* str, const char* expected)
+{
+ if (str != NULL && expected != NULL)
+ {
+ return (strcmp(str, expected) == 0);
+ }
+ return 0;
+}
12 src/base/cstr.h
@@ -0,0 +1,12 @@
+/**
+ * \file cstr.h
+ * \brief C string handling.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+#if !defined(PREMAKE_CSTR_H)
+#define PREMAKE_CSTR_H
+
+int cstr_ends_with(const char* str, const char* expected);
+int cstr_eq(const char* str, const char* expected);
+
+#endif
106 src/base/dir.c
@@ -0,0 +1,106 @@
+/**
+ * \file dir.c
+ * \brief Directory handling.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <sys/stat.h>
+#include "premake.h"
+#include "base/buffers.h"
+#include "base/error.h"
+#include "base/dir.h"
+#include "base/path.h"
+#include "platform/platform.h"
+
+
+/**
+ * Create a directory, if it doesn't exist already.
+ * \returns OKAY if successful.
+ */
+int dir_create(const char* path)
+{
+ char* parent;
+
+ assert(path);
+
+ if (dir_exists(path))
+ return OKAY;
+
+ /* make sure the parent directory exists */
+ parent = path_directory(path);
+ if (strlen(parent) > 0)
+ {
+ if (dir_create(parent) != OKAY)
+ return !OKAY;
+ }
+
+ if (platform_create_dir(path) != OKAY)
+ {
+ error_set("Unable to create directory %s", path);
+ return !OKAY;
+ }
+
+ return OKAY;
+}
+
+
+/**
+ * Determine if a particular directory exists on the filesystem.
+ * \returns True if the directory exists.
+ */
+int dir_exists(const char* path)
+{
+ struct stat buf;
+
+ assert(path);
+
+ /* empty path is equivalent to ".", must be true */
+ if (strlen(path) == 0)
+ {
+ return 1;
+ }
+
+ if (stat(path, &buf) == 0)
+ {
+ return (buf.st_mode & S_IFDIR);
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+
+/**
+ * Get the current working directory.
+ * \returns The current working directory, or NULL on error. Path separators
+ * are converted to forward slashes, regardless of platform.
+ */
+char* dir_get_current()
+{
+ char* buffer = buffers_next();
+
+ int result = platform_dir_get_current(buffer, BUFFER_SIZE);
+ if (result == OKAY)
+ {
+ return path_translate(buffer, "/");
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+
+/**
+ * Set the current working directory.
+ * \param path The new working directory.
+ * \returns OKAY if successful.
+ */
+int dir_set_current(const char* path)
+{
+ assert(path);
+ return platform_dir_set_current(path);
+}
14 src/base/dir.h
@@ -0,0 +1,14 @@
+/**
+ * \file dir.h
+ * \brief Directory handling.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+#if !defined(PREMAKE_DIR_H)
+#define PREMAKE_DIR_H
+
+int dir_create(const char* path);
+int dir_exists(const char* path);
+char* dir_get_current(void);
+int dir_set_current(const char* path);
+
+#endif
51 src/base/error.c
@@ -0,0 +1,51 @@
+/**
+ * \file error.c
+ * \brief Application-wide error reporting.
+ * \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include "premake.h"
+#include "error.h"
+
+static char error_message[8192] = { 0 };
+
+
+/**
+ * Clear any existing error state.
+ */
+void error_clear(void)
+{
+ error_message[0] = 0;
+}
+
+
+/**
+ * Returns the most recent error message set by error_set().
+ * \returns The error message, or NULL if no error message has been set.
+ */
+const char* error_get(void)
+{
+ return (strlen(error_message) > 0) ? error_message : NULL;
+}
+
+
+/**
+ * Set the description of an error condition, which may be retrieved with session_get_error().
+ * The session uses a fixed length (around 8K) buffer for storing the error message, so make
+ * sure the final size of the formatted message will fall under that limit.
+ * \param message A description of the error condition.
+ */
+void error_set(const char* message, ...)
+{
+ va_list args;
+
+ assert(message);
+
+ va_start(args, message);
+ vsprintf(error_message, message, args);
+ va_end(args);
+}
13 src/base/error.h
@@ -0,0 +1,13 @@
+/**
+ * \file error.h
+ * \brief Application-wide error reporting.
+ * \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
+ */
+#if !defined(PREMAKE_ERROR_H)
+#define PREMAKE_ERROR_H
+
+void error_clear(void);
+const char* error_get(void);
+void error_set(const char* message, ...);
+
+#endif
206 src/base/path.c
@@ -0,0 +1,206 @@
+/**
+ * \file path.c
+ * \brief Path handling.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include "premake.h"
+#include "base/path.h"
+#include "platform/platform.h"
+#include "base/buffers.h"
+#include "base/cstr.h"
+#include "base/dir.h"
+
+
+/**
+ * Create an absolute path from a relative one.
+ * \param path The relative path to convert.
+ * \returns An absolute version of the relative path.
+ */
+char* path_absolute(const char* path)
+{
+ char* source;
+ char* result;
+
+ assert(path);
+
+ /* normalize the target path */
+ source = path_translate(path, "/");
+ if (strlen(source) == 0)
+ strcpy(source, ".");
+
+ /* If the directory is already absolute I don't have to do anything */
+ if (path_is_absolute(source))
+ return source;
+
+ /* start from the current location */
+ result = dir_get_current();
+
+ /* split up the supplied relative path and tackle it bit by bit */
+ while (source)
+ {
+ char* end = strchr(source, '/');
+ if (end)
+ *end = 0;
+
+ if (cstr_eq(source, ".."))
+ {
+ char* up = strrchr(result, '/');
+ if (up)
+ *up = 0;
+ }
+ else if (!cstr_eq(source, "."))
+ {
+ strcat(result, "/");
+ strcat(result, source);
+ }
+
+ source = end ? end + 1 : NULL;
+ }
+
+ return result;
+}
+
+
+/**
+ * Assemble a complete file path from its component parts.
+ * \param dir The directory portion of the path.
+ * \param filename The file name portion of the path.
+ * \param ext The extension portion of the path.
+ * \returns The assembled file path.
+ */
+char* path_assemble(const char* dir, const char* filename, const char* ext)
+{
+ char* buffer;
+
+ assert(dir);
+ assert(filename);
+ assert(ext);
+
+ buffer = path_join(dir, filename);
+ if (ext)
+ {
+ strcat(buffer, ext);
+ }
+ return buffer;
+}
+
+
+/**
+ * Retrieve the directory portion of a path.
+ * \param path The path to split.
+ * \returns The directory portion of the path. Returns an empty string ("") if
+ * the path does not contain any directory information.
+ */
+char* path_directory(const char* path)
+{
+ char* ptr;
+ char* buffer;
+
+ assert(path);
+
+ buffer = buffers_next();
+ strcpy(buffer, path);
+
+ /* look for the last path separator */
+ ptr = strrchr(buffer, '/');
+ if (ptr)
+ *ptr = '\0';
+ else
+ *buffer = '\0';
+
+ return buffer;
+}
+
+
+/**
+ * Determine is a path is absolute (rooted at base of filesystem).
+ * \param path The path to check.
+ * \returns True if the path is absolute.
+ */
+int path_is_absolute(const char* path)
+{
+ assert(path);
+
+ if (path[0] == '/' || path[0] == '\\')
+ return 1;
+ if (path[1] == ':')
+ return 1;
+ return 0;
+}
+
+
+/**
+ * Join two paths togethers.
+ * \param leading The leading path.
+ * \param trailing The trailing path.
+ * \returns A unified path.
+ * \note If the trailing path is absolute, that will be the return value.
+ * A join is only performed if the trailing path is relative.
+ */
+char* path_join(const char* leading, const char* trailing)
+{
+ char* buffer = buffers_next();
+
+ if (!trailing)
+ {
+ strcpy(buffer, leading);
+ return buffer;
+ }
+
+ if (!leading || path_is_absolute(trailing))
+ {
+ strcpy(buffer, trailing);
+ return buffer;
+ }
+
+ if (leading)
+ {
+ strcat(buffer, leading);
+ }
+
+ if (strlen(buffer) > 0 && !cstr_ends_with(buffer, "/"))
+ {
+ strcat(buffer, "/");
+ }
+
+ strcat(buffer, trailing);
+ return buffer;
+}
+
+
+/**
+ * Replace all path separator characters in a path.
+ * \param path The path to translate.
+ * \param sep The desired separator, or NULL for the platform's native separator.
+ * \returns The translated path.
+ */
+char* path_translate(const char* path, const char* sep)
+{
+ char* ptr;
+ char* buffer;
+
+ assert(path);
+
+ buffer = buffers_next();
+ if (sep == NULL)
+ {
+#if defined(PLATFORM_WINDOWS)
+ sep = "\\";
+#else
+ sep = "/";
+#endif
+ }
+
+ strcpy(buffer, path);
+ for (ptr = buffer; *ptr; ++ptr)
+ {
+ if (*ptr == '/' || *ptr == '\\')
+ *ptr = *sep;
+ }
+
+ return buffer;
+}
16 src/base/path.h
@@ -0,0 +1,16 @@
+/**
+ * \file path.h
+ * \brief Path handling.
+ * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ */
+#if !defined(PREMAKE_PATH_H)
+#define PREMAKE_PATH_H
+
+char* path_absolute(const char* path);
+char* path_assemble(const char* dir, const char* filename, const char* ext);
+char* path_directory(const char* path);
+int path_is_absolute(const char* path);
+char* path_join(const char* leading, const char* trailing);
+char* path_translate(const char* path, const char* sep);
+
+#endif
190 src/base/stream.c
@@ -0,0 +1,190 @@
+/**
+ * \file stream.c
+ * \brief Output stream handling.
+ * \author Copyright (c) 2007-2008 Jason Perkins and the Premake project
+ */
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "premake.h"
+#include "base/error.h"
+#include "base/dir.h"
+#include "base/path.h"
+#include "base/stream.h"
+
+
+DEFINE_CLASS(Stream)
+{
+ FILE* file;
+ const char* newline;
+ char* buffer;
+};
+
+
+static struct Stream_impl Console_impl = { NULL, "\n", NULL };
+
+
+/**
+ * The console output stream.
+ * Use the stream_write() functions and this stream object instead
+ * of the usual C functions like printf(). The stream functions have
+ * more features -- such as setting the line ending sequence -- and
+ * can be captured for automated testing.
+ */
+Stream Console = &Console_impl;
+
+
+/**
+ * Create a new file output stream, overwriting any existing file.
+ * \param filename The name of the file to create.
+ * \returns A new file stream.
+ */
+Stream stream_create_file(const char* filename)
+{
+ Stream strm;
+ const char* dirname;
+ FILE* file;
+
+ /* make sure the directory exists before writing to it */
+ dirname = path_directory(filename);
+ if (dir_create(dirname) != OKAY)
+ {
+ return NULL;
+ }
+
+ /* create the file */
+ file = fopen(filename, "wb");
+ if (file == NULL)
+ {
+ error_set("Unable to open file %s", filename);
+ return NULL;
+ }
+
+ /* build the stream object */
+ strm = stream_create_null();
+ strm->file = file;
+ return strm;
+}
+
+
+/**
+ * Create a "null" stream, which discards any writes; intended for automated testing.
+ * \returns A new stream object.
+ */
+Stream stream_create_null()
+{
+ Stream strm = ALLOC_CLASS(Stream);
+ strm->file = NULL;
+ strm->newline = "\n";
+ strm->buffer = NULL;
+ return strm;
+}
+
+
+/**
+ * Close a stream and release the associated memory.
+ * \param strm The stream to close.