Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Portability Strategies: Java, C, and Makefiles, Study notes of Software Engineering

Various strategies for achieving portability in software development, focusing on java's virtualization approach, c's code branching pitfalls, and the use of makefiles to manage dependencies and compile programs across different environments. It also touches upon the autoconf and automake tools for handling configuration differences.

Typology: Study notes

2012/2013

Uploaded on 04/23/2013

ashakiran
ashakiran ๐Ÿ‡ฎ๐Ÿ‡ณ

4.5

(27)

268 documents

1 / 47

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The extent to which a program written on
one platform can be run on a different
platform.
Portability
Portability by virtualization: create a
virtual platform that is the same,
regardless of where you try to run the
program.
Portability by code branching: create
source code branches that deal with
specifics of platforms.
Portability by abstraction: utilize libraries
that abstract away architectural details,
e.g., Windows versus linux.
Basic strategies for portability
Portability
Wednesday, October 24, 2012
2:18 PM
Portability Page 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f

Partial preview of the text

Download Portability Strategies: Java, C, and Makefiles and more Study notes Software Engineering in PDF only on Docsity!

The extent to which a program written on one platform can be run on a different platform. Portability Portability by virtualization : create a virtual platform that is the same, regardless of where you try to run the program. Portability by code branching : create source code branches that deal with specifics of platforms. Portability by abstraction : utilize libraries that abstract away architectural details, e.g., Windows versus linux. Basic strategies for portability Portability Wednesday, October 24, 2012 2:18 PM Docsity.com

Every java program executes on the same Java virtual machine. The JVM is re-implemented on every hardware platform. Java and portability: virtualization Good news: If the program only accesses the JVM, then portability is guaranteed. Bad news: it is very difficult to limit dependencies to the JVM: the platform dependencies must be considered also. Good news and bad news: Thus java is often described as " write once, debug everywhere ". Portability by virtualization is not enough. Portability by virtualization Wednesday, October 24, 2012 10:51 AM Docsity.com

The way that C is translated into machine code differs by architecture and choice of compiler. Thus one must debug everywhere. C and portability Integers are defined in C as the most efficient word length. So the length of an int changes with architecture! In practice, never declare anything as an int! Use long and short instead. Word length: IA32 versus IA first byte in memory is most significant. last byte in memory is least significant. Little-endian: first byte in memory is least significant. last byte in memory is most significant. Big-endian: Some machines are little-endian, some are big-endian, i.e., is the sequence of bytes 0x0 0x0 0x0 0x interpreted as 1 (big-endian) or 2^25 (little-endian) (This comes into play when one does one's own manipulation of integers via bitwise operations.) Machine byte order: Versions of libraries and their capabilities. Version skew between dynamic and static libraries. Locations of files in different distributions of linux. Some common C portability traps C portability by code branching Wednesday, October 24, 2012 10:56 AM Docsity.com

Heterogeneity: systems upon which you wish to run the compiler differ in configuration.

Conditional compilation: dealing with heterogeneity by modifying the program that gets compiled for different circumstances.

Environmental probing: how one figures out whether the program needs modification.

Environmental probe design: creating software that always, on every platform, figures out what customizations are needed.

Why C software portability is difficult: Why software portability is difficult Tuesday, October 30, 2012 7:10 PM Docsity.com

Here's how we deal with adapting programs to run in multiple environments (autoconf/automake model): Makefile.am: description of all goals | | +----- configure.in: map of all constraints | | | | |automake |autoconf | | | v v | Makefile.in | | | |configure<--+ | v Makefile | |make | v executable program!

  • โ—‹ nodes are files. โ—‹ arrows are processes. โ—‹ arrow labels are programs that accomplish the processes.
  • In this diagram: โ—‹ automake reads Makefile.am and configure.in and creates Makefile.in โ—‹ autoconf reads configure.in and creates configure. โ—‹ configure reads Makefile.in and creates Makefile. โ—‹ make reads Makefile and creates desired compiled binaries.
  • In English: A schema for C program portability among *nix's Tuesday, October 30, 2012 7:11 PM Docsity.com

โ—‹ doesn't know what to compile or link โ—‹ must figure out how to compile things by hand.

  • gcc: compiler determines what needs to be done to build an executable.

โ—‹ does dependency analysis on intermediate files. โ—‹ creates an execution order for making the files.

  • make: dependency analyzer remembers things that don't change for your site/machine.

โ—‹ generates a Makefile containing those things. โ—‹ unique to X11 and older packages not useful for modern programs or for working around bugs in operating systems.

  • imake: site dependency envelope โ—‹ tells C programs what your environment is like. โ—‹ allows 'portable' c code to be written. โ—‹ de-facto standard for portability analysis. configure: environment analyzer and portable code generator

โ—‹ you describe what needs to be located or determined. โ—‹ it builds a configure script that locates it!

  • autoconf and automake: how to create configure scripts! Up the long ladder Tuesday, October 30, 2012 7:12 PM Docsity.com
  • analyzes dependencies between actions
  • orders actions into a linear sequence.
  • calls compilers as appropriate.
  • rules specified in a file Makefile (or makefile) Make: Make: Tuesday, October 30, 2012 7:13 PM Docsity.com

line starting with word is a rule: target files : source files to use

lines thereafter, starting with the character, are commands to execute: command to use to make the target files from the source files. another command another command

commands executed inside /bin/sh (not /bin/tcsh, so syntax differs slightly)

first line not starting with ends command stream.

General form of a make rule: General form of a make rule Tuesday, October 30, 2012 7:14 PM Docsity.com

then make proceeds to make everything it knows how to make that's older than its precedent , using that sequence and the commands given.

Docsity.com

  • manages dependencies between files. reads a control file Makefile that designates dependencies between files and commands that can be used to make one file from others.

uses the timestamps on files to remake any files older than their sources.

converts the dependency partial order into a total order and executes appropriate commands in order.

Make automagically: Make's functions Tuesday, October 30, 2012 7:16 PM Docsity.com

Default rules and make variables simplify complex makefiles.

The default transformation from a .c file to a .o file is $(CC) $(CFLAGS) - c file.c where CC and CFLAGS are specified by the user. These are make variables , similar to shell variables.

This means that the Makefile: CC= g++ CFLAGS= - g LIBS= - lcurses - ltermcap a1.o: a1.c a1.h t1.o: t1.c a1.h t1 : t1.o a1.o $(CC) $(CFLAGS) - o t1 t1.o a1.o $(LIBS) calls two implicit rules.

Default rules Default rules Tuesday, October 30, 2012 7:17 PM Docsity.com

The code: .c.o: $(CC) $(CFLAGS) $(MYFLAGS) - g - c $< - o $@ does the same thing as the one above, but has all site- specific information at the top.

Changing a default rule: Changing a default rule Tuesday, October 30, 2012 7:18 PM Docsity.com

Certain conventions for target names help us remember what they do across all makefiles.

all: make everything make all makes all targets defined in the makefile, e.g. all: foo bar faw faux

install: make available to users make install installs all targets in a reasonable place where normal users can get to them to use them, e.g., install: foo bar faw faux cp $< /usr/local/bin

clean: clean up after a make make clean removes all intermediate files that aren't needed in the final result, e.g. clean: rm *.o

realclean: make clean enough to redistribute make realclean removes all created files regardless of function, e.g.: realclean: rm *.o foo bar faw faux

Make target conventions: Make target conventions Tuesday, October 30, 2012 7:19 PM Docsity.com

  • Any .c file depends on ALL .h FILES IT INCLUDES. If any header changes, the .c file has to be RECOMPILED.

Fortunately, gcc and g++ can automatically generate dependency parts of a makefile by tracing #include's. To do this, g++ - MM file.c file2.c file3.c ... >Make.deps which generates a file of dependencies, and put the line include Make.deps in your Makefile as the first line.

Method: G++ runs the C preprocessor, picks up all the #includes, collates a list of every file you include!

Automatic dependency generation gcc - MM: automatic dependency generation Tuesday, October 30, 2012 7:20 PM Docsity.com