Skip to contentSkip to conversation

Compatibility make fixes for meson

PATCH Superseded Roman Bolshakov 4 participants 19 messages Aug 22, 2020 – Aug 25, 2020 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Compatibility make fixes for meson

The set of changes addresses "Diagnose "make is too old" in configure (or in the makefile?)" from https://wiki.qemu.org/Features/Meson#Easy.
It also provides cleaner backwards compatible build invocation on macOS.

Roman Bolshakov (4):
configure: Use discovered make for in-source build
Makefile: Require GNU make 3.82+
configure: Prefer gmake on darwin
configure: Test if $make actually exists

 Makefile  |  5 +++++
 configure | 28 ++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
Signature · 1 line
2.28.0
#1 lore raw

PATCH 1/4 configure: Use discovered make for in-source build

A recursive make is inovked if in-source build is used but $(MAKE) is the same as the one used in the original make invocaton.

Some platforms have preference to use gmake, or a make passed as an option to "configure". Honor the choice.

---
 configure | 2 ++
 1 file changed, 2 insertions(+)
configure +2 -0
index 4e5fe33211..9e0d505067 100755
@@ -38,6 +38,8 @@ then
 # This file is auto-generated by configure to support in-source tree
 # 'make' command invocation
 
+include build/config-host.mak
+
 ifeq ($(MAKECMDGOALS),)
 recurse: all
 endif
Signature · 1 line
2.28.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] configure: Use discovered make for in-source build

Quoted 10 lines · Roman Bolshakov

A recursive make is inovked if in-source build is used but $(MAKE) is the same as the one used in the original make invocaton.

Some platforms have preference to use gmake, or a make passed as an option to "configure". Honor the choice.

---
 configure | 2 ++
 1 file changed, 2 insertions(+)

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#3 lore raw

Re: [PATCH 1/4] configure: Use discovered make for in-source build

In reply to Roman Bolshakov
Quoted 1 line · Roman Bolshakov

A recursive make is inovked if in-source build is used but $(MAKE) is

invoked

Quoted 1 line

the same as the one used in the original make invocaton.

invocation

Quoted 9 lines

Some platforms have preference to use gmake, or a make passed as an option to "configure". Honor the choice.

---
  configure | 2 ++
  1 file changed, 2 insertions(+)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#4 lore raw

Re: [PATCH 1/4] configure: Use discovered make for in-source build

In reply to Roman Bolshakov
Quoted 16 lines · Roman Bolshakov

A recursive make is inovked if in-source build is used but $(MAKE) is the same as the one used in the original make invocaton.

Some platforms have preference to use gmake, or a make passed as an option to "configure". Honor the choice.

---
  configure | 2 ++
  1 file changed, 2 insertions(+)
configure +0 -0
index 4e5fe33211..9e0d505067 100755

configure then · line 41

Quoted 4 lines
configure +1 -0
@@ -38,6 +38,8 @@ then
  # This file is auto-generated by configure to support in-source tree
  # 'make' command invocation
 
+include build/config-host.mak

Should this use '-include' (also spelled 'sinclude'), to avoid halting the build if build/config-host.mak doesn't exist for whatever reason?

Quoted 5 lines
configure +1 -0
+
  ifeq ($(MAKECMDGOALS),)
  recurse: all
  endif
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#5 lore raw

Re: [PATCH 1/4] configure: Use discovered make for in-source build

Quoted 9 lines · Eric Blake

configure then · line 40

Quoted 4 lines · Roman Bolshakov
configure +1 -0
@@ -38,6 +38,8 @@ then
  # This file is auto-generated by configure to support in-source tree
  # 'make' command invocation
+include build/config-host.mak

Should this use '-include' (also spelled 'sinclude'), to avoid halting the build if build/config-host.mak doesn't exist for whatever reason?

Sure I can do (and thanks for the noticed typos) but I tested that if the build is interrupted too early (before Makefile is symlinked to build directory but after GNUmakefile is created) it would fail even if -include is used:

$ make
changing dir to build for /Library/Developer/CommandLineTools/usr/bin/make ""...
make[1]: Makefile: No such file or directory
make[1]: *** No rule to make target `Makefile'.  Stop.
changing dir to build for /Library/Developer/CommandLineTools/usr/bin/make ""...
make[1]: Makefile: No such file or directory
make[1]: *** No rule to make target `Makefile'.  Stop.
make: *** [all] Error 2

