// GetPath gets a shared object file from a library name
111
121
// it does it in the following order
112
-
// see if PUREGOTK_LIBNAME_PATH is set
122
+
// see if PUREGOTK_LIBNAME_FOLDER is set (full path to the lib)
123
+
// - e.g. PUREGOTK_GTK_PATH
124
+
// see if PUREGOTK_LIB_FOLDER is set (root folder where to look for libs)
113
125
// go over the hardcoded paths
114
126
// find a library name with pkg-config
115
127
// panic if failed
116
128
// TODO: Hardcore a library shared object with linker -X flag
117
129
// This is useful for packaging
118
130
func GetPath(name string) string {
131
+
// resolve alias
132
+
if v, ok := aliases[name]; ok {
133
+
name = v
134
+
}
119
135
// try to get from env var
120
136
ev := fmt.Sprintf("PUREGOTK_%s_PATH", name)
121
137
if v := os.Getenv(ev); v != "" {
122
138
return v
123
139
}
124
140
125
-
// try to loop over paths
126
-
for _, p := range paths {
127
-
g := findSo(p, name)
128
-
if g != "" {
129
-
return g
141
+
// Or if a general folder is set where everywhere is located, return that
142
+
ep := os.Getenv("PUREGOTK_LIB_FOLDER")
143
+
if ep != "" {
144
+
g := findSo(ep, name)
145
+
if g == "" {
146
+
panic(fmt.Sprintf("Could not find lib: %s, at path: %s with env: %s", name, ep, "PUREGOTK_FOLDER"))
130
147
}
148
+
return g
149
+
}
131
150
151
+
// fallback to lookup a path if no env var is found
152
+
gp, ok := paths[runtime.GOARCH]
153
+
if ok {
154
+
// try to loop over paths
155
+
for _, p := range gp {
156
+
g := findSo(p, name)
157
+
if g != "" {
158
+
return g
159
+
}
160
+
161
+
}
132
162
}
163
+
// last effort: pkg-config
133
164
g := findPkgConf(name)
134
165
if g != "" {
135
166
return g
136
167
}
137
168
138
-
panic(fmt.Sprintf("Path for library: %s not found. Please set the path to this library shared object file manually with env variable: %s. Or make sure pkg-config is setup correctly", strings.ToLower(name), ev))
169
+
panic(fmt.Sprintf("Path for library: %s not found. Please set the path to this library shared object file manually with env variable: %s or PUREGOTK_LIB_FOLDER. Or make sure pkg-config is setup correctly", strings.ToLower(name), ev))
// GetPath gets a shared object file from a library name
120
// GetPath gets a shared object file from a library name
111
// it does it in the following order
121
// it does it in the following order
112
-
// see if PUREGOTK_LIBNAME_PATH is set
122
+
// see if PUREGOTK_LIBNAME_FOLDER is set (full path to the lib)
123
+
// - e.g. PUREGOTK_GTK_PATH
124
+
// see if PUREGOTK_LIB_FOLDER is set (root folder where to look for libs)
113
// go over the hardcoded paths
125
// go over the hardcoded paths
114
// find a library name with pkg-config
126
// find a library name with pkg-config
115
// panic if failed
127
// panic if failed
116
// TODO: Hardcore a library shared object with linker -X flag
128
// TODO: Hardcore a library shared object with linker -X flag
117
// This is useful for packaging
129
// This is useful for packaging
118
func GetPath(name string) string {
130
func GetPath(name string) string {
131
+
// resolve alias
132
+
if v, ok := aliases[name]; ok {
133
+
name = v
134
+
}
119
// try to get from env var
135
// try to get from env var
120
ev := fmt.Sprintf("PUREGOTK_%s_PATH", name)
136
ev := fmt.Sprintf("PUREGOTK_%s_PATH", name)
121
if v := os.Getenv(ev); v != "" {
137
if v := os.Getenv(ev); v != "" {
122
return v
138
return v
123
}
139
}
124
140
125
-
// try to loop over paths
141
+
// Or if a general folder is set where everywhere is located, return that
126
-
for _, p := range paths {
142
+
ep := os.Getenv("PUREGOTK_LIB_FOLDER")
127
-
g := findSo(p, name)
143
+
if ep != "" {
128
-
if g != "" {
144
+
g := findSo(ep, name)
129
-
return g
145
+
if g == "" {
146
+
panic(fmt.Sprintf("Could not find lib: %s, at path: %s with env: %s", name, ep, "PUREGOTK_FOLDER"))
130
}
147
}
148
+
return g
149
+
}
131
150
151
+
// fallback to lookup a path if no env var is found
152
+
gp, ok := paths[runtime.GOARCH]
153
+
if ok {
154
+
// try to loop over paths
155
+
for _, p := range gp {
156
+
g := findSo(p, name)
157
+
if g != "" {
158
+
return g
159
+
}
160
+
161
+
}
132
}
162
}
163
+
// last effort: pkg-config
133
g := findPkgConf(name)
164
g := findPkgConf(name)
134
if g != "" {
165
if g != "" {
135
return g
166
return g
136
}
167
}
137
168
138
-
panic(fmt.Sprintf("Path for library: %s not found. Please set the path to this library shared object file manually with env variable: %s. Or make sure pkg-config is setup correctly", strings.ToLower(name), ev))
169
+
panic(fmt.Sprintf("Path for library: %s not found. Please set the path to this library shared object file manually with env variable: %s or PUREGOTK_LIB_FOLDER. Or make sure pkg-config is setup correctly", strings.ToLower(name), ev))