Skip to content

Commit

Permalink
Merge pull request #22 from FelixEcker/topic/mcfg_2
Browse files Browse the repository at this point in the history
Update to MCFG/2
  • Loading branch information
MarieEckert authored Feb 15, 2024
2 parents 431165d + b92cc97 commit 92b36c8
Show file tree
Hide file tree
Showing 34 changed files with 2,269 additions and 1,330 deletions.
2 changes: 2 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CompileFlags:
Add: -I./include/
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
out/
Session.vim
obj/
lib/
.vs
mb
vgcore.*
valgrind.*
*.log
*.swp
compile_flags.txt
92 changes: 20 additions & 72 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,87 +4,26 @@ A build system primarly designed and intended for my use.
## Building
### Setup
To quickly setup mariebuild for development, simply run the `setup.sh` script. This will
automatically build [libmcfg](https://github.com/FelixEcker/mcfg) from the latest release.

If there is no pre-existing install of mariebuild on the system, the script will download the
latest binary and use it for building. This gets deleted after the setup script is finished.
automatically build [libmcfg_2](https://github.com/FelixEcker/mcfg_2) from the latest commit on its main branch.

### Compiling
If you do not have any binary of mariebuild, you can build it by running the
`build.py` python script.

If the compilation is successful a binary by the name of `mb` should be output
in the projects root directory.

## Regarding Sourcecode Quality
Since this is my first "real" project in C, the source code might be less then
good. If anyone has suggestions for improving the source please create an issue
with the details on how to improve it.

## Syntax
Mariebuild files are basically [mcfg](https://github.com/FelixEcker/mcfg) files,
with a few specifics:
* Certain fields are required:
* .config/mariebuild/files
* .config/mariebuild/comp_cmd
* Some fields are automatically generated:
* .config/mariebuild/mode_flags (from <mode name>_flags)
* .config/mariebuild/file (each element of the list .config/mariebuild/files)

Example Build-File:
```
sector .config
fields depends:
str includes 'include/'
str libdir 'lib/'
str libs '-Llib/ -lmcfg'
list srcs ''
fields mariebuild:
str name 'mb'
str compiler 'gcc'
str src_dir 'src'
str obj_dir 'out'
str shell 'bash'
list srcs 'mb_utils.c:mb_script.c:mb_execute.c:mb.c'
; A required field, holding all source files in a colon-seperated list.
list files '$(depends/srcs):$(srcs)'
str std_flags '-Wall -I$(depends/includes)'
str debug_flags '-ggdb'
str release_flags '-O3'
; Another required field, insert your compilation command in here.
; The command within this field is run for every file within the files field.
str comp_cmd '$(compiler) $(mode_flags) $(std_flags) -c -o $(obj_dir)/$(file).o $(src_dir)/$(file)'
; An optional field, run on the finalize build stage.
str finalize_cmd '$(compiler) $(mode_flags) -o $(name) out/$(files).o $(depends/libs)'
```

See `doc/intro.md` and `doc/intro.md` and the files in `doc/examples/` for more details.
**With mariebuild (0.4.0 or higher):** `mb -t release` <br>
**Without mariebuild:** `sh build.sh`

## mb usage
By default mb looks for a `build.mb` file which is the executed in debug mode.
```
Usage: mb [OPTION...]
Usage: mb [OPTION...]
A simple build system inspired by my hate against makefiles
Author: Marie Eckert
-c, --check Check if a build file is valid
-d, --disable-extensions Disable all extensions used by the build-file
-e, --exec=SCRIPT Specify a specific script to be executed
-f, --force Force a build, regardless if target is
incremental
-i, --in=FILE Specify a buildfile
-l, --list-platforms Get a list of platforms supported by the
build-file
-m, --mode=MODE Specify the building mode
-p, --platform=PLATFORM Specify the targeted platform
-q, --quiet Disable all output except for Important messages
-s, --structure Print parsed structure then exit
-v, --verbose Output all messages
-k, --keep-going Ignore any failures (if possible) and keep on building
-n, --no-splash Disable splash screen/logo
-t, --target=TARGET Specify the build target
-v, --verbosity=LEVEL Set the verbosity level (0-3)
-?, --help Give this help list
--usage Give a short usage message
-V, --version Print program version
Expand All @@ -93,8 +32,17 @@ Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Report bugs to https://github.com/FelixEcker/mariebuild/issues.
```

## TODO (for mariebuild 1.0.0)

- [X] Move to MCFG/2
- [X] Incremental and Full Builds
- [X] Unify and Singular Rules
- [ ] Implementation of the "force" argument
- [ ] Target-Dependant Fields
- [ ] Inclusion of other build files
- [ ] Documentation

## License
Mariebuild is licensed under the BSD 3-Clause License, see [The LICENSE file](https://github.com/FelixEcker/mariebuild/blob/master/LICENSE).
48 changes: 48 additions & 0 deletions build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

CC="clang"
SRCDIR="src/"
OBJDIR="obj/"

CFLAGS="-ggdb -Iinclude/ -Isrc/ -DDEFAULT_LOG_LEVEL=LOG_DEBUG"
LDFLAGS="-lm -Llib/ -lmcfg_2"

BIN_NAME="mb"

function build_objs() {
COMPILED_OBJECTS=()

for i in $1
do
OUTNAME="$OBJDIR$i.o"
INNAME="$SRCDIR$i.c"

echo " CC $INNAME"

$CC $CFLAGS -c -o $OUTNAME $INNAME || exit

COMPILED_OBJECTS+=("${OUTNAME}")
done
}

function build() {
OBJECTS=("xmem strlist logging types executor c_rule target build main")

echo "==> Compiling Sources for \"$BIN_NAME\""
build_objs "${OBJECTS[@]}"

echo "==> Linking \"$BIN_NAME\""
echo " LD -o $BIN_NAME ${COMPILED_OBJECTS[@]} $LDFLAGS"
$CC $CFLAGS -o $BIN_NAME ${COMPILED_OBJECTS[@]} $LDFLAGS
}

echo "MB build script. "

if [ "$1" = "--compile-flags" ]; then
sed --posix 's/ /\n/g' <<<"${CFLAGS[@]}" > compile_flags.txt

echo "==> Generated compile_flags.txt"
else
build
echo "==> Finished build!"
fi
138 changes: 103 additions & 35 deletions build.mb
Original file line number Diff line number Diff line change
@@ -1,38 +1,106 @@
sector .config
fields depends:
list includes 'include/:src/'
str libdir 'lib/'
str libs '-Llib/ -lmcfg'
list srcs ''

fields mariebuild:
str name 'mb'
str compiler 'gcc'
str src_dir 'src'
str obj_dir 'out'

str shell 'bash'

list srcs 'mb_utils.c:mb_execute.c:mb.c'
list files '$(depends/srcs):$(srcs)'

str std_flags '-Wall -I$(depends/includes)'
str debug_flags '-ggdb'
str release_flags '-O3'

str comp_cmd '$(compiler) $(mode_flags) $(std_flags) -c -o $(obj_dir)/$(file).o $(src_dir)/$(file)'
str finalize_cmd '$(compiler) $(mode_flags) -o $(name) out/$(files).o $(depends/libs)'

sector .scripts

lines prepare:
#!/usr/bin/bash
if [[ ! -f lib/libmcfg.a ]]; then
sh setup.sh
fi
; !MCFG_VERSION 3

sector config
section info
str name 'example'
str version '1.0'
str license 'BSD-3'
end

section files
str obj 'obj/'
list str sources 'xmem', 'strlist', 'logging', 'types', 'executor', 'c_rule', 'target', 'build', 'main'
end

section mariebuild
; mariebuild now supports incremental building. In this mode, a compilation rule
; is only executed if a file it executes upon is
str build_type 'incremental'

str cc 'clang'

; mcfg 2 has brought along a new list syntax, where each element is its own string
; and seperated by commas.
list str targets 'clean', 'debug', 'release'
str default 'debug'
end
end

if [[ -d "./out/" ]]; then
rm -rf out/*
; Mariebuild now works with targets defined in this sector.
; Each target can list other targets which it requires. Fields
; from the current target are accesible via %target%.
sector targets
section clean
str exec '
#!/bin/sh
if [ -d obj ]; then
rm -rf obj/
fi

mkdir -p out/
mkdir obj
'
end

section debug
; Each target lists c_rules (or compilation rules) which are executed in order.
list str c_rules 'executable'
end

section release
list str required_targets 'clean'

list str c_rules 'executable'
end
end

; Each compilation rule is defined within this sector. They can access Fields
; of the current target using %target%.
sector c_rules
section executable
; Compilation rules can list other compilation rules which they require
; These are executed in order.
list str c_rules 'main'

str binname 'mb'

str build_type 'full'
str exec_mode 'unify'

str input_src '/config/files/sources'

str input_format '$(/config/files/obj)$(%element%).o'
str output_format '$(binname)'

str ldflags '-lm -Llib/ -lmcfg_2'

; The command which is specified in the exec field is executed for each member of
; the list specified in exec_on
str exec '
$(/config/mariebuild/cc) -o $(%output%) $(%input%) $(ldflags)
'
end

section main
; Run the 'exec' command for each input element.
str exec_mode 'singular'

str obj 'obj/'
str src 'src/'

; Declare our set of input elements. If no output list is defined,
; the input list is used for that as well.
str input_src '/config/files/sources'
str output_src '/config/files/sources'

; The input and output_format fields are used to determine if a output file
; is out of date. They are also used to generate the input and output dynfields
str input_format '$(src)$(%element%).c'
str output_format '$(obj)$(%element%).o'

str cflags '-ggdb -Iinclude/ -Isrc/'

str exec '
$(/config/mariebuild/cc) $(cflags) -c $(%input%) -o $(%output%)
'
end
end
38 changes: 0 additions & 38 deletions build.py

This file was deleted.

Loading

0 comments on commit 92b36c8

Please sign in to comment.