Makefile: fix "version.h" build for cross-compiling
Subsystems (2)
PATCH 1/3 Makefile: fix "version.h" build for cross-compiling
When using "make CROSS=mipsel-linux-", I get the following errors:
/bin/sh: /home/norris/git/mtd-utils/mipsel-linux/include/version.h.tmp: No such file or directory
make: *** [/home/norris/git/mtd-utils/mipsel-linux/include/version.h.tmp] Error 1
So instead of "building" our version.h within $(BUILDIR), we should just build it in the main source directory, as it isn't architecture- specific or anything. Hopefully that doesn't "break the rules" of our cross-compilation setup...
--- Makefile | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
Makefile +4 -4
@@ -38,7 +38,7 @@ TARGETS = $(BINS) TARGETS += lib/libmtd.a TARGETS += ubi-utils/libubi.a -OBJDEPS = $(BUILDDIR)/include/version.h +OBJDEPS = include/version.h include common.mk
@@ -53,7 +53,7 @@ endif find $(BUILDDIR)/ -xdev \ '(' -name '*.[ao]' -o -name '.*.c.dep' ')' \ -exec rm -f {} + - rm -f $(BUILDDIR)/include/version.h + rm -f include/version.h $(MAKE) -C $(TESTS) clean install:: ${BINS} ${SCRIPTS}
@@ -68,9 +68,9 @@ tests:: cscope: cscope -bR -$(BUILDDIR)/include/version.h: $(BUILDDIR)/include/version.h.tmp +include/version.h: include/version.h.tmp $(Q)cmp -s $@ [email protected] && rm -f [email protected] || mv [email protected] $@ -$(BUILDDIR)/include/version.h.tmp: +include/version.h.tmp: $(Q)echo '#define VERSION "$(VERSION)"' > $@ #
Signature · 1 line
1.7.0.4
PATCH 2/3 Makefile: fix "make clean" for cross-compile
When cross-compiling (make CROSS=mipsel-linux-), I get this error:
rm -rf /home/norris/git/mtd-utils/mipsel-linux
find /home/norris/git/mtd-utils/mipsel-linux/ -xdev \
'(' -name '*.[ao]' -o -name '.*.c.dep' ')' \
-exec rm -f {} +find: `/home/norris/git/mtd-utils/mipsel-linux/': No such file or directory
make: *** [clean] Error 1
Now, for cross-compiling, we've already deleted the $(BUILDDIR), so we should check this before cleaning individual objects with "find."
--- Makefile | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
Makefile +5 -3
@@ -50,9 +50,11 @@ ifneq ($(BUILDDIR),$(CURDIR)) endif endif endif - find $(BUILDDIR)/ -xdev \ - '(' -name '*.[ao]' -o -name '.*.c.dep' ')' \ - -exec rm -f {} + + @if test -d "$(BUILDDIR)/"; then \ + find $(BUILDDIR)/ -xdev \ + '(' -name '*.[ao]' -o -name '.*.c.dep' ')' \ + -exec rm -f {} + ; \ + fi rm -f include/version.h $(MAKE) -C $(TESTS) clean
Signature · 1 line
1.7.0.4
PATCH 3/3 Makefile: show nice message when checking version.h
In reply to Brian Norris--- Makefile | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
Makefile +1 -0
@@ -71,6 +71,7 @@ cscope: cscope -bR include/version.h: include/version.h.tmp + $(call BECHO,CHK) $(Q)cmp -s $@ [email protected] && rm -f [email protected] || mv [email protected] $@ include/version.h.tmp: $(Q)echo '#define VERSION "$(VERSION)"' > $@
Signature · 1 line
1.7.0.4
Quoted 9 lines · Brian Norris
When using "make CROSS=mipsel-linux-", I get the following errors:
/bin/sh:/home/norris/git/mtd-utils/mipsel-linux/include/version.h.tmp: No such file or directory
make: *** [/home/norris/git/mtd-utils/mipsel-linux/include/version.h.tmp] Error 1So instead of "building" our
version.hwithin $(BUILDIR), we should just build it in the main source directory, as it isn't architecture- specific or anything. Hopefully that doesn't "break the rules" of our cross-compilation setup...
i dont think it's just a matter of "diff build dir for diff toolchains, so common version.h is ok". it's a matter of "building out of tree should build out of tree".
i think the fix to your problem is:
$(BUILDDIR)/include/version.h.tmp
+ $(Q)mkdir -p $(dir $@)
$(Q)echo '#define VERSION "$(VERSION)"' > $@
-mike
Re: [PATCH 3/3] Makefile: show nice message when checking version.h
In reply to Brian Norris-mike
Re: [PATCH 2/3] Makefile: fix "make clean" for cross-compile
In reply to Brian Norris-mike
Quoted 3 lines · Mike Frysinger
i dont think it's just a matter of "diff build dir for diff toolchains, so common
version.his ok". it's a matter of "building out of tree should build out of tree".
OK, but what is the point of in- vs. out-of-tree? So that we can have a readonly source directory where the mtd-utils code stays? Or so that we keep object files away from code? Or some other reason?
Quoted 4 lines
i think the fix to your problem is:
$(BUILDDIR)/include/version.h.tmp
+ $(Q)mkdir -p $(dir $@)
$(Q)echo '#define VERSION "$(VERSION)"' > $@
Except that gives this error:
CC ftl_format.o
CC lib/libmtd.o
In file included from lib/libmtd.c:40:0:./include/common.h:28:21: fatal error: version.h: No such file or directory compilation terminated.
make: *** [/home/norris/git/mtd-utils/mipsel-linux/lib/libmtd.o] Error 1
Really, the build system is setup to look for headers in-tree, not out-of-tree. I'm not sure a good way to fix this other than to generate that header in-tree...any better suggestions?
Brian
Quoted 7 lines · Brian Norris
Quoted 3 lines · Mike Frysinger
i dont think it's just a matter of "diff build dir for diff toolchains, so common
version.his ok". it's a matter of "building out of tree should build out of tree".OK, but what is the point of in- vs. out-of-tree? So that we can have a readonly source directory where the mtd-utils code stays?
this one imo, but maybe Artem can speak to the origins (which predate my contributions)
Quoted 13 lines
Quoted 4 lines
i think the fix to your problem is:
$(BUILDDIR)/include/version.h.tmp
+ $(Q)mkdir -p $(dir $@)
$(Q)echo '#define VERSION "$(VERSION)"' > $@Except that gives this error:
CC ftl_format.o
CC lib/libmtd.o
In file included fromlib/libmtd.c:40:0:./include/common.h:28:21: fatal error:version.h: No such file or directory compilation terminated.
make: *** [/home/norris/git/mtd-utils/mipsel-linux/lib/libmtd.o] Error 1
Quoted 3 lines
Really, the build system is setup to look for headers in-tree, not out-of-tree. I'm not sure a good way to fix this other than to generate that header in-tree...any better suggestions?
top level Makefile:
-CPPFLAGS += -I./include -I./ubi-utils/include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) +CPPFLAGS += -I./include -I$(BUILDDIR)/include -I./ubi-utils/include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS)
-mike
Quoted 4 lines · Mike Frysinger
top level
Makefile:(quoted diff) +1
-1-CPPFLAGS += -I./include -I./ubi-utils/include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) +CPPFLAGS += -I./include -I$(BUILDDIR)/include -I./ubi-utils/include$(ZLIBCPPFLAGS) $(LZOCPPFLAGS)
I still get the same error.
The rule for:
CC lib/libmtd.o
doesn't include $(CPPFLAGS). Is this intentional? See:
%: %.o $(LDDEPS)
$(call BECHO,LD)
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_$(notdir $@)) -g -o$@ $^ $(LDLIBS) $(LDLIBS_$(notdir $@))
Anyway, it's hard to trade lines about Makefile fixes, since one fix will pop up another problem in hacked-together build systems like mtd-utils...can you reproduce my bug completely, Mike? Or shall I continue trial and error until we find something good enough for both of us? :)
Brian
with my two proposed changes, it's working for me now ...
$ git clean -x -d $ git diff --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@
VERSION = 1.4.5
-CPPFLAGS += -I./include -I./ubi-utils/include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) +CPPFLAGS += -I./include -I$(BUILDDIR)/include -I./ubi-utils/include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS)
ifeq ($(WITHOUT_XATTR), 1)
CPPFLAGS += -DWITHOUT_XATTR
@@ -71,6 +71,7 @@ cscope:
$(BUILDDIR)/include/version.h: $(BUILDDIR)/include/version.h.tmp
$(Q)cmp -s $@ [email protected] && rm -f [email protected] || mv [email protected] $@ $(BUILDDIR)/include/version.h.tmp: + $(Q)mkdir -p $(dir $@) $(Q)echo '#define VERSION "$(VERSION)"' > $@
#
$ make CROSS=x86_64-pc-linux-gnu- -j2 ... success ... -mike
Quoted 8 lines · Brian Norris
Quoted 4 lines · Mike Frysinger
top level
Makefile:(quoted diff) +1
-1-CPPFLAGS += -I./include -I./ubi-utils/include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) +CPPFLAGS += -I./include -I$(BUILDDIR)/include -I./ubi-utils/include$(ZLIBCPPFLAGS) $(LZOCPPFLAGS)
I still get the same error.
Quoted 7 lines
The rule for:
CC lib/libmtd.o
doesn't include $(CPPFLAGS). Is this intentional? See:
%: %.o $(LDDEPS)
$(call BECHO,LD)
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_$(notdir $@)) -g -o $@ $^ $(LDLIBS) $(LDLIBS_$(notdir $@))
that's a link, not a compile, so CPPFLAGS shouldnt be needed as it should only be used on *.o files. that also shows "BECHO,LD" but your quoted output is "CC ...", and the CC rule does use CPPFLAGS.
Quoted 5 lines
Anyway, it's hard to trade lines about
Makefilefixes, since one fix will pop up another problem in hacked-together build systems like mtd-utils...can you reproduce my bug completely, Mike? Or shall I continue trial and error until we find something good enough for both of us? :)
np ... i'll look at it
-mike
Quoted 1 line · Mike Frysinger
with my two proposed changes, it's working for me now ...
Oops, never mind, I just goofed on my git-rebase! Looks good. I'll send v2 in a moment.
Thanks,
Brian
PATCH v2 1/3 Makefile: fix "version.h" build for cross-compiling
When using "make CROSS=mipsel-linux-", I get the following errors:
/bin/sh: /home/norris/git/mtd-utils/mipsel-linux/include/version.h.tmp: No such file or directory
make: *** [/home/norris/git/mtd-utils/mipsel-linux/include/version.h.tmp] Error 1
Fix (suggested by Mike Frysinger): create the directory if it doesn't exist. Also, $(CC) needs to be able to find the generated header in $(BUILDDIR)/include.
--- Makefile | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
Makefile +2 -1
@@ -3,7 +3,7 @@ VERSION = 1.4.5 -CPPFLAGS += -I./include -I./ubi-utils/include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) +CPPFLAGS += -I./include -I$(BUILDDIR)/include -I./ubi-utils/include $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) ifeq ($(WITHOUT_XATTR), 1) CPPFLAGS += -DWITHOUT_XATTR
@@ -71,6 +71,7 @@ cscope: $(BUILDDIR)/include/version.h: $(BUILDDIR)/include/version.h.tmp $(Q)cmp -s $@ [email protected] && rm -f [email protected] || mv [email protected] $@ $(BUILDDIR)/include/version.h.tmp: + ${Q}mkdir -p $(dir $@) $(Q)echo '#define VERSION "$(VERSION)"' > $@ #
Signature · 1 line
1.7.0.4
-mike
Quoted 11 lines · Mike Frysinger
Quoted 7 lines · Brian Norris
Quoted 3 lines · Mike Frysinger
i dont think it's just a matter of "diff build dir for diff toolchains, so common
version.his ok". it's a matter of "building out of tree should build out of tree".OK, but what is the point of in- vs. out-of-tree? So that we can have a readonly source directory where the mtd-utils code stays?
this one imo, but maybe Artem can speak to the origins (which predate my contributions)
Sorry, I do not know about the origins, I came into MTD area when most of the things have been already implemented and worked.
Signature · 2 lines
Best Regards, Artem Bityutskiy
May I get I push for these?
Quoted 1 line · Brian Norris
May I get I push for these?
Done, sorry and thanks for reminding!
Signature · 2 lines
Best Regards, Artem Bityutskiy