Skip to content
Snippets Groups Projects
Commit d8734cfb authored by Federico's avatar Federico
Browse files

Improved Makefile path referencing to always use relative paths, as using...

Improved Makefile path referencing to always use relative paths, as using absolute ones fails when the absolute path contains spaces.
parent b0b44f6c
Branches
Tags
Loading
##
## Makefile for Miosix embedded OS
##
MAKEFILE_VERSION := 1.03
## Path to kernel directory
MAKEFILE_VERSION := 1.04
## Path to kernel directory (edited by init_project_out_of_git_repo.pl)
KPATH := miosix
## Path to config directory
CONFPATH := $(realpath $(KPATH))
## Path to config directory (edited by init_project_out_of_git_repo.pl)
CONFPATH := $(KPATH)
include $(CONFPATH)/config/Makefile.inc
##
......@@ -59,10 +59,16 @@ program:
$(PROGRAM_CMDLINE)
all-recursive:
$(foreach i,$(SUBDIRS),$(MAKE) -C $(i) CONFPATH="$(CONFPATH)" || exit 1;)
$(foreach i,$(SUBDIRS),$(MAKE) -C $(i) \
KPATH=$(shell perl $(KPATH)/_tools/relpath.pl $(i) $(KPATH)) \
CONFPATH=$(shell perl $(KPATH)/_tools/relpath.pl $(i) $(CONFPATH)) \
|| exit 1;)
clean-recursive:
$(foreach i,$(SUBDIRS),$(MAKE) -C $(i) CONFPATH="$(CONFPATH)" clean || exit 1;)
$(foreach i,$(SUBDIRS),$(MAKE) -C $(i) \
KPATH=$(shell perl $(KPATH)/_tools/relpath.pl $(i) $(KPATH)) \
CONFPATH=$(shell perl $(KPATH)/_tools/relpath.pl $(i) $(CONFPATH)) \
clean || exit 1;)
clean-topdir:
-rm -f $(OBJ) main.elf main.hex main.bin main.map $(OBJ:.o=.d)
......
......@@ -2,10 +2,8 @@
## Makefile for Miosix embedded OS
## This makefile builds the whole kernel
##
MAKEFILE_VERSION := 1.03
## Path to kernel directory
KPATH := .
## CONFPATH is forwarded by the parent Makefile
MAKEFILE_VERSION := 1.04
## KPATH and CONFPATH are forwarded by the parent Makefile
include $(CONFPATH)/config/Makefile.inc
## List of all Miosix OS source files that have no special requirements
......
Changelog for Miosix np embedded OS
- Improved Makefile path referencing to always use relative paths, as using
absolute ones fails when the absolute path contains spaces. This proved to
be impossible with makefiles alone and required to add a small perl script
- Added versioning to miosix_settings.h and board_settings.h to prevent
misconfiguration when those files are updated.
- Moved board_settings.h in the config directory to allow out of git tree
......
##
## Makefile for Miosix embedded OS
##
MAKEFILE_VERSION := 1.03
## Path to kernel directory
MAKEFILE_VERSION := 1.04
## Path to kernel directory (edited by init_project_out_of_git_repo.pl)
KPATH := miosix
## Path to config directory
CONFPATH := $(realpath $(KPATH))
## Path to config directory (edited by init_project_out_of_git_repo.pl)
CONFPATH := $(KPATH)
include $(CONFPATH)/config/Makefile.inc
##
......@@ -59,10 +59,16 @@ program:
$(PROGRAM_CMDLINE)
all-recursive:
$(foreach i,$(SUBDIRS),$(MAKE) -C $(i) CONFPATH="$(CONFPATH)" || exit 1;)
$(foreach i,$(SUBDIRS),$(MAKE) -C $(i) \
KPATH=$(shell perl $(KPATH)/_tools/relpath.pl $(i) $(KPATH)) \
CONFPATH=$(shell perl $(KPATH)/_tools/relpath.pl $(i) $(CONFPATH)) \
|| exit 1;)
clean-recursive:
$(foreach i,$(SUBDIRS),$(MAKE) -C $(i) CONFPATH="$(CONFPATH)" clean || exit 1;)
$(foreach i,$(SUBDIRS),$(MAKE) -C $(i) \
KPATH=$(shell perl $(KPATH)/_tools/relpath.pl $(i) $(KPATH)) \
CONFPATH=$(shell perl $(KPATH)/_tools/relpath.pl $(i) $(CONFPATH)) \
clean || exit 1;)
clean-topdir:
-rm -f $(OBJ) main.elf main.hex main.bin main.map $(OBJ:.o=.d)
......
......@@ -50,7 +50,7 @@ sub copy_and_fixup_makefile
while(<$in>)
{
s/^KPATH := miosix$/KPATH := $relpath\/miosix/;
s/^CONFPATH := \$\(realpath \$\(KPATH\)\)$/CONFPATH := \$\(realpath \.\)/;
s/^CONFPATH := \$\(KPATH\)$/CONFPATH := \./;
print $out "$_";
}
close($in);
......
#!/usr/bin/perl
# This script is used by the makefiles to convert a relative path from
# a source directory to a relative path to a target directory when recursively
# calling make. Unfortunately, GNU make has no such feature built in. It has,
# however, a way to convert a relative path to an absolute one, that can be
# passed to recursive makefiles while still referencing the same directory,
# but dealing with absolute paths and makefiles is totally useless. Why?
# Because an absolute path may easily end up containing a space character in
# some of the directories, and GNU make fails *very* badly when dealing with
# spaces in filenames. Using relative paths instead only requires that the
# paths between directories containing source files are whitespace free, and
# noth *all* the directory names up to the root one.
use Cwd qw(abs_path);
use File::Spec;
die "Use: perl relpath.pl from to\n" unless($#ARGV+1==2);
my $from=abs_path($ARGV[0]);
my $to=abs_path($ARGV[1]);
my $relpath=File::Spec->abs2rel($to,$from);
print "$relpath";
#print STDERR "========== from='$from' to='$to' relpath='$relpath'\n";
......@@ -265,7 +265,7 @@ endif
## a new board or porting Miosix to a new architecture ##
############################################################################
ifneq ($(MAKEFILE_VERSION),1.03)
ifneq ($(MAKEFILE_VERSION),1.04)
$(info You are using an incompatible makefile. Make sure it matches \
the one distributed with the current version of the kernel)
$(error Error)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment