zoukankan      html  css  js  c++  java
  • Makefile模板

    Makefile模板:

    1.生成可执行程序的Makefile

     1 ########################################
     2 #
     3 # build exectable object Makefile
     4 ########################################
     5 SOURCE  := $(wildcard *.c) $(wildcard *.cpp)
     6 OBJS    := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))
     7 
     8 # edit the following variables
     9 TARGET  := test
    10 CC      :=
    11 LIBS    :=
    12 LDFLAGS :=
    13 DEFINES :=
    14 INCLUDE :=
    15 
    16 CFLAGS  := -Wall $(DEFINES) $(INCLUDE)
    17 CXXFLAGS:= $(CFLAGS)
    18 
    19 
    20 # do not change the following objects below before you understand it's use
    21 .PHONY : everything objs rebuild clean veryclean
    22 
    23 everything : $(TARGET)
    24 
    25 objs : $(OBJS)
    26 
    27 rebuild: veryclean everything
    28 
    29 clean :
    30     rm -fr *.o
    31 
    32 veryclean : clean
    33     rm -fr $(TARGET)
    34 
    35 $(TARGET) : $(OBJS)
    36     $(CC) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

    2.生成静态链接库的Makefile

     1 ########################################
     2 #
     3 # build static library Makefile
     4 ########################################
     5 SOURCE  := $(wildcard *.c) $(wildcard *.cpp)
     6 OBJS    := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))
     7 
     8 # edit the following variables
     9 TARGET  := libtest.a
    10 CC      :=
    11 AR      :=
    12 LIBS    :=
    13 LDFLAGS :=
    14 DEFINES :=
    15 INCLUDE :=
    16 
    17 RANLIB  := ranlib
    18 CFLAGS  := -Wall $(DEFINES) $(INCLUDE)
    19 CXXFLAGS:= $(CFLAGS)
    20 
    21 
    22 # do not change the following objects below before you understand it's use
    23 .PHONY : everything objs rebuild clean veryclean
    24 
    25 everything : $(TARGET)
    26 
    27 objs : $(OBJS)
    28 
    29 rebuild: veryclean everything
    30 
    31 clean :
    32     rm -fr *.o
    33 
    34 veryclean : clean
    35     rm -fr $(TARGET)
    36 
    37 $(TARGET) : $(OBJS)
    38     $(AR) cr $(TARGET) $(OBJS)
    39     $(RANLIB) $(TARGET)

    3.生成动态链接库的Makefile

     1 ########################################
     2 #
     3 # build dynamic library Makefile
     4 ########################################
     5 SOURCE  := $(wildcard *.c) $(wildcard *.cpp)
     6 OBJS    := $(SOURCE)
     7 
     8 # edit the following variables
     9 TARGET  := libtest.so
    10 CC      :=
    11 LIBS    :=
    12 LDFLAGS :=
    13 DEFINES :=
    14 INCLUDE :=
    15 
    16 CFLAGS  := -Wall $(DEFINES) $(INCLUDE)
    17 CXXFLAGS:= $(CFLAGS)
    18 SHARE   := -fPIC -shared -o
    19 
    20 
    21 # do not change the following objects below before you understand it's use
    22 .PHONY : everything objs rebuild clean veryclean
    23 
    24 everything : $(TARGET)
    25 
    26 objs : $(OBJS)
    27 
    28 rebuild: veryclean everything
    29 
    30 clean :
    31     rm -fr *.o
    32 
    33 veryclean : clean
    34     rm -fr $(TARGET)
    35 
    36 $(TARGET) : $(OBJS)
    37     $(CC) $(CXXFLAGS) $(SHARE) $@ $(OBJS) $(LDFLAGS) $(LIBS)
  • 相关阅读:
    BZOJ_2661_[BeiJing wc2012]连连看_费用流
    BZOJ_4867_[Ynoi2017]舌尖上的由乃_分块+dfs序
    BZOJ_3238_[Ahoi2013]差异_后缀自动机
    BZOJ_3207_花神的嘲讽计划Ⅰ_哈希+主席树
    [转载]快速幂与矩阵快速幂
    ACM的一点基础知识
    [转载]C++STL—vector的插入与删除
    C++STL—map的使用
    [转载]汇编语言assume伪指令的作用
    [转载]c++中的位运算符
  • 原文地址:https://www.cnblogs.com/live-program/p/11110243.html
Copyright © 2011-2022 走看看