建立include, src, out文件夹
#
# filename: Makefile
#
# Authors: Li Bo <>
# Version: 1.0
#
# Create Time: 2009.8.14
# Last Modified: 2009.8.14
#
src = $(wildcard src/*.c)
obj = $(patsubst src/%.c, out/%.o,$(src))
CC = gcc
CFLAGS = -g -Wall
LDFLAGS = -pthread
target = app
vpath %.o out
vpath %.c src
vpath %.h include
all: $(target)
$(target): $(obj)
$(CC) $(LDFLAGS) -o $@ $(obj) -Iinclude
$(obj): $(patsubst out/%.o, src/%.c, $(@))
$(CC) $(CFLAGS) -c -o $@ $(patsubst out/%.o, src/%.c, $(@)) -Iinclude
.PHONY:
clean:
rm -f $(obj)
rm -f $(target)
#
# filename: Makefile for static lib
#
# Authors: Li Bo <>
# Version: 1.0
#
# Create Time: 2009.8.14
# Last Modified: 2009.8.14
#
src = $(wildcard src/*.c)
obj = $(patsubst src/%.c, out/%.o, src/add.c src/sub.c)
AR = ar
CC = gcc
CFLAGS = -g -Wall
LDFLAGS = -pthread
target = out/libaddsub.a
vpath %.a out
vpath %.o out
vpath %.c src
vpath %.h include
all: $(target)
$(target): $(obj)
$(AR) -cr $@ $(obj)
$(obj): $(patsubst out/%.o, src/%.c, $(@))
$(CC) $(CFLAGS) -c -o $@ $(patsubst out/%.o, src/%.c, $(@)) -Iinclude
.PHONY:
clean:
rm -f $(obj)
rm -f $(target)
#
# filename: Makefile for dynamic lib
#
# Authors: Li Bo <>
# Version: 1.0
#
# Create Time: 2009.8.14
# Last Modified: 2009.8.14
#
src = $(wildcard src/*.c)
obj = $(patsubst src/%.c, out/%PIC.o, src/add.c src/sub.c)
CC = gcc
CFLAGS = -g -Wall
CFLAGSLIB = -fPIC
LDFLAGS = -shared
target = out/libaddsub.so
vpath %.o out
vpath %.c src
vpath %.h include
all: $(target)
$(target): $(obj)
$(CC) $(LDFLAGS) -o $@ $(obj) -Iinclude
$(obj): $(patsubst out/%PIC.o, src/%.c, $(@))
$(CC) $(CFLAGSLIB) -c -o $@ $(patsubst out/%PIC.o, src/%.c, $(@)) -Iinclude
.PHONY:
clean:
rm -f $(obj)
rm -f $(target)
all: app
app:
gcc src/main.c -o app -laddsub -Lout/ -Iinclude
#
# add path to /etc/ld.so.conf
# ldconfig
#
# ldd app
#
all: app
app:
gcc -o app src/main.c -laddsub -Lout -Iinclude
阅读(1705) | 评论(0) | 转发(0) |