11# Autark – A self-contained build system for C and C++
22
3+ ## Quick links
4+
5+ - [ meta] ( #meta- )
6+ - [ option] ( #option- )
7+ - [ check] ( #check- )
8+ - [ set] ( #set- )
9+ - [ env] ( #env- )
10+ - [ ${}] ( #-variable-evaluation )
11+ - [ @{}] ( #-program-output-evaluation )
12+ - [ ^ {} ] (#-expressions-concatenation)
13+ - [ if] ( #if--condition )
14+ - [ echo] ( #echo- )
15+ - [ configure] ( #configure- )
16+ - [ path helpers] ( #s--ss--c--cc---path-helpers )
17+ - [ run] ( #run- )
18+ - [ in-sources] ( #in-sources- )
19+ - [ run-on-install] ( #run-on-install- )
20+ - [ foreach] ( #foreach- )
21+ - [ cc/cxx] ( #cc-----cxx--- )
22+ - [ library] ( #library- )
23+ - [ install] ( #install- )
24+
325[ Autark source code repository] ( https://github.com/Softmotions/autark )
426
527** Autark** is a self-contained build system that resides entirely within
@@ -14,7 +36,7 @@ The `build.sh` script automatically initializes the Autark build system, and the
1436Autark handles both internal and external project dependencies much more precisely and cleanly than is typically done with Makefiles by hands.
1537Build rules are defined using a specialized DSL in Autark files, which is mostly declarative in nature.
1638
17- ## Key features of Autark
39+ ## Key features
1840
1941- To initialize the project build system on the target system, nothing is required except a C99-compliant compiler.
2042- The build process does not modify the project's source tree.
@@ -326,30 +348,8 @@ It is primarily used for rules that install the built project artifacts.
326348 may be vague or imprecise. This is due to the use of the ` leg ` PEG parser generator,
327349 which can produce generic error reports for malformed input.
328350
329- # Autark script rules
330-
331- - [ meta] ( #meta- )
332- - [ option] ( #option- )
333- - [ check] ( #check- )
334- - [ set] ( #set- )
335- - [ env] ( #env- )
336- - [ ${}] ( #-variable-evaluation )
337- - [ @{}] ( #-program-output-evaluation )
338- - [ ^ {} ] (#-expressions-concatenation)
339- - [ if] ( #if--condition )
340- - [ echo] ( #echo- )
341- - [ configure] ( #configure- )
342- - [ path helpers] ( #s--ss--c--cc---path-helpers )
343- - [ run] ( #run- )
344- - [ in-sources] ( #in-sources- )
345- - [ run-on-install] ( #run-on-install- )
346- - [ foreach] ( #foreach- )
347- - [ cc/cxx] ( #cc-----cxx--- )
348- - [ library] ( #library- )
349- - [ install] ( #install- )
350-
351351
352- ## meta {...}
352+ # meta {...}
353353
354354Sets script variables using a simple convention:
355355each variable name is automatically prefixed with ` META_ ` .
@@ -371,7 +371,7 @@ If variable is defined using the `let` clause inside `meta`,
371371the ` META_ ` prefix is not added to its name.
372372
373373
374- ## option {...}
374+ # option {...}
375375
376376``` cfg
377377option { <OPTION NAME> [OPTION DESCRIPTION] }
@@ -401,7 +401,7 @@ To list all documented build options, use:
401401./build.sh -l
402402```
403403
404- ## check {...}
404+ # check {...}
405405
406406This construct is the workhorse for checking system configuration and capabilities
407407before compiling the project. Checks are performed using ` dash ` shell scripts.
@@ -517,7 +517,7 @@ set {
517517}
518518```
519519
520- ## set {...}
520+ # set {...}
521521
522522The ` set ` rule assigns a value to a variable in the build script.
523523
@@ -580,15 +580,15 @@ set {
580580}
581581```
582582
583- ## env {...}
583+ # env {...}
584584
585585Similar to ` set ` , but sets an ** environment variable** for the build process
586586using ` setenv(3) ` at the operating system level.
587587
588588Unlike ` set ` , the value of this rule is evaluated at the time it is executed,
589589which happens during the ` setup ` phase of the build.
590590
591- ## ${...} Variable evaluation
591+ # ${...} Variable evaluation
592592
593593``` cfg
594594${VARIABLE [DEFAULT]}`
@@ -599,7 +599,7 @@ as an argument to another rule.
599599If the variable is not defined in the current script context, the ` DEFAULT ` value will be used if provided.
600600
601601
602- ## @{...} Program output evaluation
602+ # @{...} Program output evaluation
603603
604604``` cfg
605605# Run program every build
@@ -613,7 +613,7 @@ Invokes the specified program `PROGRAM` and returns its standard output as a str
613613The ` @@ ` form caches the program’s output and reuses it in subsequent builds,
614614which is useful for time-consuming invocations such as ` pkg-config ` .
615615
616- ### Example:
616+ ## Example:
617617
618618``` cfg
619619set {
@@ -626,7 +626,7 @@ In this example, the output of `pkgconf --libs --static libcurl` is appended to
626626** Note** what ` .. ` in pkgconf instruction means what space separated output of pkgconf programm
627627will be converted to list and merged with LDFLAGS list.
628628
629- ## ^{...} Expressions concatenation
629+ # ^{...} Expressions concatenation
630630
631631``` cfg
632632^{EXPR1 [EXPR2]...}
@@ -657,7 +657,7 @@ set {
657657
658658Note: the space between ` -DBUILD_TYPE= ` and ` ${BUILD_TYPE} ` is required.
659659
660- ## if {...} condition
660+ # if {...} condition
661661
662662Conditional directive.
663663
@@ -692,7 +692,7 @@ If the condition `CONDITION_RULE` evaluates to a `truthy` value,
692692the entire ` if ` expression is replaced by ` EXPR1 ` in the Autark script’s instruction tree.
693693Otherwise, if an ` else ` block is provided, it will be replaced by ` EXPR2 ` .
694694
695- ### Conditions
695+ ## Conditions
696696
697697Exclamation mark ` ! ` means expression result negation, when trufly evaluated expressions became false.
698698
@@ -732,7 +732,7 @@ Exclamation mark `!` means expression result negation, when trufly evaluated exp
732732** Please Note:** Autark syntax does not support ` else if ` constructs.
733733
734734
735- ## error {...} Abort build and report error
735+ # error {...} Abort build and report error
736736
737737Typical example ` error ` directive usage:
738738
@@ -742,7 +742,7 @@ if { !defined{ PTHREAD_LFLAG }
742742}
743743```
744744
745- ## echo {...}
745+ # echo {...}
746746
747747Prints arbitrary information to the console (standard output, ` stdout ` ).
748748
@@ -771,7 +771,7 @@ echo {
771771```
772772This will print the current values of the CFLAGS and LDFLAGS variables.
773773
774- ## configure {...}
774+ # configure {...}
775775
776776The ` configure ` rule acts as a preprocessor for text files and C/C++ source templates,
777777replacing specific sections with values of variables from the current script context.
@@ -806,7 +806,7 @@ configure {
806806}
807807```
808808
809- ### @...@ Substitutions
809+ ## @...@ Substitutions
810810
811811Text fragments enclosed in ` @ ` symbols are interpreted as variable names
812812and replaced with their corresponding values.
@@ -830,7 +830,7 @@ Cflags: -I@INSTALL_PREFIX@/@INSTALL_INCLUDE_DIR@ -I${includedir}
830830Cflags.private: -DIW_STATIC
831831```
832832
833- ### //autarkdef for C/C++ Headers
833+ ## //autarkdef for C/C++ Headers
834834
835835For C/C++ header files, the ` //autarkdef ` directive is a convenient way
836836to conditionally generate ` #define ` statements based on variable presence.
@@ -862,11 +862,11 @@ If `VAR_NAME` is defined, this becomes:
862862#define VAR_NAME 1
863863```
864864
865- ## `S` / `SS` / `C` / `CC` / `%` Path Helpers
865+ # `S` / `SS` / `C` / `CC` / `%` Path Helpers
866866These small helper rules are useful for computing file paths in build scripts.
867867They help avoid hardcoding paths that may depend on the current location of the project's source code.
868868
869- ### S {...}
869+ ## S {...}
870870Computes the **absolute path** of the given argument(s) relative to the **project root**.
871871If multiple arguments are provided, they are concatenated into a single path string.
872872
@@ -878,17 +878,17 @@ If multiple arguments are provided, they are concatenated into a single path str
878878 S{foo bar baz}
879879```
880880
881- ### SS {...}
881+ ## SS {...}
882882Same as ` S ` , but relative to the directory where the current script is located.
883883
884- ### C {...}
884+ ## C {...}
885885Computes the ** absolute path** to the argument(s) relative to the ** project-wide autark-cache dir** .
886886
887- ### CC {...}
887+ ## CC {...}
888888Computes the ** absolute path** relative to the ** local cache directory** of the current script.
889889This is the default working directory for tools and commands that operate on build artifacts.
890890
891- ### % {...}
891+ ## % {...}
892892Returns the ` basename ` of the given filename changing its extension optionally.
893893
894894``` cfg
@@ -903,7 +903,7 @@ Returns the `basename` of the given filename changing its extension optionally.
903903%{hello.x .c}
904904```
905905
906- ## run {...}
906+ # run {...}
907907
908908The ` run ` rule is the most powerful construct in the Autark system.
909909It allows you to define custom build actions and their dependency chains.
@@ -951,7 +951,7 @@ run {
951951}
952952```
953953
954- ## in-sources {...}
954+ # in-sources {...}
955955
956956By default, most Autark rules are executed inside the ** autark-cache dir**
957957corresponding to the current build script.
@@ -967,7 +967,7 @@ in-sources {
967967}
968968```
969969
970- ### Example: Appending glob-matched source Files
970+ ## Example: Appending glob-matched source Files
971971In the example below, the ` SOURCES ` variable is extended with the output of a glob-matching command
972972executed in the source directory. The result is assigned merged with ` SOURCES ` variable in the parent script:
973973``` cfg
@@ -982,7 +982,7 @@ set {
982982}
983983```
984984
985- ### Example: Finding Java Source Files
985+ ## Example: Finding Java Source Files
986986``` cfg
987987set {
988988 JAVA_SOURCES
@@ -995,7 +995,7 @@ set {
995995This example populates ` JAVA_SOURCES ` with the full paths of all ` .java ` files under ` src/main/java ` ,
996996resolved from the script's source directory.
997997
998- ## run-on-install {...}
998+ # run-on-install {...}
999999
10001000` run-on-install ` is a special form of the ` run ` rule that is executed during the ` post-build ` phase.
10011001
@@ -1022,7 +1022,7 @@ with the proper build flags and installation prefix.
10221022Reference:
10231023https://github.com/Softmotions/iwnet/blob/master/Autark
10241024
1025- ## foreach {...}
1025+ # foreach {...}
10261026
10271027When you need to perform many similar actions for a list of files or objects,
10281028` foreach ` provides a concise and powerful solution.
@@ -1089,7 +1089,7 @@ In this example:
10891089
10901090This approach enables clean, scalable test orchestration without hardcoding individual test names.
10911091
1092- ## ` cc { ... } ` / ` cxx { ... } `
1092+ # ` cc { ... } ` / ` cxx { ... } `
10931093
10941094This rule compiles C or C++ source files into object files,
10951095while automatically tracking all required dependencies including header files.
@@ -1105,7 +1105,7 @@ cc|cxx {
11051105}
11061106```
11071107
1108- ### SOURCES
1108+ ## SOURCES
11091109
11101110The first argument must be an expression that returns a list of source files.
11111111It can be a single string (for one file) or a list defined by a ` set ` rule.
@@ -1117,14 +1117,14 @@ Paths to source files can be:
11171117- Paths relative to the cache directory corresponding to the script
11181118 (this is useful when compiling generated sources from other rules)
11191119
1120- ### COMPILER_FLAGS
1120+ ## COMPILER_FLAGS
11211121
11221122A list of compiler flags, typically defined using a set rule.
11231123
11241124** Note:** the ` -I. ` flag is automatically added to the compiler flags,
11251125which includes the current cache directory in the include path for header files.
11261126
1127- ### COMPILER_CMD
1127+ ## COMPILER_CMD
11281128
11291129The compiler to use.
11301130
@@ -1136,7 +1136,7 @@ If not explicitly specified:
11361136** Note:** The compiler must support dependency generation using the ` -MMD ` flag
11371137to allow Autark to correctly track header file dependencies.
11381138
1139- ### objects { NAME }
1139+ ## objects { NAME }
11401140
11411141By default, the ` cc ` rule sets a variable named ` CC_OBJS `
11421142containing the list of object files produced during compilation.
@@ -1146,7 +1146,7 @@ you may want to assign different output variable names using the `objects { NAME
11461146
11471147This allows you to manage multiple sets of object files independently.
11481148
1149- ### consumes { ... }
1149+ ## consumes { ... }
11501150
11511151This section declares ** additional dependencies** for the ` cc ` compilation rule.
11521152
@@ -1165,7 +1165,7 @@ You can change this using the `-J` option on the command line. For example:
11651165This will run up to 8 compilation jobs in parallel.
11661166
11671167
1168- ## library {...}
1168+ # library {...}
11691169
11701170Search for a library file by name.
11711171
@@ -1207,13 +1207,13 @@ This will search for `libm.a`, and if found, store its absolute path in `LIB_M`
12071207If the library is not found, the script will terminate with an error.
12081208
12091209
1210- ## install {..}
1210+ # install {..}
12111211
12121212If ` build.sh ` is run with the ` -I ` or ` --install ` option (to install all built artifacts),
12131213or if an install prefix is explicitly specified using ` -R ` or ` --prefix=<dir> ` ,
12141214then all ` install ` rules will be executed after the ` build ` phase completes.
12151215
1216- ### Available variables when install is enabled
1216+ ## Available variables when install is enabled
12171217
12181218- ` INSTALL_PREFIX ` – Absolute path to the installation prefix.
12191219 ** Default:** ` $HOME/.local `
0 commit comments