달력

52024  이전 다음

  • 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

cscope

Tool/editor & source viewer 2011. 5. 23. 23:22
cscope - interactively examine a C program

i.e) cscope -R
i.e) cscope -b -q -k -R
i.e) cscope -d

-sdir  Look in dir for additional source files. This option is ignored if source files are given on the command line.

-R     Recurse subdirectories during search for source files.

-b     Build the cross-reference only.

-q     Enable fast symbol lookup via an inverted index. This option causes cscope to  create  2  more  files (default  names  ``cscope.in.out''  and  ``cscope.po.out'')  in addition to the normal database. This allows a faster symbol search algorithm that provides noticeably faster lookup performance for  large projects.

-k     ``Kernel Mode'', turns off the use of the default include dir (usually /usr/include)  when  building the database, since kernel source trees generally do not use it.

-d     Do not update the cross-reference.

<vim plugin>
$ cd ~/.vim/plugin
$ wget http://cscope.sourceforge.net/cscope_maps.vim

    " The following maps all invoke one of the following cscope search types:
"
" 's' symbol: find all references to the token under cursor
" 'g' global: find global definition(s) of the token under cursor
" 'c' calls: find all calls to the function name under cursor
" 't' text: find all instances of the text under cursor
" 'e' egrep: egrep search for the word under cursor
" 'f' file: open the filename under cursor
" 'i' includes: find files that include the filename under cursor
" 'd' called: find functions that function under cursor calls
아래와 같이 Ctrl + \ 에 위 단축 알파벳을 입력하면 된다.
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>

그밖에 Ctrl + space 로 찾은 결과를 새 Window에서 볼 수 있으며,
nmap <C-@>s :scs find s <C-R>=expand("<cword>")<CR><CR>

Ctrl + space + space 로 Vertical Split도 가능하다.
nmap <C-@><C-@>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>
Posted by neodelicious
|

srcexpl.vim

vim_plugin.tgz


편한 IDE가 많겠지만 개인적으로 Linux의 Source를 Windows 에서 Source Insight로 분석하고 편집한다. Linux에서 Eclipse가 좋다고는 하지만 느린 것도 같고 UI가 불편하다.

Linux에서 source를 좀 보려고 vi를 열면서 혹시나 해서 'Linux Source Insight'로 구글에게 물어봤더니 아래 Link를 알려주었다.

http://linux.softpedia.com/get/Text-Editing-Processing/Others/Text-Editor/Vim-Plugins/Source-Explorer-39586.shtml

Source Explorer 라는 Vim plugin 인데, source code에서 함수나 변수에 커서를 가져가면 선언부를 아래에 보여준다.

아래와 같이 Vim 윗 부분에 mProfile 변수에 대해서 아랫부분에 선언부분을 보여준다. 사실 이 plugin은 ctags 의 TAG에 의존하기 때문에 ctags 기능인 ctrl + } 와 ctll + t 입력도 가능하고, ctrl + w, w 를 통해서 아래 preview 부분도 이동해서 scroll 해 볼 수 있다.


이제 위 Source Explorer 를 이용하는 방법을 알아보자.

우선 현재 system에 Vim가 설치되어 있어야 한다. 그런데 기본 Ubuntu의 경우 vim-basic이 아니라 vim-tiny가 설치되어 있다.

vi 는 아래와 같이 /etc/alternatives/vi 로 symbolic link 되어 있는데,

$ ls -l /usr/bin/vi
 /usr/bin/vi -> /etc/alternatives/vi

이를 다시 확인해 보면 아래처럼 vim.tiny 라는 것을 알 수 있다.

$ ls -l /etc/alternatives/vi
 /etc/alternatives/vi -> /usr/bin/vim.tiny

만약 이미 아래와 같이 vim.basic 이라면 상관 없지만,

$ ls -l /etc/alternatives/vi
 /etc/alternatives/vi -> /usr/bin/vim.basic

아니라면 아래처럼 vim 을 설치한다.

$ sudo apt-get install vim

참고적으로 https://lists.ubuntu.com/archives/sounder/2006-September/008662.html 에 아래와 같은 글도 있더라...

AFAIK 'vim-tiny' is a very basic build of 'vim' with most optional
features disabled, so that it is functionally pretty close to the
original 'vi'.
You could say it's "vim de-improved"...  ;-)

이제 Source Explorer 를 설치해야 한다. 직접 Link 에서 받거나 첨부파일에서 srcexpl.vim 을 받아 plugin 에 복사한다. 만약 plugin 디렉토리가 없으면 만들면 된다.

$ cp srcexpl.vim /home/jaeawon/.vim/plugin

그리고 Source Explorer 는 ctags의 TAG가 필요하기 때문에,
ctags 가 없다면 우선 설치하고,

$ sudo apt-get install exuberant-ctags
해당 source path로 이동하여 TAG 정보를 생성한다.
$ ctags -R .

끝으로 source path 안에 source 파일을 열고 :SrcExplToggle 를 입력하면 Source Explorer를 즐길(?) 수 있다.

참고적으로 srcexpl.vim 파일 맨 위에 설명도 있는데, 환경 설정을 일부 할 수 있는데, 나는 아래 것 하나만 .vimrc 에 넣어서 F8로 하도록 했다.

nmap <F8> :SrcExplToggle<CR>

그리고 Link 페이지에 있는 Taglist 와 MiniBufExpl 도 쓸만한 plugin 이다.


'Tool > editor & source viewer' 카테고리의 다른 글

cscope  (0) 2011.05.23
vim 이용하기 (내가 필요한 것만...)  (0) 2011.03.01
vim 이용  (0) 2007.12.31
Posted by neodelicious
|
아래 vim 문서를 보다가 일부 정리함....
http://www.truth.sk/vim/vimbook-OPL.pdf

<line 이동하기>
$ - 현재 line 끝으로 이동
2$ - 1 line 아래 끝으로 이동
3$ - 2 line 아래 끝으로 이동

<search - 1>
f - 현재 line에서 우측 방향으로 처음 알파벳이나 숫자 등의 위치로 이동 (예, fa 는 우측 첫 a 위치)
F - 현재 line에서 좌측 방향으로 처음 처음 알파벳이나 숫자 등의 위치로 이동 (예, Fa 는 좌측 첫 a 위치)

<search - 2>
/ 는 forward search, ? 는 backward search 이다.
n 는 현재 방향으로 반복 search, N 는 방향을 바꿔서 반복 search
'/' 입력하고 PgUp 이나 PgDn 으로 이전에 찾았던 키워드를 이용할 수 있다.

<search - 3>
:set hlsearch    - search 결과를 highlight 하도록 설정한다.
:set nohlsearch - search 결과를 highlight 하지 않도록 설정한다.
:nohlsearch      - 현재 highlight 한 search 결과에 한해서만 highlight 해제한다.

<windows>
split hello.c 으로 hello.c 을 새 window 에서 보여줄 수 있다.
vsplit 으로 vertical 하게 새 window를 보여줄 수도 있다.
split, vsplit은 각각 sp, vs으로 약자로 이용할 수 있다.
ctrl-w,w 로써 두 split window 사이에 커서를 옮겨다닐 수 있다

<programmer - 1>
>> 혹은 << 로 우측 혹은 좌측으로 shift 할 수 있다.
이때 간격 기본은 8이며 이를 :set shiftwidth=4 처럼 변경할 수 있다.

