







































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








































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!
ā doesn't know what to compile or link ā must figure out how to compile things by hand.
ā does dependency analysis on intermediate files. ā creates an execution order for making the files.
ā 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.
ā you describe what needs to be located or determined. ā it builds a configure script that locates it!
line starting with word is a rule: target files : source files to use
lines thereafter, starting with the
commands executed inside /bin/sh (not /bin/tcsh, so syntax differs slightly)
first line not starting with
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
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
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