diff mbox series

[iproute2-next,3/3] Makefile: support building from subdirectories

Message ID 20240703131521.60284-4-przemyslaw.kitszel@intel.com (mailing list archive)
State New
Delegated to: David Ahern
Headers show
Series minor improvements to makefile, devlink | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Przemek Kitszel July 3, 2024, 1:15 p.m. UTC
Support building also from subdirectories, like: `make -C devlink` or
`cd devlink; make`.

Extract common defines and include flags to a new file (common.mk) which
will be included from subdir makefiles via the generated config.mk file.

Note that the current, toplevel-issued, `make` still works as before.
Note that `./configure && make` is still required once after the fresh
checkout.

Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
---
 Makefile  | 45 ---------------------------------------------
 common.mk | 43 +++++++++++++++++++++++++++++++++++++++++++
 configure |  3 +++
 3 files changed, 46 insertions(+), 45 deletions(-)
 create mode 100644 common.mk

Comments

Stephen Hemminger July 3, 2024, 3:16 p.m. UTC | #1
On Wed,  3 Jul 2024 15:15:21 +0200
Przemek Kitszel <przemyslaw.kitszel@intel.com> wrote:

> Support building also from subdirectories, like: `make -C devlink` or
> `cd devlink; make`.
> 
> Extract common defines and include flags to a new file (common.mk) which
> will be included from subdir makefiles via the generated config.mk file.
> 
> Note that the current, toplevel-issued, `make` still works as before.
> Note that `./configure && make` is still required once after the fresh
> checkout.
> 
> Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>

Not sure if this really needed, it impacts more than devlink.
Przemek Kitszel July 3, 2024, 3:28 p.m. UTC | #2
On 7/3/24 17:16, Stephen Hemminger wrote:
> On Wed,  3 Jul 2024 15:15:21 +0200
> Przemek Kitszel <przemyslaw.kitszel@intel.com> wrote:
> 
>> Support building also from subdirectories, like: `make -C devlink` or
>> `cd devlink; make`.
>>
>> Extract common defines and include flags to a new file (common.mk) which
>> will be included from subdir makefiles via the generated config.mk file.
>>
>> Note that the current, toplevel-issued, `make` still works as before.
>> Note that `./configure && make` is still required once after the fresh
>> checkout.

[1]
This last "Note" could be fixed too to have proper dependencies
(in example of devlink, lib should be build first for example), and it
works now only thanks to serialized builds in terms of SUBDIRS in top
level Makefile.

>>
>> Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
> 
> Not sure if this really needed, it impacts more than devlink.

devlink is just an example here

This patch makes my development easier but it is not fixing [1]
above, so it's just a shortcut. You could drop this patch, let
me know if you will be interested in extending it to have [1] fixed.
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 2b2c3dec927e..1915b8191d3e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,6 @@ 
 # SPDX-License-Identifier: GPL-2.0
 # Top level Makefile for iproute2
 
--include config.mk
-
 ifeq ("$(origin V)", "command line")
 VERBOSE = $(V)
 endif
@@ -14,37 +12,6 @@  ifeq ($(VERBOSE),0)
 MAKEFLAGS += --no-print-directory
 endif
 
-PREFIX?=/usr
-SBINDIR?=/sbin
-NETNS_RUN_DIR?=/var/run/netns
-NETNS_ETC_DIR?=/etc/netns
-DATADIR?=$(PREFIX)/share
-HDRDIR?=$(PREFIX)/include/iproute2
-CONF_ETC_DIR?=/etc/iproute2
-CONF_USR_DIR?=$(DATADIR)/iproute2
-DOCDIR?=$(DATADIR)/doc/iproute2
-MANDIR?=$(DATADIR)/man
-ARPDDIR?=/var/lib/arpd
-KERNEL_INCLUDE?=/usr/include
-BASH_COMPDIR?=$(DATADIR)/bash-completion/completions
-
-# Path to db_185.h include
-DBM_INCLUDE:=$(DESTDIR)/usr/include
-
-SHARED_LIBS = y
-
-DEFINES= -DRESOLVE_HOSTNAMES -DLIBDIR=\"$(LIBDIR)\"
-ifneq ($(SHARED_LIBS),y)
-DEFINES+= -DNO_SHARED_LIBS
-endif
-
-DEFINES+=-DCONF_USR_DIR=\"$(CONF_USR_DIR)\" \
-         -DCONF_ETC_DIR=\"$(CONF_ETC_DIR)\" \
-         -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
-         -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\" \
-         -DARPDDIR=\"$(ARPDDIR)\" \
-         -DCONF_COLOR=$(CONF_COLOR)
-
 #options for AX.25
 ADDLIB+=ax25_ntop.o
 
@@ -59,24 +26,12 @@  ADDLIB+=netrom_ntop.o
 
 CC := gcc
 HOSTCC ?= $(CC)
-DEFINES += -D_GNU_SOURCE
-# Turn on transparent support for LFS
-DEFINES += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
-CCOPTS = -O2 -pipe
-WFLAGS := -Wall -Wstrict-prototypes  -Wmissing-prototypes
-WFLAGS += -Wmissing-declarations -Wold-style-definition -Wformat=2
-
-CFLAGS := $(WFLAGS) $(CCOPTS) -I../include -I../include/uapi $(DEFINES) $(CFLAGS)
-YACCFLAGS = -d -t -v
 
 SUBDIRS=lib ip tc bridge misc netem genl man
 ifeq ($(HAVE_MNL),y)
 SUBDIRS += tipc devlink rdma dcb vdpa
 endif
 
-LIBNETLINK=../lib/libutil.a ../lib/libnetlink.a
-LDLIBS += $(LIBNETLINK)
-
 all: config.mk
 	@set -e; \
 	for i in $(SUBDIRS); \
diff --git a/common.mk b/common.mk
new file mode 100644
index 000000000000..de26322322d6
--- /dev/null
+++ b/common.mk
@@ -0,0 +1,43 @@ 
+PREFIX?=/usr
+SBINDIR?=/sbin
+NETNS_RUN_DIR?=/var/run/netns
+NETNS_ETC_DIR?=/etc/netns
+DATADIR?=$(PREFIX)/share
+HDRDIR?=$(PREFIX)/include/iproute2
+CONF_ETC_DIR?=/etc/iproute2
+CONF_USR_DIR?=$(DATADIR)/iproute2
+DOCDIR?=$(DATADIR)/doc/iproute2
+MANDIR?=$(DATADIR)/man
+ARPDDIR?=/var/lib/arpd
+KERNEL_INCLUDE?=/usr/include
+BASH_COMPDIR?=$(DATADIR)/bash-completion/completions
+
+# Path to db_185.h include
+DBM_INCLUDE:=$(DESTDIR)/usr/include
+
+SHARED_LIBS = y
+
+DEFINES= -DRESOLVE_HOSTNAMES -DLIBDIR=\"$(LIBDIR)\"
+ifneq ($(SHARED_LIBS),y)
+DEFINES+= -DNO_SHARED_LIBS
+endif
+
+DEFINES+=-DCONF_USR_DIR=\"$(CONF_USR_DIR)\" \
+         -DCONF_ETC_DIR=\"$(CONF_ETC_DIR)\" \
+         -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
+         -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\" \
+         -DARPDDIR=\"$(ARPDDIR)\" \
+         -DCONF_COLOR=$(CONF_COLOR)
+
+DEFINES += -D_GNU_SOURCE
+# Turn on transparent support for LFS
+DEFINES += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
+CCOPTS = -O2 -pipe
+WFLAGS := -Wall -Wstrict-prototypes  -Wmissing-prototypes
+WFLAGS += -Wmissing-declarations -Wold-style-definition -Wformat=2
+
+CFLAGS := $(WFLAGS) $(CCOPTS) -I../include -I../include/uapi $(DEFINES) $(CFLAGS)
+YACCFLAGS = -d -t -v
+
+LIBNETLINK=../lib/libutil.a ../lib/libnetlink.a
+LDLIBS += $(LIBNETLINK)
diff --git a/configure b/configure
index 928048b3d8c0..978f787ce4d3 100755
--- a/configure
+++ b/configure
@@ -615,6 +615,9 @@  check_cap
 echo -n "color output: "
 check_color
 
+# must be after check_color
+echo "include ../common.mk" >> $CONFIG
+
 echo >> $CONFIG
 echo "%.o: %.c" >> $CONFIG
 echo '	$(QUIET_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CPPFLAGS) -c -o $@ $<' >> $CONFIG