linux库文件编译的makefile

很久之前需要自己写几个库,但是每次敲命令感觉很麻烦,所以参考其他开源库的makefile自己写了一个专门生成动态库和静态库的makefile。

之后有一段时间很忙就没有分享出来,中间项目也被停滞了一段时间,昨天又开始一个新项目,恰好也需要编译动态库,就用之前的makefile改了改,发现确实好用,所以趁着没有忘记都是什么东西之前赶紧分享出来。

首先是我要编译的东西的目录结构

linux@ubuntu:~/share/rtbuslib$ tree
.
├── includes
│   └── rt_bus.h
├── Makefile
├── rt_bus_cli.c
└── rt_bus_ser.c

1 directory, 4 files

 然后是Makefile讲解,如果不想看,可以直接复制后面的代码修改使用。

#记住当前工程的根目录路径
ROOT_DIR=$(shell pwd)
## 需要使用的库添加在这里,但是也可以不写,因为编译库的时候并不查找依赖函数是否存在,只有在调用时才去查找个人建议不要填写,但是运行时需要保证系统能够找到所依赖的库文件
LIBS :=
#LIBS :=pthread nanomsg msg_queue
#使用的库目录,静态库和动态库添加在这里,这里与上面的关系一样,完全可以不写
LIBRARY_PATH :=$(ROOT_DIR)/../msg_queuelib/lib /home/linux/work/nanomsg/lib
## 头文件路径,如果使用了其他库的头文件务必写入进去,否则编译时会报错,找不到文件
INCLUDE_PATH := $(ROOT_DIR)/includes/ $(ROOT_DIR)/../msg_queuelib/includes/msg_queue /home/linux/work/nanomsg/include
## 获取所有头文件路径,也就是将上边的路径前面加上"-I"
CFLAGS  += $(foreach dir, $(INCLUDE_PATH), -I$(dir))
## 获取所有的库文件路径,也就是将上边的路径加上"-L"
LDFLAGS += $(foreach lib, $(LIBRARY_PATH), -L$(lib))
## 获取所有的库文件,就是在前边加上"-l"
LDFLAGS += $(foreach lib, $(LIBS), -l$(lib))

#编译选项,做嵌入式的都明白

#CC=arm-linux-gcc
CC=gcc

#需要生成的.o文件,如果需要同时生成多个库文件可以写多个,后面会放一个生成多个库文件的Makefile

RTBUS_OBJ = rt_bus_ser.o rt_bus_cli.o

#生成库文件名

RTBUS_LIBNAME = librtbus

#库文件版本

LIBVERSION = 1.0.0

#2级软连接文件小版本
RTBUS_SOVERSION = 1

#安装库文件路径,这里我是临时安装,正常应该安装在系统库路径下

PREFIX ?= /home/linux/share/rtbuslib

#头文件安装路径文件夹
PREFIX_INCLUDE_PATH ?= includes/rtbus

#库文件安装文件夹
PREFIX_LIBRARY_PATH ?= lib

#此处连接使用,无续修改

INSTALL_INCLUDE_PATH = $(DESTDIR)$(PREFIX)/$(PREFIX_INCLUDE_PATH)
INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(PREFIX_LIBRARY_PATH)

#安装库文件时使用的指令

INSTALL ?= cp -a

#下面是编译时做的一些判断和编译选项

# validate gcc version for use fstack-protector-strong
MIN_GCC_VERSION = "4.9"
GCC_VERSION := "`gcc -dumpversion`"
IS_GCC_ABOVE_MIN_VERSION := $(shell expr "$(GCC_VERSION)" ">=" "$(MIN_GCC_VERSION)")
ifeq "$(IS_GCC_ABOVE_MIN_VERSION)" "1"
    CFLAGS += -fstack-protector-strong
else
    CFLAGS += -fstack-protector
endif

R_CFLAGS = -fPIC -Wall -O0 $(CFLAGS)

uname := $(shell sh -c 'uname -s 2>/dev/null || echo false')

#library file extensions

#库文件后缀
SHARED = so
STATIC = a

## create dynamic (shared) library on Darwin (base OS for MacOSX and IOS)
ifeq (Darwin, $(uname))
    SHARED = dylib
endif

#生成库文件名的一些字符连接,如果需要同时生成多个,需要写多个

