# Makefile to build sysstat commands
# # (C) 1999-2009 Sebastien GODARD (sysstat <at> orange.fr)

# Version and package name
VERSION = 9.0.3
PACKAGE = sysstat
# Needed by docdir
PACKAGE_TARNAME = $(PACKAGE)-$(VERSION)

# Compiler to use
# CC = $(TOOLCHAIN)/bin/mips-linux-uclibc-gcc

# Other commands
CHMOD = chmod
CHOWN = chown
LN_S = ln -s
# AR = $(TOOLCHAIN)/bin/mips-linux-uclibc-ar
# Full path to prevent from using aliases
CP = /bin/cp

CHKCONFIG = /sbin/chkconfig
INSTALL = install
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_BIN = ${INSTALL} -m 755

# Directories
ifndef PREFIX
PREFIX = /usr/
endif
ifndef DESTDIR
DESTDIR = $(INSTALL_DIR)
endif
# These two variables are needed by other ones (eg bindir)
prefix = $(PREFIX)
exec_prefix = ${prefix}
datarootdir = ${prefix}/share

ifndef SA_LIB_DIR
SA_LIB_DIR = /lib/sa
endif
SADC_PATH = $(SA_LIB_DIR)/sadc
ifndef SA_DIR
SA_DIR = /var/log/sa
endif
BIN_DIR = ${exec_prefix}/bin

ifndef MAN_DIR
# With recent versions of autoconf, mandir defaults to ${datarootdir}/man
# (i.e. $prefix/share/man) which is not necessarily in man path!
# MAN_DIR = ${datarootdir}/man
MAN_DIR = /usr/local/man
endif
MAN1_DIR = $(MAN_DIR)/man1
MAN8_DIR = $(MAN_DIR)/man8

ifndef DOC_DIR
DOC_DIR = ${datarootdir}/doc/${PACKAGE_TARNAME}
endif

NLS_DIR = $(PREFIX)/share/locale
SYSCONFIG_DIR = /etc/sysconfig

# Compiler flags
CFLAGS = -g -O2 -Wall -Wstrict-prototypes -pipe -O2
DFLAGS = 
LFLAGS =  -s
# DFLAGS may already contain SMP_RACE definition
DFLAGS += -DSA_DIR=\"$(SA_DIR)\" -DSADC_PATH=\"$(SADC_PATH)\"

# Commands
ifndef MSGFMT
MSGFMT = msgfmt
endif
ifndef XGETTEXT
XGETTEXT = xgettext
endif
ifndef MSGMERGE
MSGMERGE = msgmerge
endif
ifndef ZIP
ZIP = bzip2
endif

# Settings 
NLS = n
ifeq ($(NLS),y)
REQUIRE_NLS = -DUSE_NLS -DPACKAGE=\"$(PACKAGE)\" -DLOCALEDIR=\"$(NLS_DIR)\"
endif
ifdef REQUIRE_NLS
   DFLAGS += $(REQUIRE_NLS)
endif
INSTALL_CRON = n
CRON_OWNER = root

MAN_GROUP = man
ifndef IGNORE_MAN_GROUP
IGNORE_MAN_GROUP = n
endif
ifeq ($(IGNORE_MAN_GROUP),y)
MANGRPARG =
else
MANGRPARG = -g $(MAN_GROUP)
endif
ifndef CLEAN_SA_DIR
CLEAN_SA_DIR = n
endif
ifndef COMPRESS_MANPG
COMPRESS_MANPG = n
endif
ifndef INSTALL_ISAG
INSTALL_ISAG = n
endif
ifndef INSTALL_DOC
INSTALL_DOC = n
endif

# Run-command directories
ifndef RC_DIR
RC_DIR = /etc/init.d
endif
RC0_DIR = $(RC_DIR)/rc0.d
RC1_DIR = $(RC_DIR)/rc1.d
RC2_DIR = $(RC_DIR)/rc2.d
RC3_DIR = $(RC_DIR)/rc3.d
RC4_DIR = $(RC_DIR)/rc4.d
RC5_DIR = $(RC_DIR)/rc5.d
RC6_DIR = $(RC_DIR)/rc6.d
ifndef INIT_DIR
INIT_DIR = /etc/init.d
endif
ifndef INITD_DIR
INITD_DIR = .
endif

