Thread: Makefile help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Makefile help


    Hi,

    I've got the following Makefile:

    Code:
    CFLAGS = -g -O9 -Wall -pedantic 	# for Linux and other gcc systems
    OP=$(CFLAGS)  
    CC=cc	#for Linux
    
    # compilation rule for general cases
    .o :
    	$(CC) $(OP) -o $@ $? -lm
    .c.o:
    	$(CC) -c $(OP) $<     
    
    SWEOBJ = swedate.o swehouse.o swejpl.o swemmoon.o swemplan.o swepcalc.o sweph.o\
    	swepdate.o swephlib.o swecl.o swehel.o
    
    swetest: swetest.o libswe.a
    	$(CC) $(OP) -o swetest swetest.o -L. -lswe -lm
    
    swemini: swemini.o libswe.a
    	$(CC) $(OP) -o swemini swemini.o -L. -lswe -lm
    
    libswe.a: $(SWEOBJ)
    	ar r libswe.a	$(SWEOBJ)
    
    libswe.so: $(SWEOBJ)
    	$(CC) -shared -o libswe.so $(SWEOBJ)
    
    clean:
    	rm -f *.o swetest libswe*
    	
    ###
    swecl.o: swejpl.h sweodef.h swephexp.h swedll.h sweph.h swephlib.h
    sweclips.o: sweodef.h swephexp.h swedll.h
    swedate.o: swephexp.h sweodef.h swedll.h
    swehouse.o: swephexp.h sweodef.h swedll.h swephlib.h swehouse.h
    swejpl.o: swephexp.h sweodef.h swedll.h sweph.h swejpl.h
    swemini.o: swephexp.h sweodef.h swedll.h
    swemmoon.o: swephexp.h sweodef.h swedll.h sweph.h swephlib.h
    swemplan.o: swephexp.h sweodef.h swedll.h sweph.h swephlib.h swemptab.c
    swepcalc.o: swepcalc.h swephexp.h sweodef.h swedll.h
    sweph.o: swejpl.h sweodef.h swephexp.h swedll.h sweph.h swephlib.h
    swehel.o: sweodef.h swedll.h swephexp.h sweph.h swephlib.h
    swephlib.o: swephexp.h sweodef.h swedll.h sweph.h swephlib.h
    swetest.o: swephexp.h sweodef.h swedll.h
    It compiles "swetest", and "libswe.a" but not "swemini" and "libswe.so". I don't know why.

    Does anyone have any ideas that can help me out or improve the Makefile?

    Kind regards,

    Johannes Kepler
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0
    Originally Posted by ishnid
    How are you running this?
    Hi,

    Typing "make".

    Regards,

    Johannes
  6. #4
  7. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    If you do that, it will by default run the first target, which is swetest. It's not asked to run swemini so that's why your files are missing.

    You could add another target at the top of the file that would have a dependency on both swetest and swemini if you wanted to run both by default, e.g.:
    Code:
    all: swetest swemini
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0
    Hi,

    How would I do that? - sorry to bother. Just add the line?
    And what about "libswe.so"?

    Regards,

    Johannes
  10. #6
  11. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    I'd suggest reading a tutorial on makefiles so that you can fully understand what's going on with this.

    Yes, place the line I gave you somewhere above the "swetest: swetest.o libswe.a" line, so that it's the first target that 'make' sees.

    As for libswe.so, I hadn't spotted that. If you want that target to be run too, then add it as a dependency for 'all' too.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0
    Hi,

    Thank you very much - it works fine. And it "makes" perfect sense

    Kind regards,

    Johannes

IMN logo majestic logo threadwatch logo seochat tools logo