Makefile 의 이해

  • Published on
    14-Jan-2016

  • View
    71

  • Download
    1

Embed Size (px)

DESCRIPTION

Makefile . FALinux http://www.falinux.com . . make Makefile make include Makefile Makefile . make (1). make . make (Makefile makefile) , . - PowerPoint PPT Presentation

Transcript

  • Makefile FALinux http://www.falinux.com

  • 2007-05-13make Makefile make include Makefile Makefile

  • make (1)make .

    make (Makefile makefile) , .

    , .

    2007-05-13

  • make (2)make , .

    make .

    2007-05-13

  • Makefile (1)(:) Dependency

    (Tab) .2007-05-13

  • Makefile (2) Makefile

    Target .DependencyTarget .Command .2007-05-13Target: Dependency[TAB] Command

  • Makefile (3)

    LableTarget .ex) all: ex) clean: Command .2007-05-13Lable: [TAB] Command

  • make .

    #

    '\' . '\' make .2007-05-13

  • (1) $ += 2007-05-13INCLUDE = -I/usr/includeINCLUDE += -I/usr/locla/include

    INCLUDE -I/usr/include -I/usr/locla/include .

  • (2)= NULL .

    NULL .

    .

    .

    2007-05-13

  • (3) make .$(CC) C .$(LD) . make p .2007-05-13

  • (4) make .

    () () .

    make .2007-05-13$ make test DIR=/usr/project$ make test DIR=/usr/project /usr/project/lib $ DIR=/usr/project make test

  • (5)2007-05-13 1. 2. Makefile 3. 4. make

  • (6) $* ( )

    $< ()

    2007-05-13main.o : io.h main.c[TAB] gcc c $*.cmain.o : io.h main.c[TAB] gcc c $

  • (6)

    $@

    $^

    2007-05-13test : main.o foo.o bar.o[TAB] gcc o $@ $*.ctest : main.o foo.o bar.o[TAB] gcc o $@ $^

  • (1)make ,

    , .SUFFIXES .2007-05-13

  • (2).SUFFIXES , make .c, .s .make .SUFFIXES .

    2007-05-13.SUFFIXES: .out .a .ln .o .c .cc .C .cpp .p .f .F .r .y .l .s .S .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo .w .ch .web .sh .elc .el

  • (3) make .

    .c C .o .c .o 2007-05-13.c.o:[TAB] $(CC) c $< -o $@

  • includeincludeinclude . include .include 'file_name' Makefile .include file_name

    2007-05-13

  • (1) make .#include , , . Makefile .2007-05-13

  • (2) GNU (gcc) -M , .

    include .depend Makefile .

    gcc , gccmakedep .2007-05-13gcc -M $(SRCS) > .dependinclude .depend

  • (1) make . make .

    2007-05-13make C

  • (2) #ifdef #ifdef #ifndef .

    -f .

    2007-05-13[Makeflie ]CFLAGS = -DTEST[Source Code ]#ifdef TESTtest_print();#endifmake f ./test.mk

  • Makefile (1) 2007-05-13

  • Makefile (2) 2007-05-13all: test

    test : main.o foo.o bar.ogcc o test main.o foo.o bar.o

    main.o : io.h main.cgcc c main.c

    foo.o : io.h foo.cgcc c foo.c

    bar.o : io.h bar.cgcc c bar.c

  • Makefile (3) 2007-05-13OBJS = main.o foo.o bar.oSRCS = main.c foo.c bar.cCC = gccCFLAGS = -g -c

    TARGET = test

    all: $(TARGET)

    $(TARGET) : $(OBJS) $(CC) -o $(TARGET) $(OBJS)

    clean : rm -rf $(OBJS) $(TARGET) core

    main.o : io.h main.cfoo.o : io.h foo.cbar.o : io.h bar.c

  • Makefile (4) 2007-05-13CC = gccCFLAGS = -O2 -g

    OBJS = main.o foo.o bar.oSRCS = $(OBJS:.o=.c)

    TARGET = test

    all: $(TARGET)

    $(TARGET) : $(OBJS) $(CC) -o $@ $(OBJS)

    dep: gccmakedep $(SRCS)

    clean : rm -rf $(OBJS) $(TARGET) core

  • Makefile (1) 3 Makefile Makefile .

    Makefile Makefile .

    2007-05-13

  • Makefile (2) .Makefile , .

    Makefile 2007-05-13

    ****************************