'NDK'에 해당되는 글 2건

  1. 2009.11.12 Android NDK 콘솔용 Makefile (1)
  2. 2009.10.28 Android NDK 빌드환경을 사용하지 않는 Makefile

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
NDK의 Makefile을 사용하지 않는 간단버전의 Makefile, target은 so파일

# tool chain setting
ANDROID_NDK16=c:\andoird\android-ndk-1.6_r1
NDKROOT:=$(shell cygpath -u '$(ANDROID_NDK16)')
SYSROOT:=$(NDKROOT)/build/platforms/android-4/arch-arm
TOOLCHAINDIR:=$(NDKROOT)/build/prebuilt/windows/arm-eabi-4.2.1/bin
CC:=$(TOOLCHAINDIR)/arm-eabi-gcc.exe
CXX:=$(TOOLCHAINDIR)/arm-eabi-g++.exe
AR:=$(TOOLCHAINDIR)/arm-eabi-ar.exe
LD:=$(TOOLCHAINDIR)/arm-eabi-ld.exe

TARGET_LIBGCC := $(shell $(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)
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__
ifeq ($(DEBUG),y)
    CFLAGS+= -O0 -g
else
    CFLAGS+= -O2
endif
LDFLAGS=-nostdlib -Wl,-soname,$(notdir $@) \
    -Wl,-shared,-Bsymbolic \
    -Wl,--no-whole-archive \
    $(TARGET_LDLIBS) \
    -Wl,--whole-archive -o

# source setting
EXCLUDES:=
SRCDIR:=../src \
    ../test/src
CSRCS:=$(foreach SRCDIR, $(SRCDIR), $(filter-out $(EXCLUDES), $(wildcard $(SRCDIR)/*.c)))
OBJS=$(CSRCS:.c=.o)
TARGET=libTest.so

INCLUDE+=
CFLAGS+=
LIBFILES+=

# label
%.o: %.c
    $(CC) $(CFLAGS) -o $@ $<

all: $(TARGET)
   
$(TARGET): $(OBJS)
        $(CC) $(LDFLAGS) $@ $(OBJS) $(LIBFILES)

clean:
    rm $(OBJS) $(TARGET)

Posted by NOP 트랙백 0 : 댓글 0