Last active
June 2, 2017 00:11
-
-
Save caiofcm/83d4d3d2370546d846454ff74dea7348 to your computer and use it in GitHub Desktop.
Generate new CPP Project based on Makefile for g++ with folders to organize files (default including ipopt/adolc - change it; create a help command also)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Use -gt 1 to consume two arguments per pass in the loop (e.g. each | |
| # argument has a corresponding value to go with it). | |
| # Use -gt 0 to consume one or more arguments per pass in the loop (e.g. | |
| # some arguments don't have a corresponding value to go with it such | |
| # as in the --default example). | |
| # note: if this is set to -gt 0 the /etc/hosts part is not recognized ( may be a bug ) | |
| while [[ $# -gt 0 ]] | |
| do | |
| key="$1" | |
| case $key in | |
| -n|--name) | |
| PROJECTNAME="$2" | |
| shift # past argument | |
| ;; | |
| -d|--delete) | |
| #DELETEALL="$2" | |
| DELETEALL="YES" | |
| echo $DELETEALL | |
| shift # past argument | |
| ;; | |
| -f|--newcppfile) | |
| NEWCPPFILENAME="$2" | |
| shift # past argument | |
| ;; | |
| --default) | |
| DEFAULT=YES | |
| ;; | |
| *) | |
| # unknown option | |
| ;; | |
| esac | |
| shift # past argument or value | |
| done | |
| # if [[ -d $1 ]]; then | |
| # echo "I M HERO" | |
| # tail -1 $1 | |
| # fi | |
| if [ "$PROJECTNAME" != "" ]; then | |
| echo "Creating new project $PROJECTNAME." | |
| echo "" | |
| mkdir bin -p -v | |
| mkdir build -p -v | |
| mkdir doc -p -v | |
| mkdir include -p -v | |
| mkdir lib -p -v | |
| # touch Makefile | |
| # touch README.md | |
| mkdir spike -p -v | |
| mkdir src -p -v | |
| mkdir test -p -v | |
| echo " | |
| # PROJECT $PROJECTNAME | |
| # Created on: `date` | |
| #TODO: .... | |
| # | |
| ########################################################################## | |
| # You can modify this example makefile to fit for your own program. # | |
| # Usually, you only need to change LIB/INC/CFLAGS entries below. # | |
| ########################################################################## | |
| CC := g++ # This is the main compiler | |
| SRCDIR := src | |
| BUILDDIR := build | |
| TARGET := bin/$PROJECTNAME | |
| SRCEXT := cpp | |
| SOURCES := \$(shell find \$(SRCDIR) -type f -name *.\$(SRCEXT)) | |
| OBJECTS := \$(patsubst \$(SRCDIR)/%,\$(BUILDDIR)/%,\$(SOURCES:.\$(SRCEXT)=.o)) | |
| CFLAGS := -O3 -pipe -DNDEBUG -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas -Wno-long-long -DIPOPT_BUILD | |
| LIB := \`PKG_CONFIG_PATH=/mingw64/lib64/pkgconfig:/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig:/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig pkg-config --libs ipopt\` \\ | |
| -L /c/Users/Marcellos/lib/ADOL-C-2.6.3/ADOL-C/.libs -ladolc | |
| INC := \`PKG_CONFIG_PATH=/mingw64/lib64/pkgconfig:/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig:/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig pkg-config --cflags ipopt\` \\ | |
| -I include | |
| ########################################################################## | |
| # Usually, you don't have to change anything below. Note that if you # | |
| # change certain compiler options, you might have to recompile Ipopt. # | |
| ########################################################################## | |
| \$(TARGET): \$(OBJECTS) | |
| @echo \" Linking...\" | |
| @echo \" \$(CC) \$^ -o \$(TARGET) \$(LIB)\"; \$(CC) \$^ -o \$(TARGET) \$(LIB) | |
| \$(BUILDDIR)/%.o: \$(SRCDIR)/%.\$(SRCEXT) | |
| @mkdir -p \$(BUILDDIR) | |
| @echo \" \$(CC) \$(CFLAGS) \$(INC) -c -o \$@ \$<\"; \$(CC) \$(CFLAGS) \$(INC) -c -o \$@ \$< | |
| clean: | |
| @echo \" Cleaning...\"; | |
| @echo \" \$(RM) -r \$(BUILDDIR) \$(TARGET)\"; \$(RM) -r \$(BUILDDIR) \$(TARGET) | |
| # Tests | |
| tester: | |
| \$(CC) \$(CFLAGS) test/tester.cpp \$(INC) \$(LIB) -o bin/tester | |
| # Spikes | |
| ticket: | |
| \$(CC) \$(CFLAGS) spikes/ticket.cpp \$(INC) \$(LIB) -o bin/ticket | |
| .PHONY: clean | |
| " > Makefile | |
| fi | |
| if [ "$DELETEALL" != "" ]; then | |
| echo " AOWWW" | |
| while true; do | |
| read -p "Deleting project, are you sure (y/n)? " yn | |
| case $yn in | |
| [Yy]* ) | |
| rm bin -r -v | |
| rm build -r -v | |
| rm doc -r -v | |
| rm include -r -v | |
| rm lib -r -v | |
| rm spike -r -v | |
| rm src -r -v | |
| rm test -r -v | |
| rm Makefile | |
| rm README.md | |
| break;; | |
| [Nn]* ) exit;; | |
| * ) echo "Please answer yes or no.";; | |
| esac | |
| done | |
| fi | |
| if [ "$NEWCPPFILENAME" != "" ]; then | |
| touch include/$NEWCPPFILENAME.h | |
| echo " | |
| #include \"$NEWCPPFILENAME.h\" | |
| " > src/$NEWCPPFILENAME.cpp | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment