Оберон-клуб «ВЄДАsoft»

Твердыня модульных языков
Текущее время: 11 июл 2020, 10:16

Часовой пояс: UTC + 2 часа




Начать новую тему Ответить на тему  [ Сообщений: 3 ] 
Автор Сообщение
 Заголовок сообщения: use makefiles
СообщениеДобавлено: 31 авг 2013, 17:43 
Не в сети

Сообщения: 104
Makefiles can be used on linux and windows and they are powerful
makefiles are good because they only compile files that have changed, this saves a lot of time
here is mine for xdev/zxdev

Цитата:
all: $(targetname).tap

OBJECTS = Globals.lib MapSquares.lib Spiral.lib Rsrc.lib path.lib UnitFunctions.lib Graphics.lib line.lib Helper.lib Dungeon.lib EnemyAI.lib


$(targetname).tap: $(targetname).bin
Bin/bin2tap -b -a 25000 -c 24999 -r 25000 -o $(targetname).tap $(targetname).bin

fuse-gtk $(targetname).tap
$(targetname).bin: $(targetname).ihx
Bin/hex2bin $(targetname).ihx

$(targetname).ihx: $(targetname).c
/root/sdcc/bin/sdcc $(targetname).c -mz80 --code-loc 25000 --data-loc 49000 --no-std-crt0 --opt-code-size --funsigned-char --disable-warning 126 -I Lib -I Obj Lib/z80/Basic.lib Lib/z80/XDev.lib $(OBJECTS)

$(targetname).c :$(OBJECTS) $(targetname).mod
"/root/ofront/linux2/bin/ofront" /root/Dropbox/oberon/$(targetname).mod -m

%.lib: %.rel
/root/sdcc/bin/sdcclib $@ $<

%.rel:%.c
/root/sdcc/bin/sdcc -mz80 -c $< -I Lib

%.c %.sym:%.mod
"/root/ofront/linux2/bin/ofront" /root/Dropbox/oberon/$< -e -s
clean:
rm *.lib *.rel *.c *.h *.ihx *.bin


it looks complicated but its not

lets start at the bottom:
Цитата:
clean:
rm *.lib *.rel *.c *.h *.ihx *.bin

when you type in 'make clean' this will be executed
rm means remove
*.lib means all files that end in .lib
this just cleans up all the files you dont need, so you can recompile everything later.

Цитата:
%.c %.sym:%.mod
"/root/ofront/linux2/bin/ofront" /root/Dropbox/oberon/$< -e -s


Цитата:
%.c %.sym:%.mod


this means that you want a file that ends in .c and one that ends in .sym
then there is the colon :
then %.mod means that you need files that begin with .mod to get the files that end in .c
the next line needs a tab
this tells the makefile how to get the .c files

Цитата:
"/root/ofront/linux2/bin/ofront" /root/Dropbox/oberon/$< -e -s


$< is the name of the file on the right of the colon, something.mod

so if I type in 'make' this will happen:
"/root/ofront/linux2/bin/ofront" /root/Dropbox/oberon/hi.mod -e -s
"/root/ofront/linux2/bin/ofront" /root/Dropbox/oberon/basic.mod -e -s
"/root/ofront/linux2/bin/ofront" /root/Dropbox/oberon/line.mod -e -s
"/root/ofront/linux2/bin/ofront" /root/Dropbox/oberon/path.mod -e -s

makefiles only compile files that have changed remember,
if basic.mod is newer than basic.c it will compile basic.mod again,

because you put this in the makefile
Цитата:
%.c %.sym:%.mod


it will compare the file dates of the files ending in .c and .sym to see if they are older than the .mod files and compile the .mod files if they are newer.

the next 2 lines are similar:
Цитата:

%.lib: %.rel
/root/sdcc/bin/sdcclib $@ $<

%.rel:%.c
/root/sdcc/bin/sdcc -mz80 -c $< -I Lib


they tell the makefile that to get .rel files you need a .c file
and underneath is the command to get it
$< gives the name of all the .c files to the makefile

Цитата:
%.lib: %.rel
/root/sdcc/bin/sdcclib $@ $<

this says to get a .lib file you need a .rel file
$< is the .rel file
and $@ is the .lib file
the makefile will execute this command
/root/sdcc/bin/sdcclib basic.lib basic.rel
if basic .rel is newer than basic.lib

but this will happen to every .rel file in the same folder as the makefile

Цитата:
$(targetname).c :$(OBJECTS) $(targetname).mod
"/root/ofront/linux2/bin/ofront" /root/Dropbox/oberon/$(targetname).mod -m

$(targetname) is a word that is passed to the makefile

if I type in
make targetname=basic

then the line will look like this:
basic.c :$(OBJECTS) basic.mod
"/root/ofront/linux2/bin/ofront" /root/Dropbox/oberon/basic.mod -m

$(OBJECTS) is a list of all the files I am using

Цитата:
OBJECTS = Globals.lib MapSquares.lib Spiral.lib Rsrc.lib path.lib UnitFunctions.lib Graphics.lib line.lib Helper.lib Dungeon.lib EnemyAI.lib


so really it looks like this
Цитата:
basic.c :Globals.lib MapSquares.lib Spiral.lib Rsrc.lib path.lib UnitFunctions.lib Graphics.lib line.lib Helper.lib Dungeon.lib EnemyAI.lib basic.mod
"/root/ofront/linux2/bin/ofront" /root/Dropbox/oberon/basic.mod -m



this tells the makefile that I want basic.c
but before trying to get basic.c for me I need basic.mod and all those lib files

the other line we looked at tell the makefile how to get lib files
Цитата:
%.lib: %.rel
/root/sdcc/bin/sdcclib $@ $<

so the makefile will compile lib files first because they are needed by this line:
Цитата:
basic.c :Globals.lib MapSquares.lib Spiral.lib Rsrc.lib path.lib UnitFunctions.lib Graphics.lib line.lib Helper.lib Dungeon.lib EnemyAI.lib basic.mod
"/root/ofront/linux2/bin/ofront" /root/Dropbox/oberon/basic.mod -m


Цитата:
$(targetname).ihx: $(targetname).c
/root/sdcc/bin/sdcc $(targetname).c -mz80 --code-loc 25000 --data-loc 49000 --no-std-crt0 --opt-code-size --funsigned-char --disable-warning 126 -I Lib -I Obj Lib/z80/Basic.lib Lib/z80/XDev.lib $(OBJECTS)


this line means we want basic.ihx
we need basic.c to get it
below that is the command to get basic.ihx

notice I put the libs in the right order so they will compile:

OBJECTS = Globals.lib MapSquares.lib Spiral.lib Rsrc.lib path.lib UnitFunctions.lib Graphics.lib line.lib Helper.lib Dungeon.lib EnemyAI.lib

Globals doesnt import anything so it goes first, Mapsquares imports Globals so it has to go after Globals etc.


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: use makefiles
СообщениеДобавлено: 01 сен 2013, 22:18 
Не в сети
Администратор
Аватара пользователя

Сообщения: 269
Откуда: Россия
slenkar писал(а):
Makefiles can be used on linux and windows and they are powerful
makefiles are good because they only compile files that have changed, this saves a lot of time
Yes, Makefiles are good,of course. In Linux "make" is an ordinary thing, but Windows has no "make" as standard utility. It is necessary in Windows to install http://gnuwin32.sourceforge.net/packages/make.htm or other. It makes quick start of XDev more difficult for newbies.


Вернуться к началу
 Профиль  
Ответить с цитатой  
 Заголовок сообщения: Re: use makefiles
СообщениеДобавлено: 13 сен 2013, 18:47 
Не в сети
Аватара пользователя

Сообщения: 995
Откуда: Днепропетровская обл.
Undoubtedly makefiles are especially good if used console-based development tools like GCC, Ofront or GPCP (btw, Java world has something - ant named. This tool is very similar to make). Using makefiles is a clean Unix-way, and I would use make whenever I need to build the project with a lot of modules by a console-based tool.

I must explain why XDev does not use makefiles. Firstly, it proposes not Unix-way, and Oberon-way, that looks some different.

Secondly, it's yet GUI environment, based on BlackBox, and don't proposes to work in command-line.

Thirdly, XDev examples are simple (one module usually). What I propose as XDev-way to build multi-module projects? Only one thing: use smart scripts compile.bat and build.bat. For example:
Код: "WINBATCH"
@IF NOT EXIST abc.rel sdcc -c abc.c -mz80 ...
And this script will compile only modules with non-existing .rel file. You usually work on one module, and need to recompile only it, and rebuild program with one changed modules. No problems: F11 - compile.bat recompiles this one module (and recreates its .rel). If you press F12 and start rebuilding - build.bat recompiles the same module, and may stay other modules, but recompile only main module - to have executable application. If a .rel not exists, build.bat recompiles all needed sources automatically. And we have all we need, although without make.

And, finally, I had a hard time imagine a universal makefile. In my opinion, it has to be adapted every time for a new project.

Yes, still exists question how to design scripts to rebuild XDev libraries - to recompile only changed sources. But the libraries compile not so often, and I use full rebuilding for a higher guarantee the correct result. Because adding modules partially to a library may lead to some problems, I have met before.


Вернуться к началу
 Профиль  
Ответить с цитатой  
Показать сообщения за:  Поле сортировки  
Начать новую тему Ответить на тему  [ Сообщений: 3 ] 

Часовой пояс: UTC + 2 часа


Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2


Вы не можете начинать темы
Вы не можете отвечать на сообщения
Вы не можете редактировать свои сообщения
Вы не можете удалять свои сообщения
Вы не можете добавлять вложения

Найти:
Перейти:  
Создано на основе phpBB® Forum Software © phpBB Group
© VEDAsoft Oberon Club