<programmer - 2>
% 는 {} () [] 와 같이 짝이 되는 행을 찾아 준다.
예를 들어 { 가 있는 행에서 % 하면 짝이 되는 } 가 있는 행으로 이동한다.
>% 혹은 >i{ 는 {} 포함 혹은 미포함하여 indentation을 맞추는데 이용한다.

'Tool > editor & source viewer' 카테고리의 다른 글

cscope  (0) 2011.05.23
Source Explorer - Vim 에서 Source Insight 따라잡기  (0) 2011.03.01
vim 이용  (0) 2007.12.31
Posted by neodelicious
|

git commit 복구하기

Tool/git 2010. 12. 8. 01:26
git를 사용하면서 과감히 commit을 삭제할 때가 있는데, 때로는 이걸 복구해야 할 때가 있다.
git reset --hard 혹은 git branch -D 를 실수로 했을 때가 그 대표적 예일 것이다.

결론부터 얘기하면 git reset --hard에 대해서 다음과 같이 복구할 수 있고,
$ git reset --hard HEAD@{1}
git branch -D에 대해서 다음과 같이 복구할 수 있다.
$ git branch <new branch> HEAD@{1}
=> $ git branch mybranch HEAD@{1}

사실상 git branch -D 는 실행 직후 아래와 같은 log를 참고하여
Deleted branch temp (was c64b6d0).
아래와 같이 복구할 수도 있다.
$ git branch <new branch> <commit>
==> $ git branch mybranch c64b6d0

이는 git 내부에 소위 쓰레기통 같은 것이 있어서 사용자가 reference를 삭제하더라도
reflog에서 30일간 reference를 유지하여 git의 garbage collection으로부터 보호하기 때문이다.
reflog는 HEAD의 commit 이동을 기록하며, 아래와 같은 명령으로 이를 확인할 수 있다.
$ git reflog
HEAD@{#}에서 #는 HEAD가 #번 이전에 reference한 commit으로 HEAD@{1}가 직전이기 때문에 위와 같이 복구할 수가 있는 것이다.

위 내용은 아래 참고 문서에서 보고 따라한 것으로
아래 문서에서는 git reset --hard를 하기 전에 git stash를 통해 임시 저장하거나,
cron과 같은 것을 이용해서 자동으로 매일 git stash 하여 저장하는 것을 추천하고 있다.

참고 : Git from the bottom up - Git from the bottom up

'Tool > git' 카테고리의 다른 글

git 알면 편한 기능  (0) 2010.11.13
git reference  (0) 2010.07.05
git staic build  (0) 2010.04.27
git init --bare 이용  (1) 2010.04.23
git init --bare 발단  (0) 2010.04.23
Posted by neodelicious
|

git 알면 편한 기능

Tool/git 2010. 11. 13. 08:29
사내 세미나로 열심히 PPT 만들었는데, 역시 가지고 나올 수 없네요.. ㅎㅎ

git 사용할 때 알면 편한 옵션 몇 개를 소개하고자 합니다.
자세한 것은 git manual이나 기타 자료를 참고하시고요 대충 어떤 용도로 쓰면 좋은지 기능 위주로 설명하고자 합니다.
퍼 가실 때는 작성자 좀 남겨주세요~ ^^; (neodelicious - 김재원)

우선 소스 파일들을 working directory, add를 통한 commit 파일 설정한 것을 index, commit 한 후에 반영된 정보를 local repo로 부르도록 하니, 참고하세요.

1. 취소하기

작업하다보면 수정한 사항에 대해서 취소하고 싶은 경우가 생기는데, 아래 방법이 유용하다.

1.1 git add 를 통해 index 에 반영한 내용 즉, add 취소
git reset 을 통해 index의 내용을 HEAD로 되돌리고, working directory는 그대로 유지한다.
$ git reset
대표적인 사용 예가 잘못 해서 git add -u 로 모든 tracked files를 add 했을 때 특정 파일만 add 취소할 때 좋다.
$ git reset <path>
i.e) $ git reset ./a.txt
다시 얘기하지만 add에 대한 취소는 reset이다. rm 이 아니다. rm을 이용하면 git tracking에서 제외하는 엄청난 결과를 초래할 수 있다.

1.2 git commit 을 통해 local repo 에 반영한 내용 즉, commit 취소
여러 가지 경우가 있을 수 있는데, 우선 수정할 경우을 알아보면 commit --amend가 있다.
직전 commit에 대한 Log를 잘못 작성해서 Log만 수정하거나,
commit 이후에 같은 내용의 변경에 대해서 새 commit을 만들지 않고 직전 commit에 합칠 경우 유용하다.
아래와 같이 git --amend 를 통해 이전 commit과 합칠 수 있다.
$ git commit --amend
$ git commit --amend -C HEAD
그밖에 직전 commit을 취소할 경우 git reset 을 통해 직전 commit을 local repo.에서 삭제할 수 있다.
이때 HEAD가 직전 commit을 가리키므로 HEAD^로 reset 하면 된다.
$ git reset --hard HEAD^
이때 주의할 것은 --hard 옵션은 working directory 의 내용에서도 직전 commit을 삭제하고, 복구할 수 없다는 것이다.
만약 local repo에서의 commit만 삭제하고 working directory는 유지하고자 한다면,
--hard 대신 --soft 혹은 --mixed 를 사용해야 한다.
--soft와 --mixed의 차이는 index에도 삭제 여부이며, --soft는 index에 유지한다.

2. 이전 상태로 복구(roll back)하기

여러 commit을 하다보면 이전 commit 상태로 돌아가고 싶은 때가 있다.
이런 개념을 소위 check out 이라고 하는데, 이전 commit 에 대해서 check out 하면 그때 상태로 working directory가 복구된다.
git를 이용할 때는 복구하고자 하는 상태 이후에 변경한 사항을 유지할 것인가에 따라  checkout  혹은 reset 를 잘 사용해야 한다.

2.1 변경 사항을 유지할 경우 checkout을 이용한다.
git checkout 에 특정 commit을 주어 해당 commit으로 working direcotory를 변경할 수 있다.
$ git checkout <commit>
단, 이때는 임시 branch 상태이므로 잠시 이용할 사항이 아니라 이 상태에서 추가적으로 commit을 하려면
임시 branch가 아니라 새 branch를 생성해야 한다.
$ git checkout -b <new branch name>
애초에 checkout 이후에 commit 할 생각이면 특정 commit 에서 새 branch를 만드는 것이 좋다.
$ git checkout -b <new branch name> <commit>
위의 경우 복구 후에 다시 변경 사항을 그대로 유지한 branch로 checkout 할 수 있다.

2.2 변경 사항을 유지 하지 않을 경우 reset 한다.
git reset 에는 --soft, --hard, --mixed 등 옵션이 많은데, working directory까지 해당 commit으로 복구하려면,
--hard를 사용하면 되는데 해당 commit 이후의 commit은 복구할 수 없으니 주의해야 한다.
$ git reset --hard <commit>

2.3 특정 파일만 이전 상태로 변경할 경우에도 checkout 을 한다.
git checkout 에 file을 명시하지 않고 commit을 주면 전체 commit을 반영하지만, file까지 추가하면 해당 file만 반영한다.
이때는 임시 branch를 만들지 않고 해당 file만 변경하며 필요시 git commit 하면 된다.
$ git checkout <commit> <file>

3. rebase 이용하기
rebase을 이용하면 기존 commit 에 대해서 합치고, 나누고, 순서를 바꾸는 등의 다양한 기능을 할 수 있다.
거시적으로 다른 branch와의 rebase와 현재 branch에 대한 rebase로 구분할 수 있다.

3.1 다른 branch에 대한 rebase
만약 기존의 branch에서 분리하여 새 branch에서 작업하고 있었는데,
기존 branch의 추가 commit을 새 branch에 반영하고 싶다면 merge 혹은 rebase를 해야 한다.
최종 결과의 working directory를 보면 차이가 없을 수도 있지만,
gitk 와 같은 GUI로 보면 merge 와 rebase의 차이를 확연히 볼 수 있는데,
rebase는 우선적으로 기존 branch의 commit을 모두 적용한 이후에 새 branch의 commit을 적용하는 차이가 있다.
물론 rebase도 변경 사항에 따라 merge error가 발생할 수 있다.
$ git rebase <other branch>

3.2 현재 branch에 대한 rebase
현재 branch에서의 commit 에 대해서 합치고, 나누고, 순서를 바꿀 수 있다.
이때는 -i, interactive 옵션이 필요하며, 아래와 같이 변경할 범위를 지정한 후에 변경할 수 있다.
$ git rebase -i <commit>
i.e) git rebase -i HEAD~5
위 명령을 입력하면 commit 목록이 보이며,
위에서부터 commit 을 다시 적용하게 되는데 이 순서를 변경할 수 있고,
필요에 따라 edit, reword, fixup, squash 등으로 합치거나 log를 변경할 수 있다.

