makefile 2.83 KB
Newer Older
Daniel Abrecht's avatar
Daniel Abrecht committed
1 2 3
# Copyright (c) 2018 Daniel Abrecht
# SPDX-License-Identifier: AGPL-3.0-or-later

4 5
PREFIX = /usr

6 7 8 9 10 11 12 13 14 15 16
OPTIONS += -ffunction-sections -fdata-sections

ifdef DEBUG
CC_OPTS += -Og -g
endif

ifndef LENIENT
CC_OPTS += -Werror
endif

CC_OPTS += -ffunction-sections -fdata-sections
17
CC_OPTS += -fvisibility=hidden -I include
18
CC_OPTS += -std=c99 -Wall -Wextra -pedantic
19
CC_OPTS += -D_DEFAULT_SOURCE
Daniel Abrecht's avatar
Daniel Abrecht committed
20
CC_OPTS += -DTYM_LOG_PROJECT='"console-keyboard-multiplexer"'
21
LD_OPTS += -Wl,-gc-sections
Daniel Abrecht's avatar
Daniel Abrecht committed
22

23
LIBS += -lttymultiplex
Daniel Abrecht's avatar
Daniel Abrecht committed
24

25
OBJECTS += build/console-keyboard-multiplexer.o
26
OBJECTS += build/man/console-keyboard-multiplexer.1.res.o
27

Daniel Abrecht's avatar
Daniel Abrecht committed
28 29 30 31 32 33 34
all: bin/console-keyboard-multiplexer

%/.dir:
	mkdir -p "$(dir $@)"
	touch "$@"

build/%.o: src/%.c | build/.dir
35
	$(CC) -c -o "$@" $(CC_OPTS) $(CFLAGS) "$<"
Daniel Abrecht's avatar
Daniel Abrecht committed
36

37
build/%.res.o: % | build/%/.dir
38
	file="$^"; \
39
	id="res_$$(printf '%s' "$$file"|sed 's/[^a-zA-Z0-9]/_/g'|sed 's/.*/\L\0/')"; \
40 41 42 43 44 45 46
	( \
	  echo '#include <stddef.h>'; \
	  printf "extern const char %s[];" "$$id"; \
	  printf "extern const size_t %s_size;" "$$id"; \
	  printf "const char %s[] = {" "$$id"; \
	  cat "$$file" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/.*/  "\0\\n"/'; \
	  printf "};\nconst size_t %s_size = sizeof(%s)-1;\n" "$$id" "$$id"; \
47
	) | $(CC) -c -o "$@" -x c - $(CC_OPTS) $(CFLAGS)
48 49

bin/console-keyboard-multiplexer: $(OBJECTS)
50
	mkdir -p bin
51
	$(CC) -o "$@" $(LD_OPTS) $^ $(LIBS) $(LDFLAGS)
Daniel Abrecht's avatar
Daniel Abrecht committed
52

53
install: install-bin install-config install-initramfs-tools-config
54 55 56
	@true

install-bin:
57 58
	mkdir -p "$(DESTDIR)$(PREFIX)/bin/"
	cp bin/console-keyboard-multiplexer "$(DESTDIR)$(PREFIX)/bin/console-keyboard-multiplexer"
59
	cp script/ckmvt "$(DESTDIR)$(PREFIX)/bin/ckmvt"
60 61 62

install-config:
	mkdir -p "$(DESTDIR)$(PREFIX)/lib/systemd/system/getty@.service.d/"
63
	cp config/console-keyboard-multiplexer-systemd-override.conf "$(DESTDIR)$(PREFIX)/lib/systemd/system/getty@.service.d/console-keyboard-multiplexer.conf"
64

65 66 67 68 69 70 71 72 73 74 75 76 77
install-initramfs-tools-config:
	for file in \
	  hooks/consolation \
	  scripts/init-bottom/consolation \
	  scripts/init-premount/consolation \
	  hooks/console-keyboard-multiplexer \
	  scripts/init-bottom/console-keyboard-multiplexer \
	  scripts/init-premount/console-keyboard-multiplexer; \
	do \
	  mkdir -p "$$(dirname "$(DESTDIR)/usr/share/initramfs-tools/$$file")"; \
	  cp -r "config/initramfs-tools/$$file" "$(DESTDIR)/usr/share/initramfs-tools/$$file"; \
	done

78
uninstall:
79
	rm -f "$(DESTDIR)$(PREFIX)/bin/console-keyboard-multiplexer"
80
	rm -f "$(DESTDIR)$(PREFIX)/lib/systemd/system/getty@.service.d/console-keyboard-multiplexer.conf"
81 82 83 84 85 86 87 88 89 90
	for file in \
	  hooks/consolation \
	  scripts/init-bottom/consolation \
	  scripts/init-premount/consolation \
	  hooks/console-keyboard-multiplexer \
	  scripts/init-bottom/console-keyboard-multiplexer \
	  scripts/init-premount/console-keyboard-multiplexer; \
	do \
	  rm "$(DESTDIR)/usr/share/initramfs-tools/$$file"; \
	done
91

Daniel Abrecht's avatar
Daniel Abrecht committed
92 93
clean:
	rm -rf bin/ build/