制作linux下到安装包,常见的是.gz等这样的压缩包,在制作这样到安装文件到时候,可以从一个简单到例子实现:
--src(目录)
------helloworld.c
------inter.c
--lib(目录)
------maxnum.c
--include(目录)
------helloworld.h
------inter.h
------maxnum.h
一. 进入src目录进行相关配置
(1). helloworld.c
- #include "helloworld.h"
- #include "inter.h"
- #include <stdio.h>
- int main()
- {
- test_print();
- return 0;
- }
- void test_print()
- {
- int num1 = 1;
- int num2 = 2;
- int max_num = max(num1, num2);
- printf("max_num: %d ", max_num);
- print(max_num);
- }
(2). inter.c
- #include "inter.h"
- int print(int num)
- {
- printf("HAHA: num: %d\n", num);
- return 0;
- }
(3) Makefile.am
- AUTOMAKE_OPTIONS=foreign
INCLUDES=-I ../include
bin_PROGRAMS=hello
hello_SOURCES=helloworld.c inter.c
hello_LDADD = ../lib/libmaxnum.la
二。进入lib 目录配置
(1)maxnum.c
- #include "maxnum.h"
- int max(int first, int second)
- {
- return first > second ? first : second;
- }
(2) Makefile.am
- AUTOMAKE_OPTIONS=foreign
INCLUDES = -I ../include
noinst_LTLIBRARIES = libmaxnum.la
libmaxnum_la_SOURCES = maxnum.c
三. 进入include目录配置
(1) helloworld.h
- #ifndef __HELLOWORLD_H__
#define __HELLOWORLD_H__
extern int max(int first, int second);
#endif
(2) inter.h
- #ifndef __INTER_H__
#define __INTER_H__
#include <stdio.h>
void test_print();
#endif
(3) maxnum.h
- #ifndef __MAXNUM_H__
#define __MAXNUM_H__
int max(int first, int second);
#endif
四。返回主目录下,进行相关配置
(1) Makefile.am
- AUTOMAKE_OPTIONS=foreign
SUBDIRS=lib src
五。 运行相关操作
(1) autoscan 生成configure.scan, 将其变成configure.in, 采用到命令: mv configure.scan configure.in, 修改configure.in
- # -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.68])
AC_INIT(hello, 1.1, [liuz@163.com])
AC_CONFIG_SRCDIR([src/helloworld.c])
#AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# FIXME: Replace `main' with a function in `-lcurl':
#AC_CHECK_LIB([curl], [main])
AC_PROG_LIBTOOL
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
#AC_CONFIG_FILES([Makefile
# lib/Makefile
# src/Makefile])
AC_OUTPUT(Makefile
lib/Makefile
src/Makefile)
(2) aclocal 生成相关到文件
(3)libtoolize -f -c 生成和lib库相关信息
(4) autoconf
(5) automake --add-missing
(6) 经过上述步骤后,就可以生成我们需要到安装到文件,即: make dist 则生成我们需要到 hello-1.1.tar.gz 文件
(7) 在第(5)后,可以先安装该文件,
1. ./configure 配置相关环境,生存Makefile文件
2. sudo make 编译makefile
3. sudo make install 则安装我们到文件,此时可以敲入: hello, 则可以显示我们到运行结果
4. sudo make uninstal 则卸载安装文件