SHELL := /bin/bash
PACKAGING_DIR := $(shell cd ..; pwd)
PATH := $(PATH):$(shell pwd)/build
TDE_VERSION = 3.5.13.2

buildpkg = \
  @echo "Now processing '$(1)' [from $(PACKAGING_DIR)]."; \
  export PACKAGING_DIR=$(PACKAGING_DIR); \
  if [ "${REBUILD}" = "$(1)" ] || ! is_latest_package_installed.sh "$(1)" ${TDE_VERSION}; then \
    echo "  Package '${1}' is not yet installed."; \
    if [ "${REBUILD}" = "$(1)" ] || ! is_latest_package_built.sh "$(1)" ${TDE_VERSION}; then \
      echo "  Building package."; \
      build_rpm_package.sh "$(1)" ${TDE_VERSION} || exit 1; \
      echo "  Updating repository."; \
      update_repository.sh ${TDE_VERSION}; \
    fi; \
    echo "Now installing package '$(1)'"; \
    install_rpm_package.sh "$(1)" || exit 2; \
  fi; \
  echo


all:	dependencies main libraries applications i18n meta extras
dependencies:	qt3 tqtinterface arts libcaldav libcarddav tqca tqca-tls avahi-tqt dbus-tqt dbus-1-tqt akode hal
main:	tdelibs tdebase tdeaccessibility tdeadmin tdegames tdemultimedia tdepim tdetoys tdevelop tdeaddons tdeartwork tdebindings tdeedu tdegraphics tdenetwork tdesdk tdeutils tdewebdev
libraries:	libkdcraw libkexiv2 libkipi libksquirrel pytdeextensions python-trinity
applications:	abakus amarok basket bibletime digikam dolphin filelight gtk-qt-engine gwenview k3b k9copy kaffeine kaffeine-mozilla katapult kbarcode kbfx kbookreader kchmviewer kcmautostart kcpuload kdbusnotification kdiff3 kdirstat kgtk-qt3 keep kile kima kiosktool kmplayer kmyfirewall kmymoney knemo knetload knetstats knights knowit knutclient koffice konversation kopete-otr kpicosim kpilot kpowersave krename krusader ksplash-engine-moodin ksquirrel kstreamripper ksystemlog ktechlab ktorrent kuickshow kvirc kvkbd piklab potracegui rosegarden smartcardauth smb4k soundkonverter tde-guidance tdeio-apt tdeio-locate tdeio-umountwrapper tderadio tde-style-lipstik tde-style-qtcurve tdesudo tdesvn tde-systemsettings tdmtheme tellico twin-style-crystal wlassistant yakuake
i18n:	gwenview-i18n k3b-i18n koffice-i18n tde-i18n


### Trinity Dependencies
arts:	tqtinterface trinity-filesystem esound cmake
	$(call buildpkg,dependencies/arts)

avahi-tqt:	tqtinterface autoconf automake libtool
	$(call buildpkg,dependencies/avahi-tqt)

dbus-1-tqt:	tqtinterface cmake
	$(call buildpkg,dependencies/dbus-1-tqt)

dbus-tqt: tqtinterface cmake
	$(call buildpkg,dependencies/dbus-tqt)

libcaldav: tqtinterface autoconf libcurl
	$(call buildpkg,dependencies/libcaldav)

libcarddav:	tqtinterface autoconf libcurl
	$(call buildpkg,dependencies/libcarddav)
	
tqca:	tqtinterface
	$(call buildpkg,dependencies/tqca)

tqca-tls: tqtinterface tqca
	$(call buildpkg,dependencies/tqca-tls)

qt3: esound
	$(call buildpkg,dependencies/qt3)

tqtinterface:	qt3 cmake
	$(call buildpkg,dependencies/tqtinterface)

# Main packages
tdeaccessibility:	tdebase tdemultimedia
	$(call buildpkg,main/tdeaccessibility)

tdeaddons:	tdebase tdegames tdemultimedia tdenetwork tdepim
	$(call buildpkg,main/tdeaddons)

