diff mbox

[1/3] Makefile: fix "version.h" build for cross-compiling

Message ID 1310071467-9017-1-git-send-email-computersforpeace@gmail.com
State New, archived
Headers show

Commit Message

Brian Norris July 7, 2011, 8:44 p.m. UTC
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...

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
 Makefile |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Comments

Mike Frysinger July 7, 2011, 8:48 p.m. UTC | #1
On Thu, Jul 7, 2011 at 16:44, Brian Norris wrote:
> 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
Brian Norris July 7, 2011, 9:09 p.m. UTC | #2
On Thu, Jul 7, 2011 at 1:48 PM, Mike Frysinger <vapier.adi@gmail.com> wrote:
> 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?

> 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
Mike Frysinger July 7, 2011, 9:12 p.m. UTC | #3
On Thu, Jul 7, 2011 at 17:09, Brian Norris wrote:
> On Thu, Jul 7, 2011 at 1:48 PM, Mike Frysinger wrote:
>> 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)

>> 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?

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
Brian Norris July 7, 2011, 9:36 p.m. UTC | #4
On Thu, Jul 7, 2011 at 2:12 PM, Mike Frysinger <vapier.adi@gmail.com> wrote:
> top level Makefile:
> -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
Mike Frysinger July 7, 2011, 9:49 p.m. UTC | #5
On Thu, Jul 7, 2011 at 17:36, Brian Norris wrote:
> On Thu, Jul 7, 2011 at 2:12 PM, Mike Frysinger wrote:
>> top level Makefile:
>> -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 $@))

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.

> 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
Artem Bityutskiy July 8, 2011, 3:57 a.m. UTC | #6
On Thu, 2011-07-07 at 17:12 -0400, Mike Frysinger wrote:
> On Thu, Jul 7, 2011 at 17:09, Brian Norris wrote:
> > On Thu, Jul 7, 2011 at 1:48 PM, Mike Frysinger wrote:
> >> 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.
Brian Norris July 19, 2011, 6:17 p.m. UTC | #7
May I get I push for these?
Artem Bityutskiy July 20, 2011, 5:29 a.m. UTC | #8
On Tue, 2011-07-19 at 11:17 -0700, Brian Norris wrote:
> May I get I push for these?

Done, sorry and thanks for reminding!
diff mbox

Patch

diff --git a/Makefile b/Makefile
index afbe201..7c20ea5 100644
--- a/Makefile
+++ b/Makefile
@@ -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 $@ $@.tmp && rm -f $@.tmp || mv $@.tmp $@
-$(BUILDDIR)/include/version.h.tmp:
+include/version.h.tmp:
 	$(Q)echo '#define VERSION "$(VERSION)"' > $@
 
 #