#!/bin/sh
#
# Copyright 1997-2000 Trolltech AS.  All rights reserved.
#

VERBOSE=
LIST=
SUBARGS=
SYMLINKS=
while [ -n "$2" ]
do
    case "$1" in
       -v) VERBOSE=1
    ;; -p) LIST=1
	    SUBARGS="$SUBARGS $1"
    ;; -s) SYMLINKS="symlinks "
    esac
    shift
done

PLATFORM=$1

cd ${QTDIR}
unset CPLUS_INCLUDE_DIR
QT_VERSION=`perl -n -e 'if (/#define\s+QT_VERSION\s+(\d)(\d+)/) { $maj=$1; $min=$2; $min =~ s/00/0/; print "$maj.$min\n";}' src/tools/qglobal.h`

if [ -n "$LIST" ] ; then echo Makefile ; fi

exec > Makefile

cat <<EOF
# -*- makefile -*-
#
# Main Makefile for building the Qt library, examples and tutorial.
# Read PORTING for instructions how to port Qt to a new platform.

SHELL=/bin/sh

init: FORCE
	@\$(MAKE) QTDIR=\`pwd\` all

all: $SYMLINKS src-moc src-mt sub-src sub-tools sub-tutorial sub-examples
	@echo
	@echo "The Qt library is now built in ./lib"
	@echo "The Qt examples are built in the directories in ./examples"
	@echo "The Qt tutorials are built in the directories in ./tutorial"
	@echo
	@echo 'Note: be sure to set \$\$QTDIR to point to here or to wherever'
	@echo '      you move these directories.'
	@echo
	@echo "Enjoy!   - the Trolltech team"
	@echo

src-moc: .buildopts $SYMLINKS FORCE
	cd src/moc; \$(MAKE)
	-rm -f bin/moc
	cp src/moc/moc bin/moc

sub-tools: sub-src FORCE
	cd tools; \$(MAKE)

symlinks: .buildopts
	@cd include; rm -f q*.h;  for i in ../src/*/q*.h ../src/3rdparty/*/q*.h ../extensions/*/src/q*.h; do ln -s \$\$i .; done; rm -f q*_p.h

sub-src: src-moc src-mt .buildopts FORCE
	cd src; \$(MAKE)

src-mt: src-moc .buildopts FORCE
	\$(MAKE) -f src-mt.mk

sub-tutorial: sub-src FORCE
	cd tutorial; \$(MAKE)

sub-examples: sub-src FORCE
	cd examples; \$(MAKE)

clean:
	cd src/moc; \$(MAKE) clean
	cd src; \$(MAKE) clean
	-rm src/tmp/*.o src/tmp/*.a src/allmoc.cpp
	-find src/3rdparty -name '*.o' | xargs rm
	cd tutorial; \$(MAKE) clean
	cd examples; \$(MAKE) clean
	cd tools; \$(MAKE) clean

depend:
	cd src; \$(MAKE) depend
	cd tutorial; \$(MAKE) depend
	cd examples; \$(MAKE) depend

.buildopts: Makefile
	@echo
	@echo '  Qt must first be configured using the "configure" script.'
	@echo
	@echo '  The make process will now run this...'
	@echo
	@./configure -frommake

dep: depend

FORCE:


EOF
