On walkabout in life and technology

The Simple C++ Makefile - Executable Edition

I develop a lot of applications in C++ using Xcode on OS X and deploy them to CentOS Linux Servers to run. I follow the Simple C++ Project Structure (and the Xcode edition) to code up each product.

However, Xcode is not available on Linux. To compile and deploy (and to test compiles and deploys), I use standard Unix Makefiles, available almost everywhere.

In this post I will show you the Makefile I use for multi-platform C++ executable builds and explain what each line and command does in detail. For Library builds, I have a similar, but different Makefile, see The Simple C++ Makefile - Library Edition (Coming Soon).

The Standard Project

I have selected one of my real projects for this post. The project is laid out as follows (most of the source files have been removed to shorten the list):

├── Makefile
├── README.markdown
├── SantaCruzServer.xcodeproj
├── doc
│   └── SantaCruz-dev.yml
├── include
│   ├── caches
│   │   └── session_cache.h
│   ├── components
│   ├── connections
│   ├── queues
│   ├── workers
│   └── version.h
└── src
    ├── caches
    │   └── session_cache.cpp
    ├── components
    ├── connections
   ├── workers
    └── main.cpp

As expected, the C++ source files are under the src folder and includes are in the include tree.

And here is the Makefile, the actual one I am using. Scroll below to see the breakdown and why I did it this way.

#  Makefile
#  SantaCruzServer
#  Created by Hilton Lipschitz on 2015-09-01.
#  Copyright (c) 2015 Maritime Capital LP. All rights reserved.

# HIL: No spaces or comments after otherwise it captures them!
# Determine the platform
UNAME_S := $(shell uname -s)

# CC
ifeq ($(UNAME_S),Darwin)
  CC := clang++ -arch x86_64
  CC := g++

# Folders
SRCDIR := src
BUILDDIR := build

# Targets
EXECUTABLE := SantaCruzServer

# Final Paths
INSTALLBINDIR := /usr/local/bin

# Code Lists
SRCEXT := cpp
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))

# Folder Lists
# Note: Intentionally excludes the root of the include folder so the lists are clean
INCDIRS := $(shell find include/**/* -name '*.h' -exec dirname {} \; | sort | uniq)
INCLIST := $(patsubst include/%,-I include/%,$(INCDIRS))
BUILDLIST := $(patsubst include/%,$(BUILDDIR)/%,$(INCDIRS))

# Shared Compiler Flags
CFLAGS := -c
INC := -I include $(INCLIST) -I /usr/local/include
LIB := -L /usr/local/lib -lsantacruzengine -lsantacruzlib -larcadia -lcorinth -lyaml-cpp -lzmq -lhiredis -lbondoas

# Platform Specific Compiler Flags
ifeq ($(UNAME_S),Linux)
    CFLAGS += -std=gnu++11 -O2 # -fPIC

    # PostgreSQL Special
    PG_VER := 9.3
    INC += -I /usr/pgsql-$(PG_VER)/include
    LIB += -L /usr/pgsql-$(PG_VER)/lib
  CFLAGS += -std=c++11 -stdlib=libc++ -O2

  @mkdir -p $(TARGETDIR)
  @echo "Linking..."
  @echo "  Linking $(TARGET)"; $(CC) $^ -o $(TARGET) $(LIB)

  @mkdir -p $(BUILDLIST)
  @echo "Compiling $<..."; $(CC) $(CFLAGS) $(INC) -c -o $@ $<

  @echo "Cleaning $(TARGET)..."; $(RM) -r $(BUILDDIR) $(TARGET)

  @echo "Installing $(EXECUTABLE)..."; cp $(TARGET) $(INSTALLBINDIR)

.PHONY: clean

Breaking the Makefile down

This Makefile compiles a program called SantaCruzServer into the local bin folder, and installs it into the standard shared OS X and Linux /usr/local/bin folder. Lets see how it does it, line by line.

UNAME_S := $(shell uname -s)

The first step is to determine which platform the make is running on. I look for Darwin indicating an OS X computer or Linux for Linux.

# CC
ifeq ($(UNAME_S),Darwin)
    CC := clang++ -arch x86_64
    CC := g++

OS X uses the new LLVM Clang compiler (I choose the C++ version), but my Linux servers run GCC 4.8. The $(CC) variable now contains the compiler command for the current platform.

# Folders
SRCDIR := src
BUILDDIR := build

These variables set the location of the Source Code (src), where the build object files will go (build) and where the target will be saved (bin).

# Targets
EXECUTABLE := SantaCruzServer

This sets up the Makefile target to make bin/SantaCruzServer. Note that, by default, this Makefile builds to a local bin folder so it does not overwrite the running application in case of a failed compile on deploy.

# Final Paths
INSTALLBINDIR := /usr/local/bin

This sets where the executable will be installed.

# Code Lists
SRCEXT := cpp
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))

Make needs a list of source code files to compile to object files. This list gets built here. I use the $(SRCEXT) variable to store my source code file extension. I then use a shell command to search the src folder (and its subfolders) for all .cpp files and build the $(SOURCES) list. I then create an $(OBJECTS) list from the $(SOURCES) substituting the source path and extension with the build path and the object extension. This makes our compile rule simpler.

# Folder Lists
# Note: Intentionally excludes the root of the include folder so the lists are clean
INCDIRS := $(shell find include/**/* -name '*.h' -exec dirname {} \; | sort | uniq)
INCLIST := $(patsubst include/%,-I include/%,$(INCDIRS))
BUILDLIST := $(patsubst include/%,$(BUILDDIR)/%,$(INCDIRS))

The next set of lists are used to build the list of include folders and related lists.

Aside: I am one of those quirky C++ programmers that does not use pathed #includes (e.g. Instead of #include "../caches/session_cache.h" I simply use #include "session_cache.h") and expect the compiler to figure it where things are. This way I can re-arrange the code-base by moving files around, not change anything and it still compiles and runs. Xcode behaves the same way by default.

So, the $(INCDIRS) variable contains a unique list of subfolders under the include folder where all my header files reside. The $(INCLIST) variable is a transformation of $(INCDIRS) into the format needed as compiler flags. For example include/caches is transformed into -I include/caches. The $(BUILDLIST) variable creates a list of pathed subfolders for the build folder, where include/caches becomes build/caches for the compile step.

# Shared Compiler Flags
CFLAGS := -c
INC := -I include $(INCLIST) -I /usr/local/include
LIB := -L /usr/local/lib -lsantacruzengine -lsantacruzlib -larcadia -lcorinth -lyaml-cpp -lzmq -lhiredis -lbondoas

Most of the compiler flags are shared across both platforms and are set here. In this case, $(CFLAGS) is set to tell the compiler to compile only.

The $(INC) variable is set to help the compiler find include files automatically, so it adds the include folder where the root header files are, the list of include subfolders determined above and the system shared /usr/local/include folder for shared library includes. Now I no longer need to worry when I move files around the code-base.

The $(LIB) variable adds the shared system /usr/local/lib folder where the shared libraries can be found. The rest of that line contains a long list of libraries that this real program needs to link with (and is project specific - you need to set these for each project based on that project’s needs). Note that all my shared libraries are in /usr/local.

# Platform Specific Compiler Flags
ifeq ($(UNAME_S),Linux)
    CFLAGS += -std=gnu++11 -O2 # -fPIC

    # PostgreSQL Special
    PG_VER := 9.3
    INC += -I /usr/pgsql-$(PG_VER)/include
    LIB += -L /usr/pgsql-$(PG_VER)/lib 
    CFLAGS += -std=c++11 -stdlib=libc++ -O2

Not all settings are the same, which is why the Makefile now adds platform-specific parameters to our variables.

On Linux, I use the gnu++11 system library (to go with g++) and this gets added to the $(CFLAGS) variable. Also, for some unknowable reason, the PostgreSQL include and library files are in a non-standard location in Linux, so they get added to the $(INC) and $(LIB) variables too.

On OS X, I set clang to use the c++11 language and to link with the libc++ system library.

    @mkdir -p $(TARGETDIR)
    @echo "Linking..."
    @echo "  Linking $(TARGET)"; $(CC) $^ -o $(TARGET) $(LIB)

As a habit, I set the final goal of the Makefile first. In this case, make needs to make the $(TARGET) which is bin/SantaCruzServer given the list of $(OBJECTS) we generated above.

First it creates the bin folder if it does not exist, then links the objects into an executable. The $^ represents the list of targets.

Aside: I am also not one of those people who has to see a busy screen of detailed commands as they compile. So, for Makefile rules, I prepend them with a friendly message and do not print out the actual multi-line incomprehensible command. See the output later on for examples.

    @mkdir -p $(BUILDLIST)
    @echo "Compiling $<..."; $(CC) $(CFLAGS) $(INC) -c -o $@ $<

The Makefile needs to know how to generate the $(OBJECTS), and that’s where the compile step comes in. For all files in the src folder, it compiles to a matching object file in the build folder.

