Forum Discussion
Altera_Forum
Honored Contributor
19 years agoHi PhillipD
To get rid of the IDE was the first thing I did after it was introduced. I my humble opinion it sucks. No way I could live with that as a programmer. Way too slow, very hard to document your compiler settings etc, just a plain pain. Now I uses my favourite editor slickedit and a makefile and GNU make (3.80 remember something about problems with never versions) via CYGWIN. I spent quite some time figuring out what to compile etc. But now this sort of makefile works nicely in several projects. Hope it might help you too. You will need the linker script created by the IDE too. Makefile is below. Regards Jacob <div class='quotetop'>QUOTE </div> --- Quote Start ---#!/bin/bash
TOOLS = ..\tools
PROJECT = ..\\..\\sandbox.pj
PROGRAM_NAME = Firmware
PTF = ./cpu/FirmwareCpu.ptf
OBJDIR = c:/temp/$(PROGRAM_NAME)/obj
OBJLIB = alt_exception_entry.o
alt_do_ctors.o
alt_do_dtors.o
alt_usleep.o
alt_busy_sleep.o
alt_irq_register.o
alt_irq_entry.o
alt_irq_handler.o
alt_malloc_lock.o
alt_exit.o
alt_errno.o
alt_write.o
alt_env_lock.o
alt_lseek.o
alt_close.o
alt_read.o
alt_fstat.o
alt_getpid.o
alt_kill.o
alt_sbrk.o
alt_dev.o
alt_release_fd.o
alt_isatty.o
alt_load.o
alt_dcache_flush_all.o
alt_icache_flush_all.o
alt_icache_flush.o
alt_dcache_flush.o
alt_irq_vars.o
CRT0 = crt0.o
SOURCE = ..\\Firmware\\Firmware.cpp
..\\Firmware\\kernel.cpp
..\\Firmware\\CardDecode.cpp
..\\Firmware\\i2c.cpp
..\\Userware\\usb.cpp
..\\Userware\\Hal4d12.cpp
..\\Userware\\proto.cpp
..\\Firmware\\ccd.cpp
..\\common\\flash.cpp
..\\common\\log.cpp
..\\common\\safe_sprintf.cpp
..\\common\\random.cpp
..\\common\\crc32.cpp
..\\common\\regexpclass.cpp
OBJECTS = $(addsuffix .o, $(notdir $(basename $(SOURCE))))
NIOSKIT = nios2_51
SOPC_KIT_NIOS2_REVISED = /cygdrive/c/altera/kits/$(NIOSKIT)
VPATH = ../common:../UserWare:../Firmware:$(SOPC_KIT_NIOS2_REVISED)/components/altera_nios2/HAL/src:$(SOPC_KIT_NIOS2_REVISED)/components/altera_hal/HAL/src
# +--------------------------------# | First, some traditional defines# | for our particular tool chain
GNU_TOOLS_PREFIX = nios2-elf
AS = $(GNU_TOOLS_PREFIX)-gcc
CC = $(GNU_TOOLS_PREFIX)-gcc
AR = $(GNU_TOOLS_PREFIX)-ar
LD = $(GNU_TOOLS_PREFIX)-g++
OC = $(GNU_TOOLS_PREFIX)-objcopy
NM = $(GNU_TOOLS_PREFIX)-nm
OD = $(GNU_TOOLS_PREFIX)-objdump
INCLUDE_PATH = -I ./
INCLUDE_PATH += -I ../include
INCLUDE_PATH += -I ../UserWare
INCLUDE_PATH += -I $(SOPC_KIT_NIOS2)/components/altera_nios2/HAL/inc
INCLUDE_PATH += -I $(SOPC_KIT_NIOS2)/components/altera_hal/HAL/inc
# +------------------------------------# | Switches for the compiler, the assembler,# | and the linker# |
ASFlags =
CCFLAGS = $(INCLUDE_PATH)
CCFLAGS += -DTERMINAL # # CCFLAGS += -DBOOTLOADER
CCFLAGS += -DNIOS2 -fshort-enums
CCFLAGS += -DSYSTEM_BUS_WIDTH=32
CCFLAGS += -mhw-mul -mno-hw-mulx -mhw-div -g# # CCFLAGS += -DUSESAFEMALLOC # # CCFLAGS += -DTRACELOG# # CCFLAGS += -DNOLOG
CCFLAGS += -O3 -Wall
CCFLAGS += -DALT_MAX_HEAP_BYTES=524288
LDFLAGS = -pipe -Tlinker.ld# LDFLAGS += -Wl,--defsym,exit=_exit# LDFLAGS += -msmallc
# Rules
$(OBJDIR)/%.o : %.cpp
@Echo Compiling $<
@$(CC) -c -xc++ $(CCFLAGS) $< -o $@
$(OBJDIR)/%.o : %.cxx
@Echo Compiling $<
@$(CC) -c -xc++ $(CCFLAGS) $< -o $@
$(OBJDIR)/%.o : %.S
@Echo Assembling $<
@$(AS) -c $(CCFLAGS) $< -o $@
$(OBJDIR)/%.o : %.c
@Echo Compiling $<
@$(CC) -c -xc $(CCFLAGS) $< -o $@
system.h: system.stf $(PTF)
@Echo Generating system.h
gtf-generate --output-directory=. --gtf=$(SOPC_KIT_NIOS2)/bin/gtf/system.h.gtf --stf=system.stf
@touch system.h
dep :
@Echo Making dependencies $<
for i in $(SOURCE);
do
$(CC) -MM -c $(CCFLAGS) $$i >> dependencies;
done
sed -e 's/^/$$(OBJDIR)\/&/g' dependencies > $(PROGRAM_NAME).dep
@rm -rf dependencies
clean :
@Echo Removing objects
rm -rf $(OBJDIR)/*.o
rm -rf $(PROGRAM_NAME).objdump
rm -rf $(PROGRAM_NAME).elf
rm -rf ./Firmware/system.h
rm -rf $(PROGRAM_NAME).bin
rm -rf libsys.a
$(PROGRAM_NAME).elf : $(addprefix $(OBJDIR)/,$(OBJECTS)) $(addprefix $(OBJDIR)/,$(CRT0))
@Echo Linking $@
$(LD) $(LDFLAGS) -msys-lib=sys -L '.' -msys-crt0=$(addprefix $(OBJDIR)/,$(CRT0)) -o $@ $(addprefix $(OBJDIR)/,$(OBJECTS))
$(PROGRAM_NAME).bin : $(PROGRAM_NAME).elf
@Echo converting elf->bin
nios2-elf-objcopy -O binary $(PROGRAM_NAME).elf $(PROGRAM_NAME).bin
# | Handy auxilliary files
$(PROGRAM_NAME).objdump : $(PROGRAM_NAME).elf
@Echo Making $(PROGRAM_NAME).objdump
nios2-elf-objdump -t -d -S $(PROGRAM_NAME).elf > $(PROGRAM_NAME).objdump
# Library
libsys.a: $(addprefix $(OBJDIR)/,$(OBJLIB)) system.h
@echo Archiving into libsys.a
@$(AR) -src libsys.a $(addprefix $(OBJDIR)/,$(OBJLIB))
lib: libsys.a
misc:
-@mkdir -p $(OBJDIR)
# +-------------------------------------# | Shortcut Targets
elf : $(PROGRAM_NAME).elf
bin : misc lib $(PROGRAM_NAME).bin
nios2-elf-size $(PROGRAM_NAME).elf
aux : $(PROGRAM_NAME).objdump
include $(PROGRAM_NAME).dep
[/b] --- Quote End ---