Austin Schuh | 8c794d5 | 2019-03-03 21:17:37 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # File : cimg_buildpackage |
| 4 | # ( Bash script ) |
| 5 | # |
| 6 | # Description : Build .zip package file of the CImg Library, from the current CImg/ |
| 7 | # directory. Must be run from ../CImg |
| 8 | # This file is a part of the CImg Library project. |
| 9 | # ( http://gmic.eu/CImg ) |
| 10 | # |
| 11 | # Usage : ./cimg_buildpackage [final] |
| 12 | # |
| 13 | # Copyright : David Tschumperle |
| 14 | # ( http://tschumperle.users.greyc.fr/ ) |
| 15 | # |
| 16 | # License : CeCILL v2.0 |
| 17 | # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) |
| 18 | # |
| 19 | # This software is governed by the CeCILL license under French law and |
| 20 | # abiding by the rules of distribution of free software. You can use, |
| 21 | # modify and/ or redistribute the software under the terms of the CeCILL |
| 22 | # license as circulated by CEA, CNRS and INRIA at the following URL |
| 23 | # "http://www.cecill.info". |
| 24 | # |
| 25 | # As a counterpart to the access to the source code and rights to copy, |
| 26 | # modify and redistribute granted by the license, users are provided only |
| 27 | # with a limited warranty and the software's author, the holder of the |
| 28 | # economic rights, and the successive licensors have only limited |
| 29 | # liability. |
| 30 | # |
| 31 | # In this respect, the user's attention is drawn to the risks associated |
| 32 | # with loading, using, modifying and/or developing or reproducing the |
| 33 | # software by the user in light of its specific status of free software, |
| 34 | # that may mean that it is complicated to manipulate, and that also |
| 35 | # therefore means that it is reserved for developers and experienced |
| 36 | # professionals having in-depth computer knowledge. Users are therefore |
| 37 | # encouraged to load and test the software's suitability as regards their |
| 38 | # requirements in conditions enabling the security of their systems and/or |
| 39 | # data to be ensured and, more generally, to use and operate it in the |
| 40 | # same conditions as regards security. |
| 41 | # |
| 42 | # The fact that you are presently reading this means that you have had |
| 43 | # knowledge of the CeCILL license and that you accept its terms. |
| 44 | # |
| 45 | |
| 46 | # Define release number. |
| 47 | RELEASE0=`grep "#define cimg_version" CImg/CImg.h | tail -c 4` |
| 48 | RELEASE1=`echo $RELEASE0 | head -c 1` |
| 49 | RELEASE2=`echo $RELEASE0 | head -c 2 | tail -c 1` |
| 50 | RELEASE3=`echo $RELEASE0 | head -c 3 | tail -c 1` |
| 51 | VERSION=${RELEASE1}${RELEASE2}${RELEASE3} |
| 52 | SVERSION=${RELEASE1}.${RELEASE2}.${RELEASE3} |
| 53 | |
| 54 | # Read command line options. |
| 55 | if [ "$1" == "final" ]; then SUFFIX=""; SSUFFIX=""; else SUFFIX=_pre`date +%m%d%y`; SSUFFIX=_pre; fi |
| 56 | |
| 57 | # Define the different paths and filenames used in this script. |
| 58 | BASE_DIR=`pwd` |
| 59 | SRC_DIR=${BASE_DIR}/CImg |
| 60 | DEST_DIR=/tmp/CImg-${SVERSION}${SUFFIX} |
| 61 | ZIP_FILE=CImg_${SVERSION}${SSUFFIX}.zip |
| 62 | LOG_FILE=${BASE_DIR}/LOG_`basename $ZIP_FILE .zip`.txt |
| 63 | rm -rf $LOG_FILE |
| 64 | |
| 65 | echo |
| 66 | echo " - Release number : $SVERSION$SUFFIX" |
| 67 | echo " - Base directory : $BASE_DIR/" |
| 68 | echo " - Source directory : $SRC_DIR/" |
| 69 | echo " - Build directory : $DEST_DIR/" |
| 70 | echo " - ZIP package filename : $ZIP_FILE" |
| 71 | echo " - LOG file : $LOG_FILE" |
| 72 | |
| 73 | # Create clean archive structure. |
| 74 | echo " - Create package structure." |
| 75 | rm -rf $DEST_DIR |
| 76 | mkdir $DEST_DIR |
| 77 | cd $SRC_DIR |
| 78 | cp -f CImg.h Licence_CeCILL-C_V1-en.txt Licence_CeCILL_V2-en.txt $DEST_DIR |
| 79 | sed s\/_cimg_version\/$SVERSION$SUFFIX\/ README.txt > $DEST_DIR/README.txt |
| 80 | |
| 81 | mkdir $DEST_DIR/examples |
| 82 | cd $SRC_DIR/examples |
| 83 | cp -f *.cpp *.m CMakeLists.txt Makefile $DEST_DIR/examples/ |
| 84 | |
| 85 | mkdir $DEST_DIR/examples/img |
| 86 | cd $SRC_DIR/examples/img |
| 87 | cp -f *.pgm *.ppm *.bmp *.h $DEST_DIR/examples/img/ |
| 88 | |
| 89 | mkdir $DEST_DIR/plugins |
| 90 | cd $SRC_DIR/plugins |
| 91 | cp -f *.h $DEST_DIR/plugins/ |
| 92 | |
| 93 | mkdir $DEST_DIR/resources |
| 94 | cd $SRC_DIR/resources |
| 95 | cp -rf *.bat $DEST_DIR/resources/ |
| 96 | |
| 97 | cd $DEST_DIR |
| 98 | for i in CImg.h examples/*.cpp; do |
| 99 | sed -e 's/ *$//' $i >/tmp/cimg_buildpackage$$ && mv /tmp/cimg_buildpackage$$ $i |
| 100 | done |
| 101 | for i in `find . -name "\#*"`; do rm -rf $i; done |
| 102 | for i in `find . -name "*~"`; do rm -rf $i; done |
| 103 | for i in `find . -name "core*"`; do rm -rf $i; done |
| 104 | for i in `find . -name "CVS"`; do rm -rf $i; done |
| 105 | for i in `find . -name ".git"`; do rm -rf $i; done |
| 106 | for i in `find . -name "*.plg"`; do rm -rf $i; done |
| 107 | for i in `find . -name "*.ncb"`; do rm -rf $i; done |
| 108 | for i in `find . -name "*.layout"`; do rm -rf $i; done |
| 109 | for i in `find . -name "*.win"`; do rm -rf $i; done |
| 110 | for i in `find . -name "Debug"`; do rm -rf $i; done |
| 111 | for i in `find . -name "Release"`; do rm -rf $i; done |
| 112 | for i in `find . -name "*.h"`; do col -x <$i >tmp; mv tmp $i; done |
| 113 | for i in `find . -name "*.cpp"`; do col -x <$i >tmp; mv tmp $i; done |
| 114 | for i in `find . ! -type d`; do chmod a-x $i; done |
| 115 | for i in `find . -name "*.sh"`; do chmod a+x $i; done |
| 116 | for i in `find . -name "rules"`; do chmod a+x $i; done |
| 117 | |
| 118 | # Generate Documentation with doxygen |
| 119 | echo " - Generate reference documentation using Doxygen." |
| 120 | cd $SRC_DIR/html |
| 121 | |
| 122 | if [ "$1" == "final" ]; then |
| 123 | gmic _update_header_html header.html,${VERSION},0 |
| 124 | gmic _update_header_html header_reference.html,${VERSION},0 |
| 125 | else |
| 126 | gmic _update_header_html header.html,${VERSION},1 |
| 127 | gmic _update_header_html header_reference.html,${VERSION},1 |
| 128 | fi |
| 129 | |
| 130 | echo -e "\n** Log generated by 'doxygen' **\n\n">>$LOG_FILE |
| 131 | ( cat CImg.doxygen ; echo "PROJECT_NUMBER=$SVERSION$SUFFIX" ) | doxygen - >>$LOG_FILE 2>&1 |
| 132 | |
| 133 | echo " - Build reference documentation in PDF format." |
| 134 | cd $SRC_DIR/html/latex |
| 135 | echo -e "\n** Log generated by 'latex' **\n\n">>$LOG_FILE |
| 136 | make>>$LOG_FILE 2>&1 |
| 137 | cp -f refman.pdf ../CImg_reference.pdf |
| 138 | cp -f refman.pdf $DEST_DIR/resources/CImg_reference.pdf |
| 139 | rm -rf ../latex |
| 140 | |
| 141 | # Commit changes on GIT repository |
| 142 | echo " - Commit on GIT repository." |
| 143 | cd $SRC_DIR |
| 144 | if [ "$1" == "final" ]; then |
| 145 | git tag -d v.$SVERSION |
| 146 | git tag v.$SVERSION |
| 147 | git commit -m "Final release "${SVERSION} >>$LOG_FILE 2>&1 |
| 148 | else |
| 149 | git commit -m "Auto-commit for release "${SVERSION}${SUFFIX} >>$LOG_FILE 2>&1 |
| 150 | fi |
| 151 | git push --tags |
| 152 | |
| 153 | # Create ZIP archive |
| 154 | echo " - Build ZIP archive file '$ZIP_FILE'." |
| 155 | cd $DEST_DIR/.. |
| 156 | rm -f $ZIP_FILE |
| 157 | echo -e "\n** Log generated by 'zip' **\n\n">>$LOG_FILE |
| 158 | zip -r -9 $ZIP_FILE `basename $DEST_DIR`>>$LOG_FILE 2>&1 |
| 159 | |
| 160 | # Clean temporary files and directories |
| 161 | echo " - Clean temporary files and directories." |
| 162 | cd $DEST_DIR/.. |
| 163 | mv $ZIP_FILE $BASE_DIR |
| 164 | |
| 165 | # Copy files to CImg server. |
| 166 | cd $BASE_DIR |
| 167 | if [ "$1" == "final" ]; then |
| 168 | lftp ftp://$GMIC_LOGIN:$GMIC_PASSWD@ftp.gmic.eu -e "put -O /www/CImg/files/ ${ZIP_FILE}; quit"; |
| 169 | fi |
| 170 | lftp ftp://$GMIC_LOGIN:$GMIC_PASSWD@ftp.gmic.eu -e "put -O /www/CImg/files/ ${ZIP_FILE} -o CImg_latest.zip; quit" |
| 171 | |
| 172 | cd $SRC_DIR/html/ |
| 173 | lftp ftp://$GMIC_LOGIN:$GMIC_PASSWD@ftp.gmic.eu -e "mirror -RL . /www/CImg/ ; quit" |
| 174 | |
| 175 | # End of build script |
| 176 | echo -e " - All done, you should look at the LOG file '$LOG_FILE'.\n" |