MakeFile Set Variable at Runtime - makefile

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.

Related

GNU Make: "pipe: No such file or directory" error

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

How to use arm-none-eabi with multiple files?

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...

What is the equivalent of mkdir -p on Windows 10?

I've been unable to find help files on Windows for things like MD, mkdir or new-item. Doing update-help just throws errors.
How do I do mkdir -p on Windows 10 in Command Prompt?
I want to create a directory even if that directory already exists.
mkdir of Windows 10 does not support -p or /p or an equivalent flag.
If you want realize the -p functionality according to Unix operating systems you can do that in one line as follows:
set MKDIR_DIR=D:\XYZ\123\ABC && if not exist %MKDIR_DIR% mkdir %MKDIR_DIR%
Replace D:\XYZ\123\ABC with the desired directory.
Use mkdir /? to get information on the command. -p is not a flag in Windows, parent/intermediate directories will be created if command extensions are turned on.
See this Microsoft documentation for more information.
Since mkdir in Windows 10 (even with command extensions enabled) does not the job, here is the content of my mkdir.bat that DOES it for a %path% at a %drive% :)
#ECHO OFF
SETLOCAL enableextensions
SETLOCAL enabledelayedexpansion
REM ## Create directory structure levelwise since there is nothing like "mkdir -p"
REM ## substitute "\" with ";"
SET "pathParts=%path:\=;%"
REM ## iterate over a list of the tokens between " ", ",", ";" or "="
SET pathToMake=%drive%
FOR %%d IN (%pathParts::= %) DO (
SET pathToMake=!pathToMake!\%%d
ECHO !pathToMake!
IF NOT EXIST !pathToMake! MKDIR !pathToMake!
)
Just call it like that:
D:\>SET drive=D:
D:\>SET path=XYZ\123\ABC
D:\>mkdir.bat
D:\XYZ
D:\XYZ\123
D:\XYZ\123\ABC
And et voilà: D:\XYZ\123\ABC exists :)
There is very easy solution in windows. -p is not required at all.
If you want to create nested folders then write like below:
mkdir \Taxes\Property\Current
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/mkdir
On Windows 11 Pro using bash this command did the job for me:
mkdir.exe -p folder/subFolder
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/mkdir

Makefile no longer works (Windows)

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?

Reuse makefile rule

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,

Resources