Skip to contentSkip to conversation

btrfs-progs: fix cross-compile build

PATCH In review Eric Sandeen 4 participants 7 messages Aug 15, 2017 – Aug 25, 2017

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

PATCH 1/1 btrfs-progs: fix cross-compile build

The mktables binary needs to be build with the host compiler at built time, not the target compiler, because it runs at build time to generate the raid tables.

Copy auto-fu from xfsprogs and modify Makefile to
accomodate this.

---

Makefile +1 -1
index b3e2b63..2647b95 100644
@@ -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)$(BUILD_CC) $(BUILD_CFLAGS) $< -o $@
 
 kernel-lib/tables.c: mktables
 	@echo "    [TABLE]  $@"
Makefile.inc.in +2 -0
index 4e1b68c..0570bf8 100644
@@ -4,6 +4,8 @@
 export
 
 CC = @CC@
+BUILD_CC = @BUILD_CC@
+BUILD_CFLAGS = @BUILD_CFLAGS@
 LN_S = @LN_S@
 AR = @AR@
 RM = @RM@
configure.ac +17 -0
index 30055f8..bc590cc 100644
@@ -26,6 +26,23 @@ AC_CONFIG_SRCDIR([btrfs.c])
 AC_PREFIX_DEFAULT([/usr/local])
 
 AC_PROG_CC
+AC_ARG_VAR(BUILD_CC, [C compiler for build tools])
+if test "${BUILD_CC+set}" != "set"; then
+  if test $cross_compiling = no; then
+    BUILD_CC="$CC"
+  else
+    AC_CHECK_PROGS(BUILD_CC, gcc cc)
+  fi
+fi
+AC_ARG_VAR(BUILD_CFLAGS, [C compiler flags for build tools])
+if test "${BUILD_CFLAGS+set}" != "set"; then
+  if test $cross_compiling = no; then
+    BUILD_CFLAGS="$CFLAGS"
+  else
+    BUILD_CFLAGS="-g -O2"
+  fi
+fi
+
 AC_CANONICAL_HOST
 AC_C_CONST
 AC_C_VOLATILE
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Eric Sandeen

The mktables binary needs to be build with the host compiler at built time, not the target compiler, because it runs at build time to generate the raid tables.

Copy auto-fu from xfsprogs and modify Makefile to
accomodate this.

Looks better than my previous patch.
With @BUILD_CLFAGS support and better BUILD_CC/CLFAGS detection for native build environment.

Thanks,
Qu

Quoted 61 lines

---

Makefile +1 -1
index b3e2b63..2647b95 100644
@@ -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)$(BUILD_CC) $(BUILD_CFLAGS) $< -o $@
 
  kernel-lib/tables.c: mktables
  	@echo "    [TABLE]  $@"
Makefile.inc.in +2 -0
index 4e1b68c..0570bf8 100644
@@ -4,6 +4,8 @@
  export
 
  CC = @CC@
+BUILD_CC = @BUILD_CC@
+BUILD_CFLAGS = @BUILD_CFLAGS@
  LN_S = @LN_S@
  AR = @AR@
  RM = @RM@
configure.ac +16 -1
index 30055f8..bc590cc 100644
@@ -26,6 +26,23 @@ AC_CONFIG_SRCDIR([btrfs.c])
  AC_PREFIX_DEFAULT([/usr/local])
 
  AC_PROG_CC
+AC_ARG_VAR(BUILD_CC, [C compiler for build tools])
+if test "${BUILD_CC+set}" != "set"; then
+  if test $cross_compiling = no; then
+    BUILD_CC="$CC"
+  else
+    AC_CHECK_PROGS(BUILD_CC, gcc cc) > +  fi
+fi
+AC_ARG_VAR(BUILD_CFLAGS, [C compiler flags for build tools])
+if test "${BUILD_CFLAGS+set}" != "set"; then
+  if test $cross_compiling = no; then
+    BUILD_CFLAGS="$CFLAGS"
+  else
+    BUILD_CFLAGS="-g -O2"
+  fi
+fi
+
  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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 10 lines · Qu Wenruo
Quoted 7 lines · Eric Sandeen

The mktables binary needs to be build with the host compiler at built time, not the target compiler, because it runs at build time to generate the raid tables.