I'm also curious why the switch happens twice... According to the debug trace, it tries to remake build/config-host.mak using the implicit force rule:

GNUmakefile:12: update target 'build/config-host.mak' due to: force

Then there should be an explicit empty rule for build/config-host.mak. I will send a fix for that in v2. Then it would fail like this:

$ make
changing dir to build for /Library/Developer/CommandLineTools/usr/bin/make ""...
make[1]: Makefile: No such file or directory
make[1]: *** No rule to make target `Makefile'.  Stop.
make: *** [all] Error 2

Regards,
Roman

Quoted 6 lines
Quoted 5 lines
configure +1 -0
+
  ifeq ($(MAKECMDGOALS),)
  recurse: all
  endif
 
#6 lore raw

Re: [PATCH 1/4] configure: Use discovered make for in-source build

Quoted 31 lines · Roman Bolshakov
Quoted 9 lines · Eric Blake

configure then · line 40

Quoted 4 lines · Roman Bolshakov
configure +1 -0
@@ -38,6 +38,8 @@ then
  # This file is auto-generated by configure to support in-source tree
  # 'make' command invocation
+include build/config-host.mak

Should this use '-include' (also spelled 'sinclude'), to avoid halting the build if build/config-host.mak doesn't exist for whatever reason?

Sure I can do (and thanks for the noticed typos) but I tested that if the build is interrupted too early (before Makefile is symlinked to build directory but after GNUmakefile is created) it would fail even if -include is used:

$ make
changing dir to build for /Library/Developer/CommandLineTools/usr/bin/make ""...
make[1]: Makefile: No such file or directory
make[1]: *** No rule to make target `Makefile'.  Stop.
changing dir to build for /Library/Developer/CommandLineTools/usr/bin/make ""...
make[1]: Makefile: No such file or directory
make[1]: *** No rule to make target `Makefile'.  Stop.
make: *** [all] Error 2

I'm also curious why the switch happens twice... According to the debug trace, it tries to remake build/config-host.mak using the implicit force rule:

GNUmakefile:12: update target 'build/config-host.mak' due to: force

Quoted 15 lines

Then there should be an explicit empty rule for build/config-host.mak. I will send a fix for that in v2. Then it would fail like this:

$ make
changing dir to build for /Library/Developer/CommandLineTools/usr/bin/make ""...
make[1]: Makefile: No such file or directory
make[1]: *** No rule to make target `Makefile'.  Stop.
make: *** [all] Error 2
Quoted 6 lines
Quoted 5 lines
configure +1 -0
+
  ifeq ($(MAKECMDGOALS),)
  recurse: all
  endif
 

Hi Eric,

What if we just print an error if build/config-host.mak can't be found?

ifeq ($(wildcard build/config-host.mak),)
$(error "Incomplete configuration. Please run ./configure") endif

IMO this is more sane approach than proceeding with partially-configured not working build without a Makefile in proper place.

Regards,
Roman

#7 lore raw

Re: [PATCH 1/4] configure: Use discovered make for in-source build

Quoted 11 lines · Roman Bolshakov

Hi Eric,

What if we just print an error if build/config-host.mak can't be found?

ifeq ($(wildcard build/config-host.mak),)
$(error "Incomplete configuration. Please run ./configure") endif

IMO this is more sane approach than proceeding with partially-configured not working build without a Makefile in proper place.

Yes, that is definitely a better approach.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#8 lore raw

PATCH 2/4 Makefile: Require GNU make 3.82+

In reply to Roman Bolshakov

QEMU build fails with cryptic messages if make is too old:

Makefile.ninja:2655: *** multiple target patterns. Stop.

To avoid the confusion it's worth to fail the build right away and print a friendly error message.

---
 Makefile | 5 +++++
 1 file changed, 5 insertions(+)
Makefile +5 -0
index 8373ddccc9..45d688b87b 100644
@@ -4,6 +4,11 @@ ifneq ($(words $(subst :, ,$(CURDIR))), 1)
   $(error main directory cannot contain spaces nor colons)
 endif
 
+ifeq ($(filter undefine,$(value .FEATURES)),)
+$(error Unsupported Make version: $(MAKE_VERSION). \
+        Please use GNU Make 3.82 or above)
+endif
+
 # Always point to the root of the build tree (needs GNU make).
 BUILD_DIR=$(CURDIR)
 
Signature · 1 line
2.28.0
Reviewed-by on v1 2/4
#9 lore raw

Re: [PATCH 2/4] Makefile: Require GNU make 3.82+

Quoted 11 lines · Roman Bolshakov

QEMU build fails with cryptic messages if make is too old:

Makefile.ninja:2655: *** multiple target patterns. Stop.

To avoid the confusion it's worth to fail the build right away and print a friendly error message.

---
 Makefile | 5 +++++
 1 file changed, 5 insertions(+)

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#10 lore raw

PATCH 3/4 configure: Prefer gmake on darwin

In reply to Roman Bolshakov

New meson/make build requires GNU make 3.82+ but macOS ships 3.81 even on Big Sur while homebrew provides GNU make 4.3 as 'gmake' in $PATH.

With the change, 'make' switches over to gmake implicitly.

---
 configure | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
configure +22 -0
index 9e0d505067..90b02b7271 100755
@@ -903,6 +903,7 @@ Darwin)
   darwin="yes"
   hax="yes"
   hvf="yes"
+  make="${MAKE-gmake}"
   LDFLAGS_SHARED="-bundle -undefined dynamic_lookup"
   if [ "$cpu" = "x86_64" ] ; then
     QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
@@ -916,6 +917,27 @@ Darwin)
   # won't work when we're compiling with gcc as a C compiler.
   QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
   HOST_VARIANT_DIR="darwin"
+  cat > GNUmakefile <<'EOF'
+# This file is auto-generated by configure to implicitly switch from a 'make'
+# invocation to 'gmake'
+
+OLD_MAKE := $(MAKE)
+
+include config-host.mak
+
+ifeq ($(MAKECMDGOALS),)
+recurse: all
+endif
+
+.NOTPARALLEL: %
+%: force
+	@echo 'Switch from $(OLD_MAKE) to $(MAKE)'
+	@$(MAKE) -f Makefile $(MAKECMDGOALS)
+force: ;
+.PHONY: force
+GNUmakefile: ;
+
+EOF
 ;;
 SunOS)
   solaris="yes"
Signature · 1 line
2.28.0
Reviewed-by on v1 3/4
#11 lore raw

Re: [PATCH 3/4] configure: Prefer gmake on darwin

Quoted 37 lines · Roman Bolshakov

New meson/make build requires GNU make 3.82+ but macOS ships 3.81 even on Big Sur while homebrew provides GNU make 4.3 as 'gmake' in $PATH.

With the change, 'make' switches over to gmake implicitly.

---
 configure | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
configure +12 -0
index 9e0d505067..90b02b7271 100755
@@ -903,6 +903,7 @@ Darwin)
   darwin="yes"
   hax="yes"
   hvf="yes"
+  make="${MAKE-gmake}"
   LDFLAGS_SHARED="-bundle -undefined dynamic_lookup"
   if [ "$cpu" = "x86_64" ] ; then
     QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
@@ -916,6 +917,27 @@ Darwin)
   # won't work when we're compiling with gcc as a C compiler.
   QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
   HOST_VARIANT_DIR="darwin"
+  cat > GNUmakefile <<'EOF'
+# This file is auto-generated by configure to implicitly switch from a 'make'
+# invocation to 'gmake'
+
+OLD_MAKE := $(MAKE)
+
+include config-host.mak
+
+ifeq ($(MAKECMDGOALS),)
+recurse: all
+endif

configure Darwin) · line 940

Quoted 10 lines
configure +10 -0
+
+.NOTPARALLEL: %
+%: force
+	@echo 'Switch from $(OLD_MAKE) to $(MAKE)'
+	@$(MAKE) -f Makefile $(MAKECMDGOALS)
+force: ;
+.PHONY: force
+GNUmakefile: ;
+
+EOF

I was wondering why you duplicated the GNUmakefile I created earlier, then I realized this one is created in the build dir, whereas the other was created in the source dir. I would note this works for macOS which has a GNU make, but doesn't work for FreeBSD has non-GNU make by default.

