# Makefile for a shared build of Jlib for X_WINDOWS and X_320x200x256
# DIRECTIONS:
# If you have the DLL tools on you machine - you just need to ensure you
# have a directory jumpx 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. 

# note: doesn't make the utes or demos yet

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

CFLAGS = $(OPTIMIZE) 

TARGET	= target/x/palette.o target/x/misc.o target/x/blit.o 

TARGETJUMPS	= target/x/palette.jo target/x/misc.jo target/x/blit.jo 

include target/common           

all:	libj.a

clean:
	rm $(TARGET) $(MODULES)

realclean:
	rm $(UTES) $(DEMOS)

# Extra stuff for shared library build
# DLL Jump library config
JUMP_DIR= 	./jumpx
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/ -L/usr/X11R6/lib/ -lX11 -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

.SUFFIXES: .jo

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

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

.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 $*

