iw: Makefile: support out-of-tree builds
PATCH 1/1 iw: Makefile: support out-of-tree builds
Enable out-of-tree builds without modifying the source tree. Out-of-tree builds are required by build frameworks such as OpenEmbedded.
--- Makefile | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
Makefile +16 -7
@@ -1,5 +1,8 @@ MAKEFLAGS += --no-print-directory +SRCDIR := $(dir $(lastword $(MAKEFILE_LIST))) +VPATH := $(SRCDIR) + PREFIX ?= /usr SBINDIR ?= $(PREFIX)/sbin MANDIR ?= $(PREFIX)/share/man
@@ -21,7 +24,11 @@ CFLAGS += -D__SANE_USERSPACE_TYPES__ CFLAGS += $(CFLAGS_EVAL) CFLAGS += $(EXTRA_CFLAGS) -_OBJS := $(sort $(patsubst %.c,%.o,$(wildcard *.c))) +CPPFLAGS += -I$(SRCDIR) +CPPFLAGS += -I. + +_SRCS := $(wildcard $(SRCDIR)/*.c) +_OBJS := $(sort $(patsubst $(SRCDIR)/%.c,%.o,$(_SRCS))) VERSION_OBJS := $(filter-out version.o, $(_OBJS)) OBJS := $(VERSION_OBJS) version.o
@@ -92,16 +99,18 @@ endif all: $(ALL) -version.c: version.sh $(patsubst %.o,%.c,$(VERSION_OBJS)) nl80211.h iw.h Makefile \ - $(wildcard .git/index .git/refs/tags) +version.c: $(SRCDIR)/version.sh \ + $(patsubst %.o,$(SRCDIR)/%.c,$(VERSION_OBJS)) \ + $(SRCDIR)/nl80211.h $(SRCDIR)/iw.h $(SRCDIR)/Makefile \ + $(wildcard $(SRCDIR)/.git/index $(SRCDIR)/.git/refs/tags) @$(NQ) ' GEN ' $@ - $(Q)./version.sh $@ + $(Q)$(SRCDIR)/version.sh $@ -nl80211-commands.inc: nl80211.h +nl80211-commands.inc: $(SRCDIR)/nl80211.h @$(NQ) ' GEN ' $@ - $(Q)sed 's%^\tNL80211_CMD_%%;t n;d;:n s%^\([^=]*\),.*%\t[NL80211_CMD_\1] = \"\L\1\",%;t;d' nl80211.h | grep -v "reserved" > $@ + $(Q)sed 's%^\tNL80211_CMD_%%;t n;d;:n s%^\([^=]*\),.*%\t[NL80211_CMD_\1] = \"\L\1\",%;t;d' $(SRCDIR)/nl80211.h | grep -v "reserved" > $@ -%.o: %.c iw.h nl80211.h nl80211-commands.inc +%.o: %.c $(SRCDIR)/iw.h $(SRCDIR)/nl80211.h nl80211-commands.inc @$(NQ) ' CC ' $@ $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
Signature · 1 line
2.47.3
Quoted 2 lines · Maxin John
Enable out-of-tree builds without modifying the source tree. Out-of-tree builds are required by build frameworks such as OpenEmbedded.
You should probably say how this is intended to be used, clearly not in the O= way that the kernel has, for example.
Quoted 1 line
+SRCDIR := $(dir $(lastword $(MAKEFILE_LIST)))
That doesn't work if there's whitespace anywhere along the path.
Makefile CFLAGS += -D__SANE_USERSPACE_TYPES__ · line 28
Quoted 2 lines
Makefile +2
-0+CPPFLAGS += -I$(SRCDIR) +CPPFLAGS += -I.
The "-I." seems questionable since you evidently intend to have "." *not* be the source dir?
Overall it might be simpler to actually do it with the kernel-style O= so you just need to change all the outputs, rather than all the inputs?
johannes
Hi Johannes,
Thanks for the review comments.
Quoted 6 lines · Johannes Berg
Quoted 2 lines · Maxin John
Enable out-of-tree builds without modifying the source tree. Out-of-tree builds are required by build frameworks such as OpenEmbedded.
You should probably say how this is intended to be used, clearly not in the O= way that the kernel has, for example.
I will clarify the intended usage in the next iteration.
Quoted 9 lines
Quoted 1 line
+SRCDIR := $(dir $(lastword $(MAKEFILE_LIST)))
That doesn't work if there's whitespace anywhere along the path.
Makefile CFLAGS += -D__SANE_USERSPACE_TYPES__ · line 28
Quoted 2 lines
Makefile +2
-0+CPPFLAGS += -I$(SRCDIR) +CPPFLAGS += -I.The "-I." seems questionable since you evidently intend to have "." *not* be the source dir?
The -I. was intended to ensure that generated files such as nl80211-commands.inc, which are produced in the build directory,
remain discoverable by the compiler. Agree that it doesn't look right
and I will update it.
Quoted 3 lines
Overall it might be simpler to actually do it with the kernel-style O= so you just need to change all the outputs, rather than all the inputs?
Got it. I will update it as per your comments and send a v2.
Quoted 2 lines
johannes
Best Regards,
Maxin
Quoted 10 lines · Maxin John
Quoted 5 lines
Quoted 2 lines
+CPPFLAGS += -I.
The "-I." seems questionable since you evidently intend to have "." *not* be the source dir?
The -I. was intended to ensure that generated files such as nl80211-commands.inc, which are produced in the build directory,
remain discoverable by the compiler. Agree that it doesn't look right
and I will update it.
Oh, I guess that makes sense, maybe just add a comment? But that's after guessing you somehow intend to call 'make -f ../src/Makefile' or something, which seems a little odd to me?
johannes