TinyURL widget - shorten your URL's for free!

Enter a long URL to make tiny:

Thursday, March 26, 2015

Gnu Make real-time variable static library construction and testing

You can do a lot without automake, but I don't recommend it. In some cases it makes sense if you can isolate your work in development to simple lightweight fast code that doesn't have a lot of dependencies.

Also, GNU make is hard to learn without real examples.  The GNU suite of tools, GCC included is very steep learning for a beginner.  A lot of time is spent on head smashing against grammar errors.  Gnu tools are very unforgiving. I have learned by error and pattern more times than not.

So when I do things that are complicated, and use the special rules, I will try to pass on what I know by writing them down.

This code will appear in marrspace in the future.   I have off-lined this development in order to make sure this piece works first.  Once that's accomplished I will install the working code inside marrspace.

# Makefile for the messages that come out of the visual information message packages

# DRE 2015
# This library makes a C protocol buffers implementation for other code elsewhere.
# This nasty little subdir should be kept isolated as it deals with agnostic elements of a message protocol.
# that does not need localization because it is stripped away from operating system issues.
# It is a self contained message generation folder.
# that can make a library of messages if needed that can be referenced elsewhere.
# The makefile need only append more message types into MESSAGES and
# that will make a longer list of message elements compiled together.
# I made a test application for atof when it didn't convert large double values correctly, to check if you need strtod
#
# Self-contained testing can happen between msg1 that pipes to msg2 a generic message
# If the output looks like the input, the messages are working

MESSAGES = VMessage  FMessage  GMessage  LMessage  PMessage  MMessage WMessage

# redefine all message types as the final protocol-buffer autogenerated pb-c.c files that might not be present when the folder is spawned

MESSAGES_C = $(MESSAGES:=.pb-c.c)

# redefine all message types as protocol .proto files from the same root. This will tell you if the message is missing as well.
MESSAGES_P = $(MESSAGES:=.proto)
# redefine messages as object files.

MESSAGES_O = $(MESSAGES:=.pb-c.o)


CC = gcc
AR = ar
CFLAGS     = -I./
OBJ1     = msg1.o
OBJ2     = msg2.o

LIBS = -lprotobuf-c -lm libmessage.a

msg1: $(OBJ1)
    $(CC) -o $@ $^ $(MESSAGES_C) $(CFLAGS)  $(LIBS)

msg2: $(OBJ2)
    $(CC) -o $@ $^ $(MESSAGES_C) $(CFLAGS) $(LIBS)

libmessage:  VisObject.o $(MESSAGES_O)
    $(AR) ru  libmessage.a  VisObject.o $(MESSAGES_O)


test-atof: test-atof.o
    $(CC) -o $@ $^ $(CFLAGS) $(LIBS)

.PHONY:    clean check


list : $(MESSAGES_P)
    echo $(MESSAGES_C)
    echo $(MESSAGES_P)

messages :    $(MESSAGES_P)
    protoc-c --c_out=./ $(MESSAGES_P)

all :  messages  libmessage msg1 msg2

# tester recipe that creates the test case and sends data through and outputs to file test.out so you can review what was sent.
# we use the special case $(shell command) to send BASH a command line to execute.
check:  msg1 msg2
    $(shell ./msg1 1  23.44  34.55666 56566 43433.3 4545454.4 444444.5 9999999999999999999993.0  45   -7.777777777777777e1 | ./msg2 2> test.out  )




clean    :   
    rm -f *.o
    rm -f *.pb-c.c
    rm -f *.pb-c.h
    rm -fr *~
    rm -f msg1 msg2 test-atof
    rm -f test.out
    rm -f libmessage.a


    This is a modified version of yesterday's work.  Instead of making two programs with all the C object files, I use the AR archive program to make a static library that is linked to the programs.  Why static? Because it will be small and you want it to run fast.  Why make only? Because this code is agnostic because it references library dependencies that aren't unique apart from protocol buffers that are made generic.  Why C? Because the production system needs to run extremely fast. The marrspace library adds vertexes and lines to a rolling real time model of the visual scene.  I detest bloated C++ code so I am taking more time to make functions that will execute minimally.



To test the output of the piped message from msg1 to msg2 by using a phony recipe that runs the two programs with a canned set of data. 


I use the special $(shell) command to run in the shell's environment.  To call it phony means that make won't look for output files from the shell execution.  There is a test output .out made so one can review the messages passed and converted.  That's all you need for a production library.  GNU make is more powerful than people imagine, if only people have the time to read all the documentation.


   
   

Tuesday, March 24, 2015

Making auto substitutions in GNU Makefiles

One of the skills I stumbled with being a self-taught Unix programmer, was to uncover all the tricks that Unix style development has. 

If you make a makefile, and want to autocreate variables from a pattern, then you can use make's variable substitution to keep a growing list without needing automake. 

There are of course many places where the need for many libraries and so on won't make that a portable thing, you will have too many dependencies that creep in and spoil the simplicity. 

I was hit with the need to make a simple self-contained message protocol to pass data, and I started with Google's protocol buffers in C. 

Since those are simple self-contained protocols that pass data and depend on one library, I thought I could just get away with a Makefile for this subdir:

Here is the reference for substitution:

