1# Copyright 2018 Oticon A/S
2# SPDX-License-Identifier: Apache-2.0
3
4OBJS=$(abspath $(addprefix $(COMPONENT_OUTPUT_DIR)/,${SRCS:.c=.o}))
5LIBFILE=${LIB_NAME}.a
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#setting the dependencies as phony targets will actually speed up things.. (otherwise make will check if there is implicit rules to remake them)
20
21compile: $(COMPONENT_OUTPUT_DIR)/${LIBFILE}
22
23$(COMPONENT_OUTPUT_DIR):
24	@mkdir -p $(COMPONENT_OUTPUT_DIR)
25
26$(COMPONENT_OUTPUT_DIR)/%.o: %.c
27	@if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
28	@${CC} ${CPPFLAGS} ${CFLAGS} ${COVERAGE} -c $< -o $@
29
30%.c: ;
31%.h: ;
32
33$(COMPONENT_OUTPUT_DIR)/${LIBFILE}: $(COMPONENT_OUTPUT_DIR) ${OBJS} ${A_LIBS}
34	@rm $(COMPONENT_OUTPUT_DIR)/${LIBFILE} &> /dev/null ; true
35	@${AR} -cr $(COMPONENT_OUTPUT_DIR)/${LIBFILE} ${OBJS} ${A_LIBS}
36
37lib :compile
38
39${A_LIBS}:;
40	$(error Required library ($@) not found. Run top level make to build all dependencies in order)
41
42clean:
43	@echo "Deleting intermediate compilation results"
44	@find $(COMPONENT_OUTPUT_DIR) -name "*.o" -or -name "*.so" -or -name "*.a" -or -name "*.d" | xargs rm -f
45	@rm $(COMPONENT_OUTPUT_DIR)/${LIBFILE} &> /dev/null ; true
46
47clean_coverage:
48	@find $(COMPONENT_OUTPUT_DIR) -name "*.gcda" -or -name "*.gcno" | xargs rm -f ; true
49
50clean_all: clean clean_coverage
51
52${BSIM_LIBS_DIR}/${VERSION_FILE}: version
53	@if [[ -f "$<" ]]; then\
54	  cp $< $@; \
55	else \
56	  echo "unknown" > $@; \
57	fi
58
59${BSIM_LIBS_DIR}/% : $(COMPONENT_OUTPUT_DIR)/%
60	@cp $< $@
61
62install: ${BSIM_LIBS_DIR}/${LIBFILE} ${BSIM_LIBS_DIR}/${VERSION_FILE}
63
64Makefile: ;