# To cross compile, override one or more of CC, AR, CROSS_CFLAGS,
# LOADLIBES, LDFLAGS, & LIB_DIR and be sure to always build from the top level.
#
# To override them from the make commandline, do something like this:
# $ CROSS_COMPILER=/opt/cegl-1.4/hardhat/devkit/ppc/405/bin/powerpc-linux-
# $ make \
#     CROSS_CFLAGS="-mcpu=403 -D__PPC405__" \
#     LDFLAGS=-static \
#     LOADLIBES="-lpthread -lc -lresolv -lnss_dns -lnss_files -lm -lc"
#
# Alternately, to override them by editing this file, uncomment the 
# following lines:
#   CROSS_COMPILER=/opt/ppc64/powerpc64-linux/bin/powerpc64-linux-
#   CROSS_CFLAGS= -mpowerpc64
#   LDFLAGS=-static 
#   LOADLIBES=-lpthread -lc -lresolv -lnss_dns -lnss_files -lm -lc
#   LIB_DIR=/lib64
#   export LOADLIBES LIB_DIR
#
# Or, you can save all your settings into the local 'config.mk' file.
# The defaults will not be usable in that case; you will need to
# override things explicitly.
#
# uClinux Users: make sure you add -DUCLINUX to your CFLAGS
#
# Note: If you override a variable from the commandline all
# assignments to it in the Makefiles will be ignored. To set it both 
# in the commandline and in the Makefiles use a dummy variable like in
# CFLAGS

export CFLAGS += -Wall $(CROSS_CFLAGS)

include config.mk

PRIM_TARGETS = pan tools testcases

.PHONY: all clean install menuconfig pan preinstall print-install testcases tools

all: $(PRIM_TARGETS) print-install ;

clean:
	@for dir in lib $(PRIM_TARGETS); do \
		$(MAKE) -C $$dir $@; \
	done

install: all
	@for dir in doc/man1 doc/man3 include lib $(PRIM_TARGETS); do \
		$(MAKE) -C $$dir bindir=$(bindir) libdir=$(libdir) prefix=$(prefix) srcdir=$(srcdir) UCLINUX=$(UCLINUX) $@; \
	 done
#	@cd $(prefix) && $(srcdir)/IDcheck.sh

pan testcases tools: lib/libltp.a

lib/libltp.a: preinstall
	@set -e; $(MAKE) -C $(@D) bindir=$(bindir) libdir=$(libdir) prefix=$(prefix) srcdir=$(srcdir) UCLINUX=$(UCLINUX) $(@F)

menuconfig:
	@./ltpmenu

package: 
	rpmbuild -ba ltp-devel.spec

print-install:
	@echo ""
	@echo "***********************************************"
	@echo "** You now need to do a make install as root **"
	@echo "***********************************************"
	@echo

$(PRIM_TARGETS):
	@set -e; $(MAKE) -C $@ bindir=$(bindir) libdir=$(libdir) prefix=$(prefix) srcdir=$(srcdir) UCLINUX=$(UCLINUX);
