Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a shell script, and would like to convert it to a makefile so that it can be executed with the command 'make all'.

How would I go about this?


share|improve this question

2 Answers 2

You can create a minimal makefile containing:


But you haven't really gained anything by doing so unless you rewrite it to make use of some of the features of a Makefile - multiple targets, target dependencies, etc. See here (or many other Makefile tutorials) for some information about what you can do with a makefile.

(Note that the shell commands are executed with sh separately for each line, so if you're doing anything complex like loops, setting variables it won't just work, and the indentation of commands needs to be a TAB character, not spaces.)

A quick Makefile for the case described (normal warnings, probably has all sorts of edge cases, might kill your dog, etc):

src=$(wildcard pictures/*.jpg)
out=$(subst pictures,thumb,$(src))

all : $(out)

thumb/%.jpg: pictures/%.jpg
    convert $< -thumbnail 100 $@
share|improve this answer
#! /bin/bash cd pictures for i in *.jpg; do if [ "$i" -nt "../thumbs/$i" ]; then convert "$i" -thumbnail 100 "../thumbs/$i"; fi done; That's the shell script. What can do so that the script can be called with 'make all'. Thank you very much for your help –  Duby Nov 28 '12 at 12:49
If I run it with./filename it runs, but I want to be able to run it with make all –  Duby Nov 28 '12 at 13:02

It's best if you separate your shell scripts out into several parts. E.g. prebuild, build, postbuild. Several small tasks make it easier to test the script.

  rm -rf build

  gcc sample.c

  git log >> changelog.txt

package: changelog build
  zip release.zip a.out changelog.txt 

all: clean package
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.