~rcr/rirc

5c69d728ed1c827df2d1b6a25fa474f0b8ecd3b6 — Richard Robbins 22 days ago 481bc3a
cleanup makefiles and README, add .gitattributes
6 files changed, 90 insertions(+), 109 deletions(-)

A .gitattributes
M .gitignore
M Makefile
M README.md
R rirc.1 => docs/rirc.1
M lib/mbedtls.Makefile
A .gitattributes => .gitattributes +3 -0
@@ 0,0 1,3 @@
.builds        export-ignore
.gitignore     export-ignore
.gitattributes export-ignore

M .gitignore => .gitignore +2 -1
@@ 7,13 7,14 @@
*.t
*.td
.cache
bld
build
compile_commands.json
config.h
coverage
lib/mbedtls-*
lib/mbedtls.sha256
rirc
rirc.1
rirc.debug
rirc.debug.address
rirc.debug.thread

M Makefile => Makefile +52 -74
@@ 1,86 1,65 @@
VERSION := 0.1.4

# Release and debug executable names
BIN_R := rirc
BIN_D := rirc.debug
PREFIX   ?= /usr/local
PATH_BIN := $(DESTDIR)$(PREFIX)/bin
PATH_MAN := $(DESTDIR)$(PREFIX)/share/man/man1

# Install paths
BIN_DIR := /usr/local/bin
MAN_DIR := /usr/local/share/man/man1
PATH_BUILD := build
PATH_LIB   := lib
PATH_SRC   := src
PATH_TEST  := test

# Build, source, lib, and test directories
DIR_B := bld
DIR_S := src
DIR_L := lib
DIR_T := test
include lib/mbedtls.Makefile

CONFIG := config.h

include lib/mbedtls.Makefile

CFLAGS ?= -O2 -flto
CFLAGS += -D NDEBUG
CFLAGS += -DNDEBUG

CFLAGS_DEBUG ?=
CFLAGS_DEBUG += -O0 -g3
CFLAGS_DEBUG += -O0 -g3 -Wall -Wextra -Werror

CFLAGS_LOCAL := -std=c11 -Wall -Wextra -Werror -D VERSION=\"$(VERSION)\"
CFLAGS_LOCAL += -I . -I $(MBEDTLS_SRC)/include/
CFLAGS_LOCAL += -D MBEDTLS_CONFIG_FILE='<$(MBEDTLS_CFG)>'
CFLAGS_LOCAL += -D _POSIX_C_SOURCE=200809L
CFLAGS_LOCAL += -D _DARWIN_C_SOURCE
RIRC_CFLAGS += -std=c11 -I. -DVERSION=\"$(VERSION)\"
RIRC_CFLAGS += -D_POSIX_C_SOURCE=200809L
RIRC_CFLAGS += -D_DARWIN_C_SOURCE

LDFLAGS ?=
LDFLAGS += -lpthread

SRC     := $(shell find $(DIR_S) -name '*.c')
SUBDIRS += $(shell find $(DIR_S) -name '*.c' -exec dirname {} \; | sort -u)
SRC       := $(shell find $(PATH_SRC) -name '*.c')
SRC_GPERF := $(patsubst %, %.out, $(shell find $(PATH_SRC) -name '*.gperf'))

SRC_G   := $(shell find $(DIR_S) -name '*.gperf')
SUBDIRS += $(shell find $(DIR_S) -name '*.gperf' -exec dirname {} \; | sort -u)
# Release objects, debug objects, testcases
OBJS_R := $(patsubst $(PATH_SRC)/%.c, $(PATH_BUILD)/%.o,    $(SRC))
OBJS_D := $(patsubst $(PATH_SRC)/%.c, $(PATH_BUILD)/%.db.o, $(SRC))
OBJS_T := $(patsubst $(PATH_SRC)/%.c, $(PATH_BUILD)/%.t,    $(SRC))
OBJS_T += $(PATH_BUILD)/utils/tree.t # Header only file

# Release, debug, and testcase build objects
OBJS_D := $(patsubst $(DIR_S)/%.c, $(DIR_B)/%.db.o, $(SRC))
OBJS_R := $(patsubst $(DIR_S)/%.c, $(DIR_B)/%.o,    $(SRC))
OBJS_T := $(patsubst $(DIR_S)/%.c, $(DIR_B)/%.t,    $(SRC))
OBJS_T += $(DIR_B)/utils/tree.t # Header only file

# Gperf generated source files
OBJS_G := $(patsubst %.gperf, %.gperf.out, $(SRC_G))

# Release build executable
$(BIN_R): $(MBEDTLS_LIBS) $(OBJS_G) $(OBJS_R)
rirc: $(RIRC_LIBS) $(SRC_GPERF) $(OBJS_R)
	@echo "  CC    $@"
	@$(CC) $(LDFLAGS) -o $@ $(OBJS_R) $(MBEDTLS_LIBS)
	@$(CC) $(LDFLAGS) -o $@ $(OBJS_R) $(RIRC_LIBS)

# Debug build executable
$(BIN_D): $(MBEDTLS_LIBS) $(OBJS_G) $(OBJS_D)
rirc.debug: $(RIRC_LIBS) $(SRC_GPERF) $(OBJS_D)
	@echo "  CC    $@"
	@$(CC) $(LDFLAGS) -o $@ $(OBJS_D) $(MBEDTLS_LIBS)
	@$(CC) $(LDFLAGS) -o $@ $(OBJS_D) $(RIRC_LIBS)

# Release build objects
$(DIR_B)/%.o: $(DIR_S)/%.c $(CONFIG) | $(DIR_B)
$(PATH_BUILD)/%.o: $(PATH_SRC)/%.c $(CONFIG) | $(PATH_BUILD)
	@echo "  CC    $<"
	@$(CPP) $(CFLAGS) $(CFLAGS_LOCAL) -MM -MP -MT $@ -MF $(@:.o=.o.d) $<
	@$(CC)  $(CFLAGS) $(CFLAGS_LOCAL) -c -o $@ $<
	@$(CPP) $(CFLAGS) $(RIRC_CFLAGS) -MM -MP -MT $@ -MF $(@:.o=.o.d) $<
	@$(CC)  $(CFLAGS) $(RIRC_CFLAGS) -c -o $@ $<

# Debug build objects
$(DIR_B)/%.db.o: $(DIR_S)/%.c $(CONFIG) | $(DIR_B)
$(PATH_BUILD)/%.db.o: $(PATH_SRC)/%.c $(CONFIG) | $(PATH_BUILD)
	@echo "  CC    $<"
	@$(CPP) $(CFLAGS_DEBUG) $(CFLAGS_LOCAL) -MM -MP -MT $@ -MF $(@:.o=.o.d) $<
	@$(CC)  $(CFLAGS_DEBUG) $(CFLAGS_LOCAL) -c -o $@ $<

# Testcases
$(DIR_B)/%.t: $(DIR_T)/%.c $(OBJS_G) $(CONFIG) | $(DIR_B)
	@$(CPP) $(CFLAGS_DEBUG) $(CFLAGS_LOCAL) -MM -MP -MT $@ -MF $(@:.t=.t.d) $<
	@$(CC)  $(CFLAGS_DEBUG) $(CFLAGS_LOCAL) -c -o $(@:.t=.t.o) $<
	@$(CC)  $(CFLAGS_DEBUG) $(CFLAGS_LOCAL) -o $@ $(@:.t=.t.o)
	@$(CPP) $(CFLAGS_DEBUG) $(RIRC_CFLAGS) -MM -MP -MT $@ -MF $(@:.o=.o.d) $<
	@$(CC)  $(CFLAGS_DEBUG) $(RIRC_CFLAGS) -c -o $@ $<

