1# 2# library include Makefile. 3# 4# Copyright (c) Linux Test Project, 2009-2020 5# Copyright (c) Cisco Systems Inc., 2009 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License along 18# with this program; if not, write to the Free Software Foundation, Inc., 19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20# 21# Ngie Cooper, July 2009 22# 23# Copyright (C) Cyril Hrubis <[email protected]> 2012 24# 25 26# Makefile to include for libraries. 27 28include $(top_srcdir)/include/mk/env_pre.mk 29include $(top_srcdir)/include/mk/sparse.mk 30 31INSTALL_DIR := $(libdir) 32 33# An extension of generic_leaf_target, strictly for libraries. 34.PHONY: install_headers 35 36ifndef LIB 37ifndef INTERNAL_LIB 38$(error You must define LIB or INTERNAL_LIB when including this Makefile) 39endif 40endif 41 42install_headers: $(addprefix $(DESTDIR)/$(includedir)/,$(notdir $(HEADER_FILES))) 43 44INSTALL_MODE ?= 00664 45 46# Hide the LIB target for internal libs on install 47ifneq ($(MAKECMDGOALS),install) 48LIB ?= $(INTERNAL_LIB) 49endif 50 51MAKE_TARGETS += $(LIB) 52 53LIBSRCS ?= $(wildcard $(abs_srcdir)/*.c) 54LIBSRCS := $(sort $(LIBSRCS)) 55LIBSRCS := $(abspath $(LIBSRCS)) 56LIBSRCS := $(subst $(abs_srcdir)/,,$(wildcard $(LIBSRCS))) 57LIBSRCS := $(filter-out $(FILTER_OUT_LIBSRCS),$(LIBSRCS)) 58 59LIBOBJS := $(LIBSRCS:.c=.o) 60 61CHECK_TARGETS := $(addprefix check-,$(notdir $(LIBSRCS:.c=))) 62 63$(LIB): $(notdir $(LIBOBJS)) 64 @if [ -z "$(strip $^)" ] ; then \ 65 echo "Cowardly refusing to create empty archive"; \ 66 exit 1; \ 67 fi 68ifdef VERBOSE 69 $(if $(AR),$(AR),ar) -rc "$@" $^ 70 $(if $(RANLIB),$(RANLIB),ranlib) "$@" 71else 72 @echo "AR $@" 73 @$(if $(AR),$(AR),ar) -rc "$@" $^ 74 @echo "RANLIB $@" 75 @$(if $(RANLIB),$(RANLIB),ranlib) "$@" 76endif 77 78include $(top_srcdir)/include/mk/generic_leaf_target.mk 79