'Tool > git' 카테고리의 다른 글

git commit 복구하기  (3) 2010.12.08
git reference  (0) 2010.07.05
git staic build  (0) 2010.04.27
git init --bare 이용  (1) 2010.04.23
git init --bare 발단  (0) 2010.04.23
Posted by neodelicious
|

git reference

Tool/git 2010. 7. 5. 20:54
git user manual
http://www.kernel.org/pub/software/scm/git/docs/user-manual.html

git user manual 한글 번역본
http://namhyung.springnote.com/pages/3132772

git diagram 비롯한 사용법
http://osteele.com/archives/2008/05/my-git-workflow

git tutorial 1&2
http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html
http://www.kernel.org/pub/software/scm/git/docs/gittutorial-2.html

'Tool > git' 카테고리의 다른 글

git commit 복구하기  (3) 2010.12.08
git 알면 편한 기능  (0) 2010.11.13
git staic build  (0) 2010.04.27
git init --bare 이용  (1) 2010.04.23
git init --bare 발단  (0) 2010.04.23
Posted by neodelicious
|

CMake 를 써 보자

Tool/build 2010. 5. 8. 07:13

Autotools보다 cMake가 얼마나 좋을까?
CMake는 Linux 외에 다른 OS에서도 범용적으로 build 환경을 제공한다는 점에서 분명히 장점이 있을 것 같다.

그런데 아직 CMake를 많이 안 써봐서 모르겠지만,
Autotools 에서는 기본값으로 되어 있는 'build command 보이기' 나 '-g 옵션을 추가' 등이
CMake에는 기본값으로 되어 있지 않은 등 분명 사용함에 있어서 차이가 있어 보인다.

KDE의 CMake 선정을 비롯한 사례로 볼 때 아마도 아직 내가 모를 뿐,
CMake에서도 Autotools의 기능을 대부분 지원하지 않을까 싶다.

아무튼 개인적으로 CMake의 소위 build template을 만들면서 공부한 것을 정리해서 올린다.

아래 링크에서 source code를 download 할 수 있으며, 이하 글은 이 source code를 설명한다.

http://www.neodelicious.com/repos/cmake_example.tar.bz2


Assumption
1. Linux 환경을 기준으로 설명하며, '$'는 Linux Shell Prompt 를 의미함
2. 각 module 별로 CMakeLists.txt 파일을 생성하지 않고, (top directory)/CMakeLists.txt 에 모두 기술함을 기본으로 함
  2.1 원하면 (top directory)/CMakeLists.txt 파일에서 하위 directory 별로 CMakeLists.txt 파일로 분리하고 상위 directory의 CMakeLists.txt 에서 add_subdirectory 명령어를 통해 재귀적으로 호출할 수 있음
3. Top directory가 아닌 build directory에 build metadata를 생성하는 것을 기본(희망)으로 함
  3.1 Top directory에서 'cmake .'를 실행하면 top directory에 build metadata를 생성함

