11.07.2015 Views

Parlante's Unix Programming Tools - Faculty.rmc.edu

Parlante's Unix Programming Tools - Faculty.rmc.edu

Parlante's Unix Programming Tools - Faculty.rmc.edu

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7## This is the first rule (the default)## Build the program from the three .o's$(PROG) : $(OBJS)tab$(CC) $(LDFLAGS) $(OBJS) -o $(PROG)## Rules for the source files -- these do not have## second build rule lines, so they will use the## default build rule to compile X.c to make X.omain.o : main.c binky.h akbar.h defs.hbinky.o : binky.c binky.hakbar.o : akbar.c akbar.h defs.h## Remove all the compilation and debugging filesclean :tabrm -f core $(PROG) $(OBJS)## Build tags for these sourcesTAGS : $(SRCS) $(HDRS)tabetags -t $(SRCS) $(HDRS)The first (default) target builds the program from the three .o's. The next three targetssuch as “main.o : main.c binky.h akbar.h defs.h” identify the .o's thatneed to be built and which source files they depend on. These rules identify what needs tobe built, but they omit the second line build rule. Therefore they will use the default rulewhich knows how to build one .o from one .c with the same name. Finally, makeautomatically knows that a .o always depends on its source .c, so the main.c,binky.c, and akbar.c dependencies could have been omitted from the threedependency lines.The later targets, clean and TAGS, perform other convenient operations. The cleantarget is used to remove all of the object files, the executable, and a core file if you'vebeen debugging, so that you can perform the build process from scratch . You can makeclean if you want to recover space by removing all the compilation and debuggingoutput files. You also may need to make clean if you move to a system with adifferent architecture from where your object libraries were originally compiled, and soyou need to recompile from scratch. The TAGS rule creates a tag file that most <strong>Unix</strong>editors can use to search for symbol definitions.Compiling in EmacsEmacs has built-in support for the compile process. To compile your code from emacs,type M-x compile. You will be prompted for a compile command. If you have amakefile, just type make and hit return. The makefile will be read and the appropriatecommands executed. The emacs buffer will split at this point, and compile errors will bebrought up in the newly created buffer. In order to go to the line where a compile erroroccurred, place the cursor on the line which contains the error message and hit ^c-^c.This will jump the cursor to the line in your code where the error occurred (“cc” is thehistorical name for the C compiler).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!