Skip to content

Commit

Permalink
build: properly split CFLAGS from AC_CFLAGS
Browse files Browse the repository at this point in the history
`CFLAGS` is a "user variable", not intended to be controlled by
configure itself.  Let's put all the "important" stuff in AC_CFLAGS and
only leave debug/optimization controls in CFLAGS.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
  • Loading branch information
eqvinox committed Apr 21, 2021
1 parent 0978119 commit 0c4285d
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 31 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ AUTOMAKE_OPTIONS = subdir-objects 1.12
ACLOCAL_AMFLAGS = -I m4

AM_CFLAGS = \
$(AC_CFLAGS) \
$(LIBYANG_CFLAGS) \
$(SQLITE3_CFLAGS) \
$(UNWIND_CFLAGS) \
Expand Down
5 changes: 4 additions & 1 deletion bgpd/rfp-example/rfptest/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ if ENABLE_BGP_VNC
noinst_PROGRAMS += bgpd/rfp-example/rfptest/rfptest
endif

bgpd_rfp_example_rfptest_rfptest_CFLAGS = -I$(top_srcdir)/bgpd/rfapi
bgpd_rfp_example_rfptest_rfptest_CFLAGS = \
$(AM_CFLAGS) \
-I$(top_srcdir)/bgpd/rfapi \
# end
bgpd_rfp_example_rfptest_rfptest_SOURCES = \
bgpd/rfp-example/rfptest/rfptest.c \
# end
Expand Down
7 changes: 2 additions & 5 deletions bgpd/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,17 @@ noinst_HEADERS += \
bgpd_bgpd_SOURCES = bgpd/bgp_main.c
bgpd_bgp_btoa_SOURCES = bgpd/bgp_btoa.c

bgpd_bgpd_CFLAGS = $(AM_CFLAGS)
bgpd_bgp_btoa_CFLAGS = $(AM_CFLAGS)

# RFPLDADD is set in bgpd/rfp-example/librfp/subdir.am
bgpd_bgpd_LDADD = bgpd/libbgp.a $(RFPLDADD) lib/libfrr.la $(LIBCAP) $(LIBM) $(UST_LIBS)
bgpd_bgp_btoa_LDADD = bgpd/libbgp.a $(RFPLDADD) lib/libfrr.la $(LIBCAP) $(LIBM) $(UST_LIBS)

bgpd_bgpd_snmp_la_SOURCES = bgpd/bgp_snmp.c bgpd/bgp_mplsvpn_snmp.c
bgpd_bgpd_snmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) -std=gnu11
bgpd_bgpd_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11
bgpd_bgpd_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
bgpd_bgpd_snmp_la_LIBADD = lib/libfrrsnmp.la

bgpd_bgpd_rpki_la_SOURCES = bgpd/bgp_rpki.c
bgpd_bgpd_rpki_la_CFLAGS = $(WERROR) $(RTRLIB_CFLAGS)
bgpd_bgpd_rpki_la_CFLAGS = $(AM_CFLAGS) $(RTRLIB_CFLAGS)
bgpd_bgpd_rpki_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
bgpd_bgpd_rpki_la_LIBADD = $(RTRLIB_LIBS)

Expand Down
21 changes: 12 additions & 9 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ AC_SUBST([SED])
dnl try and enable CFLAGS that are useful for FRR
dnl - specifically, options to control warnings

