xref: /nrf52832-nimble/packages/NimBLE-latest/porting/npl/linux/test/Makefile (revision 042d53a763ad75cb1465103098bb88c245d95138)
1# Makefile
2
3PROJ_ROOT = ../../../..
4
5### ===== Toolchain =====
6
7CROSS_COMPILE ?=
8CC  = ccache $(CROSS_COMPILE)gcc
9CPP = ccache $(CROSS_COMPILE)g++
10LD  = $(CROSS_COMPILE)gcc
11AR  = $(CROSS_COMPILE)ar
12
13### ===== Compiler Flags =====
14
15INCLUDES = \
16    -I.    \
17    -I$(PROJ_ROOT)/nimble/include             \
18    -I$(PROJ_ROOT)/porting/npl/linux/include  \
19    -I$(PROJ_ROOT)/porting/npl/linux/src      \
20    -I$(PROJ_ROOT)/porting/nimble/include     \
21    $(NULL)
22
23DEFINES =
24
25CFLAGS =                    \
26    $(INCLUDES) $(DEFINES)  \
27    -g                      \
28    -D_GNU_SOURCE           \
29    $(NULL)
30
31LIBS = -lrt -lpthread -lstdc++
32
33LDFLAGS =
34
35### ===== Sources =====
36
37OSAL_PATH = $(PROJ_ROOT)/porting/npl/linux/src
38
39SRCS  = $(shell find $(OSAL_PATH) -maxdepth 1 -name '*.c')
40SRCS += $(shell find $(OSAL_PATH) -maxdepth 1 -name '*.cc')
41SRCS += $(PROJ_ROOT)/porting/nimble/src/os_mempool.c
42
43OBJS  = $(patsubst %.c, %.o,$(filter %.c,  $(SRCS)))
44OBJS += $(patsubst %.cc,%.o,$(filter %.cc, $(SRCS)))
45
46TEST_SRCS  = $(shell find . -maxdepth 1 -name '*.c')
47TEST_SRCS += $(shell find . -maxdepth 1 -name '*.cc')
48
49TEST_OBJS  = $(patsubst %.c, %.o,$(filter %.c,  $(SRCS)))
50TEST_OBJS += $(patsubst %.cc,%.o,$(filter %.cc, $(SRCS)))
51
52### ===== Rules =====
53
54all: depend                   \
55     test_npl_task.exe        \
56     test_npl_callout.exe     \
57     test_npl_eventq.exe      \
58     test_npl_sem.exe         \
59     $(NULL)
60
61test_npl_task.exe: test_npl_task.o $(OBJS)
62	$(LD) -o $@ $^ $(LDFLAGS) $(LIBS)
63
64test_npl_eventq.exe: test_npl_eventq.o $(OBJS)
65	$(LD) -o $@ $^ $(LDFLAGS) $(LIBS)
66
67test_npl_callout.exe: test_npl_callout.o $(OBJS)
68	$(LD) -o $@ $^ $(LDFLAGS) $(LIBS)
69
70test_npl_sem.exe: test_npl_sem.o $(OBJS)
71	$(LD) -o $@ $^ $(LDFLAGS) $(LIBS)
72
73test: all
74	./test_npl_task.exe
75	./test_npl_callout.exe
76	./test_npl_eventq.exe
77	./test_npl_sem.exe
78
79show_objs:
80	@echo $(OBJS)
81
82### ===== Clean =====
83clean:
84	@echo "Cleaning artifacts."
85	rm *~ .depend $(OBJS) *.o *.exe
86
87### ===== Dependencies =====
88### Rebuild if headers change
89depend: .depend
90
91.depend: $(SRCS) $(TEST_SRCS)
92	@echo "Building dependencies."
93	rm -f ./.depend
94	$(CC) $(CFLAGS) -MM $^ > ./.depend;
95
96include .depend
97
98### Generic rules based on extension
99%.o: %.c
100	$(CC) -c $(CFLAGS) $< -o $@
101
102%.o: %.cc
103	$(CPP) -c $(CFLAGS) $< -o $@
104