-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
106 lines (82 loc) · 2.84 KB
/
makefile
File metadata and controls
106 lines (82 loc) · 2.84 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
CFLAGS ?= -Wall -Werror -Wextra -g -s -w
LDFLAGS ?=
CC ?= gcc
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
DESTDIR ?=
IMAGE = suex-builder
BUILDDIR ?= ./build
PROGS := suex sush usrx uarch
AUTH_PROGS := suex sush
PROG ?= suex
SRCS := $(PROG).c
AUTH_DEPS := $(if $(filter $(PROG),$(AUTH_PROGS)),auth_common.o,)
ENV_COMMON_DEPS := $(if $(filter $(PROG),$(AUTH_PROGS)),env_common.h,)
archs = amd64 arm64
arch ?= $(shell arch)
.PHONY: build
build: builddir $(BUILDDIR)/$(PROG)
.PHONY: all
all: builddir
for prog in $(PROGS); do $(MAKE) clean && $(MAKE) PROG=$$prog; done
.PHONY: auth_common.o
auth_common.o: auth_common.c auth_common.h
$(CC) $(CFLAGS) -c auth_common.c
STATIC ?= -static
$(BUILDDIR)/$(PROG): $(SRCS) $(AUTH_DEPS) $(ENV_COMMON_DEPS)
$(CC) $(CFLAGS) -o $@ $(SRCS) $(AUTH_DEPS) $(STATIC) $(LDFLAGS)
strip -s $@
.PHONY: install
install: all
install -d $(DESTDIR)$(BINDIR)
install -m 4755 $(BUILDDIR)/suex $(DESTDIR)$(BINDIR)/suex
install -m 4755 $(BUILDDIR)/sush $(DESTDIR)$(BINDIR)/sush
install -m 755 $(BUILDDIR)/usrx $(DESTDIR)$(BINDIR)/usrx
install -m 755 $(BUILDDIR)/uarch $(DESTDIR)$(BINDIR)/uarch
.PHONY: builddir
builddir:
if [ ! -d $(BUILDDIR) ]; then mkdir -p $(BUILDDIR); fi
.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)$(BINDIR)/suex $(DESTDIR)$(BINDIR)/sush
rm -f $(DESTDIR)$(BINDIR)/usrx $(DESTDIR)$(BINDIR)/uarch
clean:
rm -f *.o *.c~
distclean: clean
rm -f $(addprefix $(BUILDDIR)/,$(PROGS)) $(addprefix $(BUILDDIR)/,$(addsuffix -static,$(PROGS)))
fmt:
docker run --rm -v "$$PWD":/src -w /src alpine:latest sh -c "apk add --no-cache indent && indent -linux $(SRCS) && indent -linux $(SRCS)"
fmt-all:
$(MAKE) fmt SRCS="*.c"
release-all:
$(MAKE) release
.PHONY: release
release: $(archs)
$(archs):
mkdir -p release
$(MAKE) build-docker arch=$@
export COPYFILE_DISABLE=true; \
for PROG in $(PROGS); do \
tar -czf ./release/$$PROG-linux-$@.tgz LICENSE -C ./build $$PROG; \
done
.PHONY: build-image
build-image:
docker build -t $(IMAGE):$(arch) --platform linux/$(arch) -f build.dockerfile .
build-docker: build-image
$(MAKE) distclean
docker run --rm -v "$$PWD":/src -w /src -e PROGS="$(PROGS)" \
--platform linux/$(arch) $(IMAGE):$(arch) make all
test-install-docker: build-image
$(MAKE) distclean
docker run --rm -v "$$PWD":/src -w /src -e BUILDDIR="/tmp/build" \
--platform linux/$(arch) $(IMAGE):$(arch) make install
build-test-image:
docker buildx build -t suex-test -f test.dockerfile --platform linux/$(arch) --load .
.PHONY: test-suex
test-suex: build-test-image
@set -e; \
c=$$(docker run --rm -d --platform linux/$(arch) suex-test sh -c "tail -f /dev/null"); \
trap "docker stop $$c >/dev/null" EXIT; \
tar -cf - makefile suex-test.sh auth_common.c auth_common.h env_common.h suex.c | docker exec -i $$c tar -xf - -C /test; \
docker exec $$c make build BUILDDIR=. STATIC=; \
docker exec $$c ./suex-test.sh