2.9. Placing arbitrary artifacts in the system using the make install command
Using the make install
command is an automated way to install built software to the system. In this case, you need to specify how to install the arbitrary artifacts to the system in the Makefile
that is usually written by the developer.
This procedure shows how to install a build artifact into a chosen location on the system.
Procédure
Add the
install
section to theMakefile
:Makefile
cello: gcc -g -o cello cello.c clean: rm cello install: mkdir -p $(DESTDIR)/usr/bin install -m 0755 cello $(DESTDIR)/usr/bin/cello
Note that the lines under
cello:
,clean:
, andinstall:
must begin with a tab space.NoteThe $(DESTDIR) variable is a GNU make built-in and is commonly used to specify installation to a directory different than the root directory.
Now you can use
Makefile
not only to build software, but also to install it to the target system.Build and install the
cello.c
program:$ make gcc -g -o cello cello.c $ sudo make install install -m 0755 cello /usr/bin/cello
As a result,
cello
is now located in the directory that is listed in the$PATH
variable.Execute
cello
from any directory without specifying its full path:$ cd ~ $ cello Hello World