'Make' for the MonkeyC compiler

I am trying to start with monkey c just now and try to live without eclipse - as it tries to change my windows system settings during the setup.

So I did a small batch file which is able to compile the samples very easily. All you need is to copy the following script 'make.cmd' into the connect iq directory and create a private key ('YourKey.der').

Then you can compile and start one of the samples by entering:

make ApplicationName resource-codes [simulation]

where the resource-codes is a string with characters to include various xml files (e.g. 'r' for resources.xml) and additional compiler flags (e.g. '*' to exclude debug information).

Have fun,
Michael

@echo off

if /%2==/ (

set sample=SimpleDataField
set options=brs

) else (

set sample=%1
set options=%2

)

: -------------------------------------------------------------

set loc=samples\%sample%\
set res=%loc%resources\
set src=%loc%source\
set all=
set flags=

:loop
set check=%options:~0,1%
set options=%options:~1%

if /%check%==/r ( set all=%all%;%res%resources.xml)
if /%check%==/R ( set all=%all%;%res%resource\resources.xml)
if /%check%==/s ( set all=%all%;%res%strings.xml)
if /%check%==/S ( set all=%all%;%res%strings\strings.xml)
if /%check%==/l ( set all=%all%;%res%layout.xml)
if /%check%==/L ( set all=%all%;%res%layouts\layout.xml)
if /%check%==/b ( set all=%all%;%res%bitmaps.xml)
if /%check%==/B ( set all=%all%;%res%images\bitmaps.xml)
if /%check%==/D ( set all=%all%;%res%drawables\drawables.xml)
if /%check%==/M ( set all=%all%;%res%menus\menu.xml)
if /%check%==/X ( set all=%all%;%res%menus\auxmenu.xml)
if /%check%==/* ( set flags=%flags% --release )
if /%check%==/! ( set flags=%flags% --warn )
if /%check%==/0 ( set flags=%flags% --device round_watch )

if not /%options%==/ goto loop

set all=%all:~1%

: -------------------------------------------------------------

echo.
echo Compile: '%src%%sample%*.mc':
echo.

if "%all%"=="~1" (
echo /!\ No valid resource file
goto :eof )

setlocal enabledelayedexpansion
echo Resource files:
set /a count=0
for %%i in (%all%) do (
set /a count+=1
set "v_!count!=%%i" )

for /l %%i in (1,1,%count%) do ( echo - !v_%%i! )
endlocal

echo.
if not "%flags%"=="" (
echo Flags: %flags%
echo. )

:compile
call bin\monkeyc -o test.prg -m %loc%manifest.xml %flags% -z %all% %src%%sample%*.mc -y YourKey.der

:run
set options=%3.
set check=%options:~0,1%
set options=%options:~1%

if not "%check%"=="!" ( goto :eof )

set check=square_watch
if "%options%"=="0." ( set check=round_watch)
if "%options%"=="9." ( set check=fr935)

bin\monkeydo test.prg %check%
  • Well if you enjoy pain you can go the command line way but... if it's just a matter of the setup annoys you then why use the setup if you can just extract the eclipse package?
    Pick the 32 bit or 64 bit link next to Eclipse IDE for Java EE Developers http://www.eclipse.org/downloads/eclipse-packages/
  • I'm guessing the script may have problems with resource overrides and other things, and may only work with really simple projects.

    In reality, eclipse has things you can't do from a command line, such as the debugger (2.3.x) and the App settings editor - things you'll likely want to use.
  • Cheers!
    Check out our seed project that has a bash make script for ConnectIQ baked in it [HTML]github.com/.../HTML]

    I can't help with Windows side of this but I have definitely been able to live without Eclipse until now using make...
  • Thank you all for your comments and hints, actually I continue using the command line (newest version of make is below) but I will see if there are limitations when going further.

    Actually I am making my first code for doing a datafield which should show the pace for the actual and the past kilometers showing a graph - this seems to be possible using the batch file and a simple text editor. Next step is to check if I can add some menus to allow different settings (target pace etc.) and after doing so I will see how to create apps (maybe to have offline tide calculation for my next holidays)...

    @echo off

    : make ApplicationName resources [simulation]
    : BirdDataField bs0! !9
    : ^ directory ^ flags ^ ! starts simulation, 9 means Forerunner935

    if /%2==/ (

    set sample=SimpleDataField
    set options=brs

    ) else (

    set sample=%1
    set options=%2

    )

    : -------------------------------------------------------------

    set loc=samples\%sample%\
    set res=%loc%resources\
    set src=%loc%source\
    set all=
    set flags=

    :loop
    set check=%options:~0,1%
    set options=%options:~1%

    if /%check%==/r ( set all=%all%;%res%resources.xml)
    if /%check%==/R ( set all=%all%;%res%resource\resources.xml)
    if /%check%==/s ( set all=%all%;%res%strings.xml)
    if /%check%==/S ( set all=%all%;%res%strings\strings.xml)
    if /%check%==/l ( set all=%all%;%res%layout.xml)
    if /%check%==/L ( set all=%all%;%res%layouts\layout.xml)
    if /%check%==/b ( set all=%all%;%res%bitmaps.xml)
    if /%check%==/B ( set all=%all%;%res%images\bitmaps.xml)
    if /%check%==/D ( set all=%all%;%res%drawables\drawables.xml)
    if /%check%==/M ( set all=%all%;%res%menus\menu.xml)
    if /%check%==/X ( set all=%all%;%res%menus\auxmenu.xml)
    if /%check%==/* ( set flags=%flags% --release )
    if /%check%==/! ( set flags=%flags% --warn )
    if /%check%==/0 ( set flags=%flags% --device round_watch )

    if not /%options%==/ goto loop

    set all=%all:~1%

    : -------------------------------------------------------------

    echo.
    echo Compile: '%src%*.mc':
    for /f %%i in ('dir /b %src%*.mc') do ( echo - %%i )
    echo.

    if "%all%"=="~1" (
    echo /!\ No valid resource file
    goto :eof )

    setlocal enabledelayedexpansion
    echo Resource files:
    set /a count=0
    for %%i in (%all%) do (
    set /a count+=1
    set "v_!count!=%%i" )

    for /l %%i in (1,1,%count%) do ( echo - !v_%%i! )
    endlocal

    echo.
    if not "%flags%"=="" (
    echo Flags: %flags%
    echo. )

    :compile
    call bin\monkeyc -o test.prg -m %loc%manifest.xml %flags% -z %all% %src%*.mc -y MichaelVogel.der

    if errorlevel 1 goto :error

    :run
    set options=%3.
    set check=%options:~0,1%
    set options=%options:~1%

    if not "%check%"=="!" ( goto :eof )

    set check=square_watch
    if "%options%"=="0." ( set check=round_watch)
    if "%options%"=="9." ( set check=fr935)

    bin\monkeydo test.prg %check%

    goto :eof

    :error
    echo -----------------------------------------------------
    echo /!\ Compiler-Error (Code %errorlevel%), ignore running options
  • Next step is to check if I can add some menus to allow different settings (target pace etc.) and after doing so I will see how to create apps (maybe to have offline tide calculation for my next holidays)...


    The way you can add configuration options to a DF is with app settings (you can change things from your phone or Garmin Express.). And as I mentioned, you can really only test app settings is with the App settings editor in Eclipse.
  • The way you can add configuration options to a DF is with app settings (you can change things from your phone or Garmin Express.). And as I mentioned, you can really only test app settings is with the App settings editor in Eclipse.


    Testing is not so much needed for now because the projects are really tiny (at least for the moment :rolleyes:). About the menus, there's a sample app in the SDK (which can be compiled by a simple 'make menutest DLMXS' using my batch file), would it be possible to integrate such a menu into data fields? I don't want to use external devices to do some changes on my watch, if possible.

    BTW here's my first version of my 'Birdie Datafield', which shows your pace for the last kilometers of your run - actually it has a target pace of 5 minutes and show bar graphs between 3 and 7 minutes. It would be fine to adapt this values by a menu. Another thing for configuring could be the output format for the pace, for instance "4:53" or what is used now "+7" (the difference to the target pace).
  • About the menus, there's a sample app in the SDK (which can be compiled by a simple 'make menutest DLMXS' using my batch file), would it be possible to integrate such a menu into data fields?


    No. You can't do menus in a data field. You'll want to look at app settings.
  • No. You can't do menus in a data field. You'll want to look at app settings.

    I would like to have a target pace which can be changed like in the virtual partner data field, is there any possibility to to configuration changes by using the watch only? I would even think about an extra app to control the data field settings :o
  • You'll need to use app settings for things like this in a CIQ data field. You can't change settings for anything else from a different CIQ app on the watch.
  • The actual "make" is doing quite a lot of things now - it checks if there if the source code is in a subdirectory 'App', 'Datafield', 'Widget' or 'Watchface' and also looks for a 'make.ini' file which contains a command line with prefered resource parameters. Before using the tool, you should change the line "set add=" to your java directory and don't forget to replace "Information\Tools\YOURKEY.der" with your personal key file path.

    @echo off

    : Make for Connect IQ - Version 1.10
    : © 2017 created by Michael H. Vogel
    : !? are not permitted in parameters

    set add=C:\Program Files\System\Java SDK\jre\bin
    echo "%path%"|find "%add%" > nul || set path=%path%;%add%


    :check first parameter - app
    if /%1==/ (
    echo make [type*]ApplicationName [resources] [simulation]
    goto :eof
    )
    set appdir=samples\
    set subdir=
    set p1=%1
    set p2=%2
    set p3=%3


    :check starting mode (default options)
    set message=
    set check=%p1%.
    set check=%check:~0,1%
    if %check%==: (
    set p1=%p1:~1%
    set message= DEFAULT
    )


    :check type of application
    set check=%p1%..
    set check=%check:~1,1%
    set fiffi=0

    if %check%==* (
    set check=%p1:~0,1%
    set p1=%p1:~2%
    set fiffi=1
    )
    if %fiffi%==1 (
    if %check%==a ( set subdir=%subdir%App\)
    if %check%==d ( set subdir=%subdir%Datafield\)
    if %check%==f ( set subdir=%subdir%Watchface\)
    if %check%==w ( set subdir=%subdir%Widget\)
    )


    :scan directories
    set sample=%p1%
    set sample=%sample:.prg=%

    if exist %appdir%%subdir%%sample%\. goto :set directories
    if exist %appdir%%subdir%app\%sample%\. ( set subdir=%subdir%App\)
    if exist %appdir%%subdir%watchface\%sample%\. ( set subdir=%subdir%Watchface\)
    if exist %appdir%%subdir%datafield\%sample%\. ( set subdir=%subdir%Datafield\)
    if exist %appdir%%subdir%widget\%sample%\. ( set subdir=%subdir%Widget\)


    :set directories
    set loc=%appdir%%subdir%%sample%\
    set res=%loc%resources\
    set src=%loc%source\
    set all=
    set flags=
    set recursive=0


    :check default options
    set check=%sample%
    set count=0

    if not exist "%src%%check%.mc" set check=%check%App
    if not exist "%src%%check%.mc" goto :FileError

    :options make 1
    if not exist "%loc%make.ini" goto :options make 2
    for /f "tokens=*" %%i in ('findstr /C:"\/\/ make " "%loc%make.ini"') do (
    set default=%%i
    goto :options done
    )
    :options make 2
    if not exist "%src%make.ini" goto :options source
    for /f "tokens=*" %%i in ('findstr /C:"\/\/ make " "%src%make.ini"') do (
    set default=%%i
    goto :options done
    )
    :options source
    for /f "tokens=*" %%i in ('findstr /C:"\/\/ make " "%src%%check%.mc"') do (
    set default=%%i
    goto :options done
    )

    :options done
    set default=%default:~3%
    set check=%default:~0,4%


    :check first parameter - options
    if /%p2%==/ (
    if "%check%"=="make" (
    :echo Using default options...
    call make :%default:~5%
    goto :eof
    )
    echo Resource parameters missing.
    goto :eof
    ) else (
    set check=%p2%
    call set options=%%check:!=.%% )
    echo.
    echo Project '%subdir%%sample%' with%message% options '%options: =%':
    )


    :loop
    set check=%options:~0,1%
    set options=%options:~1%

    if /%check%==/b ( set all=%all%;%res%bitmaps.xml)
    if /%check%==/B ( set all=%all%;%res%images\bitmaps.xml)
    if /%check%==/d ( set all=%all%;%res%drawables.xml)
    if /%check%==/D ( set all=%all%;%res%drawables\drawables.xml)
    if /%check%==/f ( set all=%all%;%res%fonts.xml)
    if /%check%==/F ( set all=%all%;%res%fonts\fonts.xml)
    if /%check%==/j ( set all=%all%;%res%jsonresources.xml)
    if /%check%==/J ( set all=%all%;%res%jsondata\jsonresources.xml)
    if /%check%==/l ( set all=%all%;%res%layout.xml)
    if /%check%==/L ( set all=%all%;%res%layouts\layout.xml)
    if /%check%==/m ( set all=%all%;%res%menu\mainmenu.xml)
    if /%check%==/M ( set all=%all%;%res%menus\menu.xml)
    if /%check%==/o ( set all=%all%;%res%settings.xml)
    if /%check%==/O ( set all=%all%;%res%settings\settings.xml)
    if /%check%==/p ( set all=%all%;%res%properties.xml)
    if /%check%==/P ( set all=%all%;%res%properties\properties.xml)
    if /%check%==/r ( set all=%all%;%res%resources.xml)
    if /%check%==/R ( set all=%all%;%res%resource\resources.xml)
    if /%check%==/s ( set all=%all%;%res%strings.xml)
    if /%check%==/S ( set all=%all%;%res%strings\strings.xml)
    if /%check%==/X ( set all=%all%;%res%menus\auxmenu.xml)
    if /%check%==// ( set recursive=1 )
    if /%check%==/+ ( set all=%all%;%loc%%options% & set options= )
    if /%check%==/# ( set all=%all%;%res%%options% & set options= )
    if /%check%==/* ( set flags=%flags% --release)
    if /%check%==/. ( set flags=%flags% --warn)
    if /%check%==/: ( set flags=%flags% --debug)
    if /%check%==/~ ( set flags=%flags% --unit-test)
    if /%check%==/0 ( set flags=%flags% --device round_watch)
    if /%check%==/4 ( set flags=%flags% --device square_watch)
    if /%check%==/9 ( set flags=%flags% --device fr935)

    if not /%options%==/ goto loop

    call set all=%%all:+=;%loc%%%
    call set all=%%all:#=;%res%%%
    set all=%all:~1%


    :display settings

    setlocal enabledelayedexpansion
    if /%recursive%==/1 (
    set check= ^(subdirectory files not listed^)
    ) else (
    set check=
    )
    endlocal & set check=%check%

    echo ----------------------------------------------------------
    echo Compile: '%src%*.mc'%check%:
    for /f %%i in ('dir /b %src%*.mc') do ( echo - %%i )
    echo.

    set check=%default:~0,4%
    if "%check%" neq "make" ( goto :resources )

    echo Default: '%default%'
    echo.

    :resources
    if "%all%"=="~1" (
    echo /!\ No valid resource file
    goto :eof )

    setlocal enabledelayedexpansion
    echo Resource files:
    set /a count=0
    for %%i in (%all%) do (
    set /a count+=1
    set "v_!count!=%%i" )

    for /l %%i in (1,1,%count%) do ( echo - !v_%%i! )
    endlocal

    if not "%flags%"=="" (
    echo.
    echo Flags: %flags% )

    echo ----------------------------------------------------------
    echo.

    :scan source files
    set src=%src%*.mc

    if %recursive%==0 goto :compile
    setlocal enableDelayedExpansion
    set scan=
    for /f "delims=*" %%l in ('dir "%src%" /b /s') do (
    set check="%%l"
    echo !check!|find ".mc">nul && set scan=!scan! !check!
    )
    set scan=%scan:~1%
    endlocal & set src=%scan%

    :compile
    call bin\monkeyc -o %sample%.prg -m %loc%manifest.xml%flags% -z %all% %src% -y Information\Tools\YOURKEY.der

    if errorlevel 1 goto :CompileError


    :run
    set options=%p3%.
    set check=%options:~0,1%

    if "%check%"=="." ( goto :eof )

    set options=
    if "%check%"=="0" ( set options=round_watch)
    if "%check%"=="4" ( set options=square_watch)
    if "%check%"=="9" ( set options=fr935)

    :start simulator
    init

    bin\monkeydo %sample%.prg %options%
    goto :eof


    :CompileError
    echo -----------------------------------------------------
    echo /!\ Compiler-Error (Code %errorlevel%), ignore running options
    goto :eof

    :FileError
    echo -----------------------------------------------------
    echo /!\ File '%sample%' does not exist.
    goto :eof<