macros copyright © software carpentry 2010 this work is licensed under the creative commons...

63
Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution Lice See http://software-carpentry.org/license.html for more informati Automated Builds

Upload: ernest-cox

Post on 04-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Macros

Copyright © Software Carpentry 2010

This work is licensed under the Creative Commons Attribution License

See http://software-carpentry.org/license.html for more information.

Automated Builds

Page 2: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Manage tasks and dependencies

Page 3: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

figure-1.svg

summary-1.dat

Manage tasks and dependencies

figure-2.svg

data-1-1.dat data-1-3.datdata-1-2.dat

paper.pdf

paper.wdp

Page 4: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

"must conform to university style"

Page 5: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

"must conform to university style"

figure-1.svg figure-2.svg

paper.pdf

euphoric.wps paper.wdp

Page 6: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

"must conform to university style"

figure-1.svg figure-2.svg

paper.pdf

euphoric.wps paper.wdp

C:\papers

home

Page 7: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

"must conform to university style"

figure-1.svg figure-2.svg

paper.pdf

euphoric.wps paper.wdp

C:\papers /lib/styles/

home lab

Page 8: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

"must conform to university style"

figure-1.svg figure-2.svg

paper.pdf

euphoric.wps paper.wdp

data-1-1.dat data-1-2.dateuphoric.fig

Page 9: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

"must conform to university style"

figure-1.svg figure-2.svg

paper.pdf

euphoric.wps paper.wdp

C:\papers

home

data-1-1.dat data-1-2.dateuphoric.fig

Page 10: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

"must conform to university style"

figure-1.svg figure-2.svg

paper.pdf

euphoric.wps paper.wdp

C:\papers /lib/styles/

home lab

data-1-1.dat data-1-2.dateuphoric.fig

Page 11: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# false-dependencies.mk

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf $<

figure-%.svg : summary-%.dat sgr -N -r $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

Makefile so far

Page 12: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# with-directories-at-home.mk

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf --style c:/papers/euphoric.wps $<

figure-%.svg : summary-%.dat sgr -N -r -s c:/papers/euphoric.fig $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

Add directories for working at home

Page 13: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# with-directories-at-home.mk

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf --style c:/papers/euphoric.wps $<

figure-%.svg : summary-%.dat sgr -N -r -s c:/papers/euphoric.fig $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

Add directories for working at home

Page 14: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# with-directories-at-home.mk

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf --style c:/papers/euphoric.wps $<

figure-%.svg : summary-%.dat sgr -N -r -s c:/papers/euphoric.fig $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

Usually don't list "system" files explicitly

Add directories for working at home

Page 15: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# with-directories-at-home.mk

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf --style c:/papers/euphoric.wps $<

figure-%.svg : summary-%.dat sgr -N -r -s c:/papers/euphoric.fig $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

Usually don't list "system" files explicitly

But what about the lab?

Add directories for working at home

Page 16: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

1. Write two Makefiles

Page 17: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

1. Write two Makefiles

Write and maintain

Page 18: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

1. Write two Makefiles

2. Comment and uncomment lines

Write and maintain

Page 19: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

1. Write two Makefiles

2. Comment and uncomment lines

Write and maintain

Consistently every time

Page 20: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

1. Write two Makefiles

2. Comment and uncomment lines

Write and maintain

Consistently every time

Will create lots of noise in

version control

Page 21: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

1. Write two Makefiles

2. Comment and uncomment lines

3. Refactor

Write and maintain

Consistently every time

Will create lots of noise in

version control

Page 22: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Use a macro

Page 23: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# with-macro.mk

STYLE_DIR=c:/papers/

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf --style ${STYLE_DIR}/euphoric.wps $<

figure-%.svg : summary-%.dat sgr -N -r -s ${STYLE_DIR}/euphoric.fig $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

Use a macro

Page 24: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# with-macro.mk

STYLE_DIR=c:/papers/

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf --style ${STYLE_DIR}/euphoric.wps $<

figure-%.svg : summary-%.dat sgr -N -r -s ${STYLE_DIR}/euphoric.fig $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

Use a macro

Page 25: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# with-macro.mk

STYLE_DIR=c:/papers/

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf --style ${STYLE_DIR}/euphoric.wps $<

figure-%.svg : summary-%.dat sgr -N -r -s ${STYLE_DIR}/euphoric.fig $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

Use a macro

Page 26: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Only have one thing to change

Page 27: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Only have one thing to change

✓ Consistency

Page 28: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Only have one thing to change

✓ Consistency

✗ But still have noise

Page 29: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Only have one thing to change

Must use ${MACRO} or $(MACRO), not $MACRO

✓ Consistency

✗ But still have noise

Page 30: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Only have one thing to change

Must use ${MACRO} or $(MACRO), not $MACRO

Make reads $MACRO is ($M)ACRO

✓ Consistency

✗ But still have noise

Page 31: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Only have one thing to change

Must use ${MACRO} or $(MACRO), not $MACRO

Make reads $MACRO is ($M)ACRO

Which is probably just "ACRO"

✓ Consistency

✗ But still have noise

Page 32: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Only have one thing to change

Must use ${MACRO} or $(MACRO), not $MACRO

Make reads $MACRO is ($M)ACRO

Which is probably just "ACRO"

Which is probably not what you want

✓ Consistency

✗ But still have noise

Page 33: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Only have one thing to change

Must use ${MACRO} or $(MACRO), not $MACRO

Make reads $MACRO is ($M)ACRO

Which is probably just "ACRO"

Which is probably not what you want

yet another legacy wart

✓ Consistency

✗ But still have noise

Page 34: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Commonly define macros for control flags

Page 35: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# with-lots-of-macros.mk

STYLE_DIR=c:/papers/WDP2PDF_FLAGS=--style ${STYLE_DIR}/euphoric.wpsSGR_FLAGS=-N -r -s ${STYLE_DIR}/euphoric.fig

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf ${WDP2PDF_FLAGS} $<

figure-%.svg : summary-%.dat sgr ${SGR_FLAGS} $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

Commonly define macros for control flags

Page 36: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# with-lots-of-macros.mk

STYLE_DIR=c:/papers/WDP2PDF_FLAGS=--style ${STYLE_DIR}/euphoric.wpsSGR_FLAGS=-N -r -s ${STYLE_DIR}/euphoric.fig

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf ${WDP2PDF_FLAGS} $<

figure-%.svg : summary-%.dat sgr ${SGR_FLAGS} $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

Commonly define macros for control flags

Page 37: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# with-lots-of-macros.mk

STYLE_DIR=c:/papers/WDP2PDF_FLAGS=--style ${STYLE_DIR}/euphoric.wpsSGR_FLAGS=-N -r -s ${STYLE_DIR}/euphoric.fig

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf ${WDP2PDF_FLAGS} $<

figure-%.svg : summary-%.dat sgr ${SGR_FLAGS} $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

Commonly define macros for control flags

Page 38: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# config.mk

STYLE_DIR=c:/papers/

Now put the first macro in a separate file

Page 39: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# with-include.mkinclude config.mk

WDP2PDF_FLAGS=--style ${STYLE_DIR}/euphoric.wpsSGR_FLAGS=-N -r -s ${STYLE_DIR}/euphoric.fig

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf ${WDP2PDF_FLAGS} $<

figure-%.svg : summary-%.dat sgr ${SGR_FLAGS} $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

And include it from the main file

Page 40: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# with-include.mkinclude config.mk

WDP2PDF_FLAGS=--style ${STYLE_DIR}/euphoric.wpsSGR_FLAGS=-N -r -s ${STYLE_DIR}/euphoric.fig

paper.pdf : paper.wdp figure-1.svg figure-2.svg wdp2pdf ${WDP2PDF_FLAGS} $<

figure-%.svg : summary-%.dat sgr ${SGR_FLAGS} $@ $^

summary-%.dat : data-%-*.dat stats.py $@ $^

data-*-*.dat : stats.py touch $@

And include it from the main file

Page 41: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Actually create two configuration files

Page 42: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# config-home.mk

STYLE_DIR=c:/papers/

Actually create two configuration files

Page 43: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# config-home.mk

STYLE_DIR=c:/papers/

Actually create two configuration files

# config-lab.mk

STYLE_DIR=/lib/styles

Page 44: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# config-home.mk

STYLE_DIR=c:/papers/

Actually create two configuration files

# config-lab.mk

STYLE_DIR=/lib/styles

These two files stay in version control

Page 45: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

# config-home.mk

STYLE_DIR=c:/papers/

Actually create two configuration files

# config-lab.mk

STYLE_DIR=/lib/styles

These two files stay in version control

Copy to create config.mk per machine

Page 46: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

paper/

config-lab.mkconfig-home.mkMakefile

Home

Page 47: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

paper/

config.mkconfig-lab.mkconfig-home.mkMakefile

Home

Page 48: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

paper/

config.mkconfig-lab.mkconfig-home.mkMakefile

Home

paper/

config-lab.mkconfig-home.mkMakefile

Lab

Page 49: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

paper/

config.mkconfig-lab.mkconfig-home.mkMakefile

Home

paper/

config.mkconfig-lab.mkconfig-home.mkMakefile

Lab

Page 50: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

paper/

config.mkconfig-lab.mkconfig-home.mkMakefile

Home

paper/

config.mkconfig-lab.mkconfig-home.mkMakefile

Lab

Page 51: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Can also define macro value on command line

Page 52: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

$ make -DSTYLE_DIR=/lib/styles -f Makefile

Can also define macro value on command line

Page 53: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

$ make -DSTYLE_DIR=/lib/styles -f Makefile

Can also define macro value on command line

Generally a bad idea

Page 54: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

$ make -DSTYLE_DIR=/lib/styles -f Makefile

Can also define macro value on command line

Generally a bad idea

Have to remember to type definition each time

Page 55: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

$ make -DSTYLE_DIR=/lib/styles -f Makefile

Can also define macro value on command line

Generally a bad idea

Have to remember to type definition each time

correctly

Page 56: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

$ make -DSTYLE_DIR=/lib/styles -f Makefile

Can also define macro value on command line

Generally a bad idea

Have to remember to type definition each time

correctly

And there's no record of the flag

Page 57: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Many other approaches

Page 58: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Many other approaches

CMake and Autoconf/Automake: compile higher-level

specification into a Makefile (or equivalent)

Page 59: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Many other approaches

CMake and Autoconf/Automake: compile higher-level

specification into a Makefile (or equivalent)

✓ Automatically discover/manage differences

between machines

Page 60: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Many other approaches

CMake and Autoconf/Automake: compile higher-level

specification into a Makefile (or equivalent)

✓ Automatically discover/manage differences

between machines

✗ But even harder to debug

Page 61: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Many other approaches

CMake and Autoconf/Automake: compile higher-level

specification into a Makefile (or equivalent)

✓ Automatically discover/manage differences

between machines

✗ But even harder to debug

A build file is a program

Page 62: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Automated Builds Macros

Many other approaches

CMake and Autoconf/Automake: compile higher-level

specification into a Makefile (or equivalent)

✓ Automatically discover/manage differences

between machines

✗ But even harder to debug

A build file is a program

Requires the same degree of respect

Page 63: Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

August 2010

created by

Greg Wilson

Copyright © Software Carpentry 2010

This work is licensed under the Creative Commons Attribution License

See http://software-carpentry.org/license.html for more information.