Can someone help me out with a makefile for raspbian gcc ?

Page 4 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.
May 11, 2008
22,218
1,410
126
Well, for my current test project with a single library this works.
I had the issues that made an error in the path and i reversed the priority between libraries and object files.
This current makefile works at least with my current library test project.
Now i can try the gtk examples and see if it works as well. And then adapt W-ARM to this all for me.


Code:
# Automatically generated by W-ARM for RPI !
# Do not edit this file with an editor that replaces tabs with spaces !
################################################################################

ECHO = echo.exe
CP = cp.exe
CC = arm-linux-gnueabihf-g++.exe
AS = arm-linux-gnueabihf-g++.exe -x assembler-with-cpp
CREATE_OUTPUT_FILE = arm-linux-gnueabihf-g++ -o MakingALib

################################################################################
#sources setup.
SRC =./src/main.c
ASRC =

################################################################################
# include directories setup.
USR_INC_DIR =./inc

################################################################################
#libraries setup.
LIB = -ltest

# Library directory with LD switches.
LIB_DIR_PATH =-L./lib

################################################################################

# substitution reference OBJS = every module name, replace s with o and every c with o.
OBJS = $(ASRC:.s=.o) $(SRC:.c=.o)

### compiler flags.
# architecture optimizations
MCU_FLAGS = -mcpu=cortex-a53
# compiler optimisation level
OPT =-O1

# debugger
DBGGR =
# floating point unit
FLPU =-mfpu=vfpv4
# compiler flags combined into a single variable.
CP_FLAGS = $(DBGGR) $(FLPU) $(OPT) $(MCU_FLAGS) -Wall -g -Wa,-adhln=$(<:.c=.lst)

# assembler flags combined into a single variable.
AS_FLAGS = $(OPT) $(MCU_FLAGS) -Wa

# linker flags.
LD_FLAGS = $(MCU_FLAGS) $(OBJS) $(LIB_DIR_PATH) -lgcc -lrt $(LIB) -Wl,-Map=./output/MakingALib.map,--cref

# Eye candy.
begin:
    @$(ECHO)
    @$(ECHO) ---------------- begin ----------------
    @$(ECHO)

finished:
    @$(ECHO)
    @$(ECHO) Errors none.
    @$(ECHO)
    @$(ECHO) Output format = Raspbian executable
    @$(ECHO)
    @$(ECHO) Project name = MakingALib
    @$(ECHO)

end:
    @$(ECHO)
    @$(ECHO) ---------------- end ----------------
    @$(ECHO)

clean_message:
    @$(ECHO)
    @$(ECHO) Cleaning directories of current project : MakingALib
    @$(ECHO)

# Display compiler version information.
gccversion:
    @$(CC) --version

#Execute from here.
all: begin gccversion create move_files finished end

#copy files to new destination.
move_files:
    @$(CP) ./src/*.lst ./list/
    @$(CP) ./src/*.o  ./object/
    @$(CP) MakingALib ./output/
    @-rm -f ./src/*.lst
    @-rm -f ./src/*.o
    @-rm -f MakingALib

# create output file.
#Make searches for pattern rules first.
create: $(OBJS)
    $(CREATE_OUTPUT_FILE) $(LD_FLAGS)

# This pattern rule is performed for every single c module. One object file for every c module.
%.o : %.c
    $(CC) -c $(CP_FLAGS) -I $(USR_INC_DIR) $< -o $@

# This pattern rule is performed for every single assembly module. One object file for every assembly module.
%.o : %.s
    $(AS) -c $(AS_FLAGS) -I $(USR_INC_DIR) $< -o $@

clean: begin gccversion deletefiles clean_message end

deletefiles:
    @-rm -f $(OBJS)
    @-rm -f $(SRC:.c=.c.bak)
    @-rm -f $(SRC:.c=.lst)
    @-rm -f $(ASRC:.s=.s.bak)
    @-rm -f $(ASRC:.s=.lst)
    @-rm -fR .dep
    @-rm -f ./output/*.map
    @-rm -f ./output/MakingALib
    @-rm -f ./list/*.lst
    @-rm -f ./object/*.o


# Listing of phony targets.
.PHONY : all begin finish end move_files clean_message sizebefore sizeafter gccversion build elf hex lss sym clean clean_list program

# *** EOF ***
 
Last edited:
May 11, 2008
22,218
1,410
126
Yahooo. It works.
I can now successfully build a gtk window by making use of the gnu crosscompiler under windows.
The file executes fine on the raspberry pi3.
I now have the speed of compiling native under windows and by use of realvnc i can copy the file to the raspberry pi3 and execute it.
 
May 11, 2008
22,218
1,410
126
Is it not great.

gtkwindow.jpg~original
 
May 11, 2008
22,218
1,410
126
Well, W-ARM program manager is adapted to take a txt file created by pkg-config. I just type pkg-config --cflags --libs gtk+-3.0 > gtk3.txt at the bash prompt.
Then i import the gtk3.txt file into the W-ARM program manager and it resolves all issues creating a makefile with all libs, lib paths and inc path setup correctly.

The python script i made from following examples here and there allowed me to get all libraries that i need and resolve the symlinks.
I just copy all the include files to the inc directory of the project.
After that, it is following the comments the gcc compiler generates about the missing libraries after pressing the compile button, i copy the missing libraries to the lib directory of my project.
And it works after compiling.

I just tested it with a new project that i just started working on and it compiled immediately.
My cross compiler setup is ready. I can now fully compile under windows with ease.
I can now start with the gk3 examples from this site :

http://www.raspberry-projects.com/pi/programming-in-c

Maybe outdated.
But this site is great.

http://zetcode.com/gui/gtk2/

http://zetcode.com/
 
Last edited:
May 11, 2008
22,218
1,410
126
Well, W-ARM for the raspberry pi is as good as finished. I was planning for to add sam4s microcontrollers support as well. But after creating my own custom sam4s8b (http://www.atmel.com/devices/ATSAM4S8B.aspx) pcb (by making use of http://www.shenzhen2u.com/) and installing Atmel studio 7, i am pleasantly surprised with how well atmel studio works. Thus i decided to not go the DIY road for the sam4s mcu. Now when i have time, i have to clean up the W-ARM code a bit, create documentation and then i can release W-ARM into the wild if sourceforge still works.
W-ARM is useful for the SAM7S series from Atmel and for to create code for the raspberry pi with the GNU tools cross compiler which runs on windows.