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