LIBNAME=fix!.so
LIBFILES = sigfix.o tcfix.o statfix.o dirfix.o
CFLAGS  = -O2 -W -Wall -Wno-parentheses -Wno-unused -mtune=601 -mno-string
CFLAGS += -mmultiple -msdata=sysv -G9999 
LDFLAGS = -s -G9999
CC=gcc
iroot=/
REQSYMS=__umoddi3 __udivdi3 __ashldi3 __divdi3 __lshrdi3 __moddi3

all: fixrelent fixrelent-static $(LIBNAME) $(LIBNAME)-old rename

elfload.o : elfload.c
fixrelent.o : fixrelent.c

fixrelent fixrelent-static : fixrelent.o elfload.o
fixbang : fixbang.c

$(LIBFILES) : %.o : %.c
	$(COMPILE.c) -msdata=none -fpic $< $(OUTPUT_OPTION)

fixrelent-static :
	$(LINK.o) -static $^ $(OUTPUT_OPTION)

rename : rename.o
	$(LINK.o) -nostartfiles -static $^ $(OUTPUT_OPTION)

$(LIBNAME) : $(LIBFILES) setjmp.o fixbang v.map
	$(LINK.o) -shared -Wl,--version-script=v.map $(filter %.o,$^) \
	  -Wl,-u,`echo $(REQSYMS) | sed 's/ /,-u,/g'` \
	  -Wl,-soname=$@ -o $@.T
	./fixbang $@.T
	mv $@.T $@

$(LIBNAME)-old : nofix.o fixbang v.map
	$(LINK.o) -shared -Wl,--version-script=v.map $(filter %.o,$^) \
	  -Wl,-soname=$@ -o $@.T
	./fixbang $@.T
	mv $@.T $@

clean:
	rm -f *.o fixbang
	rm -f fixrelent fixrelent-static $(LIBNAME) $(LIBNAME)-old rename

install: $(LIBNAME) fixrelent rename
	install -s $(LIBNAME) $(iroot)lib
	install -s rename $(iroot)usr/bin/rename
	install -s fixrelent $(iroot)usr/bin/fix961212

install-old: $(LIBNAME) $(LIBNAME)-old fixrelent-static rename
	install -s $(LIBNAME)-old $(iroot)lib/
	install -s $(LIBNAME) $(iroot)lib/$(LIBNAME)-new
	install -s fixrelent-static $(iroot)usr/bin/fix961212
	install -s rename $(iroot)usr/bin/rename
	ln -s $(LIBNAME)-new $(iroot)lib/$(LIBNAME)
