Fun with makefiles

I’ve been working on some code in the past few weeks that is to be run on a small embedded linux box. I initially began development on my machine, but soon got tired of compiling to check for errors, transferring to the other machine, and compiling again. So I just did all my development on the other machine. This turned out to be a big mistake as this particular machine wipes its home directory on reboot. After losing a lot of my code I found an alternate solution.

Previously I had just been using simple make files to get the job done, like this:

    gcc -llibrary program.c -o program

But after losing a lot of my code, I decided to try something new:

all: remote

remote: scp
    ssh -oStrictHostKeyChecking=no username@othermachine "cd /program; gcc -llibrary program.c -o program" 2>/dev/null

scp: local
    scp -oStrictHostKeyChecking=no *.c *.h username@othermachine:/program 2>/dev/null

    gcc -llibrary program.c -o program

This means that all I have to do now is type make and it compiles locally, transfers it to the other machine, and compiles it there too! Much better!

Leave a Reply

Your email address will not be published. Required fields are marked *