setup.sh (3183B)
1 #!/usr/bin/env bash 2 3 # This is intended for quickly developming with flatcc tools 4 # in a standalone directory 5 6 set -e 7 8 DIR=`pwd` 9 HERE=`dirname $0` 10 cd $HERE/.. 11 ROOT=`pwd` 12 13 function usage() { 14 echo "Usage: <flatcc-dir>/scripts/`basename $0` [options] <path>" 15 echo "" 16 echo "Options:" 17 echo " -g | --gitignore : create/update .gitignore file" 18 echo " -b | --build : build flatcc (otherwise is must have been)" 19 echo " -x | --example : copy example source and schema" 20 echo " -s | --script : copy generic build script" 21 echo " -a | --all : all of the above" 22 echo " -h | --help" 23 echo "" 24 echo "Sets up a client project for use with flatcc." 25 echo "" 26 echo "Links flatcc into bin, lib, and include directories and optionally" 27 echo "starts a build first. Optionally creates or updates a .gitignore file" 28 echo "and a generic build script, and a sample project." 29 echo "Also adds an empty generated directory for 'flatcc -o generated'," 30 echo "'cc -I generated', and for git to ignore. 'build' directory" 31 echo "will be ignored if '-b' is selected." 32 echo "" 33 echo "When using the build script (-s), place source and schema files in 'src'." 34 echo "It is only meant for sharing small examples." 35 echo "" 36 echo "The flatcc project must be the parent of the path to this script." 37 exit 1 38 } 39 40 while [ $# -gt 0 ]; do 41 case "$1" in 42 43 # Standard help option. 44 -h|-\?|-help|--help|--doc*) usage ;; 45 -g|--gitignore) G=1 ;; 46 -b|--build) B=1 ;; 47 -s|--script) S=1 ;; 48 -x|--example) X=1 ;; 49 -a|--all) G=1; B=1; S=1; X=1 ;; 50 51 -*) echo "Unknown option \"$1\""; usage ;; 52 *) break ;; # unforced end of user options 53 esac 54 shift # next option 55 done 56 57 if [[ -z "$1" ]]; then 58 echo "Please specify a path" 59 usage 60 fi 61 62 echo "Building flatcc libraries and tool" 63 64 if [[ ! -d "$ROOT/include/flatcc" ]]; then 65 echo "script not located in flatcc project" 66 fi 67 68 if [[ -n "$B" ]]; then 69 $ROOT/scripts/build.sh 70 fi 71 72 echo "Linking flatcc tool and library into $1" 73 74 mkdir -p $DIR/$1 75 cd $DIR/$1 76 77 if [[ -n "$S" ]]; then 78 echo "Copying build script" 79 mkdir -p scripts 80 mkdir -p src 81 cp $ROOT/scripts/_user_build.in scripts/build.sh 82 chmod +x scripts/build.sh 83 fi 84 85 if [[ -n "$X" ]]; then 86 echo "Copying monster sample project" 87 mkdir -p src 88 cp $ROOT/samples/monster/monster.{c,fbs} src 89 fi 90 91 mkdir -p lib 92 mkdir -p bin 93 mkdir -p include 94 95 ln -sf $ROOT/bin/flatcc bin/ 96 ln -sf $ROOT/lib/libflatcc.a lib/ 97 ln -sf $ROOT/lib/libflatccrt.a lib/ 98 ln -sf $ROOT/lib/libflatcc_d.a lib/ 99 ln -sf $ROOT/lib/libflatccrt_d.a lib/ 100 ln -sf $ROOT/include/flatcc include/ 101 102 if [[ -n "$G" ]]; then 103 echo "Updating .gitignore" 104 touch .gitignore 105 grep -q '^bin/flatcc*' .gitignore || echo 'bin/flatcc*' >> .gitignore 106 grep -q '^lib/libflatcc*.a' .gitignore || echo 'lib/libflatcc*.a' >> .gitignore 107 grep -q '^include/flatcc' .gitignore || echo 'include/flatcc' >> .gitignore 108 grep -q '^generated/' .gitignore || echo 'generated/' >> .gitignore 109 if [[ -n "$S" ]]; then 110 grep -q '^build/' .gitignore || echo 'build/' >> .gitignore 111 fi 112 fi