Reference
1. http://www.cmake.org/cmake/help/documentation.html
  1.1 http://www.cmake.org/cmake/help/cmake_tutorial.html
  1.2 http://www.cmake.org/cmake/help/cmake-2-8-docs.html


Note

1. 한 번 cmake build 하면 CMakeCache.txt 파일에 cmake build 결과의 설정값이 저장되는데, 이를 삭제하지 않고 CMakeLists.txt 파일을 수정하고 cmake build 하면 반영되지 않으니 주의해야 함


Preparation

1. $ tar xvjf cmake_example.tar.bz2
2. $ cd make_example


Build

1. Method 0 - CMakeLists.txt의 default 옵션으로 cmake build 하고, make 까지 진행하는 shell script를 이용 할 때
  1.1 $ ./start_build.sh
2. Method 1 - CMakeLists.txt의 default 옵션으로 cmake build르 직접 할 때
  2.1 $ mkdir build ; cd build
  2.2 $ cmake ..
  2.3 $ make
3. Method 2 - interactive 방식(wizard mode)으로 CMakeLists.txt의 옵션을 변경하여 make build 할 때
  3.1 $ mkdir build ; cd build
  3.2 $ cmake -i ..
  3.3 make
4. Method 3 - Curses Interface 로 CMakeLists.txt의 옵션을 변경하여 cmake build 할 때
  4.1 $ mkdir build ; cd build
  4.2 $ ccmake ..
  4.3 $ make


Run

1. build directory에 실행파일 example과 shared library인 libshow.so 파일이 있음
2. build directory에서 아래를 실행함
  2.1 $ ./example


CMakeLists.txt 파일 설명

# project
1. cmake_minimum_required (VERSION 2.6)
  1.1 cmake의 최소 버전을 명시함, 없으면 경고 메시지가 출력됨
2. project (cmake_example)
  2.1 새 project의 이름을 명시함
# user selectable variables
1. option (ENABLE_SHARED "Select OFF to build libararies as static" ON)
   option (DEBUG "Select ON to define DEBUG" ON)
   option (DEBUG2 "Select ON to define DEBUG2" ON)
  1.1 사용자가 선택할 수 있는 옵션에 대해서 이름, 설명, 기본값 순으로 설정함
2. message ("ENABLE_SHARED - ${ENABLE_SHARED}")
   message ("DEBUG - ${DEBUG}")
   message ("DEBUG2 - ${DEBUG2}")
  2.1 사용자 편의를 위한 화면 출력용으로 사용자가 선택한 값을 화면에 출력함
# dependency check
1. include (FindPkgConfig)
2. pkg_check_modules (pkgs x11>= 1.2.2 xrender)
  2.1 pkg-config tool을 이용해서 system의 library 정보를 확인할 수 있음
  2.2 아래와 같이 REQUIRED 옵션을 추가하여 조건에 부합하지 않으면 cmake build를 중단할 수 있음
    2.2.1 pkg_check_module (pkgs REQUIRED x11>=1.2.2 xrender)
3. foreach (flag ${pkg_CFLAGS})
     set (EXTRA_LIBS ${EXTRA_LIBS} ${flag})
   endforeach (flag)
   foreach (flag ${pkg_LDFLAGS})
     set (EXTRA_LIBS ${EXTRA_LIBS} ${flag})
   endforeach (flag)
 3.1 위의 pkg-config를 통해 얻은 CFLAGS, LDFLAGS 정보를 cmake 변수에 저장함
#global CMake variables
1. if (ENABLE_SHARED)
     set (BUILD_SHARED_LIBS true)
   endif (ENABLE_SHARED)
  1.1 명시적으로 static 혹은 shared 등을 명시하지 않은 add_library 명령에 대해서 기본 값인 static이 아닌 shared로 library를 build 하도록 설정함
  1.2. 이때 if 를 통해 위의 option에서 설정항 사용자의 선택에 따라 static일 경우 적용하지 않도록 함
2. set (CMAKE_VERBOSE_MAKEFILE ture)
  2.1 make build 할 때 build command를 화면에 출력하도록 함
3. set (CMAKE_BUILDTYPE debug)
  3.1 build 옵션에 -g를 포함하도록 함
4. set (CMAKE_INSTALL_PREFIX /usr)
  4.1 make install 을 통해 설치할 directory의 기준 path를 기본값이 아닌 /usr로 설정함
# global build variables
1. include_directories ("${PROJECT_SOURCE_DIR}/include")
  1.1 make build -I 로 설정하여 header file 을 찾을 path를 추가함
  1.2 PROJECT 는 최근 project 명을 대신하며, PROJECT_SOURCE_DIR 대신 여기서는 cmake_example_SOURCE_DIR 을 사용해도 됨
  1.3 PROJECT_BINARY_DIR 변수도 있는데, 이는 cmake를 실행한 path로서 여기에서는 build directory path임
