mirror of https://github.com/krallin/tini.git
Convert to CMake
This commit is contained in:
parent
3003e55a8c
commit
296a29e3da
|
@ -0,0 +1,27 @@
|
|||
cmake_minimum_required (VERSION 2.8.12)
|
||||
project (tini)
|
||||
|
||||
# Config
|
||||
set (tini_VERSION_MAJOR 0)
|
||||
set (tini_VERSION_MINOR 3)
|
||||
set (tini_VERSION_PATCH 1)
|
||||
execute_process (COMMAND git log -n 1 --date=local --pretty=format:"%h" OUTPUT_VARIABLE tini_VERSION_GIT)
|
||||
|
||||
# Flags
|
||||
add_definitions (-D_FORTIFY_SOURCE=2)
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wextra -Wall -pedantic -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security")
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-s")
|
||||
|
||||
# Build
|
||||
|
||||
configure_file (
|
||||
"${PROJECT_SOURCE_DIR}/tiniConfig.h.in"
|
||||
"${PROJECT_BINARY_DIR}/tiniConfig.h"
|
||||
)
|
||||
|
||||
include_directories ("${PROJECT_BINARY_DIR}")
|
||||
|
||||
add_executable (tini tini.c)
|
||||
|
||||
add_executable (tini-static tini.c)
|
||||
set_target_properties (tini-static PROPERTIES LINK_FLAGS "-static")
|
|
@ -1,10 +1,12 @@
|
|||
FROM ubuntu
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install --no-install-recommends --yes build-essential git gdb valgrind \
|
||||
&& apt-get install --no-install-recommends --yes build-essential git gdb valgrind cmake \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ADD . /tini
|
||||
RUN cd /tini && make clean && make
|
||||
WORKDIR /tini
|
||||
|
||||
RUN cmake . && make clean && make
|
||||
|
||||
ENTRYPOINT ["/tini/tini"]
|
||||
|
|
34
Makefile
34
Makefile
|
@ -1,34 +0,0 @@
|
|||
include config.mk
|
||||
|
||||
OBJ = tini.o
|
||||
BIN = tini
|
||||
|
||||
all: $(BIN) $(BIN)-static
|
||||
|
||||
$(BIN): $(OBJ)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $<
|
||||
|
||||
$(BIN)-static: $(OBJ)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -static -o $@ $<
|
||||
|
||||
$(OBJ):
|
||||
|
||||
install: all
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||
cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin
|
||||
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN)
|
||||
|
||||
dist: clean
|
||||
mkdir -p tini-$(VERSION)
|
||||
cp LICENSE Makefile README config.def.h config.mk tini.c tini-$(VERSION)
|
||||
tar -cf tini-$(VERSION).tar tini-$(VERSION)
|
||||
gzip tini-$(VERSION).tar
|
||||
rm -rf tini-$(VERSION)
|
||||
|
||||
clean:
|
||||
rm -f $(BIN) $(OBJ) tini-$(VERSION).tar.gz
|
||||
|
||||
.PHONY:
|
||||
all install uninstall dist clean check
|
11
config.mk
11
config.mk
|
@ -1,11 +0,0 @@
|
|||
VERSION=0.3.0
|
||||
GIT_REV=$(shell git log -n 1 --date=local --pretty=format:"%h")
|
||||
|
||||
# paths
|
||||
PREFIX=/usr/local
|
||||
|
||||
CC = cc
|
||||
LD = $(CC)
|
||||
CPPFLAGS=-D_FORTIFY_SOURCE=2 -DTINI_VERSION="\"$(VERSION) - $(GIT_REV)\""
|
||||
CFLAGS=-std=gnu99 -Wextra -Wall -pedantic -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security
|
||||
LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-s
|
8
ddist.sh
8
ddist.sh
|
@ -13,7 +13,13 @@ NAME="${IMG}-dist"
|
|||
BIN="tini"
|
||||
|
||||
docker build -t "${IMG}" .
|
||||
docker run -it --name="${NAME}" "${IMG}" true "-h"
|
||||
|
||||
# Smoke tests
|
||||
docker run -it --rm --entrypoint="/tini/${BIN}" "${IMG}" "-h" "--" "true"
|
||||
docker run -it --rm --entrypoint="/tini/${BIN}-static" "${IMG}" "-h" "--" "true"
|
||||
|
||||
# Copy the binaries
|
||||
docker run -it --entrypoint="/bin/true" --name="${NAME}" "${IMG}"
|
||||
docker cp "${NAME}:/tini/${BIN}" "${DIST_DIR}"
|
||||
docker cp "${NAME}:/tini/${BIN}-static" "${DIST_DIR}"
|
||||
docker rm "${NAME}"
|
||||
|
|
6
tini.c
6
tini.c
|
@ -13,9 +13,7 @@
|
|||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef TINI_VERSION
|
||||
#define TINI_VERSION "???"
|
||||
#endif
|
||||
#include "tiniConfig.h"
|
||||
|
||||
#define PRINT_FATAL(...) fprintf(stderr, "[FATAL] "); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n");
|
||||
#define PRINT_WARNING(...) if (verbosity > 0) { fprintf(stderr, "[WARN ] "); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); }
|
||||
|
@ -56,7 +54,7 @@ int spawn(const sigset_t* const child_sigset_ptr, char (*argv[]), int* const chi
|
|||
|
||||
|
||||
void print_usage(char* const name, FILE* const file) {
|
||||
fprintf(file, "%s (version %s)\n", basename(name), TINI_VERSION);
|
||||
fprintf(file, "%s (version %s - %s)\n", basename(name), TINI_VERSION, TINI_GIT);
|
||||
fprintf(file, "Usage: %s [OPTIONS] PROGRAM -- [ARGS]\n\n", basename(name));
|
||||
fprintf(file, "Execute a program under the supervision of a valid init process (%s)\n\n", basename(name));
|
||||
fprintf(file, " -h: Show this help message and exit.\n");
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#define TINI_VERSION "@tini_VERSION_MAJOR@.@tini_VERSION_MINOR@.@tini_VERSION_PATCH@"
|
||||
#define TINI_GIT @tini_VERSION_GIT@
|
Loading…
Reference in New Issue