Project

General

Profile

xcodeIncsLArIAT.sh

Script to set the include paths for Xcode development - Brian Rebel, 09/18/2015 07:43 AM

 
1
#!/bin/bash
2
#
3
# Add referneces to headers to an Xcode project
4
#
5
# You must have everything set up already first (e.g. do ". mrb s")
6
#
7
# You should add ${MRB_SOURCE} to the "Header Search Paths" in the project first.
8
#
9

    
10

    
11
function usage() {
12
cat 1>&2 << EOF
13
Usage: xcodeIncs.sh [options] /path/to/Xcode/project
14

    
15
Insert references to headers into an Xcode project.
16

    
17
You must have everything set up already (e.g. do ". mrb s").
18

    
19
You must have already added \${MRB_SOURCE} to the "Header Search Paths" in the Xcode project.
20

    
21
Paths to art, geant4, cetlib, messagefacility, fhiclcpp, clhep, root, nutools, genie, and nova* are included.
22
If you want even more (everything with an INC in the environment variable name), do "-a", but note that
23
doing so could make Xcode very slow.
24

    
25
The argument is the path to the Xcode project. The path should end in the project name (no final slash).
26

    
27
Options (not recommended unless you know what you are doing):
28
-a       Search all include paths (may make Xcode slow)
29

    
30
EOF
31
}
32

    
33
# ---- Main ----
34

    
35
# Determine command options (just -h for help)
36

    
37
doall='--none--'
38

    
39
while getopts ":ha" OPTION
40
do
41
case $OPTION in
42
h   ) usage ; exit 0 ;;
43
a   ) doall=true;;
44
*   ) echo "ERROR: Unknown option" ; usage ; exit 1 ;;
45
esac
46
done
47

    
48
# Get the path to the project
49
shift $((OPTIND - 1))
50
if [ $# -lt 1 ]; then
51
echo "ERROR: No path to xcode project"
52
usage
53
exit 1
54
fi
55

    
56
# Capture the product name
57
xcodeprojpath=$1
58
xcodeproj=$(basename $xcodeprojpath)
59
projFile=${xcodeprojpath}/${xcodeproj}.xcodeproj/project.pbxproj
60

    
61
# Does the project file exist?
62
if [ ! -r "$projFile" ]; then
63
  echo "ERROR: $projFile does not exist"
64
  exit 2
65
fi
66

    
67
# Do the search and replace
68
if [ "$doall" == "true" ]; then
69
  r=$(env | grep INC | sort | awk 'BEGIN { FS="="; ORS=" "} ; { print "\"${"$1"}\"," } ')
70
else
71
  r=$(env | grep INC | egrep 'ART|ARTDAQ_CORE|BOOST|CET|CLHEP|FANN|FHICL|FFTW|G4|GENIE|LOG4CPP|MESSAGE|LARIATFRAGMENTS|NUTOOLS|POSTGRESQL|PYTHON|PYTHIA|ROOT_|XERCES_C|' | grep -v DIR | sort | awk 'BEGIN { FS="="; ORS=" "} ; { print "\"${"$1"}\"," } ')
72
fi
73

    
74
echo "Adding $r"
75
sed -i '.bak' "s/\"\${MRB_SOURCE}\",/\"\${MRB_SOURCE}\",$r/" $projFile
76

    
77
echo "Updated $projFile"