일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- debug banner
- AlertDialog
- TCPIP
- flutter button
- c
- Listview filtering
- Server
- debugShowCheckedModeBanner
- ubuntu 19 한글 입력
- peaks
- array
- flutter tcpip server
- Properties.Settings.Default
- flutter tcpip client
- showDialog
- flutter
- ListView.build
- dart:io
- Today
- Total
Louie De Janeiru
Linux에서 Makefile 자동 생성하기 [출처] Linux에서 Makefile 자동 생성하기 (오픈소스 소프트웨어 & 하드웨어: 로봇 기술 공유 카페 (오로카)) |작성자 수야 본문
Linux에서 Makefile 자동 생성하기 [출처] Linux에서 Makefile 자동 생성하기 (오픈소스 소프트웨어 & 하드웨어: 로봇 기술 공유 카페 (오로카)) |작성자 수야
Louiey 2015. 2. 27. 21:36http://cafe.naver.com/openrt/6223
Linux에서 C 혹은 C++을 개발할 때 Makefile을 자동으로 생성하는 방법에 대해 살펴보고 있는 중입니다.
키워드는 autoconf, automake 정도가 되겠네요.
간단하게 따라하면서 Makefile 을 생성하여 Build 까지 하는 과정을 블로그에 정리해보았습니다.
( http://lifeseed.tistory.com/115 )
제가 사용하는 마스보드나 라즈베리파이, 비글보드, 오드로이드 등 리눅스가 탑재된 플랫폼에서 S/W 를 개발할 때도 사용가능할 듯하네요.
Makefile 자동 생성하기
Linux에서 Makefile을 자동 생성하는 방법을 정리한다.
기본 생성 과정은 다음과 같다.
1. autoscan -> configure.scan 생성
2. configure.scan 의 수정 및 확장자 변경 :: configure.ac
3. aclocal :: configure.ac 로 부터 aclocal.m4 생성 (Macro 정의)
4. autoconf :: configure.ac로 부터 configure 실행 script 파일 생성
5. Makefile.am 작성
6. automake :: Makefile.am 로 부터 Makefile.in 생성
7. ./configure :: Makefile 생성
8. make -f Makefile
2 ~ 6 의 과정을 bootstrap 이라는 실행 script로 생성하여 두면 편리하다.
A. 기본 준비 작업
우선 작업 Directory를 생성한다.
작업 directory 구조는 Project Root Path에 Makefile을 생성하고, Source Code 는 src 라는 Directory에 위치한다.
1) $ mkdir -p ~/work/helloworld/src
2) $ cd ~/work/helloworld
3) $ vim ./src/hello.c
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}
B. Makefile.am 생성
autoscan 시 Makefile.am 이 있으며 AC_CONFIG_FILES 가 자동으로 생성된다.
없을 경우 사용자가 editor를 통하여 추가해 주어야 한다.
1) vim ./helloworld/Makefile.am
SUBDIRS = src
2) vim ./helloworld/src/Makefile.am
AM_LDFLAGS =
bin_PROGRAMS = helloworld
helloworld_SOURCES = hello.c
C. configure.ac 생성
현재 작업 위치는 ~/work/helloworld 이다.
$ autoscan 실행
configure.scan 이 만들어 진다.
editor로 파일을 열어서 수정하자.
cf) 붉은색 글씨가 생성된 파일에서 수정한 Text 이다.
파란색 글씨는 Makefile.am 이 있을 경우 생성되는 Text이며 없을 경우 사용자가 추가하면 된다.
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.68])
#AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_INIT([helloworld], [1.0])
AM_INIT_AUTOMAKE([helloworld], [1.0])
AC_CONFIG_SRCDIR([src/hello.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile
src/Makefile])
AC_OUTPUT
configure.scan 을 configure.ac 로 변경하자.
$ mv configure.scan configure.ac
D. aclocal.m4 생성
$ aclocal 실행
aclocal.m4 파일이 생성된다.
E. configure 파일 생성
$ autoconf 실행
실행가능한 configure 파일이 생성된다.
F. config.h.in 파일 생성
$ autoheader 실행
configure.ac 의 AC_CONFIG_HEADERS([config.h]) 구문이 있을 경우 반드시 수행하여 config.h.in 파일을 생성해야 한다.
G. Makefile.in 생성
$ automake --add-missing --copy 실행
이제 ./configure 를 실행하면 Makefile이 생성되고 make 명령을 이용하여 build 를 하면 된다.
D~G 과정을 bootstrap 라는 실행 scrapt로 만들자.
$ vim bootstrap
# Run the autotools bootstrap sequence to create the configure script
# Abort execution on error
# bootstrap the autotools
(
aclocal
autoconf
autoheader
automake --add-missing --copy
)
echo "Bootstrap complete. Quick build instructions:"
echo "./configure ...."
$ chmod +x ./bootstrap
즉 C까지 실행후
$ ./bootstrap
$ ./configure
$ make
를 순서대로 수행하면 src directory에
helloworld 라는 실행파일이 생성된다.
이 후엔 configure.ac / Makefile.am 를 작성하는 법을 알아볼 예정이다.
'Linux' 카테고리의 다른 글
Ubuntu QT install (0) | 2017.01.01 |
---|---|
Ubuntu Eclipse 설치하기 (0) | 2016.12.31 |
Ubuntu JAVA_HOME 설정하기 (0) | 2016.12.31 |
bash shell 설정 (0) | 2015.05.29 |
vi tab config (0) | 2015.05.29 |