File: Makefile

package info (click to toggle)
mknbi 1.4.4-10
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 944 kB
  • ctags: 1,535
  • sloc: ansic: 3,511; asm: 2,374; perl: 1,368; makefile: 210; sh: 65; pascal: 37
file content (267 lines) | stat: -rw-r--r-- 9,375 bytes parent folder | download | duplicates (2)
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
VERSION=1.4.4
EXTRAVERSION=
TARVERSION=1.4.4
# spec file can override
RPMVERSION=$(VERSION)

# If you don't have either nasm or the ELKS as86, then just do make
# and make install because the assembler sources are supplied preassembled
# If you do make realclean you will have to unpack the mknbi archive again

# Use nasm or as86
ASM=nasm
# This must be the as86 from the ELKS project, the default Linux one won't do
#ASM=as86

# for first32*.linux
# This one makes multiple versions
FIRSTRELOCS=	0x92800 0x82800
OLDGAS:=	$(shell $(AS) --version | grep -q '2\.9\.1' && echo -DGAS291)
CFLAGS=		-I. -Os -ffreestanding -fstrength-reduce -fomit-frame-pointer \
		-fno-stack-protector \
		-m32 -mcpu=i386 \
		-Wall -W -Wno-format -Wno-unused -DVERSION=\"$(VERSION)$(EXTRAVERSION)\"
LDBINARYFLAG=	--oformat binary -m elf_i386
ASFLAGS=	--32
FIRST32SIZE=	6144

# for first32dos
F32DRELOC=0x93000

# for FreeDOS
FDKSEG=	0x60

# for menu
MENURELOC=	0x60000
# Options for auxiliary menu program
# Available: -DANSIESC -DMOTD -DUSRPARMS -DPASSWD
# -DCONSOLE_CRT -DCONSOLE_SERIAL -DSHOW_NUMERIC -DPOWERSAVE
# Might as well take the lot since code size is not a concern
# Must pick ANSIMODE=1 if ANSIESC is chosen
BOOTMENU_FLAGS=	-DCONSOLE_CRT -DANSIESC -DANSIMODE=1 -DMOTD -DUSRPARMS -DPASSWD -DPOWERSAVE -DCOMCONSOLE=0x3f8 -DCOMPRESERVE

PREFIX=		/usr/local
INSTPREFIX=	$(BUILD_ROOT)$(PREFIX)
LIBDIR=		$(PREFIX)/lib/mknbi
INSTLIBDIR=	$(INSTPREFIX)/lib/mknbi
BINDIR=		$(INSTPREFIX)/bin
MANDIR=		$(INSTPREFIX)/share/man/man1
DOCDIR=		$(INSTPREFIX)/share/doc/packages/mknbi-$(RPMVERSION)

INSTALL=	install

PROG=	mknbi disnbi dismbr disdosbb nbitoelf
MODULES=Nbi.pm Elf.pm TruncFD.pm
FIRSTS=	$(foreach i,$(FIRSTRELOCS),first32@$(i).linux first32elf@$(i).linux) \
	first.dos first.fdos menu nfl
ALTBOOT=altboot.bin
RMRD=	rmrd.com
MANS=	mknbi.1 disnbi.1 menuc.1
HTMLS=	mknbi.html disnbi.html menuc.html
DOCS=	$(MANS) $(HTMLS)


all:	$(PROG) $(FIRSTS) $(RMRD) $(DOCS)

# Tagged image builder
mknbi:	mknbi.pl Nbi.pm TruncFD.pm
	perl -ne 's|\@\@VERSION\@\@|$(VERSION)|; s|\@\@LIBDIR\@\@|$(LIBDIR)|; s|\@\@FDKSEG\@\@|$(FDKSEG)|; print $$_;' mknbi.pl > $@
	chmod 755 $@

# Tagged image display and disassemble
disnbi:	disnbi.pl
	cp -p disnbi.pl disnbi
	chmod 755 disnbi

# Master boot record display
dismbr:	dismbr.pl
	cp -p dismbr.pl dismbr
	chmod 755 dismbr

# DOS boot block display
disdosbb:	disdosbb.pl
	cp -p disdosbb.pl disdosbb
	chmod 755 disdosbb

# NBI to ELF converter
nbitoelf:	nbitoelf.pl
	cp -p nbitoelf.pl nbitoelf
	chmod 755 nbitoelf

# 32-bit first stage protected mode call setup program
first32@%.linux:	start32@%.o first32.o memsizes.o printf.o string.o
	$(LD) -N -Ttext $* -e _start $(LDBINARYFLAG) -o $@ start32@$*.o first32.o memsizes.o printf.o string.o
	@if [ `wc -c < $@` -gt $(FIRST32SIZE) ]; then echo Binary too large; fi

# 32-bit first stage ELF setup program
first32elf@%.linux:	start32@%.o first32elf.o memsizes.o printf.o string.o
	$(LD) -N -Ttext $* -e _start $(LDBINARYFLAG) -o $@ start32@$*.o first32elf.o memsizes.o printf.o string.o
	@if [ `wc -c < $@` -gt $(FIRST32SIZE) ]; then echo Binary too large; fi

# 32-bit first stage ELF DOS setup program
first32elf@%.dos:	start32@%.o first32dos.o printf.o string.o
	$(LD) -N -Ttext $* -e _start $(LDBINARYFLAG) -o $@ start32@$*.o first32dos.o printf.o string.o

start32@%.o:	start32.S
	gcc -E -DRELOC=$* $(OLDGAS) start32.S | $(AS) $(ASFLAGS) -o start32@$*.o

first32.o:	first32.c etherboot.h start32.h
	gcc $(CFLAGS) -o first32.o -c first32.c

first32elf.o:	first32.c etherboot.h start32.h
	gcc $(CFLAGS) -DFIRST32ELF -o first32elf.o -c first32.c

first32dos.o:	first32.c etherboot.h start32.h
	gcc $(CFLAGS) -DRELOC=$(F32DRELOC) -DFIRST32DOS -DFIRST32ELF -o first32dos.o -c first32.c

memsizes.o:		memsizes.c
	gcc $(CFLAGS) -c $*.c

printf.o:		printf.c
	gcc $(CFLAGS) -c $*.c

# DOS first stage setup program, depend on Makefile for version number
first.dos:	first-dos.S first-dos.h version-dos.h Makefile
ifeq ($(ASM),as86)
	gcc $(ASMCFLAGS) -DUSE_AS86 -DVENDOR_MAGIC=\"mknbi-dos-$(VERSION)\" -E -traditional -o first-dos.s first-dos.S
	as86 -0 -b first.dos first-dos.s
else
	gcc $(ASMCFLAGS) -DUSE_NASM -DVENDOR_MAGIC=\"mknbi-dos-$(VERSION)\" -E -traditional -o first-dos.s first-dos.S
	nasm -f bin first-dos.s -o first.dos
endif

# FreeDOS first stage setup program, depend on Makefile for version number
first.fdos:	first-dos.S first-dos.h version-dos.h Makefile
ifeq ($(ASM),as86)
	gcc $(ASMCFLAGS) -DFREEDOS -DFDKSEG=$(FDKSEG) -DUSE_AS86 -DVENDOR_MAGIC=\"mknbi-fdos-$(VERSION)\" -E -traditional -o first-fdos.s first-dos.S
	as86 -0 -b first.fdos first-fdos.s
else
	gcc $(ASMCFLAGS) -DFREEDOS -DFDKSEG=$(FDKSEG) -DUSE_NASM -DVENDOR_MAGIC=\"mknbi-fdos-$(VERSION)\" -E -traditional -o first-fdos.s first-dos.S
	nasm -f bin first-fdos.s -o first.fdos
endif

first-elf.dos:	first.dos first32elf@$(F32DRELOC).dos
	cat first.dos first32elf@$(F32DRELOC).dos > first-elf.dos

first-elf.fdos:	first.fdos first32elf@$(F32DRELOC).dos
	cat first.fdos first32elf@$(F32DRELOC).dos > first-elf.fdos

# Menu first stage program
menu:	startmenu.o menu.o bootmenu.o string.o printf.o ansiesc.o md5.o misc.o serial.o
	$(LD) -N -Ttext $(MENURELOC) -e _start $(LDBINARYFLAG) -o $@ startmenu.o menu.o bootmenu.o string.o printf.o ansiesc.o md5.o misc.o serial.o

# Another menu program, this one simpler
menu-simple:	startmenu.o menu-simple.o string.o printf.o ansiesc.o
	$(LD) -N -Ttext $(MENURELOC) -e _start $(LDBINARYFLAG) -o $@ startmenu.o menu-simple.o string.o printf.o ansiesc.o

# Network FreeLoader (light-bar menu program)
nfl:	startmenu.o nfl.o string.o printf.o ansiesc.o
	$(LD) -N -Ttext $(MENURELOC) -e _start $(LDBINARYFLAG) -o $@ startmenu.o nfl.o string.o printf.o ansiesc.o

# LUA interpreter
lua/bin/lua:
	cd lua; make

startmenu.o:	startmenu.S startmenu.h
	gcc -E -Ui386 -DRELOC=$(MENURELOC) $(OLDGAS) startmenu.S | $(AS) $(ASFLAGS) -o startmenu.o

menu.o:		menu.c stddef.h string.h printf.h ansiesc.h \
		misc.h linux-asm-io.h etherboot.h
	gcc $(CFLAGS) $(BOOTMENU_FLAGS) -c $*.c

bootmenu.o:	bootmenu.h bootmenu.c stddef.h string.h md5.h misc.h etherboot.h start32.h
	gcc $(CFLAGS) $(BOOTMENU_FLAGS) -c $*.c

string.o:	string.h string.c
	gcc $(CFLAGS) -c $*.c

ansiesc.o:	ansiesc.h ansiesc.c stddef.h string.h etherboot.h
	gcc $(CFLAGS) -DGFX -c $*.c

