Skip to contentSkip to conversation

Makefile: fix "version.h" build for cross-compiling

PATCH Superseded Brian Norris 3 participants 17 messages Jul 7, 2011 – Jul 20, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index afbe201..7c20ea5 100644
@@ -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
#1 lore raw

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
index 7c20ea5..78f5f9f 100644
@@ -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
#3 lore raw

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
index 78f5f9f..27e8a01 100644
@@ -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
#5 lore raw
In reply to Brian Norris
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 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...

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

#6 lore raw
In reply to Mike Frysinger
Quoted 3 lines · Mike Frysinger

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".

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

#7 lore raw
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.h is 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 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

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

#8 lore raw
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

#10 lore raw
In reply to Mike Frysinger

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
#9 lore raw
In reply to Brian Norris
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 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? :)

np ... i'll look at it
-mike

#11 lore raw
In reply to Mike Frysinger
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

#12 lore raw

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
index afbe201..1f3e270 100644
@@ -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
#14 lore raw
In reply to Mike Frysinger
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.h is 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
#16 lore raw
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