Merge pull request #438 from s4Ys369/revert-434-patch-1
[sm64pc.git] / build.sh
blob040860beb613b1c73484e40dcbb25be07d3b516c
1 #!/bin/bash
3 # Directories and Files
4 LIBDIR=./tools/lib/
5 LIBAFA=libaudiofile.a
6 LIBAFLA=libaudiofile.la
7 AUDDIR=./tools/audiofile-0.3.6
9 # Command line options
10 OPTIONS=("Analog Camera" "No Draw Distance" "Text-saves" "Smoke Texture Fix" "Release build" "Clean build")
11 EXTRA=("BETTERCAMERA=1" "NODRAWINGDISTANCE=1" "TEXTSAVES=1" "TEXTURE_FIX=1" "DEBUG=0" "clean")
13 # Colors
14 RED=$(tput setaf 1)
15 GREEN=$(tput setaf 2)
16 YELLOW=$(tput setaf 3)
17 CYAN=$(tput setaf 6)
18 RESET=$(tput sgr0)
20 # Checks to see if the libaudio directory and files exist
21 if [ -d "$LIBDIR" -a -e "${LIBDIR}$LIBAFA" -a -e "${LIBDIR}$LIBAFLA" ]; then
22 printf "\n${GREEN}libaudio files exist, going straight to compiling.${RESET}\n"
23 else
24 printf "\n${GREEN}libaudio files not found, starting initialization process.${RESET}\n\n"
26 printf "${YELLOW} Changing directory to: ${CYAN}${AUDDIR}${RESET}\n\n"
27 cd $AUDDIR
29 printf "${YELLOW} Executing: ${CYAN}autoreconf -i${RESET}\n\n"
30 autoreconf -i
32 printf "\n${YELLOW} Executing: ${CYAN}./configure --disable-docs${RESET}\n\n"
33 PATH=/mingw64/bin:/mingw32/bin:$PATH LIBS=-lstdc++ ./configure --disable-docs
35 printf "\n${YELLOW} Executing: ${CYAN}make -j${RESET}\n\n"
36 PATH=/mingw64/bin:/mingw32/bin:$PATH make -j
38 printf "\n${YELLOW} Making new directory ${CYAN}../lib${RESET}\n\n"
39 mkdir ../lib
42 printf "${YELLOW} Copying libaudio files to ${CYAN}../lib${RESET}\n\n"
43 cp libaudiofile/.libs/libaudiofile.a ../lib/
44 cp libaudiofile/.libs/libaudiofile.la ../lib/
46 printf "${YELLOW} Going up one directory.${RESET}\n\n"
47 cd ../
49 printf "${GREEN}Notepad will now open, please follow the instructions carefully.\n\n"
50 printf "${YELLOW}Locate the line: "
51 printf "${CYAN}tabledesign_CFLAGS := -Wno-uninitialized -laudiofile\n"
52 printf "${YELLOW}Then add at the end: ${CYAN}-lstdc++\n"
53 printf "${YELLOW}So it reads: "
54 printf "${CYAN}tabledesign_CFLAGS := -Wno-uninitialized -laudiofile -lstdc++\n\n"
55 notepad "Makefile"
56 read -n 1 -r -s -p $'\e[32mPRESS ENTER TO CONTINUE...\e[0m\n'
58 printf "${YELLOW} Executing: ${CYAN}make -j${RESET}\n\n"
59 PATH=/mingw64/bin:/mingw32/bin:$PATH make -j
61 printf "\n${YELLOW} Going up one directory.${RESET}\n"
62 cd ../
63 fi
65 menu() {
66 printf "\nAvaliable options:\n"
67 for i in ${!OPTIONS[@]}; do
68 printf "%3d%s) %s\n" $((i+1)) "${choices[i]:- }" "${OPTIONS[i]}"
69 done
70 if [[ "$msg" ]]; then echo "$msg"; fi
71 printf "${YELLOW}Please do not select \"Clean build\" with any other option.\n"
72 printf "Leave all options unchecked for a Vanilla build.\n${RESET}"
75 prompt="Check an option (again to uncheck, press ENTER):"
76 while menu && read -rp "$prompt" num && [[ "$num" ]]; do
77 [[ "$num" != *[![:digit:]]* ]] &&
78 (( num > 0 && num <= ${#OPTIONS[@]} )) ||
79 { msg="Invalid option: $num"; continue; }
80 ((num--)); # msg="${OPTIONS[num]} was ${choices[num]:+un}checked"
81 [[ "${choices[num]}" ]] && choices[num]="" || choices[num]="+"
82 done
84 for i in ${!OPTIONS[@]}; do
85 [[ "${choices[i]}" ]] && { CMDL+=" ${EXTRA[i]}"; }
86 done
88 printf "\n${YELLOW} Executing: ${CYAN}make ${CMDL} -j${RESET}\n\n"
89 PATH=/mingw32/bin:/mingw64/bin:$PATH make $CMDL -j
91 if [ "${CMDL}" != " clean" ]; then
93 printf "\n${GREEN}If all went well you should have a compiled .EXE in the 'builds/us_pc/' folder.\n"
94 printf "${CYAN}Would you like to run the game? [y or n]: ${RESET}"
95 read TEST
97 if [ "${TEST}" = "y" ]; then
98 exec ./build/us_pc/sm64.us.f3dex2e.exe
99 fi
100 else
101 printf "\nYour build is now clean\n"