PACKAGE=nuu
VERSION=2.2
REL=1

ARCH=$(shell if [ -r /etc/SuSE-release ] && [ "$$(uname -i)" = "i386" ]; then \
                echo "i586";                                                  \
             elif [ "$$(uname -i)" = "unknown" ]; then                        \
                uname -m;                                                     \
             else                                                             \
                uname -i;                                                     \
             fi)

DISTRO=$(shell if [ -r /etc/redhat-release ]; then \
                  sed -e 's/^Red Hat Enterprise Linux .* release \(.*\) (.*)$$/rhel\1/' \
                      -e 's/^Red Hat Enterprise Linux release \(.*\) (.*)$$/rhel\1/' \
                      -e 's/^Rocky Linux release \(.*\) (.*)$$/rhel\1/' \
                      -e 's/^CentOS release \(.*\) (.*)$$/rhel\1/' \
                      -e 's/^CentOS Linux release \(.*\) (.*) *$$/rhel\1/' \
                      -e 's/^Fedora release \(.*\) (.*)$$/f\1/' \
                      -e 's/^Fedora Core release \(.*\) (.*)$$/fc\1/' \
                      -e 's/\(.*\.[0-9]*\)\.[0-9]*/\1/' \
                      -e 's/^rhel\([56789]\)\.[0-9]*/rhel\1/' \
                      -e 's/^rhel\([1-9][0-9]\)\.[0-9]*/rhel\1/' \
                     < /etc/redhat-release; \
               elif [ -r /etc/SuSE-release ]; then \
                  head -1 /etc/SuSE-release \
                     | sed -e 's/SUSE LINUX \(.*\) (.*)$$/suse\1/' \
                           -e 's/openSUSE \(.*\) (.*)$$/osu\1/' \
                           -e 's/SUSE Linux Enterprise Server \(.*\) Beta[0-9]* (.*)$$/sles\1/' \
                           -e 's/SUSE Linux Enterprise Server \(.*\) (.*)$$/sles\1/'; \
               fi)
ifeq ($(DISTRO),)
distro_error:
	@echo "Unable to determine compatible linux distribution (DISTRO)" >&2
	@false
endif

ifneq (,$(shell echo "$(DISTRO)" | grep ' '))
distro_error_2:
	@echo "Unable to parse linux distribution \"$(DISTRO)\": has space" >&2
endif

RELEASE=$(REL).$(DISTRO)

LIB=$(shell if [ `uname -i` = "x86_64" ] || [ `uname -i` = "aarch64" ]; then   \
               echo "lib64";                                                   \
            elif [ `uname -m` = "x86_64" ] || [ `uname -m` = "aarch64" ]; then \
               echo "lib64";                                                   \
            else                                                               \
               echo "lib";                                                     \
            fi)

# Python:
PYVER=$(shell if [ -d /usr/include/python3.12 ]; then   \
                 echo 3.12;                             \
              elif [ -d /usr/include/python3.9 ]; then  \
                 echo 3.9;                              \
              elif [ -d /usr/include/python3.6m ]; then \
                 echo 3.6m;                             \
              elif [ -d /usr/include/python2.7 ]; then  \
                 echo 2.7;                              \
              elif [ -d /usr/include/python2.6 ]; then  \
                 echo 2.6;                              \
              elif [ -d /usr/include/python2.5 ]; then  \
                 echo 2.5;                              \
              elif [ -d /usr/include/python2.4 ]; then  \
                 echo 2.4;                              \
              elif [ -d /usr/include/python2.3 ]; then  \
                 echo 2.3;                              \
              elif [ -d /usr/include/python2.2 ]; then  \
                 echo 2.2;                              \
              fi)
ifeq ($(PYVER),)
py_error:
	@echo "Unable to find compatible Python version (PYVER)" >&2
	@false
endif
PYINCLUDE=-I/usr/include/python$(PYVER)
ifeq ($(PYVER),2.2)
PYLIB=-L/usr/$(LIB)/python$(PYVER)/config -lpython$(PYVER)
else
PYLIB=-lpython$(PYVER)
endif

# Uncomment this to non-empty to force use of Qt development libraries in 
# /usr/local:
#    QT_DEVEL=T

ifeq ($(QT_DEVEL),)

