Linux Programing Hints
This makefile works until you define fig82.fig and forget to translate it into fig82.eps. It is also far longer than it needs to be. I will rewrite it to be much smaller, and at the same time work better. I'm going to assume that you are using GNU make, which is the standard make on Linux and some other systems. It is very easy to build on most other systems that you may have.
0: # This is an improved version of the makefile for 1: # making book.dvi 2: # FIG is a list of all the native xfig drawings 3: FIG = $(wildcard *.fig) 4: # EPS is a list of EPS files to create from the xfig files 5: EPS = $(subst .fig,.eps,$(FIG)) 6: 7: %.fig : %.eps 8: fig2dev -Lps $< $@ 9: 10: book.dvi: book.tex $(FIG) 11: latex book.tex 12: 13: print: book.dvi 14: dvips -r -Z -q book.dvi
This makefile does everything that the previous one did, and more. It introduces several new concepts along the way, some of which are unique to GNU make. The first, and perhaps the most obvious, is that I did not explicitly list all the .fig or .eps files. Listing all the files requires me to update the makefile each time I add a figure, which is rather error-prone. Using the GNU make wildcard function allows the makefile to automatically update the files correctly, no matter how many figures you add. If you choose to use it, be careful that you really mean to list all the files, and be aware that it will not work under most commercial vendors' versions of make.
GNU make has many functions like wildcard. Like variables, they are enclosed in $(...) (or ${...}), but you can distinguish functions from variables because the functions have embedded spaces. The name of the function comes first, with the argument, or comma-seperated list of arguments, following. They are all documented in Chapter 9, “Functions for Transforming Text”, in the GNU Make manual. wildcard is equivalent to the shell “globbing” that you use every day on the command line (like ls *.fig) and subst works like a very simple version of sed (like sed 's/\.fig/\.eps/g'), replacing each instance of one substring in a string by a different substring.
Another GNU make feature used is called a “pattern rule”. This is like a “suffix rule” as used in all versions of make (suffix rules still work in GNU make, don't worry), but is more powerful. The example given here is equivalent to the suffix rule
.fig.eps:
fig2dev -Lps $< $@
but the pattern rule is a more general construct. Pattern rules may by preferable if you are writing makefiles for yourself or for projects where you can guarantee that GNU make will be used, and suffix rules are preferable if you are trying to write portable makefiles for all platforms.
The reason pattern rules are more powerful than suffix rules is they can match any sort of pattern, not just suffixes. For example:
foo.% : bar.%
would be a “prefix rule”, which does not exist in other forms of make. Patterns are a more general concept than suffixes, and can be used in other ways in other kinds of rules. The GNU Make manual has examples of this.
The variables $< and $@ are special variables that can be used in rules. The $@ variable stands for the file that is being updated, the target which depends on the files that follow the “:” in the dependency. The $< variable stands for the files upon which the target depends. This is a standard make facility, and does not require GNU make.
Finally, this makefile uses a standard trick of defining a target that doesn't exist. Typing make print will print a copy of your book with everything up-to-date, even though there is no file called print. Similarily, since the first target is the default target, many makefiles have the first rule be a rule called “all:” which does whatever seems right when “everything” is to be built. In fact, the practice of typing “make all” instead of just “make” is so common that even when there is only one program to be built by default, some people will add an all target to their makefile even though it is not at all necessary:
0: all: foo
1:
2: foo: foo.o bar.o baz.o
<and so on>
instead of
0: foo: foo.o bar.o baz.o
<and so on>
This is only a taste of make. The GNU Make manual is a gentle, but much more thorough and correct introduction to GNU make, and is distributed with the GNU make source code. It does not assume that you already know how to use any version of make. On a properly installed system, it is available through the info system. The info files can be read from within Emacs (type C-h i from within Emacs) or from a standalone info reader such as info or tkinfo. Alternately, the book can be printed with the TeX typesetting system or ordered from the Free Software Foundation.
Michael K. Johnson is the editor of Linux Journal, but that doesn't keep him from hacking.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- RSS Feeds
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- Dynamic DNS—an Object Lesson in Problem Solving
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Download the Free Red Hat White Paper "Using an Open Source Framework to Catch the Bad Guy"
- Tech Tip: Really Simple HTTP Server with Python
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




5 hours 8 min ago
8 hours 20 min ago
10 hours 35 min ago
11 hours 4 min ago
12 hours 2 min ago
13 hours 31 min ago
14 hours 39 min ago
15 hours 26 min ago
22 hours 1 min ago
1 day 3 hours ago