~rcr/rirc

281a93e4c12c84dc6f263e49e79fd3e61c3ce874 — Richard Robbins 29 days ago 528d224
remove submodules, refactor Makefile
M .builds/compat/debian.yml => .builds/compat/debian.yml +3 -8
@@ 1,24 1,19 @@
image: debian/stable

packages:
  - cmake
  - curl
  - gperf

sources:
  - https://git.sr.ht/~rcr/rirc

tasks:
  - setup: |
      cd rirc
      git submodule init
      git submodule update --recursive
      export MAKEFLAGS='-j $(nproc)'
  - build: |
      cd rirc
      make all
      MAKEFLAGS='-j $(nproc)' make all
  - check: |
      cd rirc
      make check
      MAKEFLAGS='-j $(nproc)' make check

triggers:
  - action: email

M .builds/compat/fedora.yml => .builds/compat/fedora.yml +3 -8
@@ 1,24 1,19 @@
image: fedora/latest

packages:
  - cmake
  - curl
  - gperf

sources:
  - https://git.sr.ht/~rcr/rirc

tasks:
  - setup: |
      cd rirc
      git submodule init
      git submodule update --recursive
      export MAKEFLAGS='-j $(nproc)'
  - build: |
      cd rirc
      make all
      MAKEFLAGS='-j $(nproc)' make all
  - check: |
      cd rirc
      make check
      MAKEFLAGS='-j $(nproc)' make check

triggers:
  - action: email

M .builds/compat/freebsd.yml => .builds/compat/freebsd.yml +3 -8
@@ 1,7 1,7 @@
image: freebsd/latest

packages:
  - cmake
  - curl
  - gmake
  - gperf



@@ 9,17 9,12 @@ sources:
  - https://git.sr.ht/~rcr/rirc

tasks:
  - setup: |
      cd rirc
      git submodule init
      git submodule update --recursive
      export MAKEFLAGS='-j $(nproc)'
  - build: |
      cd rirc
      gmake all
      MAKEFLAGS='-j $(nproc)' gmake all
  - check: |
      cd rirc
      gmake check
      MAKEFLAGS='-j $(nproc)' gmake check

triggers:
  - action: email

M .builds/compat/openbsd.yml => .builds/compat/openbsd.yml +3 -8
@@ 1,7 1,7 @@
image: openbsd/latest

packages:
  - cmake
  - curl
  - gmake
  - gperf



@@ 9,17 9,12 @@ sources:
  - https://git.sr.ht/~rcr/rirc

tasks:
  - setup: |
      cd rirc
      git submodule init
      git submodule update --recursive
      export MAKEFLAGS='-j $(nproc)'
  - build: |
      cd rirc
      gmake all
      MAKEFLAGS='-j $(nproc)' gmake all
  - check: |
      cd rirc
      gmake check
      MAKEFLAGS='-j $(nproc)' gmake check

triggers:
  - action: email

M .builds/dev.yml => .builds/dev.yml +2 -8
@@ 1,7 1,6 @@
image: alpine/latest

packages:
  - cmake
  - curl
  - gperf
  - unzip


@@ 14,17 13,12 @@ secrets:
  - a58d0951-f57f-44ef-8ef2-25f2f84f0e89

tasks:
  - setup: |
      cd rirc
      git submodule init
      git submodule update --recursive
      export MAKEFLAGS='-j $(nproc)'
  - build: |
      cd rirc
      make all
      MAKEFLAGS='-j $(nproc)' make all
  - check: |
      cd rirc
      make check
      MAKEFLAGS='-j $(nproc)' make check
  - static-analysis: |
      cd rirc
      [ $(git name-rev --name-only HEAD) = "remotes/origin/static_analysis" ] || complete-build

M .gitignore => .gitignore +3 -2
@@ 3,17 3,18 @@
*.gcov
*.gperf.out
*.o
*.out
*.t
*.td
.clangd
.cache
bld
compile_commands.json
config.h
coverage
lib/mbedtls-*
lib/mbedtls.sha256
rirc
rirc.debug
rirc.debug.address
rirc.debug.thread
rirc.out
tags

M .gitmodules => .gitmodules +0 -4
@@ 1,4 0,0 @@
[submodule "mbedtls"]
	path = lib/mbedtls
	url = https://github.com/ARMmbed/mbedtls.git
	ignore = dirty

M Makefile => Makefile +48 -47
@@ 1,6 1,6 @@
VERSION := 0.1.4

# Release and debug build executable names
# Release and debug executable names
BIN_R := rirc
BIN_D := rirc.debug



@@ 8,27 8,28 @@ BIN_D := rirc.debug
BIN_DIR := /usr/local/bin
MAN_DIR := /usr/local/share/man/man1

TLS_CONF := $(PWD)/lib/mbedtls.h
TLS_INCL := -I $(PWD)/lib/mbedtls/include/ -DMBEDTLS_CONFIG_FILE='<$(TLS_CONF)>'
TLS_LIBS := ./lib/mbedtls/library/libmbedtls.a \
            ./lib/mbedtls/library/libmbedx509.a \
            ./lib/mbedtls/library/libmbedcrypto.a

STDS := -std=c11 -D_POSIX_C_SOURCE=200809L

CC := cc
PP := cc -E
CFLAGS   := $(CC_EXT) $(STDS) $(TLS_INCL) -I. -DVERSION=\"$(VERSION)\" -D_DARWIN_C_SOURCE -Wall -Wextra -pedantic
CFLAGS_R := $(CFLAGS) -O2 -flto -DNDEBUG
CFLAGS_D := $(CFLAGS) -O0 -g
LDFLAGS  := $(LD_EXT) -lpthread

# Build, source, test source directories
# Build, source, lib, and test directories
DIR_B := bld
DIR_S := src
DIR_L := lib
DIR_T := test

PWD  := $(shell pwd)
include lib/mbedtls.Makefile

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

CFLAGS_DEBUG ?=
CFLAGS_DEBUG += -O0 -g3

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

LDFLAGS ?=
LDFLAGS += -lpthread

SRC     := $(shell find $(DIR_S) -name '*.c')
SUBDIRS += $(shell find $(DIR_S) -name '*.c' -exec dirname {} \; | sort -u)


@@ 36,7 37,7 @@ SUBDIRS += $(shell find $(DIR_S) -name '*.c' -exec dirname {} \; | sort -u)
SRC_G   := $(shell find $(DIR_S) -name '*.gperf')
SUBDIRS += $(shell find $(DIR_S) -name '*.gperf' -exec dirname {} \; | sort -u)

# Release, debug, testcase build objects
# 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))


@@ 46,50 47,45 @@ OBJS_T += $(DIR_B)/utils/tree.t # Header only file
OBJS_G := $(patsubst %.gperf, %.gperf.out, $(SRC_G))

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

# Debug build executable
$(BIN_D): $(TLS_LIBS) $(OBJS_G) $(OBJS_D)
	@echo " CC  $@"
	@$(CC) $(LDFLAGS) -o $@ $(OBJS_D) $(TLS_LIBS)
$(BIN_D): $(MBEDTLS_LIBS) $(OBJS_G) $(OBJS_D)
	@echo "  CC    $@"
	@$(CC) $(LDFLAGS) -o $@ $(OBJS_D) $(MBEDTLS_LIBS)

# Release build objects
$(DIR_B)/%.o: $(DIR_S)/%.c config.h | $(DIR_B)
	@echo " CC  $<"
	@$(PP) $(CFLAGS_R) -MM -MP -MT $@ -MF $(@:.o=.o.d) $<
	@$(CC) $(CFLAGS_R) -c -o $@ $<
$(DIR_B)/%.o: $(DIR_S)/%.c | $(DIR_B)
	@echo "  CC    $<"
	@$(CPP) $(CFLAGS) $(CFLAGS_LOCAL) -MM -MP -MT $@ -MF $(@:.o=.o.d) $<
	@$(CC)  $(CFLAGS) $(CFLAGS_LOCAL) -c -o $@ $<

# Debug build objects
$(DIR_B)/%.db.o: $(DIR_S)/%.c config.h | $(DIR_B)
	@echo " CC  $<"
	@$(PP) $(CFLAGS_D) -MM -MP -MT $@ -MF $(@:.o=.o.d) $<
	@$(CC) $(CFLAGS_D) -c -o $@ $<
$(DIR_B)/%.db.o: $(DIR_S)/%.c | $(DIR_B)
	@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) | $(DIR_B)
	@$(PP) $(CFLAGS_D) -MM -MP -MT $@ -MF $(@:.t=.t.d) $<
	@$(CC) $(CFLAGS_D) -c -o $(@:.t=.t.o) $<
	@$(CC) $(CFLAGS_D) -o $@ $(@:.t=.t.o)
	@$(TEST_EXT) ./$@ || mv $@ $(@:.t=.td)
	@$(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)
	@./$@ || mv $@ $(@:.t=.td)
	@[ -f $@ ]

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

config.h:
	cp config.def.h config.h

%.gperf.out: %.gperf
	gperf --output-file=$@ $<

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

# TLS libraries
$(TLS_LIBS): $(TLS_CONF)
	@CFLAGS="$(TLS_INCL)" $(MAKE) --silent -C ./lib/mbedtls clean
	@CFLAGS="$(TLS_INCL)" $(MAKE) --silent -C ./lib/mbedtls lib

