Skip to contentSkip to conversation

Do not hard-code the command name 'make' in higher-level tools

PATCH New Masahiro Yamada 3 participants 8 messages Jul 22, 2014 – Jul 29, 2014

lore
Share & tools
lore
#0 lore raw

v2 cover Do not hard-code the command name 'make' in higher-level tools

Masahiro Yamada (3):
scripts: add scripts/show-gnu-make to get GNU Make command name
MAKEALL: make sure to invoke GNU Make
buildman: make sure to invoke GNU Make

 MAKEALL                   | 12 +++++++++---
 scripts/show-gnu-make     | 25 +++++++++++++++++++++++++
 tools/buildman/builder.py |  6 ++++--
 tools/buildman/control.py |  9 ++++++++-
 4 files changed, 46 insertions(+), 6 deletions(-)
 create mode 100755 scripts/show-gnu-make
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/3 scripts: add scripts/show-gnu-make to get GNU Make command name

U-Boot is expected to be built on various platforms.

We should keep in mind that the command 'make' is not always GNU Make, while all the makefiles are written for GNU Make.

For example, on Linux, people generally do:

make <board>_config; make

But FreeBSD folks do

gmake <board>_config; gmake

(The command 'make' on FreeBSD is BSD Make, not GNU Make)

It is not a good idea to hard-code the command name 'make' in MAKEALL or buildman.

They should call this helper script and get the command name for GNU Make.

---

Changes in v2:
- Use dashes for filename
- Show the command name instead of invoking make. It allows us to check the command name once at startup (and error out if no GNU Make is found.)

 scripts/show-gnu-make | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100755 scripts/show-gnu-make
scripts/show-gnu-make new file +25 -0
new file mode 100755
index 0000000..26271b5
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# Show the command name for GNU Make
+#
+# U-Boot is supposed to be built on various platforms.
+# One problem is that the command 'make' is not always GNU Make.
+# (For ex. the command name for GNU Make on FreeBSD is usually 'gmake'.)
+# It is not a good idea to hard-code the command name in scripts
+# where where GNU Make is expected.
+# Call this helper script to get the command name for GNU Make.
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+gnu_make=
+
+for m in make gmake
+do
+	if $m --version 2>/dev/null | grep -q GNU; then
+		echo $m
+		exit 0
+	fi
+done
+
+exit 1
Signature · 1 line
1.9.1
#2 lore raw

PATCH v2 1/3 scripts: add scripts/show-gnu-make to get GNU Make command name

Quoted 15 lines · Masahiro Yamada

U-Boot is expected to be built on various platforms.

We should keep in mind that the command 'make' is not always GNU Make, while all the makefiles are written for GNU Make.

For example, on Linux, people generally do:

make <board>_config; make

But FreeBSD folks do

gmake <board>_config; gmake

(The command 'make' on FreeBSD is BSD Make, not GNU Make)

Quoted 7 lines

It is not a good idea to hard-code the command name 'make' in MAKEALL or buildman.

They should call this helper script and get the command name for GNU Make.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140729/27e0036e/attachment.pgp>
#3 lore raw

PATCH v2 2/3 MAKEALL: make sure to invoke GNU Make

In reply to Masahiro Yamada

Since the command name 'make' may not be GNU Make on some platforms such as FreeBSD, MAKEALL should call scripts/show-gnu-make to get the command name for GNU MAKE (and error out if it is not found).

The GNU Make should be searched after parsing options because we want to allow "MAKEALL -h" even if GNU Make is missing on the system.

---

Changes in v2:
- Check GNU Make only once at startup.
It seems more reasonable because MAKEALL generally invokes make over and over again.

 MAKEALL | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
MAKEALL +9 -3
index 37ef71e..9510982 100755
@@ -162,6 +162,12 @@ while true ; do
 		echo "Internal error!" >&2 ; exit 1 ;;
 	esac
 done
+
+GNU_MAKE=$(scripts/show-gnu-make) || {
+	echo "GNU Make not found" >&2
+	exit 1
+}
+
 # echo "Remaining arguments:"
 # for arg do echo '--> '"\`$arg'" ; done
 
