# Simple, but effective way of recompling the libraries for shared use

MAKE=make
SHELL=/bin/sh

# Use gcc if at all possible.  Sun's regular 4.1.3 cc places read-only
# data in the read-write section of the shared library.  Since the
# read-write segment must be replicated for all processes, this makes
# the library less efficient. 
#  Some people have reported problems using gcc, however I have not been
#  able to reproduce them.
# Define _res to be _res_shlib to avoid a global variable collision on
# _res between the shared libraries and the static resolv library.

COMP=gcc -fpic
#COMP=cc -pic

CC=$(COMP) -DBSD -D_res=_res_shlib

# Take your pick of -g, -O, -g -O.
CDEBUG=-O

# Define LDS to be no command.  This stops ld from mucking with with the
# -pic objects after they are built.
LDS=:

BUILDDIR=../../native.b

NETOBJ=getnetbyaddr.o getnetbyname.o getnetent.o getnetnamadr.o
RESOBJ=gethnamaddr.o herror.o res_comp.o res_debug.o res_init.o \
res_mkquery.o res_query.o res_send.o sethostent.o $(NETOBJ)
COMPATOBJ=inet_addr.o strerror.o

MARGS= "LDS=$(LDS)" "SUBDIRS=shres shcompat" "CC=$(CC)" "CDEBUG=$(CDEBUG)"

all: sundir objects copy

sundir: FRC
	if [ ! -d $(BUILDDIR)/shres ]; then \
		mkdir $(BUILDDIR)/shres; \
		cd $(BUILDDIR)/shres; \
		ln -s ../res/*.c ../res/Makefile .; \
	fi
	if [ ! -d $(BUILDDIR)/shcompat ]; then \
		mkdir $(BUILDDIR)/shcompat $(BUILDDIR)/shcompat/lib; \
		cd $(BUILDDIR)/shcompat; \
		ln -s ../compat/Makefile ../compat/include .; \
		cd lib; \
		ln -s ../../compat/lib/*.c ../../compat/lib/Makefile .; \
	fi

objects: FRC
	(cd $(BUILDDIR); pwd; $(MAKE) $(MARGS) all)

copy: FRC
	for f in $(RESOBJ); do \
		cp $(BUILDDIR)/shres/$$f .; \
	done
	for f in $(COMPATOBJ); do \
		cp $(BUILDDIR)/shcompat/lib/$$f .; \
	done

clean: FRC
	$(RM) *.o

veryclean: clean FRC
	$(RM) -rf $(BUILDDIR)/shres $(BUILDDIR)/shcompat

FRC:
