summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 3870e2190870b4f98990e294547edefd9a2d2ed8 (plain) (blame)
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
CONTENT=/sbin/lvm /sbin/vgchange /sbin/vgscan /bin/busybox init /dev/console etc/kmap-de /sbin/fsck.ext4
CONTENT-LINKS=bin/sh
CONTENT-MARKER=$(addprefix .root-done/,$(CONTENT))
DATE=$(shell date +%F_%T)

all:	initramfs

initramfs:	initramfs.cpio
	@echo "Compressing archive"
	@gzip > initramfs < initramfs.cpio

initramfs.cpio:	.root-done/.complete
	@echo "Generating cpio archive"
	@cd root ;\
	find . | cpio -H newc --quiet -o > ../initramfs.cpio

.root-done/.complete:	$(CONTENT-MARKER) .root-done/.links
	@touch .root-done/.complete

$(CONTENT-MARKER): .root-done/%: %
	@echo "Installing $*"
	@if ldd $* > /dev/null 2>&1 ; then \
		ldd $* | cut -d" " -f 3 | while read i ; do \
			if [ -n "$$i" ]; then \
				mkdir -p $$(dirname $$i) ;\
				cp --parents $$i root/ ;\
				echo -e "\tCopy library: $$i" ;\
			fi ;\
		done ;\
		\
		ldd $* | grep -v "=>" | cut -f1 -d" " | while read i ; do \
			if [ -n "$$i" ]; then \
				mkdir -p $$(dirname $$i) ;\
				cp --parents $$i root/ ;\
				echo -e "\tCopy library: $$i" ;\
			fi ;\
		done #;\
	fi

	@mkdir -p $(shell dirname $*)
	@cp -a --parents $* root/

	@mkdir -p $(dir .root-done/$*)
	@touch .root-done/$*
	@echo

.root-done/.links:	Makefile
	@for i in $(CONTENT-LINKS) ; do \
		mkdir -p $$(dirname $$i) ;\
		cp -a --parents $$i root/ ;\
	done

	@touch .root-done/.static

$(CONTENT-MARKER): Makefile

clean:
	${RM} initramfs initramfs.cpio
	${RM} -r root/*
	${RM} -r .root-done/

install:
	if [ ! -d "/boot/grub" ]; then \
		mount /boot ;\
	fi

	if [ -r /boot/initramfs ]; then \
		mv /boot/initramfs /boot/initramfs-$(DATE) ;\
	fi
	cp initramfs /boot/initramfs