@@ -633,11 +639,11 @@ build_target() {
 	target_arch=$(get_target_arch ${target})
 	eval cross_toolchain=\$CROSS_COMPILE_`echo $target_arch | tr '[:lower:]' '[:upper:]'`
 	if [ "${cross_toolchain}" ] ; then
-	    MAKE="make CROSS_COMPILE=${cross_toolchain}"
+	    MAKE="$GNU_MAKE CROSS_COMPILE=${cross_toolchain}"
 	elif [ "${CROSS_COMPILE}" ] ; then
-	    MAKE="make CROSS_COMPILE=${CROSS_COMPILE}"
+	    MAKE="$GNU_MAKE CROSS_COMPILE=${CROSS_COMPILE}"
 	else
-	    MAKE=make
+	    MAKE=$GNU_MAKE
 	fi
 
 	if [  "${output_dir}" != "." ] ; then
Signature · 1 line
1.9.1
#4 lore raw

PATCH v2 2/3 MAKEALL: make sure to invoke GNU Make

Quoted 7 lines · Masahiro Yamada

Since the command name 'make' may not be GNU Make on some platforms such as FreeBSD, MAKEALL should call scripts/show-gnu-make to get the command name for GNU MAKE (and error out if it is not found).

The GNU Make should be searched after parsing options because we want to allow "MAKEALL -h" even if GNU Make is missing on the system.

Quoted 7 lines

---

Changes in v2:
- Check GNU Make only once at startup.
It seems more reasonable because MAKEALL generally invokes make over and over again.

#5 lore raw

PATCH v2 2/3 MAKEALL: make sure to invoke GNU Make

In reply to Masahiro Yamada
Quoted 9 lines · Masahiro Yamada

Since the command name 'make' may not be GNU Make on some platforms such as FreeBSD, MAKEALL should call scripts/show-gnu-make to get the command name for GNU MAKE (and error out if it is not found).

The GNU Make should be searched after parsing options because we want to allow "MAKEALL -h" even if GNU Make is missing on the system.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140729/14130e8d/attachment.pgp>
#6 lore raw

PATCH v2 3/3 buildman: make sure to invoke GNU Make

In reply to Masahiro Yamada

Since the command name 'make' may not be GNU Make on some platforms such as FreeBSD, buildman should call scripts/show-gnu-make to get the command name for GNU MAKE (and error out if it is not found).

---

Changes in v2:
- Check GNU Make only once at startup.
It seems more reasonable because buildman generally invokes make over and over again.

 tools/buildman/builder.py | 6 ++++--
 tools/buildman/control.py | 9 ++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)
tools/buildman/builder.py +4 -2
index 4a2d753..4987fc9 100644
@@ -546,7 +546,7 @@ class Builder:
             self.func_sizes = func_sizes
 
     def __init__(self, toolchains, base_dir, git_dir, num_threads, num_jobs,
-                 checkout=True, show_unknown=True, step=1):
+                 gnu_make='make', checkout=True, show_unknown=True, step=1):
         """Create a new Builder object
 
         Args:
@@ -555,6 +555,7 @@ class Builder:
             git_dir: Git directory containing source repository
             num_threads: Number of builder threads to run
             num_jobs: Number of jobs to run at once (passed to make as -j)
+            gnu_make: the command name of GNU Make.
             checkout: True to check out source, False to skip that step.
                 This is used for testing.
             show_unknown: Show unknown boards (those not built) in summary
@@ -566,6 +567,7 @@ class Builder:
         self.threads = []
         self.active = True
         self.do_make = self.Make
+        self.gnu_make = gnu_make
         self.checkout = checkout
         self.num_threads = num_threads
         self.num_jobs = num_jobs
@@ -667,7 +669,7 @@ class Builder:
             args: Arguments to pass to make
             kwargs: Arguments to pass to command.RunPipe()
         """
-        cmd = ['make'] + list(args)
+        cmd = [self.gnu_make] + list(args)
         result = command.RunPipe([cmd], capture=True, capture_stderr=True,
                 cwd=cwd, raise_on_error=False, **kwargs)
         return result
tools/buildman/control.py +8 -1
index d2f4102..fd6f197 100644
@@ -14,6 +14,7 @@ import gitutil
 import patchstream
 import terminal
 import toolchain
+import command
 
 def GetPlural(count):
     """Returns a plural 's' if count is not 1"""
@@ -144,10 +145,16 @@ def DoBuildman(options, args):
     if not options.step:
         options.step = len(series.commits) - 1
 
+    gnu_make = command.Output(os.path.join(options.git,
+                                           'scripts/show-gnu-make')).rstrip()
+    if not gnu_make:
+        print >> sys.stderr, 'GNU Make not found'
+        sys.exit(1)
+
     # Create a new builder with the selected options
     output_dir = os.path.join(options.output_dir, options.branch)
     builder = Builder(toolchains, output_dir, options.git_dir,
-            options.threads, options.jobs, checkout=True,
+            options.threads, options.jobs, gnu_make=gnu_make, checkout=True,
             show_unknown=options.show_unknown, step=options.step)
     builder.force_config_on_failure = not options.quick
 
Signature · 1 line
1.9.1
#7 lore raw

PATCH v2 3/3 buildman: make sure to invoke GNU Make

Quoted 7 lines · Masahiro Yamada

Since the command name 'make' may not be GNU Make on some platforms such as FreeBSD, buildman should call scripts/show-gnu-make to get the command name for GNU MAKE (and error out if it is not found).

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140729/9b0c0957/attachment.pgp>