Fri
Nov
30

Fun with Make



I usually don’t have a reason to muck around with GNU make but I find myself sitting on a train from Ronkonkoma to Jamaica (LI to Queens, in New York) with not much to do (and no internet access), so I figured I’d do some scribbling. (BTW, I’m using the shell in Mac OS X for this, but all of these commands should work fine on Linux, for using make on Windows, check out sourceforge.net for options)

The man page provides some good info but what is really helpful is the info documentation. To access it, type:

info make

Info is usually too verbose for what people are looking for when working with the shell, but since make is more than just a simple shell command it is definitely worth a read.

So, what is make?

From the man page:

“The purpose of the make utility is to determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them.”

So, think of it as a management system for your program. As mentioned in the documentation, make is not limited to compiled programs, or even programs at all. If you have some type of file that needs a command (or set of commands) executed after it is modified you can use make for the job!

An example.

So, lets create a small C program. We’ll call it junk.c:

#include

int main()
{

printf(”Hello World\n”);
return 0;

}

Simple enough, right? Good. Now, I would normally compile this program with:

cc junk.c -o junk

and once you do that, you’ll see that you have an executable called ‘junk’ which you can run with

./junk

(if not, check permissions and see if you actually have an executable file called ‘junk’)

Fine. So, lets throw make into the mix. We’ll create a file called “Makefile” (notice the capital ‘M’, the capital ‘M’ is not required, but is convention and convenient as it separates this file from your source files in the same directory) in the same directory. That file looks like this:

# Makefile
# build junk executable

junk : junk.o

junk.o : junk.c
cc junk.c

so, once you this file created, lets run the make command:

make

You should receive output similar to this:
~/junk supertom$ make
cc junk.o -o junk
~/junk supertom$

If you run make again, you should receive output similar to this:

~/junk supertom$ make
make: `junk' is up to date.
~/junk supertom$

That’s the whole idea behind the make command. It acts as a manager for your program files. If they need to be recompiled they will be, otherwise it will do nothing. May not be a big deal with our simple program but if you are dealing with lots of program files compiling only the modified files is a big time saver. To force make to recompile in this case just remove the junk executable.

Ok, back to our example. Looking at our Makefile, “junk” is the ultimate name of our executable and to build it, we need junk.o. In terms of make, both junk and junk.o are called targets. You can think of targets as appearing to the left of the ‘:’ in the file. So, the “junk” target needs file “junk.o” and “junk.o” needs junk.c. Notice the command:

cc junk.c

This is command to be run when that target is encountered. Commands that you want executed by make must be prefaced by a tab. The make utility is actually pretty smart when it comes to C files, so if you look at the makefiles for current applications it might not be so verbose. Don’t forget, however, that make can be used for other things, so take not of what is going on in our example.

Ok, lets pick it up a bit:

# Makefile
# builds the junk executable

prg = junk
objects = junk.o

$(prg) : $(objects)

# what would normally explicitly be here...
#junk.o : junk.c

# make knows what to do with .c files so you can actually leave it out
# it knows that .c -> .o
# junk.o :

# and, we can put a var in, like this:
$(objects) :

# .IGNORE gets us around the problem of rm not finding the files to delete
.IGNORE clean :
rm $(prg) *~ *.o

tarup :
tar -czf $(prg).tar.gz $(prg).c

So, what are the targets in this file? junk, clean and tarup. “junk” is our first target and is the one that will be executed if no other targets are specified. “clean” runs the rm command to remove backup and .o files and tarup executes a command to create a tarball of junk.c. So, I can execute these targets with:

make clean
make (or make junk)
make tarup

We’ve introduced some new concepts in our Makefile, so lets discuss briefly. One is the concept of variables. See prg and objects at the top? Yup, those are vars. Similar to the bash shell, we declare and initialize with no distinct chars, but then use it with $ and parentheses. You’ll also see that we’re a little less verbose about what is going on. As I mentioned earlier, make is smart about C files and knows what to do with them.

We’ve also introduced the “phony” target .IGNORE which keeps us from receiving errors from the rm command. Ever try to rm something that didn’t exist? You’ll receive an error. Maybe not such a big deal to you now, but if you try to include it in a dependent sequence of commands, like

make clean && make

make will never execute because make clean will return with a status of 1 if there are no ~* or *.o files.

So, my train ride is about over, but here are some thoughts/reasons/ideas on how/when to use make for non-compiled applications:

  • Creating a “package” out of your application - especially in web programming, we tend to think of these files as separate, but they are heavily dependant on each other. You could use make to create a tarball of your app
  • Things that need to happen before or after a “build” - update a build file with date/time information, suck in a sql file that needs to be included in the package, tag a cvs/svn branch or include some other metadata
Wed
Oct
31

My 1st California Earthquake



So, it is official: Last night at 08:04:54 PM PST I experienced my first earthquake. It had a magnitude of 5.6 and I have to say we were pretty close to the epicenter. Nothing fell off of our shelves and nothing was damaged, but the family was pretty “shaken up” (no pun intended) about the whole thing (Ok, pun intended).

Here are some links:
Recent earthquakes - it is the “big” square.
earthquake.usgs.gov
Moderate earthquake hits Northern California - Y! News

Sat
Sep
15

Finally! Upgraded my laptop to Ubuntu 7.04



Well, you guys know me - I’m a big procrastinator, but I finally upgraded my laptop to 7.04. This is pretty ironic with the forthcoming release of Gutsy, but hey, I’m usually late to the party.

So, I was happily running 6.06 on my Dell Inspiron 5150 and decided to upgrade for really no good reason. The cd-rom drive in my laptop is a little wonky so I was planning on using an external drive and doing a fresh install. At the last minute I opted for the net upgrade instead - a risky procedure - upgrades never go well.

Well for the most part, it did go well. I did the net upgrade from 6.06 to 6.10 and then again to 7.04. I had two issues, one of which is resolved. I couldn’t get the zippy desktop effects to work and it had to do with the libGl libraries. I symlinked to the previous versions and all was good. Also had to put in some stuff in my xorg.conf, but now I have those cool desktop effects. You can see what I changed here:

supertom@supertom-laptop:~$ ls -l /usr/lib/libGL*
lrwxrwxrwx 1 root root 21 2007-08-26 22:21 /usr/lib/libGLcore.so.1 -> libGLcore.so.1.0.9631
-rw-r–r– 1 root root 8961220 2007-06-25 14:33 /usr/lib/libGLcore.so.1.0.9631
-rwxr-xr-x 1 root root 9916028 2007-02-26 17:21 /usr/lib/libGLcore.so.1.0.9746
lrwxrwxrwx 1 root root 16 2007-08-26 07:30 /usr/lib/libGLEW.so.1.3 -> libGLEW.so.1.3.4
-rw-r–r– 1 root root 199848 2007-03-04 21:16 /usr/lib/libGLEW.so.1.3.4
-rw-r–r– 1 root root 653 2007-02-26 17:22 /usr/lib/libGL.la
lrwxrwxrwx 1 root root 10 2007-02-26 17:22 /usr/lib/libGL.so -> libGL.so.1
lrwxrwxrwx 1 root root 26 2007-08-26 22:31 /usr/lib/libGL.so.1 -> /usr/lib/libGL.so.1.0.9631
-rw-r–r– 1 root root 567704 2007-06-25 14:33 /usr/lib/libGL.so.1.0.9631
-rwxr-xr-x 1 root root 601272 2007-02-26 17:21 /usr/lib/libGL.so.1.0.9746
lrwxrwxrwx 1 root root 20 2007-08-26 07:30 /usr/lib/libGLU.so.1 -> libGLU.so.1.3.060502
-rw-r–r– 1 root root 521000 2007-07-13 05:23 /usr/lib/libGLU.so.1.3.060502

Unfortunately, my Netgear WG511 stopped working with WPA and I have tried unsuccessfully to fix it so far. I had originally followed the instructions on linuxquestions.org for Dapper but no luck on 7.04. I blacklisted what I believe to be the appropriate drivers and tried different windows drivers under ndiswrappers with no luck. Works fine with WEP. I have a wireless USB adapter which I might give a shot or I might just break down and buy something better supported. This laptop is now 3+ years old, but, other than a cdrom issue (meaning, it doesn’t always work) it works fine, so it would be nice to keep it around, you know?

Thu
Aug
9

What up with Yahoo!?



We’re finally settled in and I thought I’d talk about some of the cool things going on at Yahoo, some of which I’ve been directly involved in.

Hack Day

Several times a year (it might be once a quarter) the company sponsors an internal “Hack Day” for company engineers (this is different from the Open Hack Days that the company sponsors which should be coming up at the end of September). Basically, you have 24 hours to come up with something cool and present it to the judges and your peers. To be clear, this is a work-sanctioned event - all work stuffAlthough I can’t go into specifics, I am very proud of my team’s Hack Day project. Admittedly, I contributed a small (but very prominent, I must say) piece to the Hack given my schedule (my cats were coming in from NY AND my furniture was being delivered all within those 24 hours) but we did make the top 25 and were actually singled out by Ramus on an internal mailing list as a hack that he really enjoyed. Very cool. Congrats to the team!

YSlow (no involvement, but we use it all the time)

Hopefully you’ve heard about YSlow. YSlow is a Firebug extension to help with site performance. YSlow scores are taken seriously inside Yahoo and it is a good (but certainly not the only) indicator of your sites performance. Read more about it here.

Yahoo Go for TV (no involvement, but very cool technology and killer release party)

The mashup between TV and Internet is inevitable and Go for TV brings it that much closer. See your favorite Yahoo content while watching TV and also take advantage of the DVR features. Windows only right now (hey, Linux folks, they’re hiring engineers for the Linux port, get me those resumes!). Find out the scoop and download from the Yahoo! Go site.

And for all the latest with Yahoo, you don’t need to wait for me, just check out Next @ Yahoo.

…and some fun stuff….

Great America

Great AmericaThe Media Engineering Group (to which I belong) was given the afternoon off and free passes to Great America. We had a great year with some outstanding accomplishments and this was a awesome way of the higher-ups to say thanks to the people who make it happen. Engineers are actually the folks “on the ground” when it comes to bringing a project to the finish line. The idea folks, the designers, operations, customers, special teams have all had their input and requirements, but really, it is the engineer that is given all of this and told to make it work. I’ve seen this quite often throughout my career and it is really nice to not only be recognized for the actual job that is done but to be appreciated in that way. Yahoo is good to us like that.

As many of you know, I’m a big baby when it comes to amusement park rides but I still managed to have a good time with the team.

Camp Yahoo

Camp Yahoo 2007Also, we just had Camp Yahoo a couple of weeks ago. Camp Yahoo is the company picnic and was held at the San Mateo events center. Lots of food, games and rides, and of course, free for employees and their families. Heck, Elissa and I even got to ride a Segway. Evan? Sorry, kid, you don’t meet the height requirement just yet. :-)

Tue
Aug
7

What’s up, LILUG!



Hello to all of my friends and colleagues at LILUG who are now reading this via Planet LILUG. I’m honored for my blog to be syndicated there and I hope to provide useful and interesting topics to those readers. Otherwise, just skip over my posts. :-)

Thu
Jul
19

More California-isms



Well, not really ‘-isms’ and not necessarily only in California, but especially (meaning only) pertaining to roads and food, the only two things that really affect my life at the moment.

The roads and signs - crazy. Signs in weird places or behind trees are standard fare. In fact there are several places I can think of that actually have a sign to turn for a particular road ON the exit for the road, giving you zero chance to read it in time. Other interesting road and sign traits:

  • Not unusual for two streets with almost the same name to intersect.
  • The designation of “expressway” is meaningless. Roads designated as expressways have traffic lights, intersections, retail stores and maybe exits to get on or off.
  • Speaking of exits, it is not unusual for an exit to lead you to another road with exits, but you won’t know this until you’re on that road and really probably won’t know until you missed your turn.

Yes, driving has been fun here in CA.

Iin and Out signIn other news, I had some interesting fast food over the weekend. I started out with In-and-Out burger. I had this once before back in April and the results where the same. Good burger, OK fries. I opted for the strawberry shake and I’m sorry to say it was gross. I had to throw it away.



WienerschnitzelOK, here’s the big news. Many people are aware of my dislike for hot dogs, yet I actually ate at a Wienerschnitzel and it was pretty good. Of course, I didn’t eat any hot dogs. As I expected, they had a pretty full selection of non-hot-dog related food. Who eats hot dogs, anyway?




Noah’s New York BagelsFinally on food front, as native New Yorker, I had to try Noah’s New York Bagels. The verdict? I miss NY bagels.

In other news, My car arrived! I am no longer held captive by the rental car companies.

WooHoo!

Yes, you heard me. I also went to the Kwik-E-Mart in Mountain View. If you haven’t heard, several 7-elevens have been transformed into Kwik-E-Marts as a promotional stunt for the new Simpsons Movie. I have box of Krusty O’s on top of my cube. Too bad they don’t sell Duff Beer.