#qmake code
OBJS=project.o main.o makefile.o unixmake2.o unixmake.o msvc_nmake.o \
     borland_bmake.o mingw_make.o msvc_dsp.o msvc_vcproj.o option.o \
     winmakefile.o projectgenerator.o metrowerks_xml.o pbuilder_pbx.o \
     msvc_objectmodel.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 quuid.o \
       qfileinfo_unix.o qdir_unix.o qfileinfo.o qdatetime.o qstringlist.o qmap.o \
       qconfig.o
vpath %.cpp @SOURCE_PATH@/src/tools:@SOURCE_PATH@/src/codecs:@SOURCE_PATH@/src/kernel:@BUILD_PATH@/src/tools

CFLAGS=@QMAKE_CFLAGS@ \
	-I. -Igenerators -Igenerators/unix -Igenerators/win32 -Igenerators/mac \
	-I@BUILD_PATH@/include/qmake -I@BUILD_PATH@/include -I@SOURCE_PATH@/include \
	-DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_STL \
	-DQT_NO_COMPRESS -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 @BUILD_PATH@/bin/$@
	ln -s @BUILD_PATH@/qmake/$@ @BUILD_PATH@/bin/$@

install: all
	[ -d @QT_INSTALL_BINS@ ] || mkdir -p @QT_INSTALL_BINS@
	-cp -f @BUILD_PATH@/bin/qmake @QT_INSTALL_BINS@
	[ -d @QT_INSTALL_DATA@ ] || mkdir -p @QT_INSTALL_DATA@
	-cp -r -f @SOURCE_PATH@/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) $^

mingw_make.o: mingw_make.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/$(@)