#rtbus library names
RTBUS_SHARED = $(RTBUS_LIBNAME).$(SHARED)
RTBUS_SHARED_VERSION = $(RTBUS_LIBNAME).$(SHARED).$(LIBVERSION)
RTBUS_SHARED_SO = $(RTBUS_LIBNAME).$(SHARED).$(RTBUS_SOVERSION)
RTBUS_STATIC = $(RTBUS_LIBNAME).$(STATIC)

#下面是通用命令

#SHARED_CMD = $(CC) -shared -o

.PHONY: all shared static clean install

all: shared static

#动态库和静态库的连接条件,如果需要同时生成多个,需要写多个

shared: $(RTBUS_SHARED)

static: $(RTBUS_STATIC)

.c.o:
    $(CC) -c $(R_CFLAGS) $< -o $@

#静态库的编译命令,如果需要同时生成多个,需要写多个

#static libraries
#rtbus
$(RTBUS_STATIC): $(RTBUS_OBJ)
    $(AR) rcs $@ $^

#动态库的编译命令,如果需要同时生成多个,需要写多个

#shared libraries .so.1.0.0
#rtbus
$(RTBUS_SHARED_VERSION): $(RTBUS_OBJ)
    $(CC) -shared -o $@ $^ $(LDFLAGS)

#生成库的.c文件,如果需要同时生成多个,需要写多个

#objects
#rtbus
$(RTBUS_OBJ): rt_bus_ser.c rt_bus_cli.c

#库文件软连接设置

#links .so -> .so.1 -> .so.1.0.0
#rtbus
$(RTBUS_SHARED_SO): $(RTBUS_SHARED_VERSION)
    ln -s $(RTBUS_SHARED_VERSION) $(RTBUS_SHARED_SO)
$(RTBUS_SHARED): $(RTBUS_SHARED_SO)
    ln -s $(RTBUS_SHARED_SO) $(RTBUS_SHARED)

#make 安装命令,如果需要同时生成多个,需要写多个

#install
#rtbus
install-rt_bus:
    mkdir -p $(INSTALL_LIBRARY_PATH) $(INSTALL_INCLUDE_PATH)
    $(INSTALL) includes/rt_bus.h $(INSTALL_INCLUDE_PATH)
    $(INSTALL) $(RTBUS_SHARED) $(RTBUS_SHARED_SO) $(RTBUS_SHARED_VERSION) $(INSTALL_LIBRARY_PATH)
    $(INSTALL) $(RTBUS_STATIC) $(INSTALL_LIBRARY_PATH)

install: install-rt_bus

#make 卸载安装命令,如果需要同时生成多个,需要写多个

#uninstall
#rtbus
uninstall-rt_bus:
    $(RM) $(INSTALL_LIBRARY_PATH)/$(RTBUS_SHARED)
    $(RM) $(INSTALL_LIBRARY_PATH)/$(RTBUS_SHARED_VERSION)
    $(RM) $(INSTALL_LIBRARY_PATH)/$(RTBUS_SHARED_SO)
    $(RM) $(INSTALL_LIBRARY_PATH)/$(RTBUS_STATIC)
    $(RM) $(INSTALL_INCLUDE_PATH)/rt_bus.h

uninstall: uninstall-rt_bus

#make 清除命令,如果需要同时生成多个,需要写多个

clean:
    $(RM) *.o #delete object files
    $(RM) $(RTBUS_SHARED) $(RTBUS_SHARED_VERSION) $(RTBUS_SHARED_SO) $(RTBUS_STATIC) #delete rt_bus
 

以上就是Makefile文件,运行之后如下:

linux@ubuntu:~/share/rtbuslib$ make
gcc -c -fPIC -Wall -O0  -I/home/linux/share/rtbuslib/includes/  -I/home/linux/share/rtbuslib/../msg_queuelib/includes/msg_queue  -I/home/linux/work/nanomsg/include -fstack-protector rt_bus_ser.c -o rt_bus_ser.o
gcc -c -fPIC -Wall -O0  -I/home/linux/share/rtbuslib/includes/  -I/home/linux/share/rtbuslib/../msg_queuelib/includes/msg_queue  -I/home/linux/work/nanomsg/include -fstack-protector rt_bus_cli.c -o rt_bus_cli.o
gcc -shared -o librtbus.so.1.0.0 rt_bus_ser.o rt_bus_cli.o  
ln -s librtbus.so.1.0.0 librtbus.so.1
ln -s librtbus.so.1 librtbus.so
ar rcs librtbus.a rt_bus_ser.o rt_bus_cli.o
linux@ubuntu:~/share/rtbuslib$ tree
.
├── includes
│   └── rt_bus.h
├── librtbus.a
├── librtbus.so -> librtbus.so.1
├── librtbus.so.1 -> librtbus.so.1.0.0
├── librtbus.so.1.0.0
├── Makefile
├── rt_bus_cli.c
├── rt_bus_cli.o
├── rt_bus_ser.c
└── rt_bus_ser.o

