1# Copyright 2018 Oticon A/S
2# SPDX-License-Identifier: Apache-2.0
3
4OBJS=$(abspath $(addprefix $(COMPONENT_OUTPUT_DIR)/,${SRCS:.c=.o}))
5LIBFILE_DYN=${LIB_NAME}.so
6VERSION_FILE:=${LIB_NAME}.version
7
8all: install
9
10DEPENDFILES:=$(addsuffix .d,$(basename ${OBJS}))
11
12-include ${DEPENDFILES}
13
14always_run_this_target:
15#phony target to trigger the rerun of the make of each library, but ensure that make checks if the library was regenerated (so it doesnt relink the binary if it wasnt)
16# we could do like in the root Makefile, and just go first over all the libraries makefiles we may need instead, but this is slighly more efficient (although more messy)
17
18.PHONY: all install compile lib clean clean_all ${DEPENDFILES} always_run_this_target version
19
20compile: $(COMPONENT_OUTPUT_DIR)/${LIBFILE_DYN}
21
22lib: compile
23
24$(COMPONENT_OUTPUT_DIR)/%.o: %.c
25	@if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
26	@${CC} ${CPPFLAGS} ${CFLAGS} ${COVERAGE} -c $< -o $@
27
28$(COMPONENT_OUTPUT_DIR)/${LIBFILE_DYN} : ${OBJS} $(A_LIBS)
29	@${CC} -o $@ -fPIC -shared $^ ${LDFLAGS} ${SO_LIBS} ${A_LIBS} ${COVERAGE}
30
31%.a:;
32	$(error Required library ($@) not found. Run top level make to build all dependencies in order)
33
34clean:
35	@echo "Deleting intermediate compilation results"
36	@find $(COMPONENT_OUTPUT_DIR) -name "*.a" -or -name "*.o" -or -name "*.so" -or -name "*.d" | xargs rm
37	@rm $(COMPONENT_OUTPUT_DIR)/${LIBFILE_DYN} &> /dev/null ; true
38
39clean_coverage:
40	@find $(COMPONENT_OUTPUT_DIR) -name "*.gcda" -or -name "*.gcno" | xargs rm -f ; true
41
42clean_all: clean clean_coverage
43
44${BSIM_LIBS_DIR}/${VERSION_FILE}: version
45	@if [[ -f "$<" ]]; then\
46	  cp $< $@; \
47	else \
48	  echo "unknown" > $@; \
49	fi
50
51${BSIM_LIBS_DIR}/% : $(COMPONENT_OUTPUT_DIR)/%
52	@cp $< $@
53
54install: ${BSIM_LIBS_DIR}/${LIBFILE_DYN} ${BSIM_LIBS_DIR}/${VERSION_FILE}
55
56Makefile: ;
57