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%.c: ;
42%.h: ;
43
44$(COMPONENT_OUTPUT_DIR)/${LIBFILE}: ${OBJS} ${A_LIBS}
45	@rm $(COMPONENT_OUTPUT_DIR)/${LIBFILE} &> /dev/null ; true
46	@${AR} -cr  $(COMPONENT_OUTPUT_DIR)/${LIBFILE} ${OBJS} ${A_LIBS}
47
48$(COMPONENT_OUTPUT_DIR)/${LIBFILE32}: ${OBJS32} ${A_LIBS32}
49	@rm $(COMPONENT_OUTPUT_DIR)/${LIBFILE32} &> /dev/null ; true
50	@${AR} -cr $(COMPONENT_OUTPUT_DIR)/${LIBFILE32} ${OBJS32} ${A_LIBS32}
51
52$(COMPONENT_OUTPUT_DIR)/${LIBFILE_DYN}: ${OBJS} $(A_LIBS)
53	@${CC} -o $@ -fPIC -shared $^ ${LDFLAGS} ${SO_LIBS} ${A_LIBS} ${COVERAGE}
54
55${A_LIBS32}:;
56	$(error Required library ($@) not found. Run top level make to build all dependencies in order)
57
58${A_LIBS}:;
59	$(error Required library ($@) not found. Run top level make to build all dependencies in order)
60
61clean:
62	@echo "Deleting intermediate compilation results"
63	@find $(COMPONENT_OUTPUT_DIR) -name "*.a" -or -name "*.o" -or -name "*.so" -or -name "*.d" | xargs rm
64	@rm $(COMPONENT_OUTPUT_DIR)/${LIBFILE} $(COMPONENT_OUTPUT_DIR)/${LIBFILE32} $(COMPONENT_OUTPUT_DIR)/${LIBFILE_DYN} &> /dev/null ; true
65
66clean_coverage:
67	@find $(COMPONENT_OUTPUT_DIR) -name "*.gcda" -or -name "*.gcno" | xargs rm -f ; true
68
69clean_all: clean clean_coverage
70
71${BSIM_LIBS_DIR}/${VERSION_FILE}: version
72	@if [[ -f "$<" ]]; then\
73	  cp $< $@; \
74	else \
75	  echo "unknown" > $@; \
76	fi
77
78${BSIM_LIBS_DIR}/% : $(COMPONENT_OUTPUT_DIR)/%
79	@cp $< $@
80
81install: ${BSIM_LIBS_DIR}/${LIBFILE_DYN} ${BSIM_LIBS_DIR}/${LIBFILE} ${BSIM_LIBS_DIR}/${LIBFILE32} ${BSIM_LIBS_DIR}/${VERSION_FILE}
82
83Makefile: ;
84