Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ Programming ➜ General ➜ More on Makefiles

More on Makefiles

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Robert Powell   Australia  (367 posts)  Bio
Date Mon 28 Nov 2005 09:42 AM (UTC)
Message
Seeing that we have been talking makefiles, i would like to move some of my .c files into there own directories so that there is less clutter in the /src directory.

Now i really know very little about makefiles and don't have the faintest idea on how to make this work. If anyone could give me a few pointers on how to do this based on the standard smaugfuss makefile would be most apprecated.

Thanks in advance.

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 28 Nov 2005 07:42 PM (UTC)

Amended on Mon 28 Nov 2005 08:33 PM (UTC) by Nick Gammon

Message
I'm not the world's biggest expert on Makefiles, but this seems to work. Don't copy and paste from below as you need tabs at the start of most lines, not spaces. However the changes I think I made are in bold, just copy them into your makefile:


CC      = gcc
#PROF    = -p

#Uncomment to compile in Cygwin
#CYGWIN = -DCYGWIN

# Uncomment the two lines below if compiling on a Solaris box
#SOLARIS_FLAG = -Dsun -DSYSV
#SOLARIS_LINK = -lnsl -lsocket

#IMC2 - Comment out to disable IMC2 support
IMC = 1

W_FLAGS = -Wall -Werror -Wshadow -Wformat-security -Wpointer-arith -Wcast-align -Wredundant-decls -Wbad-function-cast

C_FLAGS = -g3 $(W_FLAGS) $(SOLARIS_FLAG) $(PROF)
L_FLAGS = $(PROF) $(SOLARIS_LINK) -lz

C_FILES = act_comm.c act_info.c act_move.c act_obj.c act_wiz.c ban.c boards.c \
          build.c clans.c color.c comm.c comments.c const.c db.c deity.c fight.c \
          handler.c hashstr.c hotboot.c imm_host.c interp.c magic.c makeobjs.c mapout.c mccp.c \
          md5.c misc.c mpxset.c mud_comm.c mud_prog.c planes.c player.c polymorph.c \
          reset.c save.c services.c shops.c skills.c special.c tables.c \
          track.c update.c

ifdef IMC
   C_FILES := imc.c $(C_FILES)
   C_FLAGS := $(C_FLAGS) -DIMC -DIMCSMAUG
endif

O_FILES := $(patsubst %.c,o/%.o,$(C_FILES))

SRC_FILES := $(patsubst %.c,src/%.c,$(C_FILES))

H_FILES = $(wildcard src/*.h)

all:
        $(MAKE) -s smaug

# pull in dependency info for *existing* .o files
-include dependencies.d

ifdef CYGWIN
smaug: $(O_FILES)
        rm -f smaug.exe
        $(CC) -o smaug.exe $(O_FILES) $(L_FLAGS)
        echo "Making dependencies ...";
        $(CC) -MM $(CFLAGS) src/*.c > dependencies.d
        perl -pi -e 's.^([a-z]).o/$$1.g' dependencies.d
        echo "Done compiling mud.";
        chmod g+w smaug.exe
        chmod a+x smaug.exe
        chmod g+w $(O_FILES)

clean:
        rm -f o/*.o smaug.exe *~ src/~*
else
smaug: $(O_FILES)
        rm -f smaug
        $(CC) -o smaug $(O_FILES) $(L_FLAGS)
        echo "Making dependencies ...";
        $(CC) -MM $(CFLAGS) src/*.c > dependencies.d
        perl -pi -e 's.^([a-z]).o/$$1.g' dependencies.d
        echo "Done compiling mud.";
        chmod g+w smaug
        chmod a+x smaug
        chmod g+w $(O_FILES)

clean:
        rm -f o/*.o smaug *~ src/*~
        echo "Making dependencies ...";
        $(CC) -MM $(CFLAGS) src/*.c > dependencies.d
        perl -pi -e 's.^([a-z]).o/$$1.g' dependencies.d
endif

indent:
        indent -ts3 -nut -nsaf -nsai -nsaw -npcs -npsl -ncs -nbc -bls -prs -bap -cbi0 -cli3 -bli0 -l125 -lp -i3 -cdb -c1 -cd1 -sc -pmt $(SRC_FILES)
        indent -ts3 -nut -nsaf -nsai -nsaw -npcs -npsl -ncs -nbc -bls -prs -bap -cbi0 -cli3 -bli0 -l125 -lp -i3 -cdb -c1 -cd1 -sc -pmt $(H_FILES)

indentclean:
        rm src/*.c~ src/*.h~

o/%.o: src/%.c
        echo "  Compiling $@....";
        $(CC) -c $(C_FLAGS) $< -o $@



Basically I put "src/" in front of %.c in the line that associates .o files with .c files.

I also had to change the way it generated the dependency file (which isn't in standard SMAUG makefile anyway).

With these changes, you should be able to make a "src" subdirectory (inside src) and move all the .c and .h files into it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Robert Powell   Australia  (367 posts)  Bio
Date Reply #2 on Tue 29 Nov 2005 12:11 AM (UTC)
Message
Not exactly what i had in mind Nick, I know that i might not have been totally clear on my intentions.

Using your makefile as an example i would like to move say UPDATE.C into a directory off the src directory called update, that compiles the update.c file to update.o which is stored in the o directory off of src.

I know i could do this a number of different ways, multiple makefiles that you call from the main makefile is one way, also below is another way that i worked out i could acheive the desired result, but its way slow because its a full recompile each time.

# make file by Robert Powell
CXX = gcc


# libraries
LIBS = -lm -lcrypt -ldl

# flags
W_FLAGS = -Wall -Wshadow -Wformat-security -Winline -Wpointer-arith -Wcast-align -Wredundant-decls 
CFLAGS = -g2 $(W_FLAGS) $(PROF) -export-dynamic


eldhamud: $(wildcard *.c)
	$(CXX) $(CFLAGS) *.c -c;
	$(CXX) $(CFLAGS) Oasis_Olc/*.c -c;
	mv *.o Object_Files
	$(CXX) -export-dynamic -o eldhamud ./Object_Files/*.o $(LIBS)


clean:
	rm -f *.o eldhamud *~ 
	rm -f Object_Files/*.o 
	rm -f Oasis_Olc/*~
	


I know there has to be an easier method of doing this, and one thats not so hackish as this one above, as sometimes i like to leave stray .c files laying about that i dont want to have compiled with the wildcard method.

Thanks again

Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


11,596 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.