~callum/gmsfn

7d6cd108bce717685e2d6494719f5a222434f2a0 — Callum Brown 1 year, 3 months ago 07e6fa0
Improve Makefile
2 files changed, 36 insertions(+), 19 deletions(-)

M .gitignore
M Makefile
M .gitignore => .gitignore +3 -1
@@ 1,2 1,4 @@
obj/
bin/
doc/gmsfn.1
doc/gmsfn.5
gmsfn

M Makefile => Makefile +33 -18
@@ 1,28 1,43 @@
SRC_DIR := src
OBJ_DIR := obj
BIN_DIR := bin
SRCDIR=src
OUTDIR=obj

EXE := $(BIN_DIR)/gmsfn
SRC := $(wildcard $(SRC_DIR)/*.c)
OBJ := $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
PREFIX=/usr/local
_INSTDIR=$(DESTDIR)$(PREFIX)
BINDIR=$(_INSTDIR)/bin
MANDIR=$(_INSTDIR)/share/man

CPPFLAGS := -Iinclude -MMD -MP
CFLAGS   := -Wall
LDFLAGS  := -Llib
LDLIBS	 := -lssl -lcrypto
SRC=$(wildcard $(SRCDIR)/*.c)
OBJ=$(SRC:$(SRCDIR)/%.c=$(OUTDIR)/%.o)

.PHONY: all clean
SCDOC=scdoc

CPPFLAGS=-Iinclude -MMD -MP
CFLAGS=-Wall
LDFLAGS=-Llib
LDLIBS=-lssl -lcrypto

all: $(EXE)
$(OUTDIR)/%.o: $(SRCDIR)/%.c
	@mkdir -p $(OUTDIR)
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

$(EXE): $(OBJ) | $(BIN_DIR)
gmsfn: $(OBJ)
	$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
doc/gmsfn.1: doc/gmsfn.1.scd
	$(SCDOC) < $< > $@

$(BIN_DIR) $(OBJ_DIR):
	mkdir -p $@
doc/gmsfn.5: doc/gmsfn.5.scd
	$(SCDOC) < $< > $@

all: gmsfn doc/gmsfn.1 doc/gmsfn.5

clean:
	@$(RM) -rv $(BIN_DIR) $(OBJ_DIR) # The @ disables the echoing of the command
	$(RM) -rv gmsfn doc/gmsfn.1 doc/gmsfn.5 $(OUTDIR)

install: all
	mkdir -p $(BINDIR) $(MANDIR)/man1 $(MANDIR)/man5
	install -Dm755 gmsfn $(BINDIR)/gmsfn
	install -Dm644 doc/gmsfn.1 $(MANDIR)/man1/gmsfn.1
	install -Dm644 doc/gmsfn.5 $(MANDIR)/man5/gmsfn.5

.PHONY: all clean