all:
	@$(MAKE) --silent $(BIN_R)
	@$(MAKE) --silent $(BIN_D)


@@ 101,7 97,8 @@ clean:
	@rm -rf $(DIR_B)
	@rm -vf $(BIN_R) $(BIN_D) $(OBJS_G)

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

install: $(BIN_R)
	@echo installing executable to $(BIN_DIR)


@@ 120,4 117,8 @@ uninstall:
-include $(OBJS_D:.o=.o.d)
-include $(OBJS_T:.t=.t.d)

.DEFAULT_GOAL := $(BIN_R)

.PHONY: all check clean libs install uninstall

.SUFFIXES:

M README.md => README.md +5 -2
@@ 43,11 43,14 @@ See: https://www.gnu.org/software/gperf/
Build rirc:

```
git submodule init
git submodule update --recursive
make
```

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:

D lib/mbedtls => lib/mbedtls +0 -1
@@ 1,1 0,0 @@
Subproject commit 1c54b5410fd48d6bcada97e30cac417c5c7eea67

A lib/mbedtls.Makefile => lib/mbedtls.Makefile +26 -0
@@ 0,0 1,26 @@
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_URL := https://github.com/ARMmbed/mbedtls/archive/v$(MBEDTLS_VER).tar.gz

MBEDTLS_LIBS := \
	$(MBEDTLS_SRC)/library/libmbedtls.a \
	$(MBEDTLS_SRC)/library/libmbedx509.a \
	$(MBEDTLS_SRC)/library/libmbedcrypto.a

$(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)
	@echo "curl $(MBEDTLS_TAR)..."
	@curl -LfsS $(MBEDTLS_URL) -o $(MBEDTLS_TAR)
	@shasum -a 256 -q --check $(MBEDTLS_SHA)
	@tar -xmf $(MBEDTLS_TAR) --directory $(DIR_L)

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

M scripts/compile_commands.sh => scripts/compile_commands.sh +2 -2
@@ 3,8 3,8 @@
set -e

export CC=clang
export CC_EXT="-Wno-empty-translation-unit"
export CFLAGS="-Wno-empty-translation-unit"

rm -f compile_commands.json

bear make clean rirc.debug
bear make clean rirc

M scripts/coverage.sh => scripts/coverage.sh +1 -2
@@ 5,8 5,7 @@ set -e
CDIR="coverage"

export CC=gcc
export CC_EXT="-fprofile-arcs -ftest-coverage -fprofile-abs-path"
export LD_EXT="-fprofile-arcs"
export CFLAGS_DEBUG="-fprofile-arcs -ftest-coverage -fprofile-abs-path"

export MAKEFLAGS="-e -j $(nproc)"


M scripts/sanitizers_build.sh => scripts/sanitizers_build.sh +4 -4
@@ 4,15 4,15 @@ set -e

export CC=clang

export CC_EXT="-fsanitize=address,undefined -fno-omit-frame-pointer"
export LD_EXT="-fsanitize=address,undefined"
export CFLAGS_DEBUG="-fsanitize=address,undefined -fno-omit-frame-pointer"
export LDFLAGS="-fsanitize=address,undefined"

make -e clean rirc.debug

mv rirc.debug rirc.debug.address

export CC_EXT="-fsanitize=thread,undefined -fno-omit-frame-pointer"
export LD_EXT="-fsanitize=thread,undefined"
export CFLAGS_DEBUG="-fsanitize=thread,undefined -fno-omit-frame-pointer"
export LDFLAGS="-fsanitize=thread,undefined"

make -e clean rirc.debug


M scripts/sanitizers_test.sh => scripts/sanitizers_test.sh +2 -2
@@ 3,8 3,8 @@
set -e

export CC=clang
export CC_EXT="-fsanitize=address,undefined -fno-omit-frame-pointer"
export LD_EXT="-fsanitize=address,undefined -fuse-ld=lld"
export CFLAGS_DEBUG="-fsanitize=address,undefined -fno-omit-frame-pointer"
export LDFLAGS="-fsanitize=address,undefined -fuse-ld=lld"

# for core dumps:
# export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0"

M scripts/stack_usage.sh => scripts/stack_usage.sh +2 -2
@@ 3,8 3,8 @@
set -e

export CC=gcc
export CC_EXT="-fstack-usage"
export CFLAGS_DEBUG="-fstack-usage"

make -e clean rirc.debug

find . -name "*.su" -exec cat "{}" ";" | sort -n -k2 | column -t
find bld -name "*.su" -exec cat "{}" ";" | sort -n -k2 | column -t