That’s all we need to build the application, but the Makefile has to do more.

    @echo "Cleaning $(TARGET)..."; $(RM) -r $(BUILDDIR) $(TARGET)

The clean target tells make to remove the target bin/SantaCruzServer and the build folder. This gives us the ability to force a full recompile.

    @echo "Installing $(EXECUTABLE)..."; cp $(TARGET) $(INSTALLBINDIR)

The install target copies SantaCruzServer to /usr/local/bin where it will run in production.

    @echo "Removing $(EXECUTABLE)"; rm $(INSTALLBINDIR)/$(EXECUTABLE)

And to uninstall, we have the distclean target.

.PHONY: clean

This final line of code tricks make into being able to run the clean rules. If it were not here, make would try to build a file called clean and fail.

Using the Makefile

To start

$ make clean

This resets the environment. The output in this project is:

Cleaning bin/SantaCruzServer...

To build the executable

$ make -j

This tells make to build the primary target - in this case the first and only one in the file.

Tip: The -j parameter parallelizes the build for speed. The documentation for make specifies that you need a number of jobs as part of this parameter, but if you set none, make uses all cores.

In my case, the output is:

Compiling src/connections/control_channel_responder.cpp...
Compiling src/connections/request_listener.cpp...
Compiling src/connections/response_publisher.cpp...
Compiling src/caches/session_cache.cpp...
Compiling src/main.cpp...
Compiling src/sc_configuration.cpp...
Compiling src/sc_logger.cpp...
Compiling src/sc_server.cpp...
Compiling src/workers/worker.cpp...
Compiling src/workers/worker_pool.cpp...
  Linking bin/SantaCruzServer

The executable can now be found in bin/SantaCruzServer and run.

$ bin/SantaCruzServer
2015-09-28 21:50:53.999 Info: SantaCruz V0.01 Alpha Server Starting...
2015-09-28 21:50:53.006 Debug: Using SantaCruzLIB Version 0.1 Alpha
2015-09-28 21:50:53.013 Debug: Using SantaCruzEngine Version 0.1 Alpha

To install the executable in production:

sudo make install

This will copy the new executable into production. For development deploys, you do not need the sudo.

The output is:

Installing SantaCruzServer...

And to uninstall:

$ make distclean
Removing SantaCruzServer

And the executable is all gone.

Reusing this Makefile in the next project

The entire Makefile can be copied to the next project. Only a few changes are needed:

  • The $(EXECUTABLE) name needs to change for the new project
  • The list of libraries in the $(LIB) variable needs to match the libraries linked to by the new project.
  • If PostgreSQL is not needed, remove it from the Linux Platform Specific Compiler Flags (and remove the $(INC) and $(LIB) additions).

And that’s all there is to it.

I am using this same Makefile pattern across many, many projects and it works well for me. I hope it can help you compile and deploy your C++ projects with ease.

Follow the author as @hiltmon on Twitter.

Saturday Afternoons Watching Rugby Union

Growing up, Saturday afternoons were for watching Rugby Union games with friends and family. No matter what was going on at home, with friends, at school, or in the country I lived, the world stopped for the two games that were televised live. I am as far away from that world as one can be, yet it is with me right now.

It began with my grandfather. He played as a kid as evidenced by a hook nose and a deep understanding of the game. There were only two times we could not bother him, his post-lunch nap, and when the rugby was on. But if we were there when the game was on, he would talk, explaining the rules, the nuances, the players positioning and decisions. Rugby was real-time, dynamic chess for him, a thinking person’s sport, and he imbued that thinking, understanding and love of the game in all his grand-children.

We spent a lot of time in Cape Town as young kids. And much of that time was spent playing an ongoing game of Rugby with the cousins and neighborhood kids in my Aunt’s garden. When we arrived at the beginning of a vacation, her lawns were always perfect, flowerbeds immaculate and colors delightful. Within days, the garden was completely and utterly destroyed. We’d tackle each other into the flowers, ruining them. We’d ruck and maul deep gouges into the perfectly cut grass. When a ‘pile-up’ was called, all kids would dive in, wrecking everything. And she never said a word. There was no where else we, the kids, wanted to be but in the game, unless a real game was on for us to watch. Newlands in Cape Town always had cheap bleachers seats for us kids, right up close to the field where we could see our heroes play.

When I got older, and we finally received our own TV, our weekends revolved around the games. Friends, never invited nor needing to be invited, came over. I have no idea how many meals my mum served a bunch of rowdy, hungry, growing boys in those days, nor how many beers we quaffed as we got older and started drinking. And she never said a word. Those friendships have lasted a lifetime and remain as strong as ever, even though we are worlds apart.

And later on, even older, I went to the games. More often than not, my best mate and I would just arrive at the stadium, buy some scalped tickets for the members section and go in to watch the game. I’m not even sure we even cared who was playing sometimes, as long as we did it. Watched Rugby together.

International games were never missed. We’d get together wherever we were, have a barbecue and watch. In Japan, a friend set up a projector and screen for the big games. The Bledisloe Cup games between Australia and New Zealand were the high point of each season. Then came the Super League and the Five (now six) Nations championships. Better games, more internationals, more opportunities to hang out and enjoy.

And now there is the World Cup. The best of the best. I have rarely missed watching a World Cup Rugby game live. When Australia beat England in 1991, we were watching. When South Africa won and overcome its racial divide in 1995, we we watching. France beating the All Blacks in 1999 was the best game ever (until Japan vs South Africa yesterday maybe), and we were watching. Johnny Wilkinson’s drop goal in 2003 to aid England defeating my Australia broke our hearts, and we were watching.

This weekend I watched the first 7 of the 8 World Cup 2015 games live online. I am here in New York, far away from friends and family, from where I come from. But I was not alone. I know those kids I played with all those years ago were doing the same, wherever they are. I know my family and cousins were watching, sharing our love of the game and each other with the next generation. And I know my mates were doing the same too. All of them were on the couch with me, cheering, commenting, calling out the refs, pointing out tactical errors and debating the players and rules.

The love of watching Rugby taught us a lot as we grew up. It taught us to think, to debate, to love, to really communicate, and to be better friends. It drew this nerd out of his shell - too far some say. It showed us that even though the game may just be a game, sportsmanship, courage, honesty and strength come from the head and the heart, not the muscles. It taught us to share and to enjoy the precious moments.

Saturday afternoons were for watching Rugby with family and friends. Decades later, we’re still watching Rugby as eagerly as ever. Even though we are thousands of miles away from each-other, we’re not alone in our love for each other or the game that drew is in.

Follow the author as @hiltmon on Twitter.

The 'It Has Happened Before, It Will Happen Again.' Apple

The Apple I know and loved was doomed, so the press said. It was the crazy, emo teenager of a company. Willing to try anything, mad, crazy, radical, different and apt to succeed and fail in spectacular fashion. Against all odds, the Apple of old did not fail. Because of this we now have amazing computers, thin and light laptops, iPods, OS X, iPhones and iPads. Can you imagine a world without Apple products?

The modern Apple has grown up, thanks to Steve Job’s maturity, Tim Cook’s solid, intelligent leadership and a team of experienced people taking ownership, saying no and getting things done the Apple way. It’s the grown up but still young adult. Smart enough to know its limits, but still daring enough to challenge the status quo and push the envelope. Because of this we now have solid and mature Operating Systems, a regular update schedule, and reliable iCloud. Yet the old teenage Apple is still pushing its limits with Apple Music, Apple Pay, the Apple Watch and maybe something in TV.

What Apple is trying to do is hard. Its blitheringly hard to make good software, ridiculously hard to make hardware that’s both functional and beautiful, and insanely hard to perform and perfect design and documentation and support and services and research and manufacturing and distribution. The modern Apple does it all, and on a regular schedule no less. Its seemingly impossible, yet year after year, they keep up the pace.

Next week will be the second of their annual announcement extravaganzas. The surprise is gone, we know how it will work, the keynote, the players, the japes and jokes, and roughly what will be announced.

Its the “It has happened before, it will happen again.” Apple.

Solid, stable, regular, mature.

But not boring.

The teenage Apple released products when it could, letting product lines wither and seem abandoned until a major new release ambush or product death. The modern Apple still does this for new innovations and hobby products, Apple is still Apple. But for mature products, it now operates on a mature schedule. New OS X and iOS annually, new iPhones and iPads annually, amazingly all shipping on time to massive numbers of people world-wide.

In my opinion, the grown up Apple has found a wonderful balance. For maturing products, a regular update schedule, with a few surprises thrown in for good measure (Swift is an example) to show they still have it. For new innovations, the surprise and wonder of old remains. The recent Apple Watch and Apple Pay launches prove it.

So next week, I too will be following a regular schedule, closing the door to my office, watching the live stream of the Apple event, laughing at the jokes, seeing if there are any new features being announced on existing products, and waiting to hear the launch dates for the new OS X and iOS and iPhone and iPad.

