aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: f7836bb143f77a1bd3b286038769db3d20d0ea72 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
VERSION			=scm

CFLAGS			?= -Os
CXXFLAGS		?= $(CFLAGS)

CFLAGS			+= -static
LDFLAGS			+= -static

export CFLAGS
export CXXFLAGS
export LDFLAGS

JOBS			= $$(expr $$(grep -c processor /proc/cpuinfo) + 4)

BUILD			?= $(PWD)/build

PATH			+= :$(PWD)/toolchain

urls            =	\
	http://busybox.net/downloads/busybox-1.24.1.tar.bz2					\
	https://matt.ucc.asn.au/dropbear/releases/dropbear-2015.71.tar.bz2

make			= busybox dropbear

all:
	@printf "lighter $(VERSION)\n\n"
	@printf "%-20s%-20s\n"	\
		"CFLAGS"		"$(CFLAGS)"		\
		"CXXFLAGS"		"$(CXXFLAGS)"	\
		"JOBS"          "$(JOBS)"	\
		"BUILD"			"$(BUILD)"
	@printf "\n"
	@$(MAKE) build

toolchain:
	@printf "making any needed toolchain links...\n"
	@sh -e scripts/toolchain
	@printf "\n"
#	@for d in $(dirs);do echo "mkdir -p $(BUILD)/$$d"; [ -d "$$d" ] || mkdir -p $(BUILD)/"$$d";done

prepare: toolchain skel
	@printf "making build directories...\n"
	-mkdir -p "$(BUILD)" >/dev/null 2>&1
	-mkdir "$(BUILD)"/root >/dev/null 2>&1
	@printf "copying skeleton root to %s...\n" "$(BUILD)"
	cp -r skel/* "$(BUILD)"/root/
	@printf "\n"

fetch: prepare
	@printf "fetching all needed files...\n"
	@sh -e scripts/fetch $(urls)
	@printf "\n"

extract: fetch
	@printf "extracting downloaded files...\n"
	@sh -e scripts/extract $(urls)
	@printf "\n"

build/.built-%: toolchain
	@printf "building %s...\n" "$*"
	mkdir -p "$(BUILD)/$*"
	DESTDIR="$(BUILD)/$*" BUILD="$(BUILD)/root" J="$(JOBS)" sh -e scripts/build/$*
	cp -R "$(BUILD)/$*"/* "$(BUILD)/root"
	@touch build/.built-$*
	@printf "\n"

clean-%:
	@printf "cleaning archives/%s...\n" "$*"
	rm -rf archives/"$*"*

$(BUILD)/initramfs.cpio.gz:
	cd "$(BUILD)/root" && find . -print0 | cpio --null -ov --format=newc | gzip -9 > "$(BUILD)"/initramfs.cpio.gz

pack: $(BUILD)/initramfs.cpio.gz

repack:
	rm -f $(BUILD)/initramfs.cpio.gz
	$(MAKE) pack

build: prepare fetch extract $(foreach m,$(make),build/.built-$(m)) pack

clean:
	rm -rf downloads archives $(BUILD) toolchain

.PHONY:	clean all prepare fetch extract build pack