Linux

  1. Home
  2. Computing & Technology
  3. Linux
7.2 Simple Programming under Linux
Learn advanced Linux commands
 
 Related Resources
• Linux Newbie Administrator Guide
• 0. Linux Benefit
• 1. Before Installation
• 2. Linux Resources/Help
• 3. Basic Operations FAQ
• 4. Newbie Admin FAQ
• ~ 4.1 Lilo
• ~ 4.2 Drives
• ~ 4.3 X-Windows
• ~ 4.4 Configurations
• ~ 4.5 Networking
5. Shortcuts / Commands
• 6. Linux Applications
• 7. Learn Linux Commands
• A. How to Upgrade Kernel?
 

make

Run the "make" utility to build (compile, link, etc) a project described in the Makefile found in the current directory.

make is used to bring a system "up to date", whenever a change in one file requires an action elsewhere.  make is "intelligent" in that it will not make changes unless the change is required, as determined by the file modification date/time. Normally used for buiding software packages (compiling, linking ...),  make is also used for other tasks, e.g., system administration. Makefile looks as follows:

target :  prerequisites
[Tab]commands

where target is usually a file (but does not have to be, it can be a "phony" target), and prerequisites are files on which target depends. If target does not exist or is older than any prerequisites, "commands" are executed.  The first line above is called "the rule", the second "the action". Please note that any action line must start with the tab character. Here is an example Makefile that makes an executable file called "edit":

my_program : main.o command.o
    cc -o my_program main.o command.o
main.o : main.c defs.h
    cc -c main.c
command.o : command.c defs.h command.h
    cc -c command.c
clean :
    rm my_program main.o command.o

To use this Makefile to create an executable file called "my_program', I type:  make. It works backwards to determine the dependencies,  so first it compiles "command.c" to the object file "command.o", then it compiles "main.c" to "main.o", and finally it links "main.o" and "command.o" into the executable "my_program".
One could also use this makefile to delete the executable file and all the object files from the directory by typing: make clean.  Since the target "clean" does not depend on any prerequisites, it is not normally executed unless explicitly called. The target "clean" is an example of a "phony" target.

Next > Back to "Learn Linux Commands"

Can't find what you are looking for?
Search the

Stay up-to-date!
Subscribe to the Linux free newsletter.

Explore Linux

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Linux

  1. Home
  2. Computing & Technology
  3. Linux

©2009 About.com, a part of The New York Times Company.

All rights reserved.