diff options
author | kartofen <mladenovnasko0@gmail.com> | 2025-04-07 02:39:58 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2025-04-07 02:39:58 +0300 |
commit | 844b90ec6b79be309d0bd3d08df36b78d48eee90 (patch) | |
tree | 7f597420569186515cc7555caa74841be1e52925 | |
parent | 0606300e7638574c76b3e72e9b5f965a442b3cb7 (diff) |
refactor install things
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | builtfiles.dd.m4 | 22 | ||||
-rw-r--r-- | ninja.m4 | 33 | ||||
-rw-r--r-- | scanbuild.m4 | 22 |
4 files changed, 43 insertions, 39 deletions
@@ -15,9 +15,12 @@ use `ninja` to build, with options like: * `shared`, `static`, `header` for bulding to a usable library and * `test`to run the unit tests. +* `install` to install the built files in output directories set by `ninja configure` To change paths and presets using `ninja configure` with an appropriate environment variable: -* `BIN=<path>` to set the output directory * `PROD=1` to use the non-debug flags +* `PREFIX=<path>` used for other paths, default `installdir` +* `LIBDIR=<path>` used for libraries (.so and .a), default `PREFIX/lib` +* `INCLUDEDIR=<path>` used for c headers, default `PREFIX/include` diff --git a/builtfiles.dd.m4 b/builtfiles.dd.m4 new file mode 100644 index 0000000..bbbf713 --- /dev/null +++ b/builtfiles.dd.m4 @@ -0,0 +1,22 @@ + divert(-1) +changequote([,]) + +define(iterate_files, [esyscmd([ + for f in $(command ls $1/*.$2 2> /dev/null); do + echo -n "$f "; + done])]) +define(substitue, [esyscmd([ + for f in $1; do + echo -n "${f/$2/$3} "; + done])]) + +define(LIBS, [iterate_files([build], [so]) iterate_files([build], [a])]) +define(HEADERS, [iterate_files([build], [h])]) + +divert(0) + +ninja_dyndep_version = 1 + +build libs | substitue(LIBS, BIN, LIBDIR): dyndep | LIBS + +build includes | substitue(HEADERS, BIN, INCLUDEDIR): dyndep | HEADERS @@ -1,5 +1,4 @@ divert(-1) - changequote([,]) define([getenv], [ @@ -8,21 +7,17 @@ define([getenv], [ ifelse($2, , [undefine([$1])], [define([$1], [$2])]) ])]) -dnl For installing -getenv([PREFIX], [./testprefix]) -getenv([INCLUDEDIR], [PREFIX/include]) -getenv([LIBDIR], [PREFIX/lib]) - +# global vars getenv([PROD]) divert(0) +# building + cflags = ifdef([PROD], [], [-Wall -Wextra -g]) -std=c99 -D_DEFAULT_SOURCE bin = build m4flags = -# building - rule cc command = gcc $cflags $in -o $out rule obj @@ -46,25 +41,30 @@ build $bin/libmsgpack.so: cc $bin/msgpack.o # installing +divert(-1) +getenv([PREFIX], [installdir]) +getenv([LIBDIR], [PREFIX/lib]) +getenv([INCLUDEDIR], [PREFIX/include]) +divert(0) -# TODO: make copying better and abstract this somehow -pattern = -dir = rule cpy_to_dir - command = cp $$(/bin/ls $pattern 2> /dev/null) $dir 2> /dev/null + command = cp $$(command ls $pattern 2> /dev/null) $dir build force: phony -build $bin/files.dd: m4 scanbuild.m4 | force +build $bin/files.dd: m4 builtfiles.dd.m4 | force m4flags = -D BIN=$bin -D [LIBDIR]=LIBDIR -D [INCLUDEDIR]=INCLUDEDIR + description = Generate dynamic dependency from the built files build libs: cpy_to_dir || $bin/files.dd dir = LIBDIR - pattern = $bin/*.{so,a} + pattern = $bin/*.a $bin/*.so dyndep = $bin/files.dd + description = Install library files to 'LIBDIR' build includes: cpy_to_dir || $bin/files.dd dir = INCLUDEDIR pattern = $bin/*.h dyndep = $bin/files.dd + description = Install header files to 'INCLUDEDIR' # testing @@ -93,8 +93,9 @@ default ifdef([PROD], [static], [test]) rule regen command = m4 ninja.m4 > build.ninja - generator=1 - + generator = 1 + description = Regen build.ninja + build build.ninja: regen ninja.m4 build configure: regen diff --git a/scanbuild.m4 b/scanbuild.m4 deleted file mode 100644 index ba7b8ce..0000000 --- a/scanbuild.m4 +++ /dev/null @@ -1,22 +0,0 @@ -divert(-1) - -changequote([,]) - -define(iterate_files, [esyscmd([for f in $(/bin/ls $1/*.$2); do echo -n "$f "; done])]) -define(substitue, [esyscmd([for f in "$1"; do echo -n "${f/$2/$3} "; done])]) - -define(LIBS_STATIC, [iterate_files([build], [a])]) -define(LIBS_SHARED, [iterate_files([build], [so])]) -define(HEADERS, [iterate_files([build], [h])]) - -divert(0) -ninja_dyndep_version = 1 - -build libs | dnl -substitue(LIBS_STATIC, BIN, LIBDIR)dnl -substitue(LIBS_SHARED, BIN, LIBDIR)dnl -: dyndep | LIBS_STATIC LIBS_SHARED - -build includes | dnl -substitue(HEADERS, BIN, INCLUDEDIR)dnl -: dyndep | HEADERS |