использование autoconf для создания сценариев сборки для программ на языке ассемблера - PullRequest
0 голосов
/ 07 июня 2018

Я пытаюсь изучить autoconf и пытаюсь использовать его для создания сценариев сборки для компиляции программ на языке ассемблера, написанных на Gnu Assember (GAS).

Ниже мой файл configure.ac

   AC_INIT([hello], [0.01]])
   AC_CONFIG_SRCDIR([hello.s])
   AC_CONFIG_HEADERS([config.h])
   AC_CONFIG_AUX_DIR([build-aux])

   AM_INIT_AUTOMAKE([-Wall -Werror])
   AC_CONFIG_FILES([Makefile])
   AM_PROG_AS
   AC_OUTPUT

И ниже файл Makefile.am

  bin_PROGRAMS = hello
  hello_SOURCES = hello.s

  .hello.o:
          as -gstabs+  $< -o $@

Ниже приведена программа hello.s

    .section .text
    .globl _start
    _start:
          pushl $3
          pushl $2
          call foo
          movl $1, %eax
          int $0x80

    .type foo, @function
    foo:
         movl 4(%esp), %eax
         movl 8(%esp), %ebx
         addl %eax, %ebx
         ret

когда я запускаю autoreconf -ii, посмотрите это:

  configure.ac:6: installing `build-aux/install-sh'
  configure.ac:6: installing `build-aux/missing'

Запуск ./configure script

   checking for a BSD-compatible install... /usr/bin/install -c
   checking whether build environment is sane... yes
   checking for a thread-safe mkdir -p... /bin/mkdir -p
   checking for gawk... gawk
   checking whether make sets $(MAKE)... yes
   checking for style of include used by make... GNU
   checking for gcc... gcc
   checking for C compiler default output file name... a.out
   checking whether the C compiler works... yes
   checking whether we are cross compiling... no
   checking for suffix of executables... 
   checking for suffix of object files... o
   checking whether we are using the GNU C compiler... yes
   checking whether gcc accepts -g... yes
   checking for gcc option to accept ISO C89... none needed
   checking dependency style of gcc... none
   checking dependency style of gcc... none
   configure: creating ./config.status
   config.status: creating Makefile
   config.status: creating config.h
   config.status: executing depfiles commands

, когда я запускаю make install, происходит сбой с ошибками, приведенными ниже:, я хочу использовать"as" вместо gcc для сборки языка ассемблера.

   [foobar]$ make install
   gcc  -g -O2 -c -o hello.o hello.s
   gcc  -g -O2   -o hello hello.o  
   hello.o: In function `_start':
   /home/ashok/practice/ia32/myasm/autotools/foobar/hello.s:4: multiple    definition of `_start'
  /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../crt1.o:(.text+0x0): first defined here
 /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../crt1.o: In function `_start':
 (.text+0x18): undefined reference to `main'
  collect2: ld returned 1 exit status
  make: *** [hello] Error 1

Я хочу, чтобы autoconf использовал "as" ассемблер GNU вместо gcc для компиляции программы сборки.Как переопределить, чтобы не использовать GCC.

1 Ответ

0 голосов
/ 07 июня 2018

Мне удалось восстановить это, используя сам gcc для компиляции и компоновки проходной программы сборки pert target LDFLAGS в Makefile.am

 bin_PROGRAMS = hello
 hello_SOURCES = hello.s
 hello_LDFLAGS=-nostdlib -lgcc -Wl,-e_start

файл configure.ac остается в основном таким же.

    AC_INIT([hello], [0.01])
    AC_CONFIG_SRCDIR([hello.s])
    AC_CONFIG_HEADERS([config.h])
    AC_CONFIG_AUX_DIR([build-aux])
    AM_INIT_AUTOMAKE([-Wall -Werror])
    AC_CONFIG_FILES([Makefile])
    AM_PROG_AS
    AC_OUTPUT

Запустить autoreconf -i

  $ autoreconf -i
  configure.ac:5: installing `build-aux/install-sh'
  configure.ac:5: installing `build-aux/missing'

Запустить ./configure

 $ ./configure 
 checking for a BSD-compatible install... /usr/bin/install -c
 checking whether build environment is sane... yes
 checking for a thread-safe mkdir -p... /bin/mkdir -p
 checking for gawk... gawk
 checking whether make sets $(MAKE)... yes
 checking for style of include used by make... GNU
 checking for gcc... gcc
 checking for C compiler default output file name... a.out
 checking whether the C compiler works... yes
 checking whether we are cross compiling... no
 checking for suffix of executables... 
 checking for suffix of object files... o
 checking whether we are using the GNU C compiler... yes
 checking whether gcc accepts -g... yes
 checking for gcc option to accept ISO C89... none needed
 checking dependency style of gcc... none
 checking dependency style of gcc... none
 configure: creating ./config.status
 config.status: creating Makefile
 config.status: creating config.h
 config.status: executing depfiles commands

Запустить Make

$ make
  make  all-am
  make[1]: Entering directory `/home/ashok/practice/ia32/myasm/autotools/foobar'
  gcc  -g -O2 -c -o hello.o hello.s
  gcc  -g -O2 -nostdlib -lgcc -Wl,-e_start  -o hello hello.o  
  make[1]: Leaving directory `/home/ashok/practice/ia32/myasm/autotools/foobar'

Запустить программу приветствия

 $ ./hello 
 $ echo $?
 5
...