SlideShare a Scribd company logo
GNU Make




                                   3-1
Embedded Linux Course
GNU Make
ā€¢ makeĀ utilityĀ determinesĀ automaticallyĀ whichĀ 
  piecesĀ ofĀ aĀ largeĀ programĀ needĀ toĀ beĀ 
  recompiled,Ā andĀ issuesĀ theĀ commandsĀ toĀ 
  recompileĀ them.
ā€¢ makeĀ examineĀ theĀ sourceĀ andĀ objectĀ filesĀ toĀ 
  determineĀ whichĀ sourceĀ filesĀ needĀ toĀ beĀ 
  recompiledĀ toĀ createĀ newĀ objectĀ files.
ā€¢ YouĀ needĀ aĀ fileĀ calledĀ aĀ MakefileĀ toĀ 
  tellĀ makeĀ whatĀ toĀ do


                                                 3-2
     Embedded Linux Course
GNU Make (cont.)
ā€¢ TheĀ relationshipĀ ofĀ anĀ objectĀ fileĀ toĀ theĀ sourceĀ 
  fileĀ usedĀ toĀ produceĀ itĀ isĀ knownĀ asĀ aĀ dependencyĀ 
ā€¢ ToĀ determineĀ theĀ dependencies,Ā makeĀ readsĀ aĀ 
  scriptĀ (Makefile)Ā thatĀ definesĀ them
ā€¢ MakefileĀ tellsĀ makeĀ howĀ toĀ compileĀ andĀ linkĀ aĀ 
  program




                                                3-3
     Embedded Linux Course
Ā Makefile
ā€¢   EssentiallyĀ aĀ MakefileĀ containsĀ aĀ setĀ ofĀ rulesĀ usedĀ toĀ 
    buildĀ anĀ applicationĀ 
ā€¢   TheĀ firstĀ ruleĀ seenĀ byĀ makeĀ isĀ usedĀ asĀ theĀ default rule.Ā 
    Ā Ā makeĀ target
ā€¢   AĀ ruleĀ consistsĀ ofĀ threeĀ parts:Ā theĀ target,Ā itsĀ 
    prerequisites,Ā andĀ theĀ command(s)Ā toĀ performĀ 
              target: prereq1 prereq2
               target: prereq1 prereq2

              <TAB>shell commands
              <TAB>shell commands
              <TAB>shell commands
              <TAB>shell commands
                        ā€¦.
                        ā€¦.


                                                            3-4
       Embedded Linux Course
A Simple Makefile
edit ::main.o utils.o
 edit main.o utils.o
        gcc -o edit main.o utils.o
         gcc -o edit main.o utils.o

main.o ::main.c defs.h
main.o main.c defs.h
         gcc -c main.c
          gcc -c main.c
utils.o ::utils.c defs.h
utils.o utils.c defs.h
         gcc -c utils.c
          gcc -c utils.c

clean ::
 clean
           rm edit main.o utils.o
            rm edit main.o utils.o




                                      3-5
 Embedded Linux Course
ā€¢ TheĀ targetĀ isĀ theĀ fileĀ orĀ thingĀ thatĀ mustĀ beĀ made
ā€¢ TheĀ prerequisitesĀ orĀ dependentsĀ areĀ thoseĀ filesĀ 
  thatĀ mustĀ existĀ beforeĀ theĀ targetĀ canĀ beĀ 
  successfullyĀ created.
ā€¢ TheĀ commandsĀ areĀ justĀ shellĀ commands

             foo.o:Ā foo.cĀ foo.h
              foo.o:Ā foo.cĀ foo.h

             Ā Ā Ā Ā Ā Ā Ā Ā gccĀ -cĀ foo.c
              Ā Ā Ā Ā Ā Ā Ā Ā gccĀ -cĀ foo.c


                                                  3-6
     Embedded Linux Course
Makefile Syntax
ā€¢ OneĀ orĀ moreĀ targetsĀ appearĀ toĀ theĀ leftĀ ofĀ theĀ 
  colonĀ andĀ zeroĀ orĀ moreĀ prerequisitesĀ canĀ appearĀ 
  toĀ theĀ rightĀ ofĀ theĀ colon.
ā€¢ IfĀ noĀ prerequisitesĀ areĀ listedĀ toĀ theĀ right,Ā thenĀ 
  onlyĀ theĀ target(s)Ā thatĀ doĀ notĀ existĀ areĀ updatedĀ 
       target1Ā target2Ā target3Ā :Ā prerequisite1Ā prerequisite2

       <TAB>command1

       <TAB>command2

       <TAB>command3

                                                               3-7
     Embedded Linux Course
Makefile Syntax (cont.)
ā€¢ EachĀ commandĀ mustĀ beginĀ withĀ aĀ tabĀ character.Ā 
  ThisĀ (obscure)Ā syntaxĀ tellsĀ makeĀ thatĀ theĀ 
  charactersĀ thatĀ followĀ theĀ tabĀ areĀ toĀ beĀ passedĀ toĀ 
  aĀ subshellĀ forĀ execution.Ā 
  Makefile2:6:Ā ***Ā missingĀ separatorĀ (didĀ youĀ meanĀ TABĀ insteadĀ ofĀ 8Ā spaces?).Ā 
  Ā Stop.

   ā€“ LongĀ linesĀ canĀ beĀ continuedĀ usingĀ theĀ standardĀ UnixĀ escapeĀ 
     characterĀ backslashĀ ()
ā€¢ TheĀ commentĀ characterĀ forĀ makeĀ isĀ theĀ ā€˜#ā€™
Ā 


                                                                           3-8
       Embedded Linux Course
My First Makefile




ā€¢ AlthoughĀ theĀ allĀ targetĀ hasĀ twoĀ dependencies,Ā itĀ hasĀ noĀ 
  commandsĀ associatedĀ withĀ it,Ā butĀ thatā€™sĀ okayĀ becauseĀ 
  theĀ onlyĀ purposeĀ isĀ toĀ forceĀ theĀ dependenciesĀ toĀ beĀ 
  satisfied
                                                         3-9
      Embedded Linux Course
Phony Targets
ā€¢ AĀ phonyĀ targetĀ isĀ oneĀ thatĀ isĀ notĀ reallyĀ theĀ nameĀ 
  ofĀ aĀ file.Ā ItĀ isĀ justĀ aĀ nameĀ forĀ someĀ commandsĀ toĀ 
  beĀ executedĀ whenĀ youĀ makeĀ anĀ explicitĀ request.Ā 
ā€¢ ThereĀ areĀ twoĀ reasonsĀ toĀ useĀ aĀ phonyĀ target:Ā toĀ 
  avoidĀ aĀ conflictĀ withĀ aĀ fileĀ ofĀ theĀ sameĀ name,Ā andĀ 
  toĀ improveĀ performance.Ā 

    .PHONY: clean all
     .PHONY: clean all
    clean:
     clean:
            rm ā€“rf frammis cooker *.o *.bak *~
             rm ā€“rf frammis cooker *.o *.bak *~



                                                  3-10
      Embedded Linux Course
Force Targets
ā€¢ YouĀ canĀ useĀ aĀ targetĀ withoutĀ commandsĀ orĀ prerequisitesĀ 
  toĀ markĀ otherĀ targetsĀ asĀ phonyĀ 

          clean: FORCE
           clean: FORCE
                  rm $(objects)
                   rm $(objects)
          FORCE:
           FORCE:


ā€¢ IfĀ aĀ ruleĀ hasĀ noĀ prerequisitesĀ orĀ commands,Ā andĀ theĀ 
  targetĀ ofĀ theĀ ruleĀ isĀ aĀ nonexistentĀ file,Ā thenĀ makeĀ 
  imaginesĀ thisĀ targetĀ toĀ haveĀ beenĀ updatedĀ wheneverĀ itsĀ 
  ruleĀ isĀ run.Ā ThisĀ impliesĀ thatĀ allĀ targetsĀ dependingĀ onĀ thisĀ 
  oneĀ willĀ alwaysĀ haveĀ theirĀ commandsĀ run.Ā 


                                                            3-11
       Embedded Linux Course
Variable
ā€¢ AĀ macroĀ canĀ beĀ definedĀ inĀ oneĀ ofĀ threeĀ differentĀ 
  ways
      CC=gcc
      CC=gcc

      showmacros:
      showmacros:
           echoĀ CompilerĀ isĀ $(CC)Ā 
           echoĀ CompilerĀ isĀ $(CC)Ā 
           echoĀ HOMEĀ isĀ $(HOME)
           echoĀ HOMEĀ isĀ $(HOME)


      exportĀ Ā CC=arm-uclibc-gcc
      makeĀ Ā CC=arm-linux-gcc


                                                 3-12
     Embedded Linux Course
Variable Assignment
ā€¢ =Ā VariableĀ isĀ aĀ recursively expandedĀ variable
    CFLAGSĀ =Ā $(include_dirs)Ā -O
    include_dirsĀ =Ā -IfooĀ -Ibar
  #TheĀ followingĀ willĀ causeĀ anĀ infiniteĀ loopĀ inĀ theĀ variableĀ expansionĀ 
  CFLAGSĀ =Ā $(CFLAGS)Ā -O
ā€¢ :=Ā SimplyĀ expandedĀ variables
                           Ā Ā Ā Ā Ā xĀ :=Ā foo
                           Ā Ā Ā Ā Ā yĀ :=Ā $(x)Ā bar
                           Ā Ā Ā Ā Ā xĀ :=Ā later

                           isĀ equivalentĀ toĀ 

                           Ā Ā Ā Ā Ā yĀ :=Ā fooĀ bar
                           Ā Ā Ā Ā Ā xĀ :=Ā later
                                                                          3-13
       Embedded Linux Course
Variable Assignment (cont.)
ā€¢ ?=Ā conditional variableĀ 
ā€¢ itĀ onlyĀ hasĀ anĀ effectĀ ifĀ theĀ variableĀ isĀ notĀ yetĀ 
  defined.Ā ThisĀ statement:Ā 


          FOO ?= bar

  ThisĀ isĀ exactlyĀ equivalentĀ toĀ this

      ifeq (ā€œ$(origin FOO)ā€, ā€œundefinedā€)
          FOO = bar
     endif


                                                      3-14
      Embedded Linux Course
Variable Assignment (cont.)
ā€¢ +=Ā addĀ moreĀ textĀ toĀ theĀ valueĀ ofĀ aĀ variableĀ 
  alreadyĀ defined
      objects = main.o foo.o bar.o utils.o
      objects += another.o



 UsingĀ ā€˜+=ā€™Ā isĀ similarĀ to

    objects = main.o foo.o bar.o utils.o
    objects := $(objects) another.o




                                                 3-15
      Embedded Linux Course
Environment Variables
ā€¢     CC        C compiler command
ā€¢     CFLAGS    C compiler flags
ā€¢     LDFLAGS   linker flags, e.g. -L<lib dir> if you have libraries in a
               nonstandard directory <lib dir>
ā€¢     LIBS      libraries to pass to the linker, e.g. -l<library>
ā€¢     CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
                 you have headers in a nonstandard directory <include dir>
ā€¢     CPP       C preprocessor (gcc -E)
ā€¢     CXX       C++ compiler command
ā€¢     CXXFLAGS C++ compiler flags
ā€¢     CXXCPP    C++ preprocessor

    #example
     #example
    myprog:Ā Ā Ā Ā $(OBJS)
     myprog:Ā Ā Ā Ā $(OBJS)
    Ā Ā Ā Ā Ā Ā Ā Ā $(CC)Ā -oĀ $@Ā $^Ā $(LDFLAGS)Ā $(LIBS)
     Ā Ā Ā Ā Ā Ā Ā Ā $(CC)Ā -oĀ $@Ā $^Ā $(LDFLAGS)Ā $(LIBS)

Use these variables to override the choices made by `configure' or to help
 Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
 it to find libraries and programs with nonstandard names/locations.
                                                                               3-16
           Embedded Linux Course
Automatic variables
ā€¢ $@Ā :TheĀ fileĀ nameĀ ofĀ theĀ targetĀ ofĀ theĀ rule.
ā€¢ $<Ā Ā :TheĀ nameĀ ofĀ theĀ firstĀ prerequisite.Ā 
ā€¢ $?Ā Ā :TheĀ namesĀ ofĀ allĀ theĀ prerequisitesĀ thatĀ are
      Ā Ā newerĀ thanĀ theĀ target,Ā withĀ spacesĀ betweenĀ 
  Ā themĀ 
ā€¢ $^Ā Ā Ā :TheĀ namesĀ ofĀ allĀ theĀ prerequisites,Ā withĀ 
      Ā Ā Ā spacesĀ betweenĀ themĀ 

           libtest.a:Ā foo.oĀ bar.oĀ lose.oĀ win.oĀ 
            libtest.a:Ā foo.oĀ bar.oĀ lose.oĀ win.oĀ 
           Ā Ā Ā Ā Ā Ā Ā $(AR)Ā $(ARFLAGS)Ā $@Ā $?Ā 
            Ā Ā Ā Ā Ā Ā Ā $(AR)Ā $(ARFLAGS)Ā $@Ā $?Ā 

 makeĀ willĀ passĀ onlyĀ thoseĀ objectsĀ filesĀ thatĀ areĀ newerĀ thanĀ theĀ targetĀ toĀ ar
                                                                                3-17
        Embedded Linux Course
Exercise




                                   3-18
Embedded Linux Course
VPATH




                                3-19
Embedded Linux Course
cross.make
 # Tool names
  # Tool names
 CROSS_COMPILE = arm-linux-
  CROSS_COMPILE = arm-linux-
 AS
  AS           = $(CROSS_COMPILE)as
                = $(CROSS_COMPILE)as
 AR
  AR           = $(CROSS_COMPILE)ar
                = $(CROSS_COMPILE)ar
 CC
  CC           = $(CROSS_COMPILE)gcc
                = $(CROSS_COMPILE)gcc
 CPP
  CPP          = $(CC) -E
                = $(CC) -E
 LD
  LD           = $(CROSS_COMPILE)ld
                = $(CROSS_COMPILE)ld
 NM
  NM           = $(CROSS_COMPILE)nm
                = $(CROSS_COMPILE)nm
 OBJCOPY
  OBJCOPY      = $(CROSS_COMPILE)objcopy
                = $(CROSS_COMPILE)objcopy
 OBJDUMP
  OBJDUMP      = $(CROSS_COMPILE)objdump
                = $(CROSS_COMPILE)objdump
 RANLIB
  RANLIB       = $(CROSS_COMPILE)ranlib
                = $(CROSS_COMPILE)ranlib
 READELF
  READELF      = $(CROSS_COMPILE)readelf
                = $(CROSS_COMPILE)readelf
 SIZE
  SIZE         = $(CROSS_COMPILE)size
                = $(CROSS_COMPILE)size
 STRINGS
  STRINGS      = $(CROSS_COMPILE)strings
                = $(CROSS_COMPILE)strings
 STRIP
  STRIP        = $(CROSS_COMPILE)strip
                = $(CROSS_COMPILE)strip

 export AS AR CC CPP LD NM OBJCOPY OBJDUMP RANLIB READELF
  export AS AR CC CPP LD NM OBJCOPY OBJDUMP RANLIB READELF
 SIZE STRINGS STRIP
  SIZE STRINGS STRIP

    Note: export these values so that subsequent Makefiles called
     Note: export these values so that subsequent Makefiles called
    by this Makefile will use the same names
     by this Makefile will use the same names                        3-20
       Embedded Linux Course
Recursive Invocations of make




                                3-21
  Embedded Linux Course
Top Makfile




$(MAKE) -C $$dir ļƒØ cd dir && $(MAKE)
MAKEFLAGS += --no-print-directory


                                        3-22
      Embedded Linux Course
Recursive Invocations of make
              (cont.)




/*config.mk*/




                                  3-23
    Embedded Linux Course
Using command line




                            3-24
    Embedded Linux Course
ā€¢ Note: By declaring the subdirectories as phony
  targets (you must do this as the subdirectory
  obviously always exists; otherwise it won't be
  built)
                                                   3-25
     Embedded Linux Course
Internal Definitions
ā€¢ For convenience in constructing rules based on
  targets and dependencies, it is possible to use
  predefined macros and establish implicit rules
  that make can use to convert one file type to
  another.




                                                3-26
     Embedded Linux Course
Pattern Rules
ā€¢ Many programs that read one file type and
  output another conform to standard conventions
  ā€“ .c ==> .o , .S ==> .o
ā€¢ These conventions allow make to simplify rule
  creation by recognizing common filename
  patterns and providing built-in rules for
  processing them
ā€¢ The built-in rules are all instances of pattern
  rules %.o: %.c
          %.o: %.c
             # commands to execute (built-in):
              # commands to execute (built-in):
                  $(COMPILE.c) $(OUTPUT_OPTION) $<
                   $(COMPILE.c) $(OUTPUT_OPTION) $<
                OUTPUT_OPTION = -o $@
                COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c 3-27
     Embedded Linux Course
Looking at Predefined Rules and Macros
ā€¢ A large number of implicit rules are built into
  make (make -p)
%.o: %.S
 %.o: %.S
# commands to execute (built-in):
 # commands to execute (built-in):
     $(COMPILE.S) -o $@ $<
      $(COMPILE.S) -o $@ $<

# there is a special rule to generate a file with no suffix (always an executable)
 # there is a special rule to generate a file with no suffix (always an executable)

%: %.o
 %: %.o
# commands to execute (built-in):
 # commands to execute (built-in):
     $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
      $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@

%: %.c
 %: %.c
# commands to execute (built-in):
 # commands to execute (built-in):
     $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@
      $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@
                                                                                3-28
         Embedded Linux Course
ā€¢ The % in a pattern rule is roughly equivalent to *
  in a Unix shell
   ā€“ represents any number of any characters.
ā€¢ The % can be placed anywhere within the
  pattern but can occur only once.
ā€¢ Characters other than % match literally within a
  filename
                    cooker: cooker.c cooker.h
                    cooker.o: cooker.c cooker.h
                    cooker <----- cooker.c
                    % : %.c
                    cooker.o <-------- cooker.c
                    %.o : %.c

                                                  3-29
      Embedded Linux Course
Examples
CC=gcc
 CC=gcc
all: frammis cooker
 all: frammis cooker

frammis: frammis.c frammis.h
 frammis: frammis.c frammis.h
cooker: cooker.c cooker.h
 cooker: cooker.c cooker.h

clean:
 clean:
     rm -rf frammis cooker
      rm -rf frammis cooker

%:%.c
%:%.c
         echo "$< ===>$@ā€œ
          echo "$< ===>$@ā€œ
         $(CC) $(CFLAGS) $< ā€“o $@
          $(CC) $(CFLAGS) $< ā€“o $@




                                           3-30
        Embedded Linux Course
Suffix Rules
CC     = gcc
CFLAGS = -g                               # define a suffix rule for .c -> .o
LD     = $(CC)                            .c.o :
LDFLAGS        =                                    $(CC) $(CFLAGS) -c $<
RM     = rm
                                          # default target by convention is ``all''
EXE       = mainx                         all : $(EXE)
SRCS      = main.c sub1.c sub2.c sub3.c
OBJS      = ${SRCS:.c=.o}                 $(EXE) : $(OBJS)
                                                    $(LD) -o $@ $(OBJS)
# list only those we use
.SUFFIXES: .o .c                          $(OBJS) : proj.h

                                          clean :
                                                     -$(RM) -f $(EXE) $(OBJS)




                                                                                      3-31
             Embedded Linux Course
# Make rules
 # Make rules
all: daemon
 all: daemon
.PHONY : :install clean distclean
 .PHONY install clean distclean
.c.o:
 .c.o:
       $(CC) $(CFLAGS) $(HEADER_OPS) -c $<
        $(CC) $(CFLAGS) $(HEADER_OPS) -c $<

daemon: ${OBJS}
 daemon: ${OBJS}
    $(CC) -o $(EXEC_NAME) ${OBJS} $(LDFLAGS)
     $(CC) -o $(EXEC_NAME) ${OBJS} $(LDFLAGS)
#Copy the executable file into a directory that users typically search for
 #Copy the executable file into a directory that users typically search for
##commands;
   commands;
install: daemon
 install: daemon
      test -d $(INSTALL_DIR) ||||$(INSTALL) -d -m 755 $(INSTALL_DIR)
       test -d $(INSTALL_DIR) $(INSTALL) -d -m 755 $(INSTALL_DIR)
      $(INSTALL) -m 755 $(EXEC_NAME) $(INSTALL_DIR)
       $(INSTALL) -m 755 $(EXEC_NAME) $(INSTALL_DIR)

clean:
 clean:
     rm -f *.o $(EXEC_NAME) core
      rm -f *.o $(EXEC_NAME) core

##distclean might be defined to delete more files than `clean' does.
   distclean might be defined to delete more files than `clean' does.
distclean:
 distclean:
      rm -f *~
       rm -f *~
      rm -f *.o $(EXEC_NAME) core
       rm -f *.o $(EXEC_NAME) core
                                                                              3-32
            Embedded Linux Course
Built-in Functions
ā€¢ GNU make has a couple dozen built-in functions
  for working with variables and their contents
ā€¢ $(function-name arg1[, argn])




                                              3-33
     Embedded Linux Course
$(shell command)
ā€¢ The shell function accepts a single argument
  that is expanded (like all arguments) and passed
  to a subshell for execution.
ā€¢ The standard output of the command is then
  read and returned as the value of the function.
  Sequences of newlines in the output are
  collapsed to a single space. Any trailing newline
  is deleted.
ā€¢ The standard error is not returned, nor is any
  program exit status


                                                 3-34
     Embedded Linux Course
Example




                                  3-35
Embedded Linux Course
$(wildcard pattern . . . )
      sources := $(wildcard *.c *.h)



ā€¢ The wildcard function accepts a list of patterns
  and performs expansion on each one.
ā€¢ If a pattern does not match any files, the empty
  string is returned.
ā€¢ As with wildcard expansion in targets and
  prerequisites, the normal shell globbing
  characters are supported: ~, *, ?, [...], and [^...].

                                                      3-36
      Embedded Linux Course
ā€¢ Another use of wildcard is to test for the
  existence of a file in conditionals.
ā€¢ When used in conjunction with the if function
  (described shortly) you often see wildcard
  function calls whose argument contains no
  wildcard characters at all.

     dot-emacs-exists := $(wildcard ~/.emacs)

     will return the empty string if the user's home directory
     does not contain a .emacs file


                                                                 3-37
     Embedded Linux Course
$(subst search-string,replace-string,text)


sources := count_words.c counter.c lexer.c
sources := count_words.c counter.c lexer.c
objects := $(subst .c,.o,$(sources))
objects := $(subst .c,.o,$(sources))




                                             3-38
   Embedded Linux Course
if-condition
  if-condition
      text if the condition is true
  else
      text if the condition is false
  endif


ā€¢ The if-condition can be one of:
   ifdef variable-name
   ifndef variable-name
   ifeq test
   ifneq test




                                         3-39
       Embedded Linux Course
Example




                                  3-40
Embedded Linux Course
ifeq (a,                       a)
  # These are equal
endif

ifeq ( ā€œbā€,     ā€œbā€ )
  # These are not equal - 'b' != 'b '
endif


ifeq "a" "a"
  # These are equal
endif

ifeq 'b' 'b'
  # So are these
endif


                                        3-41
Embedded Linux Course
ifeq (.config,$(wildcard .config))
  ifeq (.config,$(wildcard .config))
 include .config
  include .config
    ifeq (.depend,$(wildcard .depend))
     ifeq (.depend,$(wildcard .depend))
       include .depend
        include .depend
            ifndef CONFIG_UCLINUX
             ifndef CONFIG_UCLINUX
               LINUX=vmlinux
                LINUX=vmlinux
           else
            else
              LINUX=linux
               LINUX=linux
           endif
            endif
      do-it-all:
       do-it-all: Version $(LINUX)
                     Version $(LINUX)
    else
     else
      CONFIGURATION = depend
       CONFIGURATION = depend
      do-it-all:
       do-it-all: depend
                     depend
    endif
     endif
 else
  else
 CONFIGURATION = config
  CONFIGURATION = config
 do-it-all:
  do-it-all: config
                  config
 endif
  endif

                                          3-42
Embedded Linux Course
GNU Build System
            (autotools)




                            3-43
Embedded Linux Course
GNU Build System


ā€¢ The GNU build system (aka, autotools )
  provides an environment to a computer
  programmer which allows them to write cross-
  platform software
ā€¢ It also makes the build process easier on the
  user, allowing the user to usually just run a
  small set of commands to build the program
  from its source code and install it.

                                                  3-44
     Embedded Linux Course
GNU Autotools
ā€¢ Autotools comprises the GNU utility programs
  Autoconf, Automake, and Libtool.
ā€¢ Other related tools frequently used with the GNU
  build system are GNUā€™s make, GNU gettext,
  pkg-config, and the GNU gcc.
ā€¢ The utilities used by the GNU build system are
  only required to be on the developerā€™s
  workstation



                                                3-45
     Embedded Linux Course
autoconf
          and                                         *       *   *
       automake

                                                          *


                                                              *




                                                              *
a. * means executable
b. template file, customarily ending in ".inā€œ, ā€œacā€


                                                                      3-46
          Embedded Linux Course
GNU Autoconf
ā€¢ Autoconf is a tool for producing shell scripts that
  automatically configure software source code
  packages to adapt to many kinds of UNIX-like
  systems.
ā€¢ Autoconf makes use of GNU m4 to transform a
  user-written 'configure.ac' file to a portable
  'configureā€˜ script.
ā€¢ The 'configure' generates customized headers
  and makefiles derived from pre-written
  templates.


                                                   3-47
      Embedded Linux Course
GNU Autoconf (cont.)
ā€¢ The Autoconf approach to portability is to test
  whether a particular feature is supported or not
ā€¢ it also allows user to have the ā€˜configureā€™ script
  to customize.




                                                       3-48
      Embedded Linux Course
GNU Automake
ā€¢ Automake aims to allow the programmer to write
  a makefile in a higher-level language, rather
  than having to write the whole makefile manually
ā€¢ Automake helps to create portable Makefile,
  which are in turn processed with the make utility.
ā€¢ Must be used with GNU autoconf




                                                  3-49
      Embedded Linux Course
GNU Automake (cont.)
ā€¢ Automake contains two commands:
   ā€“ aclocal : a program for autoconf users
   ā€“ Automake
ā€¢ In simple cases, it suffices to give:
   ā€“ a line that declares the name of the program to build
   ā€“ a list of source files
   ā€“ a list of command-line options to be passed to the gcc (namely,
     in which directories header files will be found)
   ā€“ a list of command-line options to be passed to the ld (which
     libraries the program needs and in what directories they are to
     be found).



                                                                  3-50
       Embedded Linux Course
GNU Libtool
ā€¢ Libtool helps manage the creation of static and
  dynamic libraries on various Unix-like operating
  systems.
ā€¢ Libtool accomplishes this by abstracting the
  library creation process, hiding differences
  between various systems




                                                 3-51
     Embedded Linux Course
ScreenShot for CodeBlocks
Free IDE ,e.g.,
ā€¢ Eclipse
ā€¢ Anjuta
ā€¢ CodeBlocks




                                   3-52
        Embedded Linux Course
Configure Script
ā€¢ ā€˜configureā€™ attempts to guess correct values for various
  system-dependent variables used during compilation.
  It uses those values to create a `Makefile' in each
  directory of the package.
