[erlang-questions] Use of makefiles

Dave Rafkind <>
Thu Feb 28 14:15:05 CET 2008


Alexander Lamb wrote:

> What are the various strategies to manage your build / run or build /  
> deploy cycles?
> 

There is an interesting add-on for SCons here:
http://pupeno.com/software/scons-erlang/


However one day I thought I'd obsolete Make with a bash script (assumes
code in esrc and binaries in ebin):


#!/bin/bash

ERLC=erlc
SOURCE_ROOT=esrc
DEST_ROOT=ebin
# collect source directories
for SOURCE_DIR in `find -L $SOURCE_ROOT -type d`; do
  SOURCE_INCLUDES="$SOURCE_INCLUDES -I $SOURCE_DIR"
done

COMPILE="$ERLC $SOURCE_INCLUDES"

mkdir -p $DEST_ROOT

for SOURCE_TARGET in `find -L $SOURCE_ROOT -name "*.erl"`; do
  DEST_TARGET=${DEST_ROOT}/${SOURCE_TARGET#*/}
  DEST_TARGET=${DEST_TARGET%.erl}.beam
  DEST_PATH=${DEST_TARGET%/*}

  mkdir -p $DEST_PATH

  CMD="$COMPILE -o $DEST_PATH $SOURCE_TARGET"

  if [[ -e $DEST_TARGET ]]
  then
    if [[ $SOURCE_TARGET -nt $DEST_TARGET ]]
    then
      #echo $DEST_TARGET is old, recompiling to $DEST_PATH
      echo "$CMD"
      if $CMD
      then
	# do nothing
	FOO=1
      else
	echo "Compilation halted due to errors."
	exit 1
      fi
    fi
  else
    #echo $DEST_TARGET does not exist, compiling to $DEST_PATH
    echo "$CMD"
    if $CMD
    then
      # do nothing
      FOO=1
    else
      echo "Compilation halted due to errors."
      exit 1
    fi
  fi
done



More information about the erlang-questions mailing list