# Smart Boot Manager installer Makefile
#
# Copyright (c) Suzhe 2000
#


ifeq ($(LOADER),)
LOADER=		$(DEST_DIR)/loader.bin
endif

ifeq ($(MAIN),)
MAIN=		$(DEST_DIR)/main.bin
endif           

ifeq ($(THEME_US),)
THEME_US=	$(DEST_DIR)/theme-us
endif

ifeq ($(THEME_ZH),)
THEME_ZH=	$(DEST_DIR)/theme-zh
endif

ifeq ($(TARGET_OS),linux)
CONVERT=	convert
SBMINST=	$(DEST_DIR)/sbminst
INST_TARGET=	$(BIN_DIR)/sbminst
INSTALL=	install -m 755
STRIP=		strip
endif

ifeq ($(TARGET_OS),dos)
CONVERT=	convert.exe
SBMINST=	$(DEST_DIR)/sbminst.exe
INST_TARGET=	$(BIN_DIR)/sbminst.exe
INSTALL=	cp
STRIP=		strip
endif

DATA_HEADERS=	main.h loader.h theme-us.h theme-zh.h

all: $(SBMINST)

$(SBMINST): sbminst.o $(DATA_HEADERS)
	$(CC) -o $@ $<

$(DATA_HEADERS): $(CONVERT) $(LOADER) $(MAIN) $(THEME_US) $(THEME_ZH)
	@./$(CONVERT)

$(CONVERT): convert.o
	$(CC) -o $@ $<

convert.o: convert.c
	$(CC) -DLOADER_FILE=\"$(LOADER)\" -DMAIN_FILE=\"$(MAIN)\" \
	-DTHEME_US_FILE=\"$(THEME_US)\" -DTHEME_ZH_FILE=\"$(THEME_ZH)\" -c $<

sbminst.o: sbminst.c sbminst.h $(DATA_HEADERS)
	$(CC) -DTHEME_DIR=\"$(THEME_DIR)\" -c $<

install: all
	-@$(STRIP) $(SBMINST)
	-@$(INSTALL) $(SBMINST) ${INST_TARGET}

uninstall:
	-@rm -fr $(INST_TARGET) 

.PHONY: clean
clean:
	-@rm -f *~ *.bin core *.out *.o *.bak *.bkp loader.h main.h \
	theme-us.h theme-zh.h convert convert.exe


