Skip to content

Commit

Permalink
build: use custom build flags for numademo
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
filbranden committed Aug 5, 2014
1 parent 21aa93b commit 46b0dee
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ numactl_SOURCES = numactl.c util.c shm.c shm.h
numactl_LDADD = libnuma.la

numastat_SOURCES = numastat.c
numastat_CFLAGS = -std=gnu99
numastat_CFLAGS = $(AM_CFLAGS) -std=gnu99

numademo_SOURCES = numademo.c stream_lib.c stream_lib.h mt.c mt.h clearcache.c clearcache.h
numademo_CPPFLAGS = $(AM_CPPFLAGS) -DHAVE_STREAM_LIB -DHAVE_MT -DHAVE_CLEAR_CACHE
numademo_CFLAGS = -O3 -ffast-math -funroll-loops
numademo_LDADD = libnuma.la -lm

migratepages_SOURCES = migratepages.c util.c
Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ LT_INIT

AC_PROG_CC

# Override CFLAGS so that we can specify custom CFLAGS for numademo.
AX_AM_OVERRIDE_VAR([CFLAGS])

AX_TLS

AC_CONFIG_FILES([Makefile])
Expand Down
155 changes: 155 additions & 0 deletions m4/ax_am_override_var.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_am_override_var.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_AM_OVERRIDE_VAR([varname1 varname ... ])
# AX_AM_OVERRIDE_FINALIZE
#
# DESCRIPTION
#
# This autoconf macro generalizes the approach given in
# <http://lists.gnu.org/archive/html/automake/2005-09/msg00108.html> which
# moves user specified values for variable 'varname' given at configure
# time into the corresponding AM_${varname} variable and clears out
# 'varname', allowing further manipulation by the configure script so that
# target specific variables can be given specialized versions. 'varname
# may still be specified on the make command line and will be appended as
# usual.
#
# As an example usage, consider a project which might benefit from
# different compiler flags for different components. Typically this is
# done via target specific flags, e.g.
#
# libgtest_la_CXXFLAGS = \
# -I $(top_srcdir)/tests \
# -I $(top_builddir)/tests \
# $(GTEST_CXXFLAGS)
#
# automake will automatically append $(CXXFLAGS) -- provided by the user
# -- to the build rule for libgtest_la. That might be problematic, as
# CXXFLAGS may contain compiler options which are inappropriate for
# libgtest_la.
#
# The approach laid out in the referenced mailing list message is to
# supply a base value for a variable during _configure_ time, during which
# it is possible to amend it for specific targets. The user may
# subsequently specify a value for the variable during _build_ time, which
# make will apply (via the standard automake rules) to all appropriate
# targets.
#
# For example,
#
# AX_AM_OVERRIDE_VAR([CXXFLAGS])
#
# will store the value of CXXFLAGS specified at configure time into the
# AM_CXXFLAGS variable, AC_SUBST it, and clear CXXFLAGS. configure may
# then create a target specific set of flags based upon AM_CXXFLAGS, e.g.
#
# # googletest uses variadic macros, which g++ -pedantic-errors
# # is very unhappy about
# AC_SUBST([GTEST_CXXFLAGS],
# [`AS_ECHO_N(["$AM_CXXFLAGS"]) \
# | sed s/-pedantic-errors/-pedantic/`
# ]
# )
#
# which would be used in a Makefile.am as above. Since CXXFLAGS is
# cleared, the configure time value will not affect the build for
# libgtest_la.
#
# Prior to _any other command_ which may set ${varname}, call
#
# AX_AM_OVERRIDE_VAR([varname])
#
# This will preserve the value (if any) passed to configure in
# AM_${varname} and AC_SUBST([AM_${varname}). You may pass a space
# separated list of variable names, or may call AX_AM_OVERRIDE_VAR
# multiple times for the same effect.
#
# If any subsequent configure commands set ${varname} and you wish to
# capture the resultant value into AM_${varname} in the case where
# ${varname} was _not_ provided at configure time, call
#
# AX_AM_OVERRIDE_FINALIZE
#
# after _all_ commands which might affect any of the variables specified
# in calls to AX_AM_OVERRIDE_VAR. This need be done only once, but
# repeated calls will not cause harm.
#
# There is a bit of trickery required to allow further manipulation of the
# AM_${varname} in a Makefile.am file. If AM_CFLAGS is used as is in a
# Makefile.am, e.g.
#
# libfoo_la_CFLAGS = $(AM_CFLAGS)
#
# then automake will emit code in Makefile.in which sets AM_CFLAGS from
# the configure'd value.
#
# If however, AM_CFLAGS is manipulated (i.e. appended to), you will have
# to explicitly arrange for the configure'd value to be substituted:
#
# AM_CFLAGS = @AM_CFLAGS@
# AM_CFLAGS += -lfoo
#
# or else automake will complain about using += before =.
#
# LICENSE
#
# Copyright (c) 2013 Smithsonian Astrophysical Observatory
# Copyright (c) 2013 Diab Jerius <[email protected]>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 1

AC_DEFUN([_AX_AM_OVERRIDE_INITIALIZE],
[
m4_define([_mst_am_override_vars],[])
])


# _AX_AM_OVERRIDE_VAR(varname)
AC_DEFUN([_AX_AM_OVERRIDE_VAR],
[
m4_define([_mst_am_override_vars], m4_defn([_mst_am_override_vars]) $1 )
_mst_am_override_$1_set=false
AS_IF( [test "${$1+set}" = set],
[AC_SUBST([AM_$1],["$$1"])
$1=
_mst_am_override_$1_set=:
]
)
]) # _AX_AM_OVERRIDE_VAR

# _AX_AM_OVERRIDE_FINALIZE(varname)
AC_DEFUN([_AX_AM_OVERRIDE_FINALIZE],
[
AS_IF([$_mst_am_override_$1_set = :],
[],
[AC_SUBST([AM_$1],["$$1"])
$1=
_mst_am_override_$1_set=
]
)
AC_SUBST($1)
]) # _AX_AM_OVERRIDE_FINALIZE

AC_DEFUN([AX_AM_OVERRIDE_VAR],
[
AC_REQUIRE([_AX_AM_OVERRIDE_INITIALIZE])
m4_map_args_w([$1],[_AX_AM_OVERRIDE_VAR(],[)])
])# AX_OVERRIDE_VAR


# AX_AM_OVERRIDE_FINALIZE
AC_DEFUN([AX_AM_OVERRIDE_FINALIZE],
[
AC_REQUIRE([_AX_AM_OVERRIDE_INITIALIZE])
m4_map_args_w(_mst_am_override_vars,[_AX_AM_OVERRIDE_FINALIZE(],[)])
]) # AX_AM_OVERRIDE_FINALIZE

0 comments on commit 46b0dee

Please sign in to comment.