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 <chrubis@suse.cz> 2012 24# 25 26# Makefile to include for libraries. 27 28include $(top_srcdir)/include/mk/env_pre.mk 29 30INSTALL_DIR := $(libdir) 31 32# An extension of generic_leaf_target, strictly for libraries. 33.PHONY: install_headers 34 35ifndef LIB 36ifndef INTERNAL_LIB 37$(error You must define LIB or INTERNAL_LIB when including this Makefile) 38endif 39endif 40 41install_headers: $(addprefix $(DESTDIR)/$(includedir)/,$(notdir $(HEADER_FILES))) 42 43INSTALL_MODE ?= 00664 44 45# Hide the LIB target for internal libs on install 46ifneq ($(MAKECMDGOALS),install) 47LIB ?= $(INTERNAL_LIB) 48endif 49 50MAKE_TARGETS += $(LIB) 51 52LIBSRCS ?= $(wildcard $(abs_srcdir)/*.c) 53LIBSRCS := $(sort $(LIBSRCS)) 54LIBSRCS := $(abspath $(LIBSRCS)) 55LIBSRCS := $(subst $(abs_srcdir)/,,$(wildcard $(LIBSRCS))) 56LIBSRCS := $(filter-out $(FILTER_OUT_LIBSRCS),$(LIBSRCS)) 57 58LIBOBJS := $(LIBSRCS:.c=.o) 59 60$(LIB): $(notdir $(LIBOBJS)) 61 @if [ -z "$(strip $^)" ] ; then \ 62 echo "Cowardly refusing to create empty archive"; \ 63 exit 1; \ 64 fi 65ifdef VERBOSE 66 $(if $(AR),$(AR),ar) -rc "$@" $^ 67 $(if $(RANLIB),$(RANLIB),ranlib) "$@" 68else 69 @echo "AR $@" 70 @$(if $(AR),$(AR),ar) -rc "$@" $^ 71 @echo "RANLIB $@" 72 @$(if $(RANLIB),$(RANLIB),ranlib) "$@" 73endif 74 75include $(top_srcdir)/include/mk/generic_leaf_target.mk 76