Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Escrito por Adrián Nicolás Aguilera en su eterna procrastinación para hacer más sencillo el crear y manejar nuevos proyectos
- if [[ $# != 1 ]] && [[ $# != 2 ]]
- then
- >&2 echo -ne "Uso: $0 nombre_proyecto [versión_c++]\nEj. $0 prueba 11\n"
- exit 1
- else
- mkdir $1
- cd $1
- # Makefile
- echo '# Escrito por Adrián Nicolás Aguilera en su eterna procrastinación para hacer más sencillo el crear y manejar nuevos proyectos' >> Makefile
- echo '# nombre del ejecutable (cambiar según el proyecto)' >> Makefile
- echo 'BIN=main' >> Makefile
- echo 'INCDIRS=. ./include/' >> Makefile
- echo '' >> Makefile
- echo 'CPP=g++' >> Makefile
- echo '' >> Makefile
- echo '# Generar archivos que crean reglas para las dependencias .h' >> Makefile
- echo 'DEPFLAGS=-MP -MD' >> Makefile
- echo '# Añadir -I a cada directorio de include' >> Makefile
- echo 'COMMONFLAGS=-Wall -Wextra -Wold-style-cast -Wshadow $(foreach D, $(INCDIRS), -I$(D)) $(DEPFLAGS)' >> Makefile
- echo 'CPPFLAGS=-Og -g $(COMMONFLAGS)' >> Makefile
- echo 'RELEASEFLAGS=-O2 -DNDEBUG $(COMMONFLAGS)' >> Makefile
- echo '' >> Makefile
- echo 'SRC=src' >> Makefile
- echo 'OBJ=.obj' >> Makefile
- echo 'SRCS=$(wildcard $(SRC)/*.cpp)' >> Makefile
- echo 'OBJS=$(patsubst $(SRC)/%.cpp, $(OBJ)/%.o, $(SRCS))' >> Makefile
- echo 'DEPS=$(wildcard $(OBJ)/*.d)' >> Makefile
- echo '' >> Makefile
- echo 'all: $(OBJ) $(BIN)' >> Makefile
- echo ' @echo " * Compilation finished"' >> Makefile
- echo '' >> Makefile
- echo 'release: CPPFLAGS=$(RELEASEFLAGS)' >> Makefile
- echo 'release: clean' >> Makefile
- echo 'release: all' >> Makefile
- echo '' >> Makefile
- echo '$(BIN): $(OBJS)' >> Makefile
- echo ' @$(CPP) -o $@ $^' >> Makefile
- echo '' >> Makefile
- echo '$(OBJ)/%.o: $(SRC)/%.cpp' >> Makefile
- echo ' @$(CPP) $(CPPFLAGS) -c -o $@ $< $(CPPFLAGS)' >> Makefile
- echo '' >> Makefile
- echo '$(OBJ):' >> Makefile
- echo ' @echo " * Compiling..."' >> Makefile
- echo ' @mkdir -p $@' >> Makefile
- echo '' >> Makefile
- echo 'clean:' >> Makefile
- echo ' @echo " * Cleaning..."' >> Makefile
- echo ' @$(RM) -rf $(OBJ) $(BIN) *.zip *.out' >> Makefile
- echo ' @echo " * Cleanup finished"' >> Makefile
- echo '' >> Makefile
- echo 'zip: clean' >> Makefile
- echo ' @echo " * Generating zip file..."' >> Makefile
- echo ' @zip -r $(BIN).zip $(SRC) Makefile' >> Makefile
- echo ' @echo " * Zip generated"' >> Makefile
- echo '' >> Makefile
- echo 'nuevo:' >> Makefile
- echo ' @echo " * Creating new project..."' >> Makefile
- echo ' @rm -rf $(SRC)' >> Makefile
- echo ' @mkdir -p $(SRC)' >> Makefile
- echo ' @git init -q' >> Makefile
- echo ' @echo -ne ".vscode\nobj\n*.out\n*.in\n$(BIN)\n*.zip\n*.txt\n" > .gitignore' >> Makefile
- echo ' @echo -ne "#include <iostream>\n\nint main() {\n\n\tstd::cout << \"jaja pene, lo pillas, porque dice pene jaja\" << std::endl;\n\n\treturn 0;\n}\n" > src/$(BIN).cpp' >> Makefile
- echo ' @echo "$(BIN)" > README.md' >> Makefile
- echo ' @git add .' >> Makefile
- echo ' @git commit -m "Initial commit" -q' >> Makefile
- echo ' @echo " * "Project $(BIN) created' >> Makefile
- echo '' >> Makefile
- echo 'test: all test.in' >> Makefile
- echo ' @echo " * Testing..."' >> Makefile
- echo ' @rm -rf test.out debug.out' >> Makefile
- echo ' @time ./$(BIN) < test.in > test.out 2> debug.out' >> Makefile
- echo ' @echo' >> Makefile
- echo ' @echo " * Test finished"' >> Makefile
- echo '' >> Makefile
- echo 'run: all' >> Makefile
- echo ' @echo " * Running..."' >> Makefile
- echo ' @./$(BIN)' >> Makefile
- echo '' >> Makefile
- echo 'linecount:' >> Makefile
- echo ' @echo " * Line count:"' >> Makefile
- echo ' @wc -l src/*' >> Makefile
- echo '' >> Makefile
- echo 'help:' >> Makefile
- echo ' @echo " * Help"' >> Makefile
- echo ' @echo -ne "Para compilar en modo debug: \"make\"\nPara compilar con optimizaciones: \"make release\"\nPara limpiar el proyecto: \"make clean\"\nPara generar un zip entregable: \"make zip\"\nPara ejecutar casos de prueba: \"make test\"\n - Debe existir \"test.in\" (entrada de las pruebas).\n - Genera test.out, la salida del programa y debug.out, salida de error (normalmente para pruebas).\nPara ejecutar el programa sin argumentos: \"make run\"\nPara contar el número de líneas escritas en el proyecto: \"make linecount\"\n"' >> Makefile
- echo '' >> Makefile
- echo '-include $(DEPS)' >> Makefile
- # Makefile end
- sed -i "s/BIN=main/BIN=$1/g" Makefile
- if [[ $# = 2 ]]
- then
- sed -i "s/\$(DEPFLAGS)/\$(DEPFLAGS) -std=c++$2/g" Makefile
- fi
- make nuevo
- code .
- fi
Add Comment
Please, Sign In to add comment