###Makefile編譯應用程式 cc = gcc prom = calc deps = $(shell find ./ -name "*.h") src = $(shell find ./ -name "*.c") obj = $(src:%.c=%.o) # 會將src所有的.c字串替換成.o ...
Makefile編譯應用程式
cc = gcc
prom = calc
deps = $(shell find ./ -name "*.h")
src = $(shell find ./ -name "*.c")
obj = $(src:%.c=%.o) # 會將src所有的.c字串替換成.o
$(prom): $(obj)
$(cc) -o $(prom) $(obj)
%.o: %.c $(deps) # %.o:%.c,這是一個模式規則,表示所有的.o目標都依賴於與它同名的.c文件(當然還有deps中列出的頭文件)
$(cc) -c $< -o $@ # $<代表的是依賴關係表中的第一項(如果想引用的是整個關係表,那麼就應該使用$^),具體到這裡就是%.c。而$@代表的是當前語句的目標,即%.o
clean:
rm -rf $(obj) $(prom)
Makefile編譯動態鏈接庫
CC = arm-none-linux-gnueabi-g++
SHARED = -shared -o
FPIC = -fPIC -c
RM = rm -rf
# Macro definition
DEFS = -D OS_UNIX
CFLAGS += $(DEFS)
OS_TYPE = $(shell uname -m)
ifeq ($(OS_TYPE), x86_64)
LIBS = -L./lib/x86_64 -lusb -lusb-1.0
BIN_DIR = ./lib/x86_64/
endif
ifeq ($(OS_TYPE), i686)
LIBS = -L./lib/x86_32 -lusb -lusb-1.0
BIN_DIR = ./lib/x86_32/
endif
ifeq ($(OS_TYPE), armv7l)
LIBS = -L./lib/Raspberry -lusb -lusb-1.0
BIN_DIR = ./lib/Raspberry/
endif
$(shell mkdir -p ${BIN_DIR})
SRC_OBJECT = $(shell find ./ -name "*.cpp")
H_OBJECT = $(shell find ./ -name "*.h")
OBJECT = $(src:%.c=%.o)
LIB_OBJECT = libble_sniffer.so
.PHONY:all
all:$(LIB_OBJECT)
$(LIB_OBJECT):$(OBJECT)
$(CC) $(OBJECT) $(SHARED) -fPIC -o $(LIB_OBJECT) $(LIBS)
mv $(LIB_OBJECT) $(BIN_DIR)
$(RM) -rf $(OBJS) *~ *.o
$(OBJECT):$(SRC_OBJECT) $(H_OBJECT)
$(CC) $(CFLAGS) $(FPIC) $(SRC_OBJECT)
clean:
$(RM) $(BIN_DIR)