AC_SUBST([AC_CFLAGS])
AC_USE_SYSTEM_EXTENSIONS
AC_DEFUN([AC_C_FLAG], [{
m4_pushdef([cachename],[m4_translit([frr_cv_$1],[ =-+/{}$],[________])])
Expand All @@ -223,7 +224,7 @@ AC_DEFUN([AC_C_FLAG], [{
AC_LANG_POP([C])
])
if test "$cachename" = "yes"; then
m4_if([$3], [], [CFLAGS="$CFLAGS $1"], [$3])
m4_if([$3], [], [AC_CFLAGS="$AC_CFLAGS $1"], [$3])
else
:
$2
Expand Down Expand Up @@ -275,7 +276,7 @@ if test "$enable_gcov" = "yes"; then
AC_C_FLAG([-O0])
fi

LDFLAGS="${LDFLAGS} -lgcov"
AC_LDFLAGS="${AC_LDFLAGS} -lgcov"
fi

if test "$enable_clang_coverage" = "yes"; then
Expand All @@ -302,17 +303,19 @@ if test "$enable_scripting" = "yes"; then
])
fi

dnl the following flags go in CFLAGS rather than AC_CFLAGS since they make
dnl sense to be overridden by the user
if test "$enable_dev_build" = "yes"; then
AC_DEFINE([DEV_BUILD], [1], [Build for development])
if test "$orig_cflags" = ""; then
AC_C_FLAG([-g3])
AC_C_FLAG([-O0])
AC_C_FLAG([-ggdb3])
AC_C_FLAG([-O0],,[CFLAGS="$CFLAGS -O0"])
AC_C_FLAG([-g3],,[CFLAGS="$CFLAGS -g3"])
AC_C_FLAG([-ggdb3],,[CFLAGS="$CFLAGS -ggdb3"])
fi
else
if test "$orig_cflags" = ""; then
AC_C_FLAG([-g])
AC_C_FLAG([-O2])
AC_C_FLAG([-g],,[CFLAGS="$CFLAGS -g"])
AC_C_FLAG([-O2],,[CFLAGS="$CFLAGS -O2"])
fi
fi

Expand Down Expand Up @@ -449,7 +452,7 @@ dnl ----------

AX_PTHREAD([
CC="$PTHREAD_CC"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
AC_CFLAGS="$AC_CFLAGS $PTHREAD_CFLAGS"
LIBS="$PTHREAD_LIBS $LIBS"
], [
AC_MSG_FAILURE([This FRR version needs pthreads])
Expand Down Expand Up @@ -2652,7 +2655,7 @@ FRR version : ${PACKAGE_VERSION}
host operating system : ${host_os}
source code location : ${srcdir}
compiler : ${CC}
compiler flags : ${CFLAGS} ${SAN_FLAGS}
compiler flags : ${CFLAGS} ${AC_CFLAGS} ${SAN_FLAGS}
make : ${MAKE-make}
linker flags : ${LDFLAGS} ${SAN_FLAGS} ${LIBS} ${LIBCAP} ${LIBREADLINE} ${LIBM}
state file directory : ${frr_statedir}
Expand Down
2 changes: 1 addition & 1 deletion isisd/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ nodist_isisd_isisd_SOURCES = \
# end

isisd_isisd_snmp_la_SOURCES = isisd/isis_snmp.c
isisd_isisd_snmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) -std=gnu11
isisd_isisd_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11
isisd_isisd_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
isisd_isisd_snmp_la_LIBADD = lib/libfrrsnmp.la

Expand Down
2 changes: 1 addition & 1 deletion ldpd/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ ldpd_ldpd_SOURCES = ldpd/ldpd.c
ldpd_ldpd_LDADD = ldpd/libldp.a lib/libfrr.la $(LIBCAP)

ldpd_ldpd_snmp_la_SOURCES = ldpd/ldp_snmp.c
ldpd_ldpd_snmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) -std=gnu11
ldpd_ldpd_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11
ldpd_ldpd_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
ldpd_ldpd_snmp_la_LIBADD = lib/libfrrsnmp.la
12 changes: 6 additions & 6 deletions lib/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ if SNMP
lib_LTLIBRARIES += lib/libfrrsnmp.la
endif

lib_libfrrsnmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) -std=gnu11
lib_libfrrsnmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11
lib_libfrrsnmp_la_LDFLAGS = -version-info 0:0:0
lib_libfrrsnmp_la_LIBADD = $(SNMP_LIBS)
lib_libfrrsnmp_la_SOURCES = \
Expand All @@ -334,7 +334,7 @@ lib_LTLIBRARIES += lib/libfrrcares.la
pkginclude_HEADERS += lib/resolver.h
endif

lib_libfrrcares_la_CFLAGS = $(WERROR) $(CARES_CFLAGS)
lib_libfrrcares_la_CFLAGS = $(AM_CFLAGS) $(CARES_CFLAGS)
lib_libfrrcares_la_LDFLAGS = -version-info 0:0:0
lib_libfrrcares_la_LIBADD = $(CARES_LIBS)
lib_libfrrcares_la_SOURCES = \
Expand All @@ -349,7 +349,7 @@ lib_LTLIBRARIES += lib/libfrrzmq.la
pkginclude_HEADERS += lib/frr_zmq.h
endif

lib_libfrrzmq_la_CFLAGS = $(WERROR) $(ZEROMQ_CFLAGS)
lib_libfrrzmq_la_CFLAGS = $(AM_CFLAGS) $(ZEROMQ_CFLAGS)
lib_libfrrzmq_la_LDFLAGS = -version-info 0:0:0
lib_libfrrzmq_la_LIBADD = $(ZEROMQ_LIBS)
lib_libfrrzmq_la_SOURCES = \
Expand All @@ -363,7 +363,7 @@ if CONFD
module_LTLIBRARIES += lib/confd.la
endif

lib_confd_la_CFLAGS = $(WERROR) $(CONFD_CFLAGS)
lib_confd_la_CFLAGS = $(AM_CFLAGS) $(CONFD_CFLAGS)
lib_confd_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
lib_confd_la_LIBADD = lib/libfrr.la $(CONFD_LIBS)
lib_confd_la_SOURCES = lib/northbound_confd.c
Expand All @@ -375,7 +375,7 @@ if SYSREPO
module_LTLIBRARIES += lib/sysrepo.la
endif

lib_sysrepo_la_CFLAGS = $(WERROR) $(SYSREPO_CFLAGS)
lib_sysrepo_la_CFLAGS = $(AM_CFLAGS) $(SYSREPO_CFLAGS)
lib_sysrepo_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
lib_sysrepo_la_LIBADD = lib/libfrr.la $(SYSREPO_LIBS)
lib_sysrepo_la_SOURCES = lib/northbound_sysrepo.c
Expand Down Expand Up @@ -414,7 +414,7 @@ lib_grammar_sandbox_LDADD = \
lib/libfrr.la

lib_clippy_CPPFLAGS = $(AM_CPPFLAGS) -D_GNU_SOURCE -DBUILDING_CLIPPY
lib_clippy_CFLAGS = $(PYTHON_CFLAGS)
lib_clippy_CFLAGS = $(AC_CFLAGS) $(PYTHON_CFLAGS)
lib_clippy_LDADD = $(PYTHON_LIBS) $(UST_LIBS) -lelf
lib_clippy_LDFLAGS = -export-dynamic
lib_clippy_SOURCES = \
Expand Down
2 changes: 1 addition & 1 deletion ospf6d/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ospf6d_ospf6d_SOURCES = \
# end

ospf6d_ospf6d_snmp_la_SOURCES = ospf6d/ospf6_snmp.c
ospf6d_ospf6d_snmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) -std=gnu11
ospf6d_ospf6d_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11
ospf6d_ospf6d_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
ospf6d_ospf6d_snmp_la_LIBADD = lib/libfrrsnmp.la

