commit 459f0b41f7b505ae2ea883cbbf0ec4e581076713 Author: Luke Date: Mon Sep 6 18:15:26 2021 -0700 Forgive me Greg for I have sinned. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4cecca --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +hello-world +.sheclang.*.cpp +.swp* + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c577b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d5e56a7 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# `sheclang` - A `#!` for your C++ files. +## Installation & Test +To install, just stick the bash script in your path either by a copy or a symlink. +``` +git clone https://github.com/lrenaud/sheclang +cd sheclang +sudo cp -v sheclang /usr/bin/ +``` +To run, try the demo after installing. +``` +chmod +x ./hello-world.cpp +./hello-world.cpp +``` +## Use +1. Add the following line to the first line of your C++ file. +``` +#!/usr/bin/env sheclang +``` +2. Mark your top level `*.cpp` file as executable +``` +cd ~/your-project +chmod +x your-source-code.cpp +``` +3. Run the source file like it was an executable. Arguments passed to the `*.cpp` file will be forwarded onto the resulting binary directly. +``` +./your-source-code.cpp --your-argument positional --this-flag +``` +## Why? +Because I could. And anything that makes building performant software more +assessable to more users is worth it. I can't imagine many Python beginners are +using the debugging facilities and interactivity of the Python interactive +terminal. So why not do what I can to make building C++ as trivial to get +off the ground as trivial python. \ No newline at end of file diff --git a/hello-world.cpp b/hello-world.cpp new file mode 100755 index 0000000..cb666fe --- /dev/null +++ b/hello-world.cpp @@ -0,0 +1,9 @@ +#!/usr/bin/env sheclang +#include + +int main(int argc, char *argv[]) { + + printf("Hello World!\n"); + + return 0; +} diff --git a/sheclang b/sheclang new file mode 100755 index 0000000..8124708 --- /dev/null +++ b/sheclang @@ -0,0 +1,61 @@ +#!/bin/bash +# sheclang - shebang (#!) meets automatic clang. +# Luke Renaud +# 2021-09-06 (Public Domain) +# _____________________________________________________________________________ +# I got tired of the turnaround time when debugging my code, and I don't want +# to make a full build system or frankly even maintain a ./build.sh script for +# each project. I'm well on the road to re-inventing another build system, but +# if we can make python a simple ./.py, why can't we do the same for +# C and C++? +# +# See hello-world.cpp for the source code. Install this guy wherever your bins +# are stored, try it, weep, then rejoice that you have one less buffer open. +# +# _____________________________________________________________________________ +# LICENSE: +# Public Domain (y'all really care?) + +set -e +export IFS=$'\n' + +## Phase 1: Input Collection & Argument Checking +if [[ $# -lt 1 ]]; then + printf "sheclang requires exactly one build file arugment.\n" >&2 + exit +fi + +file_input="$1" +target_dir="$(dirname "${file_input}")" + +# TODO: Validate the extension of the output file before fucking with it. +file_input_name="$(basename "${file_input}")" +file_output="${file_input_name%.*}" +file_extension="${file_input_name##*.}" +if [[ "$file_input_name" == "$file_output" ]]; then + ( + printf "ERROR! Input and output file names match.\n" + printf " file input: %s\n" "$file_input_name" + printf " file output: %s\n" "$file_output" + ) >&2 + exit; +fi + +## Phase 2: File cleanup +# Build the copy the main source file without a hashbang line +file_input_corrected="${target_dir}/.sheclang.${file_output}.${file_extension}" +cp "${file_input}" "${file_input_corrected}" + +printf "//" | dd conv=notrunc of="${file_input_corrected}" \ + count=2 bs=1 status=none + +file_output="${target_dir}/${file_output}" + +## Phase 3: Build the file, and execute it with the remaining arguments. +shift # remove the source file from the BASH argument tree. + +# Runn my prefered build script. Customize to your tastes +clang++ -o "$file_output" "$file_input_corrected" + +# And execute with the remaining arguments +"$file_output" $* \ No newline at end of file