diff mbox

btrfs-progs: Fix cross-compile error for mktables

Message ID 20170815021903.6923-1-quwenruo.btrfs@gmx.com (mailing list archive)
State New, archived
Headers show

Commit Message

Qu Wenruo Aug. 15, 2017, 2:19 a.m. UTC
When cross compiling btrfs-progs, following error will prevent
btrfs-progs to be compiled:

    [CC]     mktables
    [TABLE]  kernel-lib/tables.c
/bin/sh: ./mktables: cannot execute binary file: Exec format error
make: *** No rule to make target 'kernel-lib/tables.c', needed by 'kernel-lib/tables.o'.  Stop.

"mktables" should only be executed in host environment, while @CC
set by autoconf will follow host/build/target setting, causing mktables
to be cross-compiled.

The fix is to introduce a new @HOSTCC for mktables, which will not be
affected by host/build/target settings.

Reported-by: Hallo32 <Hallo32@gmx.net>
Suggested-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
---
Tested with AArch64 cross-toolchain created by buildroot.
---
 Makefile        | 2 +-
 Makefile.inc.in | 1 +
 configure.ac    | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

Comments

Qu Wenruo Aug. 15, 2017, 8:07 a.m. UTC | #1
On 2017年08月15日 15:14, Goffredo Baroncelli wrote:
> Hi Qu,
> 
> On 08/15/2017 04:19 AM, Qu Wenruo wrote:
>> When cross compiling btrfs-progs, following error will prevent
>> btrfs-progs to be compiled:
>>
>>      [CC]     mktables
>>      [TABLE]  kernel-lib/tables.c
>> /bin/sh: ./mktables: cannot execute binary file: Exec format error
>> make: *** No rule to make target 'kernel-lib/tables.c', needed by 'kernel-lib/tables.o'.  Stop.
>>
>> "mktables" should only be executed in host environment, while @CC
>> set by autoconf will follow host/build/target setting, causing mktables
>> to be cross-compiled.
>>
>> The fix is to introduce a new @HOSTCC for mktables, which will not be
>> affected by host/build/target settings.
>>
>> Reported-by: Hallo32 <Hallo32@gmx.net>
>> Suggested-by: David Sterba <dsterba@suse.cz>
> 
> this idea was a my suggestion.... :(

Sorry, I though all that 2 mails are from David.
And David still likes the idea to let git manage that file...

So correct tag should be:

Suggested-by: Goffredo Baroncelli <kreijack@libero.it>

Thanks for pointing this out.
Qu
> 
>> Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
>> ---
>> Tested with AArch64 cross-toolchain created by buildroot.
>> ---
>>   Makefile        | 2 +-
>>   Makefile.inc.in | 1 +
>>   configure.ac    | 1 +
>>   3 files changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/Makefile b/Makefile
>> index b3e2b636..0395e37f 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -323,7 +323,7 @@ version.h: version.sh version.h.in configure.ac
>>   
>>   mktables: kernel-lib/mktables.c
>>   	@echo "    [CC]     $@"
>> -	$(Q)$(CC) $(CFLAGS) $< -o $@
>> +	$(Q)$(HOSTCC) $(CFLAGS) $< -o $@
>>   
>>   kernel-lib/tables.c: mktables
>>   	@echo "    [TABLE]  $@"
>> diff --git a/Makefile.inc.in b/Makefile.inc.in
>> index 4e1b68cb..308acca3 100644
>> --- a/Makefile.inc.in
>> +++ b/Makefile.inc.in
>> @@ -4,6 +4,7 @@
>>   export
>>   
>>   CC = @CC@
>> +HOSTCC = @HOSTCC@
>>   LN_S = @LN_S@
>>   AR = @AR@
>>   RM = @RM@
>> diff --git a/configure.ac b/configure.ac
>> index 30055f85..f6051ebd 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -26,6 +26,7 @@ AC_CONFIG_SRCDIR([btrfs.c])
>>   AC_PREFIX_DEFAULT([/usr/local])
>>   
>>   AC_PROG_CC
>> +AC_PATH_PROGS([HOSTCC], [gcc clang])
>>   AC_CANONICAL_HOST
>>   AC_C_CONST
>>   AC_C_VOLATILE
>>
> 
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Makefile b/Makefile
index b3e2b636..0395e37f 100644
--- a/Makefile
+++ b/Makefile
@@ -323,7 +323,7 @@  version.h: version.sh version.h.in configure.ac
 
 mktables: kernel-lib/mktables.c
 	@echo "    [CC]     $@"
-	$(Q)$(CC) $(CFLAGS) $< -o $@
+	$(Q)$(HOSTCC) $(CFLAGS) $< -o $@
 
 kernel-lib/tables.c: mktables
 	@echo "    [TABLE]  $@"
diff --git a/Makefile.inc.in b/Makefile.inc.in
index 4e1b68cb..308acca3 100644
--- a/Makefile.inc.in
+++ b/Makefile.inc.in
@@ -4,6 +4,7 @@ 
 export
 
 CC = @CC@
+HOSTCC = @HOSTCC@
 LN_S = @LN_S@
 AR = @AR@
 RM = @RM@
diff --git a/configure.ac b/configure.ac
index 30055f85..f6051ebd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,7 @@  AC_CONFIG_SRCDIR([btrfs.c])
 AC_PREFIX_DEFAULT([/usr/local])
 
 AC_PROG_CC
+AC_PATH_PROGS([HOSTCC], [gcc clang])
 AC_CANONICAL_HOST
 AC_C_CONST
 AC_C_VOLATILE