-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
203 lines (165 loc) · 6.73 KB
/
Makefile
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# kexec-loader - Makefile
# Copyright (C) 2007-2010 Daniel Collins <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# This should be "vN.N" releases
#
VERSION=r$(shell git rev-parse --short HEAD)
EXTERN_DOWNLOAD := extern/download
EXTERN_BUILD := extern/build
# kexec-tools
KT_VER := 2.0.25
KT_URL := http://horms.net/projects/kexec/kexec-tools/kexec-tools-$(KT_VER).tar.gz
KT_CONFIGURE := --without-lzma
# util-linux
UL_VER := 2.38.1
UL_URL := https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.38/util-linux-$(UL_VER).tar.gz
UL_CONFIGURE :=
# mdadm
MDADM_VER := 4.2
MDADM_URL := https://mirrors.edge.kernel.org/pub/linux/utils/raid/mdadm/mdadm-$(MDADM_VER).tar.gz
MDADM_DEFS := LDFLAGS=-static "CXFLAGS=-DNO_LIBUDEV -D_LARGEFILE64_SOURCE"
CC := gcc
LD := ld
STRIP := strip
CFLAGS := -Wall -DVERSION=\"$(VERSION)\" -D_GNU_SOURCE -O0
INCLUDES := -I$(EXTERN_BUILD)/util-linux-$(UL_VER)/libblkid/src/
LIBS := -lz
FLOPPY ?= floppy.img
ISOLINUX ?= /usr/share/syslinux/isolinux.bin
ISO ?= cdrom.iso
INITRD_DEPS := kexec-loader.static
INITRD_FLAGS :=
ifdef HOST
CC := $(HOST)-gcc
LD := $(HOST)-ld
STRIP := $(HOST)-strip
KT_CONFIGURE += --host=$(HOST) CC=$(CC)
UL_CONFIGURE += --host=$(HOST) CC=$(CC) CXX=$(HOST)-g++ LD=$(LD)
MDADM_DEFS += CROSS_COMPILE=$(HOST)-
endif
# If not empty or zero
ifneq ($(filter-out 0,$(ENABLE_MDADM)),)
CFLAGS += -DENABLE_MDADM
INITRD_DEPS += $(EXTERN_BUILD)/mdadm-$(MDADM_VER)/mdadm
INITRD_FLAGS += --include-mdadm $(EXTERN_BUILD)/mdadm-$(MDADM_VER)/mdadm
endif
check-header = $(shell echo "#include <$(1)>" | gcc -x c -c -o /dev/null - > /dev/null 2>&1 && echo 1)
ifeq ($(HAVE_LZMA),)
HAVE_LZMA := $(call check-header,lzmadec.h)
endif
# If not empty or zero
ifneq ($(filter-out 0,$(HAVE_LZMA)),)
CFLAGS += -DHAVE_LZMA
LIBS += -llzmadec
endif
KEXEC_A := $(EXTERN_BUILD)/kexec-tools-$(KT_VER)/kexec.a
UTIL_LINUX_CONFIGURED := $(EXTERN_BUILD)/util-linux-$(UL_VER)/.configure-done
LIBBLKID_A := $(EXTERN_BUILD)/util-linux-$(UL_VER)/.libs/libblkid.a
LIBUUID_A := $(EXTERN_BUILD)/util-linux-$(UL_VER)/.libs/libuuid.a
MDADM_BIN := $(EXTERN_BUILD)/mdadm-$(MDADM_VER)/mdadm
OBJS := src/misc.o src/disk.o src/console.o src/menu.o src/modprobe.o \
src/boot.o src/grub.o src/shell.o src/globcmp.o src/keymap.o src/tar.o \
src/vfs.o src/trace.o $(KEXEC_A) $(LIBBLKID_A) $(LIBUUID_A)
all: kexec-loader kexec-loader.static
clean:
rm -f src/*.o
rm -f kexec-loader kexec-loader.static
rm -rf $(EXTERN_BUILD)/kexec-tools-$(KT_VER)/
rm -rf $(EXTERN_BUILD)/util-linux-$(UL_VER)/
rm -rf $(EXTERN_BUILD)/mdadm-$(MDADM_VER)/
rm -f initrd.img $(FLOPPY) $(ISO)
rm -rf iso-files/ iso-modules/
distclean: clean
rm -f $(EXTERN_DOWNLOAD)/kexec-tools-$(KT_VER).tar.gz
rm -f $(EXTERN_DOWNLOAD)/util-linux-$(UL_VER).tar.gz
rm -f $(EXTERN_DOWNLOAD)/mdadm-$(MDADM_VER).tar.gz
kexec-loader: $(OBJS)
$(CC) $(CFLAGS) -o kexec-loader $(OBJS) $(LIBS)
floppy: syslinux.cfg initrd.img
ifeq ($(KERNEL),)
@echo "Please set KERNEL to the Linux kernel binary"
@exit 1
endif
mformat -i $(FLOPPY) -C -f 1440 -v kexecloader ::
mmd -i $(FLOPPY) ::/syslinux
syslinux -d /syslinux $(FLOPPY)
mcopy -i $(FLOPPY) syslinux.cfg ::/syslinux
mcopy -i $(FLOPPY) initrd.img ::/
mcopy -i $(FLOPPY) README.html ::/
mcopy -i $(FLOPPY) kexec-loader.conf ::/
mmd -i $(FLOPPY) ::/modules
mcopy -i $(FLOPPY) $(KERNEL) ::/vmlinuz
ifneq ($(KCONFIG),)
mcopy -i $(FLOPPY) $(KCONFIG) ::/linux.cfg
endif
syslinux.cfg:
echo "DEFAULT /vmlinuz initrd=/initrd.img" > syslinux.cfg
initrd.img: $(INITRD_DEPS)
STRIP=$(STRIP) ./mkinitramfs.sh $(INITRD_FLAGS) initrd.img
cdrom: iso-files iso-modules iso-files/isolinux/initrd.img iso-files/isolinux/vmlinuz
./mkiso.sh $(ISO)
cdrom-export: iso-files iso-modules iso-files/isolinux/initrd.img iso-files/isolinux/vmlinuz
mkdir kexec-loader-$(VERSION)-cdrom
cp -a iso-files iso-modules kexec-loader-$(VERSION)-cdrom
cp -a mkiso.sh addmod.sh kexec-loader-$(VERSION)-cdrom
sed -e "s/\$$VERSION/$(VERSION)/g" cdrom-readme.html > kexec-loader-$(VERSION)-cdrom/readme.html
tar -cf cdrom.tar kexec-loader-$(VERSION)-cdrom
rm -rf kexec-loader-$(VERSION)-cdrom
iso-modules:
mkdir -p iso-modules
iso-files: $(ISOLINUX)
mkdir -p iso-files/isolinux
cp $(ISOLINUX) iso-files/isolinux/
echo "DEFAULT vmlinuz initrd=initrd.img" > iso-files/isolinux/isolinux.cfg
cp kexec-loader.conf iso-files/
iso-files/isolinux/vmlinuz: $(KERNEL)
ifeq ($(KERNEL),)
@echo "Please set KERNEL to the Linux kernel binary"
@exit 1
endif
ifneq ($(KCONFIG),)
cp $(KCONFIG) iso-files/linux.cfg
endif
cp $(KERNEL) iso-files/isolinux/vmlinuz
iso-files/isolinux/initrd.img: iso-files initrd.img
cp initrd.img iso-files/isolinux/
kexec-loader.static: $(OBJS)
$(CC) $(CFLAGS) -static -o kexec-loader.static $(OBJS) $(LIBS)
%.o: %.c $(UTIL_LINUX_CONFIGURED)
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
$(KEXEC_A):
mkdir -p $(EXTERN_DOWNLOAD) $(EXTERN_BUILD)
test -e $(EXTERN_DOWNLOAD)/$(notdir $(KT_URL)) || wget -O $(EXTERN_DOWNLOAD)/$(notdir $(KT_URL)) $(KT_URL)
tar -C $(EXTERN_BUILD) -xf $(EXTERN_DOWNLOAD)/$(notdir $(KT_URL))
patch -p1 -d $(EXTERN_BUILD)/kexec-tools-$(KT_VER)/ < patches/kexec-tools-$(KT_VER).diff
cd $(EXTERN_BUILD)/kexec-tools-$(KT_VER)/ && ./configure $(KT_CONFIGURE)
$(MAKE) -C $(EXTERN_BUILD)/kexec-tools-$(KT_VER)/
$(UTIL_LINUX_CONFIGURED):
mkdir -p $(EXTERN_DOWNLOAD) $(EXTERN_BUILD)
test -e $(EXTERN_DOWNLOAD)/$(notdir $(UL_URL)) || wget -O $(EXTERN_DOWNLOAD)/$(notdir $(UL_URL)) $(UL_URL)
tar -C $(EXTERN_BUILD) -xf $(EXTERN_DOWNLOAD)/$(notdir $(UL_URL))
cd $(EXTERN_BUILD)/util-linux-$(UL_VER)/ && ./configure $(UL_CONFIGURE)
touch $@
$(LIBBLKID_A): $(UTIL_LINUX_CONFIGURED)
$(MAKE) -C $(EXTERN_BUILD)/util-linux-$(UL_VER)/ libblkid.la
$(LIBUUID_A):
$(MAKE) -C $(EXTERN_BUILD)/util-linux-$(UL_VER)/ libuuid.la
$(MDADM_BIN):
mkdir -p $(EXTERN_DOWNLOAD) $(EXTERN_BUILD)
test -e $(EXTERN_DOWNLOAD)/$(notdir $(MDADM_URL)) || wget -O $(EXTERN_DOWNLOAD)/$(notdir $(MDADM_URL)) $(MDADM_URL)
tar -C $(EXTERN_BUILD) -xf $(EXTERN_DOWNLOAD)/$(notdir $(MDADM_URL))
patch -p1 -d $(EXTERN_BUILD)/mdadm-$(MDADM_VER)/ < patches/mdadm-$(MDADM_VER)-x86.patch
make -C $(EXTERN_BUILD)/mdadm-$(MDADM_VER)/ $(MDADM_DEFS)