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