I know the script. We all do.

Except for one part.

One more thing.

At some point (or maybe more than once), Apple’s presentation will pause. The crowd will go silent. The corner of the speaker’s mouth will curl up in a smirk. We will all hold our breaths. They will wait a moment longer.

And then they will announce “one more thing”.

The modern grown-up Apple will slip away, the gleeful teenage Apple will stand tall on the stage, and maybe, just maybe, will change the world again.

Follow the author as @hiltmon on Twitter.

Open Extension-less Files in Your Favorite Editor on OS X

Xcode does a horrible job of editing Makefiles (and other extension-less files like dot-files). If you right-click in Xcode on a Makefile and Open with External Editor, OS X opens it in TextEdit. Which is worse.

The issue is that TextEdit is associated with extension-less files. Usually to change how files are opened, you select the file in Finder, right-click and choose Get Info from the menu. You then choose the editor in the Open with dropdown and click Change All…. But this does not work for extension-less files, it throws the below error.

The solution is to use RCDefaultApp to change this association.

Install it now, its free. I’ll wait.

Once its installed, open Default Apps from System Preferences, go to Apps and select the application you prefer for extension-less files, I use trusty BBEdit if course. Scroll down to find the public.data UTI, check it and click Set as Default. Extension-less files should now open in BBEdit from Finder and from Xcode.

I figured out the necessary UTI using the command mdls Makefile and seeing that the system had it as “public.data”. Many other sites say using “public.text” is the correct mapping but that did not work for me on OS X 10.10 Yosemite.

Follow the author as @hiltmon on Twitter.

How the Apple Watch Has Changed My Behavior for the Better

I have the nerd watch, the 42mm Space Gray Aluminum with the Black Sport Band. It was ordered at launch and arrived late. I have been wearing and using it every day since.

The Apple Watch is a perfectly good watch for doing watch-like things, like telling the time. But if you view it as a wrist computer, one that has had a real impact on how one acts and behaves, it is something uniquely special.

And it has changed my behavior patterns, without me knowing about it, for the better.

Let’s start with the initial time-checking glance itself. In my case I have the rings, the temperature, the date and my next appointment added to the utility face. Invariably I am looking for the time and the analog face presents that clearly.

The first behavior change comes when I see the red dot at the top - indicating unread notifications. To explain the situation, a short digression. The iPhone presents notifications on the lock screen. And I, like all of us, used that a lot. Before Touch ID, I would tap on the home button to wake my phone and glance at the notifications. If anything looked important (or interesting), I’d unlock my phone and go take a look. Touch ID messed up that pattern. I would touch the home button to see the alerts and instead, the iPhone would log me in and show me the home screen - not what I wanted. It took a while to retrain my lizard-brain to tap the power button to see notifications instead of the home button. And then they moved the power button on the iPhone 6 which reset my home-touch-to-see-alerts behavior. Which meant I went back to unlocking the iPhone to open apps to see if anything happened.

With the Watch, if I see the red dot, I just swipe down. The notifications are always there, easy to find and read. And yes, I have gotten into the behavior of using the digital crown to scroll them. I also force-touch to delete them when read, so next time I only have to deal with new alerts.

The result of this behavior change is that I spend less time trying to see if there are notifications for me.

The second behavior change comes when I actually read a notification. Which requires another digression. Swiping a notification on the iPhone takes you to the application that sent it. Easy. Which is what I used to do. I’d then deal with that one, but then would find that I had forgotten what other notifications were there before, and locking and unlocking the iPhone clears them. Swiping down categorizes them by app, when arrival time order would be better. So I would check my Twitter, Facebook, email and other applications in case I forgot about a notification there too. Each time I pulled out my iPhone to check notifications, I would spend minutes jumping around applications looking at other things, and then forgetting my place in what I was doing before checking notifications. We all do this, whether we are aware of it or not.

With the Watch, I rarely feel the need to process notifications. If a notification comes in, I do glance to read and absorb it. Most of the time, it seems, I now realize that it does not need my full attention and get back to doing what I was doing. No more going down iPhone rabbit holes, no more losing my train of thought.

And when I do need to respond, then, and only then do I reach for my iPhone. But since I have to reach for the iPhone, I find that I have started checkpointing what I am doing (I make a note, I add a ‘HERE’ comment, etc) and then reach for the iPhone. Once I am finished with that one and only response, I get back to work. I do not look to see if I missed anything, they are still on the Apple Watch and I can get back to them later. Of course, when I am not sure what I may have missed, I swipe down again on the Watch to see.

