Forum Discussion
Altera_Forum
Honored Contributor
21 years agoHere is a makefile I use with a modified Rules.mak
Apparently the forum post code is ripping the tabs out of the posted text even though it is in a code tagset so these will need modifications to properly indent the rule commands. Also I don't use the IDE much anymore and use the NIOS shell instead, so I haven't checked these in the IDE recently, but it should get you most of the way there. note the LDLIBS change which links in the static lib d.a and the rule for d.a Makefile:include Rules.mak
# macros and variables
LDLIBS += d.a
EXEC = d.a mysoftware.flt
ifdef DEBUG
GDB := $(patsubst %.flt, %.gdb, $(EXEC))
EXEC += $(GDB)
endif
# targets
all: $(EXEC)
d.a: d.o a.o b.o
$(AR) cru $@ $^
$(RANLIB) $@
clean:
-rm -f $(EXEC) $(OBJ) *.elf *.gdb *.o
.PHONY: clean all Rules.mak ########################################################################### Variables and Rules for building Nios II Linux applications# # This file is a "template" that is copied over from the Nios II Linux# Application plug-in. This file should be included within your top-level# Makefile.#
ifeq "$(origin TOPDIR)" "undefined"
TOPDIR := $(shell pwd)
endif
# # The Settings.mak file is automatically generated by Eclipse. It# contains values for all external variables used by this Makefile# fragment.# # The "dash" in front of the include statement indicates that the Make# process will not terminate if it cannot find the Settings.mak file.#
include $(TOPDIR)/Settings.mak
# # Warn users if external variables have not yet been defined.#
ifeq "$(origin UTILSDIR)" "undefined"
$(warning The location of the utilties directory is undefined)
endif
ifeq "$(origin LIBCDIR)" "undefined"
$(warning The location of uClibc is undefined)
endif
ifeq "$(origin LINUX_NE_ROOT)" "undefined"
$(warning The location of libraries is undefined)
endif
# # Path + Name of necessary executables#
EXECSUFFIX := .exe
CROSS := nios2-elf-
CC := $(CROSS)gcc
AR := $(CROSS)ar
LD := $(CROSS)ld
NM := $(CROSS)nm
RANLIB := $(CROSS)ranlib
STRIPTOOL := $(CROSS)strip
ELF2FLT := $(UTILSDIR)/bin/elf2flt
# # Location of important files#
CRT0 := $(LIBCDIR)/lib/crt0.o
LIBC := $(LIBCDIR)/lib/libc.a
LIBGCC := $(shell $(CC) -print-file-name=libgcc.a)
LIBM := $(shell $(CC) -print-file-name=libm.a)
LIBGCCDIR := $(dir $(LIBGCC))
LINKSCRIPT := $(UTILSDIR)/scripts/elf2flt.ld
# # Various flags, modifications are not recommended and not necessarily# supported.# # To debug your app, you should use "-O0 -g" in your CFLAGS variable.# # DEPFLAGS:# -MM : ignore system includes, # -M : include system includes in the dependency#
WARNING_FLAGS := -Wall
INCS = -I$(LIBCDIR)/include -I$(LIBGCCDIR)/include -I$(ULIBDIR)/include
DEFS := -D__linux__
ifdef DEBUG
FLAGS := -O0 -g -nostdinc -c
else
FLAGS := -O2 -g -nostdinc -c
endif
CFLAGS = $(FLAGS) $(INCS) $(DEFS)
# Auto-dependency flags: -MM : ignore system includes, -M : include system includes in the dependency
DEPFLAGS = -E -MM
LDFLAGS := -msys-crt0=$(CRT0) -r -d -L$(LIBCDIR)/lib -L$(ULIBDIR)
LDLIBS := $(LIBM) $(LIBGCC) $(LIBC)
# default stack size is 4K
FLTFLAGS:=
%.exe : %.flt
cp -f $< $@
# # Make a relocatable flat file from an ELF file.# STACKSIZE is defined by individual makefiles.#
%.flt : %.elf
$(ELF2FLT) $(FLTFLAGS) -o $@ $<
# # Make a bound-address ELF file required by GDB for debugging the application.#
%.gdb : %.bin
$(LD) -T $(LINKSCRIPT) -o $@ $<
# # Make a relocatable ELF file.#
%.elf : %.bin
$(LD) -T $(LINKSCRIPT) -Ur -o $@ $<
# # Standard stuff: The object file is dependent on the C source and Makefile timestamps#
%.o : %.c Makefile
$(CC) $(CFLAGS) $(WARNING_FLAGS) -o $@ $<
%.o : %.cpp Makefile
$(CC) $(CFLAGS) $(WARNING_FLAGS) -o $@ $<
%.bin : %.o
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
# # Automatically generate dependencies for the .c source files.# Be sure to omitt debug-level flags as this can produce macro def'n output.# The sed "script" makes the .d (in addition to the .c) file a# target of the dependencies so that the .d file is rebuild if required.# e.g. "X.o: <dependency-list>" gets transformed into "X.o X.d: <dependency-list>"#
%.d: %.c
$(SHELL) -ec '$(CC) $(DEPFLAGS) $(CFLAGS) -c $< | sed '\''s/\($*\)\.o*/.o $@ : /g'\'' >$@; || rm -f $@'