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

  1. Add the install section to the Makefile:

    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:, and install: must begin with a tab space.

    Note

    The $(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.

  2. 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.

  3. Execute cello from any directory without specifying its full path:

    $ cd ~
    
    $ cello
    Hello World