view Makefile.gen @ 647:ff94100cfc7c

Commonize README building.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 09 Jan 2015 20:37:15 +0200
parents 5b059a85cab8
children 23d16d9cdf96
line wrap: on
line source

CFLAGS += -g -W -Wall -Wextra -DTH_NO_DEFAULTS
CFLAGS += -O2
#CFLAGS += -std=c99 -pedantic
THLIBS=th-libs/

MKDIR ?= mkdir
MKDIR_P ?= $(MKDIR) -p

#
# Version strings
#
NN_VERSION := $(shell cat VERSION)
comma:= ,
NN_VERSION_COM := $(subst .,$(comma),$(NN_VERSION))
CFLAGS += -DNN_VERSION=\"$(NN_VERSION)\"

#
# Objects
#
THLIBS_A=$(OBJPATH)thlibs.a
THLIBS_OBJ=th_util.o th_string.o th_args.o th_ioctx.o th_config.o th_network.o

NNCHAT_OBJ=main.o util.o ui.o
NNCHAT_BIN=$(BINPATH)nnchat$(EXEEXT)

TARGETS+=$(THLIBS_A) $(NNCHAT_BIN)

NONBUILD+=$(OBJPATH) $(BINPATH)

#
# Target rules
#
all: $(NONBUILD) $(TARGETS)

$(OBJPATH):
	$(MKDIR_P) $@

$(BINPATH):
	$(MKDIR_P) $@

$(OBJPATH)%.o: $(THLIBS)%.c $(THLIBS)%.h
	$(CC) $(CFLAGS) -c -o $@ $<

$(OBJPATH)%.o: %.c %.h
	$(CC) $(CFLAGS) -c -o $@ $< -I$(THLIBS)

$(OBJPATH)%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $< -I$(THLIBS)

$(THLIBS_A): $(addprefix $(OBJPATH),$(THLIBS_OBJ))
	$(AR) cru $@ $(addprefix $(OBJPATH),$(THLIBS_OBJ))
	$(RANLIB) $@

main.c: VERSION

$(NNCHAT_BIN): $(addprefix $(OBJPATH),$(NNCHAT_OBJ)) $(THLIBS_A) $(EXTRAOBJS)
	$(CC) $(CFLAGS) -o $@ $+ $(LDFLAGS)

#
# Documentation
#
$(DOC):
	@wget -qO- http://www.tnsp.org/~ccr/nnchat/ | tr '\n' '' | \
	sed "s/<.-- BEGIN -->.*<.-- END -->//g;s/<script.*<\/script>//g" | tr '' '\n' > "$@.tmp"
	@links -dump "$@.tmp" > $@


#
# Special targets
#
clean:
	$(RM) $(TARGETS) $(OBJPATH)*.o

srcclean: clean
	$(RM) *~