How to make a non-binary (source code) library?

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
User avatar
aclassifier
Respected Member
Posts: 483
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

How to make a non-binary (source code) library?

Post by aclassifier »

How is this done?

I see in [1], chapter "12 Using XMOS Makefiles to create binary libraries"
The default module system used by XMOS application makefiles includes common modules at the source code level. However, it is possible to build a module into a binary library for distribution without the source
If the code should be provided (like in the XMOS lib_spi], is chapter 12 still the recipe?

I see in lib_spi module_build_info that XCC_FLAGS_spi_async.xc = $(XCC_FLAGS) and I infer that this is what the build system needs to understand that lib_spi cannot be built alone, and that it's the user's XCC_FLAGS that will be used when building lib_spi with my code?

Finally, how do I start a | New | Library | of this kind from the xTIMEcomposer IDE?

[1] xTIMEcomposer user guide


--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

Hi,
Yes you can (we do this to ship the standard libraries).
But we don't support this from our tool chain.

The tools for you to do this are available in the tool chain (.o files will be in the .build directory, `xmosar` is the archive tool to package them up).
I would ask you to seek the information else where:
- search for unix-ar e.g. https://www.systutorials.com/docs/linux/man/1-ar/
- `xcc --help` tells you that "-L <directory> Add directory to library search path"
- add `-v` to your makefile XCC_FLAGS to see how other libraries are pulled in, and then add suitable flags using XCC_MAP_FLAGS.
User avatar
aclassifier
Respected Member
Posts: 483
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

Post by aclassifier »

Thanks, Robert! Now I would have the recipe!

But then, wouldn't this be good to have in the tool chain?
--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

The tools are there, just not the button to press.
User avatar
aclassifier
Respected Member
Posts: 483
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

Post by aclassifier »

Off Topic
I like buttons.. especially if they let me understand what I do, let me concentrate on my "real" problems and not how to feed the tools. ("Real" problems in this context are not real real problems, though. Perphaps because of that buttons are nice.. (But XMOS has made a wonderful tool with lots of buttons that I enjoy every day, so I won't complain))
--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/
User avatar
aclassifier
Respected Member
Posts: 483
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

Post by aclassifier »

I am trying to make a library now. However, some clues about expected params to ar probably is necessary. I have some to chose from:

Code: Select all

bash-3.2$ ar --man
usage:  ar -d [-TLsv] archive file ...
	ar -m [-TLsv] archive file ...
	ar -m [-abiTLsv] position archive file ...
	ar -p [-TLsv] archive [file ...]
	ar -q [-cTLsv] archive file ...
	ar -r [-cuTLsv] archive file ...
	ar -r [-abciuTLsv] position archive file ...
	ar -t [-TLsv] archive [file ...]
	ar -x [-ouTLsv] archive [file ...]
I expect that I need to run ar (or xmosar instead?) in Terminal.

xmosar --help

Code: Select all

bash-3.2$ xmosar --help
Usage: xmosar [emulation options] [-]{dmpqrstx}[abcDfilMNoPsSTuvV] [member-name] [count] archive-file file...
       xmosar -M [<mri-script]
 commands:
  d            - delete file(s) from the archive
  m[ab]        - move file(s) in the archive
  p            - print file(s) found in the archive
  q[f]         - quick append file(s) to the archive
  r[ab][f][u]  - replace existing or insert new file(s) into the archive
  s            - act as ranlib
  t            - display contents of archive
  x[o]         - extract file(s) from the archive
 command specific modifiers:
  [a]          - put file(s) after [member-name]
  [b]          - put file(s) before [member-name] (same as [i])
  [D]          - use zero for timestamps and uids/gids
  [U]          - use actual timestamps and uids/gids (default)
  [N]          - use instance [count] of name
  [f]          - truncate inserted file names
  [P]          - use full path names when matching
  [o]          - preserve original dates
  [u]          - only replace files that are newer than current archive contents
 generic modifiers:
  [c]          - do not warn if the library had to be created
  [s]          - create an archive index (cf. ranlib)
  [S]          - do not build a symbol table
  [T]          - make a thin archive
  [v]          - be verbose
  [V]          - display the version number
  @<file>      - read options from <file>
  --target=BFDNAME - specify the target object format as BFDNAME
 emulation options: 
  No emulation specific options
xmosar: supported targets: elf32-i386 a.out-i386-linux pei-i386 elf64-x86-64 elf32-x86-64 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex
Report bugs to <http://www.sourceware.org/bugzilla/>
I assume that while I develop the library I only work within xTIMEcomposer and then I won't need xmosar (not ar, really?) before I am going to export the code?

I am trying to log my work here (standard disclaimer: no money, ads, gifts; only fun and expenses).
Off Topic
Bear in mind that this is the first time ever I would make a library and I am sitting alone. At work with lots of embedded controllers we just reused the code base, that branched off. A library comes at a price (like do I really want to make it that general. I listened to a lecture once by a guy at (then) Philips. He said it (then) cost 5-10 times more to make a library, when the source was being used in a variety of products)
--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

yes, I would use xmosar.
The usage is the same as ar, and you shoud find plenty of help on the interent for 'ar'.
User avatar
aclassifier
Respected Member
Posts: 483
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

Post by aclassifier »

Thanks.

Right now I think that I only need to use xmosar when it's all up and working (library made and seen by user code) on my machine and I need to post it on the net...

Or do I need it "from the library sources" that I now make "to having that library seen", also locally here and now? I am still doing some restructuring of the code to have it suit a library structure, so I haven't come to that point yet.
Off Topic
After all, the sources here are supposed to be rebuilt with the user code with the application, for any user. I will also need to make the user edit in a library header file to define the struct used for the protocol. Since a library cannot include user header files, of course. Using byte arrays would have made it harder, but structs are there for a reason. There is a OSI layer problem with packet built-in CRC16 handled by the radio chip and a needed user part with CRC32 having to be added, that I also have decided to handle in the library
--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/
User avatar
aclassifier
Respected Member
Posts: 483
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

Post by aclassifier »

I have now done this. Here is my summary (detailed in the above url):
  • Make your library with “Create new build module based project”
  • Make /src and /api directories and think about your file structure
  • Add a module_build_info file and fill it with VERSION and DEPENDENT_MODULES
  • In your application (the one that’s going to use your library) add your library to USED_MODULES
  • Move the code proper into your new library
  • That’s all! It’s now compiled with your application. If not: restart xTIMEcomposer. The library sources are open
  • Make a git system
  • To export it make a zip of it (exclude the .git directory)
  • To import this then unzip to a no-workspace place and get it into your workspave by | File | New | xTIMEcomposer Project Based on Existing Application or Module
I fail to see where I should have used -L, -l or xmosar in this case?
--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/
Post Reply