2017-02-25 00:53:17 +03:00
package templater
import (
"bytes"
"fmt"
2017-03-11 00:54:09 +03:00
"go/format"
2017-02-25 00:53:17 +03:00
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"github.com/therecipe/qt/internal/binding/parser"
"github.com/therecipe/qt/internal/utils"
)
2017-02-27 00:03:27 +03:00
const (
NONE = iota
MOC
MINIMAL
RCC
)
2017-02-25 00:53:17 +03:00
2017-05-16 01:06:35 +03:00
func CgoTemplate ( module , path , target string , mode int , ipkg , tags string ) ( o string ) {
2017-03-11 00:54:09 +03:00
utils . Log . WithField ( "module" , module ) . WithField ( "path" , path ) . WithField ( "target" , target ) . WithField ( "mode" , mode ) . WithField ( "pkg" , ipkg )
2017-02-25 00:53:17 +03:00
switch module {
case "AndroidExtras" :
2017-04-17 20:21:21 +03:00
if ! ( target == "android" || target == "android-emulator" ) {
2017-02-27 00:03:27 +03:00
return
2017-02-25 00:53:17 +03:00
}
case "Sailfish" :
2017-02-27 00:03:27 +03:00
if ! strings . HasPrefix ( target , "sailfish" ) {
return
2017-02-25 00:53:17 +03:00
}
}
2017-02-27 00:03:27 +03:00
if path == "" {
path = utils . GoQtPkgPath ( strings . ToLower ( module ) )
2017-02-25 00:53:17 +03:00
}
2017-03-16 22:18:32 +03:00
//TODO:
if ! ( target == "sailfish" || target == "sailfish-emulator" ) {
if ! parser . ShouldBuildForTarget ( module , target ) ||
isAlreadyCached ( module , path , target , mode ) {
utils . Log . Debugf ( "skipping cgo generation" )
return
}
2017-03-02 21:24:25 +03:00
}
2017-03-11 00:54:09 +03:00
switch target {
case "sailfish" , "sailfish-emulator" :
cgoSailfish ( module , path , mode , ipkg ) //TODO:
case "asteroid" :
cgoAsteroid ( module , path , mode , ipkg ) //TODO:
default :
2017-03-17 23:36:32 +03:00
createProject ( module , path , target , mode )
2017-03-11 00:54:09 +03:00
createMakefile ( module , path , target , mode )
2017-05-16 01:06:35 +03:00
createCgo ( module , path , target , mode , ipkg , tags )
2017-03-11 00:54:09 +03:00
}
2017-02-27 00:03:27 +03:00
2017-02-25 00:53:17 +03:00
utils . RemoveAll ( filepath . Join ( path , "Makefile" ) )
utils . RemoveAll ( filepath . Join ( path , "Makefile.Release" ) )
2017-02-27 00:03:27 +03:00
return
}
2017-02-25 00:53:17 +03:00
2017-03-17 23:36:32 +03:00
//TODO: use qmake props ?
2017-03-02 21:24:25 +03:00
func isAlreadyCached ( module , path , target string , mode int ) bool {
for _ , file := range cgoFileNames ( module , path , target , mode ) {
file = filepath . Join ( path , file )
if utils . ExistsFile ( file ) {
2017-03-11 00:54:09 +03:00
file = utils . Load ( file )
2017-03-20 20:33:55 +03:00
for _ , dep := range parser . LibDeps [ module ] {
if ! strings . Contains ( strings . ToLower ( file ) , strings . ToLower ( dep ) ) {
2017-03-23 02:45:45 +03:00
utils . Log . Debugln ( "cgo does not contain:" , strings . ToLower ( dep ) )
2017-03-20 20:33:55 +03:00
return false
}
}
2017-05-18 01:17:02 +03:00
if utils . QT_DEBUG_QML ( ) {
if strings . Contains ( file , "-DQT_NO_DEBUG" ) {
utils . Log . Debugln ( "non debug cgo file, re-creating ..." )
return false
}
} else {
if strings . Contains ( file , "-DQT_QML_DEBUG" ) || strings . Contains ( file , "-DQT_DECLARATIVE_DEBUG" ) {
utils . Log . Debugln ( "non release cgo file, re-creating ..." )
return false
}
}
2017-03-02 21:24:25 +03:00
switch target {
case "darwin" , "linux" , "windows" :
//TODO msys pkg-config mxe brew
2017-03-11 00:54:09 +03:00
return strings . Contains ( file , utils . QT_DIR ( ) ) || strings . Contains ( file , utils . QT_DARWIN_DIR ( ) ) ||
strings . Contains ( file , utils . QT_MSYS2_DIR ( ) ) || strings . Contains ( file , utils . QT_MXE_TRIPLET ( ) )
2017-04-17 20:21:21 +03:00
case "android" , "android-emulator" :
2017-03-11 00:54:09 +03:00
return strings . Contains ( file , utils . QT_DIR ( ) ) && strings . Contains ( file , utils . ANDROID_NDK_DIR ( ) )
2017-03-02 21:24:25 +03:00
case "ios" , "ios-simulator" :
2017-03-11 00:54:09 +03:00
return strings . Contains ( file , utils . QT_DIR ( ) ) || strings . Contains ( file , utils . QT_DARWIN_DIR ( ) )
2017-03-02 21:24:25 +03:00
case "sailfish" , "sailfish-emulator" , "asteroid" :
case "rpi1" , "rpi2" , "rpi3" :
2017-03-17 23:36:32 +03:00
return strings . Contains ( file , strings . TrimSpace ( utils . RunCmd ( exec . Command ( utils . ToolPath ( "qmake" , target ) , "-query" , "QT_INSTALL_LIBS" ) , fmt . Sprintf ( "query lib path for %v on %v" , target , runtime . GOOS ) ) ) )
2017-03-02 21:24:25 +03:00
}
}
}
return false
}
2017-03-17 23:36:32 +03:00
func createProject ( module , path , target string , mode int ) {
2017-02-27 00:03:27 +03:00
var out [ ] string
2017-02-25 00:53:17 +03:00
2017-02-27 00:03:27 +03:00
switch {
case mode == RCC :
out = [ ] string { "Core" }
case mode == MOC , module == "build_ios" :
out = parser . LibDeps [ module ]
case mode == MINIMAL , mode == NONE :
out = append ( [ ] string { module } , parser . LibDeps [ module ] ... )
2017-02-25 00:53:17 +03:00
}
2017-03-17 23:36:32 +03:00
if strings . HasPrefix ( target , "rpi" ) && module == "Core" {
out = append ( [ ] string { module } , [ ] string { "Widgets" , "Gui" } ... )
}
2017-02-25 00:53:17 +03:00
for i , v := range out {
if v == "Speech" {
out [ i ] = "TextToSpeech"
}
2017-02-27 00:03:27 +03:00
out [ i ] = strings . ToLower ( out [ i ] )
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
utils . Save ( filepath . Join ( path , ".." , fmt . Sprintf ( "%v.pro" , strings . ToLower ( module ) ) ) , fmt . Sprintf ( "QT += %v" , strings . Join ( out , " " ) ) )
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
func createMakefile ( module , path , target string , mode int ) {
2017-03-04 21:01:53 +03:00
cmd := exec . Command ( utils . ToolPath ( "qmake" , target ) , filepath . Join ( path , ".." , fmt . Sprintf ( "%v.pro" , strings . ToLower ( module ) ) ) )
2017-02-27 00:03:27 +03:00
cmd . Dir = path
switch target {
case "darwin" :
cmd . Args = append ( cmd . Args , [ ] string { "-spec" , "macx-clang" , "CONFIG+=x86_64" } ... )
case "windows" :
cmd . Args = append ( cmd . Args , [ ] string { "-spec" , "win32-g++" } ... )
case "linux" :
cmd . Args = append ( cmd . Args , [ ] string { "-spec" , "linux-g++" } ... )
case "ios" :
2017-05-18 01:17:02 +03:00
cmd . Args = append ( cmd . Args , [ ] string { "-spec" , "macx-ios-clang" , "CONFIG+=iphoneos" , "CONFIG+=device" } ... )
2017-02-27 00:03:27 +03:00
case "ios-simulator" :
2017-05-18 01:17:02 +03:00
cmd . Args = append ( cmd . Args , [ ] string { "-spec" , "macx-ios-clang" , "CONFIG+=iphonesimulator" , "CONFIG+=simulator" } ... )
2017-04-17 20:21:21 +03:00
case "android" , "android-emulator" :
2017-02-27 00:03:27 +03:00
cmd . Args = append ( cmd . Args , [ ] string { "-spec" , "android-g++" } ... )
2017-03-04 21:01:53 +03:00
cmd . Env = [ ] string { fmt . Sprintf ( "ANDROID_NDK_ROOT=%v" , utils . ANDROID_NDK_DIR ( ) ) }
2017-02-25 00:53:17 +03:00
case "sailfish" , "sailfish-emulator" :
2017-02-27 00:03:27 +03:00
cmd . Args = append ( cmd . Args , [ ] string { "-spec" , "linux-g++" } ... )
cmd . Env = [ ] string {
"MER_SSH_PORT=2222" ,
fmt . Sprintf ( "MER_SSH_PRIVATE_KEY=%v" , filepath . Join ( utils . SAILFISH_DIR ( ) , "vmshare" , "ssh" , "private_keys" , "engine" , "mersdk" ) ) ,
fmt . Sprintf ( "MER_SSH_PROJECT_PATH=%v" , cmd . Dir ) ,
fmt . Sprintf ( "MER_SSH_SDK_TOOLS=%v/.config/SailfishOS-SDK/mer-sdk-tools/MerSDK/SailfishOS-armv7hl" , os . Getenv ( "HOME" ) ) ,
fmt . Sprintf ( "MER_SSH_SHARED_HOME=%v" , os . Getenv ( "HOME" ) ) ,
fmt . Sprintf ( "MER_SSH_SHARED_SRC=%v" , utils . MustGoPath ( ) ) ,
"MER_SSH_SHARED_TARGET=/opt/SailfishOS/mersdk/targets" ,
"MER_SSH_TARGET_NAME=SailfishOS-armv7hl" ,
"MER_SSH_USERNAME=mersdk" ,
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
case "asteroid" :
2017-03-17 23:36:32 +03:00
case "rpi1" :
cmd . Args = append ( cmd . Args , [ ] string { "-spec" , "devices/linux-rasp-pi-g++" } ... )
case "rpi2" :
cmd . Args = append ( cmd . Args , [ ] string { "-spec" , "devices/linux-rasp-pi2-g++" } ... )
case "rpi3" :
cmd . Args = append ( cmd . Args , [ ] string { "-spec" , "devices/linux-rpi3-g++" } ... )
2017-02-25 00:53:17 +03:00
}
2017-05-18 01:17:02 +03:00
if utils . QT_DEBUG_QML ( ) {
cmd . Args = append ( cmd . Args , [ ] string { "CONFIG+=debug" , "CONFIG+=declarative_debug" , "CONFIG+=qml_debug" } ... )
} else {
cmd . Args = append ( cmd . Args , "CONFIG+=release" )
}
2017-04-17 20:21:21 +03:00
if ( target == "android" || target == "android-emulator" ) && runtime . GOOS == "windows" {
2017-03-02 21:24:25 +03:00
//TODO: -->
2017-04-12 19:55:56 +03:00
utils . SaveExec ( filepath . Join ( cmd . Dir , "qmake.bat" ) , fmt . Sprintf ( "set ANDROID_NDK_ROOT=%v\r\n%v" , utils . ANDROID_NDK_DIR ( ) , strings . Join ( cmd . Args , " " ) ) )
2017-03-02 21:24:25 +03:00
cmd = exec . Command ( ".\\qmake.bat" )
cmd . Dir = path
utils . RunCmdOptional ( cmd , fmt . Sprintf ( "run qmake for %v on %v" , target , runtime . GOOS ) )
utils . RemoveAll ( filepath . Join ( cmd . Dir , "qmake.bat" ) )
//<--
} else {
utils . RunCmdOptional ( cmd , fmt . Sprintf ( "run qmake for %v on %v" , target , runtime . GOOS ) )
}
2017-02-25 00:53:17 +03:00
2017-02-27 00:03:27 +03:00
utils . RemoveAll ( filepath . Join ( path , ".." , fmt . Sprintf ( "%v.pro" , strings . ToLower ( module ) ) ) )
utils . RemoveAll ( filepath . Join ( path , ".qmake.stash" ) )
switch target {
case "darwin" :
case "windows" :
for _ , suf := range [ ] string { "_plugin_import" , "_qml_plugin_import" } {
2017-03-04 21:01:53 +03:00
pPath := filepath . Join ( path , fmt . Sprintf ( "%v%v.cpp" , strings . ToLower ( module ) , suf ) )
2017-04-05 22:49:26 +03:00
if ( utils . QT_MXE_STATIC ( ) || utils . QT_MSYS2_STATIC ( ) ) && utils . ExistsFile ( pPath ) {
2017-02-27 00:03:27 +03:00
if content := utils . Load ( pPath ) ; ! strings . Contains ( content , "+build windows" ) {
utils . Save ( pPath , "// +build windows\n" + content )
2017-02-25 00:53:17 +03:00
}
}
2017-04-05 22:49:26 +03:00
if mode == MOC || mode == RCC || ! ( utils . QT_MXE_STATIC ( ) || utils . QT_MSYS2_STATIC ( ) ) {
2017-02-27 00:03:27 +03:00
utils . RemoveAll ( pPath )
2017-02-25 00:53:17 +03:00
}
}
2017-02-27 00:03:27 +03:00
for _ , n := range [ ] string { "Makefile" , "Makefile.Debug" , "release" , "debug" } {
utils . RemoveAll ( filepath . Join ( path , n ) )
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
case "linux" :
case "ios" , "ios-simulator" :
for _ , suf := range [ ] string { "_plugin_import" , "_qml_plugin_import" } {
2017-03-04 21:01:53 +03:00
pPath := filepath . Join ( path , fmt . Sprintf ( "%v%v.cpp" , strings . ToLower ( module ) , suf ) )
2017-06-10 22:37:03 +03:00
/ * TODO :
2017-02-27 00:03:27 +03:00
if utils . QT_VERSION_MAJOR ( ) == "5.9" && utils . ExistsFile ( pPath ) {
2017-06-10 22:37:03 +03:00
if content := utils . Load ( pPath ) ; ! strings . Contains ( content , "+build ios,!darwin" ) {
utils . Save ( pPath , "// +build ios,!darwin\n" + utils . Load ( pPath ) )
2017-02-25 00:53:17 +03:00
}
}
2017-06-10 22:37:03 +03:00
* /
if true /*TODO: utils.QT_VERSION_MAJOR() != "5.9"*/ || mode == MOC || mode == RCC {
2017-02-27 00:03:27 +03:00
utils . RemoveAll ( pPath )
2017-02-25 00:53:17 +03:00
}
}
2017-02-27 00:03:27 +03:00
for _ , n := range [ ] string { "Info.plist" , "qt.conf" } {
utils . RemoveAll ( filepath . Join ( path , n ) )
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
utils . RemoveAll ( filepath . Join ( path , fmt . Sprintf ( "%v.xcodeproj" , strings . ToLower ( module ) ) ) )
2017-04-17 20:21:21 +03:00
case "android" , "android-emulator" :
2017-02-27 00:03:27 +03:00
utils . RemoveAll ( filepath . Join ( path , fmt . Sprintf ( "android-lib%v.so-deployment-settings.json" , strings . ToLower ( module ) ) ) )
case "sailfish" , "sailfish-emulator" :
case "asteroid" :
case "rpi1" , "rpi2" , "rpi3" :
2017-02-25 00:53:17 +03:00
}
}
2017-05-16 01:06:35 +03:00
func createCgo ( module , path , target string , mode int , ipkg , tags string ) string {
2017-03-04 21:01:53 +03:00
bb := new ( bytes . Buffer )
2017-02-25 00:53:17 +03:00
defer bb . Reset ( )
2017-05-16 01:06:35 +03:00
if mode == MOC && tags != "" {
bb . WriteString ( "// +build " + tags + "\n" )
}
2017-03-04 21:01:53 +03:00
guards := "// +build "
2017-02-27 00:03:27 +03:00
switch target {
case "darwin" :
guards += "!ios"
2017-04-17 20:21:21 +03:00
case "android" , "android-emulator" :
guards += strings . Replace ( target , "-" , "_" , - 1 )
2017-02-27 00:03:27 +03:00
case "ios" , "ios-simulator" :
guards += "ios"
case "sailfish" , "sailfish-emulator" :
guards += strings . Replace ( target , "-" , "_" , - 1 )
case "asteroid" :
2017-03-17 23:36:32 +03:00
guards += target
2017-02-27 00:03:27 +03:00
case "rpi1" , "rpi2" , "rpi3" :
2017-03-17 23:36:32 +03:00
guards += target
2017-02-25 00:53:17 +03:00
}
2017-05-16 01:06:35 +03:00
//TODO: move "minimal" build tag in separate line -->
2017-02-27 00:03:27 +03:00
switch mode {
case NONE :
if len ( guards ) > 10 {
guards += ","
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
guards += "!minimal"
case MINIMAL :
if len ( guards ) > 10 {
guards += ","
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
guards += "minimal"
}
if len ( guards ) > 10 {
bb . WriteString ( guards + "\n\n" )
2017-02-25 00:53:17 +03:00
}
2017-05-16 01:06:35 +03:00
//<--
2017-02-25 00:53:17 +03:00
2017-03-04 21:01:53 +03:00
pkg := strings . ToLower ( module )
2017-02-27 00:03:27 +03:00
if mode == MOC {
2017-03-04 21:01:53 +03:00
pkg = ipkg
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
fmt . Fprintf ( bb , "package %v\n\n/*\n" , pkg )
2017-02-25 00:53:17 +03:00
2017-02-27 00:03:27 +03:00
//
2017-02-25 00:53:17 +03:00
2017-03-04 21:01:53 +03:00
file := "Makefile"
2017-02-27 00:03:27 +03:00
if target == "windows" {
file += ".Release"
2017-02-25 00:53:17 +03:00
}
2017-03-04 21:01:53 +03:00
content := utils . Load ( filepath . Join ( path , file ) )
2017-02-25 00:53:17 +03:00
2017-02-27 00:03:27 +03:00
for _ , l := range strings . Split ( content , "\n" ) {
2017-02-25 00:53:17 +03:00
switch {
2017-02-27 00:03:27 +03:00
case strings . HasPrefix ( l , "CFLAGS" ) :
fmt . Fprintf ( bb , "#cgo CFLAGS: %v\n" , strings . Split ( l , " = " ) [ 1 ] )
case strings . HasPrefix ( l , "CXXFLAGS" ) , strings . HasPrefix ( l , "INCPATH" ) :
fmt . Fprintf ( bb , "#cgo CXXFLAGS: %v\n" , strings . Split ( l , " = " ) [ 1 ] )
case strings . HasPrefix ( l , "LFLAGS" ) , strings . HasPrefix ( l , "LIBS" ) :
2017-04-05 22:49:26 +03:00
if target == "windows" && ! ( utils . QT_MXE_STATIC ( ) || utils . QT_MSYS2_STATIC ( ) ) {
2017-03-04 21:01:53 +03:00
pFix := [ ] string {
2017-02-27 00:03:27 +03:00
filepath . Join ( utils . QT_DIR ( ) , utils . QT_VERSION_MAJOR ( ) , "mingw53_32" ) ,
2017-03-02 21:24:25 +03:00
filepath . Join ( utils . QT_MXE_DIR ( ) , "usr" , utils . QT_MXE_TRIPLET ( ) , "qt5" ) ,
2017-02-27 00:03:27 +03:00
utils . QT_MSYS2_DIR ( ) ,
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
for _ , pFix := range pFix {
pFix = strings . Replace ( filepath . Join ( pFix , "lib" , "lib" ) , "\\" , "/" , - 1 )
if strings . Contains ( l , pFix ) {
var cleaned [ ] string
for _ , s := range strings . Split ( l , " " ) {
if strings . HasPrefix ( s , pFix ) && ( strings . HasSuffix ( s , ".a" ) || strings . HasSuffix ( s , ".dll" ) ) {
s = strings . Replace ( s , pFix , "-l" , - 1 )
s = strings . TrimSuffix ( s , ".a" )
s = strings . TrimSuffix ( s , ".dll" )
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
cleaned = append ( cleaned , s )
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
l = strings . Join ( cleaned , " " )
2017-02-25 00:53:17 +03:00
}
}
}
2017-02-27 00:03:27 +03:00
fmt . Fprintf ( bb , "#cgo LDFLAGS: %v\n" , strings . Split ( l , " = " ) [ 1 ] )
2017-02-25 00:53:17 +03:00
}
}
2017-02-27 00:03:27 +03:00
switch target {
2017-04-17 20:21:21 +03:00
case "android" , "android-emulator" :
2017-02-27 00:03:27 +03:00
fmt . Fprint ( bb , "#cgo LDFLAGS: -Wl,--allow-shlib-undefined\n" )
case "windows" :
fmt . Fprint ( bb , "#cgo LDFLAGS: -Wl,--allow-multiple-definition\n" )
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
fmt . Fprint ( bb , "*/\nimport \"C\"\n" )
2017-02-25 00:53:17 +03:00
2017-03-11 00:54:09 +03:00
out , err := format . Source ( bb . Bytes ( ) )
if err != nil {
utils . Log . WithError ( err ) . Panicln ( "failed to format:" , module )
}
tmp := string ( out )
2017-02-25 00:53:17 +03:00
2017-02-27 00:03:27 +03:00
switch target {
2017-04-08 20:46:06 +03:00
case "darwin" :
tmp = strings . Replace ( tmp , "$(EXPORT_ARCH_ARGS)" , "-arch x86_64" , - 1 )
2017-02-27 00:03:27 +03:00
case "ios" :
tmp = strings . Replace ( tmp , "$(EXPORT_ARCH_ARGS)" , "-arch arm64" , - 1 )
tmp = strings . Replace ( tmp , "$(EXPORT_QMAKE_XARCH_CFLAGS)" , "" , - 1 )
tmp = strings . Replace ( tmp , "$(EXPORT_QMAKE_XARCH_LFLAGS)" , "" , - 1 )
case "ios-simulator" :
tmp = strings . Replace ( tmp , "$(EXPORT_ARCH_ARGS)" , "-arch x86_64" , - 1 )
tmp = strings . Replace ( tmp , "$(EXPORT_QMAKE_XARCH_CFLAGS)" , "" , - 1 )
tmp = strings . Replace ( tmp , "$(EXPORT_QMAKE_XARCH_LFLAGS)" , "" , - 1 )
2017-04-17 20:21:21 +03:00
case "android" , "android-emulator" :
2017-03-02 21:24:25 +03:00
tmp = strings . Replace ( tmp , fmt . Sprintf ( "-Wl,-soname,lib%v.so" , strings . ToLower ( module ) ) , "" , - 1 )
tmp = strings . Replace ( tmp , "-shared" , "" , - 1 )
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
for _ , variable := range [ ] string { "DEFINES" , "SUBLIBS" , "EXPORT_QMAKE_XARCH_CFLAGS" , "EXPORT_QMAKE_XARCH_LFLAGS" , "EXPORT_ARCH_ARGS" , "-fvisibility=hidden" , "-fembed-bitcode" } {
for _ , l := range strings . Split ( content , "\n" ) {
if strings . HasPrefix ( l , variable + " " ) {
2017-02-25 00:53:17 +03:00
if strings . Contains ( l , "-DQT_TESTCASE_BUILDDIR" ) {
l = strings . Split ( l , "-DQT_TESTCASE_BUILDDIR" ) [ 0 ]
}
2017-02-27 00:03:27 +03:00
tmp = strings . Replace ( tmp , fmt . Sprintf ( "$(%v)" , variable ) , strings . Split ( l , " = " ) [ 1 ] , - 1 )
2017-02-25 00:53:17 +03:00
}
}
2017-02-27 00:03:27 +03:00
tmp = strings . Replace ( tmp , fmt . Sprintf ( "$(%v)" , variable ) , "" , - 1 )
tmp = strings . Replace ( tmp , variable , "" , - 1 )
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
tmp = strings . Replace ( tmp , "\\" , "/" , - 1 )
2017-02-25 00:53:17 +03:00
2017-02-27 00:03:27 +03:00
if module == "build_ios" {
return tmp
2017-02-25 00:53:17 +03:00
}
2017-03-02 21:24:25 +03:00
for _ , file := range cgoFileNames ( module , path , target , mode ) {
switch target {
2017-04-11 00:38:26 +03:00
case "darwin" :
for _ , lib := range [ ] string { "WebKitWidgets" , "WebKit" } {
tmp = strings . Replace ( tmp , "-lQt5" + lib , "-framework Qt" + lib , - 1 )
}
2017-03-02 21:24:25 +03:00
case "windows" :
2017-03-11 00:54:09 +03:00
if utils . QT_MSYS2 ( ) && utils . QT_MSYS2_ARCH ( ) == "amd64" {
2017-03-02 21:24:25 +03:00
tmp = strings . Replace ( tmp , " -Wa,-mbig-obj " , " " , - 1 )
}
2017-03-11 00:54:09 +03:00
if ( utils . QT_MSYS2 ( ) && utils . QT_MSYS2_ARCH ( ) == "amd64" ) || utils . QT_MXE_ARCH ( ) == "amd64" {
2017-03-02 21:24:25 +03:00
tmp = strings . Replace ( tmp , " -Wl,-s " , " " , - 1 )
}
case "ios" :
if strings . HasSuffix ( file , "darwin_arm.go" ) {
tmp = strings . Replace ( tmp , "arm64" , "armv7" , - 1 )
}
case "ios-simulator" :
if strings . HasSuffix ( file , "darwin_386.go" ) {
tmp = strings . Replace ( tmp , "x86_64" , "i386" , - 1 )
}
}
utils . Save ( filepath . Join ( path , file ) , tmp )
}
return ""
}
func cgoFileNames ( module , path , target string , mode int ) [ ] string {
2017-02-27 00:03:27 +03:00
var pFix string
switch mode {
case RCC :
pFix = "rcc_"
case MOC :
pFix = "moc_"
case MINIMAL :
pFix = "minimal_"
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
var sFixes [ ] string
switch target {
case "darwin" :
sFixes = [ ] string { "darwin_amd64" }
case "linux" :
sFixes = [ ] string { "linux_amd64" }
case "windows" :
2017-03-11 00:54:09 +03:00
if utils . QT_MXE_ARCH ( ) == "amd64" || ( utils . QT_MSYS2 ( ) && utils . QT_MSYS2_ARCH ( ) == "amd64" ) {
2017-02-27 00:03:27 +03:00
sFixes = [ ] string { "windows_amd64" }
} else {
sFixes = [ ] string { "windows_386" }
2017-02-25 00:53:17 +03:00
}
2017-02-27 00:03:27 +03:00
case "android" :
sFixes = [ ] string { "linux_arm" }
2017-04-17 20:21:21 +03:00
case "android-emulator" :
sFixes = [ ] string { "linux_386" }
2017-02-27 00:03:27 +03:00
case "ios" :
sFixes = [ ] string { "darwin_arm64" , "darwin_arm" }
case "ios-simulator" :
sFixes = [ ] string { "darwin_amd64" , "darwin_386" }
case "sailfish" :
sFixes = [ ] string { "linux_arm" }
case "sailfish-emulator" :
sFixes = [ ] string { "linux_386" }
case "asteroid" :
sFixes = [ ] string { "linux_arm" }
case "rpi1" , "rpi2" , "rpi3" :
sFixes = [ ] string { "linux_arm" }
}
2017-02-25 00:53:17 +03:00
2017-03-02 21:24:25 +03:00
var o [ ] string
2017-02-27 00:03:27 +03:00
for _ , sFix := range sFixes {
2017-03-02 21:24:25 +03:00
o = append ( o , fmt . Sprintf ( "%vcgo_%v_%v.go" , pFix , strings . Replace ( target , "-" , "_" , - 1 ) , sFix ) )
2017-02-25 00:53:17 +03:00
}
2017-03-02 21:24:25 +03:00
return o
2017-02-25 00:53:17 +03:00
}