English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 17 August 2023, 21:16   #1
hceline
Registered User
 
Join Date: Nov 2009
Location: Top of the world
Posts: 161
Question about smake Transformation Rules and separate object-directory.

Edit: Never mind, I solved it. I was editing the wrong file. The solution was to add "OBJECTNAME=myassign:my/obj/dir/" to SCOPTIONS, and remove the "$(OBJDIR)" I put in smakefile.

Edit2: I celebrated too early, see next post.

I'm trying to stop my compiles from cluttering the source directory with binaries.
But hit a snag with one smakefile. It started out like this(irrelevant parts removed and filenames changed for brevity):

Code:
OBJS = file1.o file2.o ... file42.o

all: mylibrary.library
...


mylibrary.library: $(OBJS)
    slink with lib:utillib.with with <<
define __ctype=___ctype
libprefix _L_
libfd my_lib.fd
from lib:libent.o lib:libinit.o $(OBJS)
to mylibrary.library
lib lib:sc.lib lib:pools.lib lib:amiga.lib lib:asyncio.lib $(DEBUGLIB)
libversion $(LIBVER)
librevision $(LIBREV)
noicons
maxhunk 51200
sc sd
<

.c.o:
    sc $*.c
And I changed it like this:
Code:
OBJDIR = myassign:my/obj/dir/
BINDIR = myassign:my/bin/dir/

OBJS = $(OBJDIR)file1.o $(OBJDIR)file2.o ... $(OBJDIR)file42.o

all: $(BINDIR)mylibrary.library
...

$(BINDIR)mylibrary.library: $(OBJS)
    slink with lib:utillib.with with <<
define __ctype=___ctype
libprefix _L_
libfd my_lib.fd
from lib:libent.o lib:libinit.o $(OBJS)
to $(BINDIR)mylibrary.library
lib lib:sc.lib lib:pools.lib lib:amiga.lib lib:asyncio.lib $(DEBUGLIB)
libversion $(LIBVER)
librevision $(LIBREV)
noicons
maxhunk 51200
sc sd
<
   
.c.o:
    sc $*.c
After the change it seems the ".c.o:" rule stopped working because "smake all" gives error message:
Code:
SMAKE (line 61): Missing file, target, or action for myassign:my/obj/dir/file1.o
Line 61 is the one saying:
Code:
$(BINDIR)mylibrary.library: $(OBJS)
And I don't know how to fix this, without making 42 new targets like:
Code:
$(objdir)file1.o: file1.c
Is there a way to fix the transformation rule? Or is my approach conceptually wrong?

-Hagbard Celine

Last edited by hceline; 17 August 2023 at 22:30. Reason: Too soon.
hceline is offline  
Old 17 August 2023, 22:29   #2
hceline
Registered User
 
Join Date: Nov 2009
Location: Top of the world
Posts: 161
I just almost got it. Back to original smakefile and added this to SCOPTIONS:
Code:
OBJECTNAME=myassign:my/obj/dir/
Now it compiles, but the linker fails with:
Code:
        slink with lib:utillib.with with temp_smk.tmp
Slink - Version 6.59
Copyright (c) 1988-1995 SAS Institute, Inc.  All Rights Reserved.

Error 426: Cannot find object file1.o

slink failed returncode 140

Last edited by hceline; 17 August 2023 at 22:46. Reason: Part of linker error was missing: added.
hceline is offline  
Old 27 August 2023, 22:55   #3
hceline
Registered User
 
Join Date: Nov 2009
Location: Top of the world
Posts: 161
After trying and failing at several solutions, it seems that this is the only thing that works:
Quote:
Originally Posted by hceline View Post
And I don't know how to fix this, without making 42 new targets like:
Code:
$(objdir)file1.o: file1.c
Which is probably the reason I got no answers to this question.
hceline is offline  
Old 20 September 2023, 14:19   #4
Gilloo
Registered User
 
Join Date: Nov 2010
Location: Grenoble, Isère, Rhône-Alpes, France, Europe, Earth
Posts: 289
look at this (use google translate if you don't understand french)

https://gilles-pelletier-vft.go.yj.f...c_makefile.htm

makefiles will no longer hold any secrets for you
Gilloo is offline  
Old 28 September 2023, 16:18   #5
hceline
Registered User
 
Join Date: Nov 2009
Location: Top of the world
Posts: 161
Thanks for the link. It was a good example. But sadly it was virtually identical to my first attempt. And thus gave the same result.

But I have been thinking abut this, OBJECTNAME in SCOPTIONS works when sc starts slink. So the thing missing is how this is done. I think I must re-read the manual / find an undocumented switch/variable/something.
hceline is offline  
Old 29 September 2023, 09:15   #6
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
You have to use make or use arexx as a workaround:
Use a template and modify this with arexx then execute the modifed smakefile.

Example:
define the objects and the workdir in the smakefile
Code:
.PHONY: all

OBJ = a b c

all:
	rx fe.rexx workdir/ $(OBJ)
	smake -f smakefile.tmp
Define everything else in the template smakefile.sub
Code:
.PHONY: all

OBJ = #OBJ#
SRC = #SRC#
LIBS = LIB:sc.lib lib:scm.lib

all: prog

prog: $(OBJ)
	slink from LIB:c.o $(OBJ) to prog LIB $(LIBS)

#TRG#
and arexx does the expansion and substitution.
fe.rexx
Code:
/* smake support */
ARG dir o

obj = ""
src = ""
trg = ""

DO WHILE LENGTH(o) > 0
  PARSE VAR o a o
  obj = obj || dir || a || ".o" || " "
  src = src || dir || a || ".c" || " "
  trg = trg || dir || a || ".o: " || dir || a || ".c" || '0d'x || '0a'x || '09'x || "sc $(SCOPTS) OBJNAME=$*.o $*.c" || '0d'x || '0a'x
END

OPEN('sfile', "smakefile.sub", 'R')
content = READCH('sfile', 65536)
CALL CLOSE('sfile')

CALL patch(content, "#OBJ#", obj)
CALL patch(content, "#SRC#", src)
CALL patch(content, "#TRG#", trg)

OPEN('sfile', "smakefile.tmp", 'W')
CALL WRITECH('sfile', content)
CALL CLOSE('sfile')

EXIT

patch:
  ARG content, what, repl
  i = INDEX(content, what)
  IF i > 0 THEN
	content = SUBSTR(content, 1, i - 1) || repl || SUBSTR(content, i + LENGTH(what))
  ENDIF
RETURN

Last edited by bebbo; 29 September 2023 at 10:16.
bebbo is offline  
Old 10 October 2023, 15:04   #7
hceline
Registered User
 
Join Date: Nov 2009
Location: Top of the world
Posts: 161
Thank you for a working solution. In the meantime, I have come to the realization that the correct approach would be to generate the targets in question with a dependency-scanner.
So I think I'd rather try to do that.
hceline is offline  
Old 06 November 2023, 10:14   #8
hceline
Registered User
 
Join Date: Nov 2009
Location: Top of the world
Posts: 161
An update, in case someone has the same issue and finds this thread.
I could not find a dependency-scanner that accepted ".o" files on command-line and worked with any codebase.
So I ported and modified latest makedepend from Xorg:
http://aminet.net/package/dev/c/makedepend_AmiMod

WARNING (which was unfortunately missing in original upload):
The stack usage is dependent on organization of the files it is parsing. The
binary is compiled without stackcheck/stackextend, and will crash hard if it
runs out of stack.

Final Edit(hopefully): I feel very stupid. I had several versions of the script, only one working. And used one of the non-working ones when making this post. I have now replaced it with the working version. I had also forgotten that "modified" was needed on sc commandline for this to work.

Also, just before I realized I should use a dependency-scanner, I found a another working solution:

Edit:
I made a brainfart when first posting this. it will only work if you use
Code:
OBJECTNAME=myassign:my/obj/dir/
in SCOPTIONS or equivalent command line (see smakefile example below).
It will not work with translation rule
Code:
.c.o:
    sc $*.c objname $@
as i first posted.


Change the link command and transformation rule in smakefile like this:
Code:
OBJDIR = myassign:my/obj/dir/
BINDIR = myassign:my/bin/dir/

OBJS = file1.o file2.o ... file42.o

all: $(BINDIR)mylibrary.library
...

$(BINDIR)mylibrary.library: $(OBJS)
    cdlink $(OBJDIR) with lib:utillib.with with <<
define __ctype=___ctype
libprefix _L_
libfd my_lib.fd
from lib:libent.o lib:libinit.o $(OBJS)
to $(BINDIR)mylibrary.library
lib lib:sc.lib lib:pools.lib lib:amiga.lib lib:asyncio.lib $(DEBUGLIB)
libversion $(LIBVER)
librevision $(LIBREV)
noicons
maxhunk 51200
sc sd
<

.c.o:
    sc $*.c modified objname myassign:my/obj/dir/
And place the following script in sc:c/cdlink (remember to set S an E protection bits).
Code:
.key OBJDIR/A,ARGUMENTS/F

; $VER: cdlink 1.1 (10.10.2023)
; Break smake no ChangeDirectory rule and link directly from objdir

set echo on
FailAt 21
Set ORGDIR `cd`
Set LINKFILE temp_smk.tmp
CD <OBJDIR>
IF EXISTS $ORGDIR/$LINKFILE
MakeLink $LINKFILE $ORGDIR/$LINKFILE
EndIF
slink <ARGUMENTS>
IF EXISTS $LINKFILE
Delete $LINKFILE
EndIF
FailAt 10

Last edited by hceline; 06 November 2023 at 15:01. Reason: Multi Brainfart
hceline is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile directory, work directory and relative paths phx Coders. Asm / Hardware 13 25 July 2022 15:31
Polygon transformation problem TCH Coders. General 4 07 March 2020 15:20
Rules BippyM project.Sprites 3 20 April 2005 09:59
Rules RCK project.WHDLoad 0 02 October 2004 14:45

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:51.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09657 seconds with 15 queries