Makefile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. # * http://www.apache.org/licenses/LICENSE-2.0
  10. # * Unless required by applicable law or agreed to in writing,
  11. # software distributed under the License is distributed on an
  12. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. # KIND, either express or implied. See the License for the
  14. # specific language governing permissions and limitations
  15. # under the License.
  16. #
  17. # Makefile
  18. PROJ_ROOT = ../../../..
  19. ### ===== Toolchain =====
  20. CROSS_COMPILE ?=
  21. CC = ccache $(CROSS_COMPILE)gcc
  22. CPP = ccache $(CROSS_COMPILE)g++
  23. LD = $(CROSS_COMPILE)gcc
  24. AR = $(CROSS_COMPILE)ar
  25. ### ===== Compiler Flags =====
  26. INCLUDES = \
  27. -I. \
  28. -I$(PROJ_ROOT)/nimble/include \
  29. -I$(PROJ_ROOT)/porting/npl/linux/include \
  30. -I$(PROJ_ROOT)/porting/npl/linux/src \
  31. -I$(PROJ_ROOT)/porting/nimble/include \
  32. $(NULL)
  33. DEFINES =
  34. CFLAGS = \
  35. $(INCLUDES) $(DEFINES) \
  36. -g \
  37. -D_GNU_SOURCE \
  38. $(NULL)
  39. LIBS = -lrt -lpthread -lstdc++
  40. LDFLAGS =
  41. ### ===== Sources =====
  42. OSAL_PATH = $(PROJ_ROOT)/porting/npl/linux/src
  43. SRCS = $(shell find $(OSAL_PATH) -maxdepth 1 -name '*.c')
  44. SRCS += $(shell find $(OSAL_PATH) -maxdepth 1 -name '*.cc')
  45. SRCS += $(PROJ_ROOT)/porting/nimble/src/os_mempool.c
  46. OBJS = $(patsubst %.c, %.o,$(filter %.c, $(SRCS)))
  47. OBJS += $(patsubst %.cc,%.o,$(filter %.cc, $(SRCS)))
  48. TEST_SRCS = $(shell find . -maxdepth 1 -name '*.c')
  49. TEST_SRCS += $(shell find . -maxdepth 1 -name '*.cc')
  50. TEST_OBJS = $(patsubst %.c, %.o,$(filter %.c, $(SRCS)))
  51. TEST_OBJS += $(patsubst %.cc,%.o,$(filter %.cc, $(SRCS)))
  52. ### ===== Rules =====
  53. all: depend \
  54. test_npl_task.exe \
  55. test_npl_callout.exe \
  56. test_npl_eventq.exe \
  57. test_npl_sem.exe \
  58. $(NULL)
  59. test_npl_task.exe: test_npl_task.o $(OBJS)
  60. $(LD) -o $@ $^ $(LDFLAGS) $(LIBS)
  61. test_npl_eventq.exe: test_npl_eventq.o $(OBJS)
  62. $(LD) -o $@ $^ $(LDFLAGS) $(LIBS)
  63. test_npl_callout.exe: test_npl_callout.o $(OBJS)
  64. $(LD) -o $@ $^ $(LDFLAGS) $(LIBS)
  65. test_npl_sem.exe: test_npl_sem.o $(OBJS)
  66. $(LD) -o $@ $^ $(LDFLAGS) $(LIBS)
  67. test: all
  68. ./test_npl_task.exe
  69. ./test_npl_callout.exe
  70. ./test_npl_eventq.exe
  71. ./test_npl_sem.exe
  72. show_objs:
  73. @echo $(OBJS)
  74. ### ===== Clean =====
  75. clean:
  76. @echo "Cleaning artifacts."
  77. rm *~ .depend $(OBJS) *.o *.exe
  78. ### ===== Dependencies =====
  79. ### Rebuild if headers change
  80. depend: .depend
  81. .depend: $(SRCS) $(TEST_SRCS)
  82. @echo "Building dependencies."
  83. rm -f ./.depend
  84. $(CC) $(CFLAGS) -MM $^ > ./.depend;
  85. include .depend
  86. ### Generic rules based on extension
  87. %.o: %.c
  88. $(CC) -c $(CFLAGS) $< -o $@
  89. %.o: %.cc
  90. $(CPP) -c $(CFLAGS) $< -o $@