Skip to content

Commit e398bb2

Browse files
Add osx specific checks for cflags and ldflags
1 parent ce75d7d commit e398bb2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

java-config.jar

133 Bytes
Binary file not shown.

src/JavaConfig.java

+30-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,24 @@ public void reportJdkHome() {
143143
out.println(jdkDir.getAbsolutePath());
144144
}
145145

146-
public void reportCFlags() {
146+
public boolean isOSX() {
147+
return "Mac OS X".equals(System.getProperty("os.name"));
148+
}
149+
150+
public void reportCFlags() throws IOException {
151+
if (isOSX()) {
152+
// OSX is special, as always
153+
// Up one level from the java.home is a Headers directory
154+
File jreHome=new File(System.getProperty("java.home", ""));
155+
File headersDir=new File(jreHome.getParentFile(), "Headers");
156+
if (headersDir.isDirectory()) {
157+
out.println("-I" + headersDir.getCanonicalPath());
158+
return;
159+
}
160+
161+
// Otherwise, fall through to standard JDK directory structure detect
162+
}
163+
147164
File jdkDir=getJdkHome();
148165
if (jdkDir==null) error("Could not determine JDK location");
149166

@@ -164,6 +181,18 @@ public void reportCFlags() {
164181
}
165182

166183
public void reportLDFlags() throws IOException {
184+
if (isOSX()) {
185+
// OSX is special, as always
186+
// Up one level from the java.home is a Headers directory
187+
File jreHome=new File(System.getProperty("java.home", ""));
188+
File libDir=new File(jreHome.getParentFile(), "Libraries");
189+
if (libDir.isDirectory()) {
190+
out.println("-L" + libDir.getCanonicalPath());
191+
return;
192+
}
193+
// Otherwise, fall through to standard directory layout detect
194+
}
195+
167196
String prop=System.getProperty("java.library.path");
168197
if (prop==null) error("Could not find java.library.path");
169198
String[] paths=prop.split(Pattern.quote(String.valueOf(File.pathSeparatorChar)));

0 commit comments

Comments
 (0)