LIBS = -lnewt -lslang -lc #-lefence

#ifndef LINGUA
	LINGUA=C
#endif
#ifndef KVER
	KVER=2.0.35
#endif

ARCH=$(shell dpkg --print-architecture)
CFLAGS = -O2 -D_GNU_SOURCE 
CFLAGS += -DARCH=$(ARCH) -DARCHNAME='"$(ARCH)"' 
CFLAGS += -DKVER='"$(KVER)"' 
CFLAGS += -DLINGUA='"$(LINGUA)"' -DINCLINGUA='"messages/lang_$(LINGUA).h"'
ifdef FONT
 CFLAGS += -DFONT='"$(FONT)"'
endif
CFLAGS += -Wall -g
# CFLAGS += -DLOG 
# CFLAGS += -DTEST
ifdef INCLUDE_DINSTALL
 CFLAGS += -DINCLUDE_DINSTALL
endif

PROG = dbootstrap

BBOXOBJS = ../busybox/descend.o ../busybox/postprocess.o \
  ../busybox/fdflush.o ../busybox/losetup.o ../busybox/mount.o \
  ../busybox/mkdir.o ../busybox/utility.o ../busybox/findmount.o \
  ../busybox/umount.o ../busybox/swapon.o ../busybox/swapoff.o \
  ../busybox/block_device.o
LIBFDISK = ../libfdisk/libfdisk.a

OBJECTS = $(patsubst %.c,%.o,$(wildcard *.c))

SOURCES = $(subst .o,.c,$(OBJECTS)) dinstall.h

TEST = bootconfig_test boxes_test choose_medium_test color_or_monochrome_test \
	floppy_merge_test interactive_shell_test kbdconfig_test main_menu_test \
	netconfig_test pcmcia_test reboot_system_test release_notes_test \
	tzconfig_test select_not_mounted_test

all:    depend $(PROG)

build-objects: $(OBJECTS)

$(PROG):	build-objects $(BBOXOBJS) $(LIBFDISK)
	$(CC) $(CFLAGS) -o $(PROG) $(OBJECTS) $(BBOXOBJS) $(LIBFDISK) $(LIBS)

$(LIBFDISK): force
	$(MAKE) -C ../libfdisk libfdisk.a

depend: $(SOURCES)
	$(CPP) $(CFLAGS) -M $(SOURCES) > .depend

clean: 
	rm -rf $(OBJECTS) *_test 

distclean: clean
	rm -f $(PROG) .depend

force:

test: $(TEST)

boxes_test: boxes.c
	$(CC) $(CFLAGS) -o ./$@ -D_BOXTESTING_ -g $^ $(LIBS)

color_or_monochrome_test: color_or_monochrome.c
	$(CC) $(CFLAGS) -o ./$@ -D_TESTING_ -g $^ $(LIBS)

floppy_merge_test: floppy_merge.c boxes.c
	$(CC) $(CFLAGS) -o ./$@ -D_TESTING_ -g $^ $(LIBS)

interactive_shell_test: interactive_shell.c boxes.c
	$(CC) $(CFLAGS) -o ./$@ -D_TESTING_ -g $^ $(LIBS)

kbdconfig_test: kbdconfig.c boxes.c
	$(CC) $(CFLAGS) -o ./$@ -D_TESTING_ -g $^ $(LIBS)

main_menu_test: main_menu.c boxes.c
	$(CC) $(CFLAGS) -o ./$@ -D_TESTING_ -g $^ $(LIBS)

netconfig_test: netconfig.c boxes.c nfsroot.c \
	../busybox/descend.c ../busybox/cp.c ../busybox/utility.c \
	../busybox/postprocess.c
	$(CC) $(CFLAGS) -o ./$@ -D_TESTING_ -g $^ $(LIBS)

reboot_system_test: reboot_system.c boxes.c
	$(CC) $(CFLAGS) -o ./$@ -D_TESTING_ -g $^ $(LIBS)

release_notes_test: release_notes.c boxes.c
	$(CC) $(CFLAGS) -o ./$@ -D_TESTING_ -g $^ $(LIBS)

tzconfig_test: tzconfig.c boxes.c
	$(CC) $(CFLAGS) -o ./$@ -D_TESTING_ -g $^ $(LIBS)

pcmcia_test: pcmcia.c boxes.c ../busybox/mkdir.c ../busybox/utility.c
	$(CC) $(CFLAGS) -o ./$@ -D_TESTING_ -g $^ $(LIBS)

bootconfig_test: bootconfig.c boxes.c select_not_mounted.c lists.c \
	../busybox/umount.c ../busybox/mount.c ../busybox/utility.c \
	../busybox/fdflush.c ../busybox/findmount.c
	$(CC) $(CFLAGS) -o ./$@ -D_TESTING_ -g $^ $(LIBS)

choose_medium_test: choose_medium.c boxes.c select_not_mounted.c lists.c \
	no_match.c ../busybox/descend.c ../busybox/postprocess.c \
	../busybox/umount.c ../busybox/mount.c ../busybox/utility.c \
	../busybox/findmount.c $(LIBFDISK)
	$(CC) $(CFLAGS) -o ./$@ -D_CTESTING_ -g $^ $(LIBS)

select_not_mounted_test: boxes.c select_not_mounted.c lists.c \
	no_match.c ../busybox/descend.c ../busybox/postprocess.c \
	../busybox/umount.c ../busybox/mount.c ../busybox/utility.c \
	../busybox/findmount.c $(LIBFDISK)
	$(CC) $(CFLAGS) -o ./$@ -D_STESTING_ -g $^ $(LIBS)

partition_config_test: partition_config.c boxes.c select_not_mounted.c lists.c choose_medium.c no_match.c \
	../busybox/mount.c ../busybox/umount.c ../busybox/mkdir.c \
	../busybox/swapoff.c ../busybox/swapon.c ../busybox/findmount.c \
	../busybox/utility.c ../busybox/block_device.c ../busybox/descend.c \
	../busybox/postprocess.c $(LIBFDISK)
	$(CC) $(CFLAGS) -o ./$@ -D_TESTING_ -g $^ $(LIBS)

# Not ready yet...
# select_not_mounted 
# is_root_a_floppy lists main no_match partition_config

ifeq (.depend,$(wildcard .depend))
include .depend
endif