# This is typical on RHEL systems
ifeq ($(QT),)
ifeq ($(shell if [ -r /usr/$(LIB)/libQt6Core.so ]; then echo T; fi),T)
   QT=/usr
   QTMAJOR=6
   QTLIBDIR=$(QT)/$(LIB)
   # QTLIB=-L$(QTLIBDIR) -Wl,-rpath,$(QTLIBDIR) is unnecessary
   QTINCLUDE=-I$(QT)/qt6/mkspecs/linux-g++ -I/usr/include/qt6 -I/usr/include/qt6/QtCore -I/usr/include/qt6/QtGui -I/usr/include/qt6/QtWidgets
   QTMOC=$(QTLIBDIR)/qt6/libexec/moc
endif
endif

# This is typical on RHEL systems
ifeq ($(QT),)
ifeq ($(shell if [ -r /usr/$(LIB)/libQt5Core.so ]; then echo T; fi),T)
   QT=/usr
   QTMAJOR=5
   QTLIBDIR=$(QT)/$(LIB)
   # QTLIB=-L$(QTLIBDIR) -Wl,-rpath,$(QTLIBDIR) is unnecessary
   QTINCLUDE=-I$(QT)/qt5/mkspecs/linux-g++ -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtX11Extras
   QTMOC=$(QT)/bin/moc-qt5
endif
endif

# This is typical on RHEL systems
ifeq ($(QT),)
ifeq ($(shell if [ -r /usr/$(LIB)/qt4/$(LIB)/libQtCore.so ]; then echo T; fi),T)
   QT=/usr/$(LIB)/qt4
   QTMAJOR=4
   QTLIBDIR=$(QT)/$(LIB)
   QTLIB=-L$(QTLIBDIR) -Wl,-rpath,$(QTLIBDIR)
   QTINCLUDE=-I$(QT)/mkspecs/linux-g++ -I$(QT)/include -I$(QT)/include/QtCore -I$(QT)/include/QtGui
   QTMOC=$(QT)/bin/moc
endif
endif

# This is typical on RHEL systems (alternate)
ifeq ($(QT),)
ifeq ($(shell if [ -r /usr/$(LIB)/qt4/lib/libQtCore.so ]; then echo T; fi),T)
   # This is typical on RHEL systems
   QT=/usr/$(LIB)/qt4
   QTMAJOR=4
   QTLIBDIR=$(QT)/lib
   QTLIB=-L$(QTLIBDIR) -Wl,-rpath,$(QTLIBDIR)
   QTINCLUDE=-I$(QT)/mkspecs/linux-g++ -I$(QT)/include -I$(QT)/include/QtCore -I$(QT)/include/QtGui
   QTMOC=$(QT)/bin/moc
endif
endif

# This is typical on SUSE and SLES systems
ifeq ($(QT),)
ifeq ($(shell if [ -r /usr/$(LIB)/libQtCore.so ]; then echo T; fi),T)
   QT=/usr
   QTMAJOR=4
   QTLIBDIR=$(QT)/$(LIB)
   # QTLIB=-L$(QTLIBDIR) -Wl,-rpath,$(QTLIBDIR) is unnecessary
   QTINCLUDE=-I$(QT)/share/qt/mkspecs/linux-g++ -I$(QT)/include -I$(QT)/include/QtCore -I$(QT)/include/QtGui
   ifeq ($(QTMOC),)
   ifeq ($(shell if [ -x $(QT)/bin/moc-qt4 ]; then echo T; fi),T)
      QTMOC=$(QT)/bin/moc-qt4
   endif
   endif
   ifeq ($(QTMOC),)
   ifeq ($(shell if [ -x /usr/$(LIB)/qt4/bin/moc ]; then echo T; fi),T)
      QTMOC=/usr/$(LIB)/qt4/bin/moc
   endif
   endif
   ifeq ($(QTMOC),)
   ifeq ($(shell if [ -x $(QT)/bin/moc ]; then echo T; fi),T)
      QTMOC=$(QT)/bin/moc
   endif
   endif
   ifeq ($(QTMOC),)
qt_moc_error:
	@echo "Unable to locate Qt moc tool (QTMOC)" >&2
	@false
   endif
endif
endif

endif

