A simple Makefile

來源:互聯網
上載者:User

# A simple Makefile!<br />#<br /># The Makefile just compiles all C source and CPP source file<br /># in current directory, but your can modify and extend the it.<br /># Any problem please email me!<br />#<br /># Author: galen<br /># Email: galen.gang.liu@gmail.com<br /># 26-Mar-2010<br />TARGET := simple # << your executable name >><br />CC = gcc<br />CXX = g++<br />CCFLAGS = -g -O2 -Wall -Werror<br />CXXFLAGS = -g -O2 -Wall -Werror<br />LDFLAGS =<br />LIBS = -lcppunit -ldl # <<using library that you need >><br /># $(wildcard pattern...)<br /># http://www.gnu.org/software/make/manual/make.html#Wildcard-Function<br /># We using the wildcard function to get a list of all the<br /># C source and CPP source files in current directory.<br />SOURCES = $(wildcard *.c *.cpp)<br /># $(patsubst pattern,replacement,text)<br /># http://www.gnu.org/software/make/manual/make.html#Text-Functions<br /># We using the patsubst function applies a pattern to every word<br /># in a list of words(actually, text is consisted of words),<br /># and performs a simple textual substitution.<br />OBJS = $(patsubst %.c, %.o, $(patsubst %.cpp, %.o, $(SOURCES)))<br />all: ${TARGET}<br />${TARGET}: ${OBJS}<br /> ${CXX} ${LDFLAGS} -o $@ $^ ${LIBS} # << if your source is c language, using CC instead of CXX >><br />%.o: %.c # << compile c language >><br /> ${CC} ${CFLAGS} -c $<<br />%.o: %.cpp # << compile c++ language >><br /> ${CXX} ${CXXFLAGS} -c $<<br />.PHONY: all clean distclean<br />clean:<br /> -rm -f *~ *.o ${TARGET}<br />distclean: clean

 

Each action must be indented with at least one space
(traditional make requires a tab character)

 

TARGET := test<br />CC = g++<br />CFLAGS = -g -O2 -Wall -Werror<br />LDFLAGS =<br />LIBS = -lm<br />SRCS = $(wildcard *.cpp)<br />OBJS = $(patsubst %.cpp, %.o, $(SRCS))<br />all : ${TARGET}<br />${TARGET} : ${OBJS}<br />${CC} ${LDFLAGS} $^ -o $@ ${LIBS}<br />%.o : %.cpp<br />${CC} ${CFLAGS} -c $<<br />.PHONY: all clean distclean<br />clean:<br />-rm -f *o ${TARGET}<br />distclean: clean<br />env:<br />@echo "SRCS = ${SRCS}"<br />@echo "OBJS = ${OBJS}"

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.