Pages

Saturday, July 1, 2017

GNU - Build preparation


Warning
OUT OF DATE
It's no doubt very convenient and trustworthy to install new software through IPS or even the legacy SVr4 packages. But when those options are not available fortunately there's still a chance for the GNU build automation, which although not as convenient can also perform a good job.

The well-known essentials of GNU build automation end-user operation work-flow was the subject of another post, in which I hopefully confirmed to work reasonably with a few adjustments under Solaris 11.3 and in which I successfully integrated some well-known ZFS essential advantages, such as source-tree snapshots.

In this post I hope to somewhat complement what's been discussed by presenting a suggestion of Shell script to hopefully simplify and avoid some common mistakes in the preparation of the GNU build automation work-flow environment.

For instance, assume that an application source code (tarball app-1.0.0.tar.gz) is to be built for both 32-bit and 64-bit targets using GNU tools and that the build operation is to take place at a local staff /software/build with the results installed locally under /software/prototype.

NOTE
I assume that the source code tarball is usually named under the following convention: name-version.tar.compression.

But there are cases this convention varies, for instance. node.js prepends a v before version, which slight variation, in this particular case, is a minor annoyance and fortunately won't break the following script. After the script is run, if desired, one can rename the datasets accordingly in order to normalize things, by removing the v before version number.

But there are other cases such as maven (apache-maven-3.5.3-src.tar.gz) where the tarball name would break the script. I could attempt fixing it, but as there are so many unpredictable possibilities this would certainly become a unmanageable.
 
The general solution is to conform the tarballs' names to my original assumption, usually with a simple manual procedure (as root) of extracting the archive and then storing everything back under a conformant archive name. For instance:
 
# cd /tmp
# gtar xf .../maven/3.5.3/apache-maven-3.5.3-src.tar.gz
# gtar czf maven-3.5.3.tar.gz maven-3.5.3
# cp maven-3.5.3.tar.gz .../maven/3.5.3/

 
As an alternative while recreating the tarball, one can attempt higher compression rates with j (for a .bz2) or J (for a .xz) instead of just z (for a more common .gz compressed file). On this particular example the sizes become: 2.6M (.gz), 2.2M (.bz2) and 1.8M (.xz).

Thursday, June 29, 2017

GNU - Build Automation

