otp-build does not run as expected if called from a Makefile

Matthias Lang matthias@REDACTED
Wed Jun 23 01:09:13 CEST 2010


Hi,

in R13B04 (it looks like R14A is the same, but I haven't tried), the
top-level script 'otp_build' doesn't work as expected if it's called
from a Makefile.

Here's an example of it going wrong in R13B04 (these commands are being
issued by make, not at the command line):

  ./otp_build configure --xcomp-conf=xcomp/erl-xcomp-mips-linux.conf
  sh -c "cd otp_src_R13B04; ./otp_build boot -a"
  [: 1432: Xmake[1]:: unexpected operator
  make[1]: Entering directory `/home/matthias/corelatus/rootfs/packages/erlang/otp_src_R13B04'
  *
  * Cross compiling Erlang/OTP-R13B04 for: x86_64-unknown-linux-gnu
  *
  ...

otp_build then works for quite some time (minutes) before running into
trouble. The final error message has nothing to do with the actual problem,
the clue of the real problem is the "unexpected operator" line above.

The problem is that otp_build has a few lines like this:

    if [ X`$MAKE is_cross_configured` = Xyes ]; then

usually, if you run that line, you get the answer "yes". But if otp_build
was called by make, then the make invoked by the line above detects that
it's running inside another make and the answer becomes 

  "make[1]: Entering directory `/home/matthias/corelatus/rootfs/packages/erlang/otp_src_R13B04'yes"

Solutions I can think of:

  1. Don't allow running otp_build from within make, since it does the
     wrong thing. Fail early. I've appended a patch for that below
     (against R14A)

  2. use make's --no-print-directory switch to suppress the extra junk.
     That's a nice solution which actually solves the problem, but
     I'm not sure it'll work for clearmake (and BSD?), though.

  3. conceal the fact that make is running, by clearing MAKELEVEL and
     MAKEFLAGS. That seems dirty.

Matt
  
======================================================================
diff --git a/otp_build b/otp_build
index 1744351..33424d8 100755
--- a/otp_build
+++ b/otp_build
@@ -870,6 +870,11 @@ lookup_prog_in_path ()
 
 setup_make ()
 {
+    if [ X$MAKELEVEL != X ]; then
+        echo "This script works badly if run by 'make'. Aborting."
+       exit 1
+    fi
+
     if [ -z "$MAKE" ]; then
        case $TARGET in
            win32)


More information about the erlang-bugs mailing list