tdeadmin:	tdebase
	$(call buildpkg,main/tdeadmin)

tdeartwork:	tdebase
	$(call buildpkg,main/tdeartwork)

tdebase:	tdelibs cmake htdig fileshareset hal
	$(call buildpkg,main/tdebase)

tdebindings:	tdebase
	$(call buildpkg,main/tdebindings)

tdeedu:	tdebase
	$(call buildpkg,main/tdeedu)

tdegames:	tdebase tdemultimedia
	$(call buildpkg,main/tdegames)

tdegraphics:	tdebase poppler cmake
	$(call buildpkg,main/tdegraphics)

tdelibs:	qt3 tqtinterface arts dbus-tqt dbus-1-tqt cmake avahi-tqt fileshareset trinity-filesystem
	$(call buildpkg,main/tdelibs)

tdemultimedia:	tdebase akode
	$(call buildpkg,main/tdemultimedia)

tdenetwork:	tdebase
	$(call buildpkg,main/tdenetwork)

tdepim:	tdebase libcaldav libcarddav cmake
	$(call buildpkg,main/tdepim)

tdesdk:		tdebase tdebindings cmake
	$(call buildpkg,main/tdesdk)

tdetoys:	tdebase
	$(call buildpkg,main/tdetoys)

tdeutils:	tdebase
	$(call buildpkg,main/tdeutils)

tdevelop:	tdebase tdesdk cmake
	$(call buildpkg,main/tdevelop)

tdewebdev:	tdebase tdesdk
	$(call buildpkg,main/tdewebdev)

### 3rd party libraries and tools
autoconf: m4
# Build on CentOS 5 only
ifneq ($(wildcard /boot/vmlinuz*.el5*),)
	$(call buildpkg,3rdparty/autoconf)
endif

automake:
# Build on CentOS 5 only
ifneq ($(wildcard /boot/vmlinuz*.el5*),)
	$(call buildpkg,3rdparty/automake)
endif

cmake:
# Build on CentOS 5/6 only
ifneq ($(wildcard /boot/vmlinuz*.el5* /boot/vmlinuz*.el6*),)
	$(call buildpkg,3rdparty/cmake)
endif

esound:
# Build on Mageia and CentOS >= 7
ifneq ($(wildcard /etc/mageia-release /boot/vmlinuz*.el7*),)
	$(call buildpkg,3rdparty/esound)
endif

gnuchess:
# Build on CentOS 5, CentOS 7
ifneq ($(wildcard /boot/vmlinuz*.el5* /boot/vmlinuz*.el7*),)
	$(call buildpkg,3rdparty/gnuchess)
endif

hal: hal-info
# Do NOT build on CentOS 5, CentOS 6
ifeq ($(wildcard /boot/vmlinuz*.el5* /boot/vmlinuz*.el6*),)
	$(call buildpkg,3rdparty/hal)
endif

hal-info:
# Do NOT build on CentOS 5, CentOS 6
ifeq ($(wildcard /boot/vmlinuz*.el5* /boot/vmlinuz*.el6*),)
	$(call buildpkg,3rdparty/hal-info)
endif

htdig:
# build on Mageia, and CentOS >= 7
ifneq ($(wildcard /etc/mageia-release /boot/vmlinuz*.el7*),)
	$(call buildpkg,extras/htdig)
endif

imlib1:
# Do NOT build on Fedora, nor CentOS
ifeq ($(wildcard /etc/fedora-release),)
ifeq ($(wildcard /etc/centos-release),)
ifeq ($(wildcard /boot/vmlinuz*.el5*),)
	$(call buildpkg,3rdparty/imlib1)
endif
endif
endif

libcurl: automake libtool
# Build on CentOS 5 only
ifneq ($(wildcard /boot/vmlinuz*.el5*),)
	$(call buildpkg,3rdparty/curl)
endif

libotr3:
# Build on Mageia, CentOS >= 7
ifneq ($(wildcard /etc/mageia-release /boot/vmlinuz*.el7*),)
	$(call buildpkg,3rdparty/libotr3)
