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 \
-march=i386 \
-Wall -W -Wno-format -Wno-unused -DVERSION=\"$(VERSION)$(EXTRAVERSION)\"
LDBINARYFLAG= --oformat binary
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)/man/man1
DOCDIR= $(INSTPREFIX)/share/doc/mknbi
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) -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) -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)
syntax highlighted by Code2HTML, v. 0.9.1