Copy auto-fu from xfsprogs and modify Makefile to
accomodate this.

Quoted 7 lines
Quoted 2 lines

Looks better than my previous patch.
With @BUILD_CLFAGS support and better BUILD_CC/CLFAGS detection for native build environment.

Thanks - and sorry for missing your earlier patch, I didn't mean to ignore it. :) I just missed it.

-Eric

#3 lore raw
In reply to Qu Wenruo
Quoted 10 lines · Qu Wenruo
Quoted 7 lines · Eric Sandeen

The mktables binary needs to be build with the host compiler at built time, not the target compiler, because it runs at build time to generate the raid tables.

Copy auto-fu from xfsprogs and modify Makefile to
accomodate this.

Quoted 6 lines
Quoted 2 lines

Looks better than my previous patch.
With @BUILD_CLFAGS support and better BUILD_CC/CLFAGS detection for native build environment.

The contents of tables.c has practially not changed since its introduction in 2000s. I see no sense in regenerating it each time during build and I don't want to introduce host CC build just for this one file, standard practice or not.

#4 lore raw
Quoted 14 lines · David Sterba
Quoted 13 lines · Qu Wenruo
Quoted 9 lines · Eric Sandeen

The mktables binary needs to be build with the host compiler at built time, not the target compiler, because it runs at build time to generate the raid tables.

Copy auto-fu from xfsprogs and modify Makefile to
accomodate this.

Quoted 9 lines
Quoted 3 lines

Looks better than my previous patch.
With @BUILD_CLFAGS support and better BUILD_CC/CLFAGS detection for native build environment.

The contents of tables.c has practially not changed since its introduction in 2000s. I see no sense in regenerating it each time during build and I don't want to introduce host CC build just for this one file, standard practice or not.

I understand the worry about adding host CC. But just shown by the patch, the impact is minimal.

At least for me and already mentioned before, text file managed by git should be reviewable.
No matter if the file get modified in 20 years or not.
(BTW, I don't think there is much problem regenerating the RAID6 table. It's way faster than auto-conf/auto-header things)

And I think that's the same reason other projects doesn't manage their generated CRC tables using git.

Thanks,
Qu

#5 lore raw
In reply to David Sterba
Quoted 14 lines · David Sterba
Quoted 13 lines · Qu Wenruo
Quoted 9 lines · Eric Sandeen

The mktables binary needs to be build with the host compiler at built time, not the target compiler, because it runs at build time to generate the raid tables.

Copy auto-fu from xfsprogs and modify Makefile to
accomodate this.

Quoted 7 lines
Quoted 3 lines

Looks better than my previous patch.
With @BUILD_CLFAGS support and better BUILD_CC/CLFAGS detection for native build environment.

The contents of tables.c has practially not changed since its introduction in 2000s. I see no sense in regenerating it each time during build

Make does know enough to generate it only as needed, of course.

Quoted 2 lines

and I don't want to introduce host CC build just for this one file, standard practice or not.

*shrug* it seems like the obviously correct fix to me, but I won't fight over it.

-Eric

#6 lore raw
In reply to David Sterba
Quoted 14 lines · David Sterba
Quoted 13 lines · Qu Wenruo
Quoted 9 lines · Eric Sandeen

The mktables binary needs to be build with the host compiler at built time, not the target compiler, because it runs at build time to generate the raid tables.

Copy auto-fu from xfsprogs and modify Makefile to
accomodate this.

Quoted 8 lines
Quoted 3 lines

Looks better than my previous patch.
With @BUILD_CLFAGS support and better BUILD_CC/CLFAGS detection for native build environment.

The contents of tables.c has practially not changed since its introduction in 2000s. I see no sense in regenerating it each time during build and I don't want to introduce host CC build just for this one file, standard practice or not.

I think that is a problem to have both the table generated and the mktable.c generator int git. Only one it is sufficient. Having both generate only confusion.

As my first option, I am to have only mktable in the git with BUILD_CC/CFLAGS. As second choice, we could remove mktable and put a comment that the tables are the kernel ones.

BTW, I suggest to put a comment in table.c to change mktable in case of update of the table. Otherwise is not obvious.

BR
G.Baroncelli

Signature · 2 lines
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5