Solaris 11.3 includes many modern packages, among them some essential GNU build automation ones. The problem is that the pace of update of these third-party packages is much faster than what get updated through support repository, needless to say the public release repository. In order to better keep up with this third-party pace, there's no other better alternative than to get the sources and build ourselves what's needed, in the hope (and unfortunately sometimes it's no more than just a hope) that the sources and the build tools are compatible and available to Solaris.

Thursday, June 22, 2017

Source-tree snapshots

While setting to build projects which source-codes are distributed as a source-code tarball it's convenient to prepare some grounds before simply extracting the tarball to a plain directory on a "general" file-system. That's because while fine-tuning or experimenting on building the project it's often necessary to keep track or manage the state of the source-code tree in order to not mess things up.

In Solaris, part of this ground preparation is particularly powerful and elegant by virtue of the ZFS, specially due to the possibility of easy snapshot, clone, hold / release, send / receive and rollback operations. To take advantage of all this power it's necessary to set up some delegated ZFS permissions to the base dataset where the source-code tree will reside. This dataset could be remote, shared via NFS or SMB, but more typically it is local to an individual developer system and usually located as a descendant to its home directory.

Tuesday, June 13, 2017

GCC - library search dirs

Again, among a lot of detail to pay attention when compiling and linking a program is where the default libraries are being looked for. The general answer found everywhere is: "In the default system locations". But that may be vague, so here's my refinement to that general anwser, for instance, for GCC:

Wednesday, June 7, 2017

GCC - why build

I was studying C++11 when I faced an awful bug regarding locales in the Solaris 11.3 x86_64 platform either on plain GCC 4.8.2 or Developer Studio 12.5 which for C++11 relies on a GCC library by means of the -std=c++11 compiler flag. Simply put the feature doesn't work at all, except for C or POSIX locales, which are essentially the one and the same as the traditional USA localization since the legacy C era. It doesn't matter if I attempt any of the following forms:
...
std::locale user_native( "" )
...
 or
...
std::locale en_US( "en_US.UTF-8" )
...
Both forms fail badly with the following ugly message:
terminate ... throwing ... 'std::runtime_error'
... locale::facet::_S_create_c_locale ... not valid
Abort

Wednesday, May 17, 2017

Logging - Basics #2

After my introduction to logging it became clear to me that I needed to improve the initial ideas. As a process, the enhancements couldn't be achieved all at once, but gradually, step by step, according to the Natural laws :-) More specifically, I tried to address points 1, 2 and 4 from my initial attempt.

A new abstract type is to provide a general interface for all kinds of logging devices, not only file-system as firstly attempted. With this in mind, a log just need to be opened, written-to and finally closed when done. I tried to reflect such a model as shown next.

Tuesday, May 16, 2017

A CSS styling tool

I've been writing some code for my blog posts and every time I need to insert some excerpts of these codings it's a somewhat painful task to format it the precise way I'd like to. So I reached a threshold point where it would be worthy to set aside some time to look for some tool to help me achieve my goal. Fortunately, NetBeans, the IDE I've been using more frequently leads me half-way to where I want, by providing a Print to HTML... option:


But, unfortunately, this option does a nice job that goes beyond what I need. And the problem is that by going beyond it turns itself useless to address my current needs. It's true that it offers a tiny bit of flexibility:


But it is insufficient. The problem is that the syntax-highlighting is formatted via CSS internal styles of type text/css within a HTML comment within the well-known <style> tag. What is supposed to reflect the syntax-highlighting is within <span> tags of specific classes. Hence, I can't use it like that (not even portions of it) right away here in Blogger as I want:

<!DOCTYPE ... > 
<html>
<
head
> 
<title>framework.hxx</title
<meta ...
<style type="text/css">
<
!--
body {...}
pre {...}
table {...}
.highlight-caret-row {...}
.ST1 {...}
.preprocessor {...}
.comment {...}
.literal {...}
.pragma-omp-keyword-directive {...}
.ST0 {...}
--> 

</style>
<
/head

<body>
...
11
<span class="literal">virtual</span>
  ~
<span class="ST1">file</span>() {}
...


That is, not even portions of the above produce:
(unless with a completely inviable bit-by-bit editing)

11 virtual ~file() {}

Thursday, May 11, 2017

Logging - Basics #1

Logging is an important aspect of computer science as it provides a way of tracing back exactly or approximately to some degree what have happened in relation to a certain computation in-between a certain time interval. Of course there are many kinds of log with respect to what, where and how the operation is done and what, where and how its results are archived for later retrieval and analysis. This definition should suffice for a quick startup :-)

Depending on the system there may be different kinds of logging support and facilities but I don't know of a single system that doesn't provide at least one kind of logging per each of its subsystems. But that is of course strongly platform dependent, thus not easily or possibly portable. Because of this it is generally useful for an application (or program) to also plan its own logging features that will work across any platform it supports.

On this post I present one very simple solution consisting on a mixed strategy of encapsulating an old-style (C) logging in a C++ object. It's definitely not a final and optimal solution. There is a long way to perfect it, but nevertheless it's a start. As having traces of an old-style logging it suffers from typical problems from the past related to the care that must be taken with respect to printf-like functions and its formatting strings and respective variadic parameters. As being a helper C++ concrete object the logging interface could be more elaborated and generalized by a new interface layer consisting of an abstract C++ class factoring out the most fundamental aspects of logging. But for now it's just as it is, and it works despite of these main deficiencies.

The implementation here is target at a 64-bit Unix system but it should be easily ported to another platform such as a Windows system. The log is recorded to a standard line-oriented file where each record begins with a simple timestamp marker. Each line is "freely" composed by means of an encapsulated standard C printf-like call. Let's see how...

