• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pawn compiler for Android
#3
The software of PrimeOS is 100% Android, no matter that it is made for desktop computers. The same applies to RemixOS, PhoenixOS and Androidx86.?
Android is based on Linux, and it can run Linux programs if they are recompiled against the NDK (Native Development Kit), which uses the Bionic C library instead of the usual GNU C library, and could require some modifications to the code.
Once you successfully compile it, you can either call it from the command line, which is your best option if you already have a code editor which supports custom commands, or you could make an editor app with a GUI using the normal Android APIs (in Java, Kotlin, C# with Xamarin or other languages).

Useful links:
https://developer.android.com/ndk/guides
https://software.intel.com/en-us/article...uild-tools
https://corochann.com/build-executable-f...1-388.html

Edit:
After a few hours trying, I've been able to build the Pawn?compiler for Android, but with one small edit to the source: in amx.c at line 493 the line?
Code:
assert_static(sizeof(f)<=sizeof(cell));
?
won't compile with the NDK, so I temporarily commented it until I find a solution.?

Here's what to do to build libpawnc.so,?pawncc, pawndisasm and pawnruns?into?Android binaries (using Windows, in my case, but you can probably do it on Android itself, Linux or MacOS):
  • Download Android NDK (~2.6 GB when decompressed on disk) and extract it somewhere (https://developer.android.com/ndk/downloads)
  • Download and install CMake (https://cmake.org/download/)
  • Clone or download the pawn compiler source code?(https://github.com/pawn-lang/compiler)
  • Create a batch or Powershell script containing the cmake command with its arguments (more on this later)
  • Apply the temporary workaround to the assert_static compile error
  • Run the CMake script
  • In case it gives you an error about "-lpthread" you can comment the line?link_libraries(pthread) in CMakeLists.txt
  • Run the following:
Code:
cmake --build .

Here's my CMake command script:
Code:
cmake -G "MinGW Makefiles" ^
? ?-DCMAKE_TOOLCHAIN_FILE=C:/android-ndk-r20/build/cmake/android.toolchain.cmake ^
? ?-DANDROID_NDK=C:/android-ndk-r20 ^
? ?-DANDROID_ABI=arm64-v8a ^
? ?-DANDROID_PLATFORM=android-29 ^
? ?-DANDROID_STL=c_static ^
? ?-DCMAKE_BUILD_TYPE=Release ^
? ?-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=./bin ^
? ?-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=./bin ^
? ?-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=./bin ./compiler/source/compiler

Set?DCMAKE_TOOLCHAIN_FILE to your?android Cmake toolchain's?path (comes together with the NDK)
Set?DANDROID_NDK to your android NDK's?path
Set?DANDROID_ABI to the target CPU architecture
Set?DANDROID_PLATFORM to the target Android API level
Finally, replace?./compiler/source/compiler to the path to the compiler source code, where the CMakeLists.txt file is located.

Here is how I ran it on my rooted Android device (in my case it's an Android 9.0 Pie smartphone, but it should be the same in PrimeOS):
  • Download and install a terminal emulator app (my favorite is Material Terminal), and a file manager that takes advantage of?root functions?(my favorite is FX File Manager)
  • Move the compiled binaries to any directory whose partition is not mounted noexec.?The sdcard partition (aka storage/emulated/) is always mounted with the noexec param, so you can't add execute privileges?to the binaries. In my case, I put the binaries in /data/local/pawncc (requires root access)
  • Give execute permissions to the files
  • Run the terminal emulator and change directory to where you put the binaries
  • Set the environment variable "LD_LIBRARY_PATH" to the same directory (or wherever you chose to?put libpawnc.so)
  • Create a test pawn file and run the compiler (if you are in /data/local be sure to become?root first using the?su command)
Code:
./pawncc file.pwn -ofile.amx

In my case the pawn script was simply:
Code:
native printf(string[]);
main()
{
? ?printf("Hello World");
}

And it correctly compiled to a 67 Bytes?AMX file.?And of course I couldn't test it yet because it requires you to also build an AMX host, or at least the test AMX host which I didn't yet. If I do I will update this post.

This approach however is not the best because Android doesn't let you put arbitrary binary files in executable-enabled locations?unless you are root. The best thing you could do?in my opinion is to build a small code editor using the Android API in?Java/Kotlin or if you prefer in Xamarin C#, and then using a JNI wrapper you can embed?the pawncc as a shared library in your application, and?even an AMX host to test the scripts (not SA-MP Server?scripts?obviously).
  Reply


Messages In This Thread
Pawn compiler for Android - by Luciano - 2019-06-15, 03:04 PM
RE: Pawn compiler for Android - by Y_Less - 2019-06-15, 04:22 PM
RE: Pawn compiler for Android - by Sasino97 - 2019-06-18, 06:40 AM
RE: Pawn compiler for Android - by Chakib Chemso - 2021-05-01, 04:52 AM
RE: Pawn compiler for Android - by Y_Less - 2021-05-03, 07:09 PM
RE: Pawn compiler for Android - by Chakib Chemso - 2021-05-09, 02:13 AM

Forum Jump: