###############################################################################
#
# $Id: Makefile,v 2.6.14.3 2013/06/19 12:25:13 ronald Exp $
#
# copyright (c) 2002 topIT Informationstechnologie GmbH
# all rights reserved
#
###############################################################################

# disable this for production
# DEBUG=DEBUG

# test for "GNU Make"
ifneq (,)
This makefile requires GNU Make.
endif

ifndef OSTYPE
OSTYPE := $(shell uname | tr '[A-Z]' '[a-z]')
endif

ifeq ($(OSTYPE),linux)
        LINUX=1
else
        ifneq ($(shell echo $(OSTYPE) | grep bsd),)
                BSD=1
        else
                ifeq ($(OSTYPE),sunos)
                        SOLARIS=1
                else
                        ifeq ($(OSTYPE),aix)
                                LINUX=1
				AIX=1
                        else
                                $(error UNKNOWN OPERATING SYSTEM $(OSTYPE))
                        endif
                endif
        endif
endif

ifdef MINGWGCC
SUBDIRS = shutdownjs scrolllog_win simplesc
else
SUBDIRS = .
endif

CFILES = scrolllog.c watchdog.c common.c
HFILES = scrolllog.h watchdog.h common.h
SLOBJS = scrolllog.o common.o
WDOBJS = watchdog.o common.o
RFOBJS = reformat.o
RFLEX  = reformat.l
ifndef AIX
OBJS = $(SLOBJS) $(WDOBJS) $(RFOBJS)
EXEC = $(SDMSHOME)/bin/scrolllog watchdog reformat
else
OBJS = $(SLOBJS) $(WDOBJS)
EXEC = $(SDMSHOME)/bin/scrolllog watchdog
endif


DISTRIB = $(EXEC)

.PHONY: all generate subdirs distrib clean new

all: generate osstrip subdirs distrib

generate: commongensubdirs

subdirs: commonsubdirs

distrib: $(DISTRIB)

clean: commonclean
	-rm -f $(EXEC) *.o reformat.c

new: clean all

include $(SDMSHOME)/src/Makefile.CommonRules

CXXFLAGS += -g -fno-exceptions -Wall -Wshadow -Wpointer-arith \
	-Wwrite-strings -Wstrict-prototypes \
	-Wmissing-declarations -Wnested-externs

ifdef LINUX
CXXFLAGS += -DLINUX -Winline
else
ifdef BSD
CXXFLAGS += -DBSD -Winline
else
ifdef SOLARIS
CXXFLAGS += -DSOLARIS
endif
endif
endif
ifdef AIX
CXXFLAGS += -DAIX
LDFLAGS += -lbsd
endif

.c.o:
	$(CC) $(CXXFLAGS) -c $<

$(SDMSHOME)/bin/scrolllog: $(SLOBJS)
	$(CC) $(LDFLAGS) $(SLOBJS) -o $@

watchdog: $(WDOBJS)
	$(CC) $(LDFLAGS) $(WDOBJS) -o $@

dirwatch: $(DWOBJS)
	$(CC) $(LDFLAGS) $(DWOBJS) -o $@

reformat.c: $(RFLEX)
	flex -oreformat.c $<

reformat: $(RFOBJS)
	$(CC) $< -o $@