https://www.gnu.org/software/make/manual/html_node/Substitution-Refs.html#Substitution-Ref

here is the simple Makefile


MESSAGES = VMessage  FMessage  GMessage  LMessage  PMessage  MMessage WMessage
# redefine all message types as the final protocol-buffer autogenerated pb-c.c files that might not be present when the folder is spawned
MESSAGES_C = $(MESSAGES:=.pb-c.c)
# redefine all message types as protocol .proto files from the same root. This will tell you if the message is missing as well.
MESSAGES_P = $(MESSAGES:=.proto)

CC = gcc

CFLAGS     = -I./
OBJ1     = msg1.o
OBJ2     = msg2.o

LIBS = -lprotobuf-c

msg1: $(OBJ1)
    $(CC) -o $@ $^ $(MESSAGES_C) $(CFLAGS)  $(LIBS)

msg2: $(OBJ2)
    $(CC) -o $@ $^ $(MESSAGES_C) $(CFLAGS) $(LIBS)


list : $(MESSAGES_P)
    echo $(MESSAGES_C);
    echo $(MESSAGES_P);

messages :    $(MESSAGES)
    protoc-c --c_out=./ *.proto

all : messages msg1 msg2

.PHONY:    clean

clean    :  
    rm -f *.o
    rm -f *.pb-c.c
    rm -f *.pb-c.h
    rm -fr *~



To explain,   I define a message xMessage, and then the variable is subtstituted into $MESSAGES_C which places a .pb-c.c suffix onto the name of every message. 

The command

MESSAGES_C = $(MESSAGES:=.pb-c.c)

 defines a variable that takes every MESSAGES and adds a .pb-c.c variant that will be the autogenerated .c file from  'make messages'. These are generated from the protoc-c command.

The command

MESSAGES_P = $(MESSAGES:=.proto)
makes a similar .proto file variable if the prototype does not exist.  Why is this useful? Because what if you hadn't made all the messages first, or they were improperly defined, then your message library would be incomplete and might compile and execute leading to undefined behaviour.

One could change it to the other way around but what if I wanted a "ERROR" message as well, they don't have to follow a pattern.  The names don't have to be the same to work.  The library doesn't care but a human reader might.

Then it defines a dependency xMessage.proto which is the message prototype under the protocol buffers system to package a message.

Those are used as dependencies to make a simple message testing program set of msg1 and msg2.


 

Tuesday, March 10, 2015

How to import VCF cards into Mozilla Thunderbird

It seems odd that a major email application can't import the standard contact information file (.vcf) natively.  It's sad but true.

According to this support reply:

https://support.mozilla.org/en-US/questions/994358


vCard or .vcf
Some address book programs use a vCard format, which cannot be imported directly by Thunderbird. You can import both vCard and .vcf using the third-party Thunderbird extension 'MoreFunctionsForAddressBook'.
https://nic-nac-project.org/~kaosmos/morecols-en.html
  • download to desktop or 'downloads' folder on computer.
  • In Thunderbird. 'Tools' > 'Add-ons' to open 'Add-ons manager' in a new tab
  • click on the daisy wheel icon and select 'Install Addon from file
  • locate the .xpi file you downloaded
  • click on Open to install in Thunderbird
Save the vcard / .vcf attachment to eg: desktop
In Thunderbird:
  • open 'Address Book'
  • select the address book you want it to go to
  • 'Tools' > 'morefunctionforAddressBook' > 'Action for contacts' > 'Import vCard/vcf'
  • locate the saved vcard/.vcf file and click on 'Open'

Download the .xpi file form that website address and follow the installation instructions, then you need to restart Thunderbird.

NOTE: You need to save VCF cards to file and import them, this won't work natively from the email itself!!!

 

Thursday, March 5, 2015

How to clean inkscape SVG files

Inkscape sometimes makes SVG files with forbidden elements in them that epub readers might reject, Google epubchecker does not like inkscape:connector commands and fails with:


Error: Unable to sanitize epub

If you run it locally, it will fail with this error:


ERROR: *.svg(147,2722): attribute "inkscape:connector-curvature" not allowed here; expected attribute "class", "clip-path", "clip-rule", "color", "color-interpolation", "color-rendering", "cursor", "display", "externalResourcesRequired", "fill", "fill-opacity", "fill-rule", "filter", "image-rendering", "marker-end", "marker-mid", "marker-start", "mask", "onactivate", "onclick", "onfocusin", "onfocusout", "onload", "onmousedown", "onmousemove", "onmouseout", "onmouseover", "onmouseup", "opacity", "pathLength", "pointer-events", "requiredExtensions", "requiredFeatures", "shape-rendering", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "text-rendering", "transform", "visibility", "xml:base", "xml:lang" or "xml:space"



To get around this, download and compile SVG Cleaner.


https://github.com/RazrFalcon/SVGCleaner

https://launchpad.net/~svg-cleaner-team/+archive/ubuntu/svgcleaner

You will also need z7a   (7za-full on Ubuntu)

https://www.ibm.com/developerworks/community/blogs/6e6f6d1b-95c3-46df-8a26-b7efd8ee4b57/entry/how_to_use_7zip_on_linux_command_line144?lang=en