gnustep makefiles

25
Compiling Code using Makefiles and GNUstep 2501ICT Nathan

Upload: ln

Post on 12-Nov-2014

269 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: GNUstep Makefiles

Compiling Code usingMakefiles and GNUstep

2501ICTNathan

Page 2: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

2

Makefiles

• Save compile time• only recompile what’s necessary

• Help avoiding mistakes• that would otherwise occur if outdated modules

were linked together

• Are language independent• Objective-C• C, C++, Java

Page 3: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

3

How do Makefiles work?

• Dependency Trees• Targets• Sources

• Target• The module to be built

• Sources• The source code for the Target• Other targets that need to be build first

Page 4: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

4

Dependency Tree Example

Main_Mod

Module_A Module_B

Module_C Module_D

Page 5: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

5

Corresponding Makefile

Main_Mod: Module_A Module_B

Module_A:

Module_B: Module_C Module_D

Module_C:

Module_D:

Main

A B

C D

Page 6: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

6

Make Rules

• Lines directly below a Target• No empty lines in between• One or more empty lines after

• Indented by a TAB character• Spaces won’t work!

• Shell commands to execute• Compiler Calls• Any other shell command

Page 7: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

7

Objective-C Example

main.m

file_a.m + .h file_b.m + .h

file_c.m + .h file_d.m + .h

Page 8: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

8

Corresponding Makefile

main.o: main.m a.h b.h

a.o: a.m a.h

b.o: b.m b.h c.h d.h

c.o: c.m c.h

d.o: d.m d.h

main.m

a.ma.h

b.mb.h

c.mc.h

d.md.h

Page 9: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

9

Adding Make Rules

main.o: main.m a.h b.hgcc -Wno-import -Wall -c -o main.o main.m

a.o: a.m a.hgcc -Wno-import -Wall -c -o a.o a.m

b.o: b.m b.h c.h d.hgcc -Wno-import -Wall -c -o b.o b.m

c.o: c.m c.hgcc -Wno-import -Wall -c -o c.o c.m

d.o: d.m d.hgcc -Wno-import -Wall -c -o d.o d.m

Page 10: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

10

Generic Rules

• Save a lot of typing• Avoid repeated compiler calls (previous slide)

• Help with consistency• Avoid repeating the same change all over the

place

• Simply list suffixes, e.g.• .m.o:

• convert a ‘.m’ file to a ‘.o’ file

Page 11: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

11

Adding a Generic Rule

.SUFFIXES: .o .m .h

.m.o:gcc -Wno-import -Wall -c -o $*.o $*.m

main.o: main.m a.h b.h

a.o: a.m a.h

b.o: b.m b.h c.h d.h

c.o: c.m c.h

d.o: d.m d.h

Page 12: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

12

Make Variables

• Allow more flexible make files• Assigning a value:

CC=gcc

• Using a variable• Use $(variablename)• E.g., to compile a program, instead of gcc:$(CC) -Wall …

Page 13: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

13

Linking it all together

.SUFFIXES: .o .m .h

.m.o:$(CC) -Wno-import -Wall -c -o $*.o $*.m

main: main.o a.o b.o c.o d.o$(CC) -o main main.o a.o b.o c.o d.o -lobjc

main.o: main.m a.o b.o

a.o: a.m

b.o: b.m c.o d.o

c.o: c.m…

Page 14: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

14

GNUstep Makefiles

• Have all the rules already pre-defined• Only require some variables to be set

• Name of the Program• Name of the individual Classes (.m and .h files)• Flags to be used

• -Wall -Wno-import

• Include files for different projects• Command line tools, GUI applications, …

• Should be named GNUmakefile• or GNUmakefile.classname for testing classes

Page 15: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

15

Command Line Tool Example

# Include the common variables defined by the Makefile Packageinclude $(GNUSTEP_MAKEFILES)/common.make

# Build a simple Objective-C program, called ExampleTOOL_NAME = Example

# The Objective-C Implementation files to compileExample_OBJC_FILES = Main.m Some_Class.m Other_Class.m

# Class Header (Interface) filesExample_HEADER_FILES = Some_Class.h Other_Class.h

# Define the compiler flagsADDITIONAL_CPPFLAGS = -Wall -Wno-import

# Include the rules for making Objective-C command line toolsinclude $(GNUSTEP_MAKEFILES)/tool.make

Page 16: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

16

After removing the comments

include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME = ExampleExample_OBJC_FILES = Main.m Some_Class.m Other_Class.mExample_HEADER_FILES = Some_Class.h Other_Class.h

ADDITIONAL_CPPFLAGS = -Wall -Wno-import

include $(GNUSTEP_MAKEFILES)/tool.make

Page 17: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

17

Application Example

include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = ExampleExample_OBJC_FILES = Main.m Some_Class.m Other_Class.mExample_HEADER_FILES = Some_Class.h Other_Class.h

ADDITIONAL_CPPFLAGS = -Wall -Wno-import

include $(GNUSTEP_MAKEFILES)/application.make

Page 18: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

18

Adding an external GUI

include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = ExampleExample_OBJC_FILES = Main.m Some_Class.m Other_Class.mExample_HEADER_FILES = Some_Class.h Other_Class.hExample_RESOURCE_FILES = Example.gormExample_MAIN_MODEL_FILE = Example.gorm

ADDITIONAL_CPPFLAGS = -Wall -Wno-import

include $(GNUSTEP_MAKEFILES)/application.make

Page 19: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

19

Gorm

• GNU Object Relationship Manager• Create a GUI (View) independent of Program

(Model).

• Model-View-Controller (MVC)Paradigm• A Controller connects the View with the

underlying Model.• Changes to the GUI are independent from

changes to the model classes.

Page 20: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

20

Connecting Model and View

• Reference Controller from View• Create a Controller class in Gorm

• Add outlets (object references) for all GUI elements• Add actions for buttons, menus, etc.

• Controller instantiates Model classes• Application just calls NSApplicationMain()

• Completely dynamic• Changed GUI: no need to re-compile

• Allows different GUIs, languages, etc.

Page 21: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

21

Documentation

• Directly from source code• autogsdoc• extracts comments starting with /**

• GNUmakefile• documentation.make: rules for invokingautogsdoc

• DOCUMENT_NAME• Sets the name of the documentation

• Document_AGSDOC_FILES• Lists the files to scan for autogsdoc comments

Page 22: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

22

Tool+Documentation Makefile

include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME = ExampleExample_OBJC_FILES = Main.m Some_Class.m Other_Class.mExample_HEADER_FILES = Some_Class.h Other_Class.h

DOCUMENT_NAME = DocumentationDocumentation_AGSDOC_FILES = Some_Class.h Other_Class.m

ADDITIONAL_CPPFLAGS = -Wall -Wno-import

include $(GNUSTEP_MAKEFILES)/tool.makeinclude $(GNUSTEP_MAKEFILES)/documentation.make

Page 23: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

23

GUI Application+Documentation

include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = ExampleExample_OBJC_FILES = Main.m Some_Class.m Other_Class.mExample_HEADER_FILES = Some_Class.h Other_Class.hExample_RESOURCE_FILES = Example.gormExample_MAIN_MODEL_FILE = Example.gorm

DOCUMENT_NAME = DocumentationDocumentation_AGSDOC_FILES = Some_Class.h Other_Class.m

ADDITIONAL_CPPFLAGS = -Wall -Wno-import

include $(GNUSTEP_MAKEFILES)/application.makeinclude $(GNUSTEP_MAKEFILES)/documentation.make

Page 24: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

24

Using dwarf

• ssh dwarf.cit.griffith.edu.au

• Use gcc to compilegcc -Wall -Werror -Wno-import -o file file.c

• Use man to look up C functionsman fgetcman 3 printfman 2 openman man

Page 25: GNUstep Makefiles

P3 LectureFebruary 2007

Copyright © 2002-2007 René Hexel.All rights reserved.

25

Online References

• Writing GNUstep Makefiles• P3 Modules Page

• Week 2 Reading Material

• GNUstep Makefile Package Docs• P3 Resources Page – Web Links

• Gorm tutorial:http://www.gnustep.it/pierre-yves/index.html