Thread: Makefile
View Single Post
  #3   Spotlight this post!  
Unread 13-01-2007, 19:33
chris31 chris31 is offline
Team 2021 Captain
AKA: Chris Davidson
FRC #2021 (FA Robotics)
Team Role: Mentor
 
Join Date: Nov 2005
Rookie Year: 2006
Location: Atlanta, GA/ Fredericksburg,VA
Posts: 949
chris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond repute
Send a message via AIM to chris31
Re: Makefile

Give this a try for making your makefile
PHP Code:
#!/usr/bin/env python

#Auto Makefile Generator
#Copyright under terms of GPL
#Based on Team 245's old Makefile....
#        Copyright (C) 2005  Team 245
#
#        This program is free software; you can redistribute it and/or modify
#        it under the terms of the GNU General Public License as published by
#        the Free Software Foundation; either version 2 of the License, or
#        (at your option) any later version.
#
#        This program is distributed in the hope that it will be useful,
#        but WITHOUT ANY WARRANTY; without even the implied warranty of
#        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#        GNU General Public License for more details.
#
#        You should have received a copy of the GNU General Public License
#        along with this program; if not, write to the Free Software Foundation,
#        Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


import os

DEBUG
=False
VERSION
="0.1.92 (0.2 beta 3)"

def printGPLBanner():
    print 
"Makefile Generator, version "+VERSION+", Copyright (C) 2005 Adam-Bots"
    
print "This software comes with ABSOLUTELY NO WARRANTY"
    
print "This is free software, and you are welcome to redistribute it under certain conditions; See the accompanying license for details"
    
def isCygwin():
    
import os;
    return 
os.platform=='cygwin'

def isLinux():
    
import os;
    return 
os.platform.beginswith('linux')

def mccPath():
    
#Find path to the MCC folder.
    
if isCygwin():
        
pass
def sprint
(msg,level=0):
    
# Prints a message of a given verbosity:
        #Level 0 : Print regardless of status
        #Level 1 : Print if DEBUG is set
    
if level == 0:
        print 
msg
    elif level 
== 1:
        if 
DEBUG:
            print 
"DEBUG:",msg
    
else:
        print 
msg
def mccCommand
():
    return 
"mcc18"
def mccArgs():
    return 
"-D_FRC_BOARD -w3 pa=3 -O+ -nw=2066"
def linkerCommand():
    return 
"mplink"
def mp2hexCommand():
    return 
"mp2hex"
def ifiLoaderCommand():
    return 
"picloader_textmode"
def ifiSerialDevice():
    return 
"/dev/ttyS0"
def ifiReadLogfile():
    return 
"./read.log"
def codePath():
    
unixish_path="Z:"+os.getcwd()+"//"
    
return unixish_path.replace("/","\\")
def libPath():
    return 
"/opt/mcc18/lib"
def includePath():
    return 
"/opt/mcc18/h"
def includePathWindows():
    return 
"Z:\\\\opt\\\\mcc18\\\\h"

printGPLBanner();
print
print
print

sprint("Opening the Makefile",1)
print
outfile=open('Makefile','w')
outfile.write('#This is automatically generated by the configure.py script\n#Keep your dirty hands off');
outfile.write("\n")
outfile.write('#Run ./configure.py to generate a fresh one.')
outfile.write("\n")
outfile.write('MCC18='+mccCommand())
outfile.write("\n")
outfile.write("PIC=18F8722 # Don't change")
outfile.write("\n")
outfile.write("ARGS="+mccArgs())
outfile.write("\n")
outfile.write("LINKER="+linkerCommand())
outfile.write("\n")
outfile.write("MP2HEX="+mp2hexCommand())
outfile.write("\n")
outfile.write("IFILOAD="+ifiLoaderCommand())
outfile.write("\n")
outfile.write("SERIAL_DEV="+ifiSerialDevice())
outfile.write("\n")
outfile.write("READLOG="+ifiReadLogfile())
outfile.write("\n")
outfile.write("LIB_PATH="+libPath())
outfile.write("\n")
outfile.write("CODE_PATH="+codePath())
outfile.write("\n")
outfile.write("INCLUDE_PATH="+includePath())
outfile.write("\n")
outfile.write("INCLUDE_PATHW="+includePathWindows())
outfile.write("\n")
outfile.write("\n\n\n\n")


