aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: d3a7999c3d96a75e375e8ad9bdb58d51dcfdfc7e (plain)
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
include config.mk
CC = diet -Os clang
LD = diet clang

OBJ = sinit.o
BIN = sinit
CFLAGS = -Oz -flto -fno-asynchronous-unwind-tables -fno-unwind-tables -ffunction-sections -fdata-sections
LDFLAGS = -flto -O2 -static -Wl,--gc-sections -Wl,--strip-all -Wl,-z,norelro -fno-asynchronous-unwind-tables -Wl,--build-id=none

all: $(BIN) poweroff reboot

reboot: reboot.o
	$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LDLIBS)
	strip -R .comment -R .jcr -R .eh_data -R .note -R .eh_frame $@

poweroff: poweroff.o
	$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LDLIBS)
	strip -R .comment -R .jcr -R .eh_data -R .note -R .eh_frame $@

$(BIN): $(OBJ)
	$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LDLIBS)
	strip -R .comment -R .jcr -R .eh_data -R .note -R .eh_frame $@

$(OBJ): config.h

install: all
	mkdir -p $(DESTDIR)$(PREFIX)/bin
	cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin
	mkdir -p $(DESTDIR)$(MANPREFIX)/man8
	sed "s/VERSION/$(VERSION)/g" < $(BIN).8 > $(DESTDIR)$(MANPREFIX)/man8/$(BIN).8

uninstall:
	rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN)
	rm -f $(DESTDIR)$(MANPREFIX)/man8/$(BIN).8

dist: clean
	mkdir -p sinit-$(VERSION)
	cp LICENSE Makefile README config.def.h config.mk sinit.8 sinit.c sinit-$(VERSION)
	tar -cf sinit-$(VERSION).tar sinit-$(VERSION)
	gzip sinit-$(VERSION).tar
	rm -rf sinit-$(VERSION)

clean:
	rm -f $(BIN) $(OBJ) sinit-$(VERSION).tar.gz

.SUFFIXES: .def.h

.def.h.h:
	cp $< $@

.PHONY:
	all install uninstall dist clean