1 / 6

Makefile

Makefile. Script file to automate program compilation and linking (making) 1. Write the "makefile" 2. Write your programs 3. Run "make" or "make -f makefile" Makefile is a list of rules and commands http://www.gnu.org/software/make/. Makefile. Comments start with "#"

brandi
Download Presentation

Makefile

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Makefile • Script file to automate program compilation and linking (making) 1. Write the "makefile" 2. Write your programs 3. Run "make" or "make -f makefile" • Makefile is a list of rules and commands http://www.gnu.org/software/make/

  2. Makefile • Comments start with "#" # This is a makefile for Hello World application • Variable definitions, usually in capital letters CC = gcc • Main target definition all: hello1.c • Dependency definitions %.o: %.c $(CC) $(CFLAGS) -c $< -o $@

  3. Special Macros • $@ name of target • $? Name of depended changed • $< name of the first dependent • $^ names of all dependents

  4. Inference rules • Generalized rule • Use % as a wild character %.o: %.c $(CC) $(CFLAGS) –c $< • Alternative way .c.o : $(CC) $(CFLAGS) –c $<

  5. Makefile Example (1) #This file contains information used by a program called make to #automate building the program CFLAGS = -g -Wall CC = gcc LIBS = -lm INCLUDES = OBJS = a.o b.o c.o SRCS = a.c b.c c.c prog1.c prog2.c HDRS = abc.h

  6. Makefile Example (2) all: prog1 prog2 prog1: prog1.o ${OBJS} ${CC} ${CFLAGS} ${INCLUDES} -o $@ prog1.o\ ${OBJS} ${LIBS} # The variable $@ has the value of the target. In this case $@ = prog1 prog2: prog2.o ${OBJS} ${CC} ${CFLAGS} -o $@ prog2.o ${OBJS} ${LIBS} .c.o: ${CC} ${CFLAGS} ${INCLUDES} -c $<

More Related