首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让Makefile变得更短?

如何让Makefile变得更短?
EN

Stack Overflow用户
提问于 2010-07-18 16:17:54
回答 2查看 407关注 0票数 4

我有以下Makefile:

代码语言:javascript
复制
all: hello.exe hellogtk.exe hellogtktng.cs

hello.exe: hello.cs
 gmcs hello.cs

hellogtk.exe: hellogtk.cs
 gmcs -pkg:gtk-sharp-2.0 hellogtk.cs

hellogtktng.exe: hellogtktng.cs
 gmcs -pkg:gtk-sharp-2.0 hellogtktng.cs

clean:
 rm -f *.exe

我刚刚开始学习如何编写Makefile,我觉得所有这些都有点重复。Makefile专业人士会怎么做呢?

EN

回答 2

Stack Overflow用户

发布于 2010-07-18 16:29:08

代码语言:javascript
复制
all: hello.exe hellogtk.exe hellogtktng.exe

%.exe: %.cs
 gmcs -pkg:gtk-sharp-2.0 $<

clean:
 rm -f *.exe
票数 7
EN

Stack Overflow用户

发布于 2010-07-18 17:10:14

Here's how you can add flags to specific targets.

代码语言:javascript
复制
# An empty variable for flags (Not strictly neccessary, 
# undefined variables expand to an empty string)
GMCSFLAGS =

# The first target is made if you don't specify arguments
all: hello.exe hellogtk.exe hellogtktng.exe

# Add flags to specific files
hellogtk.exe hellogtktng.exe: GCMSFLAGS = -pkg:gtk-sharp-2.0

# A pattern rule to transform .cs to .exe
# The percent sign is substituted when looking for dependancies
%.exe:%.cs
    gmcs $(GMCSFLAGS) $<
# $() expands a variable, $< is the first dependancy in the list
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3274810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档