Makefile

this is on a linux box and i am running the compiler under wine.

i’m trying to make a Makefile that automates building individual parts of the robot code. for example, if i want to just compile the adc code, i can enter make adc in the toplevel src directory.

the problem is, i can’t seem to find the equivalent of gcc’s -c in the 2.4 compiler (which, for those unfamiliar, allows for compilation, but no linking to occur).

i think that’s the issue that’s causing compiler errors like this:
Z:\home\fauxnominal\robotics\src\adc\adc.c:0:Error: syntax error

any ideas? i looked at the compiler’s --help options, but didn’t see anything that worked.

i followed the directions here:

that didn’t seem to work either. i still get that error:
Z:\home\fauxnominal\robotics\src\adc\adc.c:0:Error : syntax error

i’m fairly sure it’s not an issue with Kevin Watson’s code as line 0 (does that imply line 1?) is a comment which can’t possibly have a syntax error

it’s quite frustrating, any ideas?

Give this a try for making your makefile


#!/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
#Keep your dirty hands off');
outfile.write("
")
outfile.write('#Run ./configure.py to generate a fresh one.')
outfile.write("
")
outfile.write('MCC18='+mccCommand())
outfile.write("
")
outfile.write("PIC=18F8722 # Don't change")
outfile.write("
")
outfile.write("ARGS="+mccArgs())
outfile.write("
")
outfile.write("LINKER="+linkerCommand())
outfile.write("
")
outfile.write("MP2HEX="+mp2hexCommand())
outfile.write("
")
outfile.write("IFILOAD="+ifiLoaderCommand())
outfile.write("
")
outfile.write("SERIAL_DEV="+ifiSerialDevice())
outfile.write("
")
outfile.write("READLOG="+ifiReadLogfile())
outfile.write("
")
outfile.write("LIB_PATH="+libPath())
outfile.write("
")
outfile.write("CODE_PATH="+codePath())
outfile.write("
")
outfile.write("INCLUDE_PATH="+includePath())
outfile.write("
")
outfile.write("INCLUDE_PATHW="+includePathWindows())
outfile.write("
")
outfile.write("



")


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("
")
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("
")
outfile.write("############ Targets: ")
outfile.write("
")
outfile.write("default: FrcCode.hex")
outfile.write("
")

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 .c 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'")

hi chris31,

i appreciate your help; however, that didn’t work either. i still get the same error message (the fact that i get a compiler error message tells you that i didn’t have any issues setting that stuff up).

any other thoughts? i doesn’t even make sense that a line 0 would be at fault for a compilation.

What version of MCC are you using? What version of GCC are you using? Also, if you could post just a little bit more of the method you’re using to do this, I might be able to shed some more light.

what was posted was not a Makefile, but a python script that will create a make file. Just cpy all of that, save it as configure.py . move it into your project directory, and in the terminal run python configure.py

if u did that, then please elaborate with what you did exactly

Lines start at 1. The compiler uses “syntax error” (w/o an error number) to mean “I’m confused. I’m giving up.” Line 0 means before it even really starts reading the file. Maybe a permissions issue?

Check line endings, although that should not affect it. Also try running it through cpp18 (the preprocessor) and see if it tosses an error. (It probably won’t but it’s worth a shot.)

Unlike gcc, MCC18 requires separate compiling and linking stages. The linker is mplink.

hi all, thanks for the input.

as far as what version of the compiler i’m using, like i said before, i am using the 2.4 compiler using wine.

the makefile was properly generated using the python script, and like i said the makefile also threw out the same error. if i try to compile by hand without a makefile, then i still get the same error.

the preprocessor doesn’t throw any errors out.

i’m much more familiar with gcc, and being the purist that i am, tend to compile source files into individual object files and then link them anyway, so having a separate compiler and a separate linker is no issue.

i have a feeling this has to do with line endings more than anything else, but how would i fix the line endings on linux in emacs?

The files come with windows line endings from IFI. I would think that emacs at least preserves line endings, although I don’t actually use it.

I got those line 0 errors with wine 0.9.22 that comes with Ubuntu Edgy. When I installed the latest 0.9.29, it works.

Yes, that’s true. There is a known bug with wine 0.9.22.

Which version of WINE are you using, what version of Linux, etc.