Make file v1

由于Makefile不是很熟悉,为了以后使用方便,在此记录一个常用Makefile,并且会继续更新。

common stanza:

#common header
SHELL = /bin/sh

CC=gcc
COMPILE.c=$(CC) $(CFLAGS) $(CPPFLAGS) -c
LINK.c=$(CC) $(CFLAGS) $(CPPFLAGS) $(LDDIR) $(LDFLAGS)
LDDIR=-L../lib
LDLIBS=../lib/libapue.a $(EXTRALIBS)
CFLAGS=-I../include -Wall -D_GNU_SOURCE $(EXTRA)

LIB=../libapue.a

.SUFFIXES:
.SUFFIXES: .c .o

使用公共部分来创建具体的target。

include ../Makefile.common

PROGS = test_orphan test_hello

all: ${PROGS}

clean:
    rm -f ${PROGS}

创建一个lib archive的Makefile:

include ../Makefile.common

# for ar parts
AR = ar
LIBMISC = libapue.a
OBJS = error.o errorlog.o pathalloc.o prexit.o prmask.o

RANLIB = ranlib

all: ${OBJS}
        ${AR} rv ${LIBMISC} $?
        ${RANLIB} ${LIBMISC}

clean:
        rm -f *.o a.out core temp.* ${LIBMISC}

posted @ 2011-07-18 18:34  yub0yue  阅读(252)  评论(0编辑  收藏  举报