-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
617 lines (550 loc) · 20.7 KB
/
Copy pathMakefile
File metadata and controls
617 lines (550 loc) · 20.7 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
VERSION = 0.15.1
NAME := ice
O ?= build/$(TRIPLE)
DIST ?= dist
STAGE ?= stage
CFLAGS ?= -Wall -Werror -std=c99 -pedantic
LDFLAGS ?=
# Tests live per-command under cmd/<path>/t/, with shared TAP helpers
# (tap.sh, tap.h) and any cross-cutting tests in the top-level t/.
# Covers both top-level commands (cmd/<name>/t/) and namespace
# subcommands (cmd/<ns>/<name>/t/). Override T on the command line
# to run a subset, e.g.
# make test T=cmd/completion/t
# make test T=cmd/idf/size/t
# make test T=cmd/completion/t/0001-completion.t
T ?= $(wildcard cmd/*/t) $(wildcard cmd/*/*/t) t
# Run prove with one worker per core by default; override PFLAGS to
# re-serialize (PFLAGS=-j1) or to add verbosity (PFLAGS="-j4 -v").
PFLAGS ?= -j$(JOBS)
T_OUT ?= t_out
# Default parallel build on the host running make. Try nproc (Linux
# and MSYS2), fall back to sysctl (macOS), finally 1 if neither works.
# Override with `make JOBS=1` to debug a parallel-build failure, or
# pass `-j N` on the command line -- the last -j wins, so user flags
# always take precedence over MAKEFLAGS.
JOBS ?= $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)
MAKEFLAGS += -j$(JOBS)
# Target triple. Prefer the CC name's prefix (e.g. aarch64-w64-mingw32-clang
# → aarch64-w64-mingw32) over $(CC) -dumpmachine, because llvm-mingw's clang
# reports its triple as "aarch64-w64-windows-gnu" which autotools config.sub
# rejects. Unprefixed compilers (gcc/clang/cc) fall back to -dumpmachine.
CC_PREFIX := $(patsubst %-,%,$(subst $(lastword $(subst -, ,$(CC))),,$(CC)))
ifneq ($(CC_PREFIX),)
TRIPLE := $(CC_PREFIX)
CROSS_COMPILE := $(CC_PREFIX)-
else
TRIPLE := $(shell $(CC) -dumpmachine 2>/dev/null)
CROSS_COMPILE :=
endif
WINDRES := $(CROSS_COMPILE)windres
BUILD_CFLAGS = $(CFLAGS) $(CFLAGS_APPEND)
BUILD_LDFLAGS = $(LDFLAGS) $(LDFLAGS_APPEND)
BUILD_DEFINES = -DVERSION=\"$(VERSION)\" -DICE_PLATFORM_OS=\"$(S)\" -DICE_PLATFORM_ARCH=\"$(ARCH)\"
# Project root on the include search path so sources under cmd/<name>/
# and platform/<os>/ can #include "ice.h" directly instead of reaching
# up with "../../ice.h". Quoted-form includes still find sibling
# headers (e.g. cmd/idf/ldgen/lf.h) in the source file's own directory.
BUILD_CFLAGS += -I$(CURDIR)
# SANITIZE=1: enable AddressSanitizer for the whole build (libice,
# ice, and the test binaries via SAN_FLAGS below). Incompatible with
# STATIC=1 because libasan is dynamically linked; release builds
# shouldn't ship it anyway. Append `-fsanitize=undefined` to SAN_FLAGS
# manually if you also have libubsan available -- not all distros
# ship it by default (Fedora packages it separately, for example).
ifdef SANITIZE
ifdef STATIC
$(error SANITIZE=1 is incompatible with STATIC=1; sanitizers need a dynamic libasan runtime)
endif
SAN_FLAGS := -fsanitize=address -fno-omit-frame-pointer
BUILD_CFLAGS += $(SAN_FLAGS)
BUILD_LDFLAGS += $(SAN_FLAGS)
endif
COMPILER_VERSION := $(shell $(CC) --version)
CONTEXT := "$(COMPILER_VERSION) $(CFLAGS) $(LDFLAGS)"
ifneq ($(findstring x86_64,$(TRIPLE)),)
ARCH := amd64
else ifneq ($(findstring i686,$(TRIPLE)),)
ARCH := i386
else ifneq ($(findstring aarch64,$(TRIPLE)),)
ARCH := arm64
else ifneq ($(findstring arm64,$(TRIPLE)),)
ARCH := arm64
else ifneq ($(findstring arm,$(TRIPLE)),)
# Check for Hard Float vs Soft Float
ifneq ($(findstring gnueabihf,$(TRIPLE))$(findstring musleabihf,$(TRIPLE)),)
ARCH := armhf
else
ARCH := armel
endif
else ifneq ($(findstring powerpc64le,$(TRIPLE)),)
ARCH := ppc64el
else ifneq ($(findstring s390x,$(TRIPLE)),)
ARCH := s390x
else ifneq ($(findstring riscv64,$(TRIPLE)),)
ARCH := riscv64
endif
ifneq ($(findstring mingw,$(TRIPLE)),)
S ?= win
else ifneq ($(findstring windows,$(TRIPLE)),)
S ?= win
else ifneq ($(findstring apple,$(TRIPLE)),)
S ?= macos
else
S ?= linux
endif
# Cross-compilation: target triple != build machine triple.
ifneq ($(TRIPLE),$(shell cc -dumpmachine 2>/dev/null))
CROSS := 1
endif
PKG_NAME := $(NAME)-$(VERSION)-$(S)-$(ARCH)$(PKG_SUFFIX)
# LIB_SRCS go into libice.a -- everything reusable except the program
# entry point. Tests link against the archive directly so they don't
# need to know which .c files implement which transitive dependency.
# Static-archive linking also drops dead code from the final binary
# (today: ar.c, elf.c, http.c have no live callers from main()).
LIB_SRCS := \
ar.c \
base64.c \
ca_certs.c \
cmake.c \
cmakecache.c \
cmd/__complete/__complete.c \
cmd/build/build.c \
cmd/clean/clean.c \
cmd/completion/completion.c \
cmd/config/config.c \
cmd/coredump/coredump.c \
cmd/debug/debug.c \
cmd/docs/docs.c \
cmd/docs/getting-started/getting-started.c \
cmd/flash/flash.c \
cmd/help/help.c \
cmd/idf/idf.c \
cmd/idf/component/component.c \
cmd/idf/component/cmake_out.c \
cmd/idf/component/fetch.c \
cmd/idf/component/manifest.c \
cmd/idf/component/lockfile.c \
cmd/idf/component/registry.c \
cmd/idf/component/rules.c \
cmd/idf/component/solve.c \
cmd/idf/component/prepare/prepare.c \
cmd/idf/component/inject/inject.c \
cmd/idf/configdep/configdep.c \
cmd/idf/coredump/coredump.c \
cmd/idf/coredump/loader.c \
cmd/idf/coredump/synth.c \
cmd/idf/crt-bundle/crt-bundle.c \
cmd/idf/hints/hints.c \
cmd/idf/kconfgen/kc_confread.c \
cmd/idf/kconfgen/kc_eval.c \
cmd/idf/kconfgen/kc_io.c \
cmd/idf/kconfgen/kc_lex.c \
cmd/idf/kconfgen/kc_parse.c \
cmd/idf/kconfgen/kc_rename.c \
cmd/idf/kconfgen/kc_report.c \
cmd/idf/kconfgen/kconfgen.c \
cmd/idf/ldgen/gen.c \
cmd/idf/ldgen/ldgen.c \
cmd/idf/ldgen/lf.c \
cmd/idf/ldgen/sinfo.c \
cmd/idf/menuconfig/menuconfig.c \
cmd/idf/partition-table/partition-table.c \
cmd/idf/partition-table/check-bootloader/check-bootloader.c \
cmd/idf/partition-table/check-partition/check-partition.c \
cmd/idf/partition-table/decode/decode.c \
cmd/idf/partition-table/empty/empty.c \
cmd/idf/partition-table/subtypes-header/subtypes-header.c \
cmd/idf/size/mem.c \
cmd/idf/size/memmap.c \
cmd/idf/size/memmap_ops.c \
cmd/idf/size/views.c \
cmd/idf/size/format_table.c \
cmd/idf/size/format_csv.c \
cmd/idf/size/format_json.c \
cmd/idf/size/format_tree.c \
cmd/idf/size/format_dot.c \
cmd/idf/size/size.c \
cmd/image/image.c \
cmd/image/create/create.c \
cmd/image/info/info.c \
cmd/image/merge/merge.c \
cmd/init/init.c \
cmd/log/log.c \
cmd/menuconfig/menuconfig.c \
cmd/qemu/qemu.c \
cmd/repo/repo.c \
cmd/repo/clone/clone.c \
cmd/repo/pull/pull.c \
cmd/repo/list/list.c \
cmd/repo/checkout/checkout.c \
cmd/repo/info/info.c \
cmd/size/size.c \
cmd/size/files/files.c \
cmd/size/components/components.c \
cmd/size/symbols/symbols.c \
cmd/size/deps/deps.c \
cmd/status/status.c \
cmd/target/target.c \
cmd/monitor/monitor.c \
cmd/target/openocd/openocd.c \
cmd/target/flash/flash.c \
cmd/target/list/list.c \
cmd/target/monitor/monitor.c \
cmd/target/partition/partition.c \
cmd/target/partition/info/info.c \
cmd/target/partition/read/read.c \
cmd/target/partition/write/write.c \
cmd/target/partition/erase/erase.c \
cmd/target/qemu/qemu.c \
cmd/tools/tools.c \
cmd/tools/install/install.c \
cmd/tools/list/list.c \
cmd/tools/info/info.c \
cmd/update/update.c \
config.c \
csv.c \
fs.c \
ice.c \
json.c \
map.c \
md5.c \
term.c \
elf.c \
error.c \
help.c \
pager.c \
options.c \
partition_table.c \
binary.c \
elf2image.c \
progress.c \
pubgrub.c \
sbuf.c \
semver.c \
serial.c \
slip.c \
smap.c \
svec.c \
http.c \
git.c \
gzip.c \
xz.c \
reader.c \
tar.c \
toolenv.c \
tui.c \
vt100.c \
vendor/cacert/ca_bundle.c \
vendor/sha256/sha256.c \
chip.c \
color_rules.c \
esf_port.c \
hints.c \
yaml.c \
zip.c
# MAIN_SRCS provide the program entry point. Excluded from libice.a
# so that unit tests (and any future external libice consumer) can
# supply their own main().
MAIN_SRCS := main.c
SRCS := $(MAIN_SRCS) $(LIB_SRCS)
# STATIC=1: use vendored deps from deps/ (fully self-contained).
# On Linux this requires a musl CC (enforced below); glibc -static is
# a lie because NSS dlopen()s the target system's libc at runtime, so
# the binary isn't actually portable. Fetch a musl toolchain via
# Makefile.toolchain. Windows uses MinGW, macOS uses system clang.
ifdef STATIC
DEPS_PREFIX := $(CURDIR)/deps/install/$(TRIPLE)
DEPS_STAMP := $(DEPS_PREFIX)/.stamp
BUILD_CFLAGS += -isystem $(DEPS_PREFIX)/include -DCURL_STATICLIB
LIBS := -L$(DEPS_PREFIX)/lib -L$(DEPS_PREFIX)/lib64 -lcurl -lmbedtls -lmbedx509 -lmbedcrypto -ltfpsacrypto -lz -llzma
ifeq ($(S),linux)
ifeq ($(findstring musl,$(TRIPLE)),)
$(error STATIC=1 on Linux requires a musl toolchain (got CC='$(CC)', triple='$(TRIPLE)'). Fetch one: eval "$$(make -f Makefile.toolchain linux-<arch>)")
endif
# -no-pie: avoid static-PIE. The default GCC specs add -pie to executables,
# so -static alone would yield a static-PIE binary that self-relocates at
# startup via libc. musl's minimal self-relocator only processes
# R_*_RELATIVE; symbolic relocs (R_RISCV_64 / R_X86_64_64) the linker emits
# for some absolute-pointer slots in static initialisers (e.g. &global in
# an option table) get silently skipped, leaving NULL at runtime — a NULL
# deref that bit us on riscv64. Plain -no-pie produces an ET_EXEC with no
# runtime relocations and sidesteps the whole class.
LDFLAGS += -static -no-pie
endif
ifeq ($(S),macos)
LIBS += -framework CoreFoundation -framework SystemConfiguration
endif
ifeq ($(S),win)
LDFLAGS += -static
endif
else
# Dev mode: link against system libraries. -lz isn't strictly
# required (libcurl pulls it in transitively for HTTP gzip), but
# being explicit removes a fragile assumption and matches what we
# actually call directly. liblzma is needed for .tar.xz extraction;
# the system package is xz-devel (Fedora) / liblzma-dev (Debian).
LIBS := -lcurl -lz -llzma
endif
# Vendor libraries (always built from source, unlike deps which are
# only needed for static/release builds).
VENDOR_PREFIX := $(CURDIR)/vendor/install/$(TRIPLE)
VENDOR_STAMP := $(VENDOR_PREFIX)/.stamp
BUILD_CFLAGS += -isystem $(VENDOR_PREFIX)/include
# PCRE2_STATIC tells the pcre2 headers to drop the default
# __declspec(dllimport) decoration on function prototypes, which on
# Windows would otherwise demand a DLL even though we link the
# static libpcre2-8.a from vendor/. Harmless on Linux / macOS.
BUILD_CFLAGS += -DPCRE2_STATIC
LIBS += -L$(VENDOR_PREFIX)/lib -lflasher -lpcre2-8
ifeq ($(S), win)
# wmain.c provides the Windows wide-char entry point that calls into
# main() from ice.c, so it lives with MAIN_SRCS. io / process / wconv
# are reusable platform glue and go into libice.a.
LIB_SRCS += platform/win/io.c platform/win/process.c platform/win/serial.c platform/win/term.c platform/win/wconv.c platform/win/fnmatch.c
MAIN_SRCS += platform/win/wmain.c
SRCS := $(MAIN_SRCS) $(LIB_SRCS)
CFLAGS += -municode
LDFLAGS += -municode
LIBS += -lws2_32 -lbcrypt -lwinhttp -liphlpapi
BINARY := $(O)/$(NAME).exe
else
LIB_SRCS += platform/posix/io.c platform/posix/process.c platform/posix/serial.c platform/posix/term.c platform/posix/fnmatch.c
SRCS := $(MAIN_SRCS) $(LIB_SRCS)
BINARY := $(O)/$(NAME)
# glibc hides POSIX symbols (readlink, popen, …) under -std=c99
# unless _POSIX_C_SOURCE is defined. macOS exposes everything by
# default; defining _POSIX_C_SOURCE there would *restrict* visibility
# and hide Darwin extensions like B115200 in <termios.h>.
ifeq ($(S),linux)
CFLAGS_APPEND += -D_POSIX_C_SOURCE=200112L
endif
endif
LIB_OBJS := $(patsubst %.c,$(O)/%.o,$(LIB_SRCS))
MAIN_OBJS := $(patsubst %.c,$(O)/%.o,$(MAIN_SRCS))
ifeq ($(S), win)
# manifest.o is per-binary metadata, not part of the library.
MAIN_OBJS += $(O)/manifest.o
endif
OBJS := $(MAIN_OBJS) $(LIB_OBJS)
LIBICE := $(O)/libice.a
LIBICE_ABS := $(abspath $(LIBICE))
# Default to the cross-compile prefix when present; users can still
# override on the command line (e.g. `make AR=clang-ar`).
AR := $(CROSS_COMPILE)ar
OBJDIRS := $(sort $(patsubst %/,%,$(dir $(OBJS))))
all: $(BINARY)
define MANIFEST_XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
type="win32"
name="$(NAME)"
version="$(VERSION).0"
processorArchitecture="*"
/>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<ws2:longPathAware>true</ws2:longPathAware>
</windowsSettings>
</application>
</assembly>
endef
$(O)/manifest.xml: Makefile | $(O)
$(file >$@,$(MANIFEST_XML))
$(O)/manifest.rc: $(O)/manifest.xml
$(file >$@,1 24 "$<")
$(O)/manifest.o: $(O)/manifest.rc $(O)/context
$(WINDRES) --input=$< --output=$@
$(OBJDIRS):
mkdir -p $@
$(DIST):
mkdir -p $@
$(O)/context: FORCE | $(O)
@echo $(CONTEXT) | md5sum | cmp -s - $@ || echo $(CONTEXT) | md5sum > $@
$(O)/%.o: %.c Makefile $(O)/context | $(OBJDIRS)
$(CC) $(BUILD_DEFINES) $(BUILD_CFLAGS) -MD -MP -o $@ -c $<
ifdef STATIC
$(OBJS): | $(DEPS_STAMP)
$(DEPS_STAMP):
$(MAKE) -C deps PREFIX=$(DEPS_PREFIX) S=$(S) TRIPLE=$(TRIPLE) $(if $(CROSS),CROSS=1)
endif
$(OBJS): | $(VENDOR_STAMP)
$(VENDOR_STAMP):
$(MAKE) -C vendor PREFIX=$(VENDOR_PREFIX) S=$(S) TRIPLE=$(TRIPLE) $(if $(CROSS),CROSS=1)
$(LIBICE): $(LIB_OBJS)
$(AR) rcs $@ $^
# Link MAIN_OBJS first so ld picks up only the libice.a members the
# binary actually references; unused modules (e.g. http.o today) drop
# out of the binary along with anything they would have pulled from
# system libs.
$(BINARY): $(MAIN_OBJS) $(LIBICE) | $(O)
$(CC) -o $@ $(MAIN_OBJS) $(LIBICE) $(BUILD_LDFLAGS) $(LIBS)
.PHONY: clean mrproper deps vendor update-ca \
libice \
targz-pkg \
tarxz-pkg \
zip-pkg \
clang-format \
clang-tidy \
lint-platform \
test \
cscope \
ctags \
tags \
help
# Convenience target: build only the static library.
libice: $(LIBICE)
FORCE:
targz-pkg: $(DIST)/$(PKG_NAME).tar.gz
tarxz-pkg: $(DIST)/$(PKG_NAME).tar.xz
zip-pkg: $(DIST)/$(PKG_NAME).zip
$(STAGE): $(BINARY)
@rm -rf $@
@install -d $@/$(NAME)-$(VERSION)/bin
@install $(BINARY) $(STAGE)/$(NAME)-$(VERSION)/bin
@touch $@
$(DIST)/$(PKG_NAME).tar.gz: $(STAGE) | $(DIST)
cd $(STAGE) && tar -cvzf $(abspath $@) $(NAME)-$(VERSION)
$(DIST)/$(PKG_NAME).tar.xz: $(STAGE) | $(DIST)
cd $(STAGE) && tar -cvJf $(abspath $@) $(NAME)-$(VERSION)
$(DIST)/$(PKG_NAME).zip: $(STAGE) | $(DIST)
cd $(STAGE) && zip -r $(abspath $@) $(NAME)-$(VERSION)
deps:
$(MAKE) -C deps PREFIX=$(CURDIR)/deps/install/$(TRIPLE) S=$(S) TRIPLE=$(TRIPLE) $(if $(CROSS),CROSS=1)
vendor:
$(MAKE) -C vendor PREFIX=$(CURDIR)/vendor/install/$(TRIPLE) S=$(S) TRIPLE=$(TRIPLE) $(if $(CROSS),CROSS=1)
# Refresh the bundled Mozilla CA store from upstream (curl.se) and
# regenerate vendor/cacert/ca_bundle.c. Run this before cutting a
# release; commit both vendor/cacert/cacert.pem and the regenerated
# ca_bundle.c together. See vendor/cacert/README.md for cadence.
update-ca:
$(MAKE) -C vendor/cacert refresh
clean:
rm -rf $(O) $(DIST) $(STAGE) $(T_OUT)
mrproper: clean
rm -rf $(CURDIR)/build
$(MAKE) -C deps mrproper
$(MAKE) -C vendor mrproper
# Routed through pre-commit so everyone uses the version pinned in
# .pre-commit-config.yaml. Raw clang-format output drifts between
# releases even with the same .clang-format config.
clang-format:
pre-commit run clang-format --all-files
# Lint checks and WarningsAsErrors: see .clang-tidy in this directory.
clang-tidy: | $(VENDOR_STAMP)
clang-tidy \
--extra-arg="--target=$(TRIPLE)" \
$(SRCS) \
-- \
$(BUILD_DEFINES) \
$(BUILD_CFLAGS)
# Enforce the platform-abstraction rules from CONTRIBUTING.md against
# ice-authored code (repo root + cmd/). Three grep checks, all of
# which must be empty:
# - no #ifdef _WIN32/__linux__/__APPLE__/... (OS-conditional code
# belongs in platform/ behind platform.h);
# - no POSIX-only <dirent.h>/<sys/select.h>/... includes
# (platform.h should expose the primitive);
# - no popen()/pclose() calls (use struct process with pipe_in +
# use_shell instead).
# platform/ and platform.h itself are the only places allowed to have
# the above; vendor/ and deps/ are third-party imports and excluded
# from the scan entirely. Wired into pre-commit via
# .pre-commit-config.yaml so it runs locally and in CI.
LINT_PLATFORM_FILES = $(shell \
find . -maxdepth 1 -type f \( -name '*.c' -o -name '*.h' \) \
-not -name 'platform.h' ; \
find cmd -type f \( -name '*.c' -o -name '*.h' \))
lint-platform:
@rc=0 ; \
if grep -HnE \
'^[[:space:]]*#[[:space:]]*(if|ifdef|ifndef|elif)[[:space:]].*(_WIN32|__linux__|__APPLE__|__MACH__|__unix__|__CYGWIN__|__MINGW32__|_MSC_VER)([^A-Za-z0-9_]|$$)' \
$(LINT_PLATFORM_FILES) ; then \
echo >&2 "error: platform #ifdef outside platform/ -- see CONTRIBUTING.md 'Platform abstraction'" ; \
rc=1 ; \
fi ; \
if grep -HnE \
'^[[:space:]]*#[[:space:]]*include[[:space:]]*<(dirent|sys/select|sys/wait|sys/ioctl|sys/mman|termios|netinet/in|arpa/inet|netdb|poll|pwd|grp|syslog)\.h>' \
$(LINT_PLATFORM_FILES) ; then \
echo >&2 "error: POSIX-only include outside platform/ -- see CONTRIBUTING.md 'Platform abstraction'" ; \
rc=1 ; \
fi ; \
if grep -HnE '(^|[^A-Za-z0-9_])(popen|pclose)[[:space:]]*\(' \
$(LINT_PLATFORM_FILES) ; then \
echo >&2 "error: popen/pclose -- use struct process with pipe_in + use_shell" ; \
rc=1 ; \
fi ; \
if [ $$rc -eq 0 ]; then echo "lint-platform: OK" ; fi ; \
exit $$rc
BINARY_ABS := $(abspath $(BINARY))
# ASan defaults to running LeakSanitizer at process exit; for a CLI
# tool that legitimately keeps state in static storage until exit
# (alias-expansion tokens, the global config, ...) this would flag
# benign "leaks" on every run. Disable it by default and rely on
# the still-active checks (use-after-free, overflow, double-free,
# stack/heap buffer over/underflow) -- a strict leak audit is a
# follow-up that needs explicit atexit cleanup of those globals.
SAN_TEST_ENV := LSAN_OPTIONS=detect_leaks=0
test: $(BINARY) $(LIBICE)
T_OUT=$(T_OUT) BINARY=$(BINARY_ABS) LIBICE=$(LIBICE_ABS) \
LINK_LIBS="$(LIBS)" \
SAN_FLAGS="$(SAN_FLAGS)" $(if $(SANITIZE),$(SAN_TEST_ENV)) \
CC=${CC} S=$(S) prove $(PFLAGS) $(T)
TAG_DIRS := cmd platform
cscope:
{ find . -maxdepth 1 -name "*.[ch]"; find $(TAG_DIRS) -name "*.[ch]"; } >cscope.files
cscope -b
ctags:
{ find . -maxdepth 1 -name "*.[ch]"; find $(TAG_DIRS) -name "*.[ch]"; } | ctags -L -
tags: cscope ctags
help:
@echo 'build variables:'
@echo ' CC - compiler to use e.g. gcc-i686-linux-gnu or x86_64-w64-mingw32-gcc (default: $(CC))'
@echo ' O - output build directory (default: $(O))'
@echo ' S - operating system win/posix/macos (default: autodetected)'
@echo ' CFLAGS - compiler options (default: $(CFLAGS))'
@echo ' LDFLAGS - linker options (default: $(LDFLAGS))'
@echo ' CFLAGS_APPEND - additional compiler options to append after CFLAGS'
@echo ' LDFLAGS_APPEND - additional linker options to append after LDFLAGS'
@echo ' JOBS - parallel build jobs; `-j N` on the command line wins (default: $(JOBS))'
@echo ' SANITIZE - SANITIZE=1 enables AddressSanitizer (incompatible with STATIC=1)'
@echo ''
@echo 'test variables:'
@echo ' T - test path(s) passed to prove; override to run a subset,'
@echo ' e.g. T=cmd/completion/t or T=cmd/completion/t/0001.t'
@echo ' (default: $(T))'
@echo ' T_OUT - directory with test artifacts (default: $(T_OUT))'
@echo ' PFLAGS - prove options for running tests through TAP harness (default: $(PFLAGS))'
@echo ''
@echo 'test targets:'
@echo ' test - run all tests (default: $(PFLAGS))'
@echo ' libice - build the static library (linked by ice and tests)'
@echo ''
@echo 'distribution variables:'
@echo ' DIST - output directory for distribution files (default: $(DIST))'
@echo ' STAGE - stagging directory for distribution preparation (default: $(STAGE))'
@echo ''
@echo 'distribution targets:'
@echo ' targz-pkg - create tar.gz archive for distribution'
@echo ' tarxz-pkg - create tar.xz archive for distribution'
@echo ' zip-pkg - create zip archive for distribution'
@echo ''
@echo 'lint targets:'
@echo ' clang-format - run clang formatter'
@echo ' clang-tidy - run clang tidy'
@echo ' lint-platform - enforce CONTRIBUTING.md platform-abstraction rules'
@echo ''
@echo 'dependency targets:'
@echo ' deps - build external deps (zlib, mbedTLS, curl, xz)'
@echo ' vendor - build vendor libs (esp-serial-flasher, pcre2)'
@echo ' update-ca - refresh bundled Mozilla CA store (vendor/cacert/)'
@echo ''
@echo 'misc targets:'
@echo ' clean - remove: $(O) $(DIST) $(STAGE) $(T_OUT)'
@echo ' mrproper - clean + remove vendored deps'
@echo ' cscope - generate cscope tags'
@echo ' ctags - generate ctags'
@echo ' tags - alias for cscope and tags'
-include $(O)/*.d