Makefile 2.2 KB

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