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%.c: ;
29%.h: ;
30
31$(COMPONENT_OUTPUT_DIR)/${LIBFILE_DYN} : ${OBJS} $(A_LIBS)
32	@${CC} -o $@ -fPIC -shared $^ ${LDFLAGS} ${SO_LIBS} ${A_LIBS} ${COVERAGE}
33
34%.a:;
35	$(error Required library ($@) not found. Run top level make to build all dependencies in order)
36
37clean:
38	@echo "Deleting intermediate compilation results"
39	@find $(COMPONENT_OUTPUT_DIR) -name "*.a" -or -name "*.o" -or -name "*.so" -or -name "*.d" | xargs rm
40	@rm $(COMPONENT_OUTPUT_DIR)/${LIBFILE_DYN} &> /dev/null ; true
41
42clean_coverage:
43	@find $(COMPONENT_OUTPUT_DIR) -name "*.gcda" -or -name "*.gcno" | xargs rm -f ; true
44
45clean_all: clean clean_coverage
46
47${BSIM_LIBS_DIR}/${VERSION_FILE}: version
48	@if [[ -f "$<" ]]; then\
49	  cp $< $@; \
50	else \
51	  echo "unknown" > $@; \
52	fi
53
54${BSIM_LIBS_DIR}/% : $(COMPONENT_OUTPUT_DIR)/%
55	@cp $< $@
56
57install: ${BSIM_LIBS_DIR}/${LIBFILE_DYN} ${BSIM_LIBS_DIR}/${VERSION_FILE}
58
59Makefile: ;
60