Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #27 from Sigmanificient/c
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelroses authored May 14, 2024
2 parents cfd424d + d981bc4 commit fdbefef
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 0 deletions.
22 changes: 22 additions & 0 deletions c/.editorconfig
Original file line number Diff line number Diff line change
@@ -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 changes: 64 additions & 0 deletions c/.gitignore
Original file line number Diff line number Diff line change
@@ -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 changes: 30 additions & 0 deletions c/Makefile
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions c/flake.nix
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions c/hello.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ stdenv }:
stdenv.mkDerivation {
name = "hello";
src = ./.;

env.BINDIR = "${placeholder "out"}/bin";
}
11 changes: 11 additions & 0 deletions c/main.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit fdbefef

Please sign in to comment.