1+ #! /bin/bash
2+ 
3+ #  Build script for PNG to ICNS Converter
4+ #  Uses Nuitka to compile the Python application into a macOS .app bundle
5+ 
6+ #  Get the directory where this script is located
7+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " &&  pwd) " 
8+ PROJECT_DIR=" $SCRIPT_DIR " 
9+ 
10+ echo  " Building PNG to ICNS Converter..." 
11+ echo  " Project directory: $PROJECT_DIR " 
12+ 
13+ #  Check if required files exist
14+ if  [ !  -f  " $PROJECT_DIR /gui_converter.py" ;  then 
15+     echo  " Error: gui_converter.py not found in project directory" 
16+     exit  1
17+ fi 
18+ 
19+ if  [ !  -d  " $PROJECT_DIR /support" ;  then 
20+     echo  " Error: support directory not found in project directory" 
21+     exit  1
22+ fi 
23+ 
24+ #  Create build directory
25+ BUILD_DIR=" $PROJECT_DIR /build" 
26+ DIST_DIR=" $PROJECT_DIR /dist" 
27+ 
28+ echo  " Creating build directories..." 
29+ mkdir -p " $BUILD_DIR " 
30+ mkdir -p " $DIST_DIR " 
31+ 
32+ #  Manually download ccache to avoid SSL issues
33+ echo  " Setting up ccache..." 
34+ CCACHE_DIR=" /Users/$USER /Library/Caches/Nuitka/downloads/ccache/v4.2.1" 
35+ CCACHE_ZIP=" $CCACHE_DIR /ccache-4.2.1.zip" 
36+ 
37+ if  [ !  -f  " $CCACHE_ZIP " ;  then 
38+     echo  " Downloading ccache to avoid SSL issues..." 
39+     mkdir -p " $CCACHE_DIR " 
40+     
41+     #  Try to download with curl, ignoring SSL errors
42+     curl -k -L " https://nuitka.net/ccache/v4.2.1/ccache-4.2.1.zip" " $CCACHE_ZIP " 
43+     
44+     if  [ !  -f  " $CCACHE_ZIP " ;  then 
45+         echo  " Failed to download ccache. Continuing without it..." 
46+     else 
47+         echo  " Downloaded ccache successfully." 
48+     fi 
49+ else 
50+     echo  " ccache already downloaded." 
51+ fi 
52+ 
53+ #  Install required dependencies if not already installed
54+ echo  " Checking and installing dependencies..." 
55+ python3.13 -m pip install Pillow nuitka
56+ 
57+ #  Try to determine Python version
58+ PYTHON_VERSION=$( python3.13 --version |  cut -d'  ' |  cut -d' .' ) 
59+ PYTHON_FULL_VERSION=$( python3.13 --version |  cut -d'  ' ) 
60+ echo  " Using Python version: $PYTHON_FULL_VERSION " 
61+ 
62+ #  Build the application using Nuitka with Python 3.13
63+ echo  " Compiling with Nuitka using Python 3.13..." 
64+ 
65+ #  Different approach for different Python versions
66+ BUILD_SUCCESS=0
67+ 
68+ #  Try the recommended approach first
69+ echo  " Trying recommended build approach..." 
70+ python3.13 -m nuitka \
71+     --standalone \
72+     --macos-create-app-bundle \
73+     --macos-app-icon=" $PROJECT_DIR /support/Success.icns" 
74+     --include-data-dir=" $PROJECT_DIR /support=support" 
75+     --enable-plugin=tk-inter \
76+     --output-dir=" $DIST_DIR " 
77+     --remove-output \
78+     " $PROJECT_DIR /gui_converter.py" &&  BUILD_SUCCESS=1
79+ 
80+ #  If that fails, try alternative approaches
81+ if  [ $BUILD_SUCCESS  -eq  0 ];  then 
82+     echo  " First approach failed. Trying alternative build approach..." 
83+     
84+     #  Try without --remove-output
85+     python3.13 -m nuitka \
86+         --standalone \
87+         --macos-create-app-bundle \
88+         --macos-app-icon=" $PROJECT_DIR /support/Success.icns" 
89+         --include-data-dir=" $PROJECT_DIR /support=support" 
90+         --enable-plugin=tk-inter \
91+         --output-dir=" $DIST_DIR " 
92+         " $PROJECT_DIR /gui_converter.py" &&  BUILD_SUCCESS=1
93+ fi 
94+ 
95+ if  [ $BUILD_SUCCESS  -eq  0 ];  then 
96+     echo  " Second approach failed. Trying minimal build approach..." 
97+     
98+     #  Try minimal approach
99+     python3.13 -m nuitka \
100+         --standalone \
101+         --macos-create-app-bundle \
102+         --include-data-dir=" $PROJECT_DIR /support=support" 
103+         --enable-plugin=tk-inter \
104+         --output-dir=" $DIST_DIR " 
105+         " $PROJECT_DIR /gui_converter.py" &&  BUILD_SUCCESS=1
106+ fi 
107+ 
108+ if  [ $BUILD_SUCCESS  -eq  0 ];  then 
109+     echo  " All Nuitka approaches failed. Creating a simple application bundle instead..." 
110+     
111+     #  Create a simple app bundle structure
112+     APP_DIR=" $DIST_DIR /PNG to ICNS Converter.app" 
113+     CONTENTS_DIR=" $APP_DIR /Contents" 
114+     MACOS_DIR=" $CONTENTS_DIR /MacOS" 
115+     RESOURCES_DIR=" $CONTENTS_DIR /Resources" 
116+     
117+     echo  " Creating simple app bundle structure..." 
118+     mkdir -p " $MACOS_DIR " 
119+     mkdir -p " $RESOURCES_DIR " 
120+     
121+     #  Copy required files
122+     echo  " Copying application files..." 
123+     cp -r " $PROJECT_DIR /support" " $RESOURCES_DIR /" 
124+     cp " $PROJECT_DIR /gui_converter.py" " $RESOURCES_DIR /" 
125+     
126+     #  Create a simple launcher script
127+     LAUNCHER_SCRIPT=" $MACOS_DIR /png_to_icns_converter" 
128+     echo  " #!/bin/bash" >  " $LAUNCHER_SCRIPT " 
129+     echo  " cd \"\$ (dirname \"\$ 0\" )/../Resources\"  || exit 1" >>  " $LAUNCHER_SCRIPT " 
130+     echo  " python3.13 gui_converter.py" >>  " $LAUNCHER_SCRIPT " 
131+     chmod +x " $LAUNCHER_SCRIPT " 
132+     
133+     #  Create Info.plist
134+     cat >  " $CONTENTS_DIR /Info.plist" <<  EOF 
135+ <?xml version="1.0" encoding="UTF-8"?> 
136+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
137+ <plist version="1.0"> 
138+ <dict> 
139+     <key>CFBundleExecutable</key> 
140+     <string>png_to_icns_converter</string> 
141+     <key>CFBundleIdentifier</key> 
142+     <string>com.png.icns.converter</string> 
143+     <key>CFBundleName</key> 
144+     <string>PNG to ICNS Converter</string> 
145+     <key>CFBundleIconFile</key> 
146+     <string>Success.icns</string> 
147+     <key>CFBundleInfoDictionaryVersion</key> 
148+     <string>6.0</string> 
149+     <key>CFBundlePackageType</key> 
150+     <string>APPL</string> 
151+     <key>CFBundleShortVersionString</key> 
152+     <string>1.0</string> 
153+     <key>CFBundleVersion</key> 
154+     <string>1.0</string> 
155+     <key>LSMinimumSystemVersion</key> 
156+     <string>10.13.0</string> 
157+ </dict> 
158+ </plist> 
159+ EOF 
160+     
161+     #  Copy the icon
162+     if  [ -f  " $PROJECT_DIR /support/Success.icns" ;  then 
163+         cp " $PROJECT_DIR /support/Success.icns" " $RESOURCES_DIR /" 
164+     fi 
165+     
166+     BUILD_SUCCESS=1
167+     echo  " Simple app bundle created at: $APP_DIR " 
168+ fi 
169+ 
170+ #  Check if build was successful
171+ if  [ $BUILD_SUCCESS  -eq  1 ];  then 
172+     if  ls " $DIST_DIR " * .app 1>  /dev/null 2>&1 ;  then 
173+         APP_NAME=$( ls " $DIST_DIR " * .app |  head -n 1) 
174+         echo  " Build successful!" 
175+         echo  " Application created at: $APP_NAME " 
176+         
177+         #  Show app bundle information
178+         echo  " Application information:" 
179+         ls -lh " $APP_NAME " 
180+         
181+         echo  " " 
182+         echo  " To run the application, double-click on the app in Finder" 
183+         echo  " or run the following command in terminal:" 
184+         echo  " open '$APP_NAME '" 
185+     else 
186+         echo  " Build process completed." 
187+         echo  " You can run the application using the launcher script:" 
188+         echo  " ./PNG_to_ICNS_Converter.command" 
189+     fi 
190+ else 
191+     echo  " Build failed with all approaches!" 
192+     echo  " Recommendations:" 
193+     echo  " 1. Run the application directly with Python 3.13:" 
194+     echo  "    python3.13 gui_converter.py" 
195+     echo  " 2. Use the simple launcher script:" 
196+     echo  "    ./PNG_to_ICNS_Converter.command" 
197+     exit  1
198+ fi 
0 commit comments