NLSPO= $(wildcard nls/*.po)
NLSGMO= $(NLSPO:.po=.gmo)
NLSPOT= $(NLSPO:.po=.pot)

%.gmo: %.po
	$(MSGFMT) -o $@ $<

%.pot: %.po
	$(MSGMERGE) -U $< nls/sysstat.pot

%.o: %.c
	$(CC) -o $@ -c $(CFLAGS) $(DFLAGS) $<

% : %.o
	$(CC) -o $@ $(CFLAGS) $^ $(LFLAGS)

all: sadc sar sadf iostat mpstat pidstat locales

common.o: common.c version.h common.h ioconf.h sysconfig.h

sa_common.o: sa_common.c sa.h common.h ioconf.h sysconfig.h rd_stats.h

ioconf.o: ioconf.c ioconf.h common.h sysconfig.h

act_sadc.o: activity.c sa.h rd_stats.h
	$(CC) -o $@ -c $(CFLAGS) -DSOURCE_SADC $(DFLAGS) $<

act_sar.o: activity.c sa.h pr_stats.h
	$(CC) -o $@ -c $(CFLAGS) -DSOURCE_SAR $(DFLAGS) $<

act_sadf.o: activity.c sa.h prf_stats.h
	$(CC) -o $@ -c $(CFLAGS) -DSOURCE_SADF $(DFLAGS) $<

rd_stats.o: rd_stats.c common.h rd_stats.h ioconf.h sysconfig.h

pr_stats.o: pr_stats.c sa.h ioconf.h sysconfig.h pr_stats.h

prf_stats.o: prf_stats.c sa.h ioconf.h sysconfig.h prf_stats.h

sa_wrap.o: sa_wrap.c sa.h rd_stats.h

# Explicit rules needed to prevent possible file corruption
# when using parallel execution.
# brcm begin - next line was replaced with rule below
#libsyscom.a: libsyscom.a(common.o ioconf.o)
# brcm end
libsyscom.a: common.o ioconf.o
	$(AR) rv $@ common.o
	$(AR) rv $@ ioconf.o
	$(AR) s $@

librdstats.a: librdstats.a(rd_stats.o)

sadc.o: sadc.c sa.h version.h common.h ioconf.h sysconfig.h rd_stats.h

sadc: sadc.o act_sadc.o sa_wrap.o sa_common.o librdstats.a libsyscom.a

sar.o: sar.c sa.h version.h common.h ioconf.h pr_stats.h sysconfig.h

sar: sar.o act_sar.o sa_common.o pr_stats.o libsyscom.a

sadf.o: sadf.c sadf.h version.h sa.h common.h ioconf.h sysconfig.h prf_stats.h

sadf: sadf.o act_sadf.o prf_stats.o sa_common.o libsyscom.a

iostat.o: iostat.c iostat.h version.h common.h ioconf.h sysconfig.h rd_stats.h

iostat: iostat.o librdstats.a libsyscom.a

pidstat.o: pidstat.c pidstat.h version.h common.h rd_stats.h

pidstat: pidstat.o librdstats.a libsyscom.a

mpstat.o: mpstat.c mpstat.h version.h common.h rd_stats.h

mpstat: mpstat.o librdstats.a libsyscom.a

ifdef REQUIRE_NLS
locales: $(NLSGMO)
else
locales:
endif

nls/sysstat.pot: $(wildcard *.c)
	$(XGETTEXT) -o $@ -k_ --msgid-bugs-address="sysstat <at> orange.fr" $^

# Phony targets
.PHONY: clean distclean install install_base install_all uninstall \
	uninstall_base uninstall_all dist bdist

install_man: man/sadc.8 man/sar.1 man/sadf.1 man/sa1.8 man/sa2.8
ifeq ($(INSTALL_DOC),y)
	mkdir -p $(DESTDIR)$(MAN1_DIR)
	mkdir -p $(DESTDIR)$(MAN8_DIR)
	rm -f $(DESTDIR)$(MAN8_DIR)/sa1.8*
	$(INSTALL_DATA) $(MANGRPARG) man/sa1.8 $(DESTDIR)$(MAN8_DIR)
	rm -f $(DESTDIR)$(MAN8_DIR)/sa2.8*
	$(INSTALL_DATA) $(MANGRPARG) man/sa2.8 $(DESTDIR)$(MAN8_DIR)
	rm -f $(DESTDIR)$(MAN8_DIR)/sadc.8*
	$(INSTALL_DATA) $(MANGRPARG) man/sadc.8 $(DESTDIR)$(MAN8_DIR)
	rm -f $(DESTDIR)$(MAN1_DIR)/sar.1*
	$(INSTALL_DATA) $(MANGRPARG) man/sar.1 $(DESTDIR)$(MAN1_DIR)
	rm -f $(DESTDIR)$(MAN1_DIR)/sadf.1*
	$(INSTALL_DATA) $(MANGRPARG) man/sadf.1 $(DESTDIR)$(MAN1_DIR)
	rm -f $(DESTDIR)$(MAN1_DIR)/iostat.1*
	$(INSTALL_DATA) $(MANGRPARG) man/iostat.1 $(DESTDIR)$(MAN1_DIR)
	rm -f $(DESTDIR)$(MAN1_DIR)/mpstat.1*
	$(INSTALL_DATA) $(MANGRPARG) man/mpstat.1 $(DESTDIR)$(MAN1_DIR)
	rm -f $(DESTDIR)$(MAN1_DIR)/pidstat.1*
	$(INSTALL_DATA) $(MANGRPARG) man/pidstat.1 $(DESTDIR)$(MAN1_DIR)
ifeq ($(INSTALL_ISAG),y)
	$(INSTALL_DATA) $(MANGRPARG) contrib/isag/isag.1 $(DESTDIR)$(MAN1_DIR)
endif
ifeq ($(COMPRESS_MANPG),y)
	$(ZIP) $(DESTDIR)$(MAN8_DIR)/sa1.8
	$(ZIP) $(DESTDIR)$(MAN8_DIR)/sa2.8
	$(ZIP) $(DESTDIR)$(MAN8_DIR)/sadc.8
	$(ZIP) $(DESTDIR)$(MAN1_DIR)/sar.1
	$(ZIP) $(DESTDIR)$(MAN1_DIR)/sadf.1
	$(ZIP) $(DESTDIR)$(MAN1_DIR)/iostat.1
	$(ZIP) $(DESTDIR)$(MAN1_DIR)/mpstat.1
	$(ZIP) $(DESTDIR)$(MAN1_DIR)/pidstat.1
ifeq ($(INSTALL_ISAG),y)
	$(ZIP) $(DESTDIR)$(MAN1_DIR)/isag.1
endif
endif
endif

install_nls: locales
ifdef REQUIRE_NLS
	mkdir -p $(DESTDIR)$(NLS_DIR)/af/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/da/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/de/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/es/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/fi/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/fr/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/id/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/it/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/ja/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/ky/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/lv/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/mt/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/nb/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/nl/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/nn/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/pl/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/pt/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/pt_BR/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/ro/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/ru/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/sk/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/sv/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/vi/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/zh_CN/LC_MESSAGES
	mkdir -p $(DESTDIR)$(NLS_DIR)/zh_TW/LC_MESSAGES
	$(INSTALL_DATA) nls/af.gmo $(DESTDIR)$(NLS_DIR)/af/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/da.gmo $(DESTDIR)$(NLS_DIR)/da/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/de.gmo $(DESTDIR)$(NLS_DIR)/de/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/es.gmo $(DESTDIR)$(NLS_DIR)/es/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/fi.gmo $(DESTDIR)$(NLS_DIR)/fi/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/fr.gmo $(DESTDIR)$(NLS_DIR)/fr/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/id.gmo $(DESTDIR)$(NLS_DIR)/id/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/it.gmo $(DESTDIR)$(NLS_DIR)/it/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/ja.gmo $(DESTDIR)$(NLS_DIR)/ja/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/ky.gmo $(DESTDIR)$(NLS_DIR)/ky/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/lv.gmo $(DESTDIR)$(NLS_DIR)/lv/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/mt.gmo $(DESTDIR)$(NLS_DIR)/mt/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/nb.gmo $(DESTDIR)$(NLS_DIR)/nb/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/nl.gmo $(DESTDIR)$(NLS_DIR)/nl/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/nn.gmo $(DESTDIR)$(NLS_DIR)/nn/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/pl.gmo $(DESTDIR)$(NLS_DIR)/pl/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/pt.gmo $(DESTDIR)$(NLS_DIR)/pt/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/pt_BR.gmo $(DESTDIR)$(NLS_DIR)/pt_BR/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/ro.gmo $(DESTDIR)$(NLS_DIR)/ro/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/ru.gmo $(DESTDIR)$(NLS_DIR)/ru/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/sk.gmo $(DESTDIR)$(NLS_DIR)/sk/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/sv.gmo $(DESTDIR)$(NLS_DIR)/sv/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/vi.gmo $(DESTDIR)$(NLS_DIR)/vi/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/zh_CN.gmo $(DESTDIR)$(NLS_DIR)/zh_CN/LC_MESSAGES/$(PACKAGE).mo
	$(INSTALL_DATA) nls/zh_TW.gmo $(DESTDIR)$(NLS_DIR)/zh_TW/LC_MESSAGES/$(PACKAGE).mo
endif

install_base: all
	mkdir -p $(DESTDIR)$(SA_LIB_DIR)
	mkdir -p $(DESTDIR)$(SA_DIR)
ifeq ($(CLEAN_SA_DIR),y)
	find $(DESTDIR)$(SA_DIR) \( -name 'sar??' -o -name 'sa??' -o -name 'sar??.gz' -o -name 'sa??.gz' \) \
		-exec rm -f {} \;
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(SA_DIR)/[0-9]?????
endif
	mkdir -p $(DESTDIR)$(BIN_DIR)
ifeq ($(INSTALL_DOC),y)
	mkdir -p $(DESTDIR)$(DOC_DIR)
endif
	mkdir -p $(DESTDIR)$(SYSCONFIG_DIR)
	$(INSTALL_BIN) sadc $(DESTDIR)$(SA_LIB_DIR)
	$(INSTALL_BIN) sar $(DESTDIR)$(BIN_DIR)
	$(INSTALL_BIN) sadf $(DESTDIR)$(BIN_DIR)
	$(INSTALL_BIN) iostat $(DESTDIR)$(BIN_DIR)
	$(INSTALL_BIN) mpstat $(DESTDIR)$(BIN_DIR)
	$(INSTALL_BIN) pidstat $(DESTDIR)$(BIN_DIR)
ifeq ($(INSTALL_ISAG),y)
	$(INSTALL_BIN) contrib/isag/isag $(DESTDIR)$(BIN_DIR)
endif
	$(INSTALL_DATA) sysstat.ioconf $(DESTDIR)$(SYSCONFIG_DIR)
ifeq ($(INSTALL_DOC),y)
	$(INSTALL_DATA) CHANGES $(DESTDIR)$(DOC_DIR)
	$(INSTALL_DATA) COPYING $(DESTDIR)$(DOC_DIR)
	$(INSTALL_DATA) CREDITS $(DESTDIR)$(DOC_DIR)
	$(INSTALL_DATA) README $(DESTDIR)$(DOC_DIR)
	$(INSTALL_DATA) FAQ $(DESTDIR)$(DOC_DIR)
	$(INSTALL_DATA) *.lsm $(DESTDIR)$(DOC_DIR)
endif

install_all: install_base crontab sysstat \
	sysstat.crond sysstat.cron.daily sysstat.cron.hourly
	$(CHOWN) $(CRON_OWNER) $(DESTDIR)$(SA_DIR)
	if [ -d $(DESTDIR)/etc/cron.d ]; then \
	   $(INSTALL_DATA) sysstat.crond $(DESTDIR)/etc/cron.d/sysstat; \
	elif [ -d $(DESTDIR)/etc/cron.hourly -a -d $(DESTDIR)/etc/cron.daily ]; then \
	   $(INSTALL_BIN) sysstat.cron.hourly $(DESTDIR)/etc/cron.hourly/sysstat; \
	   $(INSTALL_BIN) sysstat.cron.daily $(DESTDIR)/etc/cron.daily/sysstat; \
	else \
	   su $(CRON_OWNER) -c "crontab -l > /tmp/crontab-$(CRON_OWNER).save"; \
	   $(CP) -a /tmp/crontab-$(CRON_OWNER).save ./crontab-$(CRON_OWNER).`date '+%Y%m%d.%H%M%S'`.save; \
	   echo "USER'S PREVIOUS CRONTAB SAVED IN CURRENT DIRECTORY (USING .save SUFFIX)."; \
	   su $(CRON_OWNER) -c "crontab crontab"; \
	fi
	if [ -d $(DESTDIR)$(INIT_DIR) ]; then \
	   $(INSTALL_BIN) sysstat $(DESTDIR)$(INIT_DIR)/sysstat; \
	   if [ -x $(CHKCONFIG) ]; then \
	      cd $(DESTDIR)$(INIT_DIR) && $(CHKCONFIG) --add sysstat; \
	   else \
	      cd $(DESTDIR)$(RC2_DIR) && $(LN_S) -f ../$(INITD_DIR)/sysstat S01sysstat; \
	      cd $(DESTDIR)$(RC3_DIR) && $(LN_S) -f ../$(INITD_DIR)/sysstat S01sysstat; \
	      cd $(DESTDIR)$(RC5_DIR) && $(LN_S) -f ../$(INITD_DIR)/sysstat S01sysstat; \
	   fi \
	elif [ -d $(DESTDIR)$(RC_DIR) ]; then \
	   $(INSTALL_BIN) sysstat $(DESTDIR)$(RC_DIR)/rc.sysstat; \
	   if [ -x $(CHKCONFIG) ]; then \
	      cd $(DESTDIR)$(RC_DIR) && $(CHKCONFIG) --add sysstat; \
	   else \
	      [ -d $(DESTDIR)$(RC2_DIR) ] || mkdir -p $(DESTDIR)$(RC2_DIR); \
	      [ -d $(DESTDIR)$(RC3_DIR) ] || mkdir -p $(DESTDIR)$(RC3_DIR); \
	      [ -d $(DESTDIR)$(RC5_DIR) ] || mkdir -p $(DESTDIR)$(RC5_DIR); \
	      cd $(DESTDIR)$(RC2_DIR) && $(LN_S) -f ../rc.sysstat S01sysstat; \
	      cd $(DESTDIR)$(RC3_DIR) && $(LN_S) -f ../rc.sysstat S01sysstat; \
	      cd $(DESTDIR)$(RC5_DIR) && $(LN_S) -f ../rc.sysstat S01sysstat; \
	   fi \
	fi

uninstall_man:
ifeq ($(INSTALL_DOC),y)
	rm -f $(DESTDIR)$(MAN8_DIR)/sadc.8*
	rm -f $(DESTDIR)$(MAN8_DIR)/sa1.8*
	rm -f $(DESTDIR)$(MAN8_DIR)/sa2.8*
	rm -f $(DESTDIR)$(MAN1_DIR)/sar.1*
	rm -f $(DESTDIR)$(MAN1_DIR)/sadf.1*
	rm -f $(DESTDIR)$(MAN1_DIR)/iostat.1*
	rm -f $(DESTDIR)$(MAN1_DIR)/mpstat.1*
	rm -f $(DESTDIR)$(MAN1_DIR)/pidstat.1*
ifeq ($(INSTALL_ISAG),y)
	rm -f $(DESTDIR)$(MAN1_DIR)/isag.1
endif
endif

uninstall_nls:
ifdef REQUIRE_NLS
	rm -f $(DESTDIR)$(PREFIX)/share/locale/af/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/da/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/de/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/es/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/fi/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/fr/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/id/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/it/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/ja/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/ky/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/lv/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/mt/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/nb/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/nl/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/nn/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/pl/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/pt/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/pt_BR/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/ro/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/ru/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/sk/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/sv/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/vi/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/zh_CN/LC_MESSAGES/$(PACKAGE).mo
	rm -f $(DESTDIR)$(PREFIX)/share/locale/zh_TW/LC_MESSAGES/$(PACKAGE).mo
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/af/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/da/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/de/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/es/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/fi/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/fr/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/id/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/it/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/ja/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/ky/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/lv/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/mt/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/nb/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/nl/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/nn/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/pl/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/pt/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/pt_BR/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/ro/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/ru/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/sk/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/sv/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/vi/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/zh_CN/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/zh_TW/LC_MESSAGES
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/af
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/da
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/de
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/es
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/fi
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/fr
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/id
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/it
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/ja
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/ky
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/lv
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/mt
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/nb
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/nl
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/nn
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/pl
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/pt
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/pt_BR
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/ro
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/ru
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/sk
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/sv
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/vi
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/zh_CN
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/locale/zh_TW
endif

uninstall_base: uninstall_man uninstall_nls
	rm -f $(DESTDIR)$(SA_LIB_DIR)/sadc
	rm -f $(DESTDIR)$(SA_LIB_DIR)/sa1
	rm -f $(DESTDIR)$(SA_LIB_DIR)/sa2
	rm -f $(DESTDIR)$(BIN_DIR)/sar
	rm -f $(DESTDIR)$(BIN_DIR)/sadf
	rm -f $(DESTDIR)$(BIN_DIR)/iostat
	rm -f $(DESTDIR)$(BIN_DIR)/mpstat
	rm -f $(DESTDIR)$(BIN_DIR)/pidstat
ifeq ($(INSTALL_ISAG),y)
	rm -f $(DESTDIR)$(BIN_DIR)/isag
endif
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(SA_LIB_DIR)
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(SA_DIR)/[0-9]?????
	-rmdir --ignore-fail-on-non-empty $(DESTDIR)$(SA_DIR)
#       No need to keep sysstat scripts, config files and links since
#       the binaries have been deleted.
	rm -f $(DESTDIR)$(INIT_DIR)/sysstat
	rm -f $(DESTDIR)$(RC_DIR)/rc.sysstat
	rm -f $(DESTDIR)$(SYSCONFIG_DIR)/sysstat
	rm -f $(DESTDIR)$(SYSCONFIG_DIR)/sysstat.ioconf
	rm -f $(DESTDIR)$(RC2_DIR)/S??sysstat
	rm -f $(DESTDIR)$(RC3_DIR)/S??sysstat
	rm -f $(DESTDIR)$(RC5_DIR)/S??sysstat
#       Delete possible kill entries installed by chkconfig
	rm -f $(DESTDIR)$(RC0_DIR)/K??sysstat
	rm -f $(DESTDIR)$(RC1_DIR)/K??sysstat
	rm -f $(DESTDIR)$(RC4_DIR)/K??sysstat
	rm -f $(DESTDIR)$(RC6_DIR)/K??sysstat
#       Vixie cron entries also can be safely deleted here
	rm -f $(DESTDIR)/etc/cron.d/sysstat
#       Id. for Slackware cron entries
	rm -f $(DESTDIR)/etc/cron.hourly/sysstat
	rm -f $(DESTDIR)/etc/cron.daily/sysstat
ifeq ($(INSTALL_DOC),y)
	rm -f $(DESTDIR)$(DOC_DIR)/*
	-rmdir $(DESTDIR)$(DOC_DIR)
endif
	@echo "Please ignore the errors above, if any."

uninstall_all: uninstall_base
	-su $(CRON_OWNER) -c "crontab -l > /tmp/crontab-$(CRON_OWNER).old"
	-$(CP) -a /tmp/crontab-$(CRON_OWNER).old ./crontab-$(CRON_OWNER).`date '+%Y%m%d.%H%M%S'`.old
	@echo "USER CRONTAB SAVED IN CURRENT DIRECTORY (WITH .old SUFFIX)."
	-su $(CRON_OWNER) -c "crontab -r"

ifeq ($(INSTALL_CRON),y)
uninstall: uninstall_all
else
uninstall: uninstall_base
endif

ifeq ($(INSTALL_CRON),y)
install: install_all
else
install: install_base
endif

ifdef REQUIRE_NLS
po-files: nls/sysstat.pot $(NLSPOT)
else
po-files:
endif

clean:
	rm -f sadc sar sadf iostat mpstat pidstat *.o *.a core TAGS
	if [ -e nls ]; then find nls -name "*.gmo" -exec rm -f {} \;;  fi

almost-distclean: clean nls/sysstat.pot
	rm -f sa1 sa2 sysstat crontab version.h sysconfig.h
	rm -f sysstat.sysconfig sysstat.crond sysstat.cron.daily
	rm -f sysstat.cron.hourly sysstat.crond.sample sysstat.crond.sample.in
	rm -f contrib/isag/isag
	rm -f man/sa1.8 man/sa2.8 man/sadc.8 man/sadf.1 man/sar.1
	rm -f *.log config.status
	rm -rf autom4te.cache
	rm -f *.save *.old .*.swp data
	find . -name "*~" -exec rm -f {} \;

distclean: almost-distclean
	rm -f Makefile

maintainer-clean: distclean
	rm -f configure

dist: almost-distclean
	cd .. && (tar --exclude=Makefile -cvf - sysstat-$(VERSION) | gzip -v9 > sysstat-$(VERSION).tar.gz)

bdist: almost-distclean
	cd .. && (tar --exclude=Makefile -cvf - sysstat-$(VERSION) | bzip2 > sysstat-$(VERSION).tar.bz2)

tags:
	etags ./*.[hc]