# This is typical for hand-built Qt installations
ifeq ($(QT),)
ifeq ($(shell if [ -d /usr/local/Trolltech ]; then echo T; fi),T)
   # This is typical of Qt built from source
   QT=$(shell find /usr/local/Trolltech/* -type d -print -prune | tail -1)
   QTMAJOR=4
   QTLIBDIR=$(QT)/lib
   QTLIB=-L$(QTLIBDIR) -Wl,-rpath,$(QTLIBDIR)
   QTINCLUDE=-I$(QT)/mkspecs/linux-g++ -I$(QT)/include -I$(QT)/include/QtCore -I$(QT)/include/QtGui
   QTMOC=$(QT)/bin/moc
endif
endif

ifeq ($(QT),)
qt_error:
	@echo "Unable to locate Qt installation (QT)" >&2
	@false
endif

ifeq ($(shell if [ -r $(QTLIBDIR)/libQt6Core_debug.so ]; then echo T; fi),T)
   QTLIBCORE=-lQt6Core_debug
   QTLIBGUI=-lQt6Widgets_debug -lQt6Gui_debug
else
ifeq ($(shell if [ -r $(QTLIBDIR)/libQt6Core.so ]; then echo T; fi),T)
   QTLIBCORE=-lQt6Core
   QTLIBGUI=-lQt6Widgets -lQt6Gui
else
ifeq ($(shell if [ -r $(QTLIBDIR)/libQt5Core_debug.so ]; then echo T; fi),T)
   QTLIBCORE=-lQt5Core_debug
   QTLIBGUI=-lQt5Widgets_debug -lQt5Gui_debug -lQt5X11Extras_debug
else
ifeq ($(shell if [ -r $(QTLIBDIR)/libQt5Core.so ]; then echo T; fi),T)
   QTLIBCORE=-lQt5Core
   QTLIBGUI=-lQt5Widgets -lQt5Gui -lQt5X11Extras
else
ifeq ($(shell if [ -r $(QTLIBDIR)/libQtCore_debug.so ]; then echo T; fi),T)
   QTLIBCORE=-lQtCore_debug
   QTLIBGUI=-lQtGui_debug
else
ifeq ($(shell if [ -r $(QTLIBDIR)/libQtCore.so ]; then echo T; fi),T)
   QTLIBCORE=-lQtCore
   QTLIBGUI=-lQtGui
endif
endif
endif
endif
endif
endif
ifeq ($(QTLIBGUI),)
qtlib_error:
	@echo "Unable to locate Qt libraries in $(QTLIBDIR) (QTLIBCORE, QTLIBGUI)" >&2
	@false
endif
              
DOCDIR=$(shell if    [[ "$(DISTRO)" == suse* ]]         \
                  || [[ "$(DISTRO)" == sles* ]]         \
                  || [[ "$(DISTRO)" == osu*  ]]; then   \
                  echo "/usr/share/doc/packages/nuu";   \
               else                                     \
                  echo "/usr/share/doc/nuu";            \
               fi)

INSTALLSTRIP=-s

ifeq ($(QTMAJOR),5)
CXXPIC=-fPIC
else
CXXPIC=
endif

#
# Sadly, cannot use the following options:
#    -Wshadow           : because it's boneheaded by disallowing constructors'
#                         formals from having the same names as members
#    -Wredundant-decls  : python2.2 headers violate it
#    -Wwrite-strings    : python2.2 headers use char* instead of const char*
#    -Waggregate-return : Qt 4.1.1 headers have funcs that return aggregates
# Cannot use the following options because they are invalid for C++:
#    -Wbad-function-cast
#    -Wstrict-prototypes
#    -Wmissing-prototypes
#
CXXFLAGS=\
   -g \
   $(CXXPIC) \
   -pipe \
   $(PYINCLUDE) \
   $(QTINCLUDE) \
   -Wall \
   -Wcast-align \
   -Wcast-qual \
   -DVERSION="\"$(VERSION)\"" \
   -DDOCDIR="\"$(DOCDIR)\"" \
   -D_REENTRANT \
   -DQT_GUI_LIB \
   -DQT_CORE_LIB \
   -DQT_SHARED

ifeq ($(filter 4 5,$(QTMAJOR)),)
X11LIBS=
else
X11LIBS=\
   -L/usr/X11R6/$(LIB) \
   -lpng \
   -lSM \
   -lICE \
   -lXi \
   -lXrender \
   -lXrandr \
   -lXcursor \
   -lXcursor \
   -lXinerama \
   -lfreetype \
   -lfontconfig \
   -lXext \
   -lX11
endif

LDFLAGS=\
   -Xlinker \
   -export-dynamic \
   $(PYLIB) \
   $(QTLIB) \
   $(QTLIBGUI) \
   $(X11LIBS) \
   $(QTLIBCORE) \
   -lz \
   -lm \
   -ldl \
   -lpthread \
   -lutil

LDGREP=grep -E -v "In function \`posix_tmpnam':$$|: the use of \`tmpnam_r' is dangerous, better use \`mkstemp'$$|In function \`posix_tempnam':$$|: the use of \`tempnam' is dangerous, better use \`mkstemp'$$"

CXX_SRC:=$(shell /bin/ls *.c | /bin/grep -v -- "-moc.c$$" | /bin/grep -v 'qtver.c')
CXX_OBJ:=$(CXX_SRC:.c=.o)
MOC_SRC:=$(shell /bin/grep -F -l Q_OBJECT *.h | /bin/sed "s/\.h$$/-moc.c/g")
MOC_OBJ:=$(MOC_SRC:.c=.o)

OBJ=$(CXX_OBJ) $(MOC_OBJ)
DEP=$(OBJ:.o=.d)

DIRS=python icons pixmaps

PROGS=nuu

default: details build

details vars:
	@echo "================================================"
	@echo "NUU version     = $(VERSION)"
	@echo "NUU release     = $(REL)"
	@echo "Distribution    = $(DISTRO)"
	@echo "Architecture    = $(ARCH)"
	@echo "================================================"
	@echo "Qt installation = $(QT)"
	@echo "Qt libraries    = $(QTLIBCORE) $(QTLIBGUI)"
	@echo "Qt moc          = $(QTMOC)"
	@echo "Qt version      = $(shell $(MAKE) -s -$(MAKEFLAGS) qtver; ./qtver; rm -f qtver)"
	@echo "Yum version     = $(shell yum --version | grep -v '^Loading .* plugin$$' | head -1)"
	@echo "Python version  = $(PYVER)"
	@echo "Doc direcory    = $(DOCDIR)"
	@echo "================================================"

build: .dirs $(MOC_SRC) $(DEP) $(PROGS) nuu.desktop nuu.man.gz

.dirs:
	@for dir in $(DIRS); do (cd "$${dir}"; $(MAKE)); done

nuu: $(OBJ)
	@echo "Linking $@"
	@(tmp="/tmp/nuu.$$$$";                                         \
	  $(CXX) $(CXXFLAGS) -o $@ $(OBJ) $(LDFLAGS) > "$${tmp}" 2>&1; \
	  ret=$${?};                                                   \
	  $(LDGREP) "$${tmp}";                                         \
	  rm -f "$${tmp}";                                             \
	  exit ${ret})

test: build
	sudo NUUSHARE=. ./nuu

debug: build
	sudo NUUSHARE=. nview ./nuu

%.o: %.c
	@echo "Compiling $<"
	@$(CXX) $(CXXFLAGS) -c -o $@ $<

%-moc.c: %.h
	@echo "Mocking $<"
	$(QTMOC) -o $@ $<

nuu.desktop: nuu.proto.desktop
	@echo "Making $@"
	@(cat $<; \
	  echo "Version=$(VERSION)") > $@

nuu.man.gz: nuu.man
	@echo "Making $@"
	@gzip < $< > $@

qtver:
	$(CXX) $(CXXFLAGS) -o qtver qtver.c $(LDFLAGS)

install: default
	install -d -m 755                        $(BUILDROOT)/usr/bin
	if [[ "$(DISTRO)" == rhel* ]] || [[ "$(DISTRO)" == fc* ]] || [[ "$(DISTRO)" == f[0-9]* ]]; then \
	   ln -s consolehelper                   $(BUILDROOT)/usr/bin/nuu; \
	   if [[ "$(DISTRO)" == rhel[1-5] ]] || [[ "$(DISTRO)" == rhel[1-5].* ]] || [[ "$(DISTRO)" == fc[1-4]* ]]; then \
	      install -D -m 444 nuu.pam-old      $(BUILDROOT)/etc/pam.d/nuu; \
	   else \
	      install -D -m 444 nuu.pam          $(BUILDROOT)/etc/pam.d/nuu; \
	   fi; \
	   install -D -m 444 nuu.console         $(BUILDROOT)/etc/security/console.apps/nuu; \
	elif [[ "$(DISTRO)" == suse* ]] || [[ "$(DISTRO)" == sles* ]] || [[ "$(DISTRO)" == osu* ]]; then \
	   install -D -m 755 nuu.gnomesu         $(BUILDROOT)/usr/bin/nuu; \
	else \
	   echo "unknown DISTRO=$(DISTRO)" >&2; \
	   exit 1; \
	fi
	install -D -m 644 nuu.desktop            $(BUILDROOT)/usr/share/applications/nuu.desktop
	install -D -m 444 nuu.man.gz             $(BUILDROOT)/usr/share/man/man1/nuu.1.gz
	install -D -m 755 $(INSTALLSTRIP) nuu    $(BUILDROOT)/usr/share/nuu/nuu
	install -D -m 755 webbrowser             $(BUILDROOT)/usr/share/nuu/webbrowser
	install -D -m 755 mimeviewer             $(BUILDROOT)/usr/share/nuu/mimeviewer
	install -D -m 444 python/YumIO.py        $(BUILDROOT)/usr/share/nuu/python/YumIO.py
	install -D -m 444 python/YumIO.pyc       $(BUILDROOT)/usr/share/nuu/python/YumIO.pyc
	install -D -m 444 icons/check.png        $(BUILDROOT)/usr/share/nuu/icons/check.png
	install -D -m 444 icons/checkBox.png     $(BUILDROOT)/usr/share/nuu/icons/checkBox.png
	install -D -m 444 icons/group.png        $(BUILDROOT)/usr/share/nuu/icons/group.png
	install -D -m 444 icons/install.png      $(BUILDROOT)/usr/share/nuu/icons/install.png
	install -D -m 444 icons/installBox.png   $(BUILDROOT)/usr/share/nuu/icons/installBox.png
	install -D -m 444 icons/noneBox.png      $(BUILDROOT)/usr/share/nuu/icons/noneBox.png
	install -D -m 444 icons/out-of-date.png  $(BUILDROOT)/usr/share/nuu/icons/out-of-date.png
	install -D -m 444 icons/package.png      $(BUILDROOT)/usr/share/nuu/icons/package.png
	install -D -m 444 icons/remove.png       $(BUILDROOT)/usr/share/nuu/icons/remove.png
	install -D -m 444 icons/removeBox.png    $(BUILDROOT)/usr/share/nuu/icons/removeBox.png
	install -D -m 444 icons/suite.png        $(BUILDROOT)/usr/share/nuu/icons/suite.png
	install -D -m 444 icons/up-to-date.png   $(BUILDROOT)/usr/share/nuu/icons/up-to-date.png
	install -D -m 444 icons/update.png       $(BUILDROOT)/usr/share/nuu/icons/update.png
	install -D -m 444 icons/updateBox.png    $(BUILDROOT)/usr/share/nuu/icons/updateBox.png
	install -D -m 444 pixmaps/nuu.png        $(BUILDROOT)/usr/share/nuu/pixmaps/nuu.png
	install -D -m 444 pixmaps/nuu.icon.png   $(BUILDROOT)/usr/share/nuu/pixmaps/nuu.icon.png

uninstall:
	rm -f  $(BUILDROOT)/usr/bin/nuu
	if [[ "$(DISTRO)" == rhel* ]] || [[ "$(DISTRO)" == fc* ]] || [[ "$(DISTRO)" == f* ]]; then \
	   rm -f  $(BUILDROOT)/etc/pam.d/nuu; \
	   rm -f  $(BUILDROOT)/etc/security/console.apps/nuu; \
	elif [[ "$(DISTRO)" == suse* ]] || [[ "$(DISTRO)" == sles* ]] || [[ "$(DISTRO)" == osu* ]]; then \
	   :; \
	else \
	   echo "unknown DISTRO=$(DISTRO)" >&2; \
	   exit 1; \
	fi
	rm -rf $(BUILDROOT)/usr/share/applications/nuu.desktop
	rm -rf $(BUILDROOT)/man/man1/nuu.1.gz
	rm -rf $(BUILDROOT)/usr/share/nuu

clean::
	@for dir in $(DIRS); do (cd "$${dir}"; $(MAKE) -$(MAKEFLAGS) clean); done
	rm -f $(PROGS) *.o *.d *-moc.c nuu.desktop nuu.man.gz

depend: $(MOC_SRC) $(DEP)

%.d: %.c
	@echo "Depend $<"
	@(if [ -f $< ]; then                                                \
	     $(CXX) -MM $(CXXFLAGS) $(PYINCLUDE) $(QTINCLUDE) -o $@.tmp $<; \
	     sed 's@.*:@$*.o:@' < $@.tmp > $@;                              \
	     rm -f $@.tmp;                                                  \
	  fi)
                                    
#
# Release rules
#

OTHER_SRC:=Makefile $(PACKAGE).proto.spec $(wildcard *.h) \
           nuu.proto.desktop nuu.console nuu.pam nuu.pam-old nuu.gnomesu \
           nuu.man \
           webbrowser mimeviewer \
           INSTALL DESKTOP LICENSE ChangeLog DESIGN PROGRESS TODO YUM \
           PYTHON.CHEAT.SHEET RELEASE.REMINDERS \
           doc/manual.pdf \
           $(wildcard doc/html/index*) doc/html/override.css \
           $(wildcard doc/html/images/*) \
           python/Makefile python/YumIO.py \
           icons/Makefile icons/README $(wildcard icons/*.svg) \
           pixmaps/Makefile pixmaps/README $(wildcard pixmaps/*.svg) \
           qtver.c \
		   changelog2rpm

SRC_TAR=$(PACKAGE)-$(VERSION).src.tar.gz
RPMS=$(PACKAGE)-$(VERSION)-$(RELEASE).src.rpm \
     $(PACKAGE)-$(VERSION)-$(RELEASE).$(ARCH).rpm
ifeq ($(shell if [ -r /etc/redhat-release ]; then echo T; fi),T)
DEBUG_RPM=$(PACKAGE)-debuginfo-$(VERSION)-$(RELEASE).$(ARCH).rpm
DEBUGSRC_RPM=$(PACKAGE)-debugsource-$(VERSION)-$(RELEASE).$(ARCH).rpm
else
DEBUG_RPM=
DEBUGSRC_RPM=
endif

$(PACKAGE).spec: $(PACKAGE).proto.spec Makefile changelog2rpm
	@echo "Making $@"
	@(echo "%define version $(VERSION)"; \
	  echo "%define release $(RELEASE)"; \
	  echo "%define distro  $(DISTRO)"; \
	  cat $<; \
      echo; \
      echo "%changelog"; \
	  ./changelog2rpm < ChangeLog) > $@

$(SRC_TAR): $(CXX_SRC) $(OTHER_SRC)
	@echo "Tarring source"
	@rm -rf $(PACKAGE)-$(VERSION)
	@mkdir $(PACKAGE)-$(VERSION)
	@ls -1d $(CXX_SRC) $(OTHER_SRC) | cpio -pdmuvL $(PACKAGE)-$(VERSION)
	@tar cvf - $(PACKAGE)-$(VERSION) | gzip -c >| $(SRC_TAR)
	@rm -rf $(PACKAGE)-$(VERSION)

tar: $(SRC_TAR)

$(RPMS) $(DEBUG_RPM) $(DEBUGSRC_RPM): $(SRC_TAR) $(PACKAGE).spec
	@echo "Building RPMs"
	@rm -rf build buildroot
	@mkdir build
	@mkdir buildroot
	@rpmbuild -ba \
	          --buildroot "${PWD}/buildroot" \
	          --define "_builddir ${PWD}/build" \
	          --define "_rpmdir ${PWD}" \
	          --define "_srcrpmdir ${PWD}" \
	          --define "_sourcedir ${PWD}" \
	          --define "_specdir ${PWD}" \
	          --define "__check_files ''" \
	          --define "__python /bin/true" \
	          --define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
	          $(PACKAGE).spec
	@rm -rf build
	@rm -rf buildroot

# For debugging packaging issues
rebuild-ss:
	@echo "Rebuilding RPMs"
	rpmbuild -bi --short-circuit --nobuild --noclean --nocheck \
	          --buildroot "${PWD}/buildroot" \
	          --define "_builddir ${PWD}/build" \
	          --define "_rpmdir ${PWD}" \
	          --define "_srcrpmdir ${PWD}" \
	          --define "_sourcedir ${PWD}" \
	          --define "_specdir ${PWD}" \
	          --define "__check_files ''" \
	          --define "__python /bin/true" \
	          --define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" \
	         $(PACKAGE).spec

rpm: $(RPMS)

clean::
	rm -f $(PACKAGE).spec
	rm -f $(SRC_TAR)
	rm -f $(RPMS) $(DEBUG_RPM) $(DEBUGSRC_RPM)

# Because of VERSION & DOCDIR
MainWindow.o: Makefile

ifeq (,$(findstring clean,$(MAKECMDGOALS)))
ifeq (,$(findstring clobber,$(MAKECMDGOALS)))
-include *.d
endif
endif