I kind of feel like the previous patch which raises an error is good enough. User can just put the homebrew newer GNU make first in their $PATH, which is sensible regardless IMHO.

None the less, this patch does what it claims so

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#12 lore raw

Re: [PATCH 3/4] configure: Prefer gmake on darwin

In reply to Roman Bolshakov
Quoted 2 lines · Roman Bolshakov

New meson/make build requires GNU make 3.82+ but macOS ships 3.81 even on Big Sur while homebrew provides GNU make 4.3 as 'gmake' in $PATH.

Does this line up with our development policies on supported platforms? Should we be fixing the creation of Makefile.ninja to avoid constructs not understood by older GNU make, if that is what is shipped out of the box on MacOS as one of our supported platforms? Or is MacOS on the fringe for what counts as supported, where we are okay mandating that users must install a separate newer GNU make than what comes by default?

Quoted 2 lines

With the change, 'make' switches over to gmake implicitly.

If gmake ships new enough by default, then this seems like a slick trick, although I am not in a position to test it.

configure Darwin) · line 922

Quoted 7 lines
configure +3 -0
@@ -916,6 +917,27 @@ Darwin)
    # won't work when we're compiling with gcc as a C compiler.
    QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
    HOST_VARIANT_DIR="darwin"
+  cat > GNUmakefile <<'EOF'
+# This file is auto-generated by configure to implicitly switch from a 'make'
+# invocation to 'gmake'

Are we going to run into issues with an in-tree build trying to create GNUmakefile to switch over to build/, while also creating build/GNUmakefile to switch from make to gmake?

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#13 lore raw

Re: [PATCH 3/4] configure: Prefer gmake on darwin

Quoted 17 lines · Eric Blake
Quoted 2 lines · Roman Bolshakov

New meson/make build requires GNU make 3.82+ but macOS ships 3.81 even on Big Sur while homebrew provides GNU make 4.3 as 'gmake' in $PATH.

Does this line up with our development policies on supported platforms? Should we be fixing the creation of Makefile.ninja to avoid constructs not understood by older GNU make, if that is what is shipped out of the box on MacOS as one of our supported platforms? Or is MacOS on the fringe for what counts as supported, where we are okay mandating that users must install a separate newer GNU make than what comes by default?

Quoted 2 lines

With the change, 'make' switches over to gmake implicitly.

If gmake ships new enough by default, then this seems like a slick trick, although I am not in a position to test it.

Quoted 11 lines

configure Darwin) · line 922

Quoted 7 lines
configure +3 -0
@@ -916,6 +917,27 @@ Darwin)
    # won't work when we're compiling with gcc as a C compiler.
    QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
    HOST_VARIANT_DIR="darwin"
+  cat > GNUmakefile <<'EOF'
+# This file is auto-generated by configure to implicitly switch from a 'make'
+# invocation to 'gmake'

Are we going to run into issues with an in-tree build trying to create GNUmakefile to switch over to build/, while also creating build/GNUmakefile to switch from make to gmake?

Don't think so - it just means we'll go through both GNUmakefile in turn before getting to the real Makefile.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#14 lore raw

Re: [PATCH 3/4] configure: Prefer gmake on darwin

Quoted 12 lines · Daniel P. Berrangé
Quoted 11 lines

configure Darwin) · line 922

Quoted 7 lines
configure +3 -0
@@ -916,6 +917,27 @@ Darwin)
     # won't work when we're compiling with gcc as a C compiler.
     QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
     HOST_VARIANT_DIR="darwin"
+  cat > GNUmakefile <<'EOF'
+# This file is auto-generated by configure to implicitly switch from a 'make'
+# invocation to 'gmake'

Are we going to run into issues with an in-tree build trying to create GNUmakefile to switch over to build/, while also creating build/GNUmakefile to switch from make to gmake?

Quoted 2 lines

Don't think so - it just means we'll go through both GNUmakefile in turn before getting to the real Makefile.

Actually, we won't - the top-level in-tree GNUmakefile calls $(MAKE) -C build -f Makefile, which means it skips build/GNUmakefile. But on the other hand, since this series adjusts both places to source build/config-host.mak, which in turn assigns $MAKE in a timely manner, the recursion should be run through the correct gmake whether done from the top-level or directly from within build.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#15 lore raw