sprint("Enumerating Target Object Files...")
import os;
all_targets=""
pipe=os.popen("find . -maxdepth 1 -name \"*.c\" | gawk '{gsub(/\\.c/,\".o\");print}' | uniq",'rt'
line=pipe.readline()
while 
line != "":
    
all_targets+=line[2:-1]
    
all_targets+=" "
    
line=pipe.readline()

all_targets.rstrip()

outfile.write("ALL_TARGETS="+all_targets);
outfile.write("\n")
sprint("Enumerating Header Files...")

pipe=os.popen("find . -name \"*.h\"",'rt')
line=pipe.readline()
headers=""
while line != "":
        
headers+=line[2:-1]
        
headers+=" "
        
line=pipe.readline()
headers.rstrip()


outfile.write("INCLUDE_FILES="+headers);
outfile.write("\n")
outfile.write("############ Targets: ")
outfile.write("\n")
outfile.write("default: FrcCode.hex")
outfile.write("\n")

sprint("Writing static targets...")
outfile.write("""
#Remove all the individual file backup (The files ending with ~)
#NOTE that this does NOT remove your tbz2 backups!
clean-backup-files:
    @echo -e "
Removing all the backup files your annoying editor makes..."
    @find . -name "
*~" |xargs rm -f

#Removes all compiled files from the directory
clean: clean-backup-files clean-deps nohex
    @echo -e "
Cleaning compiler intermediate files..."
    @rm -rf *.o *.err

#Remove deps folder
clean-deps:
    @echo -e "
Cleaning dependency folder..."
    @rm -rf .deps
    @mkdir .deps
    @touch .deps/dummy

#Remove hexfiles
nohex:
    @echo -e "
Cleaning linker output and hex files..."
    @rm -rf *.hex *.cod *.cof

#These all start the IFI Loader.
safeload: prettycode clean check load
load: FrcCode.hex
    $(IFILOAD) FrcCode.hex $(SERIAL_DEV)

read:
    @echo -e "
Monitoring $(SERIAL_DEV) for data"
    @echo -e "
Output will also be logged to $(READLOG)"
    @echo -e "
---------"
    @cat $(SERIAL_DEV) | tee $(READLOG) || /bin/true
    
    
prettycode:
    @echo -e "
Using indent to autoformat your .and .h files..."
    @indent *.c *.h
all: clean FrcCode.hex
%.o: %.c
    @echo -e "
Compiling $@..."
    @echo -e "
1.   Checking Dependencies for $@"
    @cpp -nostdinc -isystem $(INCLUDE_PATH) -M -MP $< -MF .deps/$*.deps
    @echo -e "
2.   Launching Compiler..."
    @echo -n "
A thought to keep you occupied:  "
    @fortune -s || echo "
GET FORTUNE"
    @$(MCC18) -p=$(PIC) -fo $@ $< /i\\""$(INCLUDE_PATHW)"
\\" $(ARGS) 
    @echo -e "
Done with $@."




FrcCode.hex :  $(ALL_TARGETS) $(INCLUDE_FILES)
    @echo -e "
Linking..."
    $(LINKER) /l\\""$(LIB_PATH)"
\\" \\""18f8722.lkr"\\" $(ALL_TARGETS) \\""$(CODE_PATH)FRC_library.lib"\\" /m\\""FrcCode.map"\\" /o\\""FrcCode.cof"\\"
    $(MP2HEX) FrcCode.cof



.deps/*: 
    @echo -e "
Creating Dependency Makefiles..."
    @mkdir -p .deps
    @touch .deps/dummy
    @echo -e "
Done!"

include .deps/*
"""
)
print
print

sprint("Makefile is generated, setting up working directory....")
os.system('rm -rf .deps')
os.system('mkdir .deps')
os.system('touch .deps/dummy')

print
print
print

sprint("Finished. To build, run 'make'"