ā€¢ It may also create one or more `.h' files containing
  system-dependent definitions.

    In new development, library dependency checking has been done in great
     part using pkg-config

  pkg-config is a helper tool used when compiling applications and libraries. It
  helps you insert the correct compiler options on the command line.

                                                                             3-53
        Embedded Linux Course
Screenshot for ā€˜./configureā€™




                               3-54
Embedded Linux Course
The Output from ā€˜configureā€™
ā€¢ A script config.status that you can run in the
  future to recreate the current configuration
ā€¢ A file config.cache that saves the results of its
  tests to speed up reconfiguring, and
ā€¢ A file config.log containing compiler output,
  useful for debugging `configureā€˜

   make distclean
   make realclean
     remove the files that `configure' created (so you can compile the
    package for a different kind of computer),


                                                                         3-55
       Embedded Linux Course
ā€¢ If you need to do unusual things to compile the
  package, please try to figure out how `configure'
  could check whether to do them
ā€¢ If at some point config.cache contains results
  you don't want to keep, you may remove or edit
  it.
ā€¢ You only need configure.ac if you want to
  change it or regenerate `configure' using a
  newer version of autoconf.



                                                  3-56
      Embedded Linux Course
Compilers and Options
ā€¢ Some systems require unusual options for
  compilation or linking that the `configure' script
  does not know about
      CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
     CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure


ā€¢ The 'configure' script can be given a number of
  options to enable and disable various features.
  For a complete list, type:
      ./configure --help

                                                            3-57
      Embedded Linux Course
Specifying the System Type
ā€¢ There may be some features `configure' can not figure
  out automatically, but needs to determine by the type of
  host the package will run on

    System types:
     --build=BUILD      configure for building on BUILD [guessed]
     --host=HOST        cross-compile to build programs to run on
    HOST [BUILD]
   ā€“ type format: CPU-OS
   ā€“ See the file `config.sub' for the possible values of each field .


ā€¢ If you are building compiler tools for cross-compiling, you
  can will need ā€“host=CPU-OS

                                                                         3-58
       Embedded Linux Course
Screenshot




                                 3-59
Embedded Linux Course
Examples for configure
Step1 : Export your toolchain path firstly
    ā€“ export PATH=/usr/local/arm/3.4.1/bin:$PATH

Step 2 : Execute configure script,
    ā€“ CC=arm-linux-gcc ./configure --host=arm-linux
    ā€“ CC=mips-uclibc-gcc ./configure --host=mips-linux
    ā€“ CC=arm-elf-gcc ./configure --target=arm-linux --endian-mode=littile

   Normally, you will need to execute ā€œ./configure - - helpā€ to enable or disable
   some features supported by this software package




                                                                               3-60
         Embedded Linux Course
Cross-compiling Applications
ā€œCC=arm-linux-gcc ./configure ā€“host=arm-linux ā€

Unluckily enough, you need to go through the following..
Step 1: ā€œ./configureā€

this will create a Makefile for your x86 linux.

Step 2: include <SDK>/filesystem/make.def

Include make.def at the top of your Makefile

Step 3: Edit Makefile appropriately
For example,
         # CC=gcc
         # AR=ar
         -I<the_path_to_your_toolchain_include_path>
         -L<the_path_to_your_toolchain_library_path>




                                                           3-61
        Embedded Linux Course
Test Your Program
Download your code to board for testing
ā€¢ Ifconfig eth0 192.168.2.x
ā€¢ cd /var;
ā€¢ tftp ā€“g ā€“r <executable> <tftp_server>
ā€¢ chmod +x <executable>
ā€¢ ./ <executable>




                                          3-62
     Embedded Linux Course
Faild to configure




                                3-63
Embedded Linux Course
Cross-compiling Kernel modules
ā€¢ Building the kernel module will need the properly
  configured kernel sources
ā€¢ During the build process of this package the
  kernel Makefile and the current kernel
  configuration will be used
ā€¢ The modules should be compiled with the same
  compiler version.
 Some kernel modules are only supported with recent kernel versions. That
 means that compilation of these drivers might fail with older kernel versions.



                                                                             3-64
       Embedded Linux Course
Kernel Source Layout




                            3-65
Embedded Linux Course
#rules.make

KERNELSRC:= linux-2.6.x

export KERNELSRC

                               3-66
       Embedded Linux Course
Test Your Module
Download led.ko and test program to your board
# čح定ęæ子 IP                           # č¼‰å…„ Module
Ifconfig eth0 192.168.2.x           insmod led.ko
 cd /var;                           # ęŸ„č©¢ Module
# 取得 led.ko                         lsmod
tftp ā€“g ā€“r led.ko <tftp_server>     # ē”¢ē”Ÿ device node
# 取得ęø¬č©¦ē؋式                            mknod /dev/led c 230 0
tftp ā€“g ā€“r led_test <tftp_server>   # åŸ·č”Œęø¬č©¦ē؋式
# ęø¬č©¦ē؋式加äøŠåŸ·č”Œę¬Šé™                        ./led_test
chmod +x led_test                   # ē§»é™¤ Module
                                    rmmod led




                                                             3-67
       Embedded Linux Course
References
ā€¢ GNU Manuals Online
  ā€“ http://www.gnu.org/software/make/manual/
  ā€“ Managing Projects with GNU Makeā€ by Robert
    Mecklenburg
  ā€“ O'Reilly, Nov 19, 2004




                                                 3-68
      Embedded Linux Course

More Related Content

What's hot

Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
Anu Chaudhry
Ā 
Git and github
Git and githubGit and github
Git and github
Sayantika Banik
Ā 
LetSwift 2017 - ķ† ģŠ¤ iOS ģ•±ģ˜ ź°œė°œ/ė°°ķ¬ ķ™˜ź²½
LetSwift 2017 - ķ† ģŠ¤ iOS ģ•±ģ˜ ź°œė°œ/ė°°ķ¬ ķ™˜ź²½LetSwift 2017 - ķ† ģŠ¤ iOS ģ•±ģ˜ ź°œė°œ/ė°°ķ¬ ķ™˜ź²½
LetSwift 2017 - ķ† ģŠ¤ iOS ģ•±ģ˜ ź°œė°œ/ė°°ķ¬ ķ™˜ź²½
Mintak Son
Ā 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and Concepts
Carl Brown
Ā 
IntroducciĆ³n a GIT
IntroducciĆ³n a GITIntroducciĆ³n a GIT
IntroducciĆ³n a GIT
maxfontana90
Ā 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
vceder
Ā 
Shell programming
Shell programmingShell programming
Shell programming
Moayad Moawiah
Ā 
CMake best practices
CMake best practicesCMake best practices
CMake best practices
Henry Schreiner
Ā 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utility
Nirajan Pant
Ā 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
Joao Pereira
Ā 
Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examples
abclearnn
Ā 
MR201406 A Re-introduction to SELinux
MR201406 A Re-introduction to SELinuxMR201406 A Re-introduction to SELinux
MR201406 A Re-introduction to SELinux
FFRI, Inc.
Ā 
Js scope
Js scopeJs scope
Racing The Web - Hackfest 2016
Racing The Web - Hackfest 2016Racing The Web - Hackfest 2016
Racing The Web - Hackfest 2016
Aaron Hnatiw
Ā 
Valgrind tutorial
Valgrind tutorialValgrind tutorial
Valgrind tutorial
Satabdi Das
Ā 
Unix - Filters/Editors
Unix - Filters/EditorsUnix - Filters/Editors
Unix - Filters/Editorsananthimurugesan
Ā 
SemVer, the whole story
SemVer, the whole storySemVer, the whole story
SemVer, the whole story
JakeGinnivan
Ā 
啟動 Laravel 與ē’°å¢ƒčح定
啟動 Laravel 與ē’°å¢ƒčح定啟動 Laravel 與ē’°å¢ƒčح定
啟動 Laravel 與ē’°å¢ƒčح定
Shengyou Fan
Ā 
Introduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech Article
PRIYATHAMDARISI
Ā 
XPDDS18: A dive into kbuild - Cao jin, Fujitsu
XPDDS18: A dive into kbuild - Cao jin, FujitsuXPDDS18: A dive into kbuild - Cao jin, Fujitsu
XPDDS18: A dive into kbuild - Cao jin, Fujitsu
The Linux Foundation
Ā 

What's hot (20)

Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
Ā 
Git and github
Git and githubGit and github
Git and github
Ā 
LetSwift 2017 - ķ† ģŠ¤ iOS ģ•±ģ˜ ź°œė°œ/ė°°ķ¬ ķ™˜ź²½
LetSwift 2017 - ķ† ģŠ¤ iOS ģ•±ģ˜ ź°œė°œ/ė°°ķ¬ ķ™˜ź²½LetSwift 2017 - ķ† ģŠ¤ iOS ģ•±ģ˜ ź°œė°œ/ė°°ķ¬ ķ™˜ź²½
LetSwift 2017 - ķ† ģŠ¤ iOS ģ•±ģ˜ ź°œė°œ/ė°°ķ¬ ķ™˜ź²½
Ā 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and Concepts
Ā 
IntroducciĆ³n a GIT
IntroducciĆ³n a GITIntroducciĆ³n a GIT
IntroducciĆ³n a GIT
Ā 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
Ā 
Shell programming
Shell programmingShell programming
Shell programming
Ā 
CMake best practices
CMake best practicesCMake best practices
CMake best practices
Ā 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utility
Ā 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
Ā 
Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examples
Ā 
MR201406 A Re-introduction to SELinux
MR201406 A Re-introduction to SELinuxMR201406 A Re-introduction to SELinux
MR201406 A Re-introduction to SELinux
Ā 
Js scope
Js scopeJs scope
Js scope
Ā 
Racing The Web - Hackfest 2016
Racing The Web - Hackfest 2016Racing The Web - Hackfest 2016
Racing The Web - Hackfest 2016
Ā 
Valgrind tutorial
Valgrind tutorialValgrind tutorial
Valgrind tutorial
Ā 
Unix - Filters/Editors
Unix - Filters/EditorsUnix - Filters/Editors
Unix - Filters/Editors
Ā 
SemVer, the whole story
SemVer, the whole storySemVer, the whole story
SemVer, the whole story
Ā 
啟動 Laravel 與ē’°å¢ƒčح定
啟動 Laravel 與ē’°å¢ƒčح定啟動 Laravel 與ē’°å¢ƒčح定
啟動 Laravel 與ē’°å¢ƒčح定
Ā 
Introduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech Article
Ā 
XPDDS18: A dive into kbuild - Cao jin, Fujitsu
XPDDS18: A dive into kbuild - Cao jin, FujitsuXPDDS18: A dive into kbuild - Cao jin, Fujitsu
XPDDS18: A dive into kbuild - Cao jin, Fujitsu
Ā 

Viewers also liked

Makefiles Intro
Makefiles IntroMakefiles Intro
Makefiles Intro
Ynon Perek
Ā 
Makefile
MakefileMakefile
Makefile
Ionela
Ā 
CRAL MPS: Anatomia di un sistema GNU Linux
CRAL MPS: Anatomia di un sistema GNU LinuxCRAL MPS: Anatomia di un sistema GNU Linux
CRAL MPS: Anatomia di un sistema GNU LinuxPaolo Sammicheli
Ā 
Presentation. OpenSolaris.
Presentation. OpenSolaris. Presentation. OpenSolaris.
Presentation. OpenSolaris.
Ilya Tretyakov
Ā 
Graphical libraries
Graphical librariesGraphical libraries
Graphical libraries
guestbd40369
Ā 
Nats in action a real time microservices architecture handled by nats
Nats in action   a real time microservices architecture handled by natsNats in action   a real time microservices architecture handled by nats
Nats in action a real time microservices architecture handled by nats
Raul Perez
Ā 
Build Golang projects properly with Makefiles
Build Golang projects properly with MakefilesBuild Golang projects properly with Makefiles
Build Golang projects properly with MakefilesRaĆ¼l PĆ©rez
Ā 
Introduction To Opensource And GNU/Linux
Introduction To Opensource And GNU/LinuxIntroduction To Opensource And GNU/Linux
Introduction To Opensource And GNU/Linux
Sheila Eiffert
Ā 
ppt on linux by MUKESH PATEL
ppt on linux by MUKESH PATELppt on linux by MUKESH PATEL
ppt on linux by MUKESH PATEL
neo_patel
Ā 
Introduction to Linux OS
Introduction to Linux OSIntroduction to Linux OS
Introduction to Linux OSMohammed Safwat
Ā 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)
anandvaidya
Ā 
An Introduction to Linux
An Introduction to LinuxAn Introduction to Linux
An Introduction to Linux
anandvaidya
Ā 
Linux.ppt
Linux.ppt Linux.ppt
Linux.ppt
onu9
Ā 

Viewers also liked (13)

Makefiles Intro
Makefiles IntroMakefiles Intro
Makefiles Intro
Ā 
Makefile
MakefileMakefile
Makefile
Ā 
CRAL MPS: Anatomia di un sistema GNU Linux
CRAL MPS: Anatomia di un sistema GNU LinuxCRAL MPS: Anatomia di un sistema GNU Linux
CRAL MPS: Anatomia di un sistema GNU Linux
Ā 
Presentation. OpenSolaris.
Presentation. OpenSolaris. Presentation. OpenSolaris.
Presentation. OpenSolaris.
Ā 
Graphical libraries
Graphical librariesGraphical libraries
Graphical libraries
Ā 
Nats in action a real time microservices architecture handled by nats
Nats in action   a real time microservices architecture handled by natsNats in action   a real time microservices architecture handled by nats
Nats in action a real time microservices architecture handled by nats
Ā 
Build Golang projects properly with Makefiles
Build Golang projects properly with MakefilesBuild Golang projects properly with Makefiles
Build Golang projects properly with Makefiles
Ā 
Introduction To Opensource And GNU/Linux
Introduction To Opensource And GNU/LinuxIntroduction To Opensource And GNU/Linux
Introduction To Opensource And GNU/Linux
Ā 
ppt on linux by MUKESH PATEL
ppt on linux by MUKESH PATELppt on linux by MUKESH PATEL
ppt on linux by MUKESH PATEL
Ā 
Introduction to Linux OS
Introduction to Linux OSIntroduction to Linux OS
Introduction to Linux OS
Ā 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)
Ā 
An Introduction to Linux
An Introduction to LinuxAn Introduction to Linux
An Introduction to Linux
Ā 
Linux.ppt
Linux.ppt Linux.ppt
Linux.ppt
Ā 

Similar to Ch3 gnu make

LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
Thninh2
Ā 
嵌兄式LinuxčŖ²ē؋-GNU Toolchain
嵌兄式LinuxčŖ²ē؋-GNU Toolchain嵌兄式LinuxčŖ²ē؋-GNU Toolchain
嵌兄式LinuxčŖ²ē؋-GNU Toolchain
č‰¾é—ē§‘ꊀ
Ā 
Session3
Session3Session3
Session3Learn 2 Be
Ā 
L lpic1-v3-103-1-pdf
L lpic1-v3-103-1-pdfL lpic1-v3-103-1-pdf
L lpic1-v3-103-1-pdfhellojdr
Ā 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
Sasidhar Kothuru
Ā 
dotor.pdf
dotor.pdfdotor.pdf
dotor.pdf
JaveedAhamed7
Ā 
Types of Linux Shells
Types of Linux Shells Types of Linux Shells
Types of Linux Shells
BIT DURG
Ā 
Working with files and directories in Linux
Working with files and directories in LinuxWorking with files and directories in Linux
Working with files and directories in Linux
Zeeshan Iqbal
Ā 
Basic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualBasic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manual
Kuntal Bhowmick
Ā 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
Harikrishnan Ramakrishnan
Ā 
Lnx
LnxLnx
New features in Ruby 2.5
New features in Ruby 2.5New features in Ruby 2.5
New features in Ruby 2.5
Ireneusz Skrobiś
Ā 
Group13
Group13Group13
Group13
21MX213OMRAJUV
Ā 
Linux
LinuxLinux
Linux
RittikaBaksi
Ā 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdf
harikrishnapolaki
Ā 
LinuxCommands (1).pdf
LinuxCommands (1).pdfLinuxCommands (1).pdf
LinuxCommands (1).pdf
AnkitKushwaha792697
Ā 
Linux Basics.pptx
Linux Basics.pptxLinux Basics.pptx
Linux Basics.pptx
RanjitKumarPanda5
Ā 

Similar to Ch3 gnu make (20)

LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
Ā 
嵌兄式LinuxčŖ²ē؋-GNU Toolchain
嵌兄式LinuxčŖ²ē؋-GNU Toolchain嵌兄式LinuxčŖ²ē؋-GNU Toolchain
嵌兄式LinuxčŖ²ē؋-GNU Toolchain
Ā 
Session3
Session3Session3
Session3
Ā 
L lpic1-v3-103-1-pdf
L lpic1-v3-103-1-pdfL lpic1-v3-103-1-pdf
L lpic1-v3-103-1-pdf
Ā 
Gun make
Gun makeGun make
Gun make
Ā 
Mbuild help
Mbuild helpMbuild help
Mbuild help
Ā 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
Ā 
dotor.pdf
dotor.pdfdotor.pdf
dotor.pdf
Ā 
Types of Linux Shells
Types of Linux Shells Types of Linux Shells
Types of Linux Shells
Ā 
Working with files and directories in Linux
Working with files and directories in LinuxWorking with files and directories in Linux
Working with files and directories in Linux
Ā 
Basic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualBasic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manual
Ā 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
Ā 
Lnx
LnxLnx
Lnx
Ā 
New features in Ruby 2.5
New features in Ruby 2.5New features in Ruby 2.5
New features in Ruby 2.5
Ā 
Group13
Group13Group13
Group13
Ā 
Linux
LinuxLinux
Linux
Ā 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdf
Ā 
Unix
UnixUnix
Unix
Ā 
LinuxCommands (1).pdf
LinuxCommands (1).pdfLinuxCommands (1).pdf
LinuxCommands (1).pdf
Ā 
Linux Basics.pptx
Linux Basics.pptxLinux Basics.pptx
Linux Basics.pptx
Ā 