md5.o:	md5.h md5.c etherboot.h
	gcc $(CFLAGS) $(BOOTMENU_FLAGS) -c $*.c

misc.o:	misc.h misc.c ansiesc.h etherboot.h start32.h
	gcc $(CFLAGS) $(BOOTMENU_FLAGS) -c $*.c

serial.o:	serial.c
	gcc $(CFLAGS) $(BOOTMENU_FLAGS) -c $*.c

menu-simple.o:	menu-simple.h menu-simple.c string.h etherboot.h
	gcc $(CFLAGS) -c $*.c

# Remove ramdisk utility under DOS
rmrd.com:	rmrd.S
ifeq ($(ASM),as86)
	gcc $(ASMCFLAGS) -DUSE_AS86 -E -traditional -o rmrd.s rmrd.S
	# -s appears to be necessary to start binary at 0x100
	as86 -0 -b rmrd.com -s rmrd.map rmrd.s
else
	gcc $(ASMCFLAGS) -DUSE_NASM -E -traditional -o rmrd.s rmrd.S
	nasm -f bin rmrd.s -o rmrd.com
endif

# Alternate boot block, taken from netboot mknbi-dos
# Not made by default because not everybody has as86 installed
$(ALTBOOT):	altboot.S
	gcc -E altboot.S > altboot.s
	as86 -s /dev/null -b $(ALTBOOT) altboot.s
	$(RM) altboot.s

$(MANS):	mknbi.pl disnbi.pl Makefile
	pod2man --date=`date +%Y-%m-%d` --release="Mknbi $(VERSION)$(EXTRAVERSION)" --center="Etherboot tools" mknbi.pl > mknbi.1
	pod2man --date=`date +%Y-%m-%d` --release="Mknbi $(VERSION)$(EXTRAVERSION)" --center="Etherboot tools" disnbi.pl > disnbi.1
	pod2man --date=`date +%Y-%m-%d` --release="Mknbi $(VERSION)$(EXTRAVERSION)" --center="Etherboot tools" menuc.pl > menuc.1

$(HTMLS):	mknbi.pl disnbi.pl
	pod2html mknbi.pl > mknbi.html
	pod2html disnbi.pl > disnbi.html
	pod2html menuc.pl > menuc.html

install:	all $(ALTBOOT)
	-mkdir -p $(INSTLIBDIR)
	$(INSTALL) $(PROG) $(INSTLIBDIR)/
	$(INSTALL) -m 644 $(MODULES) $(FIRSTS) $(ALTBOOT) $(RMRD) $(INSTLIBDIR)/
	if [ -e lua-4.0.1/bin/lua ]; then \
		cp -p lua-4.0.1/bin/lua lua; \
	fi
	if [ -e lua ]; then \
		$(INSTALL) -m 644 lua $(INSTLIBDIR)/lua; \
	fi
	-mkdir -p $(BINDIR)
	cd $(BINDIR); \
	for i in linux rom fdos dos menu nfl; \
	do \
		ln -sf ../lib/mknbi/mknbi mknbi-$$i; \
	done; \
	for i in linux img menu nfl lua; \
	do \
		ln -sf ../lib/mknbi/mknbi mkelf-$$i; \
	done
	(cd $(BINDIR); ln -sf ../lib/mknbi/disnbi disnbi)
	(cd $(BINDIR); ln -sf ../lib/mknbi/dismbr dismbr)
	(cd $(BINDIR); ln -sf ../lib/mknbi/disdosbb disdosbb)
	(cd $(BINDIR); ln -sf ../lib/mknbi/nbitoelf nbitoelf)
	-mkdir -p $(MANDIR)
	$(INSTALL) -m 644 mknbi.1 disnbi.1 $(MANDIR)/
	cd $(MANDIR); \
	for i in mkelf mknbi-linux mkelf-linux mknbi-rom mkelf-img mknbi-menu mkelf-menu mknbi-nfl mkelf-nfl mknbi-dos mknbi-fdos mkelf-lua; \
	do \
		ln -sf mknbi.1 $$i.1; \
	done
	-mkdir -p $(DOCDIR)
	$(INSTALL) -m 644 COPYING README LOG spec.txt $(DOCDIR)/

tarball:
	mkdir -p luabuild
	-diff -ur --exclude='*.a' --exclude='*.o' --exclude='*.map' --unidirectional-new-file /usr/local/src/lua-4.0.1 lua-4.0.1 > luabuild/luapatch.txt
	(cd ..; tar zcf /tmp/mknbi-$(TARVERSION).tar.gz --exclude CVS --exclude lua-4.0.1 mknbi-$(TARVERSION))

clean:
	$(RM) -f $(PROG) start32*.o first32*.o \
	printf.o menu.o menu-simple.o nfl.o startmenu.o \
	bootmenu.o md5.o misc.o serial.o ansiesc.o string.o memsizes.o \
	first-dos.s first-fdos.s rmrd.s rmrd.map *.l pod2htm*

realclean:	clean
	$(RM) -f $(FIRSTS) $(RMRD) $(DOCS)