Makefile生成动态库通用模板

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生成动态库通用模板)