The result of this behavior change is that I spend less time processing notifications, way less time futzing on my iPhone and more time being productive.

The third behavior change comes when I have a few moments between tasks. In the iPhone days, that meant I had time to spend on the device. I could check email, Twitter, Facebook, my calendar, the latest news and sports and then get back to work. The reality of it was that the time spent on the iPhone was more than a few moments, it could take up a quarter hour or more.

With the Apple Watch, I check my glances instead. Swipe up and the Fantastical glance shows me my next appointment, the OmniFocus glance my next task and the MLB At-Bat glance just how badly my team is doing this year. Since these change so rarely, I actually get back to what I should be doing quicker. I check email, Twitter and Facebook less, relying on notifications in case I need to do something. Otherwise, I make time during the day between major tasks to process these. Less time in email, more time productive and, it seems, no impact on how I communicate with people.

The result of this behavior change is that I spend more time on task, and then focus and respond more clearly when on email and social networks.

And then there are the activity rings: move, exercise and stand. They have changed a lot of my behavior. Digression? Sure, why not. Back in the day when I was younger, sprightlier and more active, I used to use the Nike sports watches to track my running or riding. Later on, when the iPhone got better, I’d use apps like RunKeeper to goad me into exercising.

One thing has not changed. I have been walking to work (when not working at home) for 15 years now, first in Tokyo and now in New York. I never thought of that as exercise or healthy, just convenient. But I started doing less of that over the past year as my feet and back have started to ache as the wear and tear of many miles kick in. So I started walking less and taking the subway more.

The activity rings on the Apple Watch have lured me back. The blue stand goal is, for me, the easiest to achieve because I use a standing desk at work. The Watch does seem to think I am sitting when standing sometimes, but that’s OK (see the stand alert below).

The green exercise goal is harder to achieve, but thats where the walking comes in. I now kick off an “Outdoor Walk” exercise when I leave to walk home. Before the Watch, if my feet or back ached, I’d grab the subway. Now, I feel the need to complete the green, so I walk. And I try walk the long way round. It adds minutes to my walk, I walk further, and I get closer to the exercise goal. And when I get home and the green is still not completed, I feel bad. I may then go downstairs and hit the treadmill for more.

The red ring, move, is the hardest target to reach, even with the daily commute walk. Mostly because I have set it a tad high. Intentionally so. When I first got the Watch, I took a few days of walking and running to find a reasonably high-exercise day and see what the move (calorie) number was. Then I set the goal to that. I know I will not achieve the move goal on days where I work and then go out at night, thereby skipping additional exercise (I still walk everywhere so the green exercise still gets filled). But on days when I have nothing to do after work, the red ring calls. It draws me into walking more, going places and doing things.

The result of this behavior change is that I walk more. But since that is not enough, I just purchased a bicycle. Less stress on feet and back, and less excuse not to go out and exercise. We’ll see how this works out.

The Apple Watch, as part of the rings, sets off a stand alert every hour. I assume this is for people who actually sit all day and should stand to achieve their blue goal. For me, this alert has a far better outcome. Final digression. I pretty much program all day. Which means I get onto the zone; and lose complete track of time. If it were not for my colleagues, I’d forget to eat lunch. If it were not for calendar alarms, I’d forget to make calls or go to meetings. And since I have few lunches and meetings, it is not unusual for me to stare at the screen for many, many hours on end oblivious to time. The result, I need glasses and I get eye strain headaches. My old solution was to get better glasses.

With the Apple Watch, the tap to remind me to stand feels unique, and my lizard-brain has picked up on this as a way to get me to look away from the screen. When in the zone, I can easily ignore all alert sounds and taps, but not this one. This one makes me look at the watch (probably because it feels like no time has passed since the last one). And once I see this alert, I realize time has actually passed. I now snapshot my work, look away, drink some water, walk to the kitchen to refill my cup, glance around to see if anybody needs me, and then get back to work.

The result of this behavior change is I remain better hydrated, but more importantly, its easier on my eyes, leading to fewer, weaker eye-strain headaches.

Having and using an Apple Watch in my case has actually made me more productive, less distracted and is pushing me on health. It has changed my behavior to do so, without me actually thinking about it, being forced into it or fighting it. Some of the results are easier to observe, the fewer headaches and the improved productivity are noticeable. And the exercise improvements are starting to show.

Follow the author as @hiltmon on Twitter.

The Productive Mac Mindset

