makefileocamlocamlbuild

ocamlbuild: Nothing to be done for `all'


I'm using ocamlbuild in makefile to build my code and want to recompile when there is any code change. But make returns with error message: make: Nothing to be done for `all'.

My makefile code:

all: test1 test2

test1:
    ocamlbuild $(INCLUDES) $(FLAGS) $(TEST1_BYTE)
    mv $(TEST1_BYTE) test1.out

test2:
    ocamlbuild $(INCLUDES) $(FLAGS) $(TEST2_BYTE)
    mv $(TEST2_BYTE) test2.out

clean:
    rm -f test1.out test2.out
    rm -rf _build

I expect make will do the recompilation instead of make clean; make. It only works with make clean; make now.


Solution

  • Make your targets phony then the make utility will always rebuild them. And ocamlbuild will track the dependencies with all the knowledge of the OCaml infrastructure, and will never rebuild anything unnecessary. Here's how to declare your targets phony, add this to your Makefile

       .PHONY: test1 test2
    

    Also, it looks like that you're still learning both make and ocamlbuild utilities, and given that you're going to invest your time in learning the tools it is better to focus on something that is not that legacy. While getting accustomed to make could be considered as useful, the ocamlbuild tool is more or less deprecated with the newer, dune and much better documented. It is very easy, just create a new file named dune and put the following contents there,

    (executable 
       (name test1))
    
    (executable 
       (name test2))
    

    Now you can build your targets with dune build test1.exe. You can still create a Makefile as a courtesy to those who don't know how to invoke dune. And as usual, don't forget to make your targets phony in the makefile.