Expand Down
2 changes: 1 addition & 1 deletion ospfd/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ ospfd_ospfd_LDADD = ospfd/libfrrospf.a lib/libfrr.la $(LIBCAP) $(LIBM)
ospfd_ospfd_SOURCES = ospfd/ospf_main.c

ospfd_ospfd_snmp_la_SOURCES = ospfd/ospf_snmp.c
ospfd_ospfd_snmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) -std=gnu11
ospfd_ospfd_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11
ospfd_ospfd_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
ospfd_ospfd_snmp_la_LIBADD = lib/libfrrsnmp.la

Expand Down
2 changes: 1 addition & 1 deletion pathd/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ pathd_pathd_pcep_la_LIBADD =
endif


pathd_pathd_pcep_la_CFLAGS = $(WERROR)
#pathd_pathd_pcep_la_CFLAGS = $(AM_CFLAGS)
pathd_pathd_pcep_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
2 changes: 1 addition & 1 deletion pceplib/subdir.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if PATHD_PCEP

noinst_LTLIBRARIES = pceplib/libpcep_pcc.la pceplib/libsocket_comm_mock.la
pceplib_libpcep_pcc_la_CFLAGS = -fPIC
pceplib_libpcep_pcc_la_CFLAGS = $(AM_CFLAGS) -fPIC
pceplib_libpcep_pcc_la_SOURCES = pceplib/pcep_msg_messages.c \
pceplib/pcep_msg_objects.c \
pceplib/pcep_msg_tlvs.c \
Expand Down
4 changes: 2 additions & 2 deletions pceplib/test/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ noinst_HEADERS += pceplib/test/pcep_msg_messages_test.h \
pceplib/test/pcep_utils_ordered_list_test.h \
pceplib/test/pcep_utils_queue_test.h

pceplib_test_pcep_msg_tests_CFLAGS = -I$(top_srcdir)/pceplib
pceplib_test_pcep_msg_tests_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/pceplib
pceplib_test_pcep_msg_tests_LDADD = $(top_builddir)/pceplib/libpcep_pcc.la lib/libfrr.la -lcunit -lpthread
pceplib_test_pcep_msg_tests_SOURCES = pceplib/test/pcep_msg_messages_test.c \
pceplib/test/pcep_msg_messages_tests.c \
Expand All @@ -47,7 +47,7 @@ pceplib_test_pcep_msg_tests_SOURCES = pceplib/test/pcep_msg_messages_test.c \

# The pcc_api_tests and pcep_session_logic_tests use the
# socket_comm_mock, so the LDADD variable needs to be modified
pceplib_test_pcep_pcc_api_tests_CFLAGS = -I$(top_srcdir)/pceplib
pceplib_test_pcep_pcc_api_tests_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/pceplib
pceplib_test_pcep_pcc_api_tests_LDADD = $(top_builddir)/pceplib/libsocket_comm_mock.la $(top_builddir)/pceplib/libpcep_pcc.la lib/libfrr.la -lcunit -lpthread
pceplib_test_pcep_pcc_api_tests_SOURCES = pceplib/test/pcep_pcc_api_test.c pceplib/test/pcep_pcc_api_tests.c

Expand Down
2 changes: 1 addition & 1 deletion ripd/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ nodist_ripd_ripd_SOURCES = \
# end

ripd_ripd_snmp_la_SOURCES = ripd/rip_snmp.c
ripd_ripd_snmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) -std=gnu11
ripd_ripd_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11
ripd_ripd_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
ripd_ripd_snmp_la_LIBADD = lib/libfrrsnmp.la
1 change: 1 addition & 0 deletions tests/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ TESTS_CPPFLAGS = $(AM_CPPFLAGS) \
-I$(top_builddir)/tests/helpers/c \
# end
TESTS_CFLAGS = \
$(AC_CFLAGS) \
$(LIBYANG_CFLAGS) \
$(SAN_FLAGS) \
# end
Expand Down
2 changes: 1 addition & 1 deletion zebra/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ zebra_zebra_irdp_la_SOURCES = \
zebra_zebra_irdp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic

zebra_zebra_snmp_la_SOURCES = zebra/zebra_snmp.c
zebra_zebra_snmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) -std=gnu11
zebra_zebra_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11
zebra_zebra_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic
zebra_zebra_snmp_la_LIBADD = lib/libfrrsnmp.la

Expand Down

0 comments on commit 0c4285d

Please sign in to comment.