Как сделать Makefile короче? - PullRequest
4 голосов
/ 18 июля 2010

У меня есть следующий Makefile:

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 поступят так?

Ответы [ 2 ]

7 голосов
/ 18 июля 2010
all: hello.exe hellogtk.exe hellogtktng.exe

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

clean:
 rm -f *.exe
6 голосов
/ 18 июля 2010

Вот как вы можете добавлять флаги к определенным целям.

# 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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...