# === GNUmakefile =============================================================
# Copyright (c) 1991, 1992, 1993 Chris Provenzano, proven@athena.mit.edu
#
#	Description: This file is for creating libpthread.a
#
#	1.00 93/11/17 proven
#		-Put all the .o files into one file libpthread.a
#		-Initial cut for pthreads.
#

INSTALL_PATH = $(exec_prefix)

      BINDIR = $(INSTALL_PATH)/bin
      LIBDIR = $(INSTALL_PATH)/lib
      MANDIR = $(INSTALL_PATH)/man
      INCDIR = $(INSTALL_PATH)/include
   SUBINCDIR = $(INCDIR)/pthread

          AR = ar
          AS = gas
      CFLAGS = -g -O -Iinclude -I$(srcdir)/include -DPTHREAD_KERNEL
 CDEBUGFLAGS = -g -DDEBUG		# -g, -O, -DDEBUG
          LD = gld

        CSRC =

 PTHREAD_DIR = pthreads stdlib stdio gen
        DIRS = $(PTHREAD_DIR)

     HEADERS =

   LIBRARIES = libpthread.a

###############################################################################
#
# Read in any special flags that config knows about
include config.flags

################################################################################
#
# Here starts the nitty grity part of the Makefile.

all: $(LIBRARIES) bin

include ${srcdir}/pthreads/GNUmakefile.inc
include ${srcdir}/stdlib/GNUmakefile.inc
include ${srcdir}/stdio/GNUmakefile.inc
include ${srcdir}/gen/GNUmakefile.inc
include ${srcdir}/scripts/GNUmakefile.inc

REGULAR_OBJS= $(subst .cc,.o,$(SRCS))
REGULAR_OBJS:= $(subst .c,.o,$(REGULAR_OBJS))
REGULAR_OBJS:= $(subst .S,.o,$(REGULAR_OBJS))
OBJS= $(REGULAR_OBJS) $(EXTRA_OBJS)
REALOBJS = $(addprefix obj/, $(OBJS))

clean: 
	rm -f a.out core maketmp makeout $(LIBRARIES) $(BINARIES) libpthread.*
	rm -rf obj
	cd tests && $(MAKE) clean && cd ..

install-dirs:
	for d in $(INSTALL_PATH) $(BINDIR) $(LIBDIR) $(INCDIR) $(MANDIR) ; do \
	  test -d $(DESTDIR)$$d || mkdir $(DESTDIR)$$d || exit 1 ; \
	done

install-lib: $(LIBRARIES) install-dirs
	for x in $(LIBRARIES); \
	do install $$x $(DESTDIR)$(LIBDIR); \
	done

install-include: config.status install-dirs
	(cd ${srcdir}/include && tar cf - .)|(cd $(DESTDIR)$(INCDIR) && tar xf -)
	(cd include && tar cfh - .)|(cd $(DESTDIR)$(INCDIR) && tar xf -)

install-bin: bin install-dirs
	for x in $(SCRIPTS) ; do \
	  install $$x $(DESTDIR)$(BINDIR); \
	done

install: install-lib install-include install-bin

realclean: clean
	cd tests && $(MAKE) realclean && cd ..
	rm -f $(LINKS) config.status config.flags config.cache

libpthread.a: ${REALOBJS}
	rm -f new.a libpthread.a
	cd obj && ar r ../new.a ${OBJS} && cd ..
	ranlib new.a
	mv -f new.a libpthread.a

# For examining a combined symbol table, sizes, &c.
libpthread.o: ${REALOBJS}
	cd obj && ld -r -o ../libpthread.o ${OBJS} && cd ..

obj/x:
	if [ -d obj ]; then true; else mkdir obj; fi
	cp /dev/null obj/x

config.status: ${srcdir}/configure
	${srcdir}/configure
GNUmakefile: config.status ${srcdir}/config/GNUmakefile.in
	$(SHELL) config.status
config.flags: config.status ${srcdir}/config/config.flags.in
	$(SHELL) config.status

obj/%.o: %.c obj/x
	$(CC) $(CFLAGS) -c $< -o $@

obj/%.o: %.cc
	$(CXX) $(CXXFLAGS) -c $< -o $@

obj/%.o: %.S
	$(CC) $(CFLAGS) -c $< -o $@