More from č‰¾é—ē§‘ꊀ

TinyML - 4 speech recognition
TinyML - 4 speech recognition TinyML - 4 speech recognition
TinyML - 4 speech recognition
č‰¾é—ē§‘ꊀ
Ā 
Appendix 1 Goolge colab
Appendix 1 Goolge colabAppendix 1 Goolge colab
Appendix 1 Goolge colab
č‰¾é—ē§‘ꊀ
Ā 
Project-IOTę–¼é¤é¤Øē³»ēµ±ēš„ꇉē”Ø
Project-IOTę–¼é¤é¤Øē³»ēµ±ēš„ꇉē”ØProject-IOTę–¼é¤é¤Øē³»ēµ±ēš„ꇉē”Ø
Project-IOTę–¼é¤é¤Øē³»ēµ±ēš„ꇉē”Ø
č‰¾é—ē§‘ꊀ
Ā 
02 IoT implementation
02 IoT implementation02 IoT implementation
02 IoT implementation
č‰¾é—ē§‘ꊀ
Ā 
Tiny ML for spark Fun Edge
Tiny ML for spark Fun EdgeTiny ML for spark Fun Edge
Tiny ML for spark Fun Edge
č‰¾é—ē§‘ꊀ
Ā 
Openvino ncs2
Openvino ncs2Openvino ncs2
Openvino ncs2
č‰¾é—ē§‘ꊀ
Ā 
Step motor
Step motorStep motor
2. ę©Ÿå™Øå­øēæ’ē°”介
2. ę©Ÿå™Øå­øēæ’ē°”介2. ę©Ÿå™Øå­øēæ’ē°”介
2. ę©Ÿå™Øå­øēæ’ē°”介
č‰¾é—ē§‘ꊀ
Ā 
5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron) 5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron)
č‰¾é—ē§‘ꊀ
Ā 
3. data features
3. data features3. data features
3. data features
č‰¾é—ē§‘ꊀ
Ā 
åæƒēŽ‡č”€ę°§ęŖ¢ęø¬čˆ‡é‹å‹•äæƒé€²
åæƒēŽ‡č”€ę°§ęŖ¢ęø¬čˆ‡é‹å‹•äæƒé€²åæƒēŽ‡č”€ę°§ęŖ¢ęø¬čˆ‡é‹å‹•äæƒé€²
åæƒēŽ‡č”€ę°§ęŖ¢ęø¬čˆ‡é‹å‹•äæƒé€²
č‰¾é—ē§‘ꊀ
Ā 
利ē”Ø音ę؂&ęƒ…å¢ƒē‡ˆå¹«åŠ©ę”¾é¬†
利ē”Ø音ę؂&ęƒ…å¢ƒē‡ˆå¹«åŠ©ę”¾é¬†åˆ©ē”Ø音ę؂&ęƒ…å¢ƒē‡ˆå¹«åŠ©ę”¾é¬†
利ē”Ø音ę؂&ęƒ…å¢ƒē‡ˆå¹«åŠ©ę”¾é¬†
č‰¾é—ē§‘ꊀ
Ā 
IoTꄟęø¬å™Ø驅動ē؋式 åœØęØ¹čŽ“ę“¾äøŠåƦ作
IoTꄟęø¬å™Ø驅動ē؋式åœØęØ¹čŽ“ę“¾äøŠåƦ作IoTꄟęø¬å™Ø驅動ē؋式åœØęØ¹čŽ“ę“¾äøŠåƦ作
IoTꄟęø¬å™Ø驅動ē؋式 åœØęØ¹čŽ“ę“¾äøŠåƦ作
č‰¾é—ē§‘ꊀ
Ā 
ē„”ē·šč²ęŽ§é™ęŽ§č»Š
ē„”ē·šč²ęŽ§é™ęŽ§č»Šē„”ē·šč²ęŽ§é™ęŽ§č»Š
ē„”ē·šč²ęŽ§é™ęŽ§č»Š
č‰¾é—ē§‘ꊀ
Ā 
ęœ€ä½³å…‰ęŗēš„ē ”ē©¶å’ŒåƦ作
ęœ€ä½³å…‰ęŗēš„ē ”ē©¶å’ŒåƦ作ęœ€ä½³å…‰ęŗēš„ē ”ē©¶å’ŒåƦ作
ęœ€ä½³å…‰ęŗēš„ē ”ē©¶å’ŒåƦ作
č‰¾é—ē§‘ꊀ
Ā 
ē„”ē·šē›£ęŽ§ē¶²č·Æę”å½±ę©Ÿčˆ‡ęŽ§åˆ¶č‡Ŗ走車
ē„”ē·šē›£ęŽ§ē¶²č·Æę”å½±ę©Ÿčˆ‡ęŽ§åˆ¶č‡Ŗ走車ē„”ē·šē›£ęŽ§ē¶²č·Æę”å½±ę©Ÿčˆ‡ęŽ§åˆ¶č‡Ŗ走車
ē„”ē·šē›£ęŽ§ē¶²č·Æę”å½±ę©Ÿčˆ‡ęŽ§åˆ¶č‡Ŗ走車
č‰¾é—ē§‘ꊀ
Ā 
Reinforcement Learning
Reinforcement LearningReinforcement Learning
Reinforcement Learning
č‰¾é—ē§‘ꊀ
Ā 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
č‰¾é—ē§‘ꊀ
Ā 
äŗŗ臉č¾Øč­˜č€ƒå‹¤ē³»ēµ±
äŗŗ臉č¾Øč­˜č€ƒå‹¤ē³»ēµ±äŗŗ臉č¾Øč­˜č€ƒå‹¤ē³»ēµ±
äŗŗ臉č¾Øč­˜č€ƒå‹¤ē³»ēµ±
č‰¾é—ē§‘ꊀ
Ā 
ę™ŗę…§å®¶åŗ­Smart Home
ę™ŗę…§å®¶åŗ­Smart Homeę™ŗę…§å®¶åŗ­Smart Home
ę™ŗę…§å®¶åŗ­Smart Home
č‰¾é—ē§‘ꊀ
Ā 

More from č‰¾é—ē§‘ꊀ (20)

TinyML - 4 speech recognition
TinyML - 4 speech recognition TinyML - 4 speech recognition
TinyML - 4 speech recognition
Ā 
Appendix 1 Goolge colab
Appendix 1 Goolge colabAppendix 1 Goolge colab
Appendix 1 Goolge colab
Ā 
Project-IOTę–¼é¤é¤Øē³»ēµ±ēš„ꇉē”Ø
Project-IOTę–¼é¤é¤Øē³»ēµ±ēš„ꇉē”ØProject-IOTę–¼é¤é¤Øē³»ēµ±ēš„ꇉē”Ø
Project-IOTę–¼é¤é¤Øē³»ēµ±ēš„ꇉē”Ø
Ā 
02 IoT implementation
02 IoT implementation02 IoT implementation
02 IoT implementation
Ā 
Tiny ML for spark Fun Edge
Tiny ML for spark Fun EdgeTiny ML for spark Fun Edge
Tiny ML for spark Fun Edge
Ā 
Openvino ncs2
Openvino ncs2Openvino ncs2
Openvino ncs2
Ā 
Step motor
Step motorStep motor
Step motor
Ā 
2. ę©Ÿå™Øå­øēæ’ē°”介
2. ę©Ÿå™Øå­øēæ’ē°”介2. ę©Ÿå™Øå­øēæ’ē°”介
2. ę©Ÿå™Øå­øēæ’ē°”介
Ā 
5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron) 5.MLP(Multi-Layer Perceptron)
5.MLP(Multi-Layer Perceptron)
Ā 
3. data features
3. data features3. data features
3. data features
Ā 
åæƒēŽ‡č”€ę°§ęŖ¢ęø¬čˆ‡é‹å‹•äæƒé€²
åæƒēŽ‡č”€ę°§ęŖ¢ęø¬čˆ‡é‹å‹•äæƒé€²åæƒēŽ‡č”€ę°§ęŖ¢ęø¬čˆ‡é‹å‹•äæƒé€²
åæƒēŽ‡č”€ę°§ęŖ¢ęø¬čˆ‡é‹å‹•äæƒé€²
Ā 
利ē”Ø音ę؂&ęƒ…å¢ƒē‡ˆå¹«åŠ©ę”¾é¬†
利ē”Ø音ę؂&ęƒ…å¢ƒē‡ˆå¹«åŠ©ę”¾é¬†åˆ©ē”Ø音ę؂&ęƒ…å¢ƒē‡ˆå¹«åŠ©ę”¾é¬†
利ē”Ø音ę؂&ęƒ…å¢ƒē‡ˆå¹«åŠ©ę”¾é¬†
Ā 
IoTꄟęø¬å™Ø驅動ē؋式 åœØęØ¹čŽ“ę“¾äøŠåƦ作
IoTꄟęø¬å™Ø驅動ē؋式åœØęØ¹čŽ“ę“¾äøŠåƦ作IoTꄟęø¬å™Ø驅動ē؋式åœØęØ¹čŽ“ę“¾äøŠåƦ作
IoTꄟęø¬å™Ø驅動ē؋式 åœØęØ¹čŽ“ę“¾äøŠåƦ作
Ā 
ē„”ē·šč²ęŽ§é™ęŽ§č»Š
ē„”ē·šč²ęŽ§é™ęŽ§č»Šē„”ē·šč²ęŽ§é™ęŽ§č»Š
ē„”ē·šč²ęŽ§é™ęŽ§č»Š
Ā 
ęœ€ä½³å…‰ęŗēš„ē ”ē©¶å’ŒåƦ作
ęœ€ä½³å…‰ęŗēš„ē ”ē©¶å’ŒåƦ作ęœ€ä½³å…‰ęŗēš„ē ”ē©¶å’ŒåƦ作
ęœ€ä½³å…‰ęŗēš„ē ”ē©¶å’ŒåƦ作
Ā 
ē„”ē·šē›£ęŽ§ē¶²č·Æę”å½±ę©Ÿčˆ‡ęŽ§åˆ¶č‡Ŗ走車
ē„”ē·šē›£ęŽ§ē¶²č·Æę”å½±ę©Ÿčˆ‡ęŽ§åˆ¶č‡Ŗ走車ē„”ē·šē›£ęŽ§ē¶²č·Æę”å½±ę©Ÿčˆ‡ęŽ§åˆ¶č‡Ŗ走車
ē„”ē·šē›£ęŽ§ē¶²č·Æę”å½±ę©Ÿčˆ‡ęŽ§åˆ¶č‡Ŗ走車
Ā 
Reinforcement Learning
Reinforcement LearningReinforcement Learning
Reinforcement Learning
Ā 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
Ā 
äŗŗ臉č¾Øč­˜č€ƒå‹¤ē³»ēµ±
äŗŗ臉č¾Øč­˜č€ƒå‹¤ē³»ēµ±äŗŗ臉č¾Øč­˜č€ƒå‹¤ē³»ēµ±
äŗŗ臉č¾Øč­˜č€ƒå‹¤ē³»ēµ±
Ā 
ę™ŗę…§å®¶åŗ­Smart Home
ę™ŗę…§å®¶åŗ­Smart Homeę™ŗę…§å®¶åŗ­Smart Home
ę™ŗę…§å®¶åŗ­Smart Home
Ā 

Recently uploaded

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
Ā 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
Ā 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
Ā 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
Ā 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
Ā 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
Ā 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
Ā 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
Ā 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
Ā 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
Ā 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
Ā 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
Ā 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
Ā 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
Ā 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
Ā 
BƀI Tįŗ¬P Bį»” TRį»¢ TIįŗ¾NG ANH GLOBAL SUCCESS Lį»šP 3 - Cįŗ¢ NĂM (CƓ FILE NGHE Vƀ ĐƁP Ɓ...
BƀI Tįŗ¬P Bį»” TRį»¢ TIįŗ¾NG ANH GLOBAL SUCCESS Lį»šP 3 - Cįŗ¢ NĂM (CƓ FILE NGHE Vƀ ĐƁP Ɓ...BƀI Tįŗ¬P Bį»” TRį»¢ TIįŗ¾NG ANH GLOBAL SUCCESS Lį»šP 3 - Cįŗ¢ NĂM (CƓ FILE NGHE Vƀ ĐƁP Ɓ...
BƀI Tįŗ¬P Bį»” TRį»¢ TIįŗ¾NG ANH GLOBAL SUCCESS Lį»šP 3 - Cįŗ¢ NĂM (CƓ FILE NGHE Vƀ ĐƁP Ɓ...
Nguyen Thanh Tu Collection
Ā 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
Ā 
Lapbook sobre os Regimes TotalitƔrios.pdf
Lapbook sobre os Regimes TotalitƔrios.pdfLapbook sobre os Regimes TotalitƔrios.pdf
Lapbook sobre os Regimes TotalitƔrios.pdf
Jean Carlos Nunes PaixĆ£o
Ā 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
Ā 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
Ā 

Recently uploaded (20)

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Ā 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
Ā 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
Ā 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Ā 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
Ā 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
Ā 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Ā 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Ā 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
Ā 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Ā 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
Ā 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Ā 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Ā 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Ā 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Ā 
BƀI Tįŗ¬P Bį»” TRį»¢ TIįŗ¾NG ANH GLOBAL SUCCESS Lį»šP 3 - Cįŗ¢ NĂM (CƓ FILE NGHE Vƀ ĐƁP Ɓ...
BƀI Tįŗ¬P Bį»” TRį»¢ TIįŗ¾NG ANH GLOBAL SUCCESS Lį»šP 3 - Cįŗ¢ NĂM (CƓ FILE NGHE Vƀ ĐƁP Ɓ...BƀI Tįŗ¬P Bį»” TRį»¢ TIįŗ¾NG ANH GLOBAL SUCCESS Lį»šP 3 - Cįŗ¢ NĂM (CƓ FILE NGHE Vƀ ĐƁP Ɓ...
BƀI Tįŗ¬P Bį»” TRį»¢ TIįŗ¾NG ANH GLOBAL SUCCESS Lį»šP 3 - Cįŗ¢ NĂM (CƓ FILE NGHE Vƀ ĐƁP Ɓ...
Ā 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
Ā 
Lapbook sobre os Regimes TotalitƔrios.pdf
Lapbook sobre os Regimes TotalitƔrios.pdfLapbook sobre os Regimes TotalitƔrios.pdf
Lapbook sobre os Regimes TotalitƔrios.pdf
Ā 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
Ā 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Ā 

Ch3 gnu make

  • 1. GNU Make 3-1 Embedded Linux Course
  • 2. GNU Make ā€¢ makeĀ utilityĀ determinesĀ automaticallyĀ whichĀ  piecesĀ ofĀ aĀ largeĀ programĀ needĀ toĀ beĀ  recompiled,Ā andĀ issuesĀ theĀ commandsĀ toĀ  recompileĀ them. ā€¢ makeĀ examineĀ theĀ sourceĀ andĀ objectĀ filesĀ toĀ  determineĀ whichĀ sourceĀ filesĀ needĀ toĀ beĀ  recompiledĀ toĀ createĀ newĀ objectĀ files. ā€¢ YouĀ needĀ aĀ fileĀ calledĀ aĀ MakefileĀ toĀ  tellĀ makeĀ whatĀ toĀ do 3-2 Embedded Linux Course
  • 3. GNU Make (cont.) ā€¢ TheĀ relationshipĀ ofĀ anĀ objectĀ fileĀ toĀ theĀ sourceĀ  fileĀ usedĀ toĀ produceĀ itĀ isĀ knownĀ asĀ aĀ dependencyĀ  ā€¢ ToĀ determineĀ theĀ dependencies,Ā makeĀ readsĀ aĀ  scriptĀ (Makefile)Ā thatĀ definesĀ them ā€¢ MakefileĀ tellsĀ makeĀ howĀ toĀ compileĀ andĀ linkĀ aĀ  program 3-3 Embedded Linux Course
  • 4. Ā Makefile ā€¢ EssentiallyĀ aĀ MakefileĀ containsĀ aĀ setĀ ofĀ rulesĀ usedĀ toĀ  buildĀ anĀ applicationĀ  ā€¢ TheĀ firstĀ ruleĀ seenĀ byĀ makeĀ isĀ usedĀ asĀ theĀ default rule.Ā  Ā Ā makeĀ target ā€¢ AĀ ruleĀ consistsĀ ofĀ threeĀ parts:Ā theĀ target,Ā itsĀ  prerequisites,Ā andĀ theĀ command(s)Ā toĀ performĀ  target: prereq1 prereq2 target: prereq1 prereq2 <TAB>shell commands <TAB>shell commands <TAB>shell commands <TAB>shell commands ā€¦. ā€¦. 3-4 Embedded Linux Course
  • 5. A Simple Makefile edit ::main.o utils.o edit main.o utils.o gcc -o edit main.o utils.o gcc -o edit main.o utils.o main.o ::main.c defs.h main.o main.c defs.h gcc -c main.c gcc -c main.c utils.o ::utils.c defs.h utils.o utils.c defs.h gcc -c utils.c gcc -c utils.c clean :: clean rm edit main.o utils.o rm edit main.o utils.o 3-5 Embedded Linux Course
  • 6. ā€¢ TheĀ targetĀ isĀ theĀ fileĀ orĀ thingĀ thatĀ mustĀ beĀ made ā€¢ TheĀ prerequisitesĀ orĀ dependentsĀ areĀ thoseĀ filesĀ  thatĀ mustĀ existĀ beforeĀ theĀ targetĀ canĀ beĀ  successfullyĀ created. ā€¢ TheĀ commandsĀ areĀ justĀ shellĀ commands foo.o:Ā foo.cĀ foo.h foo.o:Ā foo.cĀ foo.h Ā Ā Ā Ā Ā Ā Ā Ā gccĀ -cĀ foo.c Ā Ā Ā Ā Ā Ā Ā Ā gccĀ -cĀ foo.c 3-6 Embedded Linux Course
  • 7. Makefile Syntax ā€¢ OneĀ orĀ moreĀ targetsĀ appearĀ toĀ theĀ leftĀ ofĀ theĀ  colonĀ andĀ zeroĀ orĀ moreĀ prerequisitesĀ canĀ appearĀ  toĀ theĀ rightĀ ofĀ theĀ colon. ā€¢ IfĀ noĀ prerequisitesĀ areĀ listedĀ toĀ theĀ right,Ā thenĀ  onlyĀ theĀ target(s)Ā thatĀ doĀ notĀ existĀ areĀ updatedĀ  target1Ā target2Ā target3Ā :Ā prerequisite1Ā prerequisite2 <TAB>command1 <TAB>command2 <TAB>command3 3-7 Embedded Linux Course
  • 8. Makefile Syntax (cont.) ā€¢ EachĀ commandĀ mustĀ beginĀ withĀ aĀ tabĀ character.Ā  ThisĀ (obscure)Ā syntaxĀ tellsĀ makeĀ thatĀ theĀ  charactersĀ thatĀ followĀ theĀ tabĀ areĀ toĀ beĀ passedĀ toĀ  aĀ subshellĀ forĀ execution.Ā  Makefile2:6:Ā ***Ā missingĀ separatorĀ (didĀ youĀ meanĀ TABĀ insteadĀ ofĀ 8Ā spaces?).Ā  Ā Stop. ā€“ LongĀ linesĀ canĀ beĀ continuedĀ usingĀ theĀ standardĀ UnixĀ escapeĀ  characterĀ backslashĀ () ā€¢ TheĀ commentĀ characterĀ forĀ makeĀ isĀ theĀ ā€˜#ā€™ Ā  3-8 Embedded Linux Course
  • 9. My First Makefile ā€¢ AlthoughĀ theĀ allĀ targetĀ hasĀ twoĀ dependencies,Ā itĀ hasĀ noĀ  commandsĀ associatedĀ withĀ it,Ā butĀ thatā€™sĀ okayĀ becauseĀ  theĀ onlyĀ purposeĀ isĀ toĀ forceĀ theĀ dependenciesĀ toĀ beĀ  satisfied 3-9 Embedded Linux Course
  • 10. Phony Targets ā€¢ AĀ phonyĀ targetĀ isĀ oneĀ thatĀ isĀ notĀ reallyĀ theĀ nameĀ  ofĀ aĀ file.Ā ItĀ isĀ justĀ aĀ nameĀ forĀ someĀ commandsĀ toĀ  beĀ executedĀ whenĀ youĀ makeĀ anĀ explicitĀ request.Ā  ā€¢ ThereĀ areĀ twoĀ reasonsĀ toĀ useĀ aĀ phonyĀ target:Ā toĀ  avoidĀ aĀ conflictĀ withĀ aĀ fileĀ ofĀ theĀ sameĀ name,Ā andĀ  toĀ improveĀ performance.Ā  .PHONY: clean all .PHONY: clean all clean: clean: rm ā€“rf frammis cooker *.o *.bak *~ rm ā€“rf frammis cooker *.o *.bak *~ 3-10 Embedded Linux Course
  • 11. Force Targets ā€¢ YouĀ canĀ useĀ aĀ targetĀ withoutĀ commandsĀ orĀ prerequisitesĀ  toĀ markĀ otherĀ targetsĀ asĀ phonyĀ  clean: FORCE clean: FORCE rm $(objects) rm $(objects) FORCE: FORCE: ā€¢ IfĀ aĀ ruleĀ hasĀ noĀ prerequisitesĀ orĀ commands,Ā andĀ theĀ  targetĀ ofĀ theĀ ruleĀ isĀ aĀ nonexistentĀ file,Ā thenĀ makeĀ  imaginesĀ thisĀ targetĀ toĀ haveĀ beenĀ updatedĀ wheneverĀ itsĀ  ruleĀ isĀ run.Ā ThisĀ impliesĀ thatĀ allĀ targetsĀ dependingĀ onĀ thisĀ  oneĀ willĀ alwaysĀ haveĀ theirĀ commandsĀ run.Ā  3-11 Embedded Linux Course
  • 12. Variable ā€¢ AĀ macroĀ canĀ beĀ definedĀ inĀ oneĀ ofĀ threeĀ differentĀ  ways CC=gcc CC=gcc showmacros: showmacros: echoĀ CompilerĀ isĀ $(CC)Ā  echoĀ CompilerĀ isĀ $(CC)Ā  echoĀ HOMEĀ isĀ $(HOME) echoĀ HOMEĀ isĀ $(HOME) exportĀ Ā CC=arm-uclibc-gcc makeĀ Ā CC=arm-linux-gcc 3-12 Embedded Linux Course
  • 13. Variable Assignment ā€¢ =Ā VariableĀ isĀ aĀ recursively expandedĀ variable CFLAGSĀ =Ā $(include_dirs)Ā -O include_dirsĀ =Ā -IfooĀ -Ibar #TheĀ followingĀ willĀ causeĀ anĀ infiniteĀ loopĀ inĀ theĀ variableĀ expansionĀ  CFLAGSĀ =Ā $(CFLAGS)Ā -O ā€¢ :=Ā SimplyĀ expandedĀ variables Ā Ā Ā Ā Ā xĀ :=Ā foo Ā Ā Ā Ā Ā yĀ :=Ā $(x)Ā bar Ā Ā Ā Ā Ā xĀ :=Ā later isĀ equivalentĀ toĀ  Ā Ā Ā Ā Ā yĀ :=Ā fooĀ bar Ā Ā Ā Ā Ā xĀ :=Ā later 3-13 Embedded Linux Course
  • 14. Variable Assignment (cont.) ā€¢ ?=Ā conditional variableĀ  ā€¢ itĀ onlyĀ hasĀ anĀ effectĀ ifĀ theĀ variableĀ isĀ notĀ yetĀ  defined.Ā ThisĀ statement:Ā  FOO ?= bar ThisĀ isĀ exactlyĀ equivalentĀ toĀ this ifeq (ā€œ$(origin FOO)ā€, ā€œundefinedā€) FOO = bar endif 3-14 Embedded Linux Course
  • 15. Variable Assignment (cont.) ā€¢ +=Ā addĀ moreĀ textĀ toĀ theĀ valueĀ ofĀ aĀ variableĀ  alreadyĀ defined objects = main.o foo.o bar.o utils.o objects += another.o UsingĀ ā€˜+=ā€™Ā isĀ similarĀ to objects = main.o foo.o bar.o utils.o objects := $(objects) another.o 3-15 Embedded Linux Course
  • 16. Environment Variables ā€¢ CC C compiler command ā€¢ CFLAGS C compiler flags ā€¢ LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir> ā€¢ LIBS libraries to pass to the linker, e.g. -l<library> ā€¢ CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir> ā€¢ CPP C preprocessor (gcc -E) ā€¢ CXX C++ compiler command ā€¢ CXXFLAGS C++ compiler flags ā€¢ CXXCPP C++ preprocessor #example #example myprog:Ā Ā Ā Ā $(OBJS) myprog:Ā Ā Ā Ā $(OBJS) Ā Ā Ā Ā Ā Ā Ā Ā $(CC)Ā -oĀ $@Ā $^Ā $(LDFLAGS)Ā $(LIBS) Ā Ā Ā Ā Ā Ā Ā Ā $(CC)Ā -oĀ $@Ā $^Ā $(LDFLAGS)Ā $(LIBS) Use these variables to override the choices made by `configure' or to help Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. it to find libraries and programs with nonstandard names/locations. 3-16 Embedded Linux Course
  • 17. Automatic variables ā€¢ $@Ā :TheĀ fileĀ nameĀ ofĀ theĀ targetĀ ofĀ theĀ rule. ā€¢ $<Ā Ā :TheĀ nameĀ ofĀ theĀ firstĀ prerequisite.Ā  ā€¢ $?Ā Ā :TheĀ namesĀ ofĀ allĀ theĀ prerequisitesĀ thatĀ are Ā Ā newerĀ thanĀ theĀ target,Ā withĀ spacesĀ betweenĀ  Ā themĀ  ā€¢ $^Ā Ā Ā :TheĀ namesĀ ofĀ allĀ theĀ prerequisites,Ā withĀ  Ā Ā Ā spacesĀ betweenĀ themĀ  libtest.a:Ā foo.oĀ bar.oĀ lose.oĀ win.oĀ  libtest.a:Ā foo.oĀ bar.oĀ lose.oĀ win.oĀ  Ā Ā Ā Ā Ā Ā Ā $(AR)Ā $(ARFLAGS)Ā $@Ā $?Ā  Ā Ā Ā Ā Ā Ā Ā $(AR)Ā $(ARFLAGS)Ā $@Ā $?Ā  makeĀ willĀ passĀ onlyĀ thoseĀ objectsĀ filesĀ thatĀ areĀ newerĀ thanĀ theĀ targetĀ toĀ ar 3-17 Embedded Linux Course
  • 18. Exercise 3-18 Embedded Linux Course
  • 19. VPATH 3-19 Embedded Linux Course
  • 20. cross.make # Tool names # Tool names CROSS_COMPILE = arm-linux- CROSS_COMPILE = arm-linux- AS AS = $(CROSS_COMPILE)as = $(CROSS_COMPILE)as AR AR = $(CROSS_COMPILE)ar = $(CROSS_COMPILE)ar CC CC = $(CROSS_COMPILE)gcc = $(CROSS_COMPILE)gcc CPP CPP = $(CC) -E = $(CC) -E LD LD = $(CROSS_COMPILE)ld = $(CROSS_COMPILE)ld NM NM = $(CROSS_COMPILE)nm = $(CROSS_COMPILE)nm OBJCOPY OBJCOPY = $(CROSS_COMPILE)objcopy = $(CROSS_COMPILE)objcopy OBJDUMP OBJDUMP = $(CROSS_COMPILE)objdump = $(CROSS_COMPILE)objdump RANLIB RANLIB = $(CROSS_COMPILE)ranlib = $(CROSS_COMPILE)ranlib READELF READELF = $(CROSS_COMPILE)readelf = $(CROSS_COMPILE)readelf SIZE SIZE = $(CROSS_COMPILE)size = $(CROSS_COMPILE)size STRINGS STRINGS = $(CROSS_COMPILE)strings = $(CROSS_COMPILE)strings STRIP STRIP = $(CROSS_COMPILE)strip = $(CROSS_COMPILE)strip export AS AR CC CPP LD NM OBJCOPY OBJDUMP RANLIB READELF export AS AR CC CPP LD NM OBJCOPY OBJDUMP RANLIB READELF SIZE STRINGS STRIP SIZE STRINGS STRIP Note: export these values so that subsequent Makefiles called Note: export these values so that subsequent Makefiles called by this Makefile will use the same names by this Makefile will use the same names 3-20 Embedded Linux Course
  • 21. Recursive Invocations of make 3-21 Embedded Linux Course
  • 22. Top Makfile $(MAKE) -C $$dir ļƒØ cd dir && $(MAKE) MAKEFLAGS += --no-print-directory 3-22 Embedded Linux Course
  • 23. Recursive Invocations of make (cont.) /*config.mk*/ 3-23 Embedded Linux Course
  • 24. Using command line 3-24 Embedded Linux Course
  • 25. ā€¢ Note: By declaring the subdirectories as phony targets (you must do this as the subdirectory obviously always exists; otherwise it won't be built) 3-25 Embedded Linux Course
  • 26. Internal Definitions ā€¢ For convenience in constructing rules based on targets and dependencies, it is possible to use predefined macros and establish implicit rules that make can use to convert one file type to another. 3-26 Embedded Linux Course
  • 27. Pattern Rules ā€¢ Many programs that read one file type and output another conform to standard conventions ā€“ .c ==> .o , .S ==> .o ā€¢ These conventions allow make to simplify rule creation by recognizing common filename patterns and providing built-in rules for processing them ā€¢ The built-in rules are all instances of pattern rules %.o: %.c %.o: %.c # commands to execute (built-in): # commands to execute (built-in): $(COMPILE.c) $(OUTPUT_OPTION) $< $(COMPILE.c) $(OUTPUT_OPTION) $< OUTPUT_OPTION = -o $@ COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c 3-27 Embedded Linux Course
  • 28. Looking at Predefined Rules and Macros ā€¢ A large number of implicit rules are built into make (make -p) %.o: %.S %.o: %.S # commands to execute (built-in): # commands to execute (built-in): $(COMPILE.S) -o $@ $< $(COMPILE.S) -o $@ $< # there is a special rule to generate a file with no suffix (always an executable) # there is a special rule to generate a file with no suffix (always an executable) %: %.o %: %.o # commands to execute (built-in): # commands to execute (built-in): $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@ $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@ %: %.c %: %.c # commands to execute (built-in): # commands to execute (built-in): $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@ $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@ 3-28 Embedded Linux Course
  • 29. ā€¢ The % in a pattern rule is roughly equivalent to * in a Unix shell ā€“ represents any number of any characters. ā€¢ The % can be placed anywhere within the pattern but can occur only once. ā€¢ Characters other than % match literally within a filename cooker: cooker.c cooker.h cooker.o: cooker.c cooker.h cooker <----- cooker.c % : %.c cooker.o <-------- cooker.c %.o : %.c 3-29 Embedded Linux Course
  • 30. Examples CC=gcc CC=gcc all: frammis cooker all: frammis cooker frammis: frammis.c frammis.h frammis: frammis.c frammis.h cooker: cooker.c cooker.h cooker: cooker.c cooker.h clean: clean: rm -rf frammis cooker rm -rf frammis cooker %:%.c %:%.c echo "$< ===>$@ā€œ echo "$< ===>$@ā€œ $(CC) $(CFLAGS) $< ā€“o $@ $(CC) $(CFLAGS) $< ā€“o $@ 3-30 Embedded Linux Course
  • 31. Suffix Rules CC = gcc CFLAGS = -g # define a suffix rule for .c -> .o LD = $(CC) .c.o : LDFLAGS = $(CC) $(CFLAGS) -c $< RM = rm # default target by convention is ``all'' EXE = mainx all : $(EXE) SRCS = main.c sub1.c sub2.c sub3.c OBJS = ${SRCS:.c=.o} $(EXE) : $(OBJS) $(LD) -o $@ $(OBJS) # list only those we use .SUFFIXES: .o .c $(OBJS) : proj.h clean : -$(RM) -f $(EXE) $(OBJS) 3-31 Embedded Linux Course
  • 32. # Make rules # Make rules all: daemon all: daemon .PHONY : :install clean distclean .PHONY install clean distclean .c.o: .c.o: $(CC) $(CFLAGS) $(HEADER_OPS) -c $< $(CC) $(CFLAGS) $(HEADER_OPS) -c $< daemon: ${OBJS} daemon: ${OBJS} $(CC) -o $(EXEC_NAME) ${OBJS} $(LDFLAGS) $(CC) -o $(EXEC_NAME) ${OBJS} $(LDFLAGS) #Copy the executable file into a directory that users typically search for #Copy the executable file into a directory that users typically search for ##commands; commands; install: daemon install: daemon test -d $(INSTALL_DIR) ||||$(INSTALL) -d -m 755 $(INSTALL_DIR) test -d $(INSTALL_DIR) $(INSTALL) -d -m 755 $(INSTALL_DIR) $(INSTALL) -m 755 $(EXEC_NAME) $(INSTALL_DIR) $(INSTALL) -m 755 $(EXEC_NAME) $(INSTALL_DIR) clean: clean: rm -f *.o $(EXEC_NAME) core rm -f *.o $(EXEC_NAME) core ##distclean might be defined to delete more files than `clean' does. distclean might be defined to delete more files than `clean' does. distclean: distclean: rm -f *~ rm -f *~ rm -f *.o $(EXEC_NAME) core rm -f *.o $(EXEC_NAME) core 3-32 Embedded Linux Course
  • 33. Built-in Functions ā€¢ GNU make has a couple dozen built-in functions for working with variables and their contents ā€¢ $(function-name arg1[, argn]) 3-33 Embedded Linux Course
  • 34. $(shell command) ā€¢ The shell function accepts a single argument that is expanded (like all arguments) and passed to a subshell for execution. ā€¢ The standard output of the command is then read and returned as the value of the function. Sequences of newlines in the output are collapsed to a single space. Any trailing newline is deleted. ā€¢ The standard error is not returned, nor is any program exit status 3-34 Embedded Linux Course
  • 35. Example 3-35 Embedded Linux Course
  • 36. $(wildcard pattern . . . ) sources := $(wildcard *.c *.h) ā€¢ The wildcard function accepts a list of patterns and performs expansion on each one. ā€¢ If a pattern does not match any files, the empty string is returned. ā€¢ As with wildcard expansion in targets and prerequisites, the normal shell globbing characters are supported: ~, *, ?, [...], and [^...]. 3-36 Embedded Linux Course
  • 37. ā€¢ Another use of wildcard is to test for the existence of a file in conditionals. ā€¢ When used in conjunction with the if function (described shortly) you often see wildcard function calls whose argument contains no wildcard characters at all. dot-emacs-exists := $(wildcard ~/.emacs) will return the empty string if the user's home directory does not contain a .emacs file 3-37 Embedded Linux Course
  • 38. $(subst search-string,replace-string,text) sources := count_words.c counter.c lexer.c sources := count_words.c counter.c lexer.c objects := $(subst .c,.o,$(sources)) objects := $(subst .c,.o,$(sources)) 3-38 Embedded Linux Course
  • 39. if-condition if-condition text if the condition is true else text if the condition is false endif ā€¢ The if-condition can be one of: ifdef variable-name ifndef variable-name ifeq test ifneq test 3-39 Embedded Linux Course
  • 40. Example 3-40 Embedded Linux Course
  • 41. ifeq (a, a) # These are equal endif ifeq ( ā€œbā€, ā€œbā€ ) # These are not equal - 'b' != 'b ' endif ifeq "a" "a" # These are equal endif ifeq 'b' 'b' # So are these endif 3-41 Embedded Linux Course
  • 42. ifeq (.config,$(wildcard .config)) ifeq (.config,$(wildcard .config)) include .config include .config ifeq (.depend,$(wildcard .depend)) ifeq (.depend,$(wildcard .depend)) include .depend include .depend ifndef CONFIG_UCLINUX ifndef CONFIG_UCLINUX LINUX=vmlinux LINUX=vmlinux else else LINUX=linux LINUX=linux endif endif do-it-all: do-it-all: Version $(LINUX) Version $(LINUX) else else CONFIGURATION = depend CONFIGURATION = depend do-it-all: do-it-all: depend depend endif endif else else CONFIGURATION = config CONFIGURATION = config do-it-all: do-it-all: config config endif endif 3-42 Embedded Linux Course
  • 43. GNU Build System (autotools) 3-43 Embedded Linux Course
  • 44. GNU Build System ā€¢ The GNU build system (aka, autotools ) provides an environment to a computer programmer which allows them to write cross- platform software ā€¢ It also makes the build process easier on the user, allowing the user to usually just run a small set of commands to build the program from its source code and install it. 3-44 Embedded Linux Course
  • 45. GNU Autotools ā€¢ Autotools comprises the GNU utility programs Autoconf, Automake, and Libtool. ā€¢ Other related tools frequently used with the GNU build system are GNUā€™s make, GNU gettext, pkg-config, and the GNU gcc. ā€¢ The utilities used by the GNU build system are only required to be on the developerā€™s workstation 3-45 Embedded Linux Course
  • 46. autoconf and * * * automake * * * a. * means executable b. template file, customarily ending in ".inā€œ, ā€œacā€ 3-46 Embedded Linux Course
  • 47. GNU Autoconf ā€¢ Autoconf is a tool for producing shell scripts that automatically configure software source code packages to adapt to many kinds of UNIX-like systems. ā€¢ Autoconf makes use of GNU m4 to transform a user-written 'configure.ac' file to a portable 'configureā€˜ script. ā€¢ The 'configure' generates customized headers and makefiles derived from pre-written templates. 3-47 Embedded Linux Course
  • 48. GNU Autoconf (cont.) ā€¢ The Autoconf approach to portability is to test whether a particular feature is supported or not ā€¢ it also allows user to have the ā€˜configureā€™ script to customize. 3-48 Embedded Linux Course
  • 49. GNU Automake ā€¢ Automake aims to allow the programmer to write a makefile in a higher-level language, rather than having to write the whole makefile manually ā€¢ Automake helps to create portable Makefile, which are in turn processed with the make utility. ā€¢ Must be used with GNU autoconf 3-49 Embedded Linux Course
  • 50. GNU Automake (cont.) ā€¢ Automake contains two commands: ā€“ aclocal : a program for autoconf users ā€“ Automake ā€¢ In simple cases, it suffices to give: ā€“ a line that declares the name of the program to build ā€“ a list of source files ā€“ a list of command-line options to be passed to the gcc (namely, in which directories header files will be found) ā€“ a list of command-line options to be passed to the ld (which libraries the program needs and in what directories they are to be found). 3-50 Embedded Linux Course
  • 51. GNU Libtool ā€¢ Libtool helps manage the creation of static and dynamic libraries on various Unix-like operating systems. ā€¢ Libtool accomplishes this by abstracting the library creation process, hiding differences between various systems 3-51 Embedded Linux Course
  • 52. ScreenShot for CodeBlocks Free IDE ,e.g., ā€¢ Eclipse ā€¢ Anjuta ā€¢ CodeBlocks 3-52 Embedded Linux Course
  • 53. Configure Script ā€¢ ā€˜configureā€™ attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. ā€¢ It may also create one or more `.h' files containing system-dependent definitions. In new development, library dependency checking has been done in great part using pkg-config pkg-config is a helper tool used when compiling applications and libraries. It helps you insert the correct compiler options on the command line. 3-53 Embedded Linux Course
  • 54. Screenshot for ā€˜./configureā€™ 3-54 Embedded Linux Course
  • 55. The Output from ā€˜configureā€™ ā€¢ A script config.status that you can run in the future to recreate the current configuration ā€¢ A file config.cache that saves the results of its tests to speed up reconfiguring, and ā€¢ A file config.log containing compiler output, useful for debugging `configureā€˜ make distclean make realclean remove the files that `configure' created (so you can compile the package for a different kind of computer), 3-55 Embedded Linux Course
  • 56. ā€¢ If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them ā€¢ If at some point config.cache contains results you don't want to keep, you may remove or edit it. ā€¢ You only need configure.ac if you want to change it or regenerate `configure' using a newer version of autoconf. 3-56 Embedded Linux Course
  • 57. Compilers and Options ā€¢ Some systems require unusual options for compilation or linking that the `configure' script does not know about CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure ā€¢ The 'configure' script can be given a number of options to enable and disable various features. For a complete list, type: ./configure --help 3-57 Embedded Linux Course
  • 58. Specifying the System Type ā€¢ There may be some features `configure' can not figure out automatically, but needs to determine by the type of host the package will run on System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] ā€“ type format: CPU-OS ā€“ See the file `config.sub' for the possible values of each field . ā€¢ If you are building compiler tools for cross-compiling, you can will need ā€“host=CPU-OS 3-58 Embedded Linux Course
  • 59. Screenshot 3-59 Embedded Linux Course
  • 60. Examples for configure Step1 : Export your toolchain path firstly ā€“ export PATH=/usr/local/arm/3.4.1/bin:$PATH Step 2 : Execute configure script, ā€“ CC=arm-linux-gcc ./configure --host=arm-linux ā€“ CC=mips-uclibc-gcc ./configure --host=mips-linux ā€“ CC=arm-elf-gcc ./configure --target=arm-linux --endian-mode=littile Normally, you will need to execute ā€œ./configure - - helpā€ to enable or disable some features supported by this software package 3-60 Embedded Linux Course
  • 61. Cross-compiling Applications ā€œCC=arm-linux-gcc ./configure ā€“host=arm-linux ā€ Unluckily enough, you need to go through the following.. Step 1: ā€œ./configureā€ this will create a Makefile for your x86 linux. Step 2: include <SDK>/filesystem/make.def Include make.def at the top of your Makefile Step 3: Edit Makefile appropriately For example, # CC=gcc # AR=ar -I<the_path_to_your_toolchain_include_path> -L<the_path_to_your_toolchain_library_path> 3-61 Embedded Linux Course
  • 62. Test Your Program Download your code to board for testing ā€¢ Ifconfig eth0 192.168.2.x ā€¢ cd /var; ā€¢ tftp ā€“g ā€“r <executable> <tftp_server> ā€¢ chmod +x <executable> ā€¢ ./ <executable> 3-62 Embedded Linux Course
  • 63. Faild to configure 3-63 Embedded Linux Course
  • 64. Cross-compiling Kernel modules ā€¢ Building the kernel module will need the properly configured kernel sources ā€¢ During the build process of this package the kernel Makefile and the current kernel configuration will be used ā€¢ The modules should be compiled with the same compiler version. Some kernel modules are only supported with recent kernel versions. That means that compilation of these drivers might fail with older kernel versions. 3-64 Embedded Linux Course
  • 65. Kernel Source Layout 3-65 Embedded Linux Course
  • 67. Test Your Module Download led.ko and test program to your board # čح定ęæ子 IP # č¼‰å…„ Module Ifconfig eth0 192.168.2.x insmod led.ko cd /var; # ęŸ„č©¢ Module # 取得 led.ko lsmod tftp ā€“g ā€“r led.ko <tftp_server> # ē”¢ē”Ÿ device node # 取得ęø¬č©¦ē؋式 mknod /dev/led c 230 0 tftp ā€“g ā€“r led_test <tftp_server> # åŸ·č”Œęø¬č©¦ē؋式 # ęø¬č©¦ē؋式加äøŠåŸ·č”Œę¬Šé™ ./led_test chmod +x led_test # ē§»é™¤ Module rmmod led 3-67 Embedded Linux Course
  • 68. References ā€¢ GNU Manuals Online ā€“ http://www.gnu.org/software/make/manual/ ā€“ Managing Projects with GNU Makeā€ by Robert Mecklenburg ā€“ O'Reilly, Nov 19, 2004 3-68 Embedded Linux Course