adriannic

makeProject.sh

May 27th, 2022 (edited)
958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.42 KB | None | 0 0
  1. #!/bin/bash
  2. # Escrito por Adrián Nicolás Aguilera en su eterna procrastinación para hacer más sencillo el crear y manejar nuevos proyectos
  3. if [[ $# != 1 ]] && [[ $# != 2 ]]
  4. then
  5.     >&2 echo -ne "Uso: $0 nombre_proyecto [versión_c++]\nEj. $0 prueba 11\n"
  6.     exit 1
  7. else
  8.     mkdir $1
  9.     cd $1
  10.     # Makefile
  11.     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
  12.     echo '# nombre del ejecutable (cambiar según el proyecto)' >> Makefile
  13.     echo 'BIN=main' >> Makefile
  14.     echo 'INCDIRS=. ./include/' >> Makefile
  15.     echo '' >> Makefile
  16.     echo 'CPP=g++' >> Makefile
  17.     echo '' >> Makefile
  18.     echo '# Generar archivos que crean reglas para las dependencias .h' >> Makefile
  19.     echo 'DEPFLAGS=-MP -MD' >> Makefile
  20.     echo '# Añadir -I a cada directorio de include' >> Makefile
  21.     echo 'COMMONFLAGS=-Wall -Wextra -Wold-style-cast -Wshadow $(foreach D, $(INCDIRS), -I$(D)) $(DEPFLAGS)' >> Makefile
  22.     echo 'CPPFLAGS=-Og -g $(COMMONFLAGS)' >> Makefile
  23.     echo 'RELEASEFLAGS=-O2 -DNDEBUG $(COMMONFLAGS)' >> Makefile
  24.     echo '' >> Makefile
  25.     echo 'SRC=src' >> Makefile
  26.     echo 'OBJ=.obj' >> Makefile
  27.     echo 'SRCS=$(wildcard $(SRC)/*.cpp)' >> Makefile
  28.     echo 'OBJS=$(patsubst $(SRC)/%.cpp, $(OBJ)/%.o, $(SRCS))' >> Makefile
  29.     echo 'DEPS=$(wildcard $(OBJ)/*.d)' >> Makefile
  30.     echo '' >> Makefile
  31.     echo 'all: $(OBJ) $(BIN)' >> Makefile
  32.     echo '  @echo " * Compilation finished"' >> Makefile
  33.     echo '' >> Makefile
  34.     echo 'release: CPPFLAGS=$(RELEASEFLAGS)' >> Makefile
  35.     echo 'release: clean' >> Makefile
  36.     echo 'release: all' >> Makefile
  37.     echo '' >> Makefile
  38.     echo '$(BIN): $(OBJS)' >> Makefile
  39.     echo '  @$(CPP) -o $@ $^' >> Makefile
  40.     echo '' >> Makefile
  41.     echo '$(OBJ)/%.o: $(SRC)/%.cpp' >> Makefile
  42.     echo '  @$(CPP) $(CPPFLAGS) -c -o $@ $< $(CPPFLAGS)' >> Makefile
  43.     echo '' >> Makefile
  44.     echo '$(OBJ):' >> Makefile
  45.     echo '  @echo " * Compiling..."' >> Makefile
  46.     echo '  @mkdir -p $@' >> Makefile
  47.     echo '' >> Makefile
  48.     echo 'clean:' >> Makefile
  49.     echo '  @echo " * Cleaning..."' >> Makefile
  50.     echo '  @$(RM) -rf $(OBJ) $(BIN) *.zip *.out' >> Makefile
  51.     echo '  @echo " * Cleanup finished"' >> Makefile
  52.     echo '' >> Makefile
  53.     echo 'zip: clean' >> Makefile
  54.     echo '  @echo " * Generating zip file..."' >> Makefile
  55.     echo '  @zip -r $(BIN).zip $(SRC) Makefile' >> Makefile
  56.     echo '  @echo " * Zip generated"' >> Makefile
  57.     echo '' >> Makefile
  58.     echo 'nuevo:' >> Makefile
  59.     echo '  @echo " * Creating new project..."' >> Makefile
  60.     echo '  @rm -rf $(SRC)' >> Makefile
  61.     echo '  @mkdir -p $(SRC)' >> Makefile
  62.     echo '  @git init -q' >> Makefile
  63.     echo '  @echo -ne ".vscode\nobj\n*.out\n*.in\n$(BIN)\n*.zip\n*.txt\n" > .gitignore' >> Makefile
  64.     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
  65.     echo '  @echo "$(BIN)" > README.md' >> Makefile
  66.     echo '  @git add .' >> Makefile
  67.     echo '  @git commit -m "Initial commit" -q' >> Makefile
  68.     echo '  @echo " * "Project $(BIN) created' >> Makefile
  69.     echo '' >> Makefile
  70.     echo 'test: all test.in' >> Makefile
  71.     echo '  @echo " * Testing..."' >> Makefile
  72.     echo '  @rm -rf test.out debug.out' >> Makefile
  73.     echo '  @time ./$(BIN) < test.in > test.out 2> debug.out' >> Makefile
  74.     echo '  @echo' >> Makefile
  75.     echo '  @echo " * Test finished"' >> Makefile
  76.     echo '' >> Makefile
  77.     echo 'run: all' >> Makefile
  78.     echo '  @echo " * Running..."' >> Makefile
  79.     echo '  @./$(BIN)' >> Makefile
  80.     echo '' >> Makefile
  81.     echo 'linecount:' >> Makefile
  82.     echo '  @echo " * Line count:"' >> Makefile
  83.     echo '  @wc -l src/*' >> Makefile
  84.     echo '' >> Makefile
  85.     echo 'help:' >> Makefile
  86.     echo '  @echo " * Help"' >> Makefile
  87.     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
  88.     echo '' >> Makefile
  89.     echo '-include $(DEPS)' >> Makefile
  90.     # Makefile end
  91.     sed -i "s/BIN=main/BIN=$1/g" Makefile
  92.     if [[ $# = 2 ]]
  93.     then
  94.         sed -i "s/\$(DEPFLAGS)/\$(DEPFLAGS) -std=c++$2/g" Makefile
  95.     fi
  96.     make nuevo
  97.     code .
  98. fi
Add Comment
Please, Sign In to add comment