Android NDK 콘솔용 Makefile

2009.11.12 19:11 from Android
안드로이드는 adb를 통해 shell 접근이 가능하다. NDK에서 사용하는 함수 확인이나 디버깅을 이렇게 shell에서 간단하게 확인해 보는것이 JNI를 통하는 것 보다 쉬울수도 있다.

Makefile
ANDROID_NDK=c:\andoird\android-ndk-1.6_r1

NDKROOT:=$(shell cygpath -u '$(ANDROID_NDK)')
SYSROOT:=$(NDKROOT)/build/platforms/android-4/arch-arm
TOOLCHAINDIR:=$(NDKROOT)/build/prebuilt/windows/arm-eabi-4.2.1/bin
TARGET_CC := $(TOOLCHAINDIR)/arm-eabi-gcc.exe
TARGET_LD := $(TOOLCHAINDIR)/arm-eabi-ld.exe

TARGET_LIBGCC := $(shell $(TARGET_CC) -mthumb-interwork -print-libgcc-file-name)
TARGET_LDLIBS := -Wl,-rpath-link=$(SYSROOT)/usr/lib $(TARGET_LIBGCC)
TARGET_CRTBEGIN_STATIC_O  := $(SYSROOT)/usr/lib/crtbegin_static.o
TARGET_CRTBEGIN_DYNAMIC_O := $(SYSROOT)/usr/lib/crtbegin_dynamic.o
TARGET_CRTEND_O := $(SYSROOT)/usr/lib/crtend_android.o
STDLIBS=c m stdc++
TARGET_SHARED_LIBRARIES:=$(foreach STDLIBS, $(STDLIBS), $(SYSROOT)/usr/lib/lib$(STDLIBS).so)
TARGET_STATIC_LIBRARIES:=$(foreach STDLIBS, $(STDLIBS), $(SYSROOT)/usr/lib/lib$(STDLIBS).a)
TARGET=test

INCLUDE:=-I$(SYSROOT)/usr/include
CFLAGS+=-c $(DEFINE) $(INCLUDE) \
    -march=armv5te -mtune=xscale \
    -msoft-float -fpic \
    -mthumb-interwork \
    -ffunction-sections \
    -funwind-tables \
    -fstack-protector \
    -fno-short-enums \
    -fshort-wchar \
    -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ \
    -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__
   
EXEFLAGS=-nostdlib -Bdynamic \
    -Wl,-dynamic-linker,/system/bin/linker \
    -Wl,--gc-sections \
    -Wl,-z,nocopyreloc \
    $(TARGET_SHARED_LIBRARIES) \
    $(TARGET_CRTBEGIN_DYNAMIC_O) \
    $(TARGET_STATIC_LIBRARIES) \
    $(TARGET_LDLIBS) \
    $(TARGET_CRTEND_O)   

all: $(TARGET)

$(TARGET): main.o
    $(TARGET_CC) $(EXEFLAGS) -o test main.o
   
clean:
    rm $(TARGET) main.o
   
main.o: main.c
    $(TARGET_CC) $(CFLAGS) -o $@ $<

main.c

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv)
{
    FILE* hFile = fopen("a.txt", "w");
   
    fprintf(hFile, "1234");
    fclose(hFile);
   
    return 0;
}

실행예
adb push test /data
adb shell
# cd /data
# chmod 777 test ; ./test
저작자 표시 비영리
신고
Posted by NOP 트랙백 0 : 댓글 1

티스토리 툴바