# Where you want it installed when you do 'make install'
PREFIX=/usr/local
# Where you want the includes to go when you do 'make install'
IPREFIX=/usr/local



# You shouldn't have to touch the rest unless the compile is failing for some reason?
SRC=.
EXAMPLE_DIR=./examples

# To assist in cross-compiling
CC=gcc
AS=fasm
CFLAGS=-Wall -O3 -I$(SRC)
LDFLAGS=

#flags for building the examples
B0_FLAGS=-felf

all: b0-ia32
b0-ia32: $(SRC)/b0.c $(SRC)/b0.h
	$(CC) $(CFLAGS) -s $(LDFLAGS) -o b0-ia32 $(SRC)/b0.c

b0-debug: $(SRC)/b0.c $(SRC)/b0.h
	$(CC) $(CFLAGS) -ggdb $(LDFLAGS) -o b0-debug $(SRC)/b0.c
	
clean: 
	rm -f *.o *.asm *.tmp *~ b0-ia32 le le2 test $(EXAMPLE_DIR)/*.asm $(EXAMPLE_DIR)/*~
	
install: b0-ia32
	if ( test ! -d $(PREFIX)/bin ) ; then mkdir -p $(PREFIX)/bin ; fi
	if ( test ! -d $(IPREFIX)/include ) ; then mkdir -p $(IPREFIX)/include ; fi
	if ( test ! -d $(IPREFIX)/include/b0 ) ; then mkdir -p $(IPREFIX)/include/b0 ; fi
	cp -f b0-ia32 $(PREFIX)/bin/b0
	chmod a+x $(PREFIX)/bin/b0-ia32
	cp -f ../../../doc/b0.man $(PREFIX)/man/man1/b0.1
	@echo 
	@echo Please set environment variable BO_INCLUDE=$(IPREFIX)/include/b0
	@echo Note: IA-32 version does not come with stdlib.
	@echo 

uninstall:
	rm -fR $(IPREFIX)/include/b0
	rm -f $(PREFIX)/bin/b0-ia32
	rm -f $(PREFIX)/man/man1/b0.1

test: $(EXAMPLE_DIR)/le.b0 $(EXAMPLE_DIR)/le2.b0 b0-ia32
	./b0-ia32 $(B0_FLAGS) $(EXAMPLE_DIR)/le.b0
	$(AS) $(EXAMPLE_DIR)/le.asm le
	./b0-ia32 $(B0_FLAGS) -UTF8 $(EXAMPLE_DIR)/le2.b0
	$(AS) $(EXAMPLE_DIR)/le2.asm le2
	cp le test