endif

libtool: autoconf automake
# Build on CentOS 5 only
ifneq ($(wildcard /boot/vmlinuz*.el5*),)
	$(call buildpkg,3rdparty/libtool)
endif

lilypond: mftrace
# Build on CentOS 6 only
ifneq ($(wildcard /boot/vmlinuz*.el6*),)
	$(call buildpkg,3rdparty/lilypond)
endif

m4:
# Build on CentOS 5 only (vendor-provided m4 is too old)
ifneq ($(wildcard /boot/vmlinuz*.el5*),)
	$(call buildpkg,3rdparty/m4)
endif

mftrace:
# Build on CentOS 6 only
ifneq ($(wildcard /boot/vmlinuz*.el6*),)
	$(call buildpkg,3rdparty/mftrace)
endif

pcsc-perl:
# Build on CentOS and openSUSE only
ifneq ($(wildcard /etc/centos-release /etc/SuSE-release /boot/vmlinuz*.el5*),)
	$(call buildpkg,3rdparty/pcsc-perl)
endif

poppler:
# Build on CentOS 5 only (vendor-provided Poppler is too old)
ifneq ($(wildcard /boot/vmlinuz*.el5*),)
	$(call buildpkg,3rdparty/poppler)
endif

python-qt3: tdelibs sip
	$(call buildpkg,3rdparty/python-qt3)

sip:
# Build on CentOS 5 only (vendor-provided SIP is too old)
ifneq ($(wildcard /boot/vmlinuz*.el5*),)
	$(call buildpkg,3rdparty/sip)
endif

sword:
# Build on Fedora >= 20, PCLinuxOS, CentOS >= 7
ifneq ($(wildcard /boot/vmlinuz*.fc20* /etc/pclinuxos-release /boot/vmlinuz*.el7*),)
	$(call buildpkg,3rdparty/sword)
endif

wv2:
# Do NOT build on Mageia or openSUSE or PCLINUXOS
ifeq ($(wildcard /etc/mageia-release /etc/SuSE-release /etc/pclinuxos-release),)
	$(call buildpkg,3rdparty/wv2)
endif

### Extra packages
akode:	tqtinterface
	$(call buildpkg,extras/akode)

cmake-macros: cmake
ifneq ($(wildcard /etc/SuSE-release),)
	$(call buildpkg,extras/trinity-cmake-macros)
endif

### Trinity Libraries
kipi-plugins:	tqtinterface libkipi
	$(call buildpkg,libraries/kipi-plugins)

libkdcraw:	tqtinterface
	$(call buildpkg,libraries/libkdcraw)

libkexiv2:	tqtinterface
	$(call buildpkg,libraries/libkexiv2)

libkipi:	tqtinterface
	$(call buildpkg,libraries/libkipi)

libksquirrel:	tqtinterface
	$(call buildpkg,libraries/libksquirrel)

mlt:	tqtinterface
	$(call buildpkg,libraries/mlt)

pytdeextensions:	tqtinterface python-trinity
	$(call buildpkg,libraries/pytdeextensions)

python-trinity:	tqtinterface python-qt3
	$(call buildpkg,libraries/python-trinity)

### Trinity Applications
abakus:	tdebase
	$(call buildpkg,applications/abakus)

adept:	tdebase
	$(call buildpkg,applications/adept)

amarok:	tdebase cmake
	$(call buildpkg,applications/amarok)

basket:	tdebase
	$(call buildpkg,applications/basket)

bibletime:	tdebase sword
	$(call buildpkg,applications/bibletime)

compizconfig-backend-kconfig:	tdebase
	$(call buildpkg,applications/compizconfig-backend-kconfig)

desktop-effects-tde:	tdebase
	$(call buildpkg,applications/desktop-effects-tde)

digikam:	tdebase libkdcraw libkexiv2 libkipi libksquirrel
	$(call buildpkg,applications/digikam)

