Skip to content

Commit

Permalink
minor qtmoc enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
therecipe committed May 26, 2016
1 parent 63cdd63 commit d3c2172
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 16 deletions.
61 changes: 47 additions & 14 deletions internal/binding/templater/cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
"github.com/therecipe/qt/internal/utils"
)

var AppPath string
var (
MocAppPath string
MocModule string
)

func CopyCgo(module string) {

Expand Down Expand Up @@ -43,7 +46,12 @@ func createCgoDarwin(module string) {
libs = cleanLibs(module)
)

tmp += fmt.Sprintf("package %v\n\n", strings.ToLower(module))
tmp += fmt.Sprintf("package %v\n\n", func() string {
if MocModule != "" {
return MocModule
}
return strings.ToLower(module)
}())
tmp += "/*\n"

tmp += "#cgo CPPFLAGS: -pipe -O2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.8 -Wall -W -fPIC\n"
Expand Down Expand Up @@ -89,7 +97,7 @@ func createCgoDarwin(module string) {
tmp += fmt.Sprintf("import \"C\"\n")

if module == parser.MOC {
utils.Save(filepath.Join(AppPath, "moc_cgo_darwin_amd64.go"), tmp)
utils.Save(filepath.Join(MocAppPath, "moc_cgo_darwin_amd64.go"), tmp)
} else {
utils.Save(utils.GetQtPkgPath(strings.ToLower(module), "cgo_darwin_amd64.go"), tmp)
}
Expand All @@ -101,7 +109,12 @@ func createCgoWindows(module string) {
libs = cleanLibs(module)
)

tmp += fmt.Sprintf("package %v\n\n", strings.ToLower(module))
tmp += fmt.Sprintf("package %v\n\n", func() string {
if MocModule != "" {
return MocModule
}
return strings.ToLower(module)
}())
tmp += "/*\n"

tmp += "#cgo CPPFLAGS: -pipe -fno-keep-inline-dllexport -O2 -Wall -Wextra\n"
Expand Down Expand Up @@ -142,7 +155,7 @@ func createCgoWindows(module string) {
tmp += fmt.Sprintf("import \"C\"\n")

if module == parser.MOC {
utils.Save(filepath.Join(AppPath, "moc_cgo_windows_386.go"), tmp)
utils.Save(filepath.Join(MocAppPath, "moc_cgo_windows_386.go"), tmp)
} else {
utils.Save(utils.GetQtPkgPath(strings.ToLower(module), "cgo_windows_386.go"), tmp)
}
Expand All @@ -154,7 +167,12 @@ func createCgoLinux(module string) {
libs = cleanLibs(module)
)

tmp += fmt.Sprintf("package %v\n\n", strings.ToLower(module))
tmp += fmt.Sprintf("package %v\n\n", func() string {
if MocModule != "" {
return MocModule
}
return strings.ToLower(module)
}())
tmp += "/*\n"

tmp += "#cgo CPPFLAGS: -pipe -O2 -Wall -W -D_REENTRANT\n"
Expand Down Expand Up @@ -195,8 +213,8 @@ func createCgoLinux(module string) {
tmp += fmt.Sprintf("import \"C\"\n")

if module == parser.MOC {
utils.Save(filepath.Join(AppPath, "moc_cgo_linux_386.go"), strings.Replace(tmp, "lib64", "lib", -1))
utils.Save(filepath.Join(AppPath, "moc_cgo_linux_amd64.go"), strings.Replace(tmp, "gcc", "gcc_64", -1))
utils.Save(filepath.Join(MocAppPath, "moc_cgo_linux_386.go"), strings.Replace(tmp, "lib64", "lib", -1))
utils.Save(filepath.Join(MocAppPath, "moc_cgo_linux_amd64.go"), strings.Replace(tmp, "gcc", "gcc_64", -1))
} else {
utils.Save(utils.GetQtPkgPath(strings.ToLower(module), "cgo_linux_386.go"), strings.Replace(tmp, "lib64", "lib", -1))
utils.Save(utils.GetQtPkgPath(strings.ToLower(module), "cgo_linux_amd64.go"), strings.Replace(tmp, "gcc", "gcc_64", -1))
Expand All @@ -209,7 +227,12 @@ func createCgoandroidDarwinAndLinux(module string) {
libs = cleanLibs(module)
)

tmp += fmt.Sprintf("package %v\n\n", strings.ToLower(module))
tmp += fmt.Sprintf("package %v\n\n", func() string {
if MocModule != "" {
return MocModule
}
return strings.ToLower(module)
}())
tmp += "/*\n"

tmp += "#cgo CPPFLAGS: -Wno-psabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -DANDROID -Wa,--noexecstack -fno-builtin-memmove -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -mthumb -Wall -Wno-psabi -W -D_REENTRANT -fPIC\n"
Expand Down Expand Up @@ -244,7 +267,7 @@ func createCgoandroidDarwinAndLinux(module string) {
tmp += fmt.Sprintf("import \"C\"\n")

if module == parser.MOC {
utils.Save(filepath.Join(AppPath, "moc_cgo_android_arm.go"), tmp)
utils.Save(filepath.Join(MocAppPath, "moc_cgo_android_arm.go"), tmp)
} else {
utils.Save(utils.GetQtPkgPath(strings.ToLower(module), "cgo_android_arm.go"), tmp)
}
Expand All @@ -256,7 +279,12 @@ func createCgoandroidWindows(module string) {
libs = cleanLibs(module)
)

tmp += fmt.Sprintf("package %v\n\n", strings.ToLower(module))
tmp += fmt.Sprintf("package %v\n\n", func() string {
if MocModule != "" {
return MocModule
}
return strings.ToLower(module)
}())
tmp += "/*\n"

tmp += "#cgo CPPFLAGS: -Wno-psabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -DANDROID -Wa,--noexecstack -fno-builtin-memmove -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -mthumb -Wall -Wno-psabi -W -D_REENTRANT\n"
Expand Down Expand Up @@ -297,7 +325,7 @@ func createCgoandroidWindows(module string) {
tmp += fmt.Sprintf("import \"C\"\n")

if module == parser.MOC {
utils.Save(filepath.Join(AppPath, "moc_cgo_android_arm.go"), tmp)
utils.Save(filepath.Join(MocAppPath, "moc_cgo_android_arm.go"), tmp)
} else {
utils.Save(utils.GetQtPkgPath(strings.ToLower(module), "cgo_android_arm.go"), tmp)
}
Expand All @@ -309,7 +337,12 @@ func createCgoiOS(module string) string {
libs = cleanLibs(module)
)

tmp += fmt.Sprintf("package %v\n\n", strings.ToLower(module))
tmp += fmt.Sprintf("package %v\n\n", func() string {
if MocModule != "" {
return MocModule
}
return strings.ToLower(module)
}())
tmp += "/*\n"

tmp += "#cgo CPPFLAGS: -pipe -fpascal-strings -fmessage-length=0 -Wno-trigraphs -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -Wno-sign-conversion -fexceptions -fasm-blocks -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-implicit-atomic-properties -Wformat -Wno-missing-braces -Wno-unused-function -Wno-unused-label -Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-sign-compare -Wpointer-sign -Wno-newline-eof -Wdeprecated-declarations -Winvalid-offsetof -Wno-conversion -O2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk -mios-simulator-version-min=7.0 -arch i386 -fobjc-nonfragile-abi -fobjc-legacy-dispatch -Wno-deprecated-implementations -Wprotocol -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wall -W -fPIC\n"
Expand Down Expand Up @@ -391,7 +424,7 @@ func createCgoiOS(module string) string {

var path, prefix = func() (string, string) {
if module == parser.MOC {
return AppPath, "moc_"
return MocAppPath, "moc_"
}
return utils.GetQtPkgPath(strings.ToLower(module)), ""
}()
Expand Down
7 changes: 6 additions & 1 deletion internal/binding/templater/template_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,12 @@ import (
return ""
}(),

module,
func() string {
if MocModule != "" {
return MocModule
}
return module
}(),

func() string {
switch module {
Expand Down
7 changes: 6 additions & 1 deletion internal/moc/moc.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func main() {
os.Exit(1)
}

if !strings.Contains(string(src), "package main") {
var plist = strings.Split(filepath.Clean(path), string(filepath.Separator))
templater.MocModule = plist[len(plist)-2]
}

for _, d := range file.Decls {
if typeDecl, ok := d.(*ast.GenDecl); ok {
for _, s := range typeDecl.Specs {
Expand Down Expand Up @@ -215,7 +220,7 @@ func main() {
gofmt.Dir = appPath
runCmd(gofmt, "moc.fmt")

templater.AppPath = appPath
templater.MocAppPath = appPath
templater.CopyCgo("main")
}
}
Expand Down

0 comments on commit d3c2172

Please sign in to comment.