The purpose of the make utility is to determine automatically which pieces of a large programme in which there are several source files need to be recompiled, and issue the commands to recompile them.
To use make, you must write a file called the Makefile that describes the relationships among files in your programme. Full documentation is available on most Unix systems, including Cosmos.
The following are some examples of Makefiles which build C programmes, with explanatory comments.
Make a programme from multiple source files; introduce some other targets which help with project management --- cleanup and printing :
# Objects to build from source files : # OBJS = hoc.o init.o math.o symbol.o # Targets : # hoc: $(OBJS) cc $(OBJS) -lm -o hoc3 # Print the source : # # ...type "make pr | lpr" or similar... # pr: @pr hoc.h init.c math.c symbol.c Makefile # Clean up : # clean: rm -f $(OBJS)
Make a programme which requires both the standard maths library and the C version of the NAg library:
# Compiler flags : # # "fast" selects the optimum combination of compilation options for # speed ---should provide close to the maximum performance; # CCFLAGS = -fast -mt -I/opt/NAG/include # Choose which C compiler to use : # CC = /software/SUNWspro/bin/cc # Linker flags : # # modules compiled with "fast" must also be linked with "fast"; # tell the linker to search for libraries in /opt/NAG/lib; # tell the linker to use libm (std maths lib) and libnagc (the NAg C lib); # CLINK = CC -fast -L/opt/NAG/lib -lm -lnagc # Object files we are building : # OBJS = myprog.o # Rules to make our programme : # .c.o: $(CC) $(CCFLAGS) -c $*.c # first char is a tab # Targets : # # link object files to make executable : # exe: $(OBJS) $(CLINK) -o $@ $(OBJS) # first char is a tab
...previous | up (conts) | next... |