Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 146263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:34:16+00:00 2026-05-11T08:34:16+00:00

I don’t know much about creating Makefiles, but I’ve been reading the make manual

  • 0

I don’t know much about creating Makefiles, but I’ve been reading the make manual and I have made some progress. My Makefile works and does what I want.

My situation usually involves between 1 and 3 different program needed to be compiled and sent to my TA for marking and such via a webform. The structure of each application is ‘prog.c’, ‘prog_lib.h’, and ‘prog_lib.c’. In the past, I have been creating separate directories for each program and creating separate Makefiles for each directory to build the program contained within. I then tar each folder and submit them separately.

Recently, the TAs have been asking for all source files to be in one directory and one Makefile with the various targets to be built so their marking applications can work without any human intervention.

I was wondering how someone more experienced would improve this Makefile and how my situation in general is usually solved? I would like to reduce the amount of typing I need to do when I move on to my next assignment and have to update several places.

Here is my Makefile:

ASSIGNMENT = 3 TARNAME = Assignment$(ASSIGNMENT).tar.bz2  CC = gcc CFLAGS = -O2 -Wall -ansi -pedantic -W # I like warnings LDFLAGS = -lm DEBUG = -g # to resolve symbols in GDB and valgrind  FREQ_OUT = frequency_table FREQ_SOURCES = frequency_table.c frequency_table_lib.c FREQ_OBJECTS = frequency_table.o frequency_table_lib.o  DECODE_OUT = decode DECODE_SOURCES = decode.c decode_lib.c DECODE_OBJECTS = decode.o decode_lib.o  SOURCES = $(FREQ_SOURCES) $(DECODE_SOURCES) OBJECTS = $(FREQ_OBJECTS) $(DECODE_OBJECTS) OUT = $(FREQ_OUT) $(DECODE_OUT)  .PHONY: info info:     @echo -e 'make info\n' \             '\tmake all \t\t\tMake all targets\n' \             '\tmake frequency_table \t\tMakes frequency table\n' \             '\tmake decode \t\t\tMakes decode\n' \             '\tmake dist \t\t\tMakes tar archive of sources and Makefile\n' \             '\tmake clean \t\t\tRemoves all the object files and executables\n' \             '\tmake distclean \t\t\tPerforms clean and removes tar archive'  .PHONY: all all:    $(OUT)  $(FREQ_OUT):    $(FREQ_OBJECTS)     $(CC) $(CFLAGS) $(DEBUG) $(LDFLAGS) $(FREQ_OBJECTS) -o $@  $(DECODE_OUT):  $(DECODE_OBJECTS)     $(CC) $(CFLAGS) $(DEBUG) $(LDFLAGS) $(DECODE_OBJECTS) -o $@  .o:     $(CC) -c $(CFLAGS) -o $@ $<  .PHONY: dist dist: $(SOURCES)     @echo 'Creating tar archive. See $(TARNAME)'     tar cvjf $(TARNAME) $(SOURCES) $(wildcard *_lib.h) Makefile  .PHONY: clean clean:     rm -f $(OUT) $(OBJECTS)  .PHONY: distclean distclean: clean     rm -f $(TARNAME) 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:34:17+00:00Added an answer on May 11, 2026 at 8:34 am

    You really don’t need the $(CC) $(CFLAGS) $(DEBUG) $(LDFLAGS) $(FREQ_OBJECTS) -o $@ lines. make already knows how to build binaries.

    If your filenames are constant for different binaries (binary.c and binary_lib.c), you can also create a general rule for that:

    FOO := $(shell ls *_lib.c) BIN = $(FOO:%_lib.c=%)  $(BIN) : % : %.o %_lib.o 

    EDIT: Here’s how it works:

    1. FOO is the list of all files ending with _lib.c
    2. BIN is the same list, with the ‘_lib.c’ suffixes removed, so it’s the list of your binaries
    3. The last line is your make rule. The rule states each foo in $(BIN) depends on foo.o and foo_lib.o
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Thanks for the all replies, after going through other libraries… May 11, 2026 at 11:10 am
  • added an answer The only way I can think of to do this… May 11, 2026 at 11:10 am
  • added an answer Your first route is a 'greedy' route and will happily… May 11, 2026 at 11:10 am

Related Questions

I don't know when to add to a dataset a tableadapter or a query
I don't edit CSS very often, and almost every time I need to go
I don't understand where the extra bits are coming from in this article about
I don't want PHP errors to display /html, but I want them to display
I don’t think I’ve grokked currying yet. I understand what it does, and how
I don't remember whether I was dreaming or not but I seem to recall
I don't expect a straightforward silver bullet answer to this, but what are the
I don't want to take the time to learn Obj-C. I've spent 7+ years
I don't know if anyone has seen this issue before but I'm just stumped.
I don't currently use ajax.net though I would be open to it if it

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.