Saturday, May 6, 2017

Studio under Solaris

I already talked about NetBeans under Solaris which is great together with GCC, but even greater is the Solaris / Developer Studio and its native optimizing compiler and tools. By the time of this writing the current version is 12.5 (developerstudio-125 is the pkg5 name) which by now (finally!) virtually includes full (regression: locales don't work!) support to C++ 11 and already some selected features of C++ 14.

Appart from the lenghty download from the Oracle public release Internet repository, my installation notes on the links above present some more powerful considerations that the graphical Package Manager cannot offer, so check it out!



NOTE
The public release Internet address is https://pkg.oracle.com/solarisstudio/release but you'll only be able to access if you first register at http://pkg-register.oracle.com/ and later generate a PKCS12(1openssl) a.k.a. a PFX file to install on your browser.
NOTE
After launching Solaris / Developer Studio for the very first time, it may be convenient to adjust the default project folder much the same as its done for NetBeans. Instead of looking for the projectui.propeties file at ~/.netbeans, do so at ~/.solstudio or ~/.oracledevstudio.
   

Monday, May 1, 2017

Formatting issues

Stream formatting is very cool in C++ but with the power and flexibility comes the complexity. It's true that many limitations of the traditional C-style I/O were addressed by the streams framework and new I/O operators (put-to and get-from), manipulators and much more. But that didn't happen on a blink-of-an-eye. It's been evolving since many years, sometimes being completely revamped. A sad legacy is that in some (or many?) circumstances, backward compatibility takes precedence over some "fixes" or adjustments. Then it's not rare to have to carry on with some old "misbehavior" at some corners.

For example, consider the following output:
(I could argue that it has "unexpected" behavior; disregard the "[" and "]")

Formatting flags ...       // OK

*******Hello, there!       // OK; better if left aligned

Number 1: .........e       // OK
Number 2: c^^^             // "Should be" [12^^]
Number 3: 14               // "Should be" [20]

Floating 1: 8.33^^^^^^     // "Should be" [      8.33]
Floating 2: 1.83           // "Should be" [  1.83]
Floating 3: 3.33^^^^^^     // "Should be" [     3.333]

Going home...^^            // "Should be" [**Going home...]


I mean "should be" assuming that:
  • member function calls would permanently change the formatting state
  • manipulators calls would temporarily override the formatting state

But as you can see that's not the case and there's no even a "congruent misbehavior". Some member functions and manipulators (fill(), hex, left) permanently change behavior, others (width(), setw()) temporarily override, yet others misbehave strangely as precision (which should affect only how many decimal places to use and not the integral part as well!). In essence each situation is very simple, but when mixed on code, things can become quickly strange, perhaps a nightmare. A programmer can become quickly stressed and choose a less than optimal quick way out! But that's bad in the long run; that's not quality programming. Even the most simple programs such as rc-03 or the one listed below (which generated the above output) can face such annoyances when trying to print formatted output.

Saturday, April 29, 2017

Formatting

I/O streams formatting is achieved by more than one framework class working together. At the core are controlling flags, but there are other attributes that can't be described/signaled by a flag, such as the (desired) width of a certain I/O field and how to pad it as necessary. Nevertheless, I'll concentrate on the flags as they form the core.

One the second ISO C++ 11 standard (ISO/IEC 14882-2011(E)), section 27.5.3.1.2, we have the description of the streams formatting flags type, std::ios_base::fmtflags, which builds on a bitmask type (section 17.5.2.13), which is an enumerated type (section 7.2), which is a compound type (section 3.9.2), and so on...

Among other things, this means that, as a bitmask, it has most (if not all) the well-defined bit operations one might expect. But the problem is that this not speak aloud as it should be, which may cause some confusion or obfuscation, resulting in much less than optimal utilization of the feature. This is one is just one out of several other similar situation appearing to establish a mild kind of obscurantism that do not help in getting the most out of the streams framework, which is very nice, flexible and powerful.