I've written a C++ program (command line, portable code) and I'm trying to release a Linux version at the same time as the Windows version. I've written a makefile as follows:
ayane: *.cpp *.h g++ -Wno-write-strings -oayane *.cpp
Straightforward enough so far; but I'm given to understand it's customary to have a second step, make install. So when I put the install: target in the makefile... what command should be associated with it? (If possible I'd prefer it to work on all Unix systems as well as Linux.)
The ”make” command in Linux is used to compile and manage a collection of applications and files from source code. It allows developers to use the terminal to install and collect a variety of programs. It also manages and reduces the amount of time that is required for the compilation.
The install command is a Unix program used to copy files and set file permissions. Some implementations offer to invoke strip while installing executable files. The command is not defined in POSIX. It has mostly split into two camps in terms of compatibility, a GNU type and a BSD type.
./configure runs a script named "configure" in the current directory. make runs the program "make" in your path, and make install runs it again with the argument "install". Generally, the "configure" script was generated by a collection of programs known as "autotools".
A less trivial installer will copy several things into place, first insuring that the appropriate paths exists (using mkdir -p
or similar). Typically something like this:
$INSTALL_PATH/bin
$INSTALL_PATH/lib
or $INSTALL_PATH/lib/yourappname
$INSTALL_PATH/share/man/man1
and possibly other sections if appropriate$INSTALL_PATH/share/yourappname
$INSTALL_PATH/etc/yourappname
$INSTALL_PATH/include/yourappname
The INSTALL_PATH
is an input to the build system, and usually defaults to /usr/local
. This gives your user the flexibility to install under their $HOME without needing elevated permission.
In the simplest case just use
INSTALL_PATH?=/usr/local
at the top of the makefile. Then the user can override it by setting an environment variable in their shell.
You also occasionally see make install
s that build a manifest to help with de-installation. The manifest can even be written as a script to do the work.
Another approach is just to have a make uninstall
that looks for the things make install
places, and removes them if they exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With