💾 Archived View for gmi.noulin.net › sheepy › sheepyReadme.md captured on 2023-07-10 at 18:19:33.
-=-=-=-=-=-=-
- [Install](#install) - [Dependencies](#dependencies) - [Starting a new project](#starting-a-new-project) - [Compilation](#compilation) - [Packages](#packages) - [Compiling multiple source files](#compiling-multiple-source-files) - [Creating classes](#creating-classes) sheepy compiles and runs C programs **without makefiles** and it has the ability to run as a C script with a hashbang. GCC (minimum 4.9) has to be installed for a working system. The build system is multiprocess by default and already built objects are reused. `sheepy` depends on [libsheepy](https://spartatek.se/r/libsheepy/file/README.md.html), `libsheepy` is installed during the installation process. Check out the [user guide](http://spartatek.se/libsheepyUserGuide/) to learn how to use sheepy and libsheepy, for more detailed information read the libsheepy reference documentation available at [http://spartatek.se/libsheepy/](http://spartatek.se/libsheepy/). The prefered C standard is `C11` because libsheepy has many **generics**, `C99` is supported but is much less convenient to use than C11 since there are thousands of functions in libsheepy (a function for each type and feature). - `sheepy` builds the executables and libraries. - `spm` is the package manager. Demo: [![asciicast](https://asciinema.org/a/sVPOkMKI951Nw8DBeLPxzNlo7.svg)](https://asciinema.org/a/sVPOkMKI951Nw8DBeLPxzNlo7) # Install Platforms: - Linux/GNU, Intel (Ivy Bridge or newer for DRNG RDRAND) - Linux/GNU, ARM (raspberry pi) - Android/Termux ARM - MacOS - FreeBSD - OpenBSD - DragonflyBSD - Alpine Linux (musl libc) - OpenIndiana (illumos, solaris, sunOS) - Haiku These commands install `sheepy` and `spm`:
git clone https://spartatek.se/git/sheepy.git
cd sheepy
sudo -H ./install.sh
To install sheepy in your home folder, run:
./homeInstall.sh
In Alpine Linux:
apk add gcc libc-dev git
git clone https://spartatek.se/git/sheepy.git
cd sheepy
sudo -H ./install.sh
In Termux:
pkg install git clang curl gdb
git clone https://spartatek.se/git/sheepy.git
cd sheepy
./installTermux.sh
In OpenIndiana:
pkg install git gcc-8 system/header
git clone https://spartatek.se/git/sheepy.git
cd sheepy
./installOpenIndiana.sh
## Configuration The user configuration is located at `~/.sheepy/config.yml`. If the configuration file doesn't already exist, it is created when sheepy is executed for the first time. Settings: - _system_ install location of the sheepy and spm commands and global packages - _cflags_ flags for the C compiler - _lflags_ flags for the linker - _linkWithGold_ enable/disable gold linker (multithreaded linking) - _32bit_ generate a 32bit executable - _parallelSheepy_ enable/disable multiprocess build - _buildPath_ directory where the intermediary object files are stored - _key_ secret key to log on the `spm` registry - _testflags_ compile flags for tests When musl libc is installed on the system, configure sheepy to link against musl libc like this:
cflags: -ggdb -std=gnu11 -fPIC -pipe -specs "/usr/local/musl/lib/musl-gcc.specs"
# statically link musl libc
lflags: -static -specs "/usr/local/musl/lib/musl-gcc.specs"
# dynamically link musl libc
#lflags: -specs "/usr/local/musl/lib/musl-gcc.specs"
The commands for installing musl libc are:
git clone git://git.musl-libc.org/musl
cd musl
./configure
make
sudo make install
Then libsheepy has to be compiled using the musl libc headers, see [README.md](https://spartatek.se/r/libsheepy/file/README.md.html) in the libsheepy repo. # Dependencies `sheepy` and `spm` have some external dependencies: - GCC 4.9 or clang - Optionally gold linker, this can be disabled in the configuration (~/.sheepy/config.yml) - curl (`spm`) - tar (`spm`) - gzip or pigz (`spm`) # Starting a new project With `sheepy`:
sheepy -n example
./example.c
To create new packages with `spm`:
spm new example1 examples2
cd example1
./example1.c
# Compilation To get help, run:
sheepy -h
To run a program:
sheepy <C_SOURCE>
To run as a script, add a hashbang at the top of the main c file:
`libsheepy.a` is always linked and `pthread` is always enabled. minimal C source:
int main(int ARGC, char** ARGV) {
}
## Compilation errors In some linux distributions (RHEL), this error occurs:
...git/libsheepy/release/libsheepy.a(libsheepy.o): In function `getMonotonicTime':
...git/libsheepy/release/libsheepy.c:50790: undefined reference to `clock_gettime'
To solve this error, add __-lrt__ in compileSheepy.sh and in ~/.sheepy/config.yml in lflags # Packages To get help, run:
spm help
To install a package:
sudo spm -g install sheepyExamples
sudo spm -g install md
The `searchReplace` requires libpcre to compile successfully, to install pcre:
sudo apt-get install libpcre3-dev
To create a new package:
spm new packageName
cd packageName
# Compiling multiple source files sheepy doesn't use makefiles, it scans the `#include` lines in the source code to figure out what to compile. When an _include_ statement is found, sheepy searches for a C source file with the same name changing the extension from .h to .c. For includes in installed packages, the source files are already in the static library so the library is statically linked. For example, main.c:
int main(int c, char **a) {
XSUCCESS;
}
sheepy compiles main.c, test.c if it exists and statically link libapkg.a. # Creating classes As seen in previously `sheepy -n name` generates a new main file. `sheepy -C className` generates the files for a class called _className_ In order to use the class, simply add `#include "className.h"` in a source file. The class templates has the methods inherited from the `baset` class, all the sheepy classes inherit from the `baset` class. The template has `TODO` comments showing how to extend the class. # Unit tests and memcheck sheepy and spm have commands for generating unit test and memcheck (valgrind) templates. The following is the instructions to generate and run the tests for <package name>: Create <package name> and edit package.yml to enable the tests:
spm new <package name>
cd <package name>
vi package.yml
Uncomment: `testBin`, `testCflags`, `testLflags`, `memcheckBin`, `memcheckCflags`, `memcheckLflags` and add the compilation flags as necessary Generate the test templates:
sheepy -T
Add the tests in test<Package name>.c __Run the tests__: - Unit tests:
spm test
Libcheck has to be available in the system since the unit tests are using it. - Memcheck:
./test<Package name>Mem.sh
In memcheck tests, the unit tests are linked to libsheepyMemcheck which has container recycling disabled to easily identify the source of the leaks. Valgrind has to be available in the system.