I have been using a set of productivity enhancement tools on my Mac for so long now that the standard, out-of-box OS X user experience seems challenging, crawling, cumbersome and somewhat convoluted.

So much so that it has become frustrating for me to use another person’s Mac.

In this post, I intend to outline how the limited set of productivity tools I use give me “ludicrous speed”. Note that I have invested the time to learn these tools and to create the productivity shortcuts they provide. Maybe it will help you with ideas to be more productive too.

Keyboard Maestro

Keyboard Maestro is my primary productivity tool. Over the years I have added more and more macros to the point that I forget how to do things without them. It has also replaced other productivity utilities as its functionality has grown. Keyboard Maestro initially started out as a way to run a series of commands using keyboard shortcuts and has grown into a tool that can do these from menus, from application launches, startup, disk mounts, even scheduled. If you can imagine it, it can probably do it.

My Keyboard Maestro macros include:

  • Launching new Safari windows from a keyboard shortcut, with additional shortcuts for Rails development, the common web applications I open at work or blog posting. For less common sets, I use the menu feature.
  • Shortcuts to speed up blog article creation.
  • Markdown tools to enable markdown formatting in other applications.
  • Setting fixed width text in Mail messages (for code snippets) with a single keystroke.
  • Mounting and un-mounting the network shares at work.
  • Kicking off iTerm 2 sessions, either a single new shell or a set of shells remotely logged into our servers and running key applications. I launch complex development environments with a single keystroke.
  • Preventing me from ⌘Q in Safari and losing all my windows.
  • Generating and sending product release notes.
  • Creating tweets and Facebook links for new blog posts.
  • Reopening a page in Google Chrome on the rare occasions I need to see Flash content.

For example, to spin up my test environment which involves launching six applications, log viewers, a web server and a calculation engine, all in different terminal windows arranged so I can see what is going on, I could manually create new terminals for each application, type in the command to launch each one, then rearrange the windows. Which takes a lot of time.

Or press a single key and let Keyboard Maestro do it for me.


TextExpander then takes over to reduce the number of keystrokes to type almost anything. In many cases, I have TextExpander snippets for specific applications.

My TextExpander quiver includes:

  • My source code snippets for headers, code blocks and other common patterns. This allows me to use them across IDEs.
  • Expansions in the terminal for:
    • Changing to project folders.
    • Launching applications.
    • Managing git with fewer keystrokes.
    • Build (make) commands.
    • Popular rake commands.
  • Typing symbols (who ever remembers the keys to press to get these).
  • Frequently retyped email content.
  • Additional snippets used for blogging in Octopress.
  • Common blocks of Markdown text.

For example, to build my current product, I type ;cdcbs (which expands to cd ~/Projects/Maritime/cb/ChesapeakeBayServer) to change to the product folder, then ;m8i (which expands to git pull; make clean; make -j 8; make install). So much faster.

It has taken a lot of time to create the macros, perfect them and convert them into habits. But the time invested has paid off incredibly. These two products on their own as configured enable me to spend more time on the keyboard, more time thinking and programming and significantly less time doing manual labor on the computer. And that means I get more done in less time with fewer frustrations and screw-ups.

Three More

There are three additional tools that in their own ways complete the limited package: 1Password, Hazel and Mail Act-On.

1Password does one thing well, it manages all my passwords so I only have to remember one. It speeds me up as I use it as a web site launcher and I never lose time mistyping passwords. ⌘\ in 1Password is your friend!

Hazel takes care of housekeeping for me, so I do not have to. It cleans up my desktop and downloads folders, it files my bills and creates OmniFocus payment reminders. The hardest part of using Hazel is to figure out what you want it to do for you, setting that up and forgetting about it is the easy part.

And Mail Act-On gives Apple’s Mail superpowers. We all get too much email, and, unfortunately, we need to hang on to it. I mainly use Mail Act-On for its single key shortcuts to file emails in folders and keep my Inbox clean (but not zero).

There are Others

You may have noticed that the two most popular productivity tools, LaunchBar and Alfred are not mentioned. I used to use them a lot, and both are still installed, just not running. With all my Keyboard Maestro macros running well, I was down to using them as application launchers only. I tried using Spotlight in Yosemite as an Application Launcher, and it worked well enough to stick.

Consider the amount of time you spend performing menial tasks on your computer, launching the same windows, typing in the same commands and text, filing, tidying up, doing the same thing over and over again. Computers are awesome at this, and these productivity tools make it easy to set up and do. The money invested in buying these tools and the time invested in setting them up pays off tremendously. To the point that the OS X experience without them seems slow and cumbersome.

Follow the author as @hiltmon on Twitter.

C++11 on CentOS 6.6

As mentioned in previous articles, I write a lot of C++11 code on OS X but deploy it on CentOS Linux 6.6 servers. But CentOS 6.6 does not contain a C++11 development environment by default.

Here’s how to set one up.

Install a C++11 Compiler

We need to get the repo files for DevTools2, a Red Hat package that contains a supported C++11 compiler. As root, run the following command to retrieve the repo file:

wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo

Then install the compiler and support tools:

yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++

Before you can compile C++11 code with the DevTools2 compiler, you need to enable it in a new shell:

scl enable devtoolset-2 bash

All compiles in this new shell will use the new compiler.

Make it permanent

In your .bash_profile, add at the bottom:

echo "WARNING: devtoolset-2 is enabled!"
. /opt/rh/devtoolset-2/enable

All new shells you create will use the new tools.


Follow the author as @hiltmon on Twitter.

In the Press: This Week's Hedge Fund Alert

I’m quoted in Hedge Fund Alert, Aug 5, 2015, reproduced without permission.

Muni-Bond Firm in Growth Mode

Municipal-bond investor Maritime Capital is adding staff and developing its own trading technology amid a sharp increase in assets under management.

The New York firm, whose assets ballooned from $150 million to $325 million in the past six months, hired Jarret Roth from Bank of America last month as head of strategy and risk management. His arrival coincided with the launch of an execution-management system Maritime built in-house after outgrowing vendor-supplied software it had been using.

Maritime is among a handful of hedge fund shops specializing in municipal bonds. The firm, founded in 2010 by Greg Gurevich, has capitalized on increased market volatility tied to expectations of rising interest rates. Adding to the turmoil is the fact that many banks have scaled back their market-making efforts in the face of more costly regulatory-capital requirements.

Unlike conventional long/short equity funds, which have access to state-of-the-art trading software developed by Advent Software, Eze Software, REDI Global Technologies and many others, municipal-bond managers have few options when it comes to off-the-shelf technology products. Maritime, for instance, had been relying on what chief technology officer Hilton Lipschitz described as “repurposed” software that an unidentified vendor had developed some 15 years ago.

Unsatisfied with the software’s capabilities, Lipschitz spearheaded the development of a proprietary system capable of processing vast amounts of data. Consider that the universe of municipal bonds includes some 2.1 million potentially tradable issues, with an average of about 50,000 different bonds changing hands each day, according to Maritime.

“Compare that to the number of securities in other asset classes and your head is already exploding,” Lipschitz said.

The in-house system went live last month. “Things that took five minutes now take a few seconds,” said Lipschitz, who joined the firm in 2013.

The rapid build-up of Maritime’s asset base followed the arrival in January of Christine Egan, the firm’s first full-time marketer. She previously worked at fund-administration shop Kaufman Rossin Fund Services.

Follow the author as @hiltmon on Twitter.

Simple C++: From Makefiles to Xcode Builds

This post will present a step-by-step process to convert C++/C++11 Makefile-based projects to Xcode build tools. I use it all the time to set up, convert, build and debug Unix/Linux executables that I develop on my Macintosh.


here's to the nights that turn into mornings
and the friends that turn into family

Unknown Unknown

Your kindred-family are the close, true friends that are your family when your real blood relatives live far far away.

Me Now

Yesterday was Independence Day here in New York and a popular day to spend with family. But my family lives in Australia and my wife’s is in Japan. No blood relatives here but ourselves.

We were not lonely. We never are at the holidays. We’re lucky enough to have a kindred-family. A kindred-family that is always there in lieu of traditional blood family.

A kindred-family is that set of close, true friends who act as your real family when your blood relatives live far far away. Author’s Note: Yes, I made up the term, it’s not in the dictionary.

We’re there for each-other as real family, we love and care as real families do. They are the notification contacts and next-of-kin names in our case of emergency folders. We celebrate each-others lives and successes and children as our own. And we’re there in the hard times, gathering together in strength, selflessly, as family does. There is nothing we cannot ask of each other, nothing we would not do for each other, just as real families do. And yet, somehow, because we are also true friends, we avoid the family bickering, intrigues and silly fights.

And we’re always together for the holidays and weekends away, thats who we choose to spend them with.

If you, like us, are living far away from your blood relatives, I hope you too truly have a kindred-family to take care of, to share with, to stand with and to celebrate life with.

For global drifters like my wife and I, it grounds and completes us.

Follow the author as @hiltmon on Twitter.