summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2015-11-11 17:19:00 -0800
committerEvan Martin <martine@danga.com>2015-11-11 17:19:00 -0800
commit4ffe56d387dce2bc5126fc4079ad2f2b31fba30e (patch)
treeb23e4182918a3d35c9f9feb470194c63f4be68f0
parenta65240d52c451f69d9b2f1252738d67eb99a296c (diff)
parentaa14d6e067c6491555150c1f40de1388c3491124 (diff)
downloadninja-4ffe56d387dce2bc5126fc4079ad2f2b31fba30e.tar.gz
Merge pull request #1007 from mikesep/aix
Support for AIX
-rw-r--r--.gitignore1
-rwxr-xr-xconfigure.py51
-rw-r--r--src/build_log.cc11
-rw-r--r--src/getopt.c2
-rw-r--r--src/getopt.h2
-rwxr-xr-xsrc/inline.sh2
-rw-r--r--src/ninja.cc3
-rw-r--r--src/ninja_test.cc3
-rw-r--r--src/util.cc12
9 files changed, 71 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index f7fc044..5a85203 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@ TAGS
/build
/build.ninja
/ninja
+/ninja.bootstrap
/build_log_perftest
/canon_perftest
/depfile_parser_perftest
diff --git a/configure.py b/configure.py
index 0cff196..0710ea2 100755
--- a/configure.py
+++ b/configure.py
@@ -58,11 +58,13 @@ class Platform(object):
self._platform = 'bitrig'
elif self._platform.startswith('netbsd'):
self._platform = 'netbsd'
+ elif self._platform.startswith('aix'):
+ self._platform = 'aix'
@staticmethod
def known_platforms():
return ['linux', 'darwin', 'freebsd', 'openbsd', 'solaris', 'sunos5',
- 'mingw', 'msvc', 'gnukfreebsd', 'bitrig', 'netbsd']
+ 'mingw', 'msvc', 'gnukfreebsd', 'bitrig', 'netbsd', 'aix']
def platform(self):
return self._platform
@@ -89,6 +91,9 @@ class Platform(object):
def is_solaris(self):
return self._platform == 'solaris'
+ def is_aix(self):
+ return self._platform == 'aix'
+
def uses_usr_local(self):
return self._platform in ('freebsd', 'openbsd', 'bitrig')
@@ -96,8 +101,12 @@ class Platform(object):
return self._platform in ('linux', 'openbsd', 'bitrig')
def supports_ninja_browse(self):
- return not self.is_windows() and not self.is_solaris()
+ return (not self.is_windows()
+ and not self.is_solaris()
+ and not self.is_aix())
+ def can_rebuild_in_place(self):
+ return not (self.is_windows() or self.is_aix())
class Bootstrap:
"""API shim for ninja_syntax.Writer that instead runs the commands.
@@ -346,6 +355,8 @@ if platform.is_mingw():
ldflags.append('-static')
elif platform.is_solaris():
cflags.remove('-fvisibility=hidden')
+elif platform.is_aix():
+ cflags.remove('-fvisibility=hidden')
elif platform.is_msvc():
pass
else:
@@ -486,6 +497,8 @@ if platform.is_windows():
objs += cc('getopt')
else:
objs += cxx('subprocess-posix')
+if platform.is_aix():
+ objs += cc('getopt')
if platform.is_msvc():
ninja_lib = n.build(built('ninja.lib'), 'ar', objs)
else:
@@ -497,6 +510,9 @@ if platform.is_msvc():
else:
libs.append('-lninja')
+if platform.is_aix():
+ libs.append('-lperfstat')
+
all_targets = []
n.comment('Main executable is library plus main() function.')
@@ -626,17 +642,28 @@ n.build('all', 'phony', all_targets)
n.close()
print('wrote %s.' % BUILD_FILENAME)
-verbose = ''
-if options.verbose:
- verbose = ' -v'
-
if options.bootstrap:
print('bootstrap complete. rebuilding...')
- if platform.is_windows():
- bootstrap_exe = 'ninja.bootstrap.exe'
+
+ rebuild_args = []
+
+ if platform.can_rebuild_in_place():
+ rebuild_args.append('./ninja')
+ else:
+ if platform.is_windows():
+ bootstrap_exe = 'ninja.bootstrap.exe'
+ final_exe = 'ninja.exe'
+ else:
+ bootstrap_exe = './ninja.bootstrap'
+ final_exe = './ninja'
+
if os.path.exists(bootstrap_exe):
os.unlink(bootstrap_exe)
- os.rename('ninja.exe', bootstrap_exe)
- subprocess.check_call('ninja.bootstrap.exe%s' % verbose, shell=True)
- else:
- subprocess.check_call('./ninja%s' % verbose, shell=True)
+ os.rename(final_exe, bootstrap_exe)
+
+ rebuild_args.append(bootstrap_exe)
+
+ if options.verbose:
+ rebuild_args.append('-v')
+
+ subprocess.check_call(rebuild_args)
diff --git a/src/build_log.cc b/src/build_log.cc
index 589c6da..8a52514 100644
--- a/src/build_log.cc
+++ b/src/build_log.cc
@@ -12,6 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// On AIX, inttypes.h gets indirectly included by build_log.h.
+// It's easiest just to ask for the printf format macros right away.
+#ifndef _WIN32
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+#endif
+
#include "build_log.h"
#include <errno.h>
@@ -19,9 +27,6 @@
#include <string.h>
#ifndef _WIN32
-#ifndef __STDC_FORMAT_MACROS
-#define __STDC_FORMAT_MACROS
-#endif
#include <inttypes.h>
#include <unistd.h>
#endif
diff --git a/src/getopt.c b/src/getopt.c
index 3350fb9..0c2ef35 100644
--- a/src/getopt.c
+++ b/src/getopt.c
@@ -385,11 +385,13 @@ getopt_internal (int argc, char **argv, char *shortopts,
return optopt;
}
+#ifndef _AIX
int
getopt (int argc, char **argv, char *optstring)
{
return getopt_internal (argc, argv, optstring, NULL, NULL, 0);
}
+#endif
int
getopt_long (int argc, char **argv, const char *shortopts,
diff --git a/src/getopt.h b/src/getopt.h
index b4247fb..965dc29 100644
--- a/src/getopt.h
+++ b/src/getopt.h
@@ -39,7 +39,9 @@ extern "C"
extern int optopt;
/* function prototypes */
+#ifndef _AIX
int getopt (int argc, char **argv, char *optstring);
+#endif
int getopt_long (int argc, char **argv, const char *shortopts,
const GETOPT_LONG_OPTION_T * longopts, int *longind);
int getopt_long_only (int argc, char **argv, const char *shortopts,
diff --git a/src/inline.sh b/src/inline.sh
index 5acc17b..fa282fa 100755
--- a/src/inline.sh
+++ b/src/inline.sh
@@ -20,6 +20,6 @@
varname="$1"
echo "const char $varname[] ="
-od -t x1 -A n -v | sed -e 's| ||g; s|..|\\x&|g; s|^|"|; s|$|"|'
+od -t x1 -A n -v | sed -e 's|[ \t]||g; s|..|\\x&|g; s|^|"|; s|$|"|'
echo ";"
diff --git a/src/ninja.cc b/src/ninja.cc
index fe4a580..21dede6 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -22,6 +22,9 @@
#include "getopt.h"
#include <direct.h>
#include <windows.h>
+#elif defined(_AIX)
+#include "getopt.h"
+#include <unistd.h>
#else
#include <getopt.h>
#include <unistd.h>
diff --git a/src/ninja_test.cc b/src/ninja_test.cc
index 54d8784..11087b6 100644
--- a/src/ninja_test.cc
+++ b/src/ninja_test.cc
@@ -17,6 +17,9 @@
#ifdef _WIN32
#include "getopt.h"
+#elif defined(_AIX)
+#include "getopt.h"
+#include <unistd.h>
#else
#include <getopt.h>
#endif
diff --git a/src/util.cc b/src/util.cc
index aa47f2f..d150fe2 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -45,6 +45,8 @@
#elif defined(__SVR4) && defined(__sun)
#include <unistd.h>
#include <sys/loadavg.h>
+#elif defined(_AIX)
+#include <libperfstat.h>
#elif defined(linux) || defined(__GLIBC__)
#include <sys/sysinfo.h>
#endif
@@ -573,6 +575,16 @@ double GetLoadAverage() {
return posix_compatible_load;
}
+#elif defined(_AIX)
+double GetLoadAverage() {
+ perfstat_cpu_total_t cpu_stats;
+ if (perfstat_cpu_total(NULL, &cpu_stats, sizeof(cpu_stats), 1) < 0) {
+ return -0.0f;
+ }
+
+ // Calculation taken from comment in libperfstats.h
+ return double(cpu_stats.loadavg[0]) / double(1 << SBITS);
+}
#else
double GetLoadAverage() {
double loadavg[3] = { 0.0f, 0.0f, 0.0f };