$(PATH_BUILD)/%.t: $(PATH_TEST)/%.c $(SRC_GPERF) $(CONFIG) | $(PATH_BUILD)
	@$(CPP) $(CFLAGS_DEBUG) $(RIRC_CFLAGS) -MM -MP -MT $@ -MF $(@:.t=.t.d) $<
	@$(CC)  $(CFLAGS_DEBUG) $(RIRC_CFLAGS) -c -o $(@:.t=.t.o) $<
	@$(CC)  $(CFLAGS_DEBUG) $(RIRC_CFLAGS) -o $@ $(@:.t=.t.o)
	@./$@ || mv $@ $(@:.t=.td)
	@[ -f $@ ]

# Build directories
$(DIR_B):
	@for dir in $(patsubst $(DIR_S)/%, $(DIR_B)/%, $(SUBDIRS)); do mkdir -p $$dir; done
$(PATH_BUILD):
	@mkdir -p $(patsubst $(PATH_SRC)%, $(PATH_BUILD)%, $(shell find $(PATH_SRC) -type d))

$(CONFIG):
	cp config.def.h config.h


@@ 89,37 68,36 @@ $(CONFIG):
	gperf --output-file=$@ $<

all:
	@$(MAKE) --silent $(BIN_R)
	@$(MAKE) --silent $(BIN_D)
	@$(MAKE) --silent rirc
	@$(MAKE) --silent rirc.debug

check:
	@$(MAKE) --silent $(OBJS_T)

clean:
	@rm -rf $(DIR_B)
	@rm -vf $(BIN_R) $(BIN_D) $(OBJS_G)
	@rm -rfv rirc rirc.debug $(SRC_GPERF) $(PATH_BUILD)

libs:
	@$(MAKE) --silent $(MBEDTLS_LIBS)
	@$(MAKE) --silent $(RIRC_LIBS)

install: $(BIN_R)
	@echo installing executable to $(BIN_DIR)
	@echo installing manual page to $(MAN_DIR)
	@mkdir -p $(BIN_DIR)
	@mkdir -p $(MAN_DIR)
	@cp -f rirc $(BIN_DIR)
	@chmod 755 $(BIN_DIR)/rirc
	@sed "s/VERSION/$(VERSION)/g" < rirc.1 > $(MAN_DIR)/rirc.1
install: rirc
	@sed "s/VERSION/$(VERSION)/g" < docs/rirc.1 > rirc.1
	mkdir -p $(BIN_PATH)
	mkdir -p $(MAN_PATH)
	cp -f rirc   $(BIN_PATH)
	cp -f rirc.1 $(MAN_PATH)
	chmod 755 $(BIN_PATH)/rirc
	chmod 644 $(MAN_PATH)/rirc.1

uninstall:
	rm -f $(BIN_DIR)/rirc
	rm -f $(MAN_DIR)/rirc.1
	rm -f $(BIN_PATH)/rirc
	rm -f $(MAN_PATH)/rirc.1

-include $(OBJS_R:.o=.o.d)
-include $(OBJS_D:.o=.o.d)
-include $(OBJS_T:.t=.t.d)

.DEFAULT_GOAL := $(BIN_R)
.DEFAULT_GOAL := rirc

.PHONY: all check clean libs install uninstall


M README.md => README.md +12 -25
@@ 30,43 30,30 @@ A minimalistic irc client written in C.

Connections are TLS enabled over port 6697 by default.

### Configuring:
## Building, installing:

Configure rirc by editing `config.h`. Defaults are in `config.def.h`

### Building:

rirc requires the latest version of GNU gperf to compile.

See: https://www.gnu.org/software/gperf/
Building rirc from source requires a c11 compiler, GNU gperf and GNU make.

Build rirc:
 - https://www.gnu.org/software/gperf/
 - https://www.gnu.org/software/make/

```
make
make install
```

The build toolchain can be configured via standard environment variables, e.g.:
```
CC=clang CFLAGS='-Os' LDFLAGS='-fuse-ld=lld' make
```

### Installing:

Default install path:
The build toolchain and install paths can be configured via standard
environment variables, i.e.:

```
BIN_DIR = /usr/local/bin
MAN_DIR = /usr/local/share/man/man1
CC, CFLAGS, LDFLAGS, DESTDIR, PREFIX
```

Edit `Makefile` to alter install path if needed, then:
## Configuring:

```
make install
```
Configure rirc by editing `config.h`. Defaults are in `config.def.h`

### Usage:
## Usage:

```
rirc [-hv] [-s server [...]]


@@ 117,6 104,6 @@ Keys:
   ↓ : input history forward
```

### More info:
## More info:

[https://rcr.io/rirc/](http://rcr.io/rirc/)

R rirc.1 => docs/rirc.1 +0 -0
M lib/mbedtls.Makefile => lib/mbedtls.Makefile +21 -9
@@ 1,10 1,10 @@
MBEDTLS_VER     := 2.25.0
MBEDTLS_VER_SHA := f838f670f51070bc6b4ebf0c084affd9574652ded435b064969f36ce4e8b586d

MBEDTLS_CFG := $(abspath $(DIR_L)/mbedtls.h)
MBEDTLS_SHA := $(abspath $(DIR_L)/mbedtls.sha256)
MBEDTLS_SRC := $(abspath $(DIR_L)/mbedtls-$(MBEDTLS_VER))
MBEDTLS_TAR := $(abspath $(DIR_L)/mbedtls-$(MBEDTLS_VER).tar.gz)
MBEDTLS_CFG := $(abspath $(PATH_LIB)/mbedtls.h)
MBEDTLS_SHA := $(abspath $(PATH_LIB)/mbedtls.sha256)
MBEDTLS_SRC := $(abspath $(PATH_LIB)/mbedtls-$(MBEDTLS_VER))
MBEDTLS_TAR := $(abspath $(PATH_LIB)/mbedtls-$(MBEDTLS_VER).tar.gz)
MBEDTLS_URL := https://github.com/ARMmbed/mbedtls/archive/v$(MBEDTLS_VER).tar.gz

MBEDTLS_LIBS := \


@@ 16,11 16,23 @@ $(MBEDTLS_LIBS): $(MBEDTLS_CFG) $(MBEDTLS_SRC)
	@$(MAKE) --silent -C $(MBEDTLS_SRC) clean
	@$(MAKE) --silent -C $(MBEDTLS_SRC) CFLAGS="$(CFLAGS) -DMBEDTLS_CONFIG_FILE='<$(MBEDTLS_CFG)>'" lib

$(MBEDTLS_SRC): $(MBEDTLS_SHA)
$(MBEDTLS_SRC): $(MBEDTLS_TAR)
	@tar -xmf $(MBEDTLS_TAR) --directory $(PATH_LIB)

$(MBEDTLS_TAR):
	@echo "$(MBEDTLS_TAR)..."
	@curl -LfsS $(MBEDTLS_URL) -o $(MBEDTLS_TAR)
	@sha256sum -c $(MBEDTLS_SHA)
	@tar -xmf $(MBEDTLS_TAR) --directory $(DIR_L)
	@eval $(MBEDTLS_SHA_FILE)
	@eval $(MBEDTLS_SHA_CHECK)

ifneq ($(shell command -v shasum 2>/dev/null),)
MBEDTLS_SHA_FILE  := 'echo "$(MBEDTLS_VER_SHA)  $(MBEDTLS_TAR)" > $(MBEDTLS_SHA)'
MBEDTLS_SHA_CHECK := 'shasum -c $(MBEDTLS_SHA)'
endif

RIRC_CFLAGS += -I$(MBEDTLS_SRC)/include/
RIRC_CFLAGS += -DMBEDTLS_CONFIG_FILE='<$(MBEDTLS_CFG)>'

RIRC_LIBS += $(MBEDTLS_LIBS)

$(MBEDTLS_SHA):
	@echo "$(MBEDTLS_VER_SHA)  $(MBEDTLS_TAR)" > $(MBEDTLS_SHA)
.DELETE_ON_ERROR: