diff --git a/ppremake/acconfig.h b/ppremake/acconfig.h index 08287ef1e3..635a1b0441 100644 --- a/ppremake/acconfig.h +++ b/ppremake/acconfig.h @@ -23,8 +23,8 @@ /* Define if we're compiling for a Windows platform. */ #undef PLATFORM_WIN32 -/* The current version number. */ -#define VERSION 0.0 +/* Define if we're compiling using Windows Microsoft Visual C++. */ +#undef WIN32_VC /* The platform ppremake is compiled for. This primarily controls the initial setting of the $[PLATFORM] variable. */ diff --git a/ppremake/config_msvc.h b/ppremake/config_msvc.h new file mode 100644 index 0000000000..239e73263e --- /dev/null +++ b/ppremake/config_msvc.h @@ -0,0 +1,83 @@ +/* config_msvc.h. + + This file was generated by hand for use on Win32 environments when + building with Microsoft Visual Studio. It will have to be kept + up-to-date by hand with the automatically-generated config.h on + other platforms. +*/ + +/* Define if the C++ compiler uses namespaces. */ +#define HAVE_NAMESPACE 1 + +/* Define if the C++ iostream library supports ios::binary. */ +/* #undef HAVE_IOS_BINARY */ + +/* Define if we're compiling for a Windows platform. */ +#define PLATFORM_WIN32 1 + +/* Define if we're compiling using Windows Microsoft Visual C++. */ +#define WIN32_VC 1 + +/* The platform ppremake is compiled for. This primarily controls the + initial setting of the $[PLATFORM] variable. */ +#define PLATFORM "Win32" + +/* Define if you have the header file. */ +/* #undef HAVE_ALLOCA_H */ + +/* Define if you have the `getopt' function. */ +/* #undef HAVE_GETOPT */ + +/* Define if you have the header file. */ +#define HAVE_IOSTREAM 1 + +/* Define if you have the header file. */ +#define HAVE_IO_H 1 + +/* Define if you have the header file. */ +#define HAVE_MALLOC_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_MINMAX_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_GLOB_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_DIRENT_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_REGEX_H */ + +/* Define if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define if you have the header file. */ +#define HAVE_STRSTREAM_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_SYS_TYPES_H 1 */ + +/* Define if you have the header file. */ +/* #undef HAVE_SYS_TIME_H 1 */ + +/* Define if you have the header file. */ +#define HAVE_SYS_UTIME_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_SYS_WAIT_H 1 */ + +/* Define if you have the header file. */ +/* #undef HAVE_UNISTD_H 1 */ + +/* Define if you have the header file. */ +/* #undef HAVE_UTIME_H 1 */ + +/* Name of package */ +#define PACKAGE "ppremake" + +/* Define if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.03" diff --git a/ppremake/configure.in b/ppremake/configure.in index 088d193f92..f621350b9a 100644 --- a/ppremake/configure.in +++ b/ppremake/configure.in @@ -35,7 +35,7 @@ AC_SUBST(libm) dnl Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS(malloc.h alloca.h unistd.h io.h minmax.h sys/types.h string.h regex.h) +AC_CHECK_HEADERS(malloc.h alloca.h unistd.h utime.h io.h minmax.h glob.h dirent.h sys/types.h sys/time.h sys/utime.h sys/wait.h string.h strstream.h regex.h) dnl Checks for typedefs, structures, and compiler characteristics. diff --git a/ppremake/find_searchpath.cxx b/ppremake/find_searchpath.cxx index 56f05b95a4..43590278b4 100644 --- a/ppremake/find_searchpath.cxx +++ b/ppremake/find_searchpath.cxx @@ -4,8 +4,11 @@ //////////////////////////////////////////////////////////////////// #include "find_searchpath.h" +#include "include_access.h" +#ifdef HAVE_UNISTD_H #include +#endif string find_searchpath(const vector &directories, const string &filename) { diff --git a/ppremake/gnu_getopt.c b/ppremake/gnu_getopt.c index a3ef62a133..7adc589e33 100644 --- a/ppremake/gnu_getopt.c +++ b/ppremake/gnu_getopt.c @@ -17,7 +17,7 @@ GNU General Public License for more details. */ -#include +#include "ppremake.h" #if !defined(HAVE_GETOPT) diff --git a/ppremake/gnu_getopt.h b/ppremake/gnu_getopt.h index 41d58ab19d..df9d85c005 100644 --- a/ppremake/gnu_getopt.h +++ b/ppremake/gnu_getopt.h @@ -35,7 +35,7 @@ extern "C" { Also, when `ordering' is RETURN_IN_ORDER, each non-option ARGV-element is returned here. */ -extern char EXPCL_DTOOL *optarg; +extern char *optarg; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller @@ -49,7 +49,7 @@ extern char EXPCL_DTOOL *optarg; Otherwise, `optind' communicates from one call to the next how much of ARGV has been scanned so far. */ -extern int EXPCL_DTOOL optind; +extern int optind; /* Callers store zero here to inhibit the error message `getopt' prints for unrecognized options. */ @@ -101,12 +101,12 @@ struct option #define required_argument 1 #define optional_argument 2 -extern EXPCL_DTOOL int +extern int getopt (int argc, char *const *argv, const char *shortopts); -extern EXPCL_DTOOL int +extern int getopt_long (int argc, char *const *argv, const char *shortopts, const struct option *long_options, int *opt_index); -extern EXPCL_DTOOL int +extern int getopt_long_only (int argc, char *const *argv, const char *shortopts, const struct option *long_options, diff --git a/ppremake/gnu_regex.c b/ppremake/gnu_regex.c index 1d8f140b86..c340d1f523 100644 --- a/ppremake/gnu_regex.c +++ b/ppremake/gnu_regex.c @@ -24,7 +24,7 @@ #pragma alloca #endif -#include +#include "ppremake.h" #if !defined(HAVE_REGEX_H) @@ -2835,7 +2835,7 @@ re_set_registers (bufp, regs, num_regs, starts, ends) { bufp->regs_allocated = REGS_UNALLOCATED; regs->num_regs = 0; - regs->start = regs->end = (regoff_t) 0; + regs->start = regs->end = (regoff_t *) 0; } } diff --git a/ppremake/gnu_regex.h b/ppremake/gnu_regex.h index de4872241f..07e71e5eac 100644 --- a/ppremake/gnu_regex.h +++ b/ppremake/gnu_regex.h @@ -393,7 +393,7 @@ typedef struct unfortunately clutters up the declarations a bit, but I think it's worth it. */ -#if __STDC__ +#if defined(__STDC__) || defined(_MSC_VER) #define _RE_ARGS(args) args diff --git a/ppremake/include_access.h b/ppremake/include_access.h new file mode 100644 index 0000000000..5177eab52e --- /dev/null +++ b/ppremake/include_access.h @@ -0,0 +1,25 @@ +// Filename: include_access.cxx +// Created by: drose (21May02) +// +//////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_ACCESS_H +#define INCLUDE_ACCESS_H + +// This file includes whatever is necessary to define the access() +// function. + +#ifdef HAVE_UNISTD_H +#include +#endif + +#ifdef WIN32_VC +#include // Windows requires this for access() +#define access _access +#define F_OK 00 +#define W_OK 02 +#define R_OK 04 +#endif // WIN32_VC + +#endif // INCLUDE_ACCESS_H + diff --git a/ppremake/ppCommandFile.cxx b/ppremake/ppCommandFile.cxx index 4c48e5bc78..6e364f4259 100644 --- a/ppremake/ppCommandFile.cxx +++ b/ppremake/ppCommandFile.cxx @@ -8,14 +8,24 @@ #include "ppNamedScopes.h" #include "ppSubroutine.h" #include "tokenize.h" +#include "include_access.h" + +#ifdef HAVE_UNISTD_H +#include +#endif + +#ifdef HAVE_UTIME_H +#include +#endif + +#ifdef HAVE_SYS_UTIME_H +#include +#endif #include #include // for tempnam() -#include #include -#include #include -#include static const string begin_comment(BEGIN_COMMENT); @@ -1664,7 +1674,11 @@ compare_output(const string &new_contents, const string &filename, } } +#ifdef WIN32_VC + ofstream out_b(filename.c_str(), ios::out); +#else // WIN32_VC ofstream out_b(filename.c_str(), ios::out, 0666); +#endif // WIN32_VC if (!out_b) { cerr << "Unable to open file " << filename << " for writing.\n"; return false; diff --git a/ppremake/ppDependableFile.cxx b/ppremake/ppDependableFile.cxx index 02734e5c20..2801095009 100644 --- a/ppremake/ppDependableFile.cxx +++ b/ppremake/ppDependableFile.cxx @@ -8,8 +8,11 @@ #include "ppDirectoryTree.h" #include "check_include.h" -#include +#ifdef HAVE_UNISTD_H #include +#endif + +#include #include #include @@ -443,11 +446,13 @@ stat_file() { return; } +#ifdef S_ISREG if (!S_ISREG(st.st_mode)) { // The file exists, but it's not a regular file--we consider that // not existing. return; } +#endif // S_ISREG _flags |= F_exists; _mtime = st.st_mtime; diff --git a/ppremake/ppDependableFile.h b/ppremake/ppDependableFile.h index 5624b9bd02..11f2451f92 100644 --- a/ppremake/ppDependableFile.h +++ b/ppremake/ppDependableFile.h @@ -7,10 +7,13 @@ #define PPDEPENDABLEFILE_H #include "ppremake.h" -#include #include #include +#ifdef HAVE_SYS_TIME_H +#include +#endif + class PPDirectory; /////////////////////////////////////////////////////////////////// diff --git a/ppremake/ppDirectory.cxx b/ppremake/ppDirectory.cxx index 785b2b0880..86de4bca5e 100644 --- a/ppremake/ppDirectory.cxx +++ b/ppremake/ppDirectory.cxx @@ -10,11 +10,27 @@ #include "ppCommandFile.h" #include "ppDependableFile.h" #include "tokenize.h" +#include "include_access.h" -#include +#ifdef HAVE_DIRENT_H #include +#endif + +#ifdef HAVE_UNISTD_H #include +#endif + +#ifdef HAVE_SYS_TYPES_H +#include +#endif + #include +#include + +#ifdef WIN32_VC +#include +#include +#endif PPDirectory *current_output_directory = (PPDirectory *)NULL; @@ -390,17 +406,48 @@ r_scan(const string &prefix) { if (!prefix.empty()) { root_name = prefix.substr(0, prefix.length() - 1); } - + + // Collect all the filenames in the directory in this vector first, + // so we can sort them. + vector filenames; + +#ifdef WIN32_VC + // Use FindFirstFile()/FindNextFile() to walk through the list of + // files in a directory. + string match; + if (root_name.empty()) { + match = "*.*"; + } else { + match = root_name + "\\*.*"; + } + WIN32_FIND_DATA find_data; + + HANDLE handle = FindFirstFile(match.c_str(), &find_data); + if (handle == INVALID_HANDLE_VALUE) { + if (GetLastError() == ERROR_NO_MORE_FILES) { + // No matching files is not an error. + return true; + } + return false; + } + + do { + string filename = find_data.cFileName; + if (filename != "." && filename != "..") { + filenames.push_back(filename); + } + } while (FindNextFile(handle, &find_data)); + + bool scan_ok = (GetLastError() == ERROR_NO_MORE_FILES); + FindClose(handle); + +#else // WIN32_VC DIR *root = opendir(root_name.c_str()); if (root == (DIR *)NULL) { cerr << "Unable to scan directory " << root_name << "\n"; return false; } - // Collect all the filenames in the directory in this vector first, - // so we can sort them. - vector filenames; - struct dirent *d; d = readdir(root); while (d != (struct dirent *)NULL) { @@ -408,6 +455,7 @@ r_scan(const string &prefix) { d = readdir(root); } closedir(root); +#endif // WIN32_VC sort(filenames.begin(), filenames.end()); @@ -675,7 +723,11 @@ update_file_dependencies(const string &cache_filename) { if (!_dependables.empty()) { bool wrote_anything = false; +#ifdef WIN32_VC + ofstream out(cache_pathname.c_str(), ios::out); +#else ofstream out(cache_pathname.c_str(), ios::out, 0666); +#endif if (!out) { cerr << "Cannot update cache dependency file " << cache_pathname << "\n"; return; diff --git a/ppremake/ppMain.cxx b/ppremake/ppMain.cxx index 1f58d9c64c..a36ed93679 100644 --- a/ppremake/ppMain.cxx +++ b/ppremake/ppMain.cxx @@ -8,12 +8,21 @@ #include "ppCommandFile.h" #include "ppDirectory.h" #include "tokenize.h" +#include "include_access.h" +#ifdef HAVE_UNISTD_H #include +#endif + #include #include #include // for perror +#ifdef WIN32_VC +#include // Windows requires this for getcwd() +#define getcwd _getcwd +#endif // WIN32_VC + string PPMain::_root; //////////////////////////////////////////////////////////////////// diff --git a/ppremake/ppScope.cxx b/ppremake/ppScope.cxx index e5a4b37a0e..15e87aa66f 100644 --- a/ppremake/ppScope.cxx +++ b/ppremake/ppScope.cxx @@ -14,20 +14,37 @@ #include "tokenize.h" #include "find_searchpath.h" #include "filename.h" +#include "include_access.h" + +#ifdef HAVE_GLOB_H +#include +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif + +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#ifdef HAVE_SYS_WAIT_H +#include +#endif #include #include #include -#include #include -#include #include // for perror() and sprintf(). #include #include -#include -#include #include +#ifdef WIN32_VC +#include // for GetFileAttributes() +#endif // WIN32_VC + static const string variable_patsubst(VARIABLE_PATSUBST); PPScope::MapVariableDefinition PPScope::_null_map_def; @@ -1280,14 +1297,24 @@ expand_isdir(const string ¶ms) { } const string &filename = results[0]; - struct stat stbuf; string result; +#ifdef WIN32_VC + DWORD dresults = GetFileAttributes(filename.c_str()); + if (dresults != -1) { + if ((dresults & FILE_ATTRIBUTE_DIRECTORY) != 0) { + result = filename; + } + } + +#else // WIN32_VC + struct stat stbuf; if (stat(filename.c_str(), &stbuf) == 0) { if (S_ISDIR(stbuf.st_mode)) { result = filename; } } +#endif // WIN32_VC return result; } @@ -1313,14 +1340,25 @@ expand_isfile(const string ¶ms) { } const string &filename = results[0]; - struct stat stbuf; string result; + +#ifdef WIN32_VC + DWORD dresults = GetFileAttributes(filename.c_str()); + if (dresults != -1) { + if (dresults == FILE_ATTRIBUTE_NORMAL) { + result = filename; + } + } + +#else // WIN32_VC + struct stat stbuf; if (stat(filename.c_str(), &stbuf) == 0) { if (S_ISREG(stbuf.st_mode)) { result = filename; } } +#endif // WIN32_VC return result; } @@ -1495,6 +1533,11 @@ expand_bintest(const string ¶ms) { //////////////////////////////////////////////////////////////////// string PPScope:: expand_shell(const string ¶ms) { +#ifdef WIN32_VC + cerr << "$[shell] is not presently supported on Win32 without Cygwin.\n"; + string output; + +#else // WIN32_VC // We run $[shell] commands within the directory indicated by // $[THISDIRPREFIX]. This way, local filenames will be expanded the // way we expect. @@ -1572,6 +1615,7 @@ expand_shell(const string ¶ms) { } } close(pd[0]); +#endif // WIN32_VC // Now get the output. We split it into words and then reconnect // it, to simulate the shell's backpop operator. @@ -3086,6 +3130,10 @@ p_find_map_variable(const string &varname) { //////////////////////////////////////////////////////////////////// void PPScope:: glob_string(const string &str, vector &results) { +#ifdef WIN32_VC + cerr << "glob temporarily unsupported in Win32 without Cygwin.\n"; + +#else // WIN32_VC // We run glob_string() within the directory indicated by // $[THISDIRPREFIX]. This way, local filenames will be expanded the // way we expect. @@ -3126,4 +3174,5 @@ glob_string(const string &str, vector &results) { // Now restore the current directory back to where it should be. PPMain::chdir_root(); } +#endif // WIN32_VC } diff --git a/ppremake/ppremake.cxx b/ppremake/ppremake.cxx index 113e3feb70..27adad7610 100644 --- a/ppremake/ppremake.cxx +++ b/ppremake/ppremake.cxx @@ -13,14 +13,18 @@ #ifdef HAVE_GETOPT #include #else -#include +#include "gnu_getopt.h" +#endif + +#ifdef HAVE_UNISTD_H +#include #endif #include #include #include #include -#include +#include bool unix_platform = false; bool windows_platform = false; diff --git a/ppremake/ppremake.h b/ppremake/ppremake.h index c87e1024f1..571b9e5bd7 100644 --- a/ppremake/ppremake.h +++ b/ppremake/ppremake.h @@ -8,7 +8,13 @@ #ifndef PPREMAKE_H #define PPREMAKE_H -#include "config.h" +#ifdef _MSC_VER + /* For Visual C, include the special config.h file. */ + #include "config_msvc.h" +#else + /* Otherwise, include the normal automatically-generated file. */ + #include "config.h" +#endif #ifdef __cplusplus #ifdef HAVE_IOSTREAM @@ -28,6 +34,11 @@ using namespace std; #endif #endif /* __cplusplus */ +#ifndef HAVE_ALLOCA_H + /* If we don't have alloca.h, use malloc() to implement gnu_regex. */ + #define REGEX_MALLOC 1 +#endif + #define PACKAGE_FILENAME "Package.pp" #define SOURCE_FILENAME "Sources.pp" diff --git a/ppremake/ppremake.sln b/ppremake/ppremake.sln new file mode 100644 index 0000000000..cb210b8386 --- /dev/null +++ b/ppremake/ppremake.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ppremake", "ppremake.vcproj", "{B2B6A5F5-4403-4386-9294-B10EE8B0B3E8}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {B2B6A5F5-4403-4386-9294-B10EE8B0B3E8}.Debug.ActiveCfg = Debug|Win32 + {B2B6A5F5-4403-4386-9294-B10EE8B0B3E8}.Debug.Build.0 = Debug|Win32 + {B2B6A5F5-4403-4386-9294-B10EE8B0B3E8}.Release.ActiveCfg = Release|Win32 + {B2B6A5F5-4403-4386-9294-B10EE8B0B3E8}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/ppremake/ppremake.vcproj b/ppremake/ppremake.vcproj new file mode 100644 index 0000000000..4d9e4ffb60 --- /dev/null +++ b/ppremake/ppremake.vcproj @@ -0,0 +1,241 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ppremake/ppremake.vsdir b/ppremake/ppremake.vsdir new file mode 100644 index 0000000000..756c0584e9 --- /dev/null +++ b/ppremake/ppremake.vsdir @@ -0,0 +1 @@ +ppremake.vsz| |ppremake|1|TODO: Wizard Description.| |6777| |ppremake diff --git a/ppremake/ppremake.vsz b/ppremake/ppremake.vsz new file mode 100644 index 0000000000..80460fe966 --- /dev/null +++ b/ppremake/ppremake.vsz @@ -0,0 +1,8 @@ +VSWIZARD 7.0 +Wizard=VsWizard.VsWizardEngine + +Param="WIZARD_NAME = ppremake" +Param="ABSOLUTE_PATH = C:\Cygwin\home\drose\player\ppremake" +Param="FALLBACK_LCID = 1033" +Param="WIZARD_UI = FALSE" +Param="SOURCE_FILTER = txt" diff --git a/ppremake/sedCommand.cxx b/ppremake/sedCommand.cxx index 99475e8e53..c9f07434eb 100644 --- a/ppremake/sedCommand.cxx +++ b/ppremake/sedCommand.cxx @@ -279,7 +279,7 @@ do_command(SedScript &script, SedContext &context) { void SedCommand:: do_s_command(SedContext &context) { size_t nmatch = _re.re_nsub + 1; - regmatch_t pmatch[nmatch]; + regmatch_t *pmatch = new regmatch_t[nmatch]; string result; const char *str = context._pattern_space.c_str(); @@ -327,6 +327,7 @@ do_s_command(SedContext &context) { // If we don't have the global flag set, stop after the first iteration. result += str; context._pattern_space = result; + delete[] pmatch; return; } @@ -336,4 +337,5 @@ do_s_command(SedContext &context) { // All done. result += str; context._pattern_space = result; + delete[] pmatch; }