Makefile自動生成工具-----autotools的使用(詳細)
相信每個學習Linux的人都知道Makefile,這是一個很有用的東西,但是編寫它是比較複雜,今天介紹一個它的自動生成工具,autotools的使用。很多GNULinux的的軟體都是用它生成Makefile的,包括我們非常熟悉的Linux核心原始碼。
1、準備:需要工具
autoscan
aclocal
autoheader
automake
autoconf
auto make
在終端敲入命令,哪個沒有安裝哪個,一般是第一個autoscan沒有,其它的我用的Ubuntu10.04下全部都有
2、測試程式編寫:建立目錄:mkdir include src
編寫程式:include/str.h
#include <stdio.h>
int str(char *string);
編寫程式:src/str.c
#include "str.h" //print string int str(char *string){ printf("\n----PRINT STRING----\n\"%s\"\n",string); return 0; } //interface of this program int main(int argc , char **argv){ char str_read[1024]; printf("Please INPUT something end by [ENTER]\n"); scanf("%s",str_read); return str(str_read ); }
3、生成configure.ac
configure.ac是automake的輸入檔案,所以必須先生成該檔案。
執行命令:
[[email protected] str]# ls
include src
[[email protected] str]# autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
[[email protected] str]# ls
autoscan.log configure.scan include src
[ [email protected] str]# cp configure.scan configure.ac
修改 configure.ac
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([include/str.h])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT
修改
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
改為:
AC_INIT(str,0.0.1, [[email protected]])
其中:FULL-PACKAGE-NAME 為程式名稱,VERSION為當前版本, BUG-REPORT-ADDRESS為bug彙報地址
然後新增兩句話:
AM_INIT_AUTOMAKE
AC_CONFIG_FILES([Makefile])
結果如下:(兩句話不是在一起的)
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
#AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_INIT(str, 0.0.1, [[email protected]])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([include/str.h])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
4、執行aclocal
[[email protected] str]# aclocal
/usr/share/aclocal/libfame.m4:6: warning: underquoted definition of AM_PATH_LIBFAME
run info '(automake)Extending aclocal'
or see http://sources.redhat.com/automake/automake.html#Extending-aclocal
5、製作Makefile.am
[[email protected] str]# vi Makefile.am
#Makefile.am
bin_PROGRAMS = str
str_SOURCES = include/str.h src/str.c
str_CPPFLAGS = -I include/
automake 這個命令需要用到這個配置檔案。各個選項意思比較直觀,不多說。
6、autoheader
[[email protected] str]# autoheader
7、automake必須檔案:
* install-sh
* missing
* INSTALL
* NEWS
* README
* AUTHORS
* ChangeLog
* COPYING
* depcomp
其中,以下檔案在執行automake -a的時候會自動生成
* install-sh
* missing
* INSTALL
* COPYING
* depcomp
所以,接下來手動生成剩下的檔案
[[email protected] str]# touch NEWS README AUTHORS ChangeLog
8、執行automake -a
[[email protected] str]# automake -a
configure.ac: installing `./install-sh'
configure.ac: installing `./missing'
Makefile.am: installing `./INSTALL'
Makefile.am: installing `./COPYING'
Makefile.am: installing `./compile'
Makefile.am: installing `./depcomp'
9、autoconf
[[email protected] str]# autoconf
[[email protected] str]# ls
aclocal.m4 autoscan.log config.h.in configure.scan include Makefile.am NEWS
AUTHORS ChangeLog configure COPYING INSTALL Makefile.in README
autom4te.cache compile configure.ac depcomp install-sh missing src
10、執行測試:
執行./configure
[[email protected] str]# ./configure --prefix=/u
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
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 ANSI C... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
執行 make
[[email protected] str]# make
make all-am
make[1]: Entering directory `/data/devel/c/str'
if gcc -DHAVE_CONFIG_H -I. -I. -I. -I include/ -g -O2 -MT str-str.o -MD -MP -MF ".deps/str-str.Tpo" -c -o str-str.o `test -f 'src/str.c' || echo './'`src/str.c; \
then mv -f ".deps/str-str.Tpo" ".deps/str-str.Po"; else rm -f ".deps/str-str.Tpo"; exit 1; fi
gcc -g -O2 -o str str-str.o
make[1]: Leaving directory `/data/devel/c/str'
此時已經生成了 str(可執行檔名字在前面設定Makefile.am的引數時候去頂)這個,可以通過./str直接看到執行結果
[[email protected] str]# ./str
Please INPUT something end by [ENTER]
abcksdhfklsdklfdjlkfd
----PRINT STRING----
"abcksdhfklsdklfdjlkfd"
不過這裡我們都做一步,把它安裝到系統裡面,這樣我們只要在終端輸入str就可以執行程式了。
執行 make install:
[[email protected] str]# make install
make[1]: Entering directory `/data/devel/c/str'
test -z "/u/bin" || mkdir -p -- "/u/bin"
/usr/bin/install -c 'str' '/u/bin/str'
make[1]: Nothing to be done for `install-data-am'.
make[1]: Leaving directory `/data/devel/c/str'
接下來你可以make clean 清除安裝的那些.o 檔案了。
這樣生成了一個自動的Makefile。
相關推薦
Makefile自動生成工具-----autotools的使用(詳細)
相信每個學習Linux的人都知道Makefile,這是一個很有用的東西,但是編寫它是比較複雜,今天介紹一個它的自動生成工具,autotools的使用。很多GNULinux的的軟體都是用它生成Makefile的,包括我們非常熟悉的Linux核心原始碼。 1、準備:
makefile專題:自動生成依賴關係(續)
.PHONY : all clean rebuild MKDIR := mkdir RM := rm -rf CC := gcc DIR_DEPS := deps DIR_EXES := exes
Intellij IDEA中使用MyBatis-generator自動生成MyBatis程式碼(Oracle)
原文地址:http://blog.csdn.net/z69183787/article/details/46560071 Intellij IDEA 14 作為JavaIDE 神器,接觸後發現,非常好用,對它愛不釋手,打算離開eclipse和myeclipse,投入Intell
自動生成日報表(改)
d1.py ______________________________________________ #-*-coding:utf-8-*- import time import datetime filename='record20180911.txt' x1,x
【暴力自動生成排列】(2015)第六屆藍橋杯省賽 C/C++ B組 題解(第三題)
第三題題目三羊獻瑞觀察下面的加法算式: 祥 瑞 生 輝 + 三 羊 獻 瑞------------------- 三 羊 生 瑞 氣(如果有對齊問題,可以參看【圖1.jpg】)其中
springcloud自動生成腳手架搭建(二)
完成之後的前臺頁面展示: 測試地址 :dota2info.cn/index 1.配置pom.xml <dependency> <groupId>org.springframework.b
TypeScript 型別定義檔案(*.d.ts)自動生成工具
在開發ts時,有時會遇到沒有d.ts檔案的庫,同時在老專案遷移到ts專案時也會遇到一些檔案需要自己編寫宣告檔案,但是在需要的宣告檔案比較多的情況,就需要自動生產宣告檔案。用過幾個庫。今天簡單記錄一下。自己怎麼編寫有很多教程和文件,那裡就不介紹了。 1、為整個包新增宣告檔案 使用微軟的dt
TypeScript 類型定義文件(*.d.ts)自動生成工具
使用 tsm 其他 說明 可能 arrow gui iuc 簡單使用 1、為整個包添加聲明文件 使用微軟的dts-gen 簡單使用 npm install -g dts-gen // 先全局安裝dts-gen npm install -g yargs // 然後
MyBatis Generator (自動生成工具) 詳解
MyBatis Generator中文文件地址: 該中文文件由於儘可能和原文內容一致,所以有些地方如果不熟悉,看中文版的文件的也會有一定的障礙,所以本章根據該中文文件以及實際應用,使用通俗的語言來講解詳細的配置。 本文中所有節點的連結都是對
程式碼自動生成工具(一)-Csv讀表程式碼自動生成工具
之前提到了自定義的Csv格式的表格讀取的一個工具類CsvReader 這裡我們實現一個可以對任意符合我們人為規定的格式的Csv檔案,自動生成其對應的讀表程式碼 本工具需要boost庫支援,本人用的是1.55.0 這裡首先定義Csv中支援的幾種列型別:FieldType:
springboot整合mybatis使用自動化生成工具(詳細)
在pom.xml中<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> &
資料庫文件自動生成工具(開放原始碼)
本人寫了一個數據庫文件自動生成工具,可以自動生成資料庫文件。 用java寫了個 客戶端介面: 輸入相關資訊後,可以自動生成資料庫文件: 模板支援自定義,點選“自定義模板?”按鈕,將新增的模板複製到該目錄下即可。
Ibatis程式碼自動生成工具——Abator安裝與應用例項(圖解)
使用也比較簡單,以下做個例項來介紹: 一、環境準備 我的環境:Eclipse SDK Version: 3.5.2 JDK1.6 Oracle9i 二、外掛安裝 1、點選"Help>In
ROS知識(16)----如何編譯時自動鏈接同一個工作空間的其他包的頭文件(包含message,srv,action自動生成的頭文件)
logs package fin 空間 依賴庫 osc div build 知識 catkin_make編譯時,往往需要自動鏈接同一個工作空間的其他包的頭文件。否則會出現類似如下的錯誤: /home/xx/xx_ws/srcA_package/src/db.hpp:13:
自動生成小學生四則運算(C語言)
.html .com 它的 百度 http htm log hub .cn 我寫的這個自動生成小學生四則運算的代碼是根據我在百度上看到的一篇博客改的,地址為http://www.cnblogs.com/ys1101/p/4368103.html。它的功能不夠完整,只有整數的
【DataProcessor】簡易的通用多程序資料生成工具類(Advanced for HVD)
0x00 前言 基於先前實現的Python多程序共享記憶體佇列實現的SMQueue(原文地址), 認真思考了一下,雖說prototype類的東西寫起來很酷,但無法產生太大的使用價值, 為了方便呼叫和擴充套件性,還是需要一個工具類來封裝一下的, 讓其得以輕鬆運用在
Spring Boot 整合Mybatis 之 Mapper外掛(自動生成XML及Mapper程式碼)
pom檔案 主要程式碼 <dependencies> <dependency> <groupId>mysql</groupId> <artifactI
自動生成材質Material(Unity3D開發之十九)
專案中,有時候匯入一些資源時候,需要對應建立材質球,如果每次自己動手建立,還是挺麻煩的,下面是如何匯入資源時候自動建立材質球。 using UnityEngine; using System.Co
SecretKeyCreateUtil工具類,採用安全的生成隨機數方法(SecureRandom),此處為10位
public class SecretKeyCreateUtil {/** * 產生金鑰資訊 * 採用安全的生成隨機數方法(SecureRandom) * @throws IOException * @throws NoSuchAlgorithmException */pu
JAVA工具類(10)--- 隨機生成字串工具類randomUtil
package com.gcloud.common; import java.util.Random; /** * 隨機數、隨即字串工具 * Created by charlin on 2017/9/9. */ public class RandomU