Autotools generate files
Let's take a look at this file for a minute. You'll recall from our discussion of Automake primaries and prefixes that the first line indicates the products to be built and installed by this Makefile. In this case, the noinst prefix indicates that this library should not be installed at all.
This is because you're creating a "convenience" library, or a library designed solely to make using the source code in the common directory more convenient for two or more consumers. Granted, you only have one consumer at this point--the jupiter program--but later on you'll add another consumer of this library, and then it will make more sense.
The library we're creating will be called "libjupcommon. Object archives are merely packages containing one or more object.
They can't be executed, or loaded into a process address space, as can shared libraries. They can only be added to a linker command line. The linker is smart enough to realize that such archives are merely groups of object files.
The linker extracts the object files it needs to complete the linkage process when building a program or shared library. The second line represents the list of source files associated with this library. I chose to place both the header and the C source file in this list.
Personally, I don't care for this style of project directory structure organization. I prefer to place private header files right along side of the source code they represent. Automake transforms library and program names in the product list into derived variable names by converting all characters except for letters, numbers and at-signs into underscore characters.
Clean up your top-level project directory, removing all files and directories except those that we've written by hand so far. Also remove all Makefile. The top-level directory should look like this when you're done:. Add two more lines to the end of the existing file, in this manner:. These product-specific option variables are used to pass options to the compiler and linker command lines. The option variables currently supported by Automake for programs include:.
This can be handy for combining multiple convenience libraries. This rule isn't particularly strict however, as I'll explain shortly here. Quite frankly, it doesn't really matter, as long as the final command line composed by Automake from all of these variables makes sense to the linker.
This is the per-file form of these flags, rather than the per-product form. The per-file forms are used when the developer wants the same set of flags to be used for all products within a given Makefile. Sometimes you need to set a group of preprocessor flags for all products in a Makefile. When you use a per-product flag variable, you need to include the per-file variable explicitly, like this:.
These are reserved for the end-user, and will be always be appended to the per-file or per-product versions of these variables. Note that this sort of syntax is really only necessary for libraries built as part of your own package. If you're linking your program with a library that's installed on the user's system, then the configure script should have found it, and automatically added an appropriate reference to the linker's command line. Header files referenced with double-quotes are not searched for, but merely expected to exist in the specified directory, relative to the directory containing the referencing source file.
Getting back to our example--edit the configure. Okay, now give your updated build system a try. Add the -i option to the autoreconf command so that it will install any additional missing files that might be required after our enhancements:.
Well, it appears that you're still not done yet. Since you've added a new type of entity to our build system--static libraries--Automake via autoreconf tells you that you need to add a new macro to the configure. There's a lot of history behind the use of the ranlib utility on archive libraries. I won't get into whether it's still useful with respect to modern development tools.
It seems however, that wherever you see it used in modern Makefiles, there's always a comment about running ranlib in order to "add karma" to the archive. You be the judge Add these two macros to your configure. Alright, once more then, but this time I'm adding the --force option, as well as the -i option to the autoreconf command line to keep it quiet about adding files that already exist.
This seems like a pointless option to me, because the entire purpose of the -i option is to add missing files, not to add all files that are required, regardless of whether they already exist, or not, and then complain if they do exist. Blessed day! It works. And it really wasn't too bad, was it? Automake told you exactly what you needed to do. I always find it ironic when a piece of software tells you how to fix your input file--why didn't it just do what it knew you wanted it to do, if it understood your intent without the correct syntax?!
Okay, I understand the "purist" point of view, but why not just do "the right thing", with a side-line comment about your ill-formatted input text? Eventually, you'd be annoyed enough to fix the problem anyway, wouldn't you? Of course you would! It seems that Automake has added yet another missing file--the "compile" script is a wrapper around some older compilers that do not understand the use of both -c and -o on the command line to name the object file differently than the source file.
When you use product-specific flags, Automake has to generate code that may compile source files multiple times with different flags for each file. Thus it has to name the files differently for each set of flags it uses. At this point, you have the following Autotools-added files in the root of our project directory structure:.
These are all scripts that are executed by the configure script, and by the generated Makefiles at various points during the end-user build process. Thus, the end-user will need these files. You can only get these files from Autotools. Since the user shouldn't be required to have Autotools installed on the final target host, you need to make these files available to the user somehow. These scripts are automatically added by "make dist" to the distribution tarball.
So, do you check them in to the repository, or not? The answer to this question is debatable, but generally I recommend against doing this. Anyone who will be creating a distribution tarball should also have the Autotools installed, and should be working from a repository work area.
As a result, this maintainer will also be running autoreconf -i --force to ensure that she has the latest updated Autotools-provided utility scripts. Checking them in will only make it more probable that they become out of date as time goes by. As mentioned in Chapter 2, this sentiment goes for the configure script as well. Some people argue that checking the utility and configure scripts into the project repository is beneficial, because it ensures that someone checking out a work area can build the project from the work area without having the Autotools installed.
But is this really important? Next: Which files are hand-written and which generated and how? Next: How do I add a Makefile. Next: How do I communicate configure test results to a Makefile?
Next: How do I override Makefile macros set by automake? Next: How can I install software below my home directory? Next: How do I add compiler or linker flags to the build system? Next: How do I use brackets in configure. GNU Autotools is a big and important piece of software that most of us take for granted. But, despite its reputation, Autotools has lots of little features that may benefit you, even if your project is a relatively simple application or series of scripts.
First of all, Autotools comes with portability in mind. With Autotools, all you need to know is what files need to be installed to what general location. It takes care of everything else.
No more custom install scripts that break on any untested OS. Autotools is also well-supported. In many cases, incorporating an Autotools project into a pipeline can even be automated. To use Autotools, you must first have Autotools installed.
Your distribution may provide one package meant to help developers build projects, or it may provide separate packages for each component, so you may have to do some research on your platform to discover what packages you need to install.
In fact, Autotools can be useful for such projects because it provides a make uninstall script for easy removal. GNU Autotools has very specific expectations, and most of them are probably familiar if you download and build source code often.
First, the source code itself is expected to be in a subdirectory called src. Create a file called configure. This file is used by autoconf to create the configure shell script that users run before building. Open the file in your favorite text editor. Craig Answered. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses.
0コメント