This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.local/bin/maker
David JULIEN 9d06a61780 legal: change license to GPLv3 in script headers
Kept wondering wether I should keep the MIT (because I highly value
freedom of act) or embrace the GPL (because I don't want this work to
become close-source).

I do understand that this commit (and the next one that is actually
changing the LICENSE) is a defeat for freedom. I guess freedom has been
defeated long time ago, when people and companies figured that was
"free" (as in gratis) was also "free" (as in disposable).

This is not how I think free (as in "libre") works but hey, that surely
is how Intel and other corporations see it (ec: Intel Management Engine
is entirely based on Minix, is close-source, and *maybe* used as a
backdoor by anybody).

It boils down to the Paradox of Tolerance, and I surely won't tolerate
shit going their way. If you want to take open source stuff, be my
guest ; but you have to play by the rules.
2021-02-16 01:09:56 +01:00

86 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env sh
######################################################################
# @author : swytch
# @file : maker
# @license : GPLv3
# @created : Wednesday May 20, 2020 18:18:53 CEST
#
# @description : create a makefile for current project (if c/c++)
# open it with (neo)vim
######################################################################
headers_list="$(ls | grep '.h$')"
sources_list="$(ls | grep '.cp*$')"
modules_list="$(printf "\n$sources_list" | sed 's/\.cp*//g' | tr '\n' ' ')"
targets_list="$(printf "\n$sources_list" | sed 's/\.cp*/\.o/g' | tr '\n' ' ')"
get_compiler(){
for source_ in "$sources_list"; do
case "$source_" in
*.cpp) comp="g++" && return;;
*.c) comp="gcc";;
esac
done
}
is_c_project(){
[ -n "$sources_list" ]
}
make_rule(){
if [ "$comp" = "gcc" ]; then
if [ "$1" = "main" ]; then
printf "\n$1.o : $1.c" >> makefile
else
printf "\n$1.o : $1.c $1.h" >> makefile
fi
printf "\n\t\$(CC) -c $1.c \$(FLAGS)" >> makefile
else
if [ "$1" = "main" ]; then
printf "\n$1.o : $1.cpp" >> makefile
else
printf "\n$1.o : $1.cpp $1.hpp" >> makefile
fi
printf "\n\t\$(CC) -c $1.cpp \$(FLAGS)" >> makefile
fi
printf "\n" >> makefile
}
if ! is_c_project; then
printf "\nNo C/C++ project in directory. Exiting..."
exit 1
fi
get_compiler
touch makefile
printf "BIN = main" > makefile
printf "\nTARGETS = $targets_list" >> makefile
printf "\n" >> makefile
printf "\nCC = $comp" >> makefile
printf "\nFLAGS = -Wall -g" >> makefile
printf "\n" >> makefile
printf "\nall : \$(BIN)" >> makefile
printf "\n" >> makefile
printf "\n\$(BIN) : \$(TARGETS)" >> makefile
printf "\n\t\$(CC) \$(TARGETS) -o \$(BIN) \$(FLAGS)" >> makefile
printf "\n" >> makefile
for module in $modules_list; do
make_rule "$module"
done
printf "\nclean :" >> makefile
printf "\n\trm \$(BIN) *.o vgcore.*" >> makefile
sed -i 's/\s$//' makefile
if command -v nvim > /dev/null 2>&1; then
nvim makefile
else
vim makefile
fi