1
0
Fork 0
forked from auxolotl/templates

Merge pull request #27 from Sigmanificient/c

This commit is contained in:
isabel roses 2024-05-14 20:24:13 +00:00 committed by GitHub
commit fdbefeff2a
Failed to generate hash of commit
6 changed files with 161 additions and 0 deletions

22
c/.editorconfig Normal file
View file

@ -0,0 +1,22 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 80
tab_width = 4
[{Makefile,*.mk}]
indent_style = tab
[*.nix]
indent_style = space
tab_width = 2
indent_size = 2
[*.lock]
indent_style = unset
insert_final_newline = unset

64
c/.gitignore vendored Normal file
View file

@ -0,0 +1,64 @@
# binaries
hello
# language support
compile_commands.json
.cache
# nix
.direnv
result*
repl-result-*
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

30
c/Makefile Normal file
View file

@ -0,0 +1,30 @@
CC ?= gcc
CFLAGS += -pedantic -Wall -Wextra -O2
OUT := hello
BINDIR ?= /usr/bin
SRC += main.c
OBJ := $(SRC:.c=.o)
.PHONY: all
all: $(OUT)
$(OUT): $(OBJ)
$(CC) -o $@ $<
.PHONY: clean
clean:
$(RM) $(OBJ)
.PHONY: fclean
fclean: clean
$(RM) -r $(OUT)
.PHONY: re
.NOTPARALLEL: re
re: fclean all
.PHONY: install
install:
install -D hello ${BINDIR}/hello --mode 0755

27
c/flake.nix Normal file
View file

@ -0,0 +1,27 @@
{
description = "Aux template for C project";
inputs.nixpkgs.url = "github:auxolotl/nixpkgs/nixos-unstable";
outputs =
{ self, nixpkgs }:
let
forAllSystems =
function:
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (
system: function nixpkgs.legacyPackages.${system}
);
in
rec {
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell { inputsFrom = [ packages.${pkgs.system}.hello ]; };
});
packages = forAllSystems (pkgs: rec {
default = hello;
hello = pkgs.callPackage ./hello.nix { };
});
overlays.default = final: prev: { hello = prev.callPackage ./default.nix { }; };
};
}

7
c/hello.nix Normal file
View file

@ -0,0 +1,7 @@
{ stdenv }:
stdenv.mkDerivation {
name = "hello";
src = ./.;
env.BINDIR = "${placeholder "out"}/bin";
}

11
c/main.c Normal file
View file

@ -0,0 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char greet[] = "hello, world!\n";
int written = printf("%s", greet);
return written == (sizeof(greet) - 1)
? EXIT_SUCCESS : EXIT_FAILURE;
}