美文网首页
Makefile生成动态库通用模板

Makefile生成动态库通用模板

作者: 小虎哥 | 来源:发表于2019-11-17 00:17 被阅读0次
    GCC := gcc
    LIB_NAME := test
    
    ifeq ($(OS),Windows_NT)
        uname_S := Windows
    else
        uname_S := $(shell uname -s)
    endif
    
    ifeq ($(uname_S), Windows)
        SHARE_LIB   := $(LIB_NAME).dll
        CFLAGS  := -I${JAVA_HOME}/include -I${JAVA_HOME}/include/win32 -Wl,--add-stdcall-alias -shared
    endif
    ifeq ($(uname_S), Linux)
        SHARE_LIB   := $(LIB_NAME).so
        CFLAGS  := -fPIC -shared -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux
    endif
    ifeq ($(uname_S), Darwin)
        SHARE_LIB   := $(LIB_NAME).jnilib
        CFLAGS := -Os -dynamiclib -I${JAVA_HOME}/include -I${JAVA_HOME}/include/darwin    
    endif
    
    DIR_SRC := .
    DIR_OBJ := .
    DIR_LIB := lib
    
    SRC := $(wildcard ${DIR_SRC}/*.c)
    OBJ := $(patsubst %.c, ${DIR_OBJ}/%.o, $(notdir ${SRC}))
    
    all:$(OBJ)
        $(GCC) -o $(DIR_LIB)/$(SHARE_LIB) $(SRC) $(CFLAGS)
    clean:
        rm -rf $(DIR_OBJ)/*.o $(DIR_LIB)/*
    

    相关文章

      网友评论

          本文标题:Makefile生成动态库通用模板

          本文链接:https://www.haomeiwen.com/subject/ggqsictx.html