Skip to content

Commit efdf77e

Browse files
committed
Support more compiler setting, GUI option: -ansi, -fno-asm, -traditional-cpp
Optimization level (-O), std
1 parent 5514c88 commit efdf77e

File tree

8 files changed

+154
-13
lines changed

8 files changed

+154
-13
lines changed

.idea/modules.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ android {
4242

4343
signingConfigs {
4444
release {
45-
def propFile = new File("signing.properties")
45+
def propFile = new File(rootProject.projectDir, "signing.properties")
4646
if (propFile.exists()) {
4747
Properties props = new Properties()
4848
props.load(new FileInputStream(propFile))
@@ -57,7 +57,7 @@ android {
5757
// Map for the version code that gives each ABI a value.
5858
applicationVariants.all { variant ->
5959
Properties props = new Properties()
60-
def propFile = new File("app/signing.properties")
60+
def propFile = new File(rootProject.projectDir, "signing.properties")
6161
if (propFile.exists()) {
6262
props.load(new FileInputStream(propFile))
6363
buildConfigField "String", "BASE64_KEY", "\"" + props['BASE64_KEY'] + "\""

app/src/main/java/com/duy/ccppcompiler/compiler/CompileSetting.java

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,75 @@
2121
import android.preference.PreferenceManager;
2222

2323
import com.duy.ccppcompiler.R;
24+
import com.duy.ccppcompiler.compiler.shell.CommandBuilder;
2425

2526
/**
2627
* Created by Duy on 17-May-18.
2728
*/
2829

2930
public class CompileSetting implements ICompileSetting {
30-
private SharedPreferences mPreferences;
31+
private SharedPreferences mPref;
3132
private Context mContext;
3233

3334
public CompileSetting(Context context) {
3435
mContext = context;
35-
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
36+
mPref = PreferenceManager.getDefaultSharedPreferences(context);
3637
}
3738

3839
@Override
3940
public String getCFlags() {
40-
return mPreferences.getString(mContext.getString(R.string.pref_key_c_options), "");
41+
CommandBuilder builder = new CommandBuilder();
42+
builder.addFlags(getGCCFlags());
43+
44+
String cFlags = mPref.getString(mContext.getString(R.string.pref_key_c_options), "");
45+
builder.addFlags(cFlags);
46+
47+
return builder.buildCommand();
4148
}
4249

4350
@Override
4451
public String getCxxFlags() {
45-
return mPreferences.getString(mContext.getString(R.string.pref_key_cxx_options), "");
52+
CommandBuilder builder = new CommandBuilder();
53+
builder.addFlags(getGCCFlags());
54+
55+
String cxxFlags = mPref.getString(mContext.getString(R.string.pref_key_cxx_options), "");
56+
builder.addFlags(cxxFlags);
57+
58+
return builder.buildCommand();
4659

4760
}
4861

4962
@Override
5063
public String getMakeFlags() {
5164
return "";
5265
}
66+
67+
private String getGCCFlags() {
68+
CommandBuilder builder = new CommandBuilder();
69+
70+
71+
//-ansi
72+
builder.addFlags(mPref.getBoolean(mContext.getString(R.string.pref_c_options_ansi), false)
73+
? "-ansi" : "");
74+
//-fno-asm
75+
builder.addFlags(mPref.getBoolean(mContext.getString(R.string.pref_c_options_fno_asm), false)
76+
? "-fno-asm" : "");
77+
//-traditional-cpp
78+
builder.addFlags(mPref.getBoolean(mContext.getString(R.string.pref_c_options_ansi), false)
79+
? "-traditional-cpp" : "");
80+
81+
//optimize
82+
String optimize = mPref.getString(mContext.getString(R.string.pref_option_optimization_level), "");
83+
if (!optimize.isEmpty()) {
84+
builder.addFlags("-O" + optimize);
85+
}
86+
87+
//language standard
88+
String std = mPref.getString(mContext.getString(R.string.pref_option_language_standard), "");
89+
if (!std.isEmpty()) {
90+
builder.addFlags("-std=" + std);
91+
}
92+
return builder.buildCommand();
93+
}
94+
5395
}

app/src/main/res/values/arrays.xml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,50 @@
2020
<item>.h</item>
2121
<item>.c</item>
2222
</string-array>
23+
24+
<string-array name="optimization_level_entries">
25+
<item>""</item>
26+
<item>Low</item>
27+
<item>Medium</item>
28+
<item>High</item>
29+
<item>Highest (fast)</item>
30+
<item>Size (s)</item>
31+
<item>Debug (g)</item>
32+
</string-array>
33+
34+
<string-array name="optimization_level_entries_value">
35+
<item>""</item>
36+
<item>1</item>
37+
<item>2</item>
38+
<item>3</item>
39+
<item>fast</item>
40+
<item>s</item>
41+
<item>g</item>
42+
</string-array>
43+
44+
<string-array name="language_standard_entries">
45+
<item>""</item>
46+
<item>c90 - Support all ISO C90 programs (certain GNU extensions that conflict with ISO C90 are disabled). Same as -ansi for C code.</item>
47+
<item>c99 - ISO C99. This standard is substantially completely supported, modulo bugs and floating-point issues (mainly but not entirely relating to optional C99 features from Annexes F and G)</item>
48+
<item>c11 - ISO C11, the 2011 revision of the ISO C standard. This standard is substantially completely supported, modulo bugs, floating-point issues (mainly but not entirely relating to optional C11 features from Annexes F and G) and the optional Annexes K (Bounds-checking interfaces) and L (Analyzability).</item>
49+
<item>gnu90 - GNU dialect of ISO C90 (including some C99 features).</item>
50+
<item>gnu99 - GNU dialect of ISO C99.</item>
51+
<item>gnu11 - GNU dialect of ISO C11.</item>
52+
<item>c++11 - The 2011 ISO C++ standard plus amendments.</item>
53+
<item>gnu++11 - GNU dialect of -std=c++11.</item>
54+
<item>c++14 - The 2014 ISO C++ standard plus amendments.</item>
55+
</string-array>
56+
57+
<string-array name="language_standard_entries_values">
58+
<item>""</item>
59+
<item>c90</item>
60+
<item>c99</item>
61+
<item>c11</item>
62+
<item>gnu90</item>
63+
<item>gnu99</item>
64+
<item>gnu11</item>
65+
<item>c++11</item>
66+
<item>gnu++11</item>
67+
<item>c++14</item>
68+
</string-array>
2369
</resources>

app/src/main/res/values/do_not_translate.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
<resources>
33
<string name="pref_key_c_options" translatable="false">pref_key_c_options</string>
44
<string name="pref_key_cxx_options" translatable="false">pref_key_cxx_options</string>
5+
6+
<string name="pref_c_options_ansi">pref_c_options_ansi</string>
7+
<string name="pref_c_options_fno_asm">pref_c_options_fno_asm</string>
8+
<string name="pref_c_options_traditional_cpp">pref_c_options_traditional_cpp</string>
9+
<string name="pref_option_optimization_level">pref_option_optimization_level</string>
10+
<string name="pref_option_language_standard">pref_option_language_standard</string>
511
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@
3838
<string name="selected_editor_theme">Selected %s. Restart app to apply theme.</string>
3939
<string name="terminal">Terminal</string>
4040
<string name="code">Code</string>
41+
4142
</resources>
Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
3-
<EditTextPreference
4-
android:key="@string/pref_key_c_options"
5-
android:title="@string/pref_ccopts" />
3+
<PreferenceCategory
4+
android:summary="Add the commands when calling the compiler"
5+
android:title="General">
6+
<EditTextPreference
7+
android:key="@string/pref_key_c_options"
8+
android:title="@string/pref_ccopts" />
9+
10+
<EditTextPreference
11+
android:key="@string/pref_key_cxx_options"
12+
android:title="@string/pref_cxxopts" />
13+
</PreferenceCategory>
14+
15+
<PreferenceCategory android:title="C setting">
16+
<CheckBoxPreference
17+
android:defaultValue="false"
18+
android:key="@string/pref_c_options_ansi"
19+
android:summary="Support all ANSI standard C programs"
20+
android:title="-ansi" />
21+
22+
<CheckBoxPreference
23+
android:defaultValue="false"
24+
android:key="@string/pref_c_options_fno_asm"
25+
android:summary="Do not recognize asm, inline or typeof as a keyword"
26+
android:title="-fno-asm" />
27+
28+
<CheckBoxPreference
29+
android:defaultValue="false"
30+
android:key="@string/pref_c_options_traditional_cpp"
31+
android:summary="Imitate traditional C preprocessors"
32+
android:title="-traditional-cpp" />
33+
</PreferenceCategory>
34+
35+
<PreferenceCategory android:title="Code generation">
36+
<ListPreference
37+
android:defaultValue="false"
38+
android:entries="@array/optimization_level_entries"
39+
android:entryValues="@array/optimization_level_entries_value"
40+
android:key="@string/pref_option_optimization_level"
41+
android:title="Optimization level (-Ox)" />
42+
43+
<ListPreference
44+
android:entries="@array/language_standard_entries"
45+
android:entryValues="@array/language_standard_entries_values"
46+
android:key="@string/pref_option_language_standard"
47+
android:title="Language standard (-std)" />
48+
</PreferenceCategory>
649

7-
<EditTextPreference
8-
android:key="@string/pref_key_cxx_options"
9-
android:title="@string/pref_cxxopts" />
1050

1151
</PreferenceScreen>

signing.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
BASE64_KEY=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnG21WIm7QUUpvYbrXVWXz4jcg06HQQKP0hNo3xg1BPpfKCXWzgVw6lm/MsDrsXb0l9j8rAd9/F0DLtUVEhALXTNmKCfiGWh/i92pnZSaPFGznkB5EXGlgvwnY1PjbwnoWmngAOu8cNISwrdM7LpNwWGIIyjfllI7PwwvAl1+NrJVVEegOhlXvYjMLRAdp23We4vAvhRIhiwmVIP48I8nc4YktecxKsSmHNx/BN5b7gb9bcg1YklLi2mmG72d01+WiPpri44unAp+OW56fyojGKdv27Zulby6DEz5ue5kSnK8Um1k5xnfFOpeykODfXgHnzsw1oeZUymgOSZ9ZzD8VwIDAQAB
2+
SKU_PREMIUM=cpp_nide_premium
3+
RELEASE_STORE_FILE=key_casio.jks
4+
RELEASE_STORE_PASSWORD=phamthiennhi221
5+
RELEASE_KEY_ALIAS=tranleduy1233
6+
RELEASE_KEY_PASSWORD=phamthiennhi221

0 commit comments

Comments
 (0)