for backward compatibility, write a list of loaded modules to /tmp
[bootcd.git] / Makefile.needlessly_complicated
1 VERSION:="3.0"
2 FULL_VERSION_STRING:="PlanetLab BootCD $(VERSION)"
3 ROOT_PASSWD:='$1$IdEn2srw$/TfrjZSPUC1xP244YCuIi0'
4 CDRECORD_FLAGS:="-v -dao -blank=fast"
5
6 SYSLINUX:=sources/syslinux-2.11.tar.bz2
7 CD_IMAGE:=cd.iso
8 CD_ROOT:=cdroot
9 CD_PWD:=$(shell pwd)
10 BOOTCD_YUM_GROUP:=BootCD
11
12 INITRD_MOUNT:=rd
13 CD_ROOT_USR:=usr-cd
14 INITRD_SIZE:=64
15 INITRD:=$(CD_ROOT)/$(CD_ROOT_USR)/isolinux/initrd
16
17 CONF_FILES_DIR=conf_files
18
19 PRE_CONF_FILES=etc/fstab \
20                    etc/mtab \
21                    etc/rpm/macros
22
23 POST_CONF_FILES=etc/inittab \
24                 etc/init.d/pl_hwinit \
25                 etc/init.d/pl_sysinit \
26                 etc/modprobe.conf \
27                 etc/hosts
28
29 # directories in the cd root to move to /usr/relocated to reduce ramdisk size
30 RELOCATE_DIRS=$(CD_ROOT)/lib/tls \
31               $(CD_ROOT)/var/lib/rpm
32
33 RELOCATE_DEST_DIR=usr/relocated
34
35 CD_PRE_CONF_FILES:=$(patsubst %,$(CD_ROOT)/%,$(PRE_CONF_FILES))
36 CD_POST_CONF_FILES:=$(patsubst %,$(CD_ROOT)/%,$(POST_CONF_FILES))
37 CD_RELOCATED_DIRS:=$(patsubst %,$(CD_ROOT)/usr/relocated/%,$(RELOCATE_DIRS))
38
39 all: $(CD_IMAGE)
40
41
42 $(CD_IMAGE): $(CD_PRE_CONF_FILES) $(CD_POST_CONF_FILES) $(CD_ROOT)/.built $(CD_ROOT)/.config $(INITRD).gz $(CD_RELOCATED_DIRS)
43         @echo "building iso"
44         mkisofs -o $(CD_IMAGE) -R -allow-leading-dots -J -r \
45             -b isolinux/isolinux.bin -c isolinux/boot.cat \
46             -no-emul-boot -boot-load-size 4 -boot-info-table \
47             -V PlanetLab-3-0 $(CD_ROOT)/usr
48
49
50 $(CD_ROOT)/.built: $(PRE_YUM)
51         @echo "initialize rpm db"
52
53         mkdir -p $(CD_ROOT)/var/lib/rpm
54         rpm --root $(CD_PWD)/$(CD_ROOT) --initdb
55
56         @echo "install boot cd base rpms"
57         yum -c yum.conf --installroot=$(CD_PWD)/$(CD_ROOT) \
58             -y groupinstall $(BOOTCD_YUM_GROUP)
59
60         touch $(CD_ROOT)/.built
61
62 $(CD_RELOCATED_DIRS): $(CD_ROOT)/.built
63 $(CD_RELOCATED_DIRS): $(CD_ROOT)/$(RELOCATE_DEST_DIR)% : $(CD_ROOT)/%
64         @echo "relocate some large directories out of the root system"
65         mkdir -p $@
66         mv $< $@
67         ln -s $@ $<
68
69
70 $(CD_PRE_CONF_FILES): $(CD_ROOT)/% : $(CONF_FILES_DIR)/%
71         mkdir -p $(dir $@)
72         cp -a $< $@
73
74
75 $(CD_POST_CONF_FILES): $(CD_ROOT)/.built $(CD_ROOT)/etc/pl_pcitable
76
77 $(CD_POST_CONF_FILES): $(CD_ROOT)/% : $(CONF_FILES_DIR)/%
78         mkdir -p $(dir $@)
79         cp -a $< $@
80
81
82 $(CD_ROOT)/usr/isolinux/.built:
83         @echo "extracting syslinux, copying isolinux files to cd"
84
85         mkdir -p syslinux
86         mkdir -p $(CD_ROOT)/usr/isolinux/
87
88         tar -C syslinux -xjvf $(SYSLINUX)
89         find syslinux -name isolinux.bin -exec cp -f {} $(CD_ROOT)/usr/isolinux/ \;
90
91         cp -f $(CONF_FILES_DIR)/usr/isolinux/isolinux.cfg $(CD_ROOT)/usr/isolinux/
92         echo "$(FULL_VERSION_STRING)" > $(CD_ROOT)/usr/isolinux/message.txt
93
94         touch $(CD_ROOT)/usr/isolinux/.built
95
96
97 $(CD_ROOT)/etc/pl_pcitable:
98         scripts/rewrite-pcitable.py \
99             $(wildcard $(CD_ROOT)/lib/modules/*/modules.pcimap) \
100             $(CD_ROOT)/etc/pl_pcitable
101
102
103 $(INITRD).gz: $(CD_ROOT)/.built
104         (cd $(CD_ROOT) && mv usr $(CD_ROOT_USR))
105         mkdir $(CD_ROOT)/usr
106
107         dd if=/dev/zero of=$(INITRD) bs=1M count=$(INITRD_SIZE)
108         mkfs.ext2 -F -m 0 -i 1024 $(INITRD)
109
110         mkdir -p $(INITRD_MOUNT)
111         mount -o loop,rw $(INITRD) $(INITRD_MOUNT)
112         (cd $(CD_ROOT) && tar --exclude $(CD_ROOT_USR) -cf initrdcontents.tar *)
113         tar -C $(INITRD_MOUNT) -xf $(CD_ROOT)/initrdcontents.tar
114         umount $(INITRD_MOUNT)
115         rmdir $(INITRD_MOUNT)
116
117         gzip $(INITRD)
118
119         rm -f $(CD_ROOT)/initrdcontents.tar
120         rmdir $(CD_ROOT)/usr
121         (cd $(CD_ROOT) && mv $(CD_ROOT_USR) usr)
122
123
124 $(CD_ROOT)/.config: $(CD_ROOT)/.built $(CD_ROOT)/usr/isolinux/.built
125         @echo "removing unneccessary build files"
126         rm -rf $(wildcard $(CD_ROOT)/lib/modules/*/build/)
127
128         @echo "setting up non-ssh authentication"
129         mkdir -p $(CD_ROOT)/etc/samba
130         chroot $(CD_ROOT) /usr/sbin/authconfig --nostart --kickstart \
131             --enablemd5 --enableshadow
132
133         @echo "setting root password"
134         sed -i "s#root::#root:$(ROOT_PASSWD):#g" $(CD_ROOT)/etc/shadow
135
136         echo "$(FULL_VERSION_STRING)" > $(CD_ROOT)/usr/isolinux/pl_version
137         echo "$(FULL_VERSION_STRING)" > $(CD_ROOT)/pl_version
138
139
140         echo "moving kernel to isolinux directory"
141         mkdir -p $(CD_ROOT)/usr/isolinux/
142         mv -f $(wildcard $(CD_ROOT)/boot/vmlinuz-*) $(CD_ROOT)/usr/isolinux/kernel
143
144
145
146 cdr: $(CD_IMAGE)
147         cdrecord $(CDRECORD_FLAGS) -data $(CD_IMAGE)
148
149 clean:
150         rm -rf $(CD_ROOT)
151         rm -f $(CD_IMAGE)
152
153
154 .PHONY: all cdr clean