# Configuration variables

# They can also be stored in a file /etc/lilo/config.defines, e.g.
# -DIGNORECASE -DONE_SHOT

# The variables configured in this Makefile are ignored if
# /etc/lilo/config.defines exists

#   IGNORECASE  Image selection is case-insensitive. Passwords are still case-
#		sensitive.
#   NOAUTO	Don't put the word "auto" on the command line when booting
#		unattendedly. (poeigl init <= 1.11 compatibility.)
#   ONE_SHOT    Disable the command-line and password timeout if any key is hit
#		at the boot prompt.
#   READONLY	Don't overwrite the default command line in the map file after
#		reading it.

CONFIG=-DIGNORECASE

# End of configuration variables

PCONFIG=`( if [ -r $$ROOT/etc/lilo/config.defines ]; then \
  cat $$ROOT/etc/lilo/config.defines; else echo $(CONFIG); fi ) | \
  sed 's/-D/-DLCF_/g'`

SHELL=/bin/sh
CC=cc
CPP=$(CC) -E
AS86=as86 -0 -a
LD86=ld86 -0

CFLAGS=-Wall -Wno-parentheses -g `if [ -f /usr/include/linux/genhd.h ]; then \
  echo -DNEW_INCLUDES; fi` $(PCONFIG)
LDFLAGS=

OBJS=lilo.o map.o geometry.o boot.o device.o common.o bsect.o cfg.o temp.o \
  partition.o identify.o

.SUFFIXES:	.img .b

all:		lilo boot.b chain.b dparam.com activate # dos_d.b

.c.o:
		$(CC) -c $(CFLAGS) $*.c

.s.o:
		$(AS86) -w -o $*.o $*.s

.o.img:
		$(LD86) -s -o $*.img $*.o

.img.b:
		dd if=$*.img of=$*.b bs=32 skip=1

activate:	activate.c
		$(CC) -o activate activate.c $(LDFLAGS)

dparam.com:	dparam.img
		dd if=dparam.img of=dparam.com bs=288 skip=1

lilo:		$(OBJS)
		$(CC) -o lilo $(LDFLAGS) $(OBJS)

boot.b:		first.b second.b
		(dd if=first.b bs=512 conv=sync; dd if=second.b) >boot.b

first.s:	first.S lilo.h lilo shared.S
		$(CPP) `./lilo -X` first.S -o first.s

second.s:	second.S lilo.h lilo shared.S
		$(CPP) $(PCONFIG) `./lilo -X` second.S -o second.s

chain.s:	chain.S lilo.h first.lis
		$(CPP) chain.S -o chain.s

dos_d.s:	chain.S lilo.h
		$(CPP) chain.S -DDOS_D -o dos_d.s \
	          -DGO=0x`sed '/go/s/^.*go  0 \(....\) A.*$$/\1/p;d' first.lis`

xxx.s:		chain.S lilo.h
		$(CPP) chain.S -DXXX -o xxx.s

first.o first.lis:	first.s
		$(AS86) -w -o first.o -l first.lis first.s

second.lis:	second.s
		$(AS86) -w -l second.lis second.s

first.img:	first.o
second.img:	second.o
chain.img:	chain.o
dos_d.img:	dos_d.o
xxx.img:	xxx.o
dparam.img:	dparam.o
first.b:	first.img
second.b:	second.img
chain.b:	chain.img
xxx.b:		xxx.img

install:	all
		if [ ! -d $$ROOT/etc/lilo ]; then mkdir $$ROOT/etc/lilo; fi
		if [ -f $$ROOT/etc/lilo/boot.b ]; then \
		  mv $$ROOT/etc/lilo/boot.b $$ROOT/etc/lilo/boot.old; fi
		if [ -f $$ROOT/etc/lilo/chain.b ]; then \
		  mv $$ROOT/etc/lilo/chain.b $$ROOT/etc/lilo/chain.old; fi
#		if [ -f $$ROOT/etc/lilo/xxx.b ]; then \
#		  mv $$ROOT/etc/lilo/xxx.b $$ROOT/etc/lilo/xxx.old; fi
#		if [ -f $$ROOT/etc/lilo/dos_d.b ]; then \
#		  mv $$ROOT/etc/lilo/dos_d.b $$ROOT/etc/lilo/dos_d.old; fi
		cp lilo boot.b chain.b mkck $$ROOT/etc/lilo
# xxx.b dos_d.b
		if [ ! -f $$ROOT/etc/lilo/disktab ]; then \
		  cp disktab $$ROOT/etc/lilo; fi
		if [ -f $$ROOT/etc/lilo/install ]; then echo; \
		  echo -n "Please don't forget to run $$ROOT/etc/lilo/install";\
		  echo " to update boot sector and map file."; fi
		
dep:
		sed '/\#\#\# Dependencies/q' <Makefile >tmp_make
		$(CPP) $(CFLAGS) -MM *.c >>tmp_make
#		(for n in *.c; do $(CPP) -MM $$n; done) >>tmp_make
		mv tmp_make Makefile

clean:
		-rm *.o *.img *.lis first.s second.s chain.s dos_d.s tmp_make \
		  first.b second.b

spotless:	clean
		-rm lilo boot.b chain.b dos_d.b

### Dependencies
activate.o : activate.c 
boot.o : boot.c config.h common.h lilo.h geometry.h cfg.h map.h partition.h \
  boot.h 
bsect.o : bsect.c config.h common.h lilo.h cfg.h device.h geometry.h map.h temp.h \
  partition.h boot.h bsect.h 
cfg.o : cfg.c common.h lilo.h temp.h cfg.h 
common.o : common.c common.h lilo.h 
device.o : device.c config.h common.h lilo.h temp.h device.h 
geometry.o : geometry.c config.h lilo.h common.h device.h geometry.h 
identify.o : identify.c cfg.h 
lilo.o : lilo.c config.h common.h lilo.h temp.h geometry.h map.h bsect.h cfg.h \
  identify.h 
map.o : map.c lilo.h common.h geometry.h map.h 
partition.o : partition.c config.h common.h lilo.h cfg.h device.h geometry.h 
temp.o : temp.c common.h lilo.h temp.h 
