Linux Makefile (中文版)

Source: Internet
Author: User

#############################################################################
# Generic Makefile for C + + program
# Usage:
# ------
# 1. Copy the Makefile to your program directory.
# 2. Customize in the ' customizable section ' only if necessary:
# * To use non-standard C + + libraries, set pre-processor or compiler
# Options to <MY_CFLAGS> and linker ones to <MY_LIBS>
# (see makefile.gtk+-2.0 for an example)
# * To search sources in + directories, set to <SRCDIRS>
# * To specify your favorite program name, set to <PROGRAM>
# 3. Type make-to-start building your program.
#
# Make Target:
# ------------
# The Makefile provides the following targets to make:
# $ make compile and link
# $ make Nodep=yes compile and link without generating dependencies
# $ make Objs compile only (no linking)
# $ make tags Create tags for Emacs editor
# $ make ctags create ctags for VI editor
# $ make clean objects and the executable file
# $ make Distclean clean objects, the executable and dependencies
# $ make help get the usage of the makefile
#
#===========================================================================

# # Customizable Section:adapt those variables to suit your program.
##==========================================================================

# The Pre-processor and compiler options.
# my_cflags =-ggdb3-pipe-o2-wall-wextra-fopenmp-march=native-mfpmath=sse-dlinux-m64-std=c++0x
My_cflags =-g-dlinux-itest1/include-itest2/include-itest1/include/test1-itest2/include/test2

# The linker options.
# my_libs =-lglew-lglut-lglu-lgl-lx11-lxmu-lxi-lm-l/usr/x11r6/lib-lgomp-lopenthreads-lpthread
My_libs =-lm

# The Pre-processor options used by the CPP (Mans CPP for more).
Cppflags =

# The options used in linking as well as in any direct use of LD.
Ldflags =

# The directories in which source files reside.
# If not specified, only the current directory would be serached.
Srcdirs =


# The executable file name.
# If not specified, the current directory name or ' a.out ' would be used.
program =

# # Implicit Section:change the following only when necessary.
##==========================================================================

# The source file types (headers excluded).
#. c indicates C source files, and others C + + ones.
Srcexts =. C. C. cc. cpp. CPP. C + +. Cxx. CP

# The header file types.
Hdrexts =. H. H. HH. hpp. HPP h++. hxx. HP

# The Pre-processor and compiler options.
# Users can override those variables from the command line.
CFLAGS =
# cxxflags=-std=c++0x
cxxflags=
# the C program compiler.
CC = gcc

# The C + + program compiler.
CXX = g++

# un-comment The following line to compile C programs as C + + ones.
#CC = $ (CXX)

# The command used to delete file.
RM = Rm-f

Etags = Etags
Etagsflags =

CTAGS = CTAGS
Ctagsflags =

