| 1 | # |
| 2 | # initramfs/Makefile |
| 3 | # |
| 4 | |
| 5 | TOPDIR = $(shell pwd) |
| 6 | |
| 7 | include $(TOPDIR)/../toolchain/vars.mk |
| 8 | |
| 9 | TARGET = arm-crux-linux-gnueabihf |
| 10 | |
| 11 | WORK = $(TOPDIR)/work |
| 12 | CLFS = $(TOPDIR)/../toolchain/clfs |
| 13 | CROSSTOOLS = $(TOPDIR)/../toolchain/crosstools |
| 14 | |
| 15 | BUSYBOX_VERSION = 1.21.1 |
| 16 | BUSYBOX_SOURCE = http://busybox.net/downloads/busybox-$(BUSYBOX_VERSION).tar.bz2 |
| 17 | |
| 18 | E2FSPROGS_VERSION = 1.42.5 |
| 19 | E2FSPROGS_SOURCE = http://downloads.sourceforge.net/project/e2fsprogs/e2fsprogs/v$(E2FSPROGS_VERSION)/e2fsprogs-$(E2FSPROGS_VERSION).tar.gz |
| 20 | |
| 21 | DIALOG_VERSION = 1.2-20130523 |
| 22 | DIALOG_SOURCE = ftp://invisible-island.net/dialog/dialog-$(DIALOG_VERSION).tgz |
| 23 | |
| 24 | NCURSES_HEADER = $(CLFS)/usr/include/ncurses.h |
| 25 | |
| 26 | .PHONY: all check-root busybox e2fsprogs dialog gen_init_cpio initramfs clean distclean |
| 27 | |
| 28 | all: initramfs |
| 29 | |
| 30 | clean: busybox-clean e2fsprogs-clean dialog-clean gen_init_cpio-clean initramfs-clean |
| 31 | |
| 32 | distclean: busybox-distclean e2fsprogs-distclean dialog-distclean gen_init_cpio-distclean initramfs-distclean |
| 33 | |
| 34 | check-root: |
| 35 | @if [ "$$UID" != "0" ]; then \ |
| 36 | echo "You need to be root to do this."; \ |
| 37 | echo "Now you should run 'make initramfs' as root to finish compilation or 'sudo make initramfs'."; \ |
| 38 | exit 1; \ |
| 39 | fi |
| 40 | |
| 41 | $(WORK)/busybox-$(BUSYBOX_VERSION).tar.bz2: |
| 42 | wget -P $(WORK) -c $(BUSYBOX_SOURCE) |
| 43 | |
| 44 | $(WORK)/busybox-$(BUSYBOX_VERSION): $(WORK)/busybox-$(BUSYBOX_VERSION).tar.bz2 $(TOPDIR)/busybox-$(BUSYBOX_VERSION).config $(WORK)/fix-resource_header.patch |
| 45 | tar -C $(WORK) -xvjf $(WORK)/busybox-$(BUSYBOX_VERSION).tar.bz2 |
| 46 | cd $(WORK)/busybox-$(BUSYBOX_VERSION) && \ |
| 47 | patch -p1 -i $(WORK)/fix-resource_header.patch |
| 48 | cp -v $(TOPDIR)/busybox-$(BUSYBOX_VERSION).config $(WORK)/busybox-$(BUSYBOX_VERSION)/.config |
| 49 | touch $(WORK)/busybox-$(BUSYBOX_VERSION) |
| 50 | |
| 51 | $(WORK)/busybox-$(BUSYBOX_VERSION)/_install/bin/busybox: $(WORK)/busybox-$(BUSYBOX_VERSION) |
| 52 | export PATH=$(CROSSTOOLS)/bin:$$PATH && \ |
| 53 | export LD_LIBRARY_PATH=$(CROSSTOOLS)/lib:$$LD_LIBRARY_PATH && \ |
| 54 | make -j1 -C $(WORK)/busybox-$(BUSYBOX_VERSION) ARCH=arm CROSS_COMPILE=$(TARGET)- install && \ |
| 55 | install -D -m 0755 $(WORK)/busybox-$(BUSYBOX_VERSION)/examples/udhcp/simple.script $(WORK)/busybox-$(BUSYBOX_VERSION)/_install/usr/share/udhcpc/default.script && \ |
| 56 | $(TARGET)-strip $(WORK)/busybox-$(BUSYBOX_VERSION)/_install/bin/busybox && \ |
| 57 | touch $(WORK)/busybox-$(BUSYBOX_VERSION)/_install/bin/busybox |
| 58 | |
| 59 | busybox: $(WORK)/busybox-$(BUSYBOX_VERSION)/_install/bin/busybox |
| 60 | |
| 61 | busybox-clean: |
| 62 | rm -vrf $(WORK)/busybox-$(BUSYBOX_VERSION) |
| 63 | |
| 64 | busybox-distclean: busybox-clean |
| 65 | rm -vf $(WORK)/busybox-$(BUSYBOX_VERSION).tar.bz2 |
| 66 | |
| 67 | $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION).tar.gz: |
| 68 | wget -P $(WORK) -c $(E2FSPROGS_SOURCE) |
| 69 | |
| 70 | $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION): $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION).tar.gz |
| 71 | tar -C $(WORK) -xvzf $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION).tar.gz |
| 72 | touch $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION) |
| 73 | |
| 74 | $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION)/misc/mke2fs: $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION) |
| 75 | export PATH=$(CROSSTOOLS)/bin:$$PATH && \ |
| 76 | export LD_LIBRARY_PATH=$(CROSSTOOLS)/lib:$$LD_LIBRARY_PATH && \ |
| 77 | cd $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION) && \ |
| 78 | ./configure --build=$(BUILD) --host=$(TARGET) --prefix=/usr --with-root-prefix= \ |
| 79 | --mandir=/usr/man --disable-symlink-install --disable-nls --disable-compression \ |
| 80 | --disable-htree --disable-elf-shlibs --disable-bsd-shlibs --disable-profile \ |
| 81 | --disable-checker --disable-jbd-debug --disable-blkid-debug --disable-testio-debug \ |
| 82 | --enable-libuuid --enable-libblkid --disable-libquota --disable-debugfs --disable-imager \ |
| 83 | --disable-resizer --disable-defrag --disable-fsck --disable-e2initrd-helper \ |
| 84 | --disable-tls --disable-rpath && \ |
| 85 | make V=1 CFLAGS="$(CFLAGS) -static" LDFLAGS="$(LDFLAGS) -static" && \ |
| 86 | $(TARGET)-strip $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION)/misc/mke2fs && \ |
| 87 | touch $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION)/misc/mke2fs |
| 88 | |
| 89 | e2fsprogs: $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION)/misc/mke2fs |
| 90 | |
| 91 | e2fsprogs-clean: |
| 92 | rm -vrf $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION) |
| 93 | |
| 94 | e2fsprogs-distclean: |
| 95 | rm -vf $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION).tar.bz2 |
| 96 | |
| 97 | $(WORK)/dialog-$(DIALOG_VERSION).tgz: |
| 98 | wget -P $(WORK) -c $(DIALOG_SOURCE) |
| 99 | |
| 100 | $(WORK)/dialog-$(DIALOG_VERSION): $(WORK)/dialog-$(DIALOG_VERSION).tgz |
| 101 | tar -C $(WORK) -xvzf $(WORK)/dialog-$(DIALOG_VERSION).tgz |
| 102 | touch $(WORK)/dialog-$(DIALOG_VERSION) |
| 103 | |
| 104 | $(WORK)/dialog-$(DIALOG_VERSION)/_install/usr/bin/dialog: $(WORK)/dialog-$(DIALOG_VERSION) |
| 105 | export PATH=$(CROSSTOOLS)/bin:$$PATH && \ |
| 106 | export LD_LIBRARY_PATH=$(CROSSTOOLS)/lib:$$LD_LIBRARY_PATH && \ |
| 107 | cd $(WORK)/dialog-$(DIALOG_VERSION) && \ |
| 108 | ./configure --build=$(BUILD) --host=$(TARGET) --prefix=/usr --with-ncursesw && \ |
| 109 | find -type f -name 'makefile' \ |
| 110 | -exec sed -e "s|-I/usr|-I$(CLFS)/usr|g" -e "s|-L/usr|-L$(CLFS)/usr|g" -i {} \; && \ |
| 111 | make CC="$(TARGET)-gcc -static" && \ |
| 112 | make DESTDIR=$(WORK)/dialog-$(DIALOG_VERSION)/_install install && \ |
| 113 | $(TARGET)-strip $(WORK)/dialog-$(DIALOG_VERSION)/_install/usr/bin/dialog && \ |
| 114 | touch $(WORK)/dialog-$(DIALOG_VERSION)/_install/usr/bin/dialog |
| 115 | |
| 116 | dialog: $(NCURSES_HEADER) $(WORK)/dialog-$(DIALOG_VERSION)/_install/usr/bin/dialog |
| 117 | |
| 118 | dialog-clean: |
| 119 | rm -vrf $(WORK)/dialog-$(DIALOG_VERSION) |
| 120 | |
| 121 | dialog-distclean: dialog-clean |
| 122 | rm -vf $(WORK)/dialog-$(DIALOG_VERSION).tgz |
| 123 | |
| 124 | $(WORK)/gen_init_cpio: $(WORK)/gen_init_cpio.c |
| 125 | cd $(WORK) && \ |
| 126 | $(CC) $(CFLAGS) -Wall -o gen_init_cpio gen_init_cpio.c |
| 127 | |
| 128 | gen_init_cpio: $(WORK)/gen_init_cpio |
| 129 | |
| 130 | gen_init_cpio-clean: |
| 131 | rm -rf $(WORK)/gen_init_cpio |
| 132 | |
| 133 | gen_init_cpio-distclean: gen_init_cpio-clean |
| 134 | |
| 135 | $(WORK)/mnt: |
| 136 | mkdir -p $(WORK)/mnt |
| 137 | |
| 138 | $(WORK)/initramfs.cpio: check-root busybox e2fsprogs dialog $(WORK)/mnt gen_init_cpio $(TOPDIR)/filesystem |
| 139 | install -d -m 0755 $(WORK)/mnt/{mnt,media,etc,dev,sys,proc,lib,usr,var/{log,lock,run},tmp} |
| 140 | mknod $(WORK)/mnt/dev/console c 5 1 && chmod 666 $(WORK)/mnt/dev/console |
| 141 | mknod $(WORK)/mnt/dev/null c 1 3 && chmod 666 $(WORK)/mnt/dev/null |
| 142 | mknod $(WORK)/mnt/dev/tty c 5 0 && chmod 666 $(WORK)/mnt/dev/tty |
| 143 | mkdir $(WORK)/mnt/dev/rd && mknod $(WORK)/mnt/dev/rd/0 b 1 0 |
| 144 | mknod $(WORK)/mnt/dev/ram0 b 1 0 && chmod 600 $(WORK)/mnt/dev/ram0 |
| 145 | for i in 0 1 2 3 4 5 6 7; do \ |
| 146 | mknod $(WORK)/mnt/dev/tty$$i c 4 $$i && chmod 666 $(WORK)/mnt/dev/tty$$i; \ |
| 147 | done |
| 148 | cp -dRv $(WORK)/busybox-$(BUSYBOX_VERSION)/_install/* $(WORK)/mnt |
| 149 | install -v -m 0755 $(WORK)/e2fsprogs-$(E2FSPROGS_VERSION)/misc/mke2fs $(WORK)/mnt/sbin |
| 150 | for i in 2 3 4 4dev; do \ |
| 151 | ln -s mke2fs $(WORK)/mnt/sbin/mkfs.ext$$i; \ |
| 152 | done |
| 153 | install -v -m 0755 $(WORK)/dialog-$(DIALOG_VERSION)/_install/usr/bin/dialog $(WORK)/mnt/usr/bin |
| 154 | cp -dRv $(CLFS)/lib/libnss_{files*,dns*} $(CLFS)/lib/libresolv* $(WORK)/mnt/lib |
| 155 | install -d $(WORK)/mnt/usr/share/terminfo |
| 156 | cp -dRv $(CLFS)/usr/share/terminfo/v $(WORK)/mnt/usr/share/terminfo |
| 157 | install -v -m 0644 $(TOPDIR)/filesystem/{fstab,inittab,profile,protocols,*.conf} $(WORK)/mnt/etc |
| 158 | install -v -m 0664 $(TOPDIR)/filesystem/group $(WORK)/mnt/etc |
| 159 | install -v -m 0600 $(TOPDIR)/filesystem/passwd $(WORK)/mnt/etc |
| 160 | install -v -m 0400 $(TOPDIR)/filesystem/shadow $(WORK)/mnt/etc |
| 161 | install -v -m 0755 $(TOPDIR)/filesystem/rc $(WORK)/mnt/etc && \ |
| 162 | install -v -m 0755 $(TOPDIR)/filesystem/{setup,setup-chroot,crux} $(WORK)/mnt/usr/bin && \ |
| 163 | ln -s bin/busybox $(WORK)/mnt/init |
| 164 | /sbin/ldconfig -r $(WORK)/mnt |
| 165 | cd $(WORK)/mnt && find . | cpio -o -H newc > $(WORK)/initramfs.cpio |
| 166 | touch $(WORK)/initramfs.cpio |
| 167 | |
| 168 | initramfs: $(WORK)/initramfs.cpio |
| 169 | |
| 170 | initramfs-clean: |
| 171 | rm -rf $(WORK)/initramfs* $(WORK)/mnt |
| 172 | |
| 173 | initramfs-distclean: initramfs-clean |
| 174 | |
| 175 | # End of file |