Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See"— Presentation transcript:

1 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

2 Macros Manage tasks and dependencies

3 Automated BuildsMacros figure-1.svg summary-1.dat Manage tasks and dependencies figure-2.svg data-1-1.datdata-1-3.datdata-1-2.dat paper.pdf paper.wdp

4 Automated BuildsMacros "must conform to university style"

5 Automated BuildsMacros "must conform to university style" figure-1.svgfigure-2.svg paper.pdf euphoric.wpspaper.wdp

6 Automated BuildsMacros "must conform to university style" figure-1.svgfigure-2.svg paper.pdf euphoric.wpspaper.wdp C:\papers home

7 Automated BuildsMacros "must conform to university style" figure-1.svgfigure-2.svg paper.pdf euphoric.wpspaper.wdp C:\papers/lib/styles/ homelab

8 Automated BuildsMacros "must conform to university style" figure-1.svgfigure-2.svg paper.pdf euphoric.wpspaper.wdp data-1-1.datdata-1-2.dateuphoric.fig

9 Automated BuildsMacros "must conform to university style" figure-1.svgfigure-2.svg paper.pdf euphoric.wpspaper.wdp C:\papers home data-1-1.datdata-1-2.dateuphoric.fig

10 Automated BuildsMacros "must conform to university style" figure-1.svgfigure-2.svg paper.pdf euphoric.wpspaper.wdp C:\papers /lib/styles/ home lab data-1-1.datdata-1-2.dateuphoric.fig

11 Automated BuildsMacros # 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

12 Automated BuildsMacros # 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

13 Automated BuildsMacros # 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

14 Automated BuildsMacros # 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

15 Automated BuildsMacros # 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

16 Automated BuildsMacros 1. Write two Makefiles

17 Automated BuildsMacros 1. Write two Makefiles Write and maintain

18 Automated BuildsMacros 1.Write two Makefiles 2. Comment and uncomment lines Write and maintain

19 Automated BuildsMacros 1.Write two Makefiles 2. Comment and uncomment lines Write and maintain Consistently every time

20 Automated BuildsMacros 1.Write two Makefiles 2. Comment and uncomment lines Write and maintain Consistently every time Will create lots of noise in version control

21 Automated BuildsMacros 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

22 Automated BuildsMacros Use a macro

23 Automated BuildsMacros # 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

24 Automated BuildsMacros # 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

25 Automated BuildsMacros # 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

26 Automated BuildsMacros Only have one thing to change

27 Automated BuildsMacros Only have one thing to change ✓ Consistency

28 Automated BuildsMacros Only have one thing to change ✓ Consistency ✗ But still have noise

29 Automated BuildsMacros Only have one thing to change Must use ${MACRO} or $(MACRO), not $MACRO ✓ Consistency ✗ But still have noise

30 Automated BuildsMacros Only have one thing to change Must use ${MACRO} or $(MACRO), not $MACRO Make reads $MACRO is ($M)ACRO ✓ Consistency ✗ But still have noise

31 Automated BuildsMacros 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

32 Automated BuildsMacros 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

33 Automated BuildsMacros 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

34 Automated BuildsMacros Commonly define macros for control flags

35 Automated BuildsMacros # with-lots-of-macros.mk STYLE_DIR=c:/papers/ WDP2PDF_FLAGS=--style ${STYLE_DIR}/euphoric.wps SGR_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

36 Automated BuildsMacros # with-lots-of-macros.mk STYLE_DIR=c:/papers/ WDP2PDF_FLAGS=--style ${STYLE_DIR}/euphoric.wps SGR_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

37 Automated BuildsMacros # with-lots-of-macros.mk STYLE_DIR=c:/papers/ WDP2PDF_FLAGS=--style ${STYLE_DIR}/euphoric.wps SGR_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

38 Automated BuildsMacros # config.mk STYLE_DIR=c:/papers/ Now put the first macro in a separate file

39 Automated BuildsMacros # with-include.mk include config.mk WDP2PDF_FLAGS=--style ${STYLE_DIR}/euphoric.wps SGR_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

40 Automated BuildsMacros # with-include.mk include config.mk WDP2PDF_FLAGS=--style ${STYLE_DIR}/euphoric.wps SGR_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

41 Automated BuildsMacros Actually create two configuration files

42 Automated BuildsMacros # config-home.mk STYLE_DIR=c:/papers/ Actually create two configuration files

43 Automated BuildsMacros # config-home.mk STYLE_DIR=c:/papers/ Actually create two configuration files # config-lab.mk STYLE_DIR=/lib/styles

44 Automated BuildsMacros # 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

45 Automated BuildsMacros # 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

46 Automated BuildsMacros paper/ config-lab.mk config-home.mk Makefile Home

47 Automated BuildsMacros paper/ config.mk config-lab.mk config-home.mk Makefile Home

48 Automated BuildsMacros paper/ config.mk config-lab.mk config-home.mk Makefile Home paper/ config-lab.mk config-home.mk Makefile Lab

49 Automated BuildsMacros paper/ config.mk config-lab.mk config-home.mk Makefile Home paper/ config.mk config-lab.mk config-home.mk Makefile Lab

50 Automated BuildsMacros paper/ config.mk config-lab.mk config-home.mk Makefile Home paper/ config.mk config-lab.mk config-home.mk Makefile Lab

51 Automated BuildsMacros Can also define macro value on command line

52 Automated BuildsMacros $ make -DSTYLE_DIR=/lib/styles -f Makefile Can also define macro value on command line

53 Automated BuildsMacros $ make -DSTYLE_DIR=/lib/styles -f Makefile Can also define macro value on command line Generally a bad idea

54 Automated BuildsMacros $ 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

55 Automated BuildsMacros $ 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

56 Automated BuildsMacros $ 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

57 Automated BuildsMacros Many other approaches

58 Automated BuildsMacros Many other approaches CMake and Autoconf/Automake: compile higher-level specification into a Makefile (or equivalent)

59 Automated BuildsMacros Many other approaches CMake and Autoconf/Automake: compile higher-level specification into a Makefile (or equivalent) ✓ Automatically discover/manage differences between machines

60 Automated BuildsMacros 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

61 Automated BuildsMacros 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

62 Automated BuildsMacros 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

63 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.


Download ppt "Macros Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See"

Similar presentations


Ads by Google