# # Stable section:usually no need to be changed. But you can add more.
##==========================================================================
SHELL =/bin/sh
EMPTY =
SPACE = $ (empty) $ (empty)
Ifeq ($ (program),)
Cur_path_names = $ (subst/,$ (space), $ (subst $ (space), _,$ (CURDIR)))
Program = $ (Word $ (words $ (cur_path_names)), $ (cur_path_names))
Ifeq ($ (program),)
program = A.out
endif
endif
Ifeq ($ (srcdirs),)
Srcdirs =.
endif
SOURCES = $ (foreach d,$ (srcdirs), $ (wildcard $ (Addprefix $ (d)/*,$ (srcexts)))
HEADERS = $ (foreach d,$ (srcdirs), $ (wildcard $ (Addprefix $ (d)/*,$ (hdrexts)))
Src_cxx = $ (filter-out%.c,$ (SOURCES))
OBJS = $ (addsuffix. O, $ (basename $ (SOURCES)))
DEPS = $ (OBJS:.O=.D)

# # Define some useful variables.
dep_opt = $ (Shell if ' $ (CC)--version | grep "GCC" >/dev/null "; then \
echo "-MM-MP"; else echo "-M"; FI)
DEPEND = $ (CC) $ (dep_opt) $ (my_cflags) $ (CFLAGS) $ (cppflags)
DEPEND.D = $ (Subst-g,, $ (DEPEND))
compile.c = $ (CC) $ (my_cflags) $ (CFLAGS) $ (cppflags)-C
Compile.cxx = $ (cxx) $ (my_cflags) $ (cxxflags) $ (cppflags)-C
LINK.C = $ (CC) $ (my_cflags) $ (CFLAGS) $ (cppflags) $ (ldflags)
Link.cxx = $ (cxx) $ (my_cflags) $ (cxxflags) $ (cppflags) $ (ldflags)

. Phony:all objs Tags ctags clean distclean help Show

# Delete The default suffixes
. Suffixes:

All: $ (program)

# Rules for creating dependency files (. d).
#------------------------------------------

%.d:%.c
@echo-N $ (dir {1}lt;) > [Email protected]
@$ (DEPEND.D) {1}lt; >> [email protected]

%.d:%. C
@echo-N $ (dir {1}lt;) > [Email protected]
@$ (DEPEND.D) {1}lt; >> [email protected]

%.d:%.cc
@echo-N $ (dir {1}lt;) > [Email protected]
@$ (DEPEND.D) {1}lt; >> [email protected]

%.d:%.cpp
@echo-N $ (dir {1}lt;) > [Email protected]
@$ (DEPEND.D) {1}lt; >> [email protected]

%.d:%. Cpp
@echo-N $ (dir {1}lt;) > [Email protected]
@$ (DEPEND.D) {1}lt; >> [email protected]

%.d:%.c++
@echo-N $ (dir {1}lt;) > [Email protected]
@$ (DEPEND.D) {1}lt; >> [email protected]

%.d:%.cp
@echo-N $ (dir {1}lt;) > [Email protected]
@$ (DEPEND.D) {1}lt; >> [email protected]

%.d:%.cxx
@echo-N $ (dir {1}lt;) > [Email protected]
@$ (DEPEND.D) {1}lt; >> [email protected]

# Rules for generating object files (. o).
#----------------------------------------
objs:$ (OBJS)

%.o:%.c
$ (compile.c) {1}lt; -O [email protected]

%.o:%. C
$ (compile.cxx) {1}lt; -O [email protected]

%.o:%.cc
$ (compile.cxx) {1}lt; -O [email protected]

%.o:%.cpp
$ (compile.cxx) {1}lt; -O [email protected]

%.o:%. Cpp
$ (compile.cxx) {1}lt; -O [email protected]

%.o:%.c++
$ (compile.cxx) {1}lt; -O [email protected]

%.o:%.cp
$ (compile.cxx) {1}lt; -O [email protected]

%.o:%.cxx
$ (compile.cxx) {1}lt; -O [email protected]

# Rules for generating the tags.
#-------------------------------------
Tags: $ (HEADERS) $ (SOURCES)
$ (etags) $ (etagsflags) $ (HEADERS) $ (SOURCES)

Ctags: $ (HEADERS) $ (SOURCES)
$ (CTAGS) $ (ctagsflags) $ (HEADERS) $ (SOURCES)

# Rules for generating the executable.
#-------------------------------------
$ (Program): $ (OBJS)
Ifeq ($ (Src_cxx),) # C Program
$ (LINK.C) $ (OBJS) $ (my_libs)-o [email protected]
@echo Type./[email protected] to execute the program.
else # C + + program
$ (link.cxx) $ (OBJS) $ (my_libs)-o [email protected]
@echo Type./[email protected] to execute the program.
endif

# TANG MODIFY START
#ifndef NODEP
Ifdef NODEP
# TANG MODIFY END
Ifneq ($ (DEPS),)
Sinclude $ (DEPS)
endif
endif

Clean
$ (RM) $ (OBJS) $ (program) $ (program). exe

Distclean:clean
$ (RM) $ (DEPS) TAGS
##############################################################################
# Show Help.
Help
@echo ' Generic Makefile for C + + Programs (gcmakefile) version 0.5 '
@echo ' Copyright (C), Whyglinux <[email protected]> '
@echo
@echo ' Usage:make [TARGET] '
@echo ' TARGETS: '
@echo ' All (=make) compile and link. '
@echo ' nodep=yes make without generating dependencies. '
@echo ' Objs compile only (no linking). '
@echo ' tags create tags for Emacs editor. '
@echo ' ctags create ctags for VI editor. '
@echo ' Clean clean objects and the executable file. '
@echo ' Distclean clean objects, the executable and dependencies. '
@echo ' Show show variables (for debug with only). '
@echo ' help print this message. '
@echo
@echo ' report Bugs-<whyglinux at Gmail DOT com>. '

# Show variables (for debug with only.)
Show
@echo ' program: ' $ (program)
@echo ' Srcdirs: ' $ (srcdirs)
@echo ' HEADERS: ' $ (HEADERS)
@echo ' SOURCES: ' $ (SOURCES)
@echo ' Src_cxx: ' $ (src_cxx)
@echo ' OBJS: ' $ (OBJS)
@echo ' DEPS: ' $ (DEPS)
@echo ' DEPEND: ' $ (DEPEND)
@echo ' compile.c: ' $ (compile.c)
@echo ' Compile.cxx: ' $ (compile.cxx)
@echo ' LINK.C: ' $ (LINK.C)
@echo ' Link.cxx: ' $ (link.cxx)

# # End of the Makefile # suggestions is welcome # All rights Reserved # #
#############################################################################

Linux Makefile (中文版)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.