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?

Thanks

share|improve this question
add comment

2 Answers 2

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.

clean:
  rm -rf build

build:
  gcc sample.c

changelog:
  git log >> changelog.txt

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

all: clean package
share|improve this answer
add comment

You can create a minimal makefile containing:

all:
        YOUR SHELL COMMANDS HERE

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
add comment

Your Answer

 
discard

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.