Skip to content

Commit edb65e0

Browse files
committed
Use configure.
1 parent 9a02305 commit edb65e0

40 files changed

+119
-118
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
install: make deps
21
language: cpp
3-
script: make test

Makefile_targets

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@ C and C++ information, cheatsheets and mini-projects.
22

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

5-
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.
5+
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.
66

77
# Most useful files
88

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

1514
# Quickstart
1615

17-
To compile and run each directory on Ubuntu 12.04 do:
16+
On Ubuntu 12.04:
1817

19-
make deps
18+
./configure
2019
make run
2120

22-
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.
23-
2421
When there are multiple files compiled, e.g.:
2522

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

4643
# About
4744

48-
Larger projects may be in separate dirs.
45+
Larger projects may be in separate repositories.
4946

50-
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.
47+
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.
5148

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file is gitignored.
21
Box = "precise32"
32
BoxUrl = "http://files.vagrantup.com/precise32.box"
3+
# Appears on the SSH PS1 line.
44
Hostname = "cpp"

boost/Makefile_targets

Lines changed: 0 additions & 3 deletions
This file was deleted.

boost/configure

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
sudo aptitude update
3+
sudo aptitude install -y libboost1.48-all-dev

boost/graph.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
// accompanying file LICENSE_1_0.txt or copy at
66
// http://www.boost.org/LICENSE_1_0.txt)
77
//=======================================================================
8-
#include <boost/config.hpp>
98
#include <iostream>
109
#include <fstream>
1110

11+
#include <boost/config.hpp>
1212
#include <boost/graph/graph_traits.hpp>
1313
#include <boost/graph/adjacency_list.hpp>
1414
#include <boost/graph/dijkstra_shortest_paths.hpp>
@@ -17,8 +17,7 @@
1717
using namespace boost;
1818

1919
int
20-
main(int, char *[])
21-
{
20+
main(int, char *[]) {
2221
typedef adjacency_list < listS, vecS, directedS,
2322
no_property, property < edge_weight_t, int > > graph_t;
2423
typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor;

c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4014,7 +4014,7 @@ int main(int argc, char **argv)
40144014
}
40154015

40164016
/*
4017-
macro
4017+
#macro
40184018
40194019
Shares the disadvantage of every macro of having no scope.
40204020

configure

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
# This cannot be put into makefiles because some systems don't have make installed.
3+
set -e
4+
distro_id="$(lsb_release -i | sed -r 's/.*:\t(.*)/\1/')"
5+
distro_version="$(lsb_release -r | sed -r 's/.*:\t(.*)/\1/')"
6+
if [ "$distro_id" = "Ubuntu" ]; then
7+
sudo apt-get update
8+
sudo apt-get install -y aptitude
9+
sudo aptitude install -y build-essential
10+
# C and C++
11+
sudo aptitude install -y python-software-properties
12+
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
13+
sudo aptitude update
14+
sudo aptitude install -y gcc-4.8
15+
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
16+
sudo aptitude install -y g++-4.8
17+
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
18+
# Fortran
19+
sudo aptitude install -y gfortran-4.8
20+
elif [ "$distro_id" = "Debian" ]; then
21+
sudo apt-get update
22+
sudo apt-get install aptitude
23+
sudo aptitude install -y build-essential
24+
sudo aptitude install -y g++
25+
else
26+
echo 'Automatic dependency installation is not supported on your system.'
27+
printf 'Dependencies are:
28+
gcc >= 4.7
29+
gfortran >= 4.7
30+
g++ >= 4.7
31+
make
32+
'
33+
exit 1
34+
fi

cpp.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6958,10 +6958,9 @@ int main(int argc, char **argv)
69586958
69596959
#printf
69606960
6961-
In c++ there is no more printf formatting strings
6962-
must use the C libs for that.
6961+
In C++ there is no more printf formatting strings: must use the C libs for that.
69636962
6964-
It is possible however to obtain some level of formatting control
6963+
It is possible however to obtain some level of formatting control.
69656964
69666965
#endl
69676966
@@ -8074,7 +8073,7 @@ int main(int argc, char **argv)
80748073
}
80758074

80768075
/*
8077-
insert
8076+
#insert
80788077
80798078
Insert pair into map.
80808079
@@ -8084,16 +8083,16 @@ int main(int argc, char **argv)
80848083
std::map<int,std::string> m;
80858084
std::pair<map<int,std::string>::iterator,bool> ret;
80868085

8087-
ret = m.insert(std::pair<int,std::string>(0, "zero") );
8086+
ret = m.insert(std::pair<int,std::string>(0, "zero"));
80888087
assert(ret.first == m.find(0));
80898088
assert(ret.second == true);
80908089

8091-
ret = m.insert(std::pair<int,std::string>(1, "one") );
8090+
ret = m.insert(std::pair<int,std::string>(1, "one"));
80928091
assert(ret.first == m.find(1));
80938092
assert(ret.second == true);
80948093

80958094
//key already present
8096-
ret = m.insert(std::pair<int,std::string>(1, "one2") );
8095+
ret = m.insert(std::pair<int,std::string>(1, "one2"));
80978096
assert(m[1] == "one");
80988097
assert(ret.first == m.find(1));
80998098
assert(ret.second == false);

flex_bison/bison/Makefile

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,29 @@ CC := gcc
1515
CFLAGS ?= -Wall -std=c99 -pedantic -Wno-unused-function
1616

1717
#paths
18-
AUX_DIR ?= _out/
19-
OBJ_EXT ?= .o
20-
IN_DIR ?= ./
21-
FLEX_EXT ?= .l
22-
BISON_EXT ?= .y
23-
IN_EXTS ?= $(FLEX_EXT) $(BISON_EXT) .c
24-
OUT_DIR ?= $(AUX_DIR)
25-
OUT_EXT ?= .elf
18+
AUX_DIR ?= _out/
19+
OBJ_EXT ?= .o
20+
IN_DIR ?= ./
21+
FLEX_EXT ?= .l
22+
BISON_EXT ?= .y
23+
IN_EXTS ?= $(FLEX_EXT) $(BISON_EXT) .c
24+
OUT_DIR ?= $(AUX_DIR)
25+
OUT_EXT ?= .elf
2626
OUT_BASENAME_NOEXT ?= a
2727

28-
INS := $(foreach IN_EXT, $(IN_EXTS), $(wildcard $(IN_DIR)*$(IN_EXT)) )
28+
INS := $(foreach IN_EXT, $(IN_EXTS), $(wildcard $(IN_DIR)*$(IN_EXT)) )
2929
INS_NODIR := $(notdir $(INS))
3030
OBJS_NODIR := $(filter %$(OBJ_EXT), $(foreach IN_EXT, $(IN_EXTS), $(patsubst %$(IN_EXT),%$(OBJ_EXT),$(INS_NODIR))))
31-
OBJS := $(addprefix $(AUX_DIR), $(OBJS_NODIR))
31+
OBJS := $(addprefix $(AUX_DIR), $(OBJS_NODIR))
3232

3333
OUT_BASENAME:= $(OUT_BASENAME_NOEXT)$(OUT_EXT)
34-
OUT := $(OUT_DIR)$(OUT_BASENAME)
34+
OUT := $(OUT_DIR)$(OUT_BASENAME)
3535

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

40-
.PHONY: all run test mkdir clean ubuntu_install_deps
40+
.PHONY: all clean mkdir run test
4141

4242
.SECONDARY: $(FLEX_C) $(BISON_H)
4343

@@ -72,6 +72,3 @@ run: all
7272

7373
test: all
7474
python test.py "$(OUT)"
75-
76-
ubuntu_install_deps:
77-
sudo aptitude install -y flex bison

flex_bison/bison/configure

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
sudo aptitude update
3+
sudo aptitude install -y flex bison

flex_bison/bison/test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/usr/bin/env python
22

33
"""
4-
does many test cases
4+
Does many test cases.
5+
6+
Run as:
57
6-
run as:
7-
88
test.py executable
99
"""
1010

1111
import subprocess
1212
import sys
13-
import unittest
13+
import unittest
1414

1515
class ProgramInput:
1616

flex_bison/cpp/Makefile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ OUT := $(OUT_DIR)$(OUT_BASENAME)
3434
BISON_H := $(addprefix $(AUX_DIR), $(notdir $(patsubst %$(BISON_EXT), %.h, $(wildcard $(IN_DIR)*$(BISON_EXT)))))
3535
FLEX_C := $(addprefix $(AUX_DIR), $(notdir $(patsubst %$(FLEX_EXT), %.c, $(wildcard $(IN_DIR)*$(FLEX_EXT)))))
3636

37-
.PHONY: all run test mkdir clean ubuntu_install_deps
37+
.PHONY: all clean mkdir run test
3838

3939
.SECONDARY: $(FLEX_C) $(BISON_H)
4040

@@ -46,20 +46,20 @@ all: mkdir $(OUT)
4646
$(OUT): $(OBJS)
4747
$(CC) $(CFLAGS) $(OBJS) -o $(OUT) -lfl
4848

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

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

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

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

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

6464
clean:
6565
rm -rf "$(AUX_DIR)" "$(OUT_DIR)"
@@ -72,6 +72,3 @@ run: all
7272

7373
test: all
7474
python test.py "$(OUT)"
75-
76-
ubuntu_install_deps:
77-
sudo aptitude install -y flex bison

flex_bison/cpp/configure

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
sudo aptitude update
3+
sudo aptitude install -y flex bison

flex_bison/flex/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ OUT := $(OUT_DIR)$(OUT_BASENAME)
2222
#bison generated header:
2323
FLEX_C := $(addprefix $(AUX_DIR), $(notdir $(patsubst %.lex, %.c, $(wildcard $(IN_DIR)*.lex))))
2424

25-
.PHONY: all run test mkdir clean ubuntu_install_deps
25+
.PHONY: all clean mkdir test run
2626

2727
all: mkdir $(OUT)
2828

@@ -51,6 +51,3 @@ run: all
5151

5252
test: all
5353
python test.py "$(OUT)"
54-
55-
ubuntu_install_deps:
56-
sudo aptitude install -y flex bison

flex_bison/flex/configure

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
sudo aptitude update
3+
sudo aptitude install -y flex bison

gsl/Makefile_targets

Lines changed: 0 additions & 6 deletions
This file was deleted.

gsl/configure

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sudo aptitude update
2+
sudo aptitude install -y libgsl0-dev
3+
sudo apt-get install -y libplplot-dev plplot11-driver-xwin

gtk/Makefile_targets

Lines changed: 0 additions & 3 deletions
This file was deleted.

gtk/configure

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
sudo aptitude update
3+
sudo aptitude install -y libgtk-3-dev

kde/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ clean:
1313
install: all
1414
cd "$(BUILD_DIR)" && make install
1515

16-
deps:
17-
sudo aptitude install -y kdelibs5-dev
18-
1916
run: all
2017
cd "$(BUILD_DIR)" && ./$(TARGET)
2118

kde/configure

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
sudo aptitude install -y kdelibs5-dev

lapack/Makefile_targets

Lines changed: 0 additions & 9 deletions
This file was deleted.

lapack/configure

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
sudo aptitude update
3+
# BLAS C/Fotran and LAPACK Fortran:
4+
sudo aptitude install -y liblapack-dev
5+
# Lapack C via LAPACKE:
6+
# TODO: how to install on Ubuntu 12.04?
7+
# The following works only on later Ubuntu
8+
#sudo aptitude install -y liblapacke-dev
9+
exit 1

ode/Makefile_targets

Lines changed: 0 additions & 3 deletions
This file was deleted.

ode/configure

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sudo aptitude update
2+
sudo aptitude install -y libode-dev

opencv/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,3 @@ $(OUT_DIR)%$(OUT_EXT): $(IN_DIR)%$(IN_EXT)
3434

3535
clean:
3636
rm -rf $(OUT_DIR) $(AUX_DIR)
37-
38-
deps:
39-
sudo apt-get install -y libopencv-dev opencv-doc

opencv/Makefile_targets

Lines changed: 0 additions & 3 deletions
This file was deleted.

opencv/configure

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
sudo aptitude update
3+
sudo aptitude install -y libopencv-dev

0 commit comments

Comments
 (0)