1 directory, 10 files

安装后如下:

linux@ubuntu:~/share/rtbuslib$ make install
mkdir -p /home/linux/share/rtbuslib/lib /home/linux/share/rtbuslib/includes/rtbus
cp -a includes/rt_bus.h /home/linux/share/rtbuslib/includes/rtbus
cp -a librtbus.so librtbus.so.1 librtbus.so.1.0.0 /home/linux/share/rtbuslib/lib
cp -a librtbus.a /home/linux/share/rtbuslib/lib
linux@ubuntu:~/share/rtbuslib$ tree
.
├── includes
│   ├── rtbus
│   │   └── rt_bus.h
│   └── rt_bus.h
├── lib
│   ├── librtbus.a
│   ├── librtbus.so -> librtbus.so.1
│   ├── librtbus.so.1 -> librtbus.so.1.0.0
│   └── librtbus.so.1.0.0
├── librtbus.a
├── librtbus.so -> librtbus.so.1
├── librtbus.so.1 -> librtbus.so.1.0.0
├── librtbus.so.1.0.0
├── Makefile
├── rt_bus_cli.c
├── rt_bus_cli.o
├── rt_bus_ser.c
└── rt_bus_ser.o

3 directories, 15 files

下面放上原始文件

#记住当前工程的根目录路径
ROOT_DIR=$(shell pwd)
## need libs, add at here
LIBS :=
#LIBS :=pthread nanomsg msg_queue
#使用的库目录,静态库和动态库添加在这里
LIBRARY_PATH :=
#LIBRARY_PATH :=$(ROOT_DIR)/../msg_queuelib/lib /home/linux/work/nanomsg/lib
## used headers  file path
INCLUDE_PATH := $(ROOT_DIR)/includes/ $(ROOT_DIR)/../msg_queuelib/includes/msg_queue /home/linux/work/nanomsg/include
## get all include path
CFLAGS  += $(foreach dir, $(INCLUDE_PATH), -I$(dir))
## get all library path
LDFLAGS += $(foreach lib, $(LIBRARY_PATH), -L$(lib))
## get all librarys
LDFLAGS += $(foreach lib, $(LIBS), -l$(lib))

#CC=arm-linux-gcc
CC=gcc

RTBUS_OBJ = rt_bus_ser.o rt_bus_cli.o

RTBUS_LIBNAME = librtbus

LIBVERSION = 1.0.0
RTBUS_SOVERSION = 1

PREFIX ?= /home/linux/share/rtbuslib
PREFIX_INCLUDE_PATH ?= includes/rtbus
PREFIX_LIBRARY_PATH ?= lib

INSTALL_INCLUDE_PATH = $(DESTDIR)$(PREFIX)/$(PREFIX_INCLUDE_PATH)
INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(PREFIX_LIBRARY_PATH)

INSTALL ?= cp -a

# validate gcc version for use fstack-protector-strong
MIN_GCC_VERSION = "4.9"
GCC_VERSION := "`gcc -dumpversion`"
IS_GCC_ABOVE_MIN_VERSION := $(shell expr "$(GCC_VERSION)" ">=" "$(MIN_GCC_VERSION)")
ifeq "$(IS_GCC_ABOVE_MIN_VERSION)" "1"
    CFLAGS += -fstack-protector-strong
else
    CFLAGS += -fstack-protector
endif

R_CFLAGS = -fPIC -Wall -O0 $(CFLAGS)

uname := $(shell sh -c 'uname -s 2>/dev/null || echo false')

#library file extensions
SHARED = so
STATIC = a

## create dynamic (shared) library on Darwin (base OS for MacOSX and IOS)
ifeq (Darwin, $(uname))
	SHARED = dylib
