

#qmake code
OBJS=project.o main.o makefile.o unixmake2.o unixmake.o borland_bmake.o msvc_nmake.o msvc_dsp.o option.o winmakefile.o \
     projectgenerator.o metrowerks_xml.o
vpath %.cpp generators/:generators/win32:generators/unix:generators/mac

#qt code
QTOBJS=qstring.o qtextstream.o qiodevice.o qglobal.o qgdict.o qcstring.o qdatastream.o qgarray.o qbuffer.o qglist.o \
	qptrcollection.o qfile.o qfile_unix.o qregexp.o qgvector.o qgcache.o qbitarray.o qdir.o \
	qfileinfo_unix.o qdir_unix.o qfileinfo.o qdatetime.o qstringlist.o qmap.o
vpath %.cpp @REL_QTDIR@/src/tools @REL_QTDIR@/src/codecs @REL_QTDIR@/src/kernel

CFLAGS=@QMAKE_CFLAGS@ -I. -Igenerators -Igenerators/unix -Igenerators/win32  -Igenerators/mac \
	-I@OUT_QTDIR@/include -I@REL_QTDIR@/include -I@OUT_QTDIR@/src/tools -DQT_NO_TEXTCODEC -DQT_NO_COMPONENT -DQT_NO_STL -I@QMAKESPEC@
LFLAGS=@QMAKE_LFLAGS@

#if cc isn't gcc I need to use the bad makefile
ifeq ($(CC),gcc)
all: qmake
DEPDIR:=$(shell [ -d .deps/ ] || mkdir -p .deps/)
-include $(OBJS:.o=.dep)
else
all: uqmake
endif

uqmake:
	$(MAKE) -f Makefile qmake

qmake: $(OBJS) $(QTOBJS)
	$(CXX) -o $@ $^ $(LFLAGS)
	rm -f @OUT_QTDIR@/bin/$@
	ln -s $(shell pwd)/$@ @OUT_QTDIR@/bin/$@

install: all
	[ -d @QT_INSTALL_BINS@ ] || mkdir -p @QT_INSTALL_BINS@
	cp -f @OUT_QTDIR@/bin/qmake @QT_INSTALL_BINS@
	cp -r -f @REL_QTDIR@/mkspecs @QT_INSTALL_PREFIX@

clean::
	rm -f $(OBJS) $(QTOBJS)

distclean:: clean
	rm -rf qmake .deps

# don't use optimization for these
projectgenerator.o: projectgenerator.cpp
	$(CXX) -c -o $@ $(CFLAGS) $^

makefile.o: makefile.cpp
	$(CXX) -c -o $@ $(CFLAGS) $^

metrowerks_xml.o: metrowerks_xml.cpp
	$(CXX) -c -o $@ $(CFLAGS) $^

unixmake2.o: unixmake2.cpp
	$(CXX) -c -o $@ $(CFLAGS) $^

unixmake.o: unixmake.cpp
	$(CXX) -c -o $@ $(CFLAGS) $^

borland_bmake.o: borland_bmake.cpp
	$(CXX) -c -o $@ $(CFLAGS) $^

msvc_nmake.o: msvc_nmake.cpp
	$(CXX) -c -o $@ $(CFLAGS) $^

msvc_dsp.o: msvc_dsp.cpp
	$(CXX) -c -o $@ $(CFLAGS) $^

#default rules
%.o: %.c
	$(CC) -c -o $@ $(CFLAGS) $^

%.o: %.cpp
	$(CXX) -c -o $@ $(CFLAGS) $^

%.dep: %.c
	@$(CC) -M $(CFLAGS) $(<) > .deps/$(@)

%.dep: %.cpp
	@$(CXX) -M $(CFLAGS) $(<) > .deps/$(@)
