2024-09-15 01:54信息 • 发布者: ElfBoard

研发过来一个需求,需要搭建一套etcd,作为注册中心,那么问题来了,如何快速的搭建一个etcd集群呢,又要整证书,又要整很多参数,网上说的都不明不白的哦,怎么办呢,这个时候需要一个神奇的网站来解决这个问题

那就是:etcd Labs ,可以直接搜索引擎搜索关键字看到

首先打开这个网站,看到上面有几个按钮,默认情况下是跳转到Install这个页面的,如果没有跳转需要点击一下哦,如图所示:


etcd labs

#include <stdio.h>
#include <string.h>
#include <hello.h>
int main(void)
{
print();
return 0;
}

好之后保存退出。

elf@ubuntu:~/work/autotools$ vi hello.c

#include <stdio.h>
#include <string.h>
void print(void)
{
printf("Hello,ElfBoard!n");
}

写好之后保存退出。

elf@ubuntu:~/work/autotools$ vi hello.h

#ifndef __HELLO_H__
#define __HELLO_H__
void print(void);
#endif

写好之后保存退出。

3、使用autoscan工具生成configure.scan 文件

autoscan将生成一个名为configure.scan的文件,其中包含了自动扫描到的可能需要配置的信息。

elf@ubuntu:~/work/autotools$ autoscan
elf@ubuntu:~/work/autotools$ ls
autoscan.log configure.scan hello.c hello.h main.c

4、修改configure.ac文件

将configure.scan文件重命名为configure.ac,然后进一步编辑该文件。开发者通常会添加更多的配置检查和必要的宏定义,以确保生成的configure 脚本能够正确地检测和配置系统环境。

elf@ubuntu:~/work/autotools$ mv configure.scan configure.ac

修改 configure.ac

AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])

修改为

AC_INIT(main,0.0.1, [bug@sounos.org])

其中:

FULL-PACKAGE-NAME为程序名称,

VERSION为当前版本,

BUG-REPORT-ADDRESS为bug汇报地址。


然后添加两句话

AM_INIT_AUTOMAKE
AC_CONFIG_FILES([Makefile])
  • AM_INIT_AUTOMAKE宏用于初始化automake,告诉autotools使用automake工具来管理生成的Makefile。
  • AC_CONFIG_FILES宏告诉autotools生成哪些文件。在这种情况下,它指定生成一个名为Makefile 的文件。


修改完成的configure.ac如下:

# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
#AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_INIT(main,0.0.1, [bug@sounos.org])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([hello.h])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([string.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

5、执行aclocal

执行aclocal命令会生成aclocal.m4文件,这个文件包含了用于自动配置和构建软件的宏定义和规则。

elf@ubuntu:~/work/autotools$ aclocal
elf@ubuntu:~/work/autotools$ ls
aclocal.m4 autom4te.cache autoscan.log configure.ac hello.c hello.h main.c

6、autoconf

autoconf命令根据configure.ac文件生成configure脚本。

elf@ubuntu:~/work/autotools$ autoconf
elf@ubuntu:~/work/autotools$ ls
aclocal.m4 autom4te.cache autoscan.log configure configure.ac hello.c hello.h main.c

7、autoheader

autoheader命令用于生成config.h.in文件。这个文件是由configure.ac中的一些宏命令生成的模板文件,它包含了预处理器定义和配置选项,会在configure脚本执行时生成最终的config.h文件。

elf@ubuntu:~/work/autotools$ autoheader
elf@ubuntu:~/work/autotools$ ls
aclocal.m4 autom4te.cache autoscan.log config.h.in configure configure.ac hello.c 
hello.h main.c

8、制作Makefile.am

Makefile.am是用来描述源代码和生成目标之间依赖关系的Automake规则文件

elf@ubuntu:~/work/autotools$ vi Makefile.am
AUTOMAKE_OPTIONS= foreign
bin_PROGRAMS= main
main_SOURCES= main.c hello.c

9、automake --add-missing

automake --add-missing命令会根据Makefile.am文件生成Makefile.in文件。

elf@ubuntu:~/work/autotools$ automake --add-missing
configure.ac:12: installing './compile'
configure.ac:7: installing './install-sh'
configure.ac:7: installing './missing'
Makefile.am: installing './depcomp'
elf@ubuntu:~/work/autotools$ ls
aclocal.m4 autom4te.cache autoscan.log compile config.h.in configure configure.ac 
depcomp hello.c hello.h install-sh main.c Makefile.am Makefile.in missing

10、./configure --host=arm

./configure --host=arm命令会生成Makefile文件。

elf@ubuntu:~/work/autotools$ . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setupcortexa7hf-neon-poky-linux-gnueabi
elf@ubuntu:~/work/autotools$ ./configure --host=arm

11、make生成可执行文件

elf@ubuntu:~/work/autotools$ make
elf@ubuntu:~/work/autotools$ ls
aclocal.m4 autoscan.log config.h config.log configure depcomp hello.h install-sh 
main.c Makefile Makefile.in stamp-h1
autom4te.cache compile config.h.in config.status configure.ac hello.c hello.o main 
main.o Makefile.am missing

12、将可执行文件拷贝到板子中运行

elf@ubuntu:~/work/autotools$ scp main root@192.168.5.98:/home/root/
root@ELF1:~# ./main 
Hello,ElfBoard!

执行应用终端打印“Hello,ElfBoard”应用可以正常运行,这证明使用autotools工具生成Makefile是没有问题的。

至此,就完成了Makefile自动生成利器—autotools的运用的介绍。衷心期望这些知识能为正在屏幕前阅读的你带来实质性的帮助,激发你在软件工程领域不断探索与创新。