aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.dockerignore1
-rw-r--r--.gitignore1
-rw-r--r--Dockerfile22
-rw-r--r--Makefile60
-rw-r--r--docker-compose.yml2
5 files changed, 73 insertions, 13 deletions
diff --git a/.dockerignore b/.dockerignore
index 9c6fc5c..01dd835 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -2,4 +2,5 @@
!/CMakeLists.txt
!/LICENSE.txt
+!/Makefile
!/src/**
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0e03e15
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/.build/
diff --git a/Dockerfile b/Dockerfile
index 3a5531d..22c9ff7 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,25 +4,23 @@ ARG install_dir="/app/install"
FROM base AS builder
-RUN apk add --no-cache bsd-compat-headers build-base clang cmake libgit2-dev
+RUN apk add --no-cache bash bsd-compat-headers build-base clang cmake libgit2-dev
-ARG default_host=127.0.0.1
+ARG C_COMPILER=clang
+ARG BUILD_TYPE=Release
+ARG DEFAULT_HOST=127.0.0.1
ARG src_dir="/app/src"
-ARG build_dir="/app/build"
ARG install_dir
COPY [".", "$src_dir"]
-RUN mkdir -- "$build_dir" && \
- cd -- "$build_dir" && \
- cmake \
- -D "DEFAULT_HOST=$default_host" \
- -D CMAKE_C_COMPILER=clang \
- -D CMAKE_BUILD_TYPE=Release \
- -D "CMAKE_INSTALL_PREFIX=$install_dir" \
- "$src_dir" && \
- make -j install
+RUN cd -- "$src_dir" && \
+ make install \
+ "C_COMPILER=$C_COMPILER" \
+ "BUILD_TYPE=$BUILD_TYPE" \
+ "DEFAULT_HOST=$DEFAULT_HOST" \
+ "INSTALL_PREFIX=$install_dir"
FROM base
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..5ae034d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,60 @@
+MAKEFLAGS += --no-builtin-rules --no-builtin-variables --warn-undefined-variables
+unexport MAKEFLAGS
+.DEFAULT_GOAL := all
+.DELETE_ON_ERROR:
+.SUFFIXES:
+SHELL := bash
+.SHELLFLAGS := -eu -o pipefail -c
+
+escape = $(subst ','\'',$(1))
+
+define noexpand
+ifeq ($$(origin $(1)),environment)
+ $(1) := $$(value $(1))
+endif
+ifeq ($$(origin $(1)),environment override)
+ $(1) := $$(value $(1))
+endif
+ifeq ($$(origin $(1)),command line)
+ override $(1) := $$(value $(1))
+endif
+endef
+
+src_dir := $(abspath .)
+build_dir := $(src_dir)/.build
+cmake_dir := $(build_dir)/cmake
+install_dir := $(build_dir)/install
+
+C_COMPILER ?= clang
+BUILD_TYPE ?= Debug
+DEFAULT_HOST ?= 127.0.0.1
+INSTALL_PREFIX ?= $(install_dir)
+
+$(eval $(call noexpand,C_COMPILER))
+$(eval $(call noexpand,BUILD_TYPE))
+$(eval $(call noexpand,DEFAULT_HOST))
+$(eval $(call noexpand,INSTALL_PREFIX))
+
+.PHONY: all
+all: build
+
+.PHONY: clean
+clean:
+ rm -rf -- '$(call escape,$(build_dir))'
+
+.PHONY: build
+build:
+ mkdir -p -- '$(call escape,$(cmake_dir))'
+ cmake \
+ -G 'Unix Makefiles' \
+ -D 'CMAKE_C_COMPILER=$(call escape,$(C_COMPILER))' \
+ -D 'CMAKE_BUILD_TYPE=$(call escape,$(BUILD_TYPE))' \
+ -D 'CMAKE_INSTALL_PREFIX=$(call escape,$(INSTALL_PREFIX))' \
+ -D 'DEFAULT_HOST=$(call escape,$(DEFAULT_HOST))' \
+ -S '$(call escape,$(src_dir))' \
+ -B '$(call escape,$(cmake_dir))'
+ cmake --build '$(call escape,$(cmake_dir))' -- -j
+
+.PHONY: install
+install: build
+ cmake --install '$(call escape,$(cmake_dir))'
diff --git a/docker-compose.yml b/docker-compose.yml
index 2fa5367..44c809c 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -4,7 +4,7 @@ x-cimple: &common
build:
context: .
args:
- default_host: server
+ DEFAULT_HOST: server
image: egortensin/cimple
restart: always