summaryrefslogtreecommitdiff
path: root/Makefile
blob: ce5803e47475c97b61397d62b06265545bcc2360 (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
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
prefix?=/usr/local

cc_files=wait_for_files samizdat-pinentry
cpp_files=dynmenu

compiled_programs=${cc_files} ${cpp_files}

CC=gcc -std=gnu99
CFLAGS=-Os

SUBMODULES = fsmgr kiki openssh

all: samizdat-paths.sh ${compiled_programs} ${SUBMODULES}

dynmenu: src/dynmenu.cpp
	$(CXX) $(CFLAGS) $< -o $@ -lcurses
samizdat-pinentry: src/samizdat-pinentry.c
	$(CC) $(CFLAGS)  $< -o $@ -lcurses
wait_for_files: src/wait_for_files.c
	$(CC) $(CFLAGS)  $< -o $@

bin_programs=$(addprefix src/, xorriso-usb.sh btrfs-functions.sh btrfs-receive-root.sh btrfs-send-root.sh var.sh grub-efi.sh keygen.sh initrd.sh qemu.sh dnsmasq-dhcp-script.sh samizdat-password-agent samizdat-gpg-agent publish-ip.sh selfstrap samizdat-daily-snapshot-root samizdat-diff-root) samizdat-paths.sh ${cc_files} ${btrfs_utils}

btrfs_utils=$(addprefix src/btrfs-utils/, btarfs btrfs-shrink with-btrfs-seed)

initrd_files:=$(wildcard src/initrd/*) dynmenu samizdat-pinentry wait_for_files
initramfs_conf_files:=$(wildcard initramfs-tools/*)

isolinux_files:=$(wildcard isolinux/*)

clean:
	rm -f samizdat-paths.sh ${compiled_programs}

.PHONY: all clean
samizdat-paths.sh: src/samizdat-paths.in
	@sed -e "s?PREFIX?$(prefix)?g" $< > $@
include samizdat-paths.sh

install-configuration:
ifndef instdir
	$(error "You must specify instdir, for safety.")
else
	install  -p  -m0644  -DT  conf/dnsmasq.conf              ${instdir}/etc/dnsmasq.conf
	install  -p  -m0644  -DT  conf/interfaces.d_eth0         ${instdir}/etc/network/interfaces.d/eth0
	install  -p  -m0644  -DT  conf/network_if-up.d_samizdat  ${instdir}/etc/network/if-up.d/samizdat
	install  -p  -m0644  -DT  conf/postfix_main.cf           ${instdir}/etc/postfix/main.cf
	install  -p  -m0644  -DT  conf/torrc                     ${instdir}/etc/tor/torrc
	install  -p  -m0644  -DT  conf/nbd-server                ${instdir}/etc/nbd-server/conf.d/samizdat.conf
	ln -sf /var/cache/kiki/config/tor/hostname  ${instdir}/etc/mailname
	ln -sf /var/cache/kiki/config/tor/hostname  ${instdir}/etc/hostname
endif

include user.mk

.PHONY: submodule $(SUBMODULES)
$(SUBMODULES):
	[ -e $@/Makefile ] || git submodule update --init
	$(MAKE) -C $@ $(cmd)

install-submodules: cmd=install
install-submodules: $(SUBMODULES)

.PHONY: rootfs
rootfs:
	[ -e install-submodules-stamp ] || make install-submodules-stamp
	[ -e install-stamp ] || sudo make install-stamp
	$(MAKE) -C rootfs
	sudo mkdir -p /srv/nbd
	sudo ln -sf "$$PWD"/rootfs/samizdat.btrfs /srv/nbd/samizdat.btrfs

define get_kernel_version
egrep '^ii  linux-image-(amd64|686)' rootfs/_build/samizdat.pkgs.txt  | \
	(read _ pkg ver _; apt-cache show $$pkg=$$ver) | \
	grep Depends | \
	(read _ a; echo $${a#linux-image-})
endef

boot: rootfs
	sudo kernel_version=$$($(get_kernel_version)) qemu.sh

reuse_child := $(shell 2>/dev/null read child < reused-child && echo --reuse_child=$$child; true)

isotest: install
	initrd.sh
	xorriso-usb.sh $(reuse_child) --bootloader --out samizdat.iso
	USE_ISO=y SLOW_BOOT=y qemu.sh

isotest-nonet: install
	initrd.sh
	xorriso-usb.sh $(reuse_child) --out samizdat-nonet.iso
	USE_ISO=y SLOW_BOOT=y NO_NET=y qemu.sh samizdat-nonet.iso

.PHONY: install
install:
	[ -e install-submodules-stamp ] || make install-submodules-stamp
	sudo make install-stamp

install-submodules-stamp: install-submodules
	touch $@

install-bin-programs: ${bin_programs}
	install -p ${bin_programs} ${instdir}${samizdat_bindir}

install-stamp: install-bin-programs samizdat-paths.sh ${compiled_programs}
	mkdir -p ${instdir}${samizdat_initrd_files_dir}
	mkdir -p ${instdir}${samizdat_child_dir}
	mkdir -p ${instdir}${samizdat_grub_efi_dir}
	mkdir -p ${instdir}${samizdat_initramfs_conf_dir}
	mkdir -p ${instdir}${samizdat_isolinux_dir}
	mkdir -p ${instdir}${samizdat_linux_dir}
	cp -r ${initrd_files} ${instdir}${samizdat_initrd_files_dir}
	cp -r ${initramfs_conf_files} ${instdir}${samizdat_initramfs_conf_dir}
	cp -r ${isolinux_files} ${instdir}${samizdat_isolinux_dir}
	touch $@