dolphin:	tdebase
	$(call buildpkg,applications/dolphin)

filelight:	tdebase
	$(call buildpkg,applications/filelight)

filelight-l10n:	tdebase
	$(call buildpkg,applications/filelight-l10n)

fusion-icon:	tdebase
	$(call buildpkg,applications/fusion-icon)

gtk-qt-engine:	tdebase
# Do NOT build on CentOS 5 (GTK2 is too old)
ifeq ($(wildcard /boot/vmlinuz*.el5*),)
	$(call buildpkg,applications/gtk-qt-engine)
endif

gwenview:	tdebase
	$(call buildpkg,applications/gwenview)

k3b:	tdebase
	$(call buildpkg,applications/k3b)

k9copy:	tdebase k3b
	$(call buildpkg,applications/k9copy)

kaffeine:	tdebase
	$(call buildpkg,applications/kaffeine)

kaffeine-mozilla:	tdebase kaffeine
	$(call buildpkg,applications/kaffeine-mozilla)

katapult:	tdebase
	$(call buildpkg,applications/katapult)

kbarcode:	tdebase
	$(call buildpkg,applications/kbarcode)

kbfx:	tdebase
	$(call buildpkg,applications/kbfx)

kbookreader:	tdebase
	$(call buildpkg,applications/kbookreader)

kchmviewer:	tdebase
	$(call buildpkg,applications/kchmviewer)

kcmautostart:	tdebase
	$(call buildpkg,applications/kcmautostart)

kcpuload:	tdebase
	$(call buildpkg,applications/kcpuload)

kdbusnotification:	tdebase
	$(call buildpkg,applications/kdbusnotification)

kdiff3:	tdebase
	$(call buildpkg,applications/kdiff3)

kdirstat:	tdebase
	$(call buildpkg,applications/kdirstat)

kdpkg:	tdebase
	$(call buildpkg,applications/kdpkg)

keep:	tdebase
	$(call buildpkg,applications/keep)

kerry:	tdebase
	$(call buildpkg,applications/kerry)

kgtk-qt3:	tdebase
# Do NOT build on CentOS 5 (GTK2 is too old)
# Do NOT build on CentOS >=7 (GTK2 is too new)
# Do NOT build on Fedora >= 20 (GTK2 is too new)
# Do NOT build on Mageia >= 4 (GTK2 is too new)
ifeq ($(wildcard /boot/vmlinuz*.el5* /boot/vmlinuz*.el7* /boot/vmlinuz*.fc20* /boot/vmlinuz*.mga4*),)
	$(call buildpkg,applications/kgtk-qt3)
endif

kile:	tdebase
	$(call buildpkg,applications/kile)

kima:	tdebase
	$(call buildpkg,applications/kima)

kiosktool:	tdebase
	$(call buildpkg,applications/kiosktool)

kmplayer:	tdebase
	$(call buildpkg,applications/kmplayer)

kmyfirewall:	tdebase
	$(call buildpkg,applications/kmyfirewall)

kmymoney:	tdebase
	$(call buildpkg,applications/kmymoney)

knemo:	tdebase
	$(call buildpkg,applications/knemo)

knetload:	tdebase
	$(call buildpkg,applications/knetload)

knetstats:	tdebase
	$(call buildpkg,applications/knetstats)

knetworkmanager8:	tdebase
	$(call buildpkg,applications/knetworkmanager8)

knights:	tdebase gnuchess
	$(call buildpkg,applications/knights)

knowit:	tdebase
	$(call buildpkg,applications/knowit)

knutclient:	tdebase
	$(call buildpkg,applications/knutclient)

koffice:	tdebase wv2
	$(call buildpkg,applications/koffice)

konversation:	tdebase
	$(call buildpkg,applications/konversation)

kopete-otr:	tdebase libotr3
	$(call buildpkg,applications/kopete-otr)

kpicosim:	tdebase
	$(call buildpkg,applications/kpicosim)

