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