I created this makefile almost two years ago in Windows 7:
SRC_DIRS = ./src/oasis ./src/oasis/commands/basic ./src/oasis/commands/immortal ./src/oasis/commands/socials ./src/oasis/util
COMPILE_FLAGS = -d ./classes
DOC_FLAGS = -quiet -private -d ./doc -sourcepath ./src -subpackages oasis -linkoffline http://java.sun.com/j2se/1.4.2/docs/api .
all:
#echo Compiling source code...
#javac $(COMPILE_FLAGS) $(foreach dir,$(SRC_DIRS),$(dir)/*.java)
#echo Creating javadocs...
#javadoc $(DOC_FLAGS)
#echo Done.
class:
#echo Compiling source code...
#javac $(COMPILE_FLAGS) $(foreach dir,$(SRC_DIRS),$(dir)/*.java)
#echo Done.
docs:
#echo Creating javadocs...
#javadoc $(DOC_FLAGS)
#echo Done.
clean:
#echo Removing classes...
#rmdir classes /q /s
#mkdir classes
#echo Removing javadocs...
#rmdir doc /q /s
#mkdir doc
#echo Done.
I used to navigate to its folder with cmd.exe, and then type "make all" or "make class" or whatever... and it would work! Now I'm returning to this project almost 2 years later, on a new computer (also Windows 7) and the "make" command isn't recognized. I don't remember installing any special software to use makefiles in Windows. Why won't it work anymore?
Related
I'm trying to create a Makefile that works on both Windows and Linux. Running make clean generates the following error:
process_begin: CreateProcess(NULL, rmdir /s /q D:\Documents\Programming\project\bin, ...) failed.
make: Makefile:13: pipe: No such file or directory
process_begin: CreateProcess(NULL, rmdir /s /q D:\Documents\Programming\project\obj, ...) failed.
make: Makefile:15: pipe: No such file or directory
The relevant parts of the Makefile are:
BIN_DIR=bin
OBJ_DIR=obj
SRC_DIR=src
ifeq ($(OS),Windows_NT)
RMDIR=$(shell rmdir /s /q $(subst /,\,$(abspath $1)))
else
RMDIR=$(shell rm -rf $(abspath $1))
endif
clean:
#echo "RM $(BIN_DIR)"
#$(call RMDIR,$(BIN_DIR))
#echo "RM $(OBJ_DIR)"
#$(call RMDIR,$(OBJ_DIR))
#echo "Done!"
.PHONY: clean
The project structure looks like this:
├─bin
├─obj
├─src
└─Makefile
I'm trying to make a modified version of the FlySky FS-i6 firmware. After a bit of searching, I found someone who decompiled the source code here.
I'm trying to compile using arm-none-eabi, which I already have installed from the Arduino IDE.
Here's a batch file I made to compile the files, which are just a bunch of .c and .h files under several directories, but I have no clue what arguments I'm supposed to be giving the arm-none-eabi-gcc command...
#echo off
set EABI_PATH="%LocalAppData%\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1\bin"
#RD /S /Q temp
mkdir temp
for /D %%d in (*) do (
echo ---- Compiling Directory: %%d
rem C Files:
for %%f in (%%d/*.c) do (
"%EABI_PATH%/arm-none-eabi-gcc" -c -mcpu=cortex-m0plus -g "%%d/%%f" -o "temp/%%~nf.o" -mthumb -g3
)
rem Header Files:
rem for %%f in (%%d/*.h) do (
rem "%EABI_PATH%/arm-none-eabi-gcc" -c -mcpu=cortex-m0plus -g "%%d/%%f" -o "temp/%%~nf.o" -mthumb -g3
rem )
)
I've searched everywhere, but I can't find any tutorials or anything about how to use the tool. All I want to do is compile the files to a firmware.hex file, you'd think it would just be a simple one-liner...
I have a makefile as follows.. At the first line that says windows.. Then on that same line, I try to set the variable to windows and jmp to $(WinDIR)/$(WinOUT)
How can I do that?
windows: ObjDIR=Windows $(WinDIR)/$(WinOUT)
#echo
#echo "Finished Making windows.."
clean:
#echo " Cleaning Build Files."
#rm -rf $(BinDIR) $(ObjDIR)
$(WinDIR)/$(WinOUT): $(ObjFiles)
#echo
#echo "Linking Object Files.."
Um...
windows: ObjDIR=Windows
windows: $(WinDIR)/$(WinOUT)
#echo
#echo "Finished Making windows.."
But I'm not sure you understand how Make works. It won't "jump to" $(WinDIR)/$(WinOUT), it will -- perhaps -- execute the $(WinDIR)/$(WinOUT) rule first.
I write a .bat to automate generating and compiling a cmake project. The batch file will
optional rmdir build
mkdir build if not exist
cd build
cmake .. generate a nmake project from upper folder
nmake compile project
the source:
#ECHO OFF
set "OpenCV_LIB=C:\Program Files (x86)\OpenCV2.1"
echo !! OpenCV Library: [ %OpenCV_LIB% ]
IF NOT EXIST "%OpenCV_LIB%" (
echo Can't find OpenCV Library, please change OpenCV_LIB setting
GOTO END
)
if %PROCESSOR_ARCHITECTURE%==x86 set BUILD_ARCH=x86
if %PROCESSOR_ARCHITECTURE%==AMD64 set BUILD_ARCH=x86_amd64
if %PROCESSOR_ARCHITECTURE%==IA64 set BUILD_ARCH=x86_IPF
echo !! Target architecture [ %BUILD_ARCH% ]
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" %BUILD_ARCH%
cd "sikuli-script"
set /p answer=Do you want to make clean first? (Y/N):
if %answer% == Y ( IF EXIST build rmdir /s /q build )
if %answer% == y ( IF EXIST build rmdir /s /q build )
IF NOT EXIST build mkdir build
cd build
IF NOT EXIST CMakeCache.txt ( cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE=Release -D "OpenCV_DIR=%OpenCV_LIB%" .. )
nmake
:END
pause
After i run this .bat over and over, i notice that cd build failed sometimes, so i change my code to test it:
#ECHO ON
set /p answer=Do you want to make clean first? (Y/N):
if %answer% == Y ( IF EXIST build rmdir /s /q build )
if %answer% == y ( IF EXIST build rmdir /s /q build )
:DO_MKDIR_CD
IF NOT EXIST build mkdir build
cd build
if errorlevel 1 (
pause
GOTO DO_MKDIR_CD
)
It comes out the error happens every time choose to clean up build, even the build is at small size (e.g. after interrupted compiling, size 3.08 MB, 183 files, 67 dirs).
!! OpenCV Library: [ C:\Program Files (x86)\OpenCV2.1 ]
!! Target architecture [ x86_amd64 ]
Setting environment for using Microsoft Visual Studio 2010 x64 cross tools.
D:\repo\sikuli>cd "sikuli-script"
D:\repo\sikuli\sikuli-script>set /p answer=Do you want to make clean first? (Y/N):
Do you want to make clean first? (Y/N):y
D:\repo\sikuli\sikuli-script>if y == Y (IF EXIST build rmdir /s /q build )
D:\repo\sikuli\sikuli-script>if y == y (IF EXIST build rmdir /s /q build )
D:\repo\sikuli\sikuli-script>IF NOT EXIST build mkdir build
D:\repo\sikuli\sikuli-script>cd build
Access is denied.
D:\repo\sikuli\sikuli-script>if errorlevel 1 (
pause
GOTO DO_MKDIR_CD
)
Press any key to continue . . .
So every time after remove and recreate build, the cd build fails, then cmake start messing up my source tree.
The error check and loop trying could fix this problem, but why is the file system not stable? or am i writing it in a wrong way?
That build directory check:
IF NOT EXIST build mkdir build
Will create the directory if both directory and file named "build" are not exist.
One way to check a directoy existence is:
if exist build\nul echo directory exist
If you want to make sure a directory exist use:
if not exist build\nul mkdir build
or better:
if not exist build\nul (
mkdir build
if not exist build\nul (
echo mkdir failed
goto :eof
)
)
I'm learning makefiles and I'm trying to figure out how to reuse a rule. Right now I have the following:
CPP = cl
CPPFLAGS = /Od /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /ZI /TP /errorReport:prompt
.SUFFIXES: .exe .cpp
Exercise35.exe:
$(CPP) Exercise35.cpp $(CPPFLAGS)
debug:
$(CPP) Exercise35.cpp $(CPPFLAGS) /D "_DEBUG"
It seems bad that the debug rule essentially repeats the Exercise35 rule with an extra command-line parameter. Is there a better way?
Recursive make, and append your debugging flag to CPPFLAGS.
debug:
$(MAKE) CPPFLAGS="$(CPPFLAGS) /D _DBEBUG" Exercise35.exe
You should check out the following properties of the make and look at the sample below:
$# - means the name of the current target file, in this case it corresponds to the value of APP.
$< - means a single file that is newer than the target on which the target is dependant.
$? - means a list of files newer than the current target on which the target is dependant.
.SUFFIXES: .cpp.exe
CPP = cl
EXTRAFLAGS =
CPPFLAGS = /Od /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /nologo /ZI /TP /errorReport:prompt
FILES = Exercise35
APP = Exercise35.exe
.cpp.exe:
$(CPP) $(EXTRAFLAGS) $(CPPFLAGS) /c $<
all : $(APP)
$(APP) : $(FILES)
$(CPP) $(EXTRAFLAGS) $(CPPFLAGS) $# $(FILES)
clobber : clean mrproper
clean:
del $(FILES)
mrproper:
del $(APP)
I got this from my old makefile template, notice that the make will appear 'intelligent' and flexible as you can override the flag specifically for debugging/release within the one make file by executing like this
make EXTRAFLAGS="/D _DDEBUG"
This will pass in the extra define into the makefile to include the _DDEBUG macro, if you wish to build a release, leave out the EXTRAFLAGS on the command line.
Edit:
As per Mike's point-out, I thought it would be useful to include the extra rules so that you can clean the directory with exe's and object code lying around...This was my original template makefile from AIX (which I've used under Linux also...) Thanks Mike for the heads up!
Hope this helps,
Best regards,
Tom.
G'day,
I'd be more inclined to make the debug option a macro within the Makefile.
CPP = cl
CPPFLAGS = /Od /D "WIN32" /D "_CONSOLE" /D \
"_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 \
/MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 \
/nologo /c /ZI /TP /errorReport:prompt
#DEBUG = /D "_DEBUG"
DEBUG =
.SUFFIXES: .exe .cpp
Exercise35.exe:
${CPP} Exercise35.cpp ${CPPFLAGS} ${DEBUG}
and then comment out the version of the DEBUG macro that you don't want to use.
BTW It's better to refer to Makefile macros using ${} rather than $() as round brackets are used for object substitution into archives and curly brackets aren't.
Edit: If you're learning make and makefiles then I'd highly recommend having a read of the first few chapters of "Managing Projects with GNU Make". It'll help you get your head around some non-intuitive aspects of the behaviour of make, esp. it's backwards-chaining behaviour.
If you can find a copy of the small first edition which isn't so gmake specific then even better. It's explanation is much better IMHO.
Edit 2: Here's a link to the Amazon site for the first edition of the book simply called "Managing Projects with Make". As I said above, great description of why make behaves as it does.
HTH
cheers,