script/makepkg: make port_save_config a little more atomic
[CDN/Mosi.git] / Makefile
1 # Defaults
2 my_arch     != uname -m
3
4 # Settables
5 arch        ?= $(my_arch)
6 conf        ?= GENERIC
7 target      ?= targets/$(arch)/$(conf)
8 srctree     ?= $(target)/world
9 worktree    ?= $(target)/tree
10 boot_pad    ?= 1280
11 cardsize    ?= 524288
12
13 # Generation scripts
14 gentree      = script/gentree
15 genufs       = script/genufs
16 geniso       = script/geniso
17 genuzip      = script/genuzip
18 gencard      = script/gencard
19
20 # Image utilities
21 makefs      != which makefs
22 makefs_opts ?= -t ffs -o version=2,optimization=space -b 8 -f 8
23 tunefs      != which tunefs
24 mkuzip      != which mkuzip
25 mkuzip_opts ?= -s 65536
26 mkisofs     != which mkisofs
27 mkisofs_opts?= -quiet -D -R -no-pad -p CyberLeo
28
29 # Default device for burn target
30 dev         ?= null
31
32 # Check current user
33 curruser    != id -u
34 checkroot    = @if [ $(curruser) -gt 0 ]; then printf "\033[1;31mI need root\033[0m\n"; exit 1; fi
35 checkdeps    = @if [ ! -x "$(mkisofs)" -o ! -x "$(mkuzip)" ]; then printf "\033[1;31mCheck depends! mkisofs: $(mkisofs) mkuzip: $(mkuzip)\033[0m\n"; exit 1; fi
36
37 # Default target
38 all: $(worktree)/card.img
39
40 image: $(worktree)/card.img
41
42 firmware: $(worktree)/card.img
43
44 # Check that we're running as root
45 checkroot:
46         $(checkroot)
47
48 # Burn to device
49 burn: $(worktree)/card.img
50         $(checkroot)
51         script/burn $(.ALLSRC) $(dev)
52
53 # Push to build target
54 push:
55         script/push cyberleo@sc1425:mosi/
56
57 # Generate components
58 $(worktree)/card.img: $(worktree)/boot.img $(worktree)/root.img
59         $(checkroot)
60         ${gencard} -b $(worktree)/boot.img -r $(worktree)/root.img -c $(worktree)/conf -s ${cardsize} -o $(worktree)/card.img
61         @printf " \033[1;32m*\033[0m Complete\n"
62
63 $(worktree)/boot.img: $(worktree)/boot
64         $(checkroot)
65         #${genufs} -p $(boot_pad) -l boot -o $(worktree)/boot.img $(worktree)/boot
66         ${makefs} ${makefs_opts} $(worktree)/boot.img $(worktree)/boot
67         ${tunefs} -L boot $(worktree)/boot.img
68
69 $(worktree)/root.img: $(worktree)/root.iso
70         $(checkroot)
71         $(checkdeps)
72         ${genuzip} $(.ALLSRC) $(.TARGET)
73
74 $(worktree)/root.iso: $(worktree)/root
75         $(checkroot)
76         $(checkdeps)
77         ${geniso} -n root $(.ALLSRC) $(.TARGET)
78
79 $(worktree): $(worktree)/root
80
81 $(worktree)/boot: $(srctree)/root
82         $(checkroot)
83         $(gentree) -a $(arch) -c $(conf)
84
85 $(worktree)/root: $(srctree)/root
86         $(checkroot)
87         $(gentree) -a $(arch) -c $(conf)
88
89 # Scrub everything clean
90 clean:
91         $(checkroot)
92         sh -c 'if ! rm -Rf $(worktree); then chflags -R noschg $(worktree); rm -Rf $(worktree); fi'