An easy way to accomplish this is using a file local variable. For my latex file, I added the following comments at the end of the file to set some file local variables.
% Local Variables:% compile-command: "make -k ch2"% fill-column: 80% comment-fill-column: 80% End:
Local value of compile-command can also be used in source files where someone need to build the whole project instead of only compiling the source targets in the current directory from Emacs.
% Local Variables:% compile-command: "cd .. && make -k"% End: