| 1 | #!/bin/bash |
| 2 | |
| 3 | # Build script for facsimile editor |
| 4 | # Provides parity between fpm and Makefile builds |
| 5 | |
| 6 | # Colors for output |
| 7 | RED='\033[0;31m' |
| 8 | GREEN='\033[0;32m' |
| 9 | BLUE='\033[0;34m' |
| 10 | NC='\033[0m' # No Color |
| 11 | |
| 12 | # Default build type |
| 13 | BUILD_TYPE=${1:-release} |
| 14 | |
| 15 | echo -e "${BLUE}Building facsimile editor (${BUILD_TYPE})...${NC}" |
| 16 | |
| 17 | # Check if fpm is available |
| 18 | if command -v fpm &> /dev/null; then |
| 19 | echo -e "${GREEN}Using fpm build system${NC}" |
| 20 | |
| 21 | case "$BUILD_TYPE" in |
| 22 | debug) |
| 23 | fpm build --flag "-g -Wall -ffree-line-length-none -fbacktrace -fcheck=bounds" |
| 24 | BINARY="./build/gfortran_*/app/fac" |
| 25 | ;; |
| 26 | release) |
| 27 | # Use same flags as Makefile for optimization parity |
| 28 | fpm build --flag "-O2 -Wall -ffree-line-length-none" |
| 29 | BINARY="./build/gfortran_*/app/fac" |
| 30 | ;; |
| 31 | clean) |
| 32 | fpm clean |
| 33 | exit 0 |
| 34 | ;; |
| 35 | *) |
| 36 | echo -e "${RED}Unknown build type: ${BUILD_TYPE}${NC}" |
| 37 | echo "Usage: $0 [debug|release|clean]" |
| 38 | exit 1 |
| 39 | ;; |
| 40 | esac |
| 41 | |
| 42 | # Show location of built binary |
| 43 | echo -e "${GREEN}Build complete!${NC}" |
| 44 | echo -e "Binary location: ${BINARY}" |
| 45 | echo -e "To install: cp ${BINARY} /usr/local/bin/fac" |
| 46 | |
| 47 | elif [ -f "Makefile" ]; then |
| 48 | echo -e "${GREEN}Using Makefile build system${NC}" |
| 49 | |
| 50 | case "$BUILD_TYPE" in |
| 51 | debug) |
| 52 | echo -e "${RED}Debug build not configured in Makefile${NC}" |
| 53 | echo "Edit FFLAGS in Makefile to add debug flags" |
| 54 | exit 1 |
| 55 | ;; |
| 56 | release) |
| 57 | make clean && make |
| 58 | BINARY="./fac" |
| 59 | ;; |
| 60 | clean) |
| 61 | make clean |
| 62 | exit 0 |
| 63 | ;; |
| 64 | *) |
| 65 | echo -e "${RED}Unknown build type: ${BUILD_TYPE}${NC}" |
| 66 | echo "Usage: $0 [debug|release|clean]" |
| 67 | exit 1 |
| 68 | ;; |
| 69 | esac |
| 70 | |
| 71 | # Show location of built binary |
| 72 | echo -e "${GREEN}Build complete!${NC}" |
| 73 | echo -e "Binary location: ${BINARY}" |
| 74 | echo -e "To install: cp ${BINARY} /usr/local/bin/" |
| 75 | |
| 76 | else |
| 77 | echo -e "${RED}No build system found!${NC}" |
| 78 | echo "Please install fpm or ensure Makefile is present" |
| 79 | exit 1 |
| 80 | fi |