How to include multiple packages with one statement in Ada? - package

I wrote a library in Ada and I would like for the client to only need to include one package into their code. Something like:
with all_packages;
That will include all the packages useful for the client. I wrote the library with one package for each tagged type to keep things simple and easy to read.
How do I give the library user the possibility to include all packages with only one statement?

You can't.
You did well by encapsulating each tagged type in its own package, that's the approach recommended for object-oriented programming in Ada.
Client code then simply 'withs' just those packages it needs.

Related

Dependency Management in C with CMake

I have recently tried to make a few basic projects in C (using CMake), but one aspect I find very difficult is getting all the different things that I've been making to link together nicely. For example, I started off by making a data-structure library that has some of the basic data structures, along with functions to traverse them, etc., and a testing library that handles unit testing. In most new projects I make, I find that I need to include these two libraries, but I can't find an easy way to do it. I tried doing this using git submodule, and while that did work for the most part, whenever I updated any of the dependencies, updating the dependant seemed to be a nightmare. I've also had a look into the cmake package system; find_package, and related functions; but I can't seem to get that to work (at least when I want to install it in a custom directory, that is).
I was wondering if there is some sort of "standard" way that C programmers go about dealing with this, and what that may be. Is submodules the way to go? If so, is there a way I could do it cleanly, making sure that everything is always the right version?
Thanks in advance.

Do I need Setup.hs file when creating Haskell projects?

I use stack new <name>, then hpack-convert and add dependencies into package.yaml in order to skip ceremony and start writing Haskell code.
Why is there's always a Setup.hs file? I don't use custom setups as far as I know. Will I need to include this file at some point?
I think it's just an old haskell convention that "Setup.hs" can be used to build the package, even for simple build types. Pretty sure it can be removed without having issues.

What is the correct way to import C header functions into an R package when they are exported from another?

For performance reasons, I'm working on implementing one of the functions in my R package at the C level using R's .Call. interface. I'd like my C function to be able to use some of the already existing C functions defined in another package (network) to access and manipulate data structures. However, I'm a C newbie, and I have not been able to figure out how to correctly set up / modify the C function registration in network and the import definitions in my package so that I can directly call the C code without creating a duplicate copy of the code in my package.
The CRAN documentation
https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Linking-to-native-routines-in-other-packages seems to say that cross-package linking is possible, and that the lme4 and Matrix packages provide an example. (I can find the R_RegisterCCallable in Matrix's init.c file, but I have not been able to locate the corresponding R_GetCCallable calls in lme4.)
Perhaps the step I'm missing is the correct portable way to import the API header from network/inst/include into my package's C src?
My question is very closely related to the following three, but the solutions seem to all use Rcpp, and so seem to gloss over the import definition step (probably because it is obvious to everyone except a C newbie like me).
using C function from other package in Rcpp
How do I share C++ functions in Rcpp-based libraries between R packages?
Best way to use c++ code from R package FOO in package BAR
I have a few working and worked examples:
xts importing from zoo
RcppRedis importing from RApiSerialize
RcppKalman (on GitHub) importing from expm
and of course the grand old (but more complicated) example of lme4 importing from Matrix. Note that none of the exporting packages uses Rcpp. And even if the importing packages do, take that as a mere distraction. This is a plain C interface so whichever package uses it is also using plain C for this.

How can I best check for C library dependencies?

I'm building something that installs a high-level stack, and to do that, I need to install the lower-level stuff.
The simplest way to look for whether, say, Java is installed, is to just shell out a which java in a shell script and check if it can find it. I'm now to the point where I need to do some libraries without an obvious binary- basically stuff that is an include from within C. libxml, for example.
I'm woefully green to C in general, so this makes things a little tricky for me. :) Ideally I could just make a shell script that calls a little C applicaiton that calls #include <xxxx>, where xxxx is the library that I'm checking the existence of. If it can't find it, it errors out. Unfortunately, of course, all that happens prior to compilation, so it's not as dynamic as I'd like.
I'm doing this on a system that probably doesn't have anything installed on it (be it high-level language or package managers or what have you), so I'm looking more for a basic shell script way of doing things (or maybe some clever C or command-line gcc options). Or maybe just manually search the include paths that gcc would look for anyway /usr/local/include, /usr/include, etc.). Any thoughts?
Autotools is really what you need. Its a huge (and bizarre) framework for dealing with this very problem:
http://www.gnu.org/software/autoconf/
You can also use pkg-config, which will work with newer software making use of that mechanism:
http://pkg-config.freedesktop.org/wiki/
this is the purpose of configure (part of automake and autoconf)

Specify makefile location to link libraries

I recently stumbled upon this in a project I'm working on. In package A, there is a required configuration option --package-B-makefile-location from which A's makefile borrows variable values.
Is this a common design pattern which has merit? It seems to me that B's package source is as important as its binary for compiling A. Might there be reasons I wouldn't want to tamper with it?
Thanks,
Andrew
It is far from unheard of for one package to need other packages pre-installed, and you have to specify those locations.
For example, building GCC (4.5.2), you need to specify the locations of the GMP, MPFR and MPC libraries if they won't be found by default.
Complex systems which are extensible - Perl, Apache, Tcl/Tk, PHP - provide configuration data to their users in various ways (Config.pm for Perl, apxs for Apache, etc), but that configuration data is crucial to dependent modules.
My suspicion is that your Package A needs some of the configuration data related to Package B, but there isn't a fully-fledged system for providing it. As a workaround, Package A needs to see the configuration data encapsulated in the makefile.
It is not common to need the makefile; it is not uncommon to need some information about other packages.
It's a common and useful design pattern as far as it goes, but it can be abused like any other.
I'm not sure I understand the second part of your question, but if the makefiles are well designed then any change you make to B's makefiles which doesn't break B won't break A either.

Resources