Normally in UNIX systems the headers go to $PREFIX/include
, library files go to $PREFIX/lib
, where PREFIX
can be /usr
or /usr/local
or whatever. In linux, if you install your library to these directories it will be found by gcc
as you want with just gcc my_source.c -lunixlib
.
The PREFIX
environment variable is commonly used by various build tools to supply that prefix.
I would also recommend to use DESTDIR
variable, it is used by Debian packaging tools at least.
So, the makefile would be like:
# PREFIX is environment variable, but if it is not set, then set default value
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
install: unixlib.a
install -d $(DESTDIR)$(PREFIX)/lib/
install -m 644 unixlib.a $(DESTDIR)$(PREFIX)/lib/
install -d $(DESTDIR)$(PREFIX)/include/
install -m 644 unixlib.h $(DESTDIR)$(PREFIX)/include/
Note, the install -d ...
is used just in case if directory does not exist in the supplied DESTDIR
for example.
You can also have a look at my non-recursive template for make
to find some hints: https://github.com/cppfw/prorab/blob/master/src/prorab.mk