build: add a .gitignore to ignore build targets and temporary files

Ignore build targets and temporary files created during the build.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
test: fix the bind_range test

Make the test script executable in the repo (and remove the chmod 755 at
test run time), set $PATH and $LD_LIBRARY_PATH correctly to use the
numactl and libnuma.so from the build tree.

Tested:
- Running "make regress2" passed.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
build: automake and libtool support

Use autotools (automake, autoconf, libtool) to build numactl, libnuma
and the additional distribution binaries.

Set up the build with:
  $ autoreconf --install --symlink

Build with:
  $ ./configure --prefix=/usr
  $ make

Install with:
  root# make install

Or install to a staging directory with:
  $ make install DESTDIR=/path/to/staging/numactl

Create a distribution archive with:
  $ make dist

Test the distribution archive with:
  $ make distcheck

Tested:
- Ran all make commands above and made sure they worked.
- Confirmed that the binaries built with automake work as expected.
- Compared the now libtool-based libnuma.so.1 with the one built
  directly and confirmed they are identical and interoperable.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
build: switch from legacy Makefile to automake

Switch to using automake for the build.

Remove files only needed by the legacy build system.

Use ./autogen.sh to generate the configure script and the Makefile and
config.h templates.

Include an INSTALL file with build instructions (from either archive or
from the git tree.)

Tested:
- Built it using autotools: ./autogen.sh && ./configure && make

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
build: use silent build rules by default

Using rules that only print "CC" and "CCLD" instead of full build
commands actually makes it easier to spot warnings and errors.

Increasing verbosity and seeing the full compile commands is still
possible by passing V=1 to the make command.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
build: enable warnings during build

Pass compile commands the -Wall parameter.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
build: use AX_TLS macro to detect whether __thread is supported

Definition of AX_TLS comes from the autoconf-archive project
(http://www.gnu.org/software/autoconf-archive/) to detect the feature.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
build: use custom build flags for numademo

numademo should be built with "-O3 -ffast-math -funroll-loops" instead
of the default (CFLAGS defaults to "-g -O2" for gcc).

Use the AX_AM_OVERRIDE_VAR macro from the autoconf-archive project
(http://www.gnu.org/software/autoconf-archive/) to rename the variable.

The AX_AM_OVERRIDE_VAR macro will rename CFLAGS to AM_CFLAGS, so that it
can be overridden for numademo with numademo_CFLAGS.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
build: use -ftree-vectorize for numademo if available

Have ./configure detect whether the compiler supports the flag. If that
is the case, then use it when compiling numademo.

Use the AX_CHECK_COMPILE_FLAG macro from the autoconf-archive project
(http://www.gnu.org/software/autoconf-archive/) to detect the compiler
feature.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
build: keep build objects in their subdirectories

This will be required when building the test cases to disambiguate
between distance.c and test/distance.c. It also makes for a cleaner
build tree.

Update .gitignore to handle temporary build files in subdirectories.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
build: add build rules for legacy test cases

Add automake rules to build the test programs and run the test scripts.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
test: do not set LD_LIBRARY_PATH in test scripts

Setting LD_LIBRARY_PATH is no longer needed since libtool is used to
build binaries and libraries. libtool creates shell stubs for the
binaries so that they do not need to be called with an appropriate
LD_LIBRARY_PATH to work.

Tested:
- Made sure "make test" still works as expected.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
test: make test scripts run from any location.

No longer require that the scripts are run from inside the test/
directory.

Introduce two environment variables ${srcdir} and ${builddir} to help
the tests find the other tests, test helper scripts and the built
binaries. Guess the locations of ${srcdir} and ${builddir} in case they
are not defined in the environment.

Tested:
- Made sure "make test" still works.
- Also called the scripts directory from outside the test directory.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
test: skip test "regress" when hardware is not available

Test "regress" needs at least two nodes with $NEEDPAGES of free memory
each. If that is not available, exit with return code 77 so that
automake will know it is supposed to skip the test.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
build: implement "make check" to run test cases

This will run the regress1 and regress2 tests, which were typically run
when "make test" was called.

"make test" would also call numademo, having "make check" run it as well
is coming up on the next commit.

Tested:
- Ran "make check" and confirmed tests passed.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
test: run numademo on "make check"

Tested:
- Ran "make check" and confirmed numademo was run.
- Inspected test/numademo.log after running the test.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
numastat: fix warning in fgets call

In get_screen_width, error checking was not being performed in the fgets
call reading the first line of the `resize` output.

Tested:
- Ran "numastat" and checked the output.
- Successfully executed "make check".

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
test: mark scripts that need bash as such

In particular, printcpu uses bash arrays, so it needs to run with bash.

Tested:
- Ran "make check" on a machine with "dash" as /bin/sh.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
cleanup: remove double "const" in affinity.c

While "const const" works, a single "const" modifier is enough.

This was caught as a warning from the clang compiler.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
cleanup: fix printf format of long long to "ll"

The "ll" modifier is the correct one according to the C99 standard,
while the "L" modifier is meant for long double.

This was caught as a warning from the clang compiler.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>