# SPDX-License-Identifier: Apache-2.0
#
# Copyright IBM Corp. 2021
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Build a static version of the library.

# Another variant of all the object files is getting built.  For this
# variant CFLAGS_SHARED and CXXFLAGS_SHARED will not be used to build
# a statically linked library.

OBJFILES_NONSHARED     := $(patsubst %.o,%.nonshared.o,$(OBJFILES))
INIT_OBJFILE_NONSHARED := $(patsubst %.o,%.nonshared.o,$(INIT_OBJFILE))


$(INIT_OBJFILE_NONSHARED): $(INIT_SRCFILE)
	$(CC) $(CFLAGS_INIT) -c $< -o $@

$(OBJDIR)/%.nonshared.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

$(OBJDIR)/%.nonshared.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

$(SODIR)/$(LIBNAME).a: $(INIT_OBJFILE_NONSHARED) $(OBJFILES_NONSHARED)
	$(AR) $(ARFLAGS) $(SODIR)/$(LIBNAME).a $^

.PHONY: install_static
install_static: install_shared
	$(INSTALL_DATA) -t $(DESTDIR)$(libdir) $(SODIR)/$(LIBNAME).a
