Skip to content

Commit

Permalink
Use configure.
Browse files Browse the repository at this point in the history
  • Loading branch information
cirosantilli committed Apr 1, 2014
1 parent 9a02305 commit edb65e0
Show file tree
Hide file tree
Showing 40 changed files with 119 additions and 118 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
install: make deps
language: cpp
script: make test
15 changes: 0 additions & 15 deletions Makefile_targets

This file was deleted.

13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@ C and C++ information, cheatsheets and mini-projects.

[![Build Status](https://travis-ci.org/cirosantilli/cpp.svg?branch=master)](https://travis-ci.org/cirosantilli/cpp)

Based on Linux tools, but portable code is clearly separated from non-portable. Thoroughly tested on Ubuntu 12.04. Ports and reproduction reports on other systems are welcome.
Relies on <https://github.com/cirosantilli/cpp-boilerplate> to factor code out. See [its documentation](https://github.com/cirosantilli/cpp-boilerplate/blob/master/README.md) for useful information on how to use this project.

# Most useful files

- [c.c](c.c): C cheatsheet.
- [cpp.cpp](main_cpp.cpp): C++ cheatsheet.
- `Makefile.*`: Makefiles that take care of a ton of possibilities.
- [opengl/](opengl/)
- [kde/](kde/)

# Quickstart

To compile and run each directory on Ubuntu 12.04 do:
On Ubuntu 12.04:

make deps
./configure
make run

You *must* run `make deps` on the top-level before compiling any subdirectories, as this will install basic tools such as recent enough `gcc` and `g++` for C11 and C++11.

When there are multiple files compiled, e.g.:

c.c -> c
Expand All @@ -45,9 +42,9 @@ To get help on all options use:

# About

Larger projects may be in separate dirs.
Larger projects may be in separate repositories.

There may be other compiled languages here for which we don't have much material for a separate dir, specially when we interface that language with C. Ex: Fortran.
There may be other compiled languages here for which we don't have much material for a separate repository, specially when we interface that language with C. Ex: Fortran.

Non-portable features shall be clearly separated from portable ones in either:

Expand Down
2 changes: 1 addition & 1 deletion Vagrantfile_local.rb.example → Vagrantfile_params.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is gitignored.
Box = "precise32"
BoxUrl = "http://files.vagrantup.com/precise32.box"
# Appears on the SSH PS1 line.
Hostname = "cpp"
2 changes: 1 addition & 1 deletion boilerplate
Submodule boilerplate updated 4 files
+0 −1 .gitignore
+1 −1 Makefile
+31 −18 README.md
+4 −2 Vagrantfile
3 changes: 0 additions & 3 deletions boost/Makefile_targets

This file was deleted.

3 changes: 3 additions & 0 deletions boost/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
sudo aptitude update
sudo aptitude install -y libboost1.48-all-dev
5 changes: 2 additions & 3 deletions boost/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
#include <boost/config.hpp>
#include <iostream>
#include <fstream>

#include <boost/config.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
Expand All @@ -17,8 +17,7 @@
using namespace boost;

int
main(int, char *[])
{
main(int, char *[]) {
typedef adjacency_list < listS, vecS, directedS,
no_property, property < edge_weight_t, int > > graph_t;
typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor;
Expand Down
2 changes: 1 addition & 1 deletion c.c
Original file line number Diff line number Diff line change
Expand Up @@ -4014,7 +4014,7 @@ int main(int argc, char **argv)
}

/*
macro
#macro
Shares the disadvantage of every macro of having no scope.
Expand Down
34 changes: 34 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# This cannot be put into makefiles because some systems don't have make installed.
set -e
distro_id="$(lsb_release -i | sed -r 's/.*:\t(.*)/\1/')"
distro_version="$(lsb_release -r | sed -r 's/.*:\t(.*)/\1/')"
if [ "$distro_id" = "Ubuntu" ]; then
sudo apt-get update
sudo apt-get install -y aptitude
sudo aptitude install -y build-essential
# C and C++
sudo aptitude install -y python-software-properties
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo aptitude update
sudo aptitude install -y gcc-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
sudo aptitude install -y g++-4.8
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
# Fortran
sudo aptitude install -y gfortran-4.8
elif [ "$distro_id" = "Debian" ]; then
sudo apt-get update
sudo apt-get install aptitude
sudo aptitude install -y build-essential
sudo aptitude install -y g++
else
echo 'Automatic dependency installation is not supported on your system.'
printf 'Dependencies are:
gcc >= 4.7
gfortran >= 4.7
g++ >= 4.7
make
'
exit 1
fi
13 changes: 6 additions & 7 deletions cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6958,10 +6958,9 @@ int main(int argc, char **argv)
#printf
In c++ there is no more printf formatting strings
must use the C libs for that.
In C++ there is no more printf formatting strings: must use the C libs for that.
It is possible however to obtain some level of formatting control
It is possible however to obtain some level of formatting control.
#endl
Expand Down Expand Up @@ -8074,7 +8073,7 @@ int main(int argc, char **argv)
}

/*
insert
#insert
Insert pair into map.
Expand All @@ -8084,16 +8083,16 @@ int main(int argc, char **argv)
std::map<int,std::string> m;
std::pair<map<int,std::string>::iterator,bool> ret;

ret = m.insert(std::pair<int,std::string>(0, "zero") );
ret = m.insert(std::pair<int,std::string>(0, "zero"));
assert(ret.first == m.find(0));
assert(ret.second == true);

ret = m.insert(std::pair<int,std::string>(1, "one") );
ret = m.insert(std::pair<int,std::string>(1, "one"));
assert(ret.first == m.find(1));
assert(ret.second == true);

//key already present
ret = m.insert(std::pair<int,std::string>(1, "one2") );
ret = m.insert(std::pair<int,std::string>(1, "one2"));
assert(m[1] == "one");
assert(ret.first == m.find(1));
assert(ret.second == false);
Expand Down
27 changes: 12 additions & 15 deletions flex_bison/bison/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ CC := gcc
CFLAGS ?= -Wall -std=c99 -pedantic -Wno-unused-function

#paths
AUX_DIR ?= _out/
OBJ_EXT ?= .o
IN_DIR ?= ./
FLEX_EXT ?= .l
BISON_EXT ?= .y
IN_EXTS ?= $(FLEX_EXT) $(BISON_EXT) .c
OUT_DIR ?= $(AUX_DIR)
OUT_EXT ?= .elf
AUX_DIR ?= _out/
OBJ_EXT ?= .o
IN_DIR ?= ./
FLEX_EXT ?= .l
BISON_EXT ?= .y
IN_EXTS ?= $(FLEX_EXT) $(BISON_EXT) .c
OUT_DIR ?= $(AUX_DIR)
OUT_EXT ?= .elf
OUT_BASENAME_NOEXT ?= a

INS := $(foreach IN_EXT, $(IN_EXTS), $(wildcard $(IN_DIR)*$(IN_EXT)) )
INS := $(foreach IN_EXT, $(IN_EXTS), $(wildcard $(IN_DIR)*$(IN_EXT)) )
INS_NODIR := $(notdir $(INS))
OBJS_NODIR := $(filter %$(OBJ_EXT), $(foreach IN_EXT, $(IN_EXTS), $(patsubst %$(IN_EXT),%$(OBJ_EXT),$(INS_NODIR))))
OBJS := $(addprefix $(AUX_DIR), $(OBJS_NODIR))
OBJS := $(addprefix $(AUX_DIR), $(OBJS_NODIR))

OUT_BASENAME:= $(OUT_BASENAME_NOEXT)$(OUT_EXT)
OUT := $(OUT_DIR)$(OUT_BASENAME)
OUT := $(OUT_DIR)$(OUT_BASENAME)

#bison generated header:
BISON_H := $(addprefix $(AUX_DIR), $(notdir $(patsubst %$(BISON_EXT), %.h, $(wildcard $(IN_DIR)*$(BISON_EXT)))))
FLEX_C := $(addprefix $(AUX_DIR), $(notdir $(patsubst %$(FLEX_EXT), %.c, $(wildcard $(IN_DIR)*$(FLEX_EXT)))))

.PHONY: all run test mkdir clean ubuntu_install_deps
.PHONY: all clean mkdir run test

.SECONDARY: $(FLEX_C) $(BISON_H)

Expand Down Expand Up @@ -72,6 +72,3 @@ run: all

test: all
python test.py "$(OUT)"

ubuntu_install_deps:
sudo aptitude install -y flex bison
3 changes: 3 additions & 0 deletions flex_bison/bison/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
sudo aptitude update
sudo aptitude install -y flex bison
8 changes: 4 additions & 4 deletions flex_bison/bison/test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env python

"""
does many test cases
Does many test cases.
Run as:
run as:
test.py executable
"""

import subprocess
import sys
import unittest
import unittest

class ProgramInput:

Expand Down
13 changes: 5 additions & 8 deletions flex_bison/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ OUT := $(OUT_DIR)$(OUT_BASENAME)
BISON_H := $(addprefix $(AUX_DIR), $(notdir $(patsubst %$(BISON_EXT), %.h, $(wildcard $(IN_DIR)*$(BISON_EXT)))))
FLEX_C := $(addprefix $(AUX_DIR), $(notdir $(patsubst %$(FLEX_EXT), %.c, $(wildcard $(IN_DIR)*$(FLEX_EXT)))))

.PHONY: all run test mkdir clean ubuntu_install_deps
.PHONY: all clean mkdir run test

.SECONDARY: $(FLEX_C) $(BISON_H)

Expand All @@ -46,20 +46,20 @@ all: mkdir $(OUT)
$(OUT): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(OUT) -lfl

$(AUX_DIR)%$(OBJ_EXT): $(IN_DIR)%.c $(BISON_H)
$(AUX_DIR)%$(OBJ_EXT): $(IN_DIR)%.c $(BISON_H)
$(CC) $(CFLAGS) -c "$<" -o "$@"

$(AUX_DIR)%$(OBJ_EXT): $(IN_DIR)%.cpp $(BISON_H)
$(AUX_DIR)%$(OBJ_EXT): $(IN_DIR)%.cpp $(BISON_H)
$(CC) $(CFLAGS) -c "$<" -o "$@"

$(AUX_DIR)%$(OBJ_EXT): $(AUX_DIR)%.c $(BISON_H)
$(AUX_DIR)%$(OBJ_EXT): $(AUX_DIR)%.c $(BISON_H)
$(CC) $(CFLAGS) -I. -c "$<" -o "$@"

$(AUX_DIR)%.c: $(IN_DIR)%$(FLEX_EXT)
flex -o "$(AUX_DIR)$*".c "$<"

$(AUX_DIR)%.c $(AUX_DIR)%.h: $(IN_DIR)%$(BISON_EXT)
bison -v -o "$(AUX_DIR)$*".c --defines="$(AUX_DIR)$*".h "$<"
bison -v -o "$(AUX_DIR)$*".c --defines="$(AUX_DIR)$*".h "$<"

clean:
rm -rf "$(AUX_DIR)" "$(OUT_DIR)"
Expand All @@ -72,6 +72,3 @@ run: all

test: all
python test.py "$(OUT)"

ubuntu_install_deps:
sudo aptitude install -y flex bison
3 changes: 3 additions & 0 deletions flex_bison/cpp/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
sudo aptitude update
sudo aptitude install -y flex bison
5 changes: 1 addition & 4 deletions flex_bison/flex/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OUT := $(OUT_DIR)$(OUT_BASENAME)
#bison generated header:
FLEX_C := $(addprefix $(AUX_DIR), $(notdir $(patsubst %.lex, %.c, $(wildcard $(IN_DIR)*.lex))))

.PHONY: all run test mkdir clean ubuntu_install_deps
.PHONY: all clean mkdir test run

all: mkdir $(OUT)

Expand Down Expand Up @@ -51,6 +51,3 @@ run: all

test: all
python test.py "$(OUT)"

ubuntu_install_deps:
sudo aptitude install -y flex bison
3 changes: 3 additions & 0 deletions flex_bison/flex/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
sudo aptitude update
sudo aptitude install -y flex bison
6 changes: 0 additions & 6 deletions gsl/Makefile_targets

This file was deleted.

3 changes: 3 additions & 0 deletions gsl/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sudo aptitude update
sudo aptitude install -y libgsl0-dev
sudo apt-get install -y libplplot-dev plplot11-driver-xwin
3 changes: 0 additions & 3 deletions gtk/Makefile_targets

This file was deleted.

3 changes: 3 additions & 0 deletions gtk/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
sudo aptitude update
sudo aptitude install -y libgtk-3-dev
3 changes: 0 additions & 3 deletions kde/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ clean:
install: all
cd "$(BUILD_DIR)" && make install

deps:
sudo aptitude install -y kdelibs5-dev

run: all
cd "$(BUILD_DIR)" && ./$(TARGET)

Expand Down
2 changes: 2 additions & 0 deletions kde/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
sudo aptitude install -y kdelibs5-dev
9 changes: 0 additions & 9 deletions lapack/Makefile_targets

This file was deleted.

9 changes: 9 additions & 0 deletions lapack/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
sudo aptitude update
# BLAS C/Fotran and LAPACK Fortran:
sudo aptitude install -y liblapack-dev
# Lapack C via LAPACKE:
# TODO: how to install on Ubuntu 12.04?
# The following works only on later Ubuntu
#sudo aptitude install -y liblapacke-dev
exit 1
3 changes: 0 additions & 3 deletions ode/Makefile_targets

This file was deleted.

2 changes: 2 additions & 0 deletions ode/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sudo aptitude update
sudo aptitude install -y libode-dev
3 changes: 0 additions & 3 deletions opencv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@ $(OUT_DIR)%$(OUT_EXT): $(IN_DIR)%$(IN_EXT)

clean:
rm -rf $(OUT_DIR) $(AUX_DIR)

deps:
sudo apt-get install -y libopencv-dev opencv-doc
3 changes: 0 additions & 3 deletions opencv/Makefile_targets

This file was deleted.

3 changes: 3 additions & 0 deletions opencv/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
sudo aptitude update
sudo aptitude install -y libopencv-dev
Loading

0 comments on commit edb65e0

Please sign in to comment.