Makefile

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
berk
Member
Posts: 37
Joined: Wed Dec 24, 2014 9:46 am

Makefile

Post by berk »

Hello,

it seems it is not possible to use Makefile. I have created simple test program:

Code: Select all

#include <stdio.h>

int main(void) {
        printf("Test\n");
        return 0;
}
If I use zcc +zx -otest -create-app test.c -lndos all works Well

But if I use following Makefile

Code: Select all

CFLAGS = +zx -c -o $@
CC = zcc

all: test.o 
        $(CC) +zx -lndos -o$@ -create-app test.o 

test.o: test.c
I get error:

Code: Select all

C:\Users\jaroslav_b\Documents\Projekty\Projects_Private\ZX Spectrum\Dev\Test>make -f Makefile.z88dk
zcc +zx -lndos -oall -create-app test.o
copy test.o C:/Users/JAROSL~1/AppData/Local/Temp\sevo_.o
        1 file(s) copied.
copy C:\z88dk\lib\config\..\..\\lib\spec_crt0.opt C:/Users/JAROSL~1/AppData/Local/Temp\sevo_1.opt
        1 file(s) copied.
copy C:/Users/JAROSL~1/AppData/Local/Temp\sevo_1.opt C:/Users/JAROSL~1/AppData/Local/Temp\sevo_1.asm
        1 file(s) copied.
Filetype "test.o" unrecognized
make: *** [all] Error 1
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

I can see the problem at line 813 of zcc.c. The default case was made to abort so that errors generated later on for unknown file types would not be so cryptic as noted in another bug report. The fix is the get_filetype_by_suffix() function should have a *.o case for object files added. I'll fix this later this evening before the nightly build but just in case dom has a go, I'll leave this note here :)

The other thing with makefiles is you probably have to use the -preserve flag when building the *.o files. The reason is zcc creates a "zcc_opts.def" file that communicates options it finds in c source to the crt. The -preserve flag makes sure the zcc invocations for object files add to that file rather than delete the file on each run. Then another question is when do you erase that zcc_opts.def file? For classic c lib builds, it would have to be during a make clean and you'd want to do a make clean if you got strange errors like printf not working.
berk
Member
Posts: 37
Joined: Wed Dec 24, 2014 9:46 am

Post by berk »

Thank you for fixing and for mentioning of other pitfalls :-)

I didnt know about -preserve flag
Yes, I will delete zcc_opts.def in clean target.

So I will try it tomorrow.
User avatar
dom
Well known member
Posts: 2091
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

I don't think I'm going to get a chance to fix this this evening so go for it Alvin.

As a note regarding zcc_opt.def, all of the pragmas can be passed in on the command line so you don't need -preserve.

-pragma-define Define the option in zcc_opt.def

From the headers:

#pragma output XYZ -> -pragma-define=XYZ on the command line.

The most common ones will be:

-pragma-define=ANSIstdio
-pragma-define=NEED1bitsound
-pragma-define=graphics

Which enable those features in the crt0

For floating point you'll need to add:

-pragma-need=floatpack

I think harmonising and documenting them should go on my todo list.
berk
Member
Posts: 37
Joined: Wed Dec 24, 2014 9:46 am

Post by berk »

Ok, I dont hurry. If you need more time for analysing and fixing you have it.
For me it is important that problem is known and somebody is working about it.

Thank you.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

It should be fixed in the June 1 build.
berk
Member
Posts: 37
Joined: Wed Dec 24, 2014 9:46 am

Post by berk »

Well Done! Works well.

Thank you
Post Reply