Skip to content

Instantly share code, notes, and snippets.

@j4cobgarby
Created July 26, 2017 21:09
Show Gist options
  • Save j4cobgarby/838f312416a3d10c43ac7b18aa6b44fa to your computer and use it in GitHub Desktop.
Save j4cobgarby/838f312416a3d10c43ac7b18aa6b44fa to your computer and use it in GitHub Desktop.
Generates a clean SFML project for you! Includes a Makefile
# Put this in your /bin
# You might need to write 'chmod a+x /bin/sfml-setup.sh'
#!/bin/bash
mkdir $1
cd $1
mkdir src
touch src/main.cpp
cd src
echo "#include <SFML/Graphics.hpp>" >> main.cpp
echo "" >> main.cpp
echo "#include <iostream>" >> main.cpp
echo "using namespace std;" >> main.cpp
echo "" >> main.cpp
echo "int main()" >> main.cpp
echo "{" >> main.cpp
echo " sf::RenderWindow window(sf::VideoMode(800, 600), \"My window\");" >> main.cpp
echo "" >> main.cpp
echo " while (window.isOpen())" >> main.cpp
echo " {" >> main.cpp
echo "" >> main.cpp
echo " sf::Event event;" >> main.cpp
echo " while (window.pollEvent(event))" >> main.cpp
echo " {" >> main.cpp
echo " if (event.type == sf::Event::Closed)" >> main.cpp
echo " window.close();" >> main.cpp
echo " }" >> main.cpp
echo "" >> main.cpp
echo " window.clear(sf::Color::Black);" >> main.cpp
echo "" >> main.cpp
echo " // Draw stuff here :)" >> main.cpp
echo "" >> main.cpp
echo " window.display();" >> main.cpp
echo " }" >> main.cpp
echo "" >> main.cpp
echo " return 0;" >> main.cpp
echo "}" >> main.cpp
cd ..
touch Makefile
echo "CXX := g++" >> Makefile
echo "CXXFLAGS := -c" >> Makefile
echo "LD := g++" >> Makefile
echo "LDFLAGS := -lsfml-graphics -lsfml-window -lsfml-system" >> Makefile
echo "" >> Makefile
echo "SRCDIR := src" >> Makefile
echo "OBJDIR := obj" >> Makefile
echo "" >> Makefile
echo "SRC := \$(wildcard \$(SRCDIR)/*.cpp)" >> Makefile
echo "OBJ := \$(patsubst \$(SRCDIR)/%.cpp, \$(OBJDIR)/%.o, \$(SRC))" >> Makefile
echo "EXE := sfml-app" >> Makefile
echo "" >> Makefile
echo ".PHONY: all clean" >> Makefile
echo "" >> Makefile
echo "all: \$(EXE)" >> Makefile
echo "" >> Makefile
echo "clean:" >> Makefile
echo " rm -f \$(OBJ)" >> Makefile
echo " rm -f \$(EXE)" >> Makefile
echo "" >> Makefile
echo "\$(EXE): \$(OBJDIR) \$(OBJ)" >> Makefile
echo " \$(LD) \$(OBJ) \$(LDFLAGS) -std=c++14 -o \$@" >> Makefile
echo "" >> Makefile
echo "\$(OBJDIR):" >> Makefile
echo " mkdir \$@" >> Makefile
echo "" >> Makefile
echo "\$(OBJDIR)/%.o: \$(SRCDIR)/%.cpp" >> Makefile
echo " \$(CXX) \$(CXXFLAGS) -std=c++14 \$< -o \$@" >> Makefile
echo "" >> Makefile
echo "\$(OBJDIR)/%.o: \$(SRCDIR)/%.cpp \$(SRCDIR)/%.h" >> Makefile
echo " \$(CXX) \$(CXXFLAGS) -std=c++14 \$< -o \$@" >> Makefile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment