1# Custom GNUMakefile to rebuild nawk for the Android NDK 2# (C) 2011 The Android Open Source Project 3# yada yda yada Apache 2.0 License.... 4 5BUILD_DIR ?= /tmp/ndk-$(USER)/build-awk 6 7 8CC := $(HOST_CC) 9CFLAGS := -O2 -I$(BUILD_DIR) -I. 10LDFLAGS := -Wl,-s 11BISON := bison 12 13MINGW := $(strip $(WIN32)) 14 15ifeq ($(V),1) 16hide := 17else 18hide := @ 19endif 20 21SOURCES := \ 22 lex.c \ 23 b.c \ 24 main.c \ 25 parse.c \ 26 lib.c \ 27 run.c \ 28 tran.c \ 29 30EXE := 31 32ifdef MINGW 33CC := i586-mingw32msvc-gcc 34EXE := .exe 35endif 36 37PROGRAM := $(BUILD_DIR)/ndk-awk$(EXE) 38 39all: $(PROGRAM) 40 41OBJECTS := 42 43YTAB_H := $(BUILD_DIR)/ytab.h 44YTAB_C := $(BUILD_DIR)/ytab.c 45YTAB_O := $(YTAB_C:.c=.o) 46$(YTAB_C): awkgram.y 47 @echo "Bison: ytab.c" 48 $(hide)$(BISON) -o $@ --defines=$(YTAB_H) awkgram.y 49 50$(YTAB_H): $(YTAB_C) awkgram.y 51 52OBJECTS += $(YTAB_O) 53 54# $1: source file 55# $2: object file 56define build-c-file 57OBJECTS += $2 58$2: $1 $(YTAB_H) 59 @echo "Compile: $1" 60 $$(hide)mkdir -p $$(dir $$@) 61 $$(hide)$$(CC) $$(CFLAGS) -c -o $$@ $$< 62endef 63 64$(foreach src,$(filter %.c,$(SOURCES)),\ 65 $(eval $(call build-c-file,$(src),$(BUILD_DIR)/$(src:%.c=%.o)))\ 66) 67 68MAKETAB := $(BUILD_DIR)/maketab$(EXE) 69$(MAKETAB): maketab.c $(BUILD_DIR)/ytab.h 70 @echo "Executable: $(notdir $@)" 71 $(hide)$(CC) $(CFLAGS) $(LDFLAGS) maketab.c -o $@ 72 73PROCTAB_C := $(BUILD_DIR)/proctab.c 74PROCTAB_O := $(PROCTAB_C:%.c=%.o) 75 76$(eval $(call build-c-file,$(PROCTAB_C),$(PROCTAB_O))) 77 78$(PROCTAB_C): $(MAKETAB) $(YTAB_H) 79 @echo "Gen: $(notdir $@)" 80 $(hide)$(MAKETAB) $(YTAB_H) > $@ 81 82 83$(PROGRAM): $(OBJECTS) 84 @echo "Link: $(notdir $@)" 85 $(hide)$(CC) $(LDFLAGS) -o $@ $(OBJECTS) -lm 86 87clean: 88 $(hide)rm -f $(OBJECTS) $(PROGRAM) $(MAKETAB) $(YTAB_C) $(YTAB_H) $(PROGTAB_C) 89