Search code examples
javacmakefilegnu

Are they specifying the compilation twice in the makefiles documentation?


I am learning how to use make, and while reading the documentation saw this example:

objects = main.o kbd.o command.o display.o \
          insert.o search.o files.o utils.o

edit : $(objects)
        cc -o edit $(objects)
main.o : main.c defs.h
        cc -c main.c
kbd.o : kbd.c defs.h command.h
        cc -c kbd.c
command.o : command.c defs.h command.h
        cc -c command.c
display.o : display.c defs.h buffer.h
        cc -c display.c
insert.o : insert.c defs.h buffer.h
        cc -c insert.c
search.o : search.c defs.h buffer.h
        cc -c search.c
files.o : files.c defs.h buffer.h command.h
        cc -c files.c
utils.o : utils.c defs.h
        cc -c utils.c
clean :
        rm edit $(objects)

My question is on the edit target. I am using make with Java so it may be a compilation difference I'm not aware of, but when I just specify the objects once on the first line of edit it goes to each of the rules I set up for those objects and runs the compilation, so why does the edit rule have another line to compile those objects? Is the documentation just compiling it twice or is there a specific difference?


Solution

  • After taking another look at the code, I realized that they are creating an executable from the created objects, pretty cool haha!

    EDIT:

    If you are trying to use make for java projects, consider using build tools such as gradle, it makes compilation and testing much easier.