# Makefile for a shared build of Jlib for LINUX_SVGALIB and MODE_13H
# DIRECTIONS:
# If you have the DLL tools on you machine - you just need to ensure you
# have a directory jump in your source directory,  then do:
# make PASS1
# remove all the .jo files:
# find . -name "*.jo" -exec rm {} \; from your source directory
# make PASS2
# make libj.sa

# ... and you should have a shared library.
# Mike

# if you think you can save some compiling time by omitting -O3 - DONT!
# the inlined string.h functions for Linux don't seem to work without it. 

# p.s this makefile doesn't make the demos or utes yet ...

AR	 = ar
CC	 = gcc
OPTIMIZE = -fomit-frame-pointer -O3 -finline-functions -fstrength-reduce    \
           -fforce-mem -fforce-addr -funroll-loops -frerun-cse-after-loop   \
           -m486

CFLAGS = $(OPTIMIZE) 

TARGET	= target/linux13h/blit.o target/linux13h/kb.o    \
	  target/linux13h/misc.o target/linux13h/mouse.o \
	  target/linux13h/palette.o 

TARGETJUMPS	= target/linux13h/blit.jo target/linux13h/kb.jo    \
	  target/linux13h/misc.jo target/linux13h/mouse.jo \
	  target/linux13h/palette.jo 

include target/common

all:	libj.a

clean:
	rm $(MODULES) $(TARGET)

realclean:
	rm $(UTES) $(DEMOS)

# Extra stuff for shared library build
# DLL Jump library config
JUMP_DIR=   ./jump
JUMP_LIB=   libj
LOAD_ADDR=  0xA0000000
JUMP_TABLE_SIZE=  0x4000
GOT_SIZE=   0x4000
JCFLAGS=    $(CFLAGS) -B/usr/dll/jump/
JLIBS=      $(LIBS) -L/usr/lib/gcc-lib/i486-linux/2.6.3/ -lvgagl -lvga -lgcc -lc
#Version Number
MAJVER=     0
MINVER=     1
PATVER=     0

libj.sa: $(JUMPOBJS) $(TARGETJUMPS)
	(JUMP_DIR=$(JUMP_DIR);export JUMP_DIR;\
	JUMP_LIB=$(JUMP_LIB);export JUMP_LIB;\
	mkimage -f -l libj -a$(LOAD_ADDR) -v$(MAJVER).$(MINVER).$(PATVER)\
		-j$(JUMP_TABLE_SIZE) -g$(GOT_SIZE) -- $(JUMPOBJS) $(JLIBS) )
	(JUMP_DIR=$(JUMP_DIR);export JUMP_DIR;\
	JUMP_LIB=$(JUMP_LIB);export JUMP_LIB;\
	mkstubs -l libj -a$(LOAD_ADDR) -v$(MAJVER).$(MINVER).$(PATVER)\
		-j$(JUMP_TABLE_SIZE) -g$(GOT_SIZE) -- libj )

PASS1: $(JUMPOBJS) $(TARGETJUMPS)
	(JUMP_DIR=$(JUMP_DIR);export JUMP_DIR;\
	JUMP_LIB=$(JUMP_LIB);export JUMP_LIB;\
	getvars;\
	getfuncs)
	rm $(JUMP_DIR)/jump.log

PASS2: $(JUMPOBJS) $(TARGETJUMPS)
	(JUMP_DIR=$(JUMP_DIR);export JUMP_DIR;\
	JUMP_LIB=$(JUMP_LIB);export JUMP_LIB;\
	getsize > $(JUMP_DIR)/jump.vars.new)
	mv $(JUMP_DIR)/jump.vars $(JUMP_DIR)/jump.vars.keep
	mv $(JUMP_DIR)/jump.vars.new $(JUMP_DIR)/jump.vars

libj.a: $(MODULES) $(TARGET)
	rm -f libj.a
	$(AR) rcs libj.a $(MODULES)

%.jo:%.c
	(JUMP_DIR=$(JUMP_DIR);export JUMP_DIR;\
	JUMP_LIB=$(JUMP_LIB);export JUMP_LIB;\
	$(CC) -c $(JCFLAGS) $(INCLUDES) $*.c -o $*.jo)

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

.S.s:
	$(CC) $(CFLAGS) -x c++ -E $< >$@

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

.c.s:
	$(CC) $(CFLAGS) -S -o $*.s $<

.o:
	$(CC) $(CFLAGS) $(LFLAGS) -o $* $*.o $(LIBS)
	chmod a+rs,go-w $*

