capri, a script language

Home | Documentation | Releases | Sources | Contact

Source browser

root / capri-lib-io / build-common.sh

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

#!/bin/bash
# Common build functionality, v0.2

#
# Overrides a variable if it is not set
#
#   with CC "g++"
#
with() {
	if [ -z "${!1}" ]; then eval $1='$2'; fi
}

#
# Requires the specified tool, quits with an error otherwise
#
#   requireTool "g++"
#
requireTool() {
	if ! type "$1" >/dev/null 2>&1
	then
		>&2 echo "error: missing required tool '$1'"
		exit 1
	fi
}

#
# Prints a list entry
#
#   list "example.txt"
#
list() {
	echo " - '$1'"	
}

#
# Cleans the given directory
#
#   cleanDirectory "bin"
#
cleanDirectory() {
	if [ -d "$1" ]
	then
		rm -rf $1
	fi
	mkdir "$1"
	list $1
}

#
# Fails if the previous command was erroneous
#
#   $CC -c ...
#   failOnError
#
failOnError() {
	if [[ $? != 0 ]]; then
		echo "build failed"
		exit 1
	fi	
}

#
# Converts a source path to an object
#
#   sourceToObject "src/myclass.cpp"
#
sourceToObject() {
	echo $1.o | sed "s/\//_/g"
}