#
# Makefile
-# Copyright (C) 2014 Michael Goehler
+# Copyright (C) 2015 Michael Goehler
#
# This file is part of mdp.
#
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-CFLAGS = -O3
-LDFLAGS = -s
-LDLIBS = -lncurses
-OBJECTS = cstring.o cstack.o markdown.o parser.o viewer.o mdp.o
-DESTDIR ?= /usr/bin
+UNAME_S := $(shell uname -s 2>/dev/null || echo not)
+
+SOURCES = $(wildcard src/*.c)
+OBJECTS = $(SOURCES:.c=.o)
+TARGET = mdp
+DESTDIR =
+PREFIX = /usr/local
+
+CURSES = ncursesw
+LDFLAGS ?= -s
+
+ifeq (Windows_NT,$(OS))
+ ifeq (,$(findstring CYGWIN,$(UNAME_S)))
+ CURSES := pdcurses
+ endif
+endif
+
+ifeq ($(UNAME_S),Darwin)
+ CURSES := ncurses
+ LDFLAGS :=
+endif
ifeq ($(DEBUG),1)
-CFLAGS := -Wall -g -O0
-LDFLAGS :=
+ LDFLAGS :=
endif
-all: mdp
+LDLIBS = -l$(CURSES)
+
+all: $(TARGET)
+
+$(TARGET): src
+ $(CC) $(OBJECTS) $(LDLIBS) $(LDFLAGS) -o $(TARGET)
-mdp: $(OBJECTS)
+src:
+ $(MAKE) $(MFLAGS) -C src
clean:
- $(RM) $(OBJECTS) mdp
+ $(MAKE) -C src clean
+ $(RM) $(TARGET)
-install: mdp
- install -d $(PREFIX)$(DESTDIR)
- install -m 755 mdp $(PREFIX)$(DESTDIR)/mdp
+install:
+ install -d $(DESTDIR)$(PREFIX)/bin
+ install -m 755 $(TARGET) $(DESTDIR)$(PREFIX)/bin/$(TARGET)
+ install -d $(DESTDIR)$(PREFIX)/share/man/man1
+ install -m 644 mdp.1 $(DESTDIR)$(PREFIX)/share/man/man1/$(TARGET).1
-.PHONY: all clean install
+uninstall:
+ $(RM) $(DESTDIR)$(PREFIX)/$(TARGET)
+.PHONY: all clean install src uninstall