-
Notifications
You must be signed in to change notification settings - Fork 40
/
makefile
102 lines (77 loc) · 2.24 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Makefile for Wirepas Dbus Sink module
# Toolchain
CC := gcc
AS := as
LD := ld
AR := ar
# Paths, including trailing path separator
SOURCEPREFIX := source/
BUILDPREFIX := build/
# This example needs the mesh lib
MESH_LIB_FOLDER := c-mesh-api/lib/
MESH_LIB := $(MESH_LIB_FOLDER)build/mesh_api_lib.a
# General compiler flags
CFLAGS := -std=gnu99 -Wall -Werror `pkg-config --cflags libsystemd`
# Targets definition
MAIN_APP := sinkService
TARGET_APP := $(BUILDPREFIX)$(MAIN_APP)
# Add Api header (including logger files)
CFLAGS += -I$(MESH_LIB_FOLDER)api
# Add pthtread lib as needed by Mesh Lib
LDFLAGS += -pthread
# Add Reentrant flag as using pthread
CFLAGS += -D_REENTRANT
# Add systemd lib as needed for sd-bus
LDFLAGS += `pkg-config --libs libsystemd`
# Add current directory for headers
CFLAGS += -I$(SOURCEPREFIX)
# Specific sources for this application
SOURCES := $(SOURCEPREFIX)main.c
SOURCES += $(SOURCEPREFIX)config.c
SOURCES += $(SOURCEPREFIX)data.c
SOURCES += $(SOURCEPREFIX)otap.c
OBJECTS := $(patsubst $(SOURCEPREFIX)%, \
$(BUILDPREFIX)%, \
$(SOURCES:.c=.o))
# Functions
# Also create the target directory if it does not exist
define COMPILE
echo " CC $(2)"
mkdir -p $(dir $(1))
$(CC) $(CFLAGS) -c -o $(1) $(2)
endef
define LINK
echo " Linking $(1)"
$(CC) $(CFLAGS) -o $(1) $(2) $(MESH_LIB) $(LDFLAGS)
endef
define CLEAN
echo " Cleaning up"
$(RM) -r $(BUILDPREFIX)
make -C $(MESH_LIB_FOLDER) clean
endef
# Target rules
# Use dependency files automatically generated by GCC.
# First collect all C source files
AUTODEPS := $(patsubst $(SOURCEPREFIX)%.c, $(BUILDPREFIX)%.d, $(SOURCES))
ifeq ($(V),1)
# "V=1" on command line, print commands.
else
# Default, do not print commands.
.SILENT:
endif
.PHONY: all
all: app
app: $(TARGET_APP) $(MESH_LIB)
.PHONY: clean
clean:
$(call CLEAN)
$(MESH_LIB_FOLDER):
$(error c-mesh-api library is required and is managed as a git submodule.\
Please run "git submodule update --init")
.PHONY: $(MESH_LIB)
$(MESH_LIB): $(MESH_LIB_FOLDER)
make -C $(MESH_LIB_FOLDER)
$(BUILDPREFIX)%.o: $(SOURCEPREFIX)%.c $(MESH_LIB_FOLDER)
$(call COMPILE,$@,$<)
$(BUILDPREFIX)$(MAIN_APP): $(OBJECTS) $(MESH_LIB)
$(call LINK,$@,$^)