kpilot:	tdebase
# Do NOT build on CentOS 5 (pilot-link library is too old)
ifeq ($(wildcard /boot/vmlinuz*.el5*),)
	$(call buildpkg,applications/kpilot)
endif

kpowersave:	tdebase
	$(call buildpkg,applications/kpowersave)

krename:	tdebase
	$(call buildpkg,applications/krename)

krusader:	tdebase
	$(call buildpkg,applications/krusader)

ksplash-engine-moodin:	tdebase
	$(call buildpkg,applications/ksplash-engine-moodin)

ksquirrel:	tdebase libksquirrel
	$(call buildpkg,applications/ksquirrel)

kstreamripper:	tdebase
	$(call buildpkg,applications/kstreamripper)

ksystemlog:	tdebase
	$(call buildpkg,applications/ksystemlog)

ktechlab:	tdebase
	$(call buildpkg,applications/ktechlab)

ktorrent:	tdebase
	$(call buildpkg,applications/ktorrent)

kuickshow:	tdebase imlib1
	$(call buildpkg,applications/kuickshow)

kvirc:	tdebase
	$(call buildpkg,applications/kvirc)

kvkbd:	tdebase
	$(call buildpkg,applications/kvkbd)

piklab:	tdebase
	$(call buildpkg,applications/piklab)

potracegui:	tdebase
	$(call buildpkg,applications/potracegui)

rosegarden:	tdebase lilypond
# Do NOT build on CentOS 5, CentOS 7
ifeq ($(wildcard /boot/vmlinuz*.el5* /boot/vmlinuz*.el7*),)
	$(call buildpkg,applications/rosegarden)
endif

smartcardauth:	tdebase pcsc-perl
	$(call buildpkg,applications/smartcardauth)

smb4k:	tdebase
	$(call buildpkg,applications/smb4k)

soundkonverter:	tdebase
	$(call buildpkg,applications/soundkonverter)

tde-guidance:	tdebase pytdeextensions
	$(call buildpkg,applications/tde-guidance)

tdeio-apt:	tdebase
	$(call buildpkg,applications/tdeio-apt)

tdeio-locate:	tdebase
	$(call buildpkg,applications/tdeio-locate)

tdeio-umountwrapper:	tdebase
	$(call buildpkg,applications/tdeio-umountwrapper)

tderadio:	tdebase
# Do NOT build on CentOS 7
ifeq ($(wildcard /boot/vmlinuz*.el7*),)
	$(call buildpkg,applications/tderadio)
endif

tde-style-lipstik:	tdebase
	$(call buildpkg,applications/tde-style-lipstik)

tde-style-qtcurve:	tdebase
	$(call buildpkg,applications/tde-style-qtcurve)

tdesudo:	tdebase
	$(call buildpkg,applications/tdesudo)

tdesvn:	tdebase
	$(call buildpkg,applications/tdesvn)

tde-systemsettings:	tdebase
	$(call buildpkg,applications/tde-systemsettings)

tdmtheme:	tdebase
	$(call buildpkg,applications/tdmtheme)

tellico:	tdebase
	$(call buildpkg,applications/tellico)

twin-style-crystal:	tdebase
	$(call buildpkg,applications/twin-style-crystal)

wlassistant:	tdebase
	$(call buildpkg,applications/wlassistant)

yakuake:	tdebase
	$(call buildpkg,applications/yakuake)

### Trinity Translations
gwenview-i18n:	tdebase
	$(call buildpkg,applications/gwenview-i18n)

k3b-i18n:	tdebase
	$(call buildpkg,applications/k3b-i18n)

koffice-i18n:	tdebase
	$(call buildpkg,applications/koffice-i18n)

tde-i18n:	tdebase cmake
	$(call buildpkg,tde-i18n)

### Meta packages
meta:
	$(call buildpkg,extras/trinity-desktop)

### Extra packages
fileshareset:
	$(call buildpkg,extras/fileshareset)

trinity-filesystem:
	$(call buildpkg,extras/trinity-filesystem)

ksensors:
	$(call buildpkg,applications/ksensors)