我有以下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
Run Code Online (Sandbox Code Playgroud)
我只是开始学习如何编写Makefile,我觉得这一切都有点重复.Makefile专业人员将如何做到这一点?
all: hello.exe hellogtk.exe hellogtktng.exe
%.exe: %.cs
gmcs -pkg:gtk-sharp-2.0 $<
clean:
rm -f *.exe
Run Code Online (Sandbox Code Playgroud)
# 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
Run Code Online (Sandbox Code Playgroud)