# variables to the configuration file
1. configure_file ("${PROJECT_SOURCE_DIR}/include/config.h.in" "${PROJECT_SOURCE_DIR}/include/config.h")
  1.1 Source code에서 참조할 값을 반영한 config.h 파일을 config.h.in 파일을 수정해서 생성함
# build library
1. add_library (show lib/show.c)
  1.1 libshow.so 파일을 build 함
# build source
1. add_executable (example src/main.c)
  1.1 실행 파일 example 파일을 build 함
2. target_link_libraries (example show ${EXTRA_LIBS})
  2.1 실행 파일에 link할 library를 명시함
  2.2 이때 위에서 pkg-config를 통해 찾은 system 상의 library 정보를 추가함
# install
1. install (TARGETS show DESTINATION lib)
   install (TARGETS example DESTINATION bin)
   install (FILES ${PROJECT_SOURCE_DIR}/include/show.h DESTINATION include)
  1.1 기본적으로 make install을 위한 install target이 Makefile에 기술되지 않음
  1.2 위의 CMAKE_INSTALL_PREFIX 변수를 기준으로 make install에서 복사할 실행 파일, library 파일, header 파일을 명시함

include/config.h.in 파일 설명
1. #define ENABLE_SHARED "@ENABLE_SHARED@"
  1.1 cmake 내 EANBLE_SHARED 변수를 설정하면 @ENABLE_SHARED@ 값을 ON으로 변경하고, 비설정시 OFF로 설정함
2. #cmakedefine DEBUG
  2.1 cmake 내 DEBUG 변수를 설정하면 #define DEBUG를 설정하고, 비설정시 #undef DEBUG를 설정함
3. #cmakedefine01 DEBUG2
  3.1 cmake 내 DEBUG2 변수를 설정하면 #define DEBUG2 1를 설정하고, 비설정싱 #define DEBUG2 0를 설정함

'Tool > build' 카테고리의 다른 글

Make 이용법 (함수 및 특수 타겟)  (0) 2007.12.31
Make 이용법 (재귀적 사용)  (0) 2007.12.29
Posted by neodelicious
|

git staic build

Tool/git 2010. 4. 27. 00:25
웹 호스팅 서비스를 통해서 개인 블로그를 사용하고 있는데,
여기에 개인용 git repository 를 두고 싶어졌다.

그런데 ssh로 접속해서 확인하니 git binary가 설치되어 있지 않았다.
그래서 아래와 같이 git binary를 직접 build 해서 이용하게 되었다.
이때 git binary에서 zlib과 pthread를 shared library로 이용하고 있어서,
관련 static library가 system에 설치되어 있어야 한다.

git binary를 위해 아래와 같이 소스를 다운로드 했다.
$ apt-get source git-core

그리고 Makefile을 열어 아래와 같이 ALL_LDFLAGS에 -static 옵션을 추가했다.
ALL_LDFLAGS = $(LDFLAGS) -static

다음과 같이 build 하고 build 디렉토리에 설치했다.
$ mkdir build
$ ./configure --prefix=/usr
$ make
$ make install DESTDIR=`pwd`/build

제대로 -static 하게 build 되었는지는 ldd git 와 같이 해서 확인할 수 있었다.
그리고 build/usr/bin 안의 git binary 들을 웹 호스팅 서버에 업로드하였다.

'Tool > git' 카테고리의 다른 글

git 알면 편한 기능  (0) 2010.11.13
git reference  (0) 2010.07.05
git init --bare 이용  (1) 2010.04.23
git init --bare 발단  (0) 2010.04.23
qgit  (0) 2010.04.20
Posted by neodelicious
|

git init --bare 이용

Tool/git 2010. 4. 23. 03:06
git repository에 소스가 있는데 이를 clone 해서 변경하고 push 하면 문제가 있다는 것을
이전 글에서 확인했다. (이전 글 --> http://www.neodelicious.com/entry/git-init-bare-1)

이번에는 --bare 옵션을 통해 위의 문제를 해결하는 방법을 설명하고자 한다.

글을 쓰기에 앞서 이전 글에서도 밝혔지만, 아래 웹 페이즈에서 많은 정보를 얻었음을 밝힌다.
http://stackoverflow.com/questions/738154/what-does-git-updating-currently-checked-out-branch-warning-mean

위 링크의 글 상단에 또 다른 링크 How to publish a Git repository를 출처로 bare repository 를 설명하고 있다.

이 bare repository 및 관련 내용을 간단히 번역하면,
우선 bare repository 는 git dababase 만 있고 소스 파일(working copy of code) 없는 것을 의미한다.
만약 bare repository가 아닌 소스 파일이 있는 git repository(non-bare repo)에 git push 하게 되면
HEAD가 git index, 소스 사이에  sync 문제가 발생하므로
(이게 이전 글 http://www.neodelicious.com/entry/git-init-bare-1 에서 확인한 사항이다.)
항상 bare repository에 git push 해야 한다.

그럼 위에서 권고한대로 우선 아무 것도 없는 디렉토리에서 git init --bare로 초기화해보자.
/.git 아래에 숨겨졌던 git database 파일들이 현재 디렉토리에 보이는 것을 확인했다.

jaewon@jaewon-laptop:~/work/study/tool/git$ mkdir remote_bare
jaewon@jaewon-laptop:~/work/study/tool/git$ cd remote_bare/
jaewon@jaewon-laptop:~/work/study/tool/git/remote_bare$ git init --bare
Initialized empty Git repository in /home/jaewon/work/study/tool/git/remote_bare/
jaewon@jaewon-laptop:~/work/study/tool/git/remote_bare$ ls
branches  config  description  HEAD  hooks  info  objects  refs

그 다음에 위의 bare repository를 git clone 하고 새 파일을 생성 및 수정하고 local에 git commit 했다.

jaewon@jaewon-laptop:~/work/study/tool/git/remote_bare$ cd ..
jaewon@jaewon-laptop:~/work/study/tool/git$ git clone ./remote_bare/ ./local
Initialized empty Git repository in /home/jaewon/work/study/tool/git/local/.git/
warning: You appear to have cloned an empty repository.
jaewon@jaewon-laptop:~/work/study/tool/git$ cd local/
jaewon@jaewon-laptop:~/work/study/tool/git/local$ echo "initial" > ./1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/local$ git add 1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/local$ git commit -a -m '1st'
[master (root-commit) 6833fa2] 1st
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 1.txt

그 다음에 bare repository에 git push를 하기 위해 git push 했는데,
다음과 같이 push의 기본 설정이 안 되어 있다고 해서 오류가 발생했다.

jaewon@jaewon-laptop:~/work/study/tool/git/local$ git push
warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated.  This may
warning: not necessarily be what you want to happen.
warning:
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning:   'nothing'  : Do not push anything
warning:   'matching' : Push all matching branches (default)
warning:   'tracking' : Push the current branch to whatever it is tracking
warning:   'current'  : Push the current branch
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '/home/jaewon/work/study/tool/git/./remote_bare/'

여러 가지 설정이 있을 수 있겠지만, 나는 일단 tracking 방식을 기본으로 설정하고자
git config push.default tracking 과 같이 입력했다.
그리고 push를 정상적으로 할 수 있었다.

jaewon@jaewon-laptop:~/work/study/tool/git/local$ git config push.default tracking
jaewon@jaewon-laptop:~/work/study/tool/git/local$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 210 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /home/jaewon/work/study/tool/git/./remote_bare/
 * [new branch]      master -> master

참고적으로 소스 파일이 있는 git repository(non-bare repo)에 git push 해서 발생하는 문제는
이후 git 버전에서 금지될 것 이라고 한다.

또한 기존에 소스 파일이 있는 git repository(non-bare repo)을 clone 하려고 할 경우,
git clone --bare 와 같이 --bare 옵션을 주면 새 repo가 bare repo 가 된다.
git clone --bare 를 아래와 같이 확인했다.

jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ cd ..
jaewon@jaewon-laptop:~/work/study/tool/git$ git clone --bare ./remote_src/ ./remote_src_bare
Initialized empty Git repository in /home/jaewon/work/study/tool/git/remote_src_bare/
jaewon@jaewon-laptop:~/work/study/tool/git$ cd remote_src_bare/
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src_bare$ ls
branches  config  description  HEAD  hooks  info  objects  packed-refs  refs
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src_bare$ git log
commit 979521d7978f7a26c989047bae7806466353ad61
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:44:44 2010 +0900
    2nd
commit fc2d23fb93c972c3f48a75f9bf7be7de6a5d5ea3
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:42:48 2010 +0900
    initial

그런데 non-bare repo 에 push 하더라도 non-bare repo 의 code를 그대로 이용하지 않고
clone 한 후 pull 로 이용하면 문제가 없었다.
그래도 새로 만들 때는 bare 로 하는 게 좋겠다.

그밖에 Using Git to manage a web siteHow to publish a Git repository
hooks/post-receive 파일을 이용해서 git push 되면 자동으로 git checkout -f 되도록 하던데,
자세한 사항은 이해를 못 해서 지금은 넘어가기로 한다.


'Tool > git' 카테고리의 다른 글

git 알면 편한 기능  (0) 2010.11.13
git reference  (0) 2010.07.05
git staic build  (0) 2010.04.27
git init --bare 발단  (0) 2010.04.23
qgit  (0) 2010.04.20
Posted by neodelicious
|

git init --bare 발단

Tool/git 2010. 4. 23. 01:37
git init --bare를 사용하게 된 배경을 설명하고 하며,
우선 간단하게 아래와 같이 문제 상황을 재현했다.

참고적으로 아래 웹 페이지에서 많은 정보를 얻었다.
http://stackoverflow.com/questions/738154/what-does-git-updating-currently-checked-out-branch-warning-mean


먼저 아래와 같이 1.txt 파일 하나가 들어 있는 디렉토리 remote_src 를 git server 로 초기화했다.

jaewon@jaewon-laptop:~/work/study/tool/git$ mkdir remote_src ; cd remote_src
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ git init
Initialized empty Git repository in /home/jaewon/work/study/tool/git/remote_src/.git/
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ touch 1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ git add 1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ git commit -a -m 'initial'
[master (root-commit) fc2d23f] initial
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 1.txt


그리고 다음과 같이 디렉토리 remote_src 의 git server 를 디렉토리 local_src 로 git clone 한 다음,
1.txt 파일을 수정하고 이를 local 에서 git commit 했다.

jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ git clone . ../local_src ; cd ../local_src
Initialized empty Git repository in /home/jaewon/work/study/tool/git/local_src/.git/
jaewon@jaewon-laptop:~/work/study/tool/git/local_src$ echo "local modification" > ./1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/local_src$ git commit -a -m '2nd'
[master 979521d] 2nd
 1 files changed, 1 insertions(+), 0 deletions(-)

그 다음 디레토리 remote_src 의 git server 로 소스 변경단을 반영하기 위해서 git push 했는데,
다음과 같은 경고 메시지를 확인했다.

jaewon@jaewon-laptop:~/work/study/tool/git/local_src$ git push
warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated.  This may
warning: not necessarily be what you want to happen.
warning:
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning:   'nothing'  : Do not push anything
warning:   'matching' : Push all matching branches (default)
warning:   'tracking' : Push the current branch to whatever it is tracking
warning:   'current'  : Push the current branch
Counting objects: 5, done.
Writing objects: 100% (3/3), 250 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
warning: updating the current branch
warning: Updating the currently checked out branch may cause confusion,
warning: as the index and work tree do not reflect changes that are in HEAD.
warning: As a result, you may see the changes you just pushed into it
warning: reverted when you run 'git diff' over there, and you may want
warning: to run 'git reset --hard' before starting to work to recover.
warning:
warning: You can set 'receive.denyCurrentBranch' configuration variable to
warning: 'refuse' in the remote repository to forbid pushing into its
warning: current branch.
warning: To allow pushing into the current branch, you can set it to 'ignore';
warning: but this is not recommended unless you arranged to update its work
warning: tree to match what you pushed in some other way.
warning:
warning: To squelch this message, you can set it to 'warn'.
warning:
warning: Note that the default will change in a future version of git
warning: to refuse updating the current branch unless you have the
warning: configuration variable set to either 'ignore' or 'warn'.
To /home/jaewon/work/study/tool/git/remote_src/.
   fc2d23f..979521d  master -> master

위의 경고 메시지를 확인해 보니 정말 문제가 있었다.
우선 위의 경고 메시지는 2가지로서 하나는 현재 local 에서 어떤 branch 를 push 할 것이냐 하는 설정이고,
또 다른 하나는 현재 local의 branch로는 remote에 정상적으로 반영되어 보이지 않는다는 것이다.

먼저 remote에 반영 경고를 확인해 봤다.
아래처럼 local 과  remote 의 index에는 정상적으로 반영되었는데,

jaewon@jaewon-laptop:~/work/study/tool/git/local_src$ git log
commit 979521d7978f7a26c989047bae7806466353ad61
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:44:44 2010 +0900
    2nd
commit fc2d23fb93c972c3f48a75f9bf7be7de6a5d5ea3
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:42:48 2010 +0900
    initial
jaewon@jaewon-laptop:~/work/study/tool/git/local_src$ cd ../remote_src/ ; git log
commit 979521d7978f7a26c989047bae7806466353ad61
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:44:44 2010 +0900
    2nd
commit fc2d23fb93c972c3f48a75f9bf7be7de6a5d5ea3
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:42:48 2010 +0900
    initial

remote의 1.txt 파일과 git diff 정보에는 변경 사항이 반영되지 않았다.

jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ cat ./1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ git diff
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$

그런데 위의 경고 메시지처럼 git reset --hard 로써 현재 HEAD로 회기하였을 때 실제 1.txt 에 반영되었다.

jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ git reset --hard
HEAD is now at 979521d 2nd
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ cat ./1.txt
local modification

경고 메시지를 직접 확인했듯이,
remote_src 디렉토리의 소스 파일을 그대로 이용하는 것은 문제가 있다.
그럼 어떻게 해야 할 것인가?

'Tool > git' 카테고리의 다른 글

git 알면 편한 기능  (0) 2010.11.13
git reference  (0) 2010.07.05
git staic build  (0) 2010.04.27
git init --bare 이용  (1) 2010.04.23
qgit  (0) 2010.04.20
Posted by neodelicious
|