#
# Makefile for LKCD libraries and utilities
#
# Copyright 2000 Silicon Graphics, Inc. All rights reserved.
#

# Cross Compiling Support
CROSS_COMPILE   =
AS              = $(CROSS_COMPILE)as
LD              = $(CROSS_COMPILE)ld
CC              = $(CROSS_COMPILE)gcc
CPP             = $(CC) -E
AR              = $(CROSS_COMPILE)ar
NM              = $(CROSS_COMPILE)nm
STRIP           = $(CROSS_COMPILE)strip
OBJCOPY         = $(CROSS_COMPILE)objcopy
OBJDUMP         = $(CROSS_COMPILE)objdump
export AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP

all: default

default: check_config subdirs_make

check_config:
	@if [ \! -f .config ] ; then \
		echo "You must run './configure' before running 'make'." ; \
		exit 1 ; \
	fi

-include .config

SUB_DIRS  = scripts libklib liballoc libutil librl libsial lcrash \
	    lkcd_ksyms lkcd_config

subdirs_make:
	for dir in $(SUB_DIRS) ; do \
		( cd $$dir ; \
			make TOPDIR=$(TOPDIR) GFLAGS=$(GFLAGS) \
			ARCH=$(ARCH) LIBSIAL=$(LIBSIAL); cd .. ); \
	done

clean:
	for dir in $(SUB_DIRS) ; do \
		( cd $$dir ; \
			make TOPDIR=$(TOPDIR) GFLAGS=$(GFLAGS) \
			ARCH=$(ARCH) LIBSIAL=$(LIBSIAL) clean; cd .. ); \
	done

clobber: clean
	for dir in $(SUB_DIRS) ; do \
		( cd $$dir ; \
			make TOPDIR=$(TOPDIR) GFLAGS=$(GFLAGS) \
			ARCH=$(ARCH) LIBSIAL=$(LIBSIAL) clobber; cd .. ); \
	done
	/bin/rm -f get_bfd_version

headers:
	for dir in $(SUB_DIRS) ; \
	do \
		( cd $$dir ; make TOPDIR=$(TOPDIR) GFLAGS=$(GFLAGS) \
			ARCH=$(ARCH) LIBSIAL=$(LIBSIAL) headers; cd .. ); \
	done

exports install: headers
	for dir in $(SUB_DIRS) ; \
	do \
		( cd $$dir ; make TOPDIR=$(TOPDIR) GFLAGS=$(GFLAGS) \
			ARCH=$(ARCH) LIBSIAL=$(LIBSIAL) install; cd .. ); \
	done