Re: [PATCH 3/4] configure: Prefer gmake on darwin

In reply to Eric Blake
Quoted 11 lines · Eric Blake
Quoted 2 lines · Roman Bolshakov

New meson/make build requires GNU make 3.82+ but macOS ships 3.81 even on Big Sur while homebrew provides GNU make 4.3 as 'gmake' in $PATH.

Does this line up with our development policies on supported platforms? Should we be fixing the creation of Makefile.ninja to avoid constructs not understood by older GNU make, if that is what is shipped out of the box on MacOS as one of our supported platforms? Or is MacOS on the fringe for what counts as supported, where we are okay mandating that users must install a separate newer GNU make than what comes by default?

If it's easy to add back support for make 3.81 that would be the nicest thing, I think. But we already require the user to install a non-system python, for instance, so asking them to also install make from homebrew isn't a completely new thing. (The only awkward thing is that homebrew doesn't actually put the new make on the path as 'make', only as 'gmake', so you have to then manually fiddle the PATH.) At some point requiring some tools from homebrew or similar for QEMU compilation is just inevitable given Apple's apparent policy of never moving the system versions of tools beyond the last GPLv2 version.

thanks
-- PMM

#16 lore raw

Re: [PATCH 3/4] configure: Prefer gmake on darwin

Quoted 13 lines · Peter Maydell
Quoted 11 lines · Eric Blake
Quoted 2 lines · Roman Bolshakov

New meson/make build requires GNU make 3.82+ but macOS ships 3.81 even on Big Sur while homebrew provides GNU make 4.3 as 'gmake' in $PATH.

Does this line up with our development policies on supported platforms? Should we be fixing the creation of Makefile.ninja to avoid constructs not understood by older GNU make, if that is what is shipped out of the box on MacOS as one of our supported platforms? Or is MacOS on the fringe for what counts as supported, where we are okay mandating that users must install a separate newer GNU make than what comes by default?

Quoted 11 lines

If it's easy to add back support for make 3.81 that would be the nicest thing, I think. But we already require the user to install a non-system python, for instance, so asking them to also install make from homebrew isn't a completely new thing. (The only awkward thing is that homebrew doesn't actually put the new make on the path as 'make', only as 'gmake', so you have to then manually fiddle the PATH.) At some point requiring some tools from homebrew or similar for QEMU compilation is just inevitable given Apple's apparent policy of never moving the system versions of tools beyond the last GPLv2 version.

Never thought of that, but perhaps it's similar to what happened with bash. Apple shipped an old GPLv2 version of bash (3.2) for quite a while even after 4.x release. Then they suddenly switched default shell to zsh. Following the approach, we're more likely to see meson and ninja in Apple Command Line Tools than GNU Make 3.82+ 🙂

As for alias, Homebrew also provides GNU coreutils and sed with g prefix and a special gnubin prefix is provided to simplify bulk addition of GNU tools to PATH, so it's consistent in some sense :)

Here's a related homebrew discussion about system binary shadowing:
https://discourse.brew.sh/t/why-was-with-default-names-removed/4405/14

-Roman

#17 lore raw

PATCH 4/4 configure: Test if $make actually exists

In reply to Roman Bolshakov

configure doesn't detect if $make is installed on the build host. This is also helpful for hosts where an alias for make is used, i.e. configure would fail if gmake is not present on macOS.

---
 configure | 4 ++++
 1 file changed, 4 insertions(+)
configure +4 -0
index 90b02b7271..c324252f60 100755
@@ -2021,6 +2021,10 @@ if test -z "$python"
 then
     error_exit "Python not found. Use --python=/path/to/python"
 fi
+if ! has "$make"
+then
+    error_exit "GNU make ($make) not found"
+fi
 
 # Note that if the Python conditional here evaluates True we will exit
 # with status 1 which is a shell 'false' value.
Signature · 1 line
2.28.0
Reviewed-by on v1 4/4
#18 lore raw

Re: [PATCH 4/4] configure: Test if $make actually exists

Quoted 8 lines · Roman Bolshakov

configure doesn't detect if $make is installed on the build host. This is also helpful for hosts where an alias for make is used, i.e. configure would fail if gmake is not present on macOS.

---
 configure | 4 ++++
 1 file changed, 4 insertions(+)

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|