Re: [Yaffs] yaffs/direct Makefile: adapt to fit library

Top Page
Attachments:
Message as email
+ (text/plain)
+ Makefile (text/plain)
Delete this message
Reply to this message
Author: Rutger Hofman
Date:  
To: Charles Manning
CC: yaffs
Subject: Re: [Yaffs] yaffs/direct Makefile: adapt to fit library
Rutger Hofman wrote:
> Charles Manning wrote:
>> On Monday 03 November 2008 14:35:08 Rutger Hofman wrote:
>>> Good evening list,
>>>
>>> I am using yaffs/direct for my project (yaffs on eCos). I adapted the
>>> Makefile in direct/, because I want it to generate a library -- right
>>> now, it generates a linked executable.
>>>
>>> The changes are:
>>>
>>> - add a target (not the default) for building a library
>>> - making a difference between the files that should belong in the
>>> library and the files that are used to build the direct/ demo executables
>>> - and some small stuff: I like to generate dependency files; I changed
>>> the symlinking of the files in direct/../ to use the files themselves,
>>> because symlinks defy dependency checking.
>>>
>>> Is yaffs interested in a patch?
>>>
>>> Rutger
>> Hello
>>
>> Please do post this to the list.
>>
>> If it is considered useful then it may be incorporated.


Here is my replacement direct/Makefile.

It depends on GNU make -- but I think the original already did that.

It has the goodies mentioned above. Dependency generation is optional:
it is done if MAKEDEPEND is defined on the command line, or if the
compiler name matches "*gcc" (as in my case: bfin-elf-gcc or arm-elf-gcc).

Invocation as just "make" ought to do the same thing as with the
original. If one wants to build as a library, do "make lib". To change
compiler name/flags etc, invoke as "make CC=<my compiler> CFLAGS="<all
compiler flags>", including those that are mandatory for direct
building, like -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_SHORT_NAMES_IN_RAM
-DCONFIG_YAFFS_YAFFS2 and friends.

This Makefile already has a target yaffs_test, even though there is no
file yaffs_test.c in the repository :-) .

Rutger
# Makefile for YAFFS direct test
#
#
# YAFFS: Yet another Flash File System. A NAND-flash specific file system.
#
# Copyright (C) 2003 Aleph One Ltd.
#
#
# Created by Charles Manning <>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# NB Warning this Makefile does not include header dependencies.
#
# $Id: Makefile,v 1.20 2008-11-11 01:48:47 charles Exp $

# Invoke this Makefile normally if you want to build the executables
#
# For building a cross-compiled library, invoke as follows:
#
# $ make CC=<your cross-compiler> CFLAGS=<your cross-compile CFLAGS> AR=<your ar> lib
#
# You *must* include in your CFLAGS:
#     -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_SHORT_NAMES_IN_RAM -DCONFIG_YAFFS_YAFFS2 -DCONFIG_YAFFS_PROVIDE_DEFS
#
# You may have to optionally add:
#     RANLIB=<your ranlib>
#     MAKEDEPEND=<your makedepend>, should generate bla.d for bla.c.
#         Unnecessary if your compiler is gcc (or arch-fmt-gcc).


# Set default for CC
CC        = gcc


#EXTRA_COMPILE_FLAGS = -DYAFFS_IGNORE_TAGS_ECC

CFLAGS =      -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_SHORT_NAMES_IN_RAM -DCONFIG_YAFFS_YAFFS2  
CFLAGS +=     -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES -DNO_Y_INLINE
CFLAGS +=    -Wall -g $(EXTRA_COMPILE_FLAGS) -Wstrict-aliasing 
#CFLAGS +=    -fno-strict-aliasing
CFLAGS +=    -O3
#CFLAGS +=    -DVALGRIND_TEST


#CFLAGS+= -Wshadow -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-declarations
#CFLAGS+= -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline

DIRECT_OBJ    =
DIRECT_OBJ    += yaffsfs.o


MAIN_OBJ    =
MAIN_OBJ    += yaffs_fileem.o
MAIN_OBJ    += yaffs_fileem2k.o
MAIN_OBJ    += yaffs_ramdisk.o
MAIN_OBJ    += yaffs_ramem2k.o
MAIN_OBJ    += yaffscfg2k.o  
MAIN_OBJ    += dtest.o


COMMON_OBJ    =
COMMON_OBJ    += yaffs_ecc.o
COMMON_OBJ    += yaffs_guts.o
COMMON_OBJ    += yaffs_packedtags1.o
COMMON_OBJ    += yaffs_tagscompat.o
COMMON_OBJ    += yaffs_packedtags2.o
COMMON_OBJ    += yaffs_tagsvalidity.o
COMMON_OBJ    += yaffs_nand.o
COMMON_OBJ    += yaffs_checkptrw.o
COMMON_OBJ    += yaffs_qsort.o
# COMMON_OBJ    += yaffs_checkptrwtest.o


BOOTTESTOBJS = yaffs_fileem.o # bootldtst.o yboot.o nand_ecc.o
YAFFSTESTOBJS = $(COMMONTESTOBJS) yaffs_test.o

DIRECT_LIB_OBJ    = $(DIRECT_OBJ) $(COMMON_OBJ)


ALLOBJS = $(DIRECT_LIB_OBJ) $(BOOTTESTOBJS) $(MAIN_OBJ)

LIB    = libyaffs.a


#all: directtest2k boottest

all: directtest2k yaffs_test

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


$(COMMON_OBJ): %.o: ../%.c
    $(CC) -c $(CFLAGS) -o $@ $<


directtest2k: $(DIRECT_LIB_OBJ) $(MAIN_OBJ)
    $(CC) -o $@ $(DIRECT_LIB_OBJ) $(MAIN_OBJ)


lib: $(LIB)

$(LIB): $(DIRECT_LIB_OBJ)
    $(AR) rcs $@ $(DIRECT_LIB_OBJ)
ifneq ($(RANLIB), )
    $(RANLIB) $@
endif


yaffs_test: $(YAFFSTESTOBJS)
    $(CC) -o $@ $(YAFFSTESTOBJS)


boottest: $(BOOTTESTOBJS)
    $(CC) -o $@ $(BOOTTESTOBJS)


clean:
    rm -f $(ALLOBJS) core $(DEPS)


# From the cheatsheet: if we use gcc, then we know how to makedepend
ifeq (gcc, $(patsubst %gcc, gcc, $(CC)))
MAKEDEPEND = $(CC) -MM -MD -E
endif

ifneq (, $(MAKEDEPEND))
%.d    : %.c
    $(MAKEDEPEND) $(CFLAGS) $< -o $@


C_FILES        =
C_FILES        += $(patsubst %.o, %.c, $(DIRECT_OBJ))
C_FILES        += $(patsubst %.o, %.c, $(BOOTTESTOBJS))
C_FILES        += $(patsubst %.o, %.c, $(MAIN_OBJ))
C_FILES        += $(patsubst %.o, ../%.c, $(COMMON_OBJ))


DEPS    = $(patsubst %.c, %.d, $(C_FILES))


include $(DEPS)
endif