

#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 pbuilder_pbx.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@
CXXFLAGS= $(CFLAGS)
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 @OUT_QTDIR@/qmake/$@ @OUT_QTDIR@/bin/$@

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

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

distclean:: clean
	rm -rf qmake .deps

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

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

pbuilder_pbx.o: pbuilder_pbx.cpp 
	$(CXX) -c -o $@ $(CXXFLAGS) $^

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

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

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

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

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

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

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

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

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

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