views:

146

answers:

2

Hope everyone is doing well

I am having a problem with make files in erlang on windows. I can't seem to get the following code to work.

.SUFFIXES: .erl .beam

.erl.beam:
    erlc -W $<

    ERL = erl -boot start_clean

MODS = main send get loops

all: compile
    ${ERL} -pa 'G:\Documents and Settings\Administrador' -s main start

compile: ${MODS:%=%.beam}

clean: 
    rm -rf *.beam erl_crash.dump

The files I am trying to compile are main.erl send.erl get.erl loops.erl

I save the make file as an .exe

And the type

make [main]

into the windows shell

All it gives me is a wierd popup error. Is the make [main] command correct? And is my actual code right?

Thanks for the help, -B

+4  A: 

Several errors here:

  1. The indented "ERL=" line won't work right. Leading tabs are special to make. You do not have complete formatting freedom, as with some other languages.

  2. The make file should be saved as Makefile, no extensions. Case may or may not matter to your particular "make" program. All versions of make accept Makefile, however.

  3. The brackets on your command line will never work. I assume you're cut-and-pasting them from somewhere, but they were probably using "[main]" as an example text you're supposed to replace, including the brackets.

  4. "make main" will also fail because you don't have a "main" target in this Makefile. "make all", "make clean" and "make compile" will work, as will several implicit targets, like "make loops.beam".

    You really should get a book on make, if you're going to continue to use it. I like O'Reilly's Managing Projects with GNU Make, 3/e by Mecklenburg, available for free online or in dead tree form. The GNU make manual is also available online and as dead trees.

  5. You probably shouldn't be using traditional "make" here, however. For purely Erlang projects, Emakefiles are shorter, clearer, and just overall better. They're not so great for building other things along side your Erlang project, but you can always do both: the Makefile uses "erl -make" to kick off the Erlang build, and does everything else itself.

Warren Young
I appreciate the response, but it really did not answer my question, just let me know what was wrong. Is it really that difficult to write a simple makefile that I need to read a book??
You asked what was wrong with your file, I told you. And yes, Makefiles are sufficiently complex that you want to have a book on the topic. The one I recommended is short, as technical books go. Also note that I recommended it with a proviso, saying you should only get the book if you are going to continue using Makefiles. If this is a one-shot deal building nothing more than we see here, build an Emakefile instead. But that would be a different question, with no bearing on whether this one is answered correctly.
Warren Young
+1  A: 

Your actual code looks more or less correct. You should remove the indentation for the line starting with ERL, and make sure that all the indented lines have TAB (not SPACE) in the beginning. (Unless you have a localised version of Windows, you should check the spelling of Administrator as well.)

The name of your Makefile should be Makefile (with no file type ending at all), and you should run it with make. Just writing make in the command line will run the topmost make-command (which in your case is 'all'). If you want to run any of the other commands (or all explicitly), then just add that to your make command, like "make clean", "make foo.beam".

Also consider putting your source files in src/ and your compiled files in ebin/ since that is the Erlang standard.

I recommend this page for further information about make (if you are using GNU Make): http://www.gnu.org/software/make/manual/make.html

Daniel Luna