CFLAGS = -Wall -W -std=gnu9x -O2 -g

# Add -ltinfo for recent systems. -lgpm for recent ncurses (install libgpm-dev).

#LDLIBS = -g -lpthread -lpanel -lform -lncurses -ltinfo -lgpm
LDLIBS = -g -lpthread -lpanel -lform -lncurses


#for FreeBSD 5.2.1, use -lthr instead of -lpthread
#LDLIBS=-g -lthr -lpanel -lform -lncurses

# Some distros (SuSE) put ncurses include files in
# /usr/include/ncurses instead of in the stanard /usr/include, so
# check to see if we can find it, and warn the user if not.

define NCURSES_WARNING

****************************************************************************
**                                                                        **
**   ncurses include files not found in standard locations -- trying to   **
**   build anyway.  If build fails because panel.h or menu.h are not      **
**   found, please install ncurses development files and try again.       **
**                                                                        **
****************************************************************************

endef



ifneq ($(MAKECMDGOALS),clean)
 ifeq ("$(wildcard /usr/include/panel.h)","")
  ifeq ("$(wildcard /usr/include/ncurses/panel.h)","/usr/include/ncurses/panel.h")
   CFLAGS += -D ALT_NCURSES_INCLUDE
  else
    ifeq ($(MAKELEVEL),0)
      $(info "$(NCURSES_WARNING)")
    endif
  endif
 endif
endif

%.d: %.c
	set -e; $(CC) -MM $(CPPFLAGS) $< \
         | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \
         [ -s $@ ] || rm -f $@

%.txt: %.1
	nroff -man $< | col -b > $@

%.ps: %.1
	groff -man $< >$@

%.pdf: %.ps
	ps2pdf $< $@

Sources=lcom.c queue.c getargs.c modes.c
Objects=$(Sources:.c=.o)

all ::
	@$(MAKE) -s depend
	@$(MAKE) --no-print-directory lcom


lcom: $(Objects)

static ::
	@$(MAKE) -s depend
	@$(MAKE) --no-print-directory slcom

slcom: $(Objects)
	gcc -ldl $^ -o $@ -static $(LDLIBS)

clean:
	rm -f $(Binaries) *.d *.o *~ core.* lcom slcom lcom.ps lcom.pdf lcom.txt

depend: $(Sources:.c=.d)

install:
	install -s lcom /usr/local/bin
	install lcom.1 /usr/local/man/man1

docs: lcom.txt lcom.ps lcom.pdf