endif

#rtbus library names
RTBUS_SHARED = $(RTBUS_LIBNAME).$(SHARED)
RTBUS_SHARED_VERSION = $(RTBUS_LIBNAME).$(SHARED).$(LIBVERSION)
RTBUS_SHARED_SO = $(RTBUS_LIBNAME).$(SHARED).$(RTBUS_SOVERSION)
RTBUS_STATIC = $(RTBUS_LIBNAME).$(STATIC)

#SHARED_CMD = $(CC) -shared -o

.PHONY: all shared static clean install

all: shared static

shared: $(RTBUS_SHARED)

static: $(RTBUS_STATIC)

.c.o:
	$(CC) -c $(R_CFLAGS) $< -o $@

#static libraries
#rtbus
$(RTBUS_STATIC): $(RTBUS_OBJ)
	$(AR) rcs $@ $^

#shared libraries .so.1.0.0
#rtbus
$(RTBUS_SHARED_VERSION): $(RTBUS_OBJ)
	$(CC) -shared -o $@ $^ $(LDFLAGS)

#objects
#rtbus
$(RTBUS_OBJ): rt_bus_ser.c rt_bus_cli.c

#links .so -> .so.1 -> .so.1.0.0
#rtbus
$(RTBUS_SHARED_SO): $(RTBUS_SHARED_VERSION)
	ln -s $(RTBUS_SHARED_VERSION) $(RTBUS_SHARED_SO)
$(RTBUS_SHARED): $(RTBUS_SHARED_SO)
	ln -s $(RTBUS_SHARED_SO) $(RTBUS_SHARED)

#install
#rtbus
install-rt_bus:
	mkdir -p $(INSTALL_LIBRARY_PATH) $(INSTALL_INCLUDE_PATH)
	$(INSTALL) includes/rt_bus.h $(INSTALL_INCLUDE_PATH)
	$(INSTALL) $(RTBUS_SHARED) $(RTBUS_SHARED_SO) $(RTBUS_SHARED_VERSION) $(INSTALL_LIBRARY_PATH)
	$(INSTALL) $(RTBUS_STATIC) $(INSTALL_LIBRARY_PATH)

install: install-rt_bus

#uninstall
#rtbus
uninstall-rt_bus:
	$(RM) $(INSTALL_LIBRARY_PATH)/$(RTBUS_SHARED)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(RTBUS_SHARED_VERSION)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(RTBUS_SHARED_SO)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(RTBUS_STATIC)
	$(RM) $(INSTALL_INCLUDE_PATH)/rt_bus.h

uninstall: uninstall-rt_bus

clean:
	$(RM) *.o #delete object files
	$(RM) $(RTBUS_SHARED) $(RTBUS_SHARED_VERSION) $(RTBUS_SHARED_SO) $(RTBUS_STATIC) #delete rt_bus

下面放一个同时生成多个库的Makefile

## need libs, add at here
LIBS := pthread
#使用的库目录,静态库和动态库添加在这里
LIBRARY_PATH :=
## used headers  file path
INCLUDE_PATH := includes/
## get all include path
CFLAGS  += $(foreach dir, $(INCLUDE_PATH), -I$(dir))
## get all library path
LDFLAGS += $(foreach lib, $(LIBRARY_PATH), -L$(lib))
## get all librarys
LDFLAGS += $(foreach lib, $(LIBS), -l$(lib))

CC=arm-linux-gcc
#CC=gcc

NLOG_OBJ = RTlog.o exception.o
NIPC_OBJ = message_queue.o semaphore.o
NDRIVER_OBJ = driver_nick.o
NLINUX_SYS_OBJ = linux_sys_nick.o

NLOG_LIBNAME = libnlog
NIPC_LIBNAME = libnipc
NDRIVER_LIBNAME = libndriver
NLINUX_SYS_LIBNAME = libnlinux_sys

LIBVERSION = 0.9.0
NLOG_SOVERSION = 1
NIPC_SOVERSION = 1
NDRIVER_SOVERSION = 1
NLINUX_SYS_SOVERSION = 1

PREFIX ?= /usr/local
PREFIX_INCLUDE_PATH ?= include/nick
PREFIX_LIBRARY_PATH ?= lib

INSTALL_INCLUDE_PATH = $(DESTDIR)$(PREFIX)/$(PREFIX_INCLUDE_PATH)
INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(PREFIX_LIBRARY_PATH)

INSTALL ?= cp -a

# validate gcc version for use fstack-protector-strong
MIN_GCC_VERSION = "4.9"
GCC_VERSION := "`gcc -dumpversion`"
IS_GCC_ABOVE_MIN_VERSION := $(shell expr "$(GCC_VERSION)" ">=" "$(MIN_GCC_VERSION)")
ifeq "$(IS_GCC_ABOVE_MIN_VERSION)" "1"
    CFLAGS += -fstack-protector-strong
else
    CFLAGS += -fstack-protector
endif

R_CFLAGS = -fPIC -Wall -O0 $(CFLAGS)

uname := $(shell sh -c 'uname -s 2>/dev/null || echo false')

#library file extensions
SHARED = so
STATIC = a

## create dynamic (shared) library on Darwin (base OS for MacOSX and IOS)
ifeq (Darwin, $(uname))
	SHARED = dylib
endif

#NICK log library names
NLOG_SHARED = $(NLOG_LIBNAME).$(SHARED)
NLOG_SHARED_VERSION = $(NLOG_LIBNAME).$(SHARED).$(LIBVERSION)
NLOG_SHARED_SO = $(NLOG_LIBNAME).$(SHARED).$(NLOG_SOVERSION)
NLOG_STATIC = $(NLOG_LIBNAME).$(STATIC)

#NICK IPC library names
NIPC_SHARED = $(NIPC_LIBNAME).$(SHARED)
NIPC_SHARED_VERSION = $(NIPC_LIBNAME).$(SHARED).$(LIBVERSION)
NIPC_SHARED_SO = $(NIPC_LIBNAME).$(SHARED).$(NIPC_SOVERSION)
NIPC_STATIC = $(NIPC_LIBNAME).$(STATIC)

#NICK driver library names
NDRIVER_SHARED = $(NDRIVER_LIBNAME).$(SHARED)
NDRIVER_SHARED_VERSION = $(NDRIVER_LIBNAME).$(SHARED).$(LIBVERSION)
NDRIVER_SHARED_SO = $(NDRIVER_LIBNAME).$(SHARED).$(NDRIVER_SOVERSION)
NDRIVER_STATIC = $(NDRIVER_LIBNAME).$(STATIC)

#NICK linux_sys library names
NLINUX_SYS_SHARED = $(NLINUX_SYS_LIBNAME).$(SHARED)
NLINUX_SYS_SHARED_VERSION = $(NLINUX_SYS_LIBNAME).$(SHARED).$(LIBVERSION)
NLINUX_SYS_SHARED_SO = $(NLINUX_SYS_LIBNAME).$(SHARED).$(NLINUX_SYS_SOVERSION)
NLINUX_SYS_STATIC = $(NLINUX_SYS_LIBNAME).$(STATIC)

#SHARED_CMD = $(CC) -shared -o

.PHONY: all shared static clean install

all: shared static

shared: $(NLOG_SHARED) $(NIPC_SHARED) $(NDRIVER_SHARED) $(NLINUX_SYS_SHARED)

static: $(NLOG_STATIC) $(NIPC_STATIC) $(NDRIVER_STATIC) $(NLINUX_SYS_STATIC)

.c.o:
	$(CC) -c $(R_CFLAGS) $< -o $@

#static libraries
#NICK log
$(NLOG_STATIC): $(NLOG_OBJ)
	$(AR) rcs $@ $^
#NICK IPC
$(NIPC_STATIC): $(NIPC_OBJ)
	$(AR) rcs $@ $^
#NICK driver
$(NDRIVER_STATIC): $(NDRIVER_OBJ)
	$(AR) rcs $@ $^
#NICK linux_sys
$(NLINUX_SYS_STATIC): $(NLINUX_SYS_OBJ)
	$(AR) rcs $@ $^

#shared libraries .so.1.0.0
#NICK log
$(NLOG_SHARED_VERSION): $(NLOG_OBJ)
	$(CC) -shared -o $@ $^ $(LDFLAGS)
#NICK IPC
$(NIPC_SHARED_VERSION): $(NIPC_OBJ)
	$(CC) -shared -o $@ $^ $(LDFLAGS)
#NICK driver
$(NDRIVER_SHARED_VERSION): $(NDRIVER_OBJ)
	$(CC) -shared -o $@ $^ $(LDFLAGS)
#NICK linux_sys
$(NLINUX_SYS_SHARED_VERSION): $(NLINUX_SYS_OBJ)
	$(CC) -shared -o $@ $^ $(LDFLAGS)

#objects
#NICK log
$(NLOG_OBJ): RTlog.c exception.c
#NICK IPC
$(NIPC_OBJ): RTlog.c exception.c message_queue.c semaphore.c
#NICK driver
$(NDRIVER_OBJ): RTlog.c exception.c driver_nick.c
#NICK linux_sys
$(NLINUX_SYS_OBJ): RTlog.c exception.c linux_sys_nick.c

#links .so -> .so.1 -> .so.1.0.0
#NICK log
$(NLOG_SHARED_SO): $(NLOG_SHARED_VERSION)
	ln -s $(NLOG_SHARED_VERSION) $(NLOG_SHARED_SO)
$(NLOG_SHARED): $(NLOG_SHARED_SO)
	ln -s $(NLOG_SHARED_SO) $(NLOG_SHARED)
#NICK IPC
$(NIPC_SHARED_SO): $(NIPC_SHARED_VERSION)
	ln -s $(NIPC_SHARED_VERSION) $(NIPC_SHARED_SO)
$(NIPC_SHARED): $(NIPC_SHARED_SO)
	ln -s $(NIPC_SHARED_SO) $(NIPC_SHARED)
#NICK driver
$(NDRIVER_SHARED_SO): $(NDRIVER_SHARED_VERSION)
	ln -s $(NDRIVER_SHARED_VERSION) $(NDRIVER_SHARED_SO)
$(NDRIVER_SHARED): $(NDRIVER_SHARED_SO)
	ln -s $(NDRIVER_SHARED_SO) $(NDRIVER_SHARED)
#NICK linux_sys
$(NLINUX_SYS_SHARED_SO): $(NLINUX_SYS_SHARED_VERSION)
	ln -s $(NLINUX_SYS_SHARED_VERSION) $(NLINUX_SYS_SHARED_SO)
$(NLINUX_SYS_SHARED): $(NLINUX_SYS_SHARED_SO)
	ln -s $(NLINUX_SYS_SHARED_SO) $(NLINUX_SYS_SHARED)

#install
#NICK log
install-nlog:
	mkdir -p $(INSTALL_LIBRARY_PATH) $(INSTALL_INCLUDE_PATH)
	$(INSTALL) includes/RTlog.h includes/exception_nick.h $(INSTALL_INCLUDE_PATH)
	$(INSTALL) $(NLOG_SHARED) $(NLOG_SHARED_SO) $(NLOG_SHARED_VERSION) $(INSTALL_LIBRARY_PATH)
	$(INSTALL) $(NLOG_STATIC) $(INSTALL_LIBRARY_PATH)
#NICK IPC
install-nipc:
	mkdir -p $(INSTALL_LIBRARY_PATH) $(INSTALL_INCLUDE_PATH)
	$(INSTALL) includes/message_queue_nick.h includes/semaphore_nick.h $(INSTALL_INCLUDE_PATH)
	$(INSTALL) $(NIPC_SHARED) $(NIPC_SHARED_SO) $(NIPC_SHARED_VERSION) $(INSTALL_LIBRARY_PATH)
	$(INSTALL) $(NIPC_STATIC) $(INSTALL_LIBRARY_PATH)
#NICK driver
install-ndriver:
	mkdir -p $(INSTALL_LIBRARY_PATH) $(INSTALL_INCLUDE_PATH)
	$(INSTALL) includes/driver_nick.h $(INSTALL_INCLUDE_PATH)
	$(INSTALL) $(NDRIVER_SHARED) $(NDRIVER_SHARED_SO) $(NDRIVER_SHARED_VERSION) $(INSTALL_LIBRARY_PATH)
	$(INSTALL) $(NDRIVER_STATIC) $(INSTALL_LIBRARY_PATH)
#NICK linux_sys
install-nlinux_sys:
	mkdir -p $(INSTALL_LIBRARY_PATH) $(INSTALL_INCLUDE_PATH)
	$(INSTALL) includes/linux_sys_nick.h $(INSTALL_INCLUDE_PATH)
	$(INSTALL) $(NLINUX_SYS_SHARED) $(NLINUX_SYS_SHARED_SO) $(NLINUX_SYS_SHARED_VERSION) $(INSTALL_LIBRARY_PATH)
	$(INSTALL) $(NLINUX_SYS_STATIC) $(INSTALL_LIBRARY_PATH)

install: install-nlog install-nipc install-ndriver install-nlinux_sys

#uninstall
#NICK log
uninstall-nlog:
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NLOG_SHARED)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NLOG_SHARED_VERSION)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NLOG_SHARED_SO)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NLOG_STATIC)
	$(RM) $(INSTALL_INCLUDE_PATH)/RTlog.h $(INSTALL_INCLUDE_PATH)/exception_nick.h 
#NICK IPC
uninstall-nipc:
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NIPC_SHARED)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NIPC_SHARED_VERSION)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NIPC_SHARED_SO)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NIPC_STATIC)
	$(RM) $(INSTALL_INCLUDE_PATH)/message_queue_nick.h $(INSTALL_INCLUDE_PATH)/semaphore_nick.h
#NICK driver
uninstall-ndriver:
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NDRIVER_SHARED)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NDRIVER_SHARED_VERSION)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NDRIVER_SHARED_SO)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NDRIVER_STATIC)
	$(RM) $(INSTALL_INCLUDE_PATH)/driver_nick.h 
#NICK linux_sys
uninstall-nlinux_sys:
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NLINUX_SYS_SHARED)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NLINUX_SYS_SHARED_VERSION)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NLINUX_SYS_SHARED_SO)
	$(RM) $(INSTALL_LIBRARY_PATH)/$(NLINUX_SYS_STATIC)
	$(RM) $(INSTALL_INCLUDE_PATH)/linux_sys_nick.h

uninstall: uninstall-nlog uninstall-nipc uninstall-ndriver uninstall-nlinux_sys

clean:
	$(RM) *.o #delete object files
	$(RM) $(NLOG_SHARED) $(NLOG_SHARED_VERSION) $(NLOG_SHARED_SO) $(NLOG_STATIC) #delete nlog
	$(RM) $(NIPC_SHARED) $(NIPC_SHARED_VERSION) $(NIPC_SHARED_SO) $(NIPC_STATIC) #delete nipc
	$(RM) $(NDRIVER_SHARED) $(NDRIVER_SHARED_VERSION) $(NDRIVER_SHARED_SO) $(NDRIVER_STATIC) #delete ndriver
	$(RM) $(NLINUX_SYS_SHARED) $(NLINUX_SYS_SHARED_VERSION) $(NLINUX_SYS_SHARED_SO) $(NLINUX_SYS_STATIC) #delete nlinux_sys

上面的文件运行make之后是这样的

linux@ubuntu:~/share/nick/lib_s$ tree
.
├── driver_nick.c
├── driver_nick.o
├── exception.c
├── exception.o
├── includes
│   ├── driver_nick.h
│   ├── exception_nick.h
│   ├── gpio.h
│   ├── linux_sys_nick.h
│   ├── message_queue_nick.h
│   ├── RTlog.h
│   └── semaphore_nick.h
├── libndriver.a
├── libndriver.so -> libndriver.so.1
├── libndriver.so.0.9.0
├── libndriver.so.1 -> libndriver.so.0.9.0
├── libnipc.a
├── libnipc.so -> libnipc.so.1
├── libnipc.so.0.9.0
├── libnipc.so.1 -> libnipc.so.0.9.0
├── libnlinux_sys.a
├── libnlinux_sys.so -> libnlinux_sys.so.1
├── libnlinux_sys.so.0.9.0
├── libnlinux_sys.so.1 -> libnlinux_sys.so.0.9.0
├── libnlog.a
├── libnlog.so -> libnlog.so.1
├── libnlog.so.0.9.0
├── libnlog.so.1 -> libnlog.so.0.9.0
├── linux_sys_nick.c
├── linux_sys_nick.o
├── Makefile
├── Makefile.back
├── message_queue.c
├── message_queue.o
├── RTlog.c
├── RTlog.o
├── semaphore.c
└── semaphore.o

1 directory, 37 files

 

你可能感兴趣的:(编程语言技巧)