~skiqqy/skelly

a9efe8b36fc530eef0c88747381c13af3877bdf4 — Stephen Cochrane 4 months ago e96b40d
Added C production
2 files changed, 81 insertions(+), 1 deletions(-)

M README.md
M skelly.sh
M README.md => README.md +1 -1
@@ 37,7 37,7 @@ is for.

By default skelly ships with:
* `init_sh` -> Init any shell script (bash, sh etc).
* `init_c` -> Init a C project. (WIP)
* `init_c` -> Init a C project.

#### Local Productions


M skelly.sh => skelly.sh +80 -0
@@ 31,6 31,7 @@ licenses[GPL3]='https://www.gnu.org/licenses/gpl-3.0.txt'
commands[new]='new PROJECTNAME LANGUAGE LICENSE\nCreate a new project.'
commands[help]='help COMMAND\nShow more information on a command.'
commands[list]='list C|L\nIf C is given, list all commands, if L then list available licenses. Defaults to commands.'
commands[langs]='langs\nShow available langauges.'

usage()
{


@@ 161,9 162,74 @@ gen_root_files()
		&& return 1
}

# Describes a C project, and setup its directory structure
# We assume that we are inside the project directory.
# Usage: inti_sh PROJECTNAME LICENSE
# Yes, the cat << EOF is verbose, this is needed to keep the script standalone.
init_C()
{
	# Init project tree.
	gen_root_files "$@"
	gen_git_ignore C > .gitignore
	mkdir include
	mkdir src
	mkdir test
	printf '#!/usr/bin/env sh\necho TODO: Setup test Suite.' > test/test.sh
	chmod +x test/test.sh
	touch include/"${1,,}.h"

	# Setup basic makefile
	cat << EOF > Makefile
CC=clang
FLAGS=
FLAGS=-Wall -Wextra -pedantic
PREFIX=/usr/local
BINARY=${1,,}
LDLIBS=
.PHONY: test

all: ${1,,}

init:
	mkdir -p bin

${1,,}: init # ${1,,}-1.o
	# \$(CC) \$(FLAGS) -o bin/\$(BINARY) src/${1,,}.c bin/*.o \$(LDLIBS) # Uncomment if you build .o's
	\$(CC) \$(FLAGS) -o bin/\$(BINARY) src/${1,,}.c \$(LDLIBS)

# Uncomment if you need to build .o's, this should be modified, and is just a basic start point
#${1,,}-1.o: init
#	\$(CC) \$(FLAGS) -o bin/\$@ src/${1,,}.c \$(LDLIBS)

test:
	./test/test.sh

install:
	@echo TODO: Setup install.

uninstall:
	@echo TODO: Setup uninstall.
EOF

	# Setup main.
	cat << EOF > "src/${1,,}.c"
#include <stdlib.h>
#include <stdio.h>

#include "../include/${1,,}.h"

int
main(int argc, char* argv[])
{
	return EXIT_SUCCESS;
}
EOF
}

# Describes an sh project, and setup its directory structure
# We assume that we are inside the project directory.
# Usage: inti_sh PROJECTNAME LICENSE
# Yes, the cat << EOF is verbose, this is needed to keep the script standalone.
init_sh()
{
	shebangs=( sh bash ) # TODO: Add other shebangs


@@ 252,6 318,20 @@ s_help()
	printf 'Usage: skelly %b\n' "${commands[$1]}"
}

s_langs()
{
	local langs=( C sh )

	[ -d "$skelly" ] && \
		while read -r dir # Check skelly dir
		do
			langs+=( "$(basename "$dir")" )
		done < <(find "$skelly" -type d)

	local tmp="${langs[*]}"
	uniq -u <(printf 'Available Productions\n\n%b\n' "${tmp// /\\n}") # Remove duplicates
}

# New skelly project
# Usage: s_new PROJECTNAME LANG LICENSE
s_new()