34
Make Command: A Magical Way for Automating Stuff
In this mini-tutorial, you will learn how to write a Makefile
for automating stuff from project builds to whatnot, which is executed by the make
command in Linux
Makefile
saves the day!make
uses a Makefile
for automating the whole process of building stuff from start to finish.make
if you want to.target: dependency
action
target: target file or command that will be invoked when a user executes the make
command with following Command-Line Argument make target
dependency (optional): they can be as many as you want (space separated) and they are a dependency for building that specific target
action: that's where you type the commands that need to be executed for building that target
If a user simply executes make
without any option, the target named all
will be executed.
Before typing the command for building the target in action, ensure to add a tab
instead of spaces or it will keep saying ":makefile:4: *** missing separator. Stop." or something like that.
Dependencies can be files as well in the local directory.
Makefile
all: one two
echo "Executed all"
one:
echo "Building one"
two:
echo "Building two (part 1)"
echo "Building two (part 2)"
make
works...make
echo "Building one"
Building one
echo "Building two (Part 1)"
Building two (Part 1)
echo "Building two (Part 2)"
Building two (Part 2)
echo "Executed all"
Executed all
make
command.make one
echo "Building one"
Building one
make two
echo "Building two (Part 1)"
Building two (Part 1)
echo "Building two (Part 2)"
Building two (Part 2)
make
command in Linux for automating stuff from builds to what not.