-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-core.mk
More file actions
189 lines (133 loc) · 3.39 KB
/
make-core.mk
File metadata and controls
189 lines (133 loc) · 3.39 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#
# Generic make helpers
#
# Copyright (c) 2006-2019 Alexei A. Smekalkine <ikle@ikle.ru>
#
# SPDX-License-Identifier: BSD-2-Clause
#
#
# target paths
#
PREFIX ?= /usr
INCDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib/$(MULTIARCH)
BINDIR ?= $(PREFIX)/bin
SBINDIR ?= $(PREFIX)/sbin
DESTDIR ?=
#
# target dependencies
#
ifneq ($(DEPENDS),)
CFLAGS += `pkg-config $(DEPENDS) --cflags`
LDFLAGS += `pkg-config $(DEPENDS) --libs`
endif
#
# guarantie default target
#
.PHONY: all clean install
all:
#
# source and target file filters
#
HEADERS = $(wildcard include/*.h include/*/*.h)
SOURCES = $(filter-out %-test.c %-tool.c %-service.c, $(wildcard *.c))
OBJECTS = $(patsubst %.c,%.o, $(SOURCES))
TESTS = $(patsubst %-test.c,%-test, $(wildcard *-test.c))
TOOLS = $(patsubst %-tool.c,%, $(wildcard *-tool.c))
SERVICES = $(patsubst %-service.c,%, $(wildcard *-service.c))
#
# rules to manage static libraries
#
%.a:
$(AR) -rc $@ $^
.PHONY: install-headers
.PHONY: build-static clean-static install-static
ifdef LIBNAME
AFILE = lib$(LIBNAME).a
LIBVER ?= 0
LIBREV ?= 0.1
PCFILE = $(LIBNAME).pc
install: install-headers
INCROOT = $(INCDIR)/$(LIBNAME)-$(LIBVER)
define install-header
install-headers:: ; install -Dm 644 $(1) $(DESTDIR)$(INCROOT)/$(1:include/%=%)
endef
$(foreach F,$(HEADERS),$(eval $(call install-header,$(F))))
all: build-static
install: install-static
$(OBJECTS): CFLAGS += -I$(CURDIR)/include
$(PCFILE):
@test -n "$(DESCRIPTION)" && echo "Description: $(DESCRIPTION)" > $@
@test -n "$(URL)" && echo "URL: $(URL)" >> $@
@echo "Name: $(LIBNAME)" >> $@
@echo "Version: $(LIBVER).$(LIBREV)" >> $@
ifneq ($(DEPENDS),)
@echo "Requires: $(DEPENDS)" >> $@
endif
@echo "Libs: -l$(LIBNAME)" >> $@
@echo "Cflags: -I$(INCROOT)" >> $@
install-static: $(AFILE) $(PCFILE)
install -d $(DESTDIR)$(LIBDIR)/pkgconfig
install -m 644 $(AFILE) $(DESTDIR)$(LIBDIR)
install -m 644 $(PCFILE) $(DESTDIR)$(LIBDIR)/pkgconfig
else # not defined LIBNAME
AFILE = bundle.a
endif # LIBNAME
$(AFILE): $(OBJECTS)
build-static: $(AFILE)
clean: clean-static
clean-static:
$(RM) $(AFILE) $(OBJECTS) $(PCFILE)
#
# rules to manage tests (ordinary programs)
#
ifneq ($(TESTS),)
%-test: %-test.c
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
.PHONY: build-test clean-tests
all: build-tests
clean: clean-tests
$(TESTS): CFLAGS += -I$(CURDIR)/include
$(TESTS): $(AFILE)
build-tests: $(TESTS)
clean-tests:
$(RM) $(TESTS)
endif # build TESTS
#
# rules to manage tools (ordinary programs)
#
ifneq ($(TOOLS),)
%: %-tool.c
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
.PHONY: build-tools clean-tools install-tools
all: build-tools
clean: clean-tools
install: install-tools
$(TOOLS): CFLAGS += -I$(CURDIR)/include
$(TOOLS): $(AFILE)
build-tools: $(TOOLS)
clean-tools:
$(RM) $(TOOLS)
install-tools: build-tools
install -d $(DESTDIR)$(BINDIR)
install -s -m 755 $(TOOLS) $(DESTDIR)$(BINDIR)
endif # build TOOLS
#
# rules to manage services (system programs)
#
ifneq ($(SERVICES),)
%: %-service.c
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
.PHONY: build-services clean-services install-services
all: build-services
clean: clean-services
install: install-services
$(SERVICES): CFLAGS += -I$(CURDIR)/include
$(SERVICES): $(AFILE)
build-services: $(SERVICES)
clean-services:
$(RM) $(SERVICES)
install-services: build-services
install -d $(DESTDIR)$(SBINDIR)
install -s -m 755 $(SERVICES) $(DESTDIR)$(SBINDIR)
endif # build SERVICES