[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Generate Custom Compiler / Build Rules?

From: Xochitl Lunde
Subject: Re: Generate Custom Compiler / Build Rules?
Date: Tue, 15 Sep 2009 14:24:08 -0500

address@hidden wrote on 09/14/2009 
11:51:26 PM:

> You can, even only as an intermediate step on the way to a unified
> makefile, put code common to several makefile in a fragment:
> <>

Xochitl: Ok, I am going to try it.

> Well, you can still use GNU make on all of them.  Your choice whether
> you want to make it a prerequisite for your users or not.

Xochitl: Ah, there are only 8 in-house users of our Makefiles.  We 
distribute RPMS or complete binaries to customers.  That said, I would 
still like to make good choices when writing Makefiles.

> But without seeing the things the rules have in common, or differ in, we
> cannot easily suggest a simplification.

Xochitl: Oh, I did not expect anyone to have the time.  I worked out some 
of the rules yesterday.  I can't figure out how to make a rule that says, 
"after all objects for 'program_a' are built, make this intermediate 
target before the EXEEXT without overriding the EXEEXT, which you saw that 
I did before.  Meaning, I can't figure out how to make a target that is 
based on a group of things like "all object files".  For the moment, 
everything is now shortened quite a bit.  I changed the EXEEXT to build 
the .elf file and now I let make create that by itself.  Then afterward I 
can type 'make safemodetest-flash' or 'make safemodetest-gdb' to complete 
my setup. This is exactly the command sequence I had before, just now the 
rules are pattern-matched.  My experimental is now 330 lines 

I would like to get to the point where for all programs it creates both 
the *.elf file and the *.bin file when I type make, instead of having to 
do it in 2 steps.  Right now if I type 'make' it will build all the *.elf 
files because that is defined as the EXEEXT, but then I have to run 
additional rules to get it to make the *.bin file.

Also you were of course right that the myprog_INCLUDES does not work.  I 
was defining myprog_INCLUDES and then adding $(myprog_INCLUDES) in 
myprog_CXXFLAGS, and that was why it worked for me.

# -----------------------------------------------------------------------
# Note: Because libcppunit uses exceptions, all of these applications
# need to have exceptions enabled.
# -----------------------------------------------------------------------
AM_CPPFLAGS = -fexceptions -g 

TESTS = safemodetest systemutilitytest

        ##stringutilitytest datetimeutilitytest timespantest
        ##datetimetest fileutilitytest


vpath %.c .
vpath %.cpp .
vpath %.c $(ac_netos_dir)/src/bsp/common
vpath %.s $(ac_netos_dir)/src/bsp/common

vpath %.cpp $(top_srcdir)/tests
vpath %.cpp $(top_srcdir)/tests/all

# --------------------------------------
# Unit test of safemode.h / safemode.cpp
# --------------------------------------
dist_safemodetest_SOURCES = \
        $(top_srcdir)/../common/tests/base/safemodetest.h \
        $(top_srcdir)/../common/tests/base/safemodetest.cpp \

# From Makefile.appbuild.ns9215, additional code needs to be compiled.
nodist_safemodetest_SOURCES= $(ac_netos_dir)/src/bsp/common/appconf_api.c

safemodetest_INCLUDES = -include 

safemodetest_CXXFLAGS = -DTESTCLASS=SafeModeTest $(safemodetest_INCLUDES)
safemodetest_LDFLAGS =  -Wl,-T,${ac_netos_linkcmd} 

# ------------------------------------------------
# Unit test of systemutility.h / systemutility.cpp
# ------------------------------------------------
dist_systemutilitytest_SOURCES = \
        $(top_srcdir)/../common/tests/base/systemutilitytest.h \
        $(top_srcdir)/../common/tests/base/systemutilitytest.cpp \

# From Makefile.appbuild.ns9215, additional code needs to be compiled.

systemutilitytest_INCLUDES = -include 

systemutilitytest_CXXFLAGS = -DTESTCLASS=SystemUtilityTest 
systemutilitytest_LDFLAGS =  -Wl,-T,${ac_netos_linkcmd} 
systemutilitytest_LDADD = $(NETOS_CUST_OBJS) $(STARTFILE) $(LDADD) 

# -----------------------------
# Include paths for all images.
# -----------------------------
        -I.. \
        -I$(top_srcdir)/src \
        -I$(top_srcdir)/../common/src \
        -I$(top_srcdir)/../common/tests \
        -I$(top_srcdir)/../../externals/cppunit/arm9/include \

# -------------------------------------------
# LDFLAGS and PowerAlert libs for all images.
# -------------------------------------------
AM_LIBTOOLFLAGS = --preserve-dup-deps

        -L$(top_srcdir)/src/startup \
        -L$(top_builddir)/src/services \
        -L$(top_builddir)/src/base \
 -L$(top_srcdir)/../../externals/cppunit/$(ac_external_arch_path)/lib \
        -L$(ac_netos_libdir) \
        -L$(ac_netos_bspdir) \
        -L$(ac_netos_dir)/lib \
        -L$(ac_netos_dir)/gnusrc \

        -lstartup \
        -lservices \

# -----------------------------------------------
# LDADD doesn't cut it for the netsilicon build.
# Instead we need to give the full library paths.
# -----------------------------------------------
        -lftpsvr \
        -ltcpip \
        -lflash \
        -lc \
        -ltx \
        -lbsp \
        -lfilesys \
        -lcrypto \
        -lsntp \
        -laddp \
        -ldnsclnt \
        -lposix \
        -ltcpip \
        -lbsp \
        -lfilesys \
        -ltx \
        -lcppunit \

LIBS = -lgcc -lm -lstdc++ -ltx

# -----------------------------------------------------------
# Additional objects are required for linking an application.
# -----------------------------------------------------------
NETOS_CUST_OBJS=$(ac_netos_bspdir)/reset.o \

# -------------------------------------------------------------
# The startfile is crt0.o.  This defines our application start.
# Only crt0.o is needed if your application is C.
# For c++ define the other 4 files. You might otherwise see the
# error: undefined symbol __dso_handle
# -------------------------------------------------------------
STARTFILE=$(ac_netos_dir)/lib/32b/gnu/crt0.o \
        $(ac_netos_dir)/lib/32b/gnu/crti.o \
        $(ac_netos_dir)/lib/32b/gnu/crtbegin.o \
        $(ac_netos_dir)/lib/32b/gnu/crtend.o \

# ---------------------------------------------------
# Define custom build rules for the executable files.
# These are the definitions for the debug image. 
# More rules are needed to initialize the debugger.
# ---------------------------------------------------
%$(SYM_EXT) : %$(EXEEXT)
        $(NM) -n $< > $@

# ------------------------------------------------------------------
# Define rules to make the *.bin images. This build rule is defined
# in Makefile.appbuild.ns9215 as the target $(IMAGE_WITH_HEADER).
# ------------------------------------------------------------------
%$(BIN_EXT) : %$(EXEEXT)
        f=`echo "$<" | sed 's/$(EXEEXT)//'`; \
        make $$f$(SYM_EXT); \
        cp $< $$f-monimage$(EXEEXT);
        $(OBJCOPY) -Obinary $< $$f$(ac_uncompress_ext) 
        $(ac_netos_imgcompress) $$f$(ac_uncompress_ext) 
        $(ac_netos_boothdr) $(ac_netos_imgheader_cfg) 
$$f$(ac_compress_ext) $@ $(PLATFORM) $(ac_netos_l2b_endian)
        $(RM) $$f$(ac_compress_ext)
        ../../$(ac_netos_binpack) $(PLATFORM) 
$(ac_netos_ldscripts)/rom.bin $@
        mv rom.bin $@
        mv rom.bin.md5 address@hidden

# ------------------------------------------------------------
# Add the rules to create the GDB debugger files. The debugger
# needs to have the information from each image, and it
# expects that image to be named 'image.elf'. Only one image
# can be ready to debug at any given time.
# ------------------------------------------------------------
debugfile=$(shell pwd)/image.elf
currentfile="`cygpath -a -w $(debugfile)`"

        echo $(currentfile) > .currentfile
        cp $(ac_netos_dir)/debugger_files/gdb$(PLATFORM).jlink ./.gdbinit
        echo source $(ac_netos_dir)/debugger_files/.gdbinit.threadx >> 
        echo source $(ac_netos_dir)/debugger_files/.gdbinit.ns9215 >> 
        echo "addresses-ns9215" >> .gdbinit
        echo "command-info" >> .gdbinit
        rm .currentfile

%$(GDB) : %$(EXEEXT)
        $(RM) ./image$(EXEEXT); \
        $(RM) ./.gdbinit; \
        cp $< image$(EXEEXT); \
        make gdbinit; \
        echo "Please find the debug image at" $(debugfile)

# ----------------------------------------------
# Create rules to make the images from the file.
# This includes creating rom.bin and image.elf
# from the desired executable targets.
# ----------------------------------------------
releasefile=$(shell pwd)/rom$(BIN_EXT)

%$(FLASH): %$(BIN_EXT) %$(GDB)
        f=`echo "$<" | sed 's/$(BIN_EXT)//'`; \
        $(RM) ./rom.bin; \
        $(RM) ./rom.bin.md5; \
        mv $$f$(BIN_EXT) rom$(BIN_EXT); \
        mv $$f$(BIN_EXT).md5 rom$(BIN_EXT).md5; \
        echo "Please find the flash image at" $(releasefile)

# -------------------------
# Additional general rules.
# -------------------------
        $(RM) ./*.o ./*.d
        $(RM) ./*.elf ./*.bin ./*.sym ./*.map ./*.*compressed ./.gdbinit 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]