File: qtdeploy.sh

package info (click to toggle)
qbrew 0.4.1-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 1,900 kB
  • sloc: cpp: 7,500; sh: 414; makefile: 13
file content (165 lines) | stat: -rwxr-xr-x 4,618 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/sh
# Copyright 2007-2008 David Johnson
# The author grants unlimited permission to
# copy, distribute and modify this script

# APPNAME=MyApp

### get system configuration ########################################

# as long as we can find qmake, we don't need QTDIR
FWPATH=`qmake -query QT_INSTALL_LIBS`
if [ ! -d $FWPATH/QtGui.framework ] ; then
    echo "ERROR: cannot find the Qt frameworks. Make sure Qt is installed"
    echo "and qmake is in your environment path."
    exit
fi

### get required user input #########################################

if [ -z $APPNAME ] ; then
    echo
    echo "This script prepares a Qt application bundle for deployment. It will"
    echo "copy over the required Qt frameworks and sets the installation"
    echo "identifications. Please see the \"Deploying an Application on Qt/Mac\""
    echo "page in the Qt documentation for more information."
    echo
    echo "This script assumes you have already built the application bundle."
    echo
    echo -n "What is the name of the application? "
    read userinput
    APPNAME=$userinput
fi

BUNDLE=$APPNAME.app
APPBIN="$BUNDLE/Contents/MacOS/$APPNAME"

if [ ! -d $BUNDLE ] ; then
    echo "ERROR: cannot find application bundle \"$BUNDLE\" in current directory"
    exit
fi

if [ ! -x $APPBIN ] ; then
    echo "ERROR: cannot find application in bundle. Did you forget to run make?"
    exit
fi

echo "application: $APPNAME"
echo "bundle:      $BUNDLE"

### query binary for frameworks #####################################

echo -n "Using frameworks"
for n in `otool -L $APPBIN | grep Qt` ; do
    path=`echo $n | grep Qt`
    if [ $path ] ; then
	name=`basename $path`
	FRAMEWORKS="$FRAMEWORKS $path"
	echo -n " $name"
    fi
done
echo

### make install ####################################################

echo "Running make install"
if [ -e Makefile.Release ] ; then
    make -f Makefile.Release install
elif [ -e Makefile ] ; then
    make install
else
    echo "ERROR: Makefile not found. This script requires the macx-g++ makespec"
fi
strip $APPBIN

### copy over frameworks ############################################

mkdir -p $BUNDLE/Contents/Frameworks
for path in $FRAMEWORKS ; do
    name=`basename $path`
    if [ ! -d "$FWPATH/$name.framework" ] ; then
        echo "ERROR: cannot find $FWPATH/$name.framework"
        exit
    fi
    echo "Copying $name framework"
    cp -fR $FWPATH/$name.framework $BUNDLE/Contents/Frameworks
    # strip libs (-x is max allowable for shared libs)
    strip -x $BUNDLE/Contents/Frameworks/$name.framework/Versions/4/$name
done

# remove unwanted parts
find $BUNDLE/Contents/Frameworks | egrep "debug|Headers" | xargs rm -rf

### set the identification names for frameworks #####################

echo -n "Setting framework IDs..."

echo -n "Setting framework IDs..."

for path in $FRAMEWORKS ; do
    name=`basename $path`
    echo -n " $name"
    install_name_tool \
	-id @executable_path/../Frameworks/$name.framework/Versions/4/$name \
        $BUNDLE/Contents/Frameworks/$name.framework/Versions/4/$name
done
echo

### change framework paths ##########################################

echo -n "Changing framework paths for $APPNAME..."
for path in $FRAMEWORKS ; do
    name=`basename $path`
    echo -n " $name"
    install_name_tool \
	-change $path \
        @executable_path/../Frameworks/$name.framework/Versions/4/$name \
        $APPBIN
done
echo

### change location for bundled frameworks #########################

echo -n "Fixing bundled frameworks..."
for fwpath in $FRAMEWORKS ; do
    fwname=`basename $fwpath`
    echo -n " $fwname"
    framework="$BUNDLE/Contents/Frameworks/$fwname.framework/Versions/4/$fwname"
    # get framework dependencies
    deps=""
    for n in `otool -LX $framework | grep Qt` ; do
	dep=`echo $n | grep Qt`
	if [ $dep ] ; then
	    deps="$deps $dep"
	fi
    done
    # fix dependency path
    for path in $deps ; do
	name=`basename $path`
	if [ "$name" != "$fwname" ] ; then
            install_name_tool \
		-change $path \
		@executable_path/../Frameworks/$name.framework/Versions/4/$name \
		$framework
	fi
    done
done
echo

### misc cleanup ###############################################

find $BUNDLE/Contents | egrep "CVS" | xargs rm -rf

### create disk image ###############################################

echo "Creating disk image"
imagedir="/tmp/$APPNAME.$$"
mkdir $imagedir
cp -R $BUNDLE $imagedir

# TODO: copy over additional files, if any
hdiutil create -ov -srcfolder $imagedir -format UDBZ -volname "$APPNAME" "$APPNAME.dmg"
hdiutil internet-enable -yes "$APPNAME